symdef.inc 99 KB

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