symdef.inc 89 KB

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