symdef.inc 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {****************************************************************************
  19. TDEF (base class for definitions)
  20. ****************************************************************************}
  21. const
  22. { if you change one of the following contants, }
  23. { you have also to change the typinfo unit }
  24. tkUnknown = 0;
  25. tkInteger = 1;
  26. tkChar = 2;
  27. tkEnumeration = 3;
  28. tkFloat = 4;
  29. tkSet = 6;
  30. tkMethod = 7;
  31. tkSString = 8;
  32. tkString = tkSString;
  33. tkLString = 9;
  34. tkAString = 10;
  35. tkWString = 11;
  36. tkVariant = 12;
  37. tkArray = 13;
  38. tkRecord = 14;
  39. tkInterface = 15;
  40. tkClass = 16;
  41. tkObject = 17;
  42. tkWChar = 18;
  43. tkBool = 19;
  44. otSByte = 0;
  45. otUByte = 1;
  46. otSWord = 2;
  47. otUWord = 3;
  48. otSLong = 4;
  49. otULong = 5;
  50. ftSingle = 0;
  51. ftDouble = 1;
  52. ftExtended = 2;
  53. ftComp = 3;
  54. ftCurr = 4;
  55. ftFixed16 = 5;
  56. ftFixed32 = 6;
  57. constructor tdef.init;
  58. begin
  59. deftype:=abstractdef;
  60. owner := nil;
  61. next := nil;
  62. sym := nil;
  63. indexnb := 0;
  64. if registerdef then
  65. symtablestack^.registerdef(@self);
  66. has_rtti:=false;
  67. has_inittable:=false;
  68. {$ifdef GDB}
  69. is_def_stab_written := false;
  70. globalnb := 0;
  71. if assigned(lastglobaldef) then
  72. begin
  73. lastglobaldef^.nextglobal := @self;
  74. previousglobal:=lastglobaldef;
  75. end
  76. else
  77. begin
  78. firstglobaldef := @self;
  79. previousglobal := nil;
  80. end;
  81. lastglobaldef := @self;
  82. nextglobal := nil;
  83. {$endif GDB}
  84. end;
  85. constructor tdef.load;
  86. begin
  87. deftype:=abstractdef;
  88. indexnb := 0;
  89. sym := nil;
  90. owner := nil;
  91. next := nil;
  92. has_rtti:=false;
  93. has_inittable:=false;
  94. {$ifdef GDB}
  95. is_def_stab_written := false;
  96. globalnb := 0;
  97. if assigned(lastglobaldef) then
  98. begin
  99. lastglobaldef^.nextglobal := @self;
  100. previousglobal:=lastglobaldef;
  101. end
  102. else
  103. begin
  104. firstglobaldef := @self;
  105. previousglobal:=nil;
  106. end;
  107. lastglobaldef := @self;
  108. nextglobal := nil;
  109. {$endif GDB}
  110. end;
  111. destructor tdef.done;
  112. begin
  113. {$ifdef GDB}
  114. { first element ? }
  115. if not(assigned(previousglobal)) then
  116. begin
  117. firstglobaldef := nextglobal;
  118. if assigned(firstglobaldef) then
  119. firstglobaldef^.previousglobal:=nil;
  120. end
  121. else
  122. begin
  123. { remove reference in the element before }
  124. previousglobal^.nextglobal:=nextglobal;
  125. end;
  126. { last element ? }
  127. if not(assigned(nextglobal)) then
  128. begin
  129. lastglobaldef := previousglobal;
  130. if assigned(lastglobaldef) then
  131. lastglobaldef^.nextglobal:=nil;
  132. end
  133. else
  134. nextglobal^.previousglobal:=previousglobal;
  135. previousglobal:=nil;
  136. nextglobal:=nil;
  137. {$endif GDB}
  138. end;
  139. procedure tdef.write;
  140. begin
  141. {$ifdef GDB}
  142. if globalnb = 0 then
  143. begin
  144. if assigned(owner) then
  145. globalnb := owner^.getnewtypecount
  146. else
  147. begin
  148. globalnb := PGlobalTypeCount^;
  149. Inc(PGlobalTypeCount^);
  150. end;
  151. end;
  152. {$endif GDB}
  153. end;
  154. function tdef.size : longint;
  155. begin
  156. size:=savesize;
  157. end;
  158. {$ifdef GDB}
  159. procedure tdef.set_globalnb;
  160. begin
  161. globalnb :=PGlobalTypeCount^;
  162. inc(PglobalTypeCount^);
  163. end;
  164. function tdef.stabstring : pchar;
  165. begin
  166. stabstring := strpnew('t'+numberstring+';');
  167. end;
  168. function tdef.numberstring : string;
  169. var table : psymtable;
  170. begin
  171. {formal def have no type !}
  172. if deftype = formaldef then
  173. begin
  174. numberstring := voiddef^.numberstring;
  175. exit;
  176. end;
  177. if (not assigned(sym)) or (not sym^.isusedinstab) then
  178. begin
  179. {set even if debuglist is not defined}
  180. if assigned(sym) then
  181. sym^.isusedinstab := true;
  182. if assigned(debuglist) and not is_def_stab_written then
  183. concatstabto(debuglist);
  184. end;
  185. if not use_dbx then
  186. begin
  187. if globalnb = 0 then
  188. set_globalnb;
  189. numberstring := tostr(globalnb);
  190. end
  191. else
  192. begin
  193. if globalnb = 0 then
  194. begin
  195. if assigned(owner) then
  196. globalnb := owner^.getnewtypecount
  197. else
  198. begin
  199. globalnb := PGlobalTypeCount^;
  200. Inc(PGlobalTypeCount^);
  201. end;
  202. end;
  203. if assigned(sym) then
  204. begin
  205. table := sym^.owner;
  206. if table^.unitid > 0 then
  207. numberstring := '('+tostr(table^.unitid)+','
  208. +tostr(sym^.definition^.globalnb)+')'
  209. else
  210. numberstring := tostr(globalnb);
  211. exit;
  212. end;
  213. numberstring := tostr(globalnb);
  214. end;
  215. end;
  216. function tdef.allstabstring : pchar;
  217. var stabchar : string[2];
  218. ss,st : pchar;
  219. name : string;
  220. sym_line_no : longint;
  221. begin
  222. ss := stabstring;
  223. getmem(st,strlen(ss)+512);
  224. stabchar := 't';
  225. if deftype in tagtypes then
  226. stabchar := 'Tt';
  227. if assigned(sym) then
  228. begin
  229. name := sym^.name;
  230. sym_line_no:=sym^.fileinfo.line;
  231. end
  232. else
  233. begin
  234. name := ' ';
  235. sym_line_no:=0;
  236. end;
  237. strpcopy(st,'"'+name+':'+stabchar+numberstring+'=');
  238. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  239. allstabstring := strnew(st);
  240. freemem(st,strlen(ss)+512);
  241. strdispose(ss);
  242. end;
  243. procedure tdef.concatstabto(asmlist : paasmoutput);
  244. var stab_str : pchar;
  245. begin
  246. if ((sym = nil) or sym^.isusedinstab or use_dbx)
  247. and not is_def_stab_written then
  248. begin
  249. If use_dbx then
  250. begin
  251. { otherwise you get two of each def }
  252. If assigned(sym) then
  253. begin
  254. if sym^.typ=typesym then
  255. sym^.isusedinstab:=true;
  256. if (sym^.owner = nil) or
  257. ((sym^.owner^.symtabletype = unitsymtable) and
  258. punitsymtable(sym^.owner)^.dbx_count_ok) then
  259. begin
  260. {with DBX we get the definition from the other objects }
  261. is_def_stab_written := true;
  262. exit;
  263. end;
  264. end;
  265. end;
  266. { to avoid infinite loops }
  267. is_def_stab_written := true;
  268. stab_str := allstabstring;
  269. if asmlist = debuglist then do_count_dbx := true;
  270. { count_dbx(stab_str); moved to GDB.PAS}
  271. asmlist^.concat(new(pai_stabs,init(stab_str)));
  272. end;
  273. end;
  274. {$endif GDB}
  275. procedure tdef.deref;
  276. begin
  277. end;
  278. { rtti generation }
  279. procedure tdef.generate_rtti;
  280. begin
  281. has_rtti:=true;
  282. getlabel(rtti_label);
  283. write_child_rtti_data;
  284. rttilist^.concat(new(pai_label,init(rtti_label)));
  285. write_rtti_data;
  286. end;
  287. function tdef.get_rtti_label : plabel;
  288. begin
  289. if not(has_rtti) then
  290. generate_rtti;
  291. get_rtti_label:=rtti_label;
  292. end;
  293. { init table handling }
  294. function tdef.needs_inittable : boolean;
  295. begin
  296. needs_inittable:=false;
  297. end;
  298. procedure tdef.generate_inittable;
  299. begin
  300. has_inittable:=true;
  301. getlabel(inittable_label);
  302. write_child_init_data;
  303. rttilist^.concat(new(pai_label,init(inittable_label)));
  304. write_init_data;
  305. end;
  306. procedure tdef.write_init_data;
  307. begin
  308. write_rtti_data;
  309. end;
  310. procedure tdef.write_child_init_data;
  311. begin
  312. write_child_rtti_data;
  313. end;
  314. function tdef.get_inittable_label : plabel;
  315. begin
  316. if not(has_inittable) then
  317. generate_inittable;
  318. get_inittable_label:=inittable_label;
  319. end;
  320. procedure tdef.writename;
  321. var
  322. str : string;
  323. begin
  324. { name }
  325. if assigned(sym) then
  326. begin
  327. str:=sym^.name;
  328. rttilist^.concat(new(pai_string,init(chr(length(str))+str)));
  329. end
  330. else
  331. rttilist^.concat(new(pai_string,init(#0)))
  332. end;
  333. { returns true, if the definition can be published }
  334. function tdef.is_publishable : boolean;
  335. begin
  336. is_publishable:=false;
  337. end;
  338. procedure tdef.write_rtti_data;
  339. begin
  340. end;
  341. procedure tdef.write_child_rtti_data;
  342. begin
  343. end;
  344. {****************************************************************************
  345. TSTRINGDEF
  346. ****************************************************************************}
  347. constructor tstringdef.init(l : byte);
  348. begin
  349. tdef.init;
  350. string_typ:=st_shortstring;
  351. deftype:=stringdef;
  352. len:=l;
  353. savesize:=len+1;
  354. end;
  355. constructor tstringdef.load;
  356. begin
  357. tdef.load;
  358. string_typ:=st_shortstring;
  359. deftype:=stringdef;
  360. len:=readbyte;
  361. savesize:=len+1;
  362. end;
  363. constructor tstringdef.longinit(l : longint);
  364. begin
  365. tdef.init;
  366. string_typ:=st_longstring;
  367. deftype:=stringdef;
  368. len:=l;
  369. savesize:=Sizeof(pointer);
  370. end;
  371. constructor tstringdef.longload;
  372. begin
  373. tdef.load;
  374. deftype:=stringdef;
  375. string_typ:=st_longstring;
  376. len:=readlong;
  377. savesize:=Sizeof(pointer);
  378. end;
  379. constructor tstringdef.ansiinit(l : longint);
  380. begin
  381. tdef.init;
  382. string_typ:=st_ansistring;
  383. deftype:=stringdef;
  384. len:=l;
  385. savesize:=sizeof(pointer);
  386. end;
  387. constructor tstringdef.ansiload;
  388. begin
  389. tdef.load;
  390. deftype:=stringdef;
  391. string_typ:=st_ansistring;
  392. len:=readlong;
  393. savesize:=sizeof(pointer);
  394. end;
  395. constructor tstringdef.wideinit(l : longint);
  396. begin
  397. tdef.init;
  398. string_typ:=st_widestring;
  399. deftype:=stringdef;
  400. len:=l;
  401. savesize:=sizeof(pointer);
  402. end;
  403. constructor tstringdef.wideload;
  404. begin
  405. tdef.load;
  406. deftype:=stringdef;
  407. string_typ:=st_widestring;
  408. len:=readlong;
  409. savesize:=sizeof(pointer);
  410. end;
  411. function tstringdef.size : longint;
  412. begin
  413. size:=savesize;
  414. end;
  415. procedure tstringdef.write;
  416. begin
  417. tdef.write;
  418. if string_typ=st_shortstring then
  419. writebyte(len)
  420. else
  421. writelong(len);
  422. case string_typ of
  423. st_shortstring : current_ppu^.writeentry(ibstringdef);
  424. st_longstring : current_ppu^.writeentry(iblongstringdef);
  425. st_ansistring : current_ppu^.writeentry(ibansistringdef);
  426. st_widestring : current_ppu^.writeentry(ibwidestringdef);
  427. end;
  428. end;
  429. {$ifdef GDB}
  430. function tstringdef.stabstring : pchar;
  431. var
  432. bytest,charst,longst : string;
  433. begin
  434. case string_typ of
  435. st_shortstring:
  436. begin
  437. charst := typeglobalnumber('char');
  438. { this is what I found in stabs.texinfo but
  439. gdb 4.12 for go32 doesn't understand that !! }
  440. {$IfDef GDBknowsstrings}
  441. stabstring := strpnew('n'+charst+';'+tostr(len));
  442. {$else}
  443. bytest := typeglobalnumber('byte');
  444. stabstring := strpnew('s'+tostr(len+1)+'length:'+bytest
  445. +',0,8;st:ar'+bytest
  446. +';1;'+tostr(len)+';'+charst+',8,'+tostr(len*8)+';;');
  447. {$EndIf}
  448. end;
  449. st_longstring:
  450. begin
  451. charst := typeglobalnumber('char');
  452. { this is what I found in stabs.texinfo but
  453. gdb 4.12 for go32 doesn't understand that !! }
  454. {$IfDef GDBknowsstrings}
  455. stabstring := strpnew('n'+charst+';'+tostr(len));
  456. {$else}
  457. bytest := typeglobalnumber('byte');
  458. longst := typeglobalnumber('longint');
  459. stabstring := strpnew('s'+tostr(len+5)+'length:'+longst
  460. +',0,32;dummy:'+bytest+',32,8;st:ar'+bytest
  461. +';1;'+tostr(len)+';'+charst+',40,'+tostr(len*8)+';;');
  462. {$EndIf}
  463. end;
  464. st_ansistring:
  465. begin
  466. { an ansi string looks like a pchar easy !! }
  467. stabstring:=strpnew('*'+typeglobalnumber('char'));
  468. end;
  469. st_widestring:
  470. begin
  471. { an ansi string looks like a pchar easy !! }
  472. stabstring:=strpnew('*'+typeglobalnumber('char'));
  473. end;
  474. end;
  475. end;
  476. procedure tstringdef.concatstabto(asmlist : paasmoutput);
  477. begin
  478. inherited concatstabto(asmlist);
  479. end;
  480. {$endif GDB}
  481. function tstringdef.needs_inittable : boolean;
  482. begin
  483. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  484. end;
  485. procedure tstringdef.write_rtti_data;
  486. begin
  487. case string_typ of
  488. st_ansistring:
  489. begin
  490. rttilist^.concat(new(pai_const,init_8bit(tkAString)));
  491. end;
  492. st_widestring:
  493. begin
  494. rttilist^.concat(new(pai_const,init_8bit(tkWString)));
  495. end;
  496. st_longstring:
  497. begin
  498. rttilist^.concat(new(pai_const,init_8bit(tkLString)));
  499. end;
  500. st_shortstring:
  501. begin
  502. rttilist^.concat(new(pai_const,init_8bit(tkSString)));
  503. rttilist^.concat(new(pai_const,init_8bit(len)));
  504. end;
  505. end;
  506. end;
  507. function tstringdef.is_publishable : boolean;
  508. begin
  509. is_publishable:=true;
  510. end;
  511. {****************************************************************************
  512. TENUMDEF
  513. ****************************************************************************}
  514. constructor tenumdef.init;
  515. begin
  516. tdef.init;
  517. deftype:=enumdef;
  518. minval:=0;
  519. maxval:=0;
  520. calcsavesize;
  521. has_jumps:=false;
  522. basedef:=nil;
  523. rangenr:=0;
  524. first:=nil;
  525. end;
  526. constructor tenumdef.init_subrange(_basedef:penumdef;_min,_max:longint);
  527. begin
  528. tdef.init;
  529. deftype:=enumdef;
  530. minval:=_min;
  531. maxval:=_max;
  532. basedef:=_basedef;
  533. calcsavesize;
  534. has_jumps:=false;
  535. rangenr:=0;
  536. first:=nil;
  537. end;
  538. constructor tenumdef.load;
  539. begin
  540. tdef.load;
  541. deftype:=enumdef;
  542. basedef:=penumdef(readdefref);
  543. minval:=readlong;
  544. maxval:=readlong;
  545. savesize:=readlong;
  546. has_jumps:=false;
  547. first:=Nil;
  548. end;
  549. procedure tenumdef.calcsavesize;
  550. begin
  551. if (aktpackenum=4) or (min<0) or (max>65535) then
  552. savesize:=4
  553. else
  554. if (aktpackenum=2) or (min<0) or (max>255) then
  555. savesize:=2
  556. else
  557. savesize:=1;
  558. end;
  559. procedure tenumdef.setmax(_max:longint);
  560. begin
  561. maxval:=_max;
  562. calcsavesize;
  563. end;
  564. procedure tenumdef.setmin(_min:longint);
  565. begin
  566. minval:=_min;
  567. calcsavesize;
  568. end;
  569. function tenumdef.min:longint;
  570. begin
  571. min:=minval;
  572. end;
  573. function tenumdef.max:longint;
  574. begin
  575. max:=maxval;
  576. end;
  577. procedure tenumdef.deref;
  578. begin
  579. resolvedef(pdef(basedef));
  580. end;
  581. destructor tenumdef.done;
  582. begin
  583. inherited done;
  584. end;
  585. procedure tenumdef.write;
  586. begin
  587. tdef.write;
  588. writedefref(basedef);
  589. writelong(min);
  590. writelong(max);
  591. writelong(savesize);
  592. current_ppu^.writeentry(ibenumdef);
  593. end;
  594. function tenumdef.getrangecheckstring : string;
  595. begin
  596. if (cs_smartlink in aktmoduleswitches) then
  597. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  598. else
  599. getrangecheckstring:='R_'+tostr(rangenr);
  600. end;
  601. procedure tenumdef.genrangecheck;
  602. begin
  603. if rangenr=0 then
  604. begin
  605. { generate two constant for bounds }
  606. getlabelnr(rangenr);
  607. if (cs_smartlink in aktmoduleswitches) then
  608. datasegment^.concat(new(pai_symbol,init_global(getrangecheckstring)))
  609. else
  610. datasegment^.concat(new(pai_symbol,init(getrangecheckstring)));
  611. datasegment^.concat(new(pai_const,init_32bit(min)));
  612. datasegment^.concat(new(pai_const,init_32bit(max)));
  613. end;
  614. end;
  615. {$ifdef GDB}
  616. function tenumdef.stabstring : pchar;
  617. var st,st2 : pchar;
  618. p : penumsym;
  619. s : string;
  620. memsize : word;
  621. begin
  622. memsize := memsizeinc;
  623. getmem(st,memsize);
  624. strpcopy(st,'e');
  625. p := first;
  626. while assigned(p) do
  627. begin
  628. s :=p^.name+':'+tostr(p^.value)+',';
  629. { place for the ending ';' also }
  630. if (strlen(st)+length(s)+1<memsize) then
  631. strpcopy(strend(st),s)
  632. else
  633. begin
  634. getmem(st2,memsize+memsizeinc);
  635. strcopy(st2,st);
  636. freemem(st,memsize);
  637. st := st2;
  638. memsize := memsize+memsizeinc;
  639. strpcopy(strend(st),s);
  640. end;
  641. p := p^.next;
  642. end;
  643. strpcopy(strend(st),';');
  644. stabstring := strnew(st);
  645. freemem(st,memsize);
  646. end;
  647. {$endif GDB}
  648. procedure tenumdef.write_child_rtti_data;
  649. begin
  650. if assigned(basedef) then
  651. basedef^.get_rtti_label;
  652. end;
  653. procedure tenumdef.write_rtti_data;
  654. begin
  655. rttilist^.concat(new(pai_const,init_8bit(tkEnumeration)));
  656. case savesize of
  657. 1:
  658. rttilist^.concat(new(pai_const,init_8bit(otUByte)));
  659. 2:
  660. rttilist^.concat(new(pai_const,init_8bit(otUWord)));
  661. 4:
  662. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  663. end;
  664. rttilist^.concat(new(pai_const,init_32bit(min)));
  665. rttilist^.concat(new(pai_const,init_32bit(max)));
  666. if assigned(basedef) then
  667. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(basedef^.get_rtti_label)))))
  668. else
  669. rttilist^.concat(new(pai_const,init_32bit(0)));
  670. {!!!!!!! Name list }
  671. end;
  672. function tenumdef.is_publishable : boolean;
  673. begin
  674. is_publishable:=true;
  675. end;
  676. {****************************************************************************
  677. TORDDEF
  678. ****************************************************************************}
  679. constructor torddef.init(t : tbasetype;v,b : longint);
  680. begin
  681. inherited init;
  682. deftype:=orddef;
  683. low:=v;
  684. high:=b;
  685. typ:=t;
  686. rangenr:=0;
  687. setsize;
  688. end;
  689. constructor torddef.load;
  690. begin
  691. inherited load;
  692. deftype:=orddef;
  693. typ:=tbasetype(readbyte);
  694. low:=readlong;
  695. high:=readlong;
  696. rangenr:=0;
  697. setsize;
  698. end;
  699. procedure torddef.setsize;
  700. begin
  701. if typ=uauto then
  702. begin
  703. { generate a unsigned range if high<0 and low>=0 }
  704. if (low>=0) and (high<0) then
  705. begin
  706. savesize:=4;
  707. typ:=u32bit;
  708. end
  709. else if (low>=0) and (high<=255) then
  710. begin
  711. savesize:=1;
  712. typ:=u8bit;
  713. end
  714. else if (low>=-128) and (high<=127) then
  715. begin
  716. savesize:=1;
  717. typ:=s8bit;
  718. end
  719. else if (low>=0) and (high<=65536) then
  720. begin
  721. savesize:=2;
  722. typ:=u16bit;
  723. end
  724. else if (low>=-32768) and (high<=32767) then
  725. begin
  726. savesize:=2;
  727. typ:=s16bit;
  728. end
  729. else
  730. begin
  731. savesize:=4;
  732. typ:=s32bit;
  733. end;
  734. end
  735. else
  736. begin
  737. case typ of
  738. u8bit,s8bit,
  739. uchar,bool8bit : savesize:=1;
  740. u16bit,s16bit,
  741. bool16bit : savesize:=2;
  742. s32bit,u32bit,
  743. bool32bit : savesize:=4;
  744. else
  745. savesize:=0;
  746. end;
  747. end;
  748. { there are no entrys for range checking }
  749. rangenr:=0;
  750. end;
  751. function torddef.getrangecheckstring : string;
  752. begin
  753. if (cs_smartlink in aktmoduleswitches) then
  754. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  755. else
  756. getrangecheckstring:='R_'+tostr(rangenr);
  757. end;
  758. procedure torddef.genrangecheck;
  759. begin
  760. if rangenr=0 then
  761. begin
  762. { generate two constant for bounds }
  763. getlabelnr(rangenr);
  764. if (cs_smartlink in aktmoduleswitches) then
  765. datasegment^.concat(new(pai_symbol,init_global(getrangecheckstring)))
  766. else
  767. datasegment^.concat(new(pai_symbol,init(getrangecheckstring)));
  768. if low<=high then
  769. begin
  770. datasegment^.concat(new(pai_const,init_32bit(low)));
  771. datasegment^.concat(new(pai_const,init_32bit(high)));
  772. end
  773. { for u32bit we need two bounds }
  774. else
  775. begin
  776. datasegment^.concat(new(pai_const,init_32bit(low)));
  777. datasegment^.concat(new(pai_const,init_32bit($7fffffff)));
  778. inc(nextlabelnr);
  779. if (cs_smartlink in aktmoduleswitches) then
  780. datasegment^.concat(new(pai_symbol,init_global('R_'+current_module^.modulename^+tostr(rangenr+1))))
  781. else
  782. datasegment^.concat(new(pai_symbol,init('R_'+tostr(rangenr+1))));
  783. datasegment^.concat(new(pai_const,init_32bit($80000000)));
  784. datasegment^.concat(new(pai_const,init_32bit(high)));
  785. end;
  786. end;
  787. end;
  788. procedure torddef.write;
  789. begin
  790. tdef.write;
  791. writebyte(byte(typ));
  792. writelong(low);
  793. writelong(high);
  794. current_ppu^.writeentry(iborddef);
  795. end;
  796. {$ifdef GDB}
  797. function torddef.stabstring : pchar;
  798. begin
  799. case typ of
  800. uvoid : stabstring := strpnew(numberstring+';');
  801. {GDB 4.12 for go32 doesn't like boolean as range for 0 to 1 !!!}
  802. bool8bit,
  803. bool16bit,
  804. bool32bit : stabstring := strpnew('r'+numberstring+';0;255;');
  805. { u32bit : stabstring := strpnew('r'+
  806. s32bitdef^.numberstring+';0;-1;'); }
  807. else
  808. stabstring := strpnew('r'+s32bitdef^.numberstring+';'+tostr(low)+';'+tostr(high)+';');
  809. end;
  810. end;
  811. {$endif GDB}
  812. procedure torddef.write_rtti_data;
  813. const
  814. trans : array[uchar..bool8bit] of byte =
  815. (otUByte,otUByte,otUWord,otULong,otSByte,otSWord,otSLong,otUByte);
  816. begin
  817. case typ of
  818. bool8bit:
  819. rttilist^.concat(new(pai_const,init_8bit(tkBool)));
  820. uchar:
  821. rttilist^.concat(new(pai_const,init_8bit(tkChar)));
  822. else
  823. rttilist^.concat(new(pai_const,init_8bit(tkInteger)));
  824. end;
  825. rttilist^.concat(new(pai_const,init_8bit(byte(trans[typ]))));
  826. rttilist^.concat(new(pai_const,init_32bit(low)));
  827. rttilist^.concat(new(pai_const,init_32bit(high)));
  828. end;
  829. function torddef.is_publishable : boolean;
  830. begin
  831. is_publishable:=typ in [uchar..bool8bit];
  832. end;
  833. {****************************************************************************
  834. TFLOATDEF
  835. ****************************************************************************}
  836. constructor tfloatdef.init(t : tfloattype);
  837. begin
  838. inherited init;
  839. deftype:=floatdef;
  840. typ:=t;
  841. setsize;
  842. end;
  843. constructor tfloatdef.load;
  844. begin
  845. inherited load;
  846. deftype:=floatdef;
  847. typ:=tfloattype(readbyte);
  848. setsize;
  849. end;
  850. procedure tfloatdef.setsize;
  851. begin
  852. case typ of
  853. f16bit : savesize:=2;
  854. f32bit,
  855. s32real : savesize:=4;
  856. s64real : savesize:=8;
  857. s64bit : savesize:=8;
  858. s80real : savesize:=extended_size;
  859. else
  860. savesize:=0;
  861. end;
  862. end;
  863. procedure tfloatdef.write;
  864. begin
  865. inherited write;
  866. writebyte(byte(typ));
  867. current_ppu^.writeentry(ibfloatdef);
  868. end;
  869. {$ifdef GDB}
  870. function tfloatdef.stabstring : pchar;
  871. begin
  872. case typ of
  873. s32real,
  874. s64real : stabstring := strpnew('r'+
  875. s32bitdef^.numberstring+';'+tostr(savesize)+';0;');
  876. { for fixed real use longint instead to be able to }
  877. { debug something at least }
  878. f32bit:
  879. stabstring := s32bitdef^.stabstring;
  880. f16bit:
  881. stabstring := strpnew('r'+s32bitdef^.numberstring+';0;'+
  882. tostr($ffff)+';');
  883. { found this solution in stabsread.c from GDB v4.16 }
  884. s64bit : stabstring := strpnew('r'+
  885. s32bitdef^.numberstring+';-'+tostr(savesize)+';0;');
  886. {$ifdef i386}
  887. { under dos at least you must give a size of twelve instead of 10 !! }
  888. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  889. s80real : stabstring := strpnew('r'+s32bitdef^.numberstring+';12;0;');
  890. {$endif i386}
  891. else
  892. internalerror(10005);
  893. end;
  894. end;
  895. {$endif GDB}
  896. procedure tfloatdef.write_rtti_data;
  897. const
  898. translate : array[tfloattype] of byte =
  899. (ftFixed32,ftSingle,ftDouble,ftExtended,ftComp,ftFixed16);
  900. begin
  901. rttilist^.concat(new(pai_const,init_8bit(tkFloat)));
  902. rttilist^.concat(new(pai_const,init_8bit(translate[typ])));
  903. end;
  904. function tfloatdef.is_publishable : boolean;
  905. begin
  906. is_publishable:=true;
  907. end;
  908. {****************************************************************************
  909. TFILEDEF
  910. ****************************************************************************}
  911. constructor tfiledef.init(ft : tfiletype;tas : pdef);
  912. begin
  913. inherited init;
  914. deftype:=filedef;
  915. filetype:=ft;
  916. typed_as:=tas;
  917. setsize;
  918. end;
  919. constructor tfiledef.load;
  920. begin
  921. inherited load;
  922. deftype:=filedef;
  923. filetype:=tfiletype(readbyte);
  924. if filetype=ft_typed then
  925. typed_as:=readdefref
  926. else
  927. typed_as:=nil;
  928. setsize;
  929. end;
  930. procedure tfiledef.deref;
  931. begin
  932. if filetype=ft_typed then
  933. resolvedef(typed_as);
  934. end;
  935. procedure tfiledef.setsize;
  936. begin
  937. case filetype of
  938. ft_text : savesize:=572;
  939. ft_typed,
  940. ft_untyped : savesize:=316;
  941. end;
  942. end;
  943. procedure tfiledef.write;
  944. begin
  945. inherited write;
  946. writebyte(byte(filetype));
  947. if filetype=ft_typed then
  948. writedefref(typed_as);
  949. current_ppu^.writeentry(ibfiledef);
  950. end;
  951. {$ifdef GDB}
  952. function tfiledef.stabstring : pchar;
  953. begin
  954. {$IfDef GDBknowsfiles}
  955. case filetyp of
  956. ft_typed : stabstring := strpnew('d'+typed_as^.numberstring{+';'});
  957. ft_untyped : stabstring := strpnew('d'+voiddef^.numberstring{+';'});
  958. ft_text : stabstring := strpnew('d'+cchardef^.numberstring{+';'});
  959. end;
  960. {$Else}
  961. {based on
  962. FileRec = Packed Record
  963. Handle,
  964. Mode,
  965. RecSize : longint;
  966. _private : array[1..32] of byte;
  967. UserData : array[1..16] of byte;
  968. name : array[0..255] of char;
  969. End; }
  970. { the buffer part is still missing !! (PM) }
  971. { but the string could become too long !! }
  972. stabstring := strpnew('s'+tostr(savesize)+
  973. 'HANDLE:'+typeglobalnumber('longint')+',0,32;'+
  974. 'MODE:'+typeglobalnumber('longint')+',32,32;'+
  975. 'RECSIZE:'+typeglobalnumber('longint')+',64,32;'+
  976. '_PRIVATE:ar'+typeglobalnumber('word')+';1;32;'+typeglobalnumber('byte')
  977. +',96,256;'+
  978. 'USERDATA:ar'+typeglobalnumber('word')+';1;16;'+typeglobalnumber('byte')
  979. +',352,128;'+
  980. 'NAME:ar'+typeglobalnumber('word')+';0;255;'+typeglobalnumber('char')
  981. +',480,2048;;');
  982. {$EndIf}
  983. end;
  984. procedure tfiledef.concatstabto(asmlist : paasmoutput);
  985. begin
  986. { most file defs are unnamed !!! }
  987. if ((sym = nil) or sym^.isusedinstab or use_dbx) and not is_def_stab_written then
  988. begin
  989. if assigned(typed_as) then forcestabto(asmlist,typed_as);
  990. inherited concatstabto(asmlist);
  991. end;
  992. end;
  993. {$endif GDB}
  994. {****************************************************************************
  995. TPOINTERDEF
  996. ****************************************************************************}
  997. constructor tpointerdef.init(def : pdef);
  998. begin
  999. inherited init;
  1000. deftype:=pointerdef;
  1001. definition:=def;
  1002. savesize:=Sizeof(pointer);
  1003. end;
  1004. constructor tpointerdef.load;
  1005. begin
  1006. inherited load;
  1007. deftype:=pointerdef;
  1008. { the real address in memory is calculated later (deref) }
  1009. definition:=readdefref;
  1010. savesize:=Sizeof(pointer);
  1011. end;
  1012. procedure tpointerdef.deref;
  1013. begin
  1014. resolvedef(definition);
  1015. end;
  1016. procedure tpointerdef.write;
  1017. begin
  1018. inherited write;
  1019. writedefref(definition);
  1020. current_ppu^.writeentry(ibpointerdef);
  1021. end;
  1022. {$ifdef GDB}
  1023. function tpointerdef.stabstring : pchar;
  1024. begin
  1025. stabstring := strpnew('*'+definition^.numberstring);
  1026. end;
  1027. procedure tpointerdef.concatstabto(asmlist : paasmoutput);
  1028. var st,nb : string;
  1029. sym_line_no : longint;
  1030. begin
  1031. if ( (sym=nil) or sym^.isusedinstab or use_dbx) and not is_def_stab_written then
  1032. begin
  1033. if assigned(definition) then
  1034. if definition^.deftype in [recorddef,objectdef] then
  1035. begin
  1036. is_def_stab_written := true;
  1037. {to avoid infinite recursion in record with next-like fields }
  1038. nb := definition^.numberstring;
  1039. is_def_stab_written := false;
  1040. if not definition^.is_def_stab_written then
  1041. begin
  1042. if assigned(definition^.sym) then
  1043. begin
  1044. if assigned(sym) then
  1045. begin
  1046. st := sym^.name;
  1047. sym_line_no:=sym^.fileinfo.line;
  1048. end
  1049. else
  1050. begin
  1051. st := ' ';
  1052. sym_line_no:=0;
  1053. end;
  1054. st := '"'+st+':t'+numberstring+'=*'+definition^.numberstring
  1055. +'=xs'+definition^.sym^.name+':",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0';
  1056. if asmlist = debuglist then do_count_dbx := true;
  1057. asmlist^.concat(new(pai_stabs,init(strpnew(st))));
  1058. end;
  1059. end else inherited concatstabto(asmlist);
  1060. is_def_stab_written := true;
  1061. end else
  1062. begin
  1063. forcestabto(asmlist,definition);
  1064. inherited concatstabto(asmlist);
  1065. end;
  1066. end;
  1067. end;
  1068. {$endif GDB}
  1069. {****************************************************************************
  1070. TCLASSREFDEF
  1071. ****************************************************************************}
  1072. constructor tclassrefdef.init(def : pdef);
  1073. begin
  1074. inherited init(def);
  1075. deftype:=classrefdef;
  1076. definition:=def;
  1077. savesize:=Sizeof(pointer);
  1078. end;
  1079. constructor tclassrefdef.load;
  1080. begin
  1081. inherited load;
  1082. deftype:=classrefdef;
  1083. end;
  1084. procedure tclassrefdef.write;
  1085. begin
  1086. { be careful, tclassdefref inherits from tpointerdef }
  1087. tdef.write;
  1088. writedefref(definition);
  1089. current_ppu^.writeentry(ibclassrefdef);
  1090. end;
  1091. {$ifdef GDB}
  1092. function tclassrefdef.stabstring : pchar;
  1093. begin
  1094. stabstring:=strpnew('');
  1095. end;
  1096. procedure tclassrefdef.concatstabto(asmlist : paasmoutput);
  1097. begin
  1098. end;
  1099. {$endif GDB}
  1100. {***************************************************************************
  1101. TSETDEF
  1102. ***************************************************************************}
  1103. { For i386 smallsets work,
  1104. for m68k there are problems
  1105. can be test by compiling with -dusesmallset PM }
  1106. {$ifdef i386}
  1107. {$define usesmallset}
  1108. {$endif i386}
  1109. constructor tsetdef.init(s : pdef;high : longint);
  1110. begin
  1111. inherited init;
  1112. deftype:=setdef;
  1113. setof:=s;
  1114. {$ifdef usesmallset}
  1115. { small sets only working for i386 PM }
  1116. if high<32 then
  1117. begin
  1118. settype:=smallset;
  1119. savesize:=Sizeof(longint);
  1120. end
  1121. else
  1122. {$endif usesmallset}
  1123. if high<256 then
  1124. begin
  1125. settype:=normset;
  1126. savesize:=32;
  1127. end
  1128. else
  1129. {$ifdef testvarsets}
  1130. if high<$10000 then
  1131. begin
  1132. settype:=varset;
  1133. savesize:=4*((high+31) div 32);
  1134. end
  1135. else
  1136. {$endif testvarsets}
  1137. Message(sym_e_ill_type_decl_set);
  1138. end;
  1139. constructor tsetdef.load;
  1140. begin
  1141. inherited load;
  1142. deftype:=setdef;
  1143. setof:=readdefref;
  1144. settype:=tsettype(readbyte);
  1145. case settype of
  1146. normset : savesize:=32;
  1147. varset : savesize:=readlong;
  1148. smallset : savesize:=Sizeof(longint);
  1149. end;
  1150. end;
  1151. procedure tsetdef.write;
  1152. begin
  1153. inherited write;
  1154. writedefref(setof);
  1155. writebyte(byte(settype));
  1156. if settype=varset then
  1157. writelong(savesize);
  1158. current_ppu^.writeentry(ibsetdef);
  1159. end;
  1160. {$ifdef GDB}
  1161. function tsetdef.stabstring : pchar;
  1162. begin
  1163. stabstring := strpnew('S'+setof^.numberstring);
  1164. end;
  1165. procedure tsetdef.concatstabto(asmlist : paasmoutput);
  1166. begin
  1167. if ( not assigned(sym) or sym^.isusedinstab or use_dbx) and
  1168. not is_def_stab_written then
  1169. begin
  1170. if assigned(setof) then
  1171. forcestabto(asmlist,setof);
  1172. inherited concatstabto(asmlist);
  1173. end;
  1174. end;
  1175. {$endif GDB}
  1176. procedure tsetdef.deref;
  1177. begin
  1178. resolvedef(setof);
  1179. end;
  1180. procedure tsetdef.write_rtti_data;
  1181. begin
  1182. rttilist^.concat(new(pai_const,init_8bit(tkSet)));
  1183. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  1184. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(setof^.get_rtti_label)))));
  1185. end;
  1186. procedure tsetdef.write_child_rtti_data;
  1187. begin
  1188. setof^.get_rtti_label;
  1189. end;
  1190. function tsetdef.is_publishable : boolean;
  1191. begin
  1192. is_publishable:=settype=smallset;
  1193. end;
  1194. {***************************************************************************
  1195. TFORMALDEF
  1196. ***************************************************************************}
  1197. constructor tformaldef.init;
  1198. begin
  1199. inherited init;
  1200. deftype:=formaldef;
  1201. savesize:=Sizeof(pointer);
  1202. end;
  1203. constructor tformaldef.load;
  1204. begin
  1205. inherited load;
  1206. deftype:=formaldef;
  1207. savesize:=Sizeof(pointer);
  1208. end;
  1209. procedure tformaldef.write;
  1210. begin
  1211. inherited write;
  1212. current_ppu^.writeentry(ibformaldef);
  1213. end;
  1214. {$ifdef GDB}
  1215. function tformaldef.stabstring : pchar;
  1216. begin
  1217. stabstring := strpnew('formal'+numberstring+';');
  1218. end;
  1219. procedure tformaldef.concatstabto(asmlist : paasmoutput);
  1220. begin
  1221. { formaldef can't be stab'ed !}
  1222. end;
  1223. {$endif GDB}
  1224. {***************************************************************************
  1225. TARRAYDEF
  1226. ***************************************************************************}
  1227. constructor tarraydef.init(l,h : longint;rd : pdef);
  1228. begin
  1229. inherited init;
  1230. deftype:=arraydef;
  1231. lowrange:=l;
  1232. highrange:=h;
  1233. rangedef:=rd;
  1234. definition:=nil;
  1235. IsVariant:=false;
  1236. IsConstructor:=false;
  1237. IsArrayOfConst:=false;
  1238. rangenr:=0;
  1239. end;
  1240. constructor tarraydef.load;
  1241. begin
  1242. inherited load;
  1243. deftype:=arraydef;
  1244. { the addresses are calculated later }
  1245. definition:=readdefref;
  1246. rangedef:=readdefref;
  1247. lowrange:=readlong;
  1248. highrange:=readlong;
  1249. IsArrayOfConst:=boolean(readbyte);
  1250. IsVariant:=false;
  1251. IsConstructor:=false;
  1252. rangenr:=0;
  1253. end;
  1254. function tarraydef.getrangecheckstring : string;
  1255. begin
  1256. if (cs_smartlink in aktmoduleswitches) then
  1257. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1258. else
  1259. getrangecheckstring:='R_'+tostr(rangenr);
  1260. end;
  1261. procedure tarraydef.genrangecheck;
  1262. begin
  1263. if rangenr=0 then
  1264. begin
  1265. { generates the data for range checking }
  1266. getlabelnr(rangenr);
  1267. if (cs_smartlink in aktmoduleswitches) then
  1268. datasegment^.concat(new(pai_symbol,init_global(getrangecheckstring)))
  1269. else
  1270. datasegment^.concat(new(pai_symbol,init(getrangecheckstring)));
  1271. datasegment^.concat(new(pai_const,init_32bit(lowrange)));
  1272. datasegment^.concat(new(pai_const,init_32bit(highrange)));
  1273. end;
  1274. end;
  1275. procedure tarraydef.deref;
  1276. begin
  1277. resolvedef(definition);
  1278. resolvedef(rangedef);
  1279. end;
  1280. procedure tarraydef.write;
  1281. begin
  1282. inherited write;
  1283. writedefref(definition);
  1284. writedefref(rangedef);
  1285. writelong(lowrange);
  1286. writelong(highrange);
  1287. writebyte(byte(IsArrayOfConst));
  1288. current_ppu^.writeentry(ibarraydef);
  1289. end;
  1290. {$ifdef GDB}
  1291. function tarraydef.stabstring : pchar;
  1292. begin
  1293. stabstring := strpnew('ar'+rangedef^.numberstring+';'
  1294. +tostr(lowrange)+';'+tostr(highrange)+';'+definition^.numberstring);
  1295. end;
  1296. procedure tarraydef.concatstabto(asmlist : paasmoutput);
  1297. begin
  1298. if (not assigned(sym) or sym^.isusedinstab or use_dbx)
  1299. and not is_def_stab_written then
  1300. begin
  1301. {when array are inserted they have no definition yet !!}
  1302. if assigned(definition) then
  1303. inherited concatstabto(asmlist);
  1304. end;
  1305. end;
  1306. {$endif GDB}
  1307. function tarraydef.elesize : longint;
  1308. begin
  1309. elesize:=definition^.size;
  1310. end;
  1311. function tarraydef.size : longint;
  1312. begin
  1313. size:=(highrange-lowrange+1)*elesize;
  1314. end;
  1315. function tarraydef.needs_inittable : boolean;
  1316. begin
  1317. needs_inittable:=definition^.needs_inittable;
  1318. end;
  1319. procedure tarraydef.write_child_rtti_table;
  1320. begin
  1321. definition^.get_rtti_label;
  1322. end;
  1323. procedure tarraydef.write_rtti_data;
  1324. begin
  1325. rttilist^.concat(new(pai_const,init_8bit(13)));
  1326. writename;
  1327. { size of elements }
  1328. rttilist^.concat(new(pai_const,init_32bit(definition^.size)));
  1329. { count of elements }
  1330. rttilist^.concat(new(pai_const,init_32bit(highrange-lowrange+1)));
  1331. { element type }
  1332. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(definition^.get_rtti_label)))));
  1333. end;
  1334. {***************************************************************************
  1335. TRECDEF
  1336. ***************************************************************************}
  1337. constructor trecdef.init(p : psymtable);
  1338. begin
  1339. inherited init;
  1340. deftype:=recorddef;
  1341. symtable:=p;
  1342. savesize:=symtable^.datasize;
  1343. symtable^.defowner := @self;
  1344. end;
  1345. constructor trecdef.load;
  1346. var
  1347. oldread_member : boolean;
  1348. begin
  1349. inherited load;
  1350. deftype:=recorddef;
  1351. savesize:=readlong;
  1352. oldread_member:=read_member;
  1353. read_member:=true;
  1354. symtable:=new(psymtable,loadasstruct(recordsymtable));
  1355. read_member:=oldread_member;
  1356. symtable^.defowner := @self;
  1357. end;
  1358. destructor trecdef.done;
  1359. begin
  1360. if assigned(symtable) then dispose(symtable,done);
  1361. inherited done;
  1362. end;
  1363. var
  1364. binittable : boolean;
  1365. procedure check_rec_inittable(s : psym);
  1366. begin
  1367. if (s^.typ=varsym) and
  1368. ((pvarsym(s)^.definition^.deftype<>objectdef)
  1369. or not(pobjectdef(pvarsym(s)^.definition)^.isclass)) then
  1370. binittable:=pvarsym(s)^.definition^.needs_inittable;
  1371. end;
  1372. function trecdef.needs_inittable : boolean;
  1373. var
  1374. oldb : boolean;
  1375. begin
  1376. { there are recursive calls to needs_rtti possible, }
  1377. { so we have to change to old value how else should }
  1378. { we do that ? check_rec_rtti can't be a nested }
  1379. { procedure of needs_rtti ! }
  1380. oldb:=binittable;
  1381. binittable:=false;
  1382. symtable^.foreach(check_rec_inittable);
  1383. needs_inittable:=binittable;
  1384. binittable:=oldb;
  1385. end;
  1386. procedure trecdef.deref;
  1387. var
  1388. hp : pdef;
  1389. oldrecsyms : psymtable;
  1390. begin
  1391. oldrecsyms:=aktrecordsymtable;
  1392. aktrecordsymtable:=symtable;
  1393. { now dereference the definitions }
  1394. hp:=symtable^.rootdef;
  1395. while assigned(hp) do
  1396. begin
  1397. hp^.deref;
  1398. { set owner }
  1399. hp^.owner:=symtable;
  1400. hp:=hp^.next;
  1401. end;
  1402. {$ifdef tp}
  1403. symtable^.foreach(derefsym);
  1404. {$else}
  1405. symtable^.foreach(@derefsym);
  1406. {$endif}
  1407. aktrecordsymtable:=oldrecsyms;
  1408. end;
  1409. procedure trecdef.write;
  1410. var
  1411. oldread_member : boolean;
  1412. begin
  1413. oldread_member:=read_member;
  1414. read_member:=true;
  1415. inherited write;
  1416. writelong(savesize);
  1417. current_ppu^.writeentry(ibrecorddef);
  1418. self.symtable^.writeasstruct;
  1419. read_member:=oldread_member;
  1420. end;
  1421. {$ifdef GDB}
  1422. Const StabRecString : pchar = Nil;
  1423. StabRecSize : longint = 0;
  1424. RecOffset : Longint = 0;
  1425. procedure addname(p : psym);
  1426. var
  1427. news, newrec : pchar;
  1428. begin
  1429. { static variables from objects are like global objects }
  1430. if ((p^.properties and sp_static)<>0) then
  1431. exit;
  1432. If p^.typ = varsym then
  1433. begin
  1434. newrec := strpnew(p^.name+':'+pvarsym(p)^.definition^.numberstring
  1435. +','+tostr(pvarsym(p)^.address*8)+','
  1436. +tostr(pvarsym(p)^.definition^.size*8)+';');
  1437. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1438. begin
  1439. getmem(news,stabrecsize+memsizeinc);
  1440. strcopy(news,stabrecstring);
  1441. freemem(stabrecstring,stabrecsize);
  1442. stabrecsize:=stabrecsize+memsizeinc;
  1443. stabrecstring:=news;
  1444. end;
  1445. strcat(StabRecstring,newrec);
  1446. strdispose(newrec);
  1447. {This should be used for case !!}
  1448. RecOffset := RecOffset + pvarsym(p)^.definition^.size;
  1449. end;
  1450. end;
  1451. function trecdef.stabstring : pchar;
  1452. Var oldrec : pchar;
  1453. oldsize : longint;
  1454. begin
  1455. oldrec := stabrecstring;
  1456. oldsize:=stabrecsize;
  1457. GetMem(stabrecstring,memsizeinc);
  1458. stabrecsize:=memsizeinc;
  1459. strpcopy(stabRecString,'s'+tostr(savesize));
  1460. RecOffset := 0;
  1461. {$ifdef tp}
  1462. symtable^.foreach(addname);
  1463. {$else}
  1464. symtable^.foreach(@addname);
  1465. {$endif}
  1466. { FPC doesn't want to convert a char to a pchar}
  1467. { is this a bug ? }
  1468. strpcopy(strend(StabRecString),';');
  1469. stabstring := strnew(StabRecString);
  1470. Freemem(stabrecstring,stabrecsize);
  1471. stabrecstring := oldrec;
  1472. stabrecsize:=oldsize;
  1473. end;
  1474. procedure trecdef.concatstabto(asmlist : paasmoutput);
  1475. begin
  1476. if (not assigned(sym) or sym^.isusedinstab or use_dbx) and
  1477. (not is_def_stab_written) then
  1478. inherited concatstabto(asmlist);
  1479. end;
  1480. {$endif GDB}
  1481. var
  1482. count : longint;
  1483. procedure count_inittable_fields(sym : psym);{$ifndef fpc}far;{$endif}
  1484. begin
  1485. if pvarsym(sym)^.definition^.needs_inittable then
  1486. inc(count);
  1487. end;
  1488. procedure count_fields(sym : psym);{$ifndef fpc}far;{$endif}
  1489. begin
  1490. inc(count);
  1491. end;
  1492. procedure write_field_inittable(sym : psym);{$ifndef fpc}far;{$endif}
  1493. begin
  1494. if pvarsym(sym)^.definition^.needs_inittable then
  1495. begin
  1496. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(pvarsym(sym)^.definition^.get_inittable_label)))));
  1497. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1498. end;
  1499. end;
  1500. procedure write_field_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  1501. begin
  1502. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(pvarsym(sym)^.definition^.get_rtti_label)))));
  1503. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1504. end;
  1505. procedure generate_child_inittable(sym : psym);{$ifndef fpc}far;{$endif}
  1506. begin
  1507. if (sym^.typ=varsym) and pvarsym(sym)^.definition^.needs_inittable then
  1508. { force inittable generation }
  1509. pvarsym(sym)^.definition^.get_inittable_label;
  1510. end;
  1511. procedure generate_child_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  1512. begin
  1513. pvarsym(sym)^.definition^.get_rtti_label;
  1514. end;
  1515. procedure trecdef.write_child_rtti_data;
  1516. begin
  1517. symtable^.foreach(generate_child_rtti);
  1518. end;
  1519. procedure trecdef.write_child_init_data;
  1520. begin
  1521. symtable^.foreach(generate_child_inittable);
  1522. end;
  1523. procedure trecdef.write_rtti_data;
  1524. begin
  1525. rttilist^.concat(new(pai_const,init_8bit(14)));
  1526. writename;
  1527. rttilist^.concat(new(pai_const,init_32bit(size)));
  1528. count:=0;
  1529. symtable^.foreach(count_fields);
  1530. rttilist^.concat(new(pai_const,init_32bit(count)));
  1531. symtable^.foreach(write_field_rtti);
  1532. end;
  1533. procedure trecdef.write_init_data;
  1534. begin
  1535. rttilist^.concat(new(pai_const,init_8bit(14)));
  1536. writename;
  1537. rttilist^.concat(new(pai_const,init_32bit(size)));
  1538. count:=0;
  1539. symtable^.foreach(count_inittable_fields);
  1540. rttilist^.concat(new(pai_const,init_32bit(count)));
  1541. symtable^.foreach(write_field_inittable);
  1542. end;
  1543. {***************************************************************************
  1544. TABSTRACTPROCDEF
  1545. ***************************************************************************}
  1546. constructor tabstractprocdef.init;
  1547. begin
  1548. inherited init;
  1549. para1:=nil;
  1550. fpu_used:=0;
  1551. options:=0;
  1552. retdef:=voiddef;
  1553. savesize:=Sizeof(pointer);
  1554. end;
  1555. procedure disposepdefcoll(var para1 : pdefcoll);
  1556. var
  1557. hp : pdefcoll;
  1558. begin
  1559. hp:=para1;
  1560. while assigned(hp) do
  1561. begin
  1562. para1:=hp^.next;
  1563. dispose(hp);
  1564. hp:=para1;
  1565. end;
  1566. end;
  1567. destructor tabstractprocdef.done;
  1568. begin
  1569. disposepdefcoll(para1);
  1570. inherited done;
  1571. end;
  1572. procedure tabstractprocdef.concatdef(p : pdef;vsp : tvarspez);
  1573. var
  1574. hp : pdefcoll;
  1575. begin
  1576. new(hp);
  1577. hp^.paratyp:=vsp;
  1578. hp^.data:=p;
  1579. hp^.next:=para1;
  1580. para1:=hp;
  1581. end;
  1582. { all functions returning in FPU are
  1583. assume to use 2 FPU registers
  1584. until the function implementation
  1585. is processed PM }
  1586. procedure tabstractprocdef.test_if_fpu_result;
  1587. begin
  1588. if assigned(retdef) and is_fpu(retdef) then
  1589. fpu_used:=2;
  1590. end;
  1591. procedure tabstractprocdef.deref;
  1592. var
  1593. hp : pdefcoll;
  1594. begin
  1595. inherited deref;
  1596. resolvedef(retdef);
  1597. hp:=para1;
  1598. while assigned(hp) do
  1599. begin
  1600. resolvedef(hp^.data);
  1601. hp:=hp^.next;
  1602. end;
  1603. end;
  1604. constructor tabstractprocdef.load;
  1605. var
  1606. last,hp : pdefcoll;
  1607. count,i : word;
  1608. begin
  1609. inherited load;
  1610. retdef:=readdefref;
  1611. fpu_used:=readbyte;
  1612. options:=readlong;
  1613. count:=readword;
  1614. para1:=nil;
  1615. savesize:=Sizeof(pointer);
  1616. for i:=1 to count do
  1617. begin
  1618. new(hp);
  1619. hp^.paratyp:=tvarspez(readbyte);
  1620. hp^.data:=readdefref;
  1621. hp^.next:=nil;
  1622. if para1=nil then
  1623. para1:=hp
  1624. else
  1625. last^.next:=hp;
  1626. last:=hp;
  1627. end;
  1628. end;
  1629. function tabstractprocdef.para_size : longint;
  1630. var
  1631. pdc : pdefcoll;
  1632. l : longint;
  1633. begin
  1634. l:=0;
  1635. pdc:=para1;
  1636. while assigned(pdc) do
  1637. begin
  1638. case pdc^.paratyp of
  1639. vs_value :
  1640. l:=l+pdc^.data^.size+(pdc^.data^.size mod 2);
  1641. vs_var :
  1642. l:=l+sizeof(pointer);
  1643. vs_const :
  1644. if dont_copy_const_param(pdc^.data) then
  1645. l:=l+sizeof(pointer)
  1646. else
  1647. l:=l+pdc^.data^.size+(pdc^.data^.size mod 2);
  1648. end;
  1649. pdc:=pdc^.next;
  1650. end;
  1651. para_size:=l;
  1652. end;
  1653. procedure tabstractprocdef.write;
  1654. var
  1655. count : word;
  1656. hp : pdefcoll;
  1657. begin
  1658. inherited write;
  1659. writedefref(retdef);
  1660. writebyte(fpu_used);
  1661. writelong(options);
  1662. hp:=para1;
  1663. count:=0;
  1664. while assigned(hp) do
  1665. begin
  1666. inc(count);
  1667. hp:=hp^.next;
  1668. end;
  1669. writeword(count);
  1670. hp:=para1;
  1671. while assigned(hp) do
  1672. begin
  1673. writebyte(byte(hp^.paratyp));
  1674. writedefref(hp^.data);
  1675. hp:=hp^.next;
  1676. end;
  1677. end;
  1678. function tabstractprocdef.demangled_paras : string;
  1679. var s : string;
  1680. p : pdefcoll;
  1681. begin
  1682. s:='';
  1683. p:=para1;
  1684. if assigned(p) then
  1685. begin
  1686. s:=s+'(';
  1687. while assigned(p) do
  1688. begin
  1689. if assigned(p^.data^.sym) then
  1690. s:=s+p^.data^.sym^.name
  1691. else if p^.paratyp=vs_var then
  1692. s:=s+'var'
  1693. else if p^.paratyp=vs_const then
  1694. s:=s+'const';
  1695. p:=p^.next;
  1696. if assigned(p) then
  1697. s:=s+','
  1698. else
  1699. s:=s+')';
  1700. end;
  1701. end;
  1702. demangled_paras:=s;
  1703. end;
  1704. {$ifdef GDB}
  1705. function tabstractprocdef.stabstring : pchar;
  1706. begin
  1707. stabstring := strpnew('abstractproc'+numberstring+';');
  1708. end;
  1709. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  1710. begin
  1711. if (not assigned(sym) or sym^.isusedinstab or use_dbx)
  1712. and not is_def_stab_written then
  1713. begin
  1714. if assigned(retdef) then forcestabto(asmlist,retdef);
  1715. inherited concatstabto(asmlist);
  1716. end;
  1717. end;
  1718. {$endif GDB}
  1719. {***************************************************************************
  1720. TPROCDEF
  1721. ***************************************************************************}
  1722. constructor tprocdef.init;
  1723. begin
  1724. inherited init;
  1725. deftype:=procdef;
  1726. _mangledname:=nil;
  1727. nextoverloaded:=nil;
  1728. extnumber:=-1;
  1729. localst:=new(psymtable,init(localsymtable));
  1730. parast:=new(psymtable,init(parasymtable));
  1731. { this is used by insert
  1732. to check same names in parast and localst }
  1733. localst^.next:=parast;
  1734. {$ifdef UseBrowser}
  1735. defref:=nil;
  1736. lastwritten:=nil;
  1737. refcount:=0;
  1738. if (cs_browser in aktmoduleswitches) and make_ref then
  1739. begin
  1740. defref:=new(pref,init(defref,@tokenpos));
  1741. inc(refcount);
  1742. end;
  1743. lastref:=defref;
  1744. {$endif UseBrowser}
  1745. { first, we assume, that all registers are used }
  1746. {$ifdef i386}
  1747. usedregisters:=$ff;
  1748. {$endif i386}
  1749. {$ifdef m68k}
  1750. usedregisters:=$FFFF;
  1751. {$endif}
  1752. {$ifdef alpha}
  1753. usedregisters_int:=$ffffffff;
  1754. usedregisters_fpu:=$ffffffff;
  1755. {$endif alpha}
  1756. forwarddef:=true;
  1757. _class := nil;
  1758. code:=nil;
  1759. end;
  1760. constructor tprocdef.load;
  1761. var
  1762. s : string;
  1763. begin
  1764. inherited load;
  1765. deftype:=procdef;
  1766. {$ifdef i386}
  1767. usedregisters:=readbyte;
  1768. {$endif i386}
  1769. {$ifdef m68k}
  1770. usedregisters:=readword;
  1771. {$endif}
  1772. {$ifdef alpha}
  1773. usedregisters_int:=readlong;
  1774. usedregisters_fpu:=readlong;
  1775. {$endif alpha}
  1776. s:=readstring;
  1777. setstring(_mangledname,s);
  1778. extnumber:=readlong;
  1779. nextoverloaded:=pprocdef(readdefref);
  1780. _class := pobjectdef(readdefref);
  1781. if (cs_link_deffile in aktglobalswitches) and ((options and poexports)<>0) then
  1782. deffile.AddExport(mangledname);
  1783. parast:=nil;
  1784. localst:=nil;
  1785. forwarddef:=false;
  1786. {$ifdef UseBrowser}
  1787. lastref:=nil;
  1788. lastwritten:=nil;
  1789. defref:=nil;
  1790. refcount:=0;
  1791. {$endif UseBrowser}
  1792. end;
  1793. {$ifdef UseBrowser}
  1794. procedure tprocdef.load_references;
  1795. var
  1796. pos : tfileposinfo;
  1797. move_last : boolean;
  1798. begin
  1799. move_last:=lastwritten=lastref;
  1800. while (not current_ppu^.endofentry) do
  1801. begin
  1802. readposinfo(pos);
  1803. inc(refcount);
  1804. lastref:=new(pref,init(lastref,@pos));
  1805. lastref^.is_written:=true;
  1806. if refcount=1 then
  1807. defref:=lastref;
  1808. end;
  1809. if move_last then
  1810. lastwritten:=lastref;
  1811. if (current_module^.flags and uf_local_browser)<>0 then
  1812. begin
  1813. new(parast,load);
  1814. parast^.load_browser;
  1815. new(localst,load);
  1816. localst^.load_browser;
  1817. end;
  1818. end;
  1819. function tprocdef.write_references : boolean;
  1820. var
  1821. ref : pref;
  1822. move_last : boolean;
  1823. begin
  1824. move_last:=lastwritten=lastref;
  1825. if move_last and ((current_module^.flags and uf_local_browser)=0) then
  1826. exit;
  1827. { write address of this symbol }
  1828. writedefref(@self);
  1829. { write refs }
  1830. if assigned(lastwritten) then
  1831. ref:=lastwritten
  1832. else
  1833. ref:=defref;
  1834. while assigned(ref) do
  1835. begin
  1836. if ref^.moduleindex=current_module^.unit_index then
  1837. begin
  1838. writeposinfo(ref^.posinfo);
  1839. ref^.is_written:=true;
  1840. if move_last then
  1841. lastwritten:=ref;
  1842. end
  1843. else if not ref^.is_written then
  1844. move_last:=false
  1845. else if move_last then
  1846. lastwritten:=ref;
  1847. ref:=ref^.nextref;
  1848. end;
  1849. current_ppu^.writeentry(ibdefref);
  1850. write_references:=true;
  1851. if (current_module^.flags and uf_local_browser)<>0 then
  1852. begin
  1853. { we need dummy para and local symtables
  1854. PPU files are then easier to read PM }
  1855. if not assigned(parast) then
  1856. parast:=new(psymtable,init(parasymtable));
  1857. parast^.write;
  1858. parast^.write_browser;
  1859. if not assigned(localst) then
  1860. localst:=new(psymtable,init(localsymtable));
  1861. localst^.write;
  1862. localst^.write_browser;
  1863. end;
  1864. end;
  1865. procedure tprocdef.add_to_browserlog;
  1866. begin
  1867. if assigned(defref) then
  1868. begin
  1869. Browse.AddLog('***'+mangledname);
  1870. Browse.AddLogRefs(defref);
  1871. if (current_module^.flags and uf_local_browser)<>0 then
  1872. begin
  1873. if assigned(parast) then
  1874. parast^.writebrowserlog;
  1875. if assigned(localst) then
  1876. localst^.writebrowserlog;
  1877. end;
  1878. end;
  1879. end;
  1880. {$endif UseBrowser}
  1881. destructor tprocdef.done;
  1882. begin
  1883. {$ifdef UseBrowser}
  1884. if assigned(defref) then
  1885. dispose(defref,done);
  1886. {$endif UseBrowser}
  1887. if assigned(parast) then
  1888. dispose(parast,done);
  1889. if assigned(localst) then
  1890. dispose(localst,done);
  1891. if assigned(code) and ((options and poinline) <> 0) then
  1892. disposetree(ptree(code));
  1893. if
  1894. {$ifdef tp}
  1895. not(use_big) and
  1896. {$endif}
  1897. assigned(_mangledname) then
  1898. strdispose(_mangledname);
  1899. inherited done;
  1900. end;
  1901. procedure tprocdef.write;
  1902. begin
  1903. inherited write;
  1904. {$ifdef i386}
  1905. writebyte(usedregisters);
  1906. {$endif i386}
  1907. {$ifdef m68k}
  1908. writeword(usedregisters);
  1909. {$endif}
  1910. {$ifdef alpha}
  1911. writelong(usedregisters_int);
  1912. writelong(usedregisters_fpu);
  1913. {$endif alpha}
  1914. writestring(mangledname);
  1915. writelong(extnumber);
  1916. if (options and pooperator) = 0 then
  1917. writedefref(nextoverloaded)
  1918. else
  1919. begin
  1920. { only write the overloads from the same unit }
  1921. if nextoverloaded^.owner=owner then
  1922. writedefref(nextoverloaded)
  1923. else
  1924. writedefref(nil);
  1925. end;
  1926. writedefref(_class);
  1927. if (options and poinline) <> 0 then
  1928. begin
  1929. { we need to save
  1930. - the para and the local symtable
  1931. - the code ptree !! PM
  1932. writesymtable(parast);
  1933. writesymtable(localst);
  1934. writeptree(ptree(code));
  1935. }
  1936. end;
  1937. current_ppu^.writeentry(ibprocdef);
  1938. end;
  1939. {$ifdef GDB}
  1940. procedure addparaname(p : psym);
  1941. var vs : char;
  1942. begin
  1943. if pvarsym(p)^.varspez = vs_value then vs := '1'
  1944. else vs := '0';
  1945. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.definition^.numberstring+','+vs+';');
  1946. end;
  1947. function tprocdef.stabstring : pchar;
  1948. var param : pdefcoll;
  1949. i : word;
  1950. vartyp : char;
  1951. oldrec : pchar;
  1952. begin
  1953. oldrec := stabrecstring;
  1954. getmem(StabRecString,1024);
  1955. param := para1;
  1956. i := 0;
  1957. while assigned(param) do
  1958. begin
  1959. inc(i);
  1960. param := param^.next;
  1961. end;
  1962. strpcopy(StabRecString,'f'+retdef^.numberstring);
  1963. if i>0 then
  1964. begin
  1965. strpcopy(strend(StabRecString),','+tostr(i)+';');
  1966. if assigned(parast) then
  1967. {$IfDef TP}
  1968. parast^.foreach(addparaname)
  1969. {$Else}
  1970. parast^.foreach(@addparaname)
  1971. {$EndIf}
  1972. else
  1973. begin
  1974. param := para1;
  1975. i := 0;
  1976. while assigned(param) do
  1977. begin
  1978. inc(i);
  1979. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  1980. {Here we have lost the parameter names !!}
  1981. {using lower case parameters }
  1982. strpcopy(strend(stabrecstring),'p'+tostr(i)
  1983. +':'+param^.data^.numberstring+','+vartyp+';');
  1984. param := param^.next;
  1985. end;
  1986. end;
  1987. {strpcopy(strend(StabRecString),';');}
  1988. end;
  1989. stabstring := strnew(stabrecstring);
  1990. freemem(stabrecstring,1024);
  1991. stabrecstring := oldrec;
  1992. end;
  1993. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  1994. begin
  1995. end;
  1996. {$endif GDB}
  1997. procedure tprocdef.deref;
  1998. begin
  1999. inherited deref;
  2000. resolvedef(pdef(nextoverloaded));
  2001. resolvedef(pdef(_class));
  2002. end;
  2003. function tprocdef.mangledname : string;
  2004. {$ifdef tp}
  2005. var
  2006. oldpos : longint;
  2007. s : string;
  2008. b : byte;
  2009. {$endif tp}
  2010. begin
  2011. {$ifdef tp}
  2012. if use_big then
  2013. begin
  2014. symbolstream.seek(longint(_mangledname));
  2015. symbolstream.read(b,1);
  2016. symbolstream.read(s[1],b);
  2017. s[0]:=chr(b);
  2018. mangledname:=s;
  2019. end
  2020. else
  2021. {$endif}
  2022. mangledname:=strpas(_mangledname);
  2023. end;
  2024. {$IfDef GDB}
  2025. function tprocdef.cplusplusmangledname : string;
  2026. var
  2027. s,s2 : string;
  2028. param : pdefcoll;
  2029. begin
  2030. s := sym^.name;
  2031. if _class <> nil then
  2032. begin
  2033. s2 := _class^.name^;
  2034. s := s+'__'+tostr(length(s2))+s2;
  2035. end else s := s + '_';
  2036. param := para1;
  2037. while assigned(param) do
  2038. begin
  2039. s2 := param^.data^.sym^.name;
  2040. s := s+tostr(length(s2))+s2;
  2041. param := param^.next;
  2042. end;
  2043. cplusplusmangledname:=s;
  2044. end;
  2045. {$EndIf GDB}
  2046. procedure tprocdef.setmangledname(const s : string);
  2047. begin
  2048. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  2049. strdispose(_mangledname);
  2050. setstring(_mangledname,s);
  2051. {$ifdef UseBrowser}
  2052. if assigned(parast) then
  2053. begin
  2054. stringdispose(parast^.name);
  2055. parast^.name:=stringdup('args of '+s);
  2056. end;
  2057. if assigned(localst) then
  2058. begin
  2059. stringdispose(localst^.name);
  2060. localst^.name:=stringdup('locals of '+s);
  2061. end;
  2062. {$endif UseBrowser}
  2063. end;
  2064. {***************************************************************************
  2065. TPROCVARDEF
  2066. ***************************************************************************}
  2067. constructor tprocvardef.init;
  2068. begin
  2069. inherited init;
  2070. deftype:=procvardef;
  2071. end;
  2072. constructor tprocvardef.load;
  2073. begin
  2074. inherited load;
  2075. deftype:=procvardef;
  2076. end;
  2077. procedure tprocvardef.write;
  2078. begin
  2079. { here we cannot get a real good value so just give something }
  2080. { plausible (PM) }
  2081. { a more secure way would be
  2082. to allways store in a temp }
  2083. if is_fpu(retdef) then
  2084. fpu_used:=2
  2085. else
  2086. fpu_used:=0;
  2087. inherited write;
  2088. current_ppu^.writeentry(ibprocvardef);
  2089. end;
  2090. function tprocvardef.size : longint;
  2091. begin
  2092. if (options and pomethodpointer)=0 then
  2093. size:=sizeof(pointer)
  2094. else
  2095. size:=2*sizeof(pointer);
  2096. end;
  2097. {$ifdef GDB}
  2098. function tprocvardef.stabstring : pchar;
  2099. var
  2100. nss : pchar;
  2101. i : word;
  2102. vartyp : char;
  2103. pst : pchar;
  2104. param : pdefcoll;
  2105. begin
  2106. i := 0;
  2107. param := para1;
  2108. while assigned(param) do
  2109. begin
  2110. inc(i);
  2111. param := param^.next;
  2112. end;
  2113. getmem(nss,1024);
  2114. strpcopy(nss,'f'+retdef^.numberstring+','+tostr(i)+';');
  2115. param := para1;
  2116. i := 0;
  2117. while assigned(param) do
  2118. begin
  2119. inc(i);
  2120. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2121. {Here we have lost the parameter names !!}
  2122. pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
  2123. strcat(nss,pst);
  2124. strdispose(pst);
  2125. param := param^.next;
  2126. end;
  2127. {strpcopy(strend(nss),';');}
  2128. stabstring := strnew(nss);
  2129. freemem(nss,1024);
  2130. end;
  2131. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2132. begin
  2133. if ( not assigned(sym) or sym^.isusedinstab or use_dbx)
  2134. and not is_def_stab_written then
  2135. inherited concatstabto(asmlist);
  2136. is_def_stab_written:=true;
  2137. end;
  2138. {$endif GDB}
  2139. procedure tprocvardef.write_rtti_data;
  2140. begin
  2141. {!!!!!!!}
  2142. end;
  2143. procedure tprocvardef.write_child_rtti_data;
  2144. begin
  2145. {!!!!!!!!}
  2146. end;
  2147. function tprocvardef.is_publishable : boolean;
  2148. begin
  2149. is_publishable:=(options and pomethodpointer)<>0;
  2150. end;
  2151. {***************************************************************************
  2152. TOBJECTDEF
  2153. ***************************************************************************}
  2154. {$ifdef GDB}
  2155. const
  2156. vtabletype : word = 0;
  2157. vtableassigned : boolean = false;
  2158. {$endif GDB}
  2159. constructor tobjectdef.init(const n : string;c : pobjectdef);
  2160. begin
  2161. tdef.init;
  2162. deftype:=objectdef;
  2163. childof:=c;
  2164. options:=0;
  2165. vmt_offset:=0;
  2166. { some options are inherited !! }
  2167. if assigned(c) then
  2168. options:= c^.options and
  2169. (oo_hasvirtual or oo_hasprivate or
  2170. oo_hasprotected
  2171. {or oo_can_have_published treated in pdecl }
  2172. );
  2173. { privatesyms:=new(psymtable,init(objectsymtable));
  2174. protectedsyms:=new(psymtable,init(objectsymtable)); }
  2175. publicsyms:=new(psymtable,init(objectsymtable));
  2176. publicsyms^.name := stringdup(n);
  2177. { add the data of the anchestor class }
  2178. if assigned(childof) then
  2179. begin
  2180. publicsyms^.datasize:=
  2181. publicsyms^.datasize-4+childof^.publicsyms^.datasize;
  2182. end;
  2183. name:=stringdup(n);
  2184. savesize := publicsyms^.datasize;
  2185. publicsyms^.defowner:=@self;
  2186. end;
  2187. constructor tobjectdef.load;
  2188. var
  2189. oldread_member : boolean;
  2190. begin
  2191. tdef.load;
  2192. deftype:=objectdef;
  2193. savesize:=readlong;
  2194. vmt_offset:=readlong;
  2195. name:=stringdup(readstring);
  2196. childof:=pobjectdef(readdefref);
  2197. options:=readlong;
  2198. oldread_member:=read_member;
  2199. read_member:=true;
  2200. object_options:=true;
  2201. publicsyms:=new(psymtable,loadasstruct(objectsymtable));
  2202. object_options:=false;
  2203. read_member:=oldread_member;
  2204. publicsyms^.defowner:=@self;
  2205. { publicsyms^.datasize:=savesize; }
  2206. publicsyms^.name := stringdup(name^);
  2207. { handles the predefined class tobject }
  2208. { the last TOBJECT which is loaded gets }
  2209. { it ! }
  2210. if (name^='TOBJECT') and not(cs_compilesystem in aktmoduleswitches) and
  2211. isclass and (childof=pointer($ffffffff)) then
  2212. class_tobject:=@self;
  2213. end;
  2214. procedure tobjectdef.check_forwards;
  2215. begin
  2216. publicsyms^.check_forwards;
  2217. if (options and oo_isforward)<>0 then
  2218. begin
  2219. { ok, in future, the forward can be resolved }
  2220. Message1(sym_e_class_forward_not_resolved,name^);
  2221. options:=options and not(oo_isforward);
  2222. end;
  2223. end;
  2224. destructor tobjectdef.done;
  2225. begin
  2226. {!!!!
  2227. if assigned(privatesyms) then
  2228. dispose(privatesyms,done);
  2229. if assigned(protectedsyms) then
  2230. dispose(protectedsyms,done); }
  2231. if assigned(publicsyms) then
  2232. dispose(publicsyms,done);
  2233. if (options and oo_isforward)<>0 then
  2234. Message1(sym_e_class_forward_not_resolved,name^);
  2235. stringdispose(name);
  2236. tdef.done;
  2237. end;
  2238. { true, if self inherits from d (or if they are equal) }
  2239. function tobjectdef.isrelated(d : pobjectdef) : boolean;
  2240. var
  2241. hp : pobjectdef;
  2242. begin
  2243. hp:=@self;
  2244. while assigned(hp) do
  2245. begin
  2246. if hp=d then
  2247. begin
  2248. isrelated:=true;
  2249. exit;
  2250. end;
  2251. hp:=hp^.childof;
  2252. end;
  2253. isrelated:=false;
  2254. end;
  2255. function tobjectdef.size : longint;
  2256. begin
  2257. if (options and oois_class)<>0 then
  2258. size:=sizeof(pointer)
  2259. else
  2260. size:=publicsyms^.datasize;
  2261. end;
  2262. procedure tobjectdef.deref;
  2263. var
  2264. hp : pdef;
  2265. oldrecsyms : psymtable;
  2266. begin
  2267. resolvedef(pdef(childof));
  2268. oldrecsyms:=aktrecordsymtable;
  2269. aktrecordsymtable:=publicsyms;
  2270. { nun die Definitionen dereferenzieren }
  2271. hp:=publicsyms^.rootdef;
  2272. while assigned(hp) do
  2273. begin
  2274. hp^.deref;
  2275. { set owner }
  2276. hp^.owner:=publicsyms;
  2277. hp:=hp^.next;
  2278. end;
  2279. {$ifdef tp}
  2280. publicsyms^.foreach(derefsym);
  2281. {$else}
  2282. publicsyms^.foreach(@derefsym);
  2283. {$endif}
  2284. aktrecordsymtable:=oldrecsyms;
  2285. end;
  2286. function tobjectdef.vmt_mangledname : string;
  2287. {DM: I get a nil pointer on the owner name. I don't know if this
  2288. mayhappen, and I have therefore fixed the problem by doing nil pointer
  2289. checks.}
  2290. var
  2291. s1,s2:string;
  2292. begin
  2293. if owner^.name=nil then
  2294. s1:=''
  2295. else
  2296. s1:=owner^.name^;
  2297. if name=nil then
  2298. s2:=''
  2299. else
  2300. s2:=name^;
  2301. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  2302. end;
  2303. function tobjectdef.rtti_name : string;
  2304. var
  2305. s1,s2:string;
  2306. begin
  2307. if owner^.name=nil then
  2308. s1:=''
  2309. else
  2310. s1:=owner^.name^;
  2311. if name=nil then
  2312. s2:=''
  2313. else
  2314. s2:=name^;
  2315. rtti_name:='RTTI_'+s1+'$_'+s2;
  2316. end;
  2317. function tobjectdef.isclass : boolean;
  2318. begin
  2319. isclass:=(options and oois_class)<>0;
  2320. end;
  2321. procedure tobjectdef.write;
  2322. var
  2323. oldread_member : boolean;
  2324. begin
  2325. tdef.write;
  2326. writelong(size);
  2327. writelong(vmt_offset);
  2328. writestring(name^);
  2329. writedefref(childof);
  2330. writelong(options);
  2331. current_ppu^.writeentry(ibobjectdef);
  2332. oldread_member:=read_member;
  2333. read_member:=true;
  2334. object_options:=true;
  2335. publicsyms^.writeasstruct;
  2336. object_options:=false;
  2337. read_member:=oldread_member;
  2338. end;
  2339. {$ifdef GDB}
  2340. procedure addprocname(p :psym);
  2341. var virtualind,argnames : string;
  2342. news, newrec : pchar;
  2343. pd,ipd : pprocdef;
  2344. lindex : longint;
  2345. para : pdefcoll;
  2346. arglength : byte;
  2347. sp : char;
  2348. begin
  2349. If p^.typ = procsym then
  2350. begin
  2351. pd := pprocsym(p)^.definition;
  2352. { this will be used for full implementation of object stabs
  2353. not yet done }
  2354. ipd := pd;
  2355. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2356. if (pd^.options and povirtualmethod) <> 0 then
  2357. begin
  2358. lindex := pd^.extnumber;
  2359. {doesnt seem to be necessary
  2360. lindex := lindex or $80000000;}
  2361. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2362. end else virtualind := '.';
  2363. { arguments are not listed here }
  2364. {we don't need another definition}
  2365. para := pd^.para1;
  2366. argnames := '';
  2367. while assigned(para) do
  2368. begin
  2369. if para^.data^.deftype = formaldef then
  2370. begin
  2371. if para^.paratyp=vs_var then
  2372. argnames := argnames+'3var'
  2373. else if para^.paratyp=vs_const then
  2374. argnames:=argnames+'5const';
  2375. end
  2376. else
  2377. begin
  2378. { if the arg definition is like (v: ^byte;..
  2379. there is no sym attached to data !!! }
  2380. if assigned(para^.data^.sym) then
  2381. begin
  2382. arglength := length(para^.data^.sym^.name);
  2383. argnames := argnames + tostr(arglength)+para^.data^.sym^.name;
  2384. end
  2385. else
  2386. begin
  2387. argnames:=argnames+'11unnamedtype';
  2388. end;
  2389. end;
  2390. para := para^.next;
  2391. end;
  2392. ipd^.is_def_stab_written := true;
  2393. { here 2A must be changed for private and protected }
  2394. { 0 is private 1 protected and 2 public }
  2395. if (p^.properties and sp_private)<>0 then sp:='0'
  2396. else if (p^.properties and sp_protected)<>0 then sp:='1'
  2397. else sp:='2';
  2398. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  2399. +'=##'+pd^.retdef^.numberstring+';:'+argnames+';'+sp+'A'
  2400. +virtualind+';');
  2401. { get spare place for a string at the end }
  2402. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2403. begin
  2404. getmem(news,stabrecsize+memsizeinc);
  2405. strcopy(news,stabrecstring);
  2406. freemem(stabrecstring,stabrecsize);
  2407. stabrecsize:=stabrecsize+memsizeinc;
  2408. stabrecstring:=news;
  2409. end;
  2410. strcat(StabRecstring,newrec);
  2411. {freemem(newrec,memsizeinc); }
  2412. strdispose(newrec);
  2413. {This should be used for case !!}
  2414. RecOffset := RecOffset + pd^.size;
  2415. end;
  2416. end;
  2417. function tobjectdef.stabstring : pchar;
  2418. var anc : pobjectdef;
  2419. oldrec : pchar;
  2420. oldrecsize : longint;
  2421. str_end : string;
  2422. begin
  2423. oldrec := stabrecstring;
  2424. oldrecsize:=stabrecsize;
  2425. stabrecsize:=memsizeinc;
  2426. GetMem(stabrecstring,stabrecsize);
  2427. strpcopy(stabRecString,'s'+tostr(size));
  2428. if assigned(childof) then
  2429. {only one ancestor not virtual, public, at base offset 0 }
  2430. { !1 , 0 2 0 , }
  2431. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  2432. {virtual table to implement yet}
  2433. RecOffset := 0;
  2434. {$ifdef tp}
  2435. publicsyms^.foreach(addname);
  2436. {$else}
  2437. publicsyms^.foreach(@addname);
  2438. {$endif tp}
  2439. if (options and oo_hasvirtual) <> 0 then
  2440. if not assigned(childof) or ((childof^.options and oo_hasvirtual) = 0) then
  2441. begin
  2442. str_end:='$vf'+numberstring+':'+typeglobalnumber('vtblarray')+',0;';
  2443. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')+',0;');
  2444. end;
  2445. {$ifdef tp}
  2446. publicsyms^.foreach(addprocname);
  2447. {$else}
  2448. publicsyms^.foreach(@addprocname);
  2449. {$endif tp }
  2450. if (options and oo_hasvirtual) <> 0 then
  2451. begin
  2452. anc := @self;
  2453. while assigned(anc^.childof) and ((anc^.childof^.options and oo_hasvirtual) <> 0) do
  2454. anc := anc^.childof;
  2455. str_end:=';~%'+anc^.numberstring+';';
  2456. end
  2457. else
  2458. str_end:=';';
  2459. strpcopy(strend(stabrecstring),str_end);
  2460. stabstring := strnew(StabRecString);
  2461. freemem(stabrecstring,stabrecsize);
  2462. stabrecstring := oldrec;
  2463. stabrecsize:=oldrecsize;
  2464. end;
  2465. {$endif GDB}
  2466. procedure tobjectdef.write_child_init_data;
  2467. begin
  2468. end;
  2469. procedure tobjectdef.write_init_data;
  2470. begin
  2471. if isclass then
  2472. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2473. else
  2474. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2475. { generate the name }
  2476. rttilist^.concat(new(pai_const,init_8bit(length(name^))));
  2477. rttilist^.concat(new(pai_string,init(name^)));
  2478. rttilist^.concat(new(pai_const,init_32bit(size)));
  2479. count:=0;
  2480. publicsyms^.foreach(count_inittable_fields);
  2481. rttilist^.concat(new(pai_const,init_32bit(count)));
  2482. publicsyms^.foreach(write_field_inittable);
  2483. end;
  2484. function tobjectdef.needs_inittable : boolean;
  2485. var
  2486. oldb : boolean;
  2487. begin
  2488. { there are recursive calls to needs_inittable possible, }
  2489. { so we have to change to old value how else should }
  2490. { we do that ? check_rec_rtti can't be a nested }
  2491. { procedure of needs_rtti ! }
  2492. oldb:=binittable;
  2493. binittable:=false;
  2494. publicsyms^.foreach(check_rec_inittable);
  2495. needs_inittable:=binittable;
  2496. binittable:=oldb;
  2497. end;
  2498. procedure count_published_properties(sym : psym);{$ifndef fpc}far;{$endif}
  2499. begin
  2500. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2501. inc(count);
  2502. end;
  2503. procedure write_property_info(sym : psym);{$ifndef fpc}far;{$endif}
  2504. var
  2505. proctypesinfo : byte;
  2506. procedure writeproc(sym : psym;def : pdef;shiftvalue : byte);
  2507. var
  2508. typvalue : byte;
  2509. begin
  2510. if not(assigned(sym)) then
  2511. begin
  2512. rttilist^.concat(new(pai_const,init_32bit(1)));
  2513. typvalue:=3;
  2514. end
  2515. else if sym^.typ=varsym then
  2516. begin
  2517. rttilist^.concat(new(pai_const,init_32bit(
  2518. pvarsym(sym)^.address)));
  2519. typvalue:=0;
  2520. end
  2521. else
  2522. begin
  2523. if (pprocdef(def)^.options and povirtualmethod)=0 then
  2524. begin
  2525. rttilist^.concat(new(pai_const,init_symbol(strpnew(pprocdef(def)^.mangledname))));
  2526. typvalue:=1;
  2527. end
  2528. else
  2529. begin
  2530. { virtual method, write vmt offset }
  2531. rttilist^.concat(new(pai_const,init_32bit(pprocdef(def)^.extnumber*4+12)));
  2532. typvalue:=2;
  2533. end;
  2534. end;
  2535. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  2536. end;
  2537. begin
  2538. if (ppropertysym(sym)^.options and ppo_indexed)<>0 then
  2539. proctypesinfo:=$40
  2540. else
  2541. proctypesinfo:=0;
  2542. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2543. begin
  2544. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(ppropertysym(sym)^.proptype^.get_rtti_label)))));
  2545. writeproc(ppropertysym(sym)^.readaccesssym,ppropertysym(sym)^.readaccessdef,0);
  2546. writeproc(ppropertysym(sym)^.writeaccesssym,ppropertysym(sym)^.writeaccessdef,2);
  2547. { isn't it stored ? }
  2548. if (ppropertysym(sym)^.options and ppo_stored)=0 then
  2549. begin
  2550. rttilist^.concat(new(pai_const,init_32bit(1)));
  2551. proctypesinfo:=proctypesinfo or (3 shl 4);
  2552. end
  2553. else
  2554. writeproc(ppropertysym(sym)^.storedsym,ppropertysym(sym)^.storeddef,4);
  2555. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.index)));
  2556. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.default)));
  2557. rttilist^.concat(new(pai_const,init_16bit(count)));
  2558. inc(count);
  2559. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  2560. rttilist^.concat(new(pai_const,init_8bit(length(ppropertysym(sym)^.name))));
  2561. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  2562. end;
  2563. end;
  2564. procedure generate_published_child_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  2565. begin
  2566. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2567. ppropertysym(sym)^.proptype^.get_rtti_label;
  2568. end;
  2569. procedure tobjectdef.write_child_rtti_data;
  2570. begin
  2571. publicsyms^.foreach(generate_published_child_rtti);
  2572. end;
  2573. procedure tobjectdef.generate_rtti;
  2574. begin
  2575. has_rtti:=true;
  2576. getlabel(rtti_label);
  2577. write_child_rtti_data;
  2578. rttilist^.concat(new(pai_symbol,init_global(rtti_name)));
  2579. rttilist^.concat(new(pai_label,init(rtti_label)));
  2580. write_rtti_data;
  2581. end;
  2582. function tobjectdef.next_free_name_index : longint;
  2583. var
  2584. i : longint;
  2585. begin
  2586. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2587. i:=childof^.next_free_name_index
  2588. else
  2589. i:=0;
  2590. count:=0;
  2591. publicsyms^.foreach(count_published_properties);
  2592. next_free_name_index:=i+count;
  2593. end;
  2594. procedure tobjectdef.write_rtti_data;
  2595. begin
  2596. if isclass then
  2597. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2598. else
  2599. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2600. { generate the name }
  2601. rttilist^.concat(new(pai_const,init_8bit(length(name^))));
  2602. rttilist^.concat(new(pai_string,init(name^)));
  2603. { write class type }
  2604. rttilist^.concat(new(pai_const,init_symbol(strpnew(vmt_mangledname))));
  2605. { write owner typeinfo }
  2606. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2607. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(childof^.get_rtti_label)))))
  2608. else
  2609. rttilist^.concat(new(pai_const,init_32bit(0)));
  2610. { write published properties count }
  2611. count:=0;
  2612. publicsyms^.foreach(count_published_properties);
  2613. rttilist^.concat(new(pai_const,init_16bit(count)));
  2614. { write unit name }
  2615. if assigned(owner^.name) then
  2616. begin
  2617. rttilist^.concat(new(pai_const,init_8bit(length(owner^.name^))));
  2618. rttilist^.concat(new(pai_string,init(owner^.name^)));
  2619. end
  2620. else
  2621. rttilist^.concat(new(pai_const,init_8bit(0)));
  2622. { count is used to write nameindex }
  2623. { but we need an offset of the owner }
  2624. { to give each property an own slot }
  2625. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2626. count:=childof^.next_free_name_index
  2627. else
  2628. count:=0;
  2629. publicsyms^.foreach(write_property_info);
  2630. end;
  2631. function tobjectdef.is_publishable : boolean;
  2632. begin
  2633. is_publishable:=isclass;
  2634. end;
  2635. {****************************************************************************
  2636. TERRORDEF
  2637. ****************************************************************************}
  2638. constructor terrordef.init;
  2639. begin
  2640. inherited init;
  2641. deftype:=errordef;
  2642. end;
  2643. {$ifdef GDB}
  2644. function terrordef.stabstring : pchar;
  2645. begin
  2646. stabstring:=strpnew('error'+numberstring);
  2647. end;
  2648. {$endif GDB}
  2649. {
  2650. $Log$
  2651. Revision 1.57 1998-10-14 15:54:20 pierre
  2652. * smallsets are not entirely implemented for
  2653. m68k added a ifdef usesmallset
  2654. that is allways defined for i386
  2655. (enables testing for m68k)
  2656. Revision 1.56 1998/10/09 11:47:56 pierre
  2657. * still more memory leaks fixes !!
  2658. Revision 1.55 1998/10/06 17:16:55 pierre
  2659. * some memory leaks fixed (thanks to Peter for heaptrc !)
  2660. Revision 1.54 1998/10/05 21:33:28 peter
  2661. * fixed 161,165,166,167,168
  2662. Revision 1.53 1998/10/05 12:48:39 pierre
  2663. * wrong handling of range check for arrays fixed
  2664. Revision 1.52 1998/10/02 07:20:38 florian
  2665. * range checking in units doesn't work if the units are smartlinked, fixed
  2666. Revision 1.51 1998/09/25 12:01:41 florian
  2667. * tobjectdef.publicsyms.datasize was set to savesize, this is wrong now
  2668. because the symtable size is read from the ppu file
  2669. Revision 1.50 1998/09/23 15:46:40 florian
  2670. * problem with with and classes fixed
  2671. Revision 1.49 1998/09/23 12:03:55 peter
  2672. * overloading fix for array of const
  2673. Revision 1.48 1998/09/22 15:37:23 peter
  2674. + array of const start
  2675. Revision 1.47 1998/09/21 15:46:01 michael
  2676. Applied florians fix for check_rec_inittable
  2677. Revision 1.46 1998/09/21 08:45:21 pierre
  2678. + added vmt_offset in tobjectdef.write for fututre use
  2679. (first steps to have objects without vmt if no virtual !!)
  2680. + added fpu_used field for tabstractprocdef :
  2681. sets this level to 2 if the functions return with value in FPU
  2682. (is then set to correct value at parsing of implementation)
  2683. THIS MIGHT refuse some code with FPU expression too complex
  2684. that were accepted before and even in some cases
  2685. that don't overflow in fact
  2686. ( like if f : float; is a forward that finally in implementation
  2687. only uses one fpu register !!)
  2688. Nevertheless I think that it will improve security on
  2689. FPU operations !!
  2690. * most other changes only for UseBrowser code
  2691. (added symtable references for record and objects)
  2692. local switch for refs to args and local of each function
  2693. (static symtable still missing)
  2694. UseBrowser still not stable and probably broken by
  2695. the definition hash array !!
  2696. Revision 1.45 1998/09/20 08:31:29 florian
  2697. + bit 6 of tpropinfo.propprocs is set, if the property contains a
  2698. constant index
  2699. Revision 1.44 1998/09/19 15:23:58 florian
  2700. * rtti for ordtypes corrected
  2701. Revision 1.43 1998/09/18 17:12:40 florian
  2702. * problem with writing of class references fixed
  2703. Revision 1.42 1998/09/17 13:41:20 pierre
  2704. sizeof(TPOINT) problem
  2705. Revision 1.40.2.2 1998/09/17 08:42:33 pierre
  2706. TPOINT sizeof fix
  2707. Revision 1.41 1998/09/15 17:39:30 jonas
  2708. + bugfix from bugfix branch
  2709. Revision 1.40.2.1 1998/09/15 17:35:32 jonas
  2710. * chenged string_typ in tstringdef.wideload from ansistring to widestring
  2711. Revision 1.40 1998/09/09 15:34:00 peter
  2712. * removed warnings
  2713. Revision 1.39 1998/09/08 10:23:44 pierre
  2714. * name field of filedef corrected
  2715. Revision 1.38 1998/09/07 23:10:23 florian
  2716. * a lot of stuff fixed regarding rtti and publishing of properties,
  2717. basics should now work
  2718. Revision 1.37 1998/09/07 19:33:24 florian
  2719. + some stuff for property rtti added:
  2720. - NameIndex of the TPropInfo record is now written correctly
  2721. - the DEFAULT/NODEFAULT keyword is supported now
  2722. - the default value and the storedsym/def are now written to
  2723. the PPU fiel
  2724. Revision 1.36 1998/09/07 17:37:01 florian
  2725. * first fixes for published properties
  2726. Revision 1.35 1998/09/06 22:42:02 florian
  2727. + rtti genreation for properties added
  2728. Revision 1.34 1998/09/04 18:15:02 peter
  2729. * filedef updated
  2730. Revision 1.33 1998/09/03 17:08:49 pierre
  2731. * better lines for stabs
  2732. (no scroll back to if before else part
  2733. no return to case line at jump outside case)
  2734. + source lines also if not in order
  2735. Revision 1.32 1998/09/03 16:03:20 florian
  2736. + rtti generation
  2737. * init table generation changed
  2738. Revision 1.31 1998/09/02 15:14:28 peter
  2739. * enum packing changed from len to max
  2740. Revision 1.30 1998/09/01 17:37:29 peter
  2741. * removed debug writeln :(
  2742. Revision 1.29 1998/09/01 12:53:25 peter
  2743. + aktpackenum
  2744. Revision 1.28 1998/09/01 07:54:22 pierre
  2745. * UseBrowser a little updated (might still be buggy !!)
  2746. * bug in psub.pas in function specifier removed
  2747. * stdcall allowed in interface and in implementation
  2748. (FPC will not yet complain if it is missing in either part
  2749. because stdcall is only a dummy !!)
  2750. Revision 1.27 1998/08/28 12:51:43 florian
  2751. + ansistring to pchar type cast fixed
  2752. Revision 1.26 1998/08/25 12:42:44 pierre
  2753. * CDECL changed to CVAR for variables
  2754. specifications are read in structures also
  2755. + started adding GPC compatibility mode ( option -Sp)
  2756. * names changed to lowercase
  2757. Revision 1.25 1998/08/23 21:04:38 florian
  2758. + rtti generation for classes added
  2759. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  2760. Revision 1.24 1998/08/20 12:53:26 peter
  2761. * object_options are always written for object syms
  2762. Revision 1.23 1998/08/19 00:42:42 peter
  2763. + subrange types for enums
  2764. + checking for bounds type with ranges
  2765. Revision 1.22 1998/08/17 10:10:10 peter
  2766. - removed OLDPPU
  2767. Revision 1.21 1998/08/10 14:50:28 peter
  2768. + localswitches, moduleswitches, globalswitches splitting
  2769. Revision 1.20 1998/07/18 22:54:30 florian
  2770. * some ansi/wide/longstring support fixed:
  2771. o parameter passing
  2772. o returning as result from functions
  2773. Revision 1.19 1998/07/14 14:47:05 peter
  2774. * released NEWINPUT
  2775. Revision 1.18 1998/07/10 10:51:04 peter
  2776. * m68k updates
  2777. Revision 1.16 1998/07/07 11:20:13 peter
  2778. + NEWINPUT for a better inputfile and scanner object
  2779. Revision 1.15 1998/06/24 14:48:37 peter
  2780. * ifdef newppu -> ifndef oldppu
  2781. Revision 1.14 1998/06/16 08:56:31 peter
  2782. + targetcpu
  2783. * cleaner pmodules for newppu
  2784. Revision 1.13 1998/06/15 15:38:09 pierre
  2785. * small bug in systems.pas corrected
  2786. + operators in different units better hanlded
  2787. Revision 1.12 1998/06/15 14:30:12 daniel
  2788. * Reverted my changes.
  2789. Revision 1.10 1998/06/13 00:10:16 peter
  2790. * working browser and newppu
  2791. * some small fixes against crashes which occured in bp7 (but not in
  2792. fpc?!)
  2793. Revision 1.9 1998/06/12 14:10:37 michael
  2794. * Fixed wrong code for ansistring
  2795. Revision 1.8 1998/06/11 10:11:58 peter
  2796. * -gb works again
  2797. Revision 1.7 1998/06/07 15:30:25 florian
  2798. + first working rtti
  2799. + data init/final. for local variables
  2800. Revision 1.6 1998/06/05 14:37:37 pierre
  2801. * fixes for inline for operators
  2802. * inline procedure more correctly restricted
  2803. Revision 1.5 1998/06/04 23:52:01 peter
  2804. * m68k compiles
  2805. + .def file creation moved to gendef.pas so it could also be used
  2806. for win32
  2807. Revision 1.4 1998/06/04 09:55:45 pierre
  2808. * demangled name of procsym reworked to become independant of the mangling
  2809. scheme
  2810. Revision 1.3 1998/06/03 22:49:03 peter
  2811. + wordbool,longbool
  2812. * rename bis,von -> high,low
  2813. * moved some systemunit loading/creating to psystem.pas
  2814. Revision 1.2 1998/05/31 14:13:37 peter
  2815. * fixed call bugs with assembler readers
  2816. + OPR_SYMBOL to hold a symbol in the asm parser
  2817. * fixed staticsymtable vars which were acessed through %ebp instead of
  2818. name
  2819. Revision 1.1 1998/05/27 19:45:09 peter
  2820. * symtable.pas splitted into includefiles
  2821. * symtable adapted for $ifndef OLDPPU
  2822. }