symdef.inc 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550
  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 (cs_gdb_dbx in aktglobalswitches) 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 (cs_gdb_dbx in aktglobalswitches))
  263. and not is_def_stab_written then
  264. begin
  265. If cs_gdb_dbx in aktglobalswitches 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 (cs_gdb_dbx in aktglobalswitches)) and
  1001. not is_def_stab_written then
  1002. begin
  1003. if assigned(typed_as) then forcestabto(asmlist,typed_as);
  1004. inherited concatstabto(asmlist);
  1005. end;
  1006. end;
  1007. {$endif GDB}
  1008. {****************************************************************************
  1009. TPOINTERDEF
  1010. ****************************************************************************}
  1011. constructor tpointerdef.init(def : pdef);
  1012. begin
  1013. inherited init;
  1014. deftype:=pointerdef;
  1015. definition:=def;
  1016. savesize:=target_os.size_of_pointer;
  1017. end;
  1018. constructor tpointerdef.load;
  1019. begin
  1020. inherited load;
  1021. deftype:=pointerdef;
  1022. { the real address in memory is calculated later (deref) }
  1023. definition:=readdefref;
  1024. savesize:=target_os.size_of_pointer;
  1025. end;
  1026. procedure tpointerdef.deref;
  1027. begin
  1028. resolvedef(definition);
  1029. end;
  1030. procedure tpointerdef.write;
  1031. begin
  1032. inherited write;
  1033. writedefref(definition);
  1034. current_ppu^.writeentry(ibpointerdef);
  1035. end;
  1036. {$ifdef GDB}
  1037. function tpointerdef.stabstring : pchar;
  1038. begin
  1039. stabstring := strpnew('*'+definition^.numberstring);
  1040. end;
  1041. procedure tpointerdef.concatstabto(asmlist : paasmoutput);
  1042. var st,nb : string;
  1043. sym_line_no : longint;
  1044. begin
  1045. if ( (sym=nil) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1046. not is_def_stab_written then
  1047. begin
  1048. if assigned(definition) then
  1049. if definition^.deftype in [recorddef,objectdef] then
  1050. begin
  1051. is_def_stab_written := true;
  1052. {to avoid infinite recursion in record with next-like fields }
  1053. nb := definition^.numberstring;
  1054. is_def_stab_written := false;
  1055. if not definition^.is_def_stab_written then
  1056. begin
  1057. if assigned(definition^.sym) then
  1058. begin
  1059. if assigned(sym) then
  1060. begin
  1061. st := sym^.name;
  1062. sym_line_no:=sym^.fileinfo.line;
  1063. end
  1064. else
  1065. begin
  1066. st := ' ';
  1067. sym_line_no:=0;
  1068. end;
  1069. st := '"'+st+':t'+numberstring+'=*'+definition^.numberstring
  1070. +'=xs'+definition^.sym^.name+':",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0';
  1071. if asmlist = debuglist then do_count_dbx := true;
  1072. asmlist^.concat(new(pai_stabs,init(strpnew(st))));
  1073. end;
  1074. end else inherited concatstabto(asmlist);
  1075. is_def_stab_written := true;
  1076. end else
  1077. begin
  1078. forcestabto(asmlist,definition);
  1079. inherited concatstabto(asmlist);
  1080. end;
  1081. end;
  1082. end;
  1083. {$endif GDB}
  1084. {****************************************************************************
  1085. TCLASSREFDEF
  1086. ****************************************************************************}
  1087. constructor tclassrefdef.init(def : pdef);
  1088. begin
  1089. inherited init(def);
  1090. deftype:=classrefdef;
  1091. definition:=def;
  1092. savesize:=target_os.size_of_pointer;
  1093. end;
  1094. constructor tclassrefdef.load;
  1095. begin
  1096. inherited load;
  1097. deftype:=classrefdef;
  1098. end;
  1099. procedure tclassrefdef.write;
  1100. begin
  1101. { be careful, tclassdefref inherits from tpointerdef }
  1102. tdef.write;
  1103. writedefref(definition);
  1104. current_ppu^.writeentry(ibclassrefdef);
  1105. end;
  1106. {$ifdef GDB}
  1107. function tclassrefdef.stabstring : pchar;
  1108. begin
  1109. stabstring:=strpnew('');
  1110. end;
  1111. procedure tclassrefdef.concatstabto(asmlist : paasmoutput);
  1112. begin
  1113. end;
  1114. {$endif GDB}
  1115. {***************************************************************************
  1116. TSETDEF
  1117. ***************************************************************************}
  1118. { For i386 smallsets work,
  1119. for m68k there are problems
  1120. can be test by compiling with -dusesmallset PM }
  1121. {$ifdef i386}
  1122. {$define usesmallset}
  1123. {$endif i386}
  1124. constructor tsetdef.init(s : pdef;high : longint);
  1125. begin
  1126. inherited init;
  1127. deftype:=setdef;
  1128. setof:=s;
  1129. {$ifdef usesmallset}
  1130. { small sets only working for i386 PM }
  1131. if high<32 then
  1132. begin
  1133. settype:=smallset;
  1134. savesize:=Sizeof(longint);
  1135. end
  1136. else
  1137. {$endif usesmallset}
  1138. if high<256 then
  1139. begin
  1140. settype:=normset;
  1141. savesize:=32;
  1142. end
  1143. else
  1144. {$ifdef testvarsets}
  1145. if high<$10000 then
  1146. begin
  1147. settype:=varset;
  1148. savesize:=4*((high+31) div 32);
  1149. end
  1150. else
  1151. {$endif testvarsets}
  1152. Message(sym_e_ill_type_decl_set);
  1153. end;
  1154. constructor tsetdef.load;
  1155. begin
  1156. inherited load;
  1157. deftype:=setdef;
  1158. setof:=readdefref;
  1159. settype:=tsettype(readbyte);
  1160. case settype of
  1161. normset : savesize:=32;
  1162. varset : savesize:=readlong;
  1163. smallset : savesize:=Sizeof(longint);
  1164. end;
  1165. end;
  1166. procedure tsetdef.write;
  1167. begin
  1168. inherited write;
  1169. writedefref(setof);
  1170. writebyte(byte(settype));
  1171. if settype=varset then
  1172. writelong(savesize);
  1173. current_ppu^.writeentry(ibsetdef);
  1174. end;
  1175. {$ifdef GDB}
  1176. function tsetdef.stabstring : pchar;
  1177. begin
  1178. stabstring := strpnew('S'+setof^.numberstring);
  1179. end;
  1180. procedure tsetdef.concatstabto(asmlist : paasmoutput);
  1181. begin
  1182. if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1183. not is_def_stab_written then
  1184. begin
  1185. if assigned(setof) then
  1186. forcestabto(asmlist,setof);
  1187. inherited concatstabto(asmlist);
  1188. end;
  1189. end;
  1190. {$endif GDB}
  1191. procedure tsetdef.deref;
  1192. begin
  1193. resolvedef(setof);
  1194. end;
  1195. procedure tsetdef.write_rtti_data;
  1196. begin
  1197. rttilist^.concat(new(pai_const,init_8bit(tkSet)));
  1198. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  1199. rttilist^.concat(new(pai_const,init_symbol(strpnew(setof^.get_rtti_label))));
  1200. end;
  1201. procedure tsetdef.write_child_rtti_data;
  1202. begin
  1203. setof^.get_rtti_label;
  1204. end;
  1205. function tsetdef.is_publishable : boolean;
  1206. begin
  1207. is_publishable:=settype=smallset;
  1208. end;
  1209. {***************************************************************************
  1210. TFORMALDEF
  1211. ***************************************************************************}
  1212. constructor tformaldef.init;
  1213. begin
  1214. inherited init;
  1215. deftype:=formaldef;
  1216. savesize:=target_os.size_of_pointer;
  1217. end;
  1218. constructor tformaldef.load;
  1219. begin
  1220. inherited load;
  1221. deftype:=formaldef;
  1222. savesize:=target_os.size_of_pointer;
  1223. end;
  1224. procedure tformaldef.write;
  1225. begin
  1226. inherited write;
  1227. current_ppu^.writeentry(ibformaldef);
  1228. end;
  1229. {$ifdef GDB}
  1230. function tformaldef.stabstring : pchar;
  1231. begin
  1232. stabstring := strpnew('formal'+numberstring+';');
  1233. end;
  1234. procedure tformaldef.concatstabto(asmlist : paasmoutput);
  1235. begin
  1236. { formaldef can't be stab'ed !}
  1237. end;
  1238. {$endif GDB}
  1239. {***************************************************************************
  1240. TARRAYDEF
  1241. ***************************************************************************}
  1242. constructor tarraydef.init(l,h : longint;rd : pdef);
  1243. begin
  1244. inherited init;
  1245. deftype:=arraydef;
  1246. lowrange:=l;
  1247. highrange:=h;
  1248. rangedef:=rd;
  1249. definition:=nil;
  1250. IsVariant:=false;
  1251. IsConstructor:=false;
  1252. IsArrayOfConst:=false;
  1253. rangenr:=0;
  1254. end;
  1255. constructor tarraydef.load;
  1256. begin
  1257. inherited load;
  1258. deftype:=arraydef;
  1259. { the addresses are calculated later }
  1260. definition:=readdefref;
  1261. rangedef:=readdefref;
  1262. lowrange:=readlong;
  1263. highrange:=readlong;
  1264. IsArrayOfConst:=boolean(readbyte);
  1265. IsVariant:=false;
  1266. IsConstructor:=false;
  1267. rangenr:=0;
  1268. end;
  1269. function tarraydef.getrangecheckstring : string;
  1270. begin
  1271. if (cs_smartlink in aktmoduleswitches) then
  1272. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1273. else
  1274. getrangecheckstring:='R_'+tostr(rangenr);
  1275. end;
  1276. procedure tarraydef.genrangecheck;
  1277. begin
  1278. if rangenr=0 then
  1279. begin
  1280. { generates the data for range checking }
  1281. getlabelnr(rangenr);
  1282. if (cs_smartlink in aktmoduleswitches) then
  1283. datasegment^.concat(new(pai_symbol,init_global(getrangecheckstring)))
  1284. else
  1285. datasegment^.concat(new(pai_symbol,init(getrangecheckstring)));
  1286. datasegment^.concat(new(pai_const,init_32bit(lowrange)));
  1287. datasegment^.concat(new(pai_const,init_32bit(highrange)));
  1288. end;
  1289. end;
  1290. procedure tarraydef.deref;
  1291. begin
  1292. resolvedef(definition);
  1293. resolvedef(rangedef);
  1294. end;
  1295. procedure tarraydef.write;
  1296. begin
  1297. inherited write;
  1298. writedefref(definition);
  1299. writedefref(rangedef);
  1300. writelong(lowrange);
  1301. writelong(highrange);
  1302. writebyte(byte(IsArrayOfConst));
  1303. current_ppu^.writeentry(ibarraydef);
  1304. end;
  1305. {$ifdef GDB}
  1306. function tarraydef.stabstring : pchar;
  1307. begin
  1308. stabstring := strpnew('ar'+rangedef^.numberstring+';'
  1309. +tostr(lowrange)+';'+tostr(highrange)+';'+definition^.numberstring);
  1310. end;
  1311. procedure tarraydef.concatstabto(asmlist : paasmoutput);
  1312. begin
  1313. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  1314. and not is_def_stab_written then
  1315. begin
  1316. {when array are inserted they have no definition yet !!}
  1317. if assigned(definition) then
  1318. inherited concatstabto(asmlist);
  1319. end;
  1320. end;
  1321. {$endif GDB}
  1322. function tarraydef.elesize : longint;
  1323. begin
  1324. elesize:=definition^.size;
  1325. end;
  1326. function tarraydef.size : longint;
  1327. begin
  1328. { dirty hack to overcome an overflow (PFV) }
  1329. if highrange=$7fffffff then
  1330. size:=$7fffffff
  1331. else
  1332. size:=(highrange-lowrange+1)*elesize;
  1333. end;
  1334. function tarraydef.needs_inittable : boolean;
  1335. begin
  1336. needs_inittable:=definition^.needs_inittable;
  1337. end;
  1338. procedure tarraydef.write_child_rtti_data;
  1339. begin
  1340. definition^.get_rtti_label;
  1341. end;
  1342. procedure tarraydef.write_rtti_data;
  1343. begin
  1344. rttilist^.concat(new(pai_const,init_8bit(13)));
  1345. writename;
  1346. { size of elements }
  1347. rttilist^.concat(new(pai_const,init_32bit(definition^.size)));
  1348. { count of elements }
  1349. rttilist^.concat(new(pai_const,init_32bit(highrange-lowrange+1)));
  1350. { element type }
  1351. rttilist^.concat(new(pai_const,init_symbol(strpnew(definition^.get_rtti_label))));
  1352. end;
  1353. {***************************************************************************
  1354. TRECDEF
  1355. ***************************************************************************}
  1356. constructor trecdef.init(p : psymtable);
  1357. begin
  1358. inherited init;
  1359. deftype:=recorddef;
  1360. symtable:=p;
  1361. savesize:=symtable^.datasize;
  1362. symtable^.defowner := @self;
  1363. end;
  1364. constructor trecdef.load;
  1365. var
  1366. oldread_member : boolean;
  1367. begin
  1368. inherited load;
  1369. deftype:=recorddef;
  1370. savesize:=readlong;
  1371. oldread_member:=read_member;
  1372. read_member:=true;
  1373. symtable:=new(psymtable,loadasstruct(recordsymtable));
  1374. read_member:=oldread_member;
  1375. symtable^.defowner := @self;
  1376. end;
  1377. destructor trecdef.done;
  1378. begin
  1379. if assigned(symtable) then dispose(symtable,done);
  1380. inherited done;
  1381. end;
  1382. var
  1383. binittable : boolean;
  1384. procedure check_rec_inittable(s : psym);
  1385. begin
  1386. if (s^.typ=varsym) and
  1387. ((pvarsym(s)^.definition^.deftype<>objectdef)
  1388. or not(pobjectdef(pvarsym(s)^.definition)^.isclass)) then
  1389. binittable:=pvarsym(s)^.definition^.needs_inittable;
  1390. end;
  1391. function trecdef.needs_inittable : boolean;
  1392. var
  1393. oldb : boolean;
  1394. begin
  1395. { there are recursive calls to needs_rtti possible, }
  1396. { so we have to change to old value how else should }
  1397. { we do that ? check_rec_rtti can't be a nested }
  1398. { procedure of needs_rtti ! }
  1399. oldb:=binittable;
  1400. binittable:=false;
  1401. symtable^.foreach(check_rec_inittable);
  1402. needs_inittable:=binittable;
  1403. binittable:=oldb;
  1404. end;
  1405. procedure trecdef.deref;
  1406. var
  1407. hp : pdef;
  1408. oldrecsyms : psymtable;
  1409. begin
  1410. oldrecsyms:=aktrecordsymtable;
  1411. aktrecordsymtable:=symtable;
  1412. { now dereference the definitions }
  1413. hp:=symtable^.rootdef;
  1414. while assigned(hp) do
  1415. begin
  1416. hp^.deref;
  1417. { set owner }
  1418. hp^.owner:=symtable;
  1419. hp:=hp^.next;
  1420. end;
  1421. {$ifdef tp}
  1422. symtable^.foreach(derefsym);
  1423. {$else}
  1424. symtable^.foreach(@derefsym);
  1425. {$endif}
  1426. aktrecordsymtable:=oldrecsyms;
  1427. end;
  1428. procedure trecdef.write;
  1429. var
  1430. oldread_member : boolean;
  1431. begin
  1432. oldread_member:=read_member;
  1433. read_member:=true;
  1434. inherited write;
  1435. writelong(savesize);
  1436. current_ppu^.writeentry(ibrecorddef);
  1437. self.symtable^.writeasstruct;
  1438. read_member:=oldread_member;
  1439. end;
  1440. {$ifdef GDB}
  1441. Const StabRecString : pchar = Nil;
  1442. StabRecSize : longint = 0;
  1443. RecOffset : Longint = 0;
  1444. procedure addname(p : psym);
  1445. var
  1446. news, newrec : pchar;
  1447. spec : string[2];
  1448. begin
  1449. { static variables from objects are like global objects }
  1450. if ((p^.properties and sp_static)<>0) then
  1451. exit;
  1452. if ((p^.properties and sp_protected)<>0) then
  1453. spec:='/1'
  1454. else if ((p^.properties and sp_private)<>0) then
  1455. spec:='/0'
  1456. else
  1457. spec:='';
  1458. If p^.typ = varsym then
  1459. begin
  1460. newrec := strpnew(p^.name+':'+spec+pvarsym(p)^.definition^.numberstring
  1461. +','+tostr(pvarsym(p)^.address*8)+','
  1462. +tostr(pvarsym(p)^.definition^.size*8)+';');
  1463. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1464. begin
  1465. getmem(news,stabrecsize+memsizeinc);
  1466. strcopy(news,stabrecstring);
  1467. freemem(stabrecstring,stabrecsize);
  1468. stabrecsize:=stabrecsize+memsizeinc;
  1469. stabrecstring:=news;
  1470. end;
  1471. strcat(StabRecstring,newrec);
  1472. strdispose(newrec);
  1473. {This should be used for case !!}
  1474. RecOffset := RecOffset + pvarsym(p)^.definition^.size;
  1475. end;
  1476. end;
  1477. function trecdef.stabstring : pchar;
  1478. Var oldrec : pchar;
  1479. oldsize : longint;
  1480. cur : psym;
  1481. begin
  1482. oldrec := stabrecstring;
  1483. oldsize:=stabrecsize;
  1484. GetMem(stabrecstring,memsizeinc);
  1485. stabrecsize:=memsizeinc;
  1486. strpcopy(stabRecString,'s'+tostr(savesize));
  1487. RecOffset := 0;
  1488. {$ifdef nonextfield}
  1489. {$ifdef tp}
  1490. symtable^.foreach(addname);
  1491. {$else}
  1492. symtable^.foreach(@addname);
  1493. {$endif}
  1494. {$else nonextfield}
  1495. cur:=symtable^.root;
  1496. while assigned(cur) do
  1497. begin
  1498. addname(cur);
  1499. cur:=cur^.nextsym;
  1500. end;
  1501. {$endif nonextfield}
  1502. { FPC doesn't want to convert a char to a pchar}
  1503. { is this a bug ? }
  1504. strpcopy(strend(StabRecString),';');
  1505. stabstring := strnew(StabRecString);
  1506. Freemem(stabrecstring,stabrecsize);
  1507. stabrecstring := oldrec;
  1508. stabrecsize:=oldsize;
  1509. end;
  1510. procedure trecdef.concatstabto(asmlist : paasmoutput);
  1511. begin
  1512. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1513. (not is_def_stab_written) then
  1514. inherited concatstabto(asmlist);
  1515. end;
  1516. {$endif GDB}
  1517. var
  1518. count : longint;
  1519. procedure count_inittable_fields(sym : psym);{$ifndef fpc}far;{$endif}
  1520. begin
  1521. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.needs_inittable) then
  1522. inc(count);
  1523. end;
  1524. procedure count_fields(sym : psym);{$ifndef fpc}far;{$endif}
  1525. begin
  1526. inc(count);
  1527. end;
  1528. procedure write_field_inittable(sym : psym);{$ifndef fpc}far;{$endif}
  1529. begin
  1530. if (sym^.typ=varsym) and pvarsym(sym)^.definition^.needs_inittable then
  1531. begin
  1532. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(pvarsym(sym)^.definition^.get_inittable_label)))));
  1533. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1534. end;
  1535. end;
  1536. procedure write_field_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  1537. begin
  1538. rttilist^.concat(new(pai_const,init_symbol(strpnew(pvarsym(sym)^.definition^.get_rtti_label))));
  1539. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1540. end;
  1541. procedure generate_child_inittable(sym : psym);{$ifndef fpc}far;{$endif}
  1542. begin
  1543. if (sym^.typ=varsym) and pvarsym(sym)^.definition^.needs_inittable then
  1544. { force inittable generation }
  1545. pvarsym(sym)^.definition^.get_inittable_label;
  1546. end;
  1547. procedure generate_child_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  1548. begin
  1549. pvarsym(sym)^.definition^.get_rtti_label;
  1550. end;
  1551. procedure trecdef.write_child_rtti_data;
  1552. begin
  1553. symtable^.foreach(generate_child_rtti);
  1554. end;
  1555. procedure trecdef.write_child_init_data;
  1556. begin
  1557. symtable^.foreach(generate_child_inittable);
  1558. end;
  1559. procedure trecdef.write_rtti_data;
  1560. begin
  1561. rttilist^.concat(new(pai_const,init_8bit(14)));
  1562. writename;
  1563. rttilist^.concat(new(pai_const,init_32bit(size)));
  1564. count:=0;
  1565. symtable^.foreach(count_fields);
  1566. rttilist^.concat(new(pai_const,init_32bit(count)));
  1567. symtable^.foreach(write_field_rtti);
  1568. end;
  1569. procedure trecdef.write_init_data;
  1570. begin
  1571. rttilist^.concat(new(pai_const,init_8bit(14)));
  1572. writename;
  1573. rttilist^.concat(new(pai_const,init_32bit(size)));
  1574. count:=0;
  1575. symtable^.foreach(count_inittable_fields);
  1576. rttilist^.concat(new(pai_const,init_32bit(count)));
  1577. symtable^.foreach(write_field_inittable);
  1578. end;
  1579. {***************************************************************************
  1580. TABSTRACTPROCDEF
  1581. ***************************************************************************}
  1582. constructor tabstractprocdef.init;
  1583. begin
  1584. inherited init;
  1585. para1:=nil;
  1586. fpu_used:=0;
  1587. options:=0;
  1588. retdef:=voiddef;
  1589. savesize:=target_os.size_of_pointer;
  1590. end;
  1591. procedure disposepdefcoll(var para1 : pdefcoll);
  1592. var
  1593. hp : pdefcoll;
  1594. begin
  1595. hp:=para1;
  1596. while assigned(hp) do
  1597. begin
  1598. para1:=hp^.next;
  1599. dispose(hp);
  1600. hp:=para1;
  1601. end;
  1602. end;
  1603. destructor tabstractprocdef.done;
  1604. begin
  1605. disposepdefcoll(para1);
  1606. inherited done;
  1607. end;
  1608. procedure tabstractprocdef.concatdef(p : pdef;vsp : tvarspez);
  1609. var
  1610. hp : pdefcoll;
  1611. begin
  1612. new(hp);
  1613. hp^.paratyp:=vsp;
  1614. hp^.data:=p;
  1615. hp^.next:=para1;
  1616. para1:=hp;
  1617. end;
  1618. { all functions returning in FPU are
  1619. assume to use 2 FPU registers
  1620. until the function implementation
  1621. is processed PM }
  1622. procedure tabstractprocdef.test_if_fpu_result;
  1623. begin
  1624. if assigned(retdef) and is_fpu(retdef) then
  1625. fpu_used:=2;
  1626. end;
  1627. procedure tabstractprocdef.deref;
  1628. var
  1629. hp : pdefcoll;
  1630. begin
  1631. inherited deref;
  1632. resolvedef(retdef);
  1633. hp:=para1;
  1634. while assigned(hp) do
  1635. begin
  1636. resolvedef(hp^.data);
  1637. hp:=hp^.next;
  1638. end;
  1639. end;
  1640. constructor tabstractprocdef.load;
  1641. var
  1642. last,hp : pdefcoll;
  1643. count,i : word;
  1644. begin
  1645. inherited load;
  1646. retdef:=readdefref;
  1647. fpu_used:=readbyte;
  1648. options:=readlong;
  1649. count:=readword;
  1650. para1:=nil;
  1651. savesize:=target_os.size_of_pointer;
  1652. for i:=1 to count do
  1653. begin
  1654. new(hp);
  1655. hp^.paratyp:=tvarspez(readbyte);
  1656. hp^.data:=readdefref;
  1657. hp^.next:=nil;
  1658. if para1=nil then
  1659. para1:=hp
  1660. else
  1661. last^.next:=hp;
  1662. last:=hp;
  1663. end;
  1664. end;
  1665. function tabstractprocdef.para_size : longint;
  1666. var
  1667. pdc : pdefcoll;
  1668. l : longint;
  1669. begin
  1670. l:=0;
  1671. pdc:=para1;
  1672. while assigned(pdc) do
  1673. begin
  1674. case pdc^.paratyp of
  1675. vs_var : inc(l,target_os.size_of_pointer);
  1676. {$ifndef VALUEPARA}
  1677. vs_value : inc(l,align(pdc^.data^.size,target_os.stackalignment));
  1678. vs_const : if dont_copy_const_param(pdc^.data) then
  1679. inc(l,target_os.size_of_pointer)
  1680. else
  1681. inc(l,align(pdc^.data^.size,target_os.stackalignment));
  1682. {$else}
  1683. vs_value,
  1684. vs_const : if push_addr_param(pdc^.data) then
  1685. inc(l,target_os.size_of_pointer)
  1686. else
  1687. inc(l,align(pdc^.data^.size,target_os.stackalignment));
  1688. {$endif}
  1689. end;
  1690. pdc:=pdc^.next;
  1691. end;
  1692. para_size:=l;
  1693. end;
  1694. procedure tabstractprocdef.write;
  1695. var
  1696. count : word;
  1697. hp : pdefcoll;
  1698. begin
  1699. inherited write;
  1700. writedefref(retdef);
  1701. writebyte(fpu_used);
  1702. writelong(options);
  1703. hp:=para1;
  1704. count:=0;
  1705. while assigned(hp) do
  1706. begin
  1707. inc(count);
  1708. hp:=hp^.next;
  1709. end;
  1710. writeword(count);
  1711. hp:=para1;
  1712. while assigned(hp) do
  1713. begin
  1714. writebyte(byte(hp^.paratyp));
  1715. writedefref(hp^.data);
  1716. hp:=hp^.next;
  1717. end;
  1718. end;
  1719. function tabstractprocdef.demangled_paras : string;
  1720. var s : string;
  1721. p : pdefcoll;
  1722. begin
  1723. s:='';
  1724. p:=para1;
  1725. if assigned(p) then
  1726. begin
  1727. s:=s+'(';
  1728. while assigned(p) do
  1729. begin
  1730. if assigned(p^.data^.sym) then
  1731. s:=s+p^.data^.sym^.name
  1732. else if p^.paratyp=vs_var then
  1733. s:=s+'var'
  1734. else if p^.paratyp=vs_const then
  1735. s:=s+'const';
  1736. p:=p^.next;
  1737. if assigned(p) then
  1738. s:=s+','
  1739. else
  1740. s:=s+')';
  1741. end;
  1742. end;
  1743. demangled_paras:=s;
  1744. end;
  1745. {$ifdef GDB}
  1746. function tabstractprocdef.stabstring : pchar;
  1747. begin
  1748. stabstring := strpnew('abstractproc'+numberstring+';');
  1749. end;
  1750. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  1751. begin
  1752. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  1753. and not is_def_stab_written then
  1754. begin
  1755. if assigned(retdef) then forcestabto(asmlist,retdef);
  1756. inherited concatstabto(asmlist);
  1757. end;
  1758. end;
  1759. {$endif GDB}
  1760. {***************************************************************************
  1761. TPROCDEF
  1762. ***************************************************************************}
  1763. constructor tprocdef.init;
  1764. begin
  1765. inherited init;
  1766. deftype:=procdef;
  1767. _mangledname:=nil;
  1768. nextoverloaded:=nil;
  1769. extnumber:=-1;
  1770. localst:=new(psymtable,init(localsymtable));
  1771. parast:=new(psymtable,init(parasymtable));
  1772. { this is used by insert
  1773. to check same names in parast and localst }
  1774. localst^.next:=parast;
  1775. {$ifdef UseBrowser}
  1776. defref:=nil;
  1777. lastwritten:=nil;
  1778. refcount:=0;
  1779. if (cs_browser in aktmoduleswitches) and make_ref then
  1780. begin
  1781. defref:=new(pref,init(defref,@tokenpos));
  1782. inc(refcount);
  1783. end;
  1784. lastref:=defref;
  1785. {$endif UseBrowser}
  1786. { first, we assume, that all registers are used }
  1787. {$ifdef i386}
  1788. usedregisters:=$ff;
  1789. {$endif i386}
  1790. {$ifdef m68k}
  1791. usedregisters:=$FFFF;
  1792. {$endif}
  1793. {$ifdef alpha}
  1794. usedregisters_int:=$ffffffff;
  1795. usedregisters_fpu:=$ffffffff;
  1796. {$endif alpha}
  1797. forwarddef:=true;
  1798. _class := nil;
  1799. code:=nil;
  1800. end;
  1801. constructor tprocdef.load;
  1802. var
  1803. s : string;
  1804. begin
  1805. inherited load;
  1806. deftype:=procdef;
  1807. {$ifdef i386}
  1808. usedregisters:=readbyte;
  1809. {$endif i386}
  1810. {$ifdef m68k}
  1811. usedregisters:=readword;
  1812. {$endif}
  1813. {$ifdef alpha}
  1814. usedregisters_int:=readlong;
  1815. usedregisters_fpu:=readlong;
  1816. {$endif alpha}
  1817. s:=readstring;
  1818. setstring(_mangledname,s);
  1819. extnumber:=readlong;
  1820. nextoverloaded:=pprocdef(readdefref);
  1821. _class := pobjectdef(readdefref);
  1822. if (cs_link_deffile in aktglobalswitches) and ((options and poexports)<>0) then
  1823. deffile.AddExport(mangledname);
  1824. parast:=nil;
  1825. localst:=nil;
  1826. forwarddef:=false;
  1827. {$ifdef UseBrowser}
  1828. lastref:=nil;
  1829. lastwritten:=nil;
  1830. defref:=nil;
  1831. refcount:=0;
  1832. {$endif UseBrowser}
  1833. end;
  1834. {$ifdef UseBrowser}
  1835. procedure tprocdef.load_references;
  1836. var
  1837. pos : tfileposinfo;
  1838. move_last : boolean;
  1839. begin
  1840. move_last:=lastwritten=lastref;
  1841. while (not current_ppu^.endofentry) do
  1842. begin
  1843. readposinfo(pos);
  1844. inc(refcount);
  1845. lastref:=new(pref,init(lastref,@pos));
  1846. lastref^.is_written:=true;
  1847. if refcount=1 then
  1848. defref:=lastref;
  1849. end;
  1850. if move_last then
  1851. lastwritten:=lastref;
  1852. if (current_module^.flags and uf_local_browser)<>0 then
  1853. begin
  1854. new(parast,load);
  1855. parast^.load_browser;
  1856. new(localst,load);
  1857. localst^.load_browser;
  1858. end;
  1859. end;
  1860. function tprocdef.write_references : boolean;
  1861. var
  1862. ref : pref;
  1863. move_last : boolean;
  1864. begin
  1865. move_last:=lastwritten=lastref;
  1866. if move_last and ((current_module^.flags and uf_local_browser)=0) then
  1867. exit;
  1868. { write address of this symbol }
  1869. writedefref(@self);
  1870. { write refs }
  1871. if assigned(lastwritten) then
  1872. ref:=lastwritten
  1873. else
  1874. ref:=defref;
  1875. while assigned(ref) do
  1876. begin
  1877. if ref^.moduleindex=current_module^.unit_index then
  1878. begin
  1879. writeposinfo(ref^.posinfo);
  1880. ref^.is_written:=true;
  1881. if move_last then
  1882. lastwritten:=ref;
  1883. end
  1884. else if not ref^.is_written then
  1885. move_last:=false
  1886. else if move_last then
  1887. lastwritten:=ref;
  1888. ref:=ref^.nextref;
  1889. end;
  1890. current_ppu^.writeentry(ibdefref);
  1891. write_references:=true;
  1892. if (current_module^.flags and uf_local_browser)<>0 then
  1893. begin
  1894. { we need dummy para and local symtables
  1895. PPU files are then easier to read PM }
  1896. if not assigned(parast) then
  1897. parast:=new(psymtable,init(parasymtable));
  1898. parast^.write;
  1899. parast^.write_browser;
  1900. if not assigned(localst) then
  1901. localst:=new(psymtable,init(localsymtable));
  1902. localst^.write;
  1903. localst^.write_browser;
  1904. end;
  1905. end;
  1906. procedure tprocdef.add_to_browserlog;
  1907. begin
  1908. if assigned(defref) then
  1909. begin
  1910. Browse.AddLog('***'+mangledname);
  1911. Browse.AddLogRefs(defref);
  1912. if (current_module^.flags and uf_local_browser)<>0 then
  1913. begin
  1914. if assigned(parast) then
  1915. parast^.writebrowserlog;
  1916. if assigned(localst) then
  1917. localst^.writebrowserlog;
  1918. end;
  1919. end;
  1920. end;
  1921. {$endif UseBrowser}
  1922. destructor tprocdef.done;
  1923. begin
  1924. {$ifdef UseBrowser}
  1925. if assigned(defref) then
  1926. dispose(defref,done);
  1927. {$endif UseBrowser}
  1928. if assigned(parast) then
  1929. dispose(parast,done);
  1930. if assigned(localst) and (localst^.symtabletype<>staticsymtable) then
  1931. dispose(localst,done);
  1932. if assigned(code) and ((options and poinline) <> 0) then
  1933. disposetree(ptree(code));
  1934. if
  1935. {$ifdef tp}
  1936. not(use_big) and
  1937. {$endif}
  1938. assigned(_mangledname) then
  1939. strdispose(_mangledname);
  1940. inherited done;
  1941. end;
  1942. procedure tprocdef.write;
  1943. begin
  1944. inherited write;
  1945. {$ifdef i386}
  1946. writebyte(usedregisters);
  1947. {$endif i386}
  1948. {$ifdef m68k}
  1949. writeword(usedregisters);
  1950. {$endif}
  1951. {$ifdef alpha}
  1952. writelong(usedregisters_int);
  1953. writelong(usedregisters_fpu);
  1954. {$endif alpha}
  1955. writestring(mangledname);
  1956. writelong(extnumber);
  1957. if (options and pooperator) = 0 then
  1958. writedefref(nextoverloaded)
  1959. else
  1960. begin
  1961. { only write the overloads from the same unit }
  1962. if nextoverloaded^.owner=owner then
  1963. writedefref(nextoverloaded)
  1964. else
  1965. writedefref(nil);
  1966. end;
  1967. writedefref(_class);
  1968. if (options and poinline) <> 0 then
  1969. begin
  1970. { we need to save
  1971. - the para and the local symtable
  1972. - the code ptree !! PM
  1973. writesymtable(parast);
  1974. writesymtable(localst);
  1975. writeptree(ptree(code));
  1976. }
  1977. end;
  1978. current_ppu^.writeentry(ibprocdef);
  1979. end;
  1980. {$ifdef GDB}
  1981. procedure addparaname(p : psym);
  1982. var vs : char;
  1983. begin
  1984. if pvarsym(p)^.varspez = vs_value then vs := '1'
  1985. else vs := '0';
  1986. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.definition^.numberstring+','+vs+';');
  1987. end;
  1988. function tprocdef.stabstring : pchar;
  1989. var param : pdefcoll;
  1990. i : word;
  1991. oldrec : pchar;
  1992. begin
  1993. oldrec := stabrecstring;
  1994. getmem(StabRecString,1024);
  1995. param := para1;
  1996. i := 0;
  1997. while assigned(param) do
  1998. begin
  1999. inc(i);
  2000. param := param^.next;
  2001. end;
  2002. strpcopy(StabRecString,'f'+retdef^.numberstring);
  2003. if i>0 then
  2004. begin
  2005. strpcopy(strend(StabRecString),','+tostr(i)+';');
  2006. (* confuse gdb !! PM
  2007. if assigned(parast) then
  2008. {$IfDef TP}
  2009. parast^.foreach(addparaname)
  2010. {$Else}
  2011. parast^.foreach(@addparaname)
  2012. {$EndIf}
  2013. else
  2014. begin
  2015. param := para1;
  2016. i := 0;
  2017. while assigned(param) do
  2018. begin
  2019. inc(i);
  2020. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2021. {Here we have lost the parameter names !!}
  2022. {using lower case parameters }
  2023. strpcopy(strend(stabrecstring),'p'+tostr(i)
  2024. +':'+param^.data^.numberstring+','+vartyp+';');
  2025. param := param^.next;
  2026. end;
  2027. end; *)
  2028. {strpcopy(strend(StabRecString),';');}
  2029. end;
  2030. stabstring := strnew(stabrecstring);
  2031. freemem(stabrecstring,1024);
  2032. stabrecstring := oldrec;
  2033. end;
  2034. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  2035. begin
  2036. end;
  2037. {$endif GDB}
  2038. procedure tprocdef.deref;
  2039. begin
  2040. inherited deref;
  2041. resolvedef(pdef(nextoverloaded));
  2042. resolvedef(pdef(_class));
  2043. end;
  2044. function tprocdef.mangledname : string;
  2045. {$ifdef tp}
  2046. var
  2047. oldpos : longint;
  2048. s : string;
  2049. b : byte;
  2050. {$endif tp}
  2051. begin
  2052. {$ifdef tp}
  2053. if use_big then
  2054. begin
  2055. symbolstream.seek(longint(_mangledname));
  2056. symbolstream.read(b,1);
  2057. symbolstream.read(s[1],b);
  2058. s[0]:=chr(b);
  2059. mangledname:=s;
  2060. end
  2061. else
  2062. {$endif}
  2063. mangledname:=strpas(_mangledname);
  2064. end;
  2065. {$IfDef GDB}
  2066. function tprocdef.cplusplusmangledname : string;
  2067. var
  2068. s,s2 : string;
  2069. param : pdefcoll;
  2070. begin
  2071. s := sym^.name;
  2072. if _class <> nil then
  2073. begin
  2074. s2 := _class^.name^;
  2075. s := s+'__'+tostr(length(s2))+s2;
  2076. end else s := s + '_';
  2077. param := para1;
  2078. while assigned(param) do
  2079. begin
  2080. s2 := param^.data^.sym^.name;
  2081. s := s+tostr(length(s2))+s2;
  2082. param := param^.next;
  2083. end;
  2084. cplusplusmangledname:=s;
  2085. end;
  2086. {$EndIf GDB}
  2087. procedure tprocdef.setmangledname(const s : string);
  2088. begin
  2089. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  2090. strdispose(_mangledname);
  2091. setstring(_mangledname,s);
  2092. {$ifdef UseBrowser}
  2093. if assigned(parast) then
  2094. begin
  2095. stringdispose(parast^.name);
  2096. parast^.name:=stringdup('args of '+s);
  2097. end;
  2098. if assigned(localst) then
  2099. begin
  2100. stringdispose(localst^.name);
  2101. localst^.name:=stringdup('locals of '+s);
  2102. end;
  2103. {$endif UseBrowser}
  2104. end;
  2105. {***************************************************************************
  2106. TPROCVARDEF
  2107. ***************************************************************************}
  2108. constructor tprocvardef.init;
  2109. begin
  2110. inherited init;
  2111. deftype:=procvardef;
  2112. end;
  2113. constructor tprocvardef.load;
  2114. begin
  2115. inherited load;
  2116. deftype:=procvardef;
  2117. end;
  2118. procedure tprocvardef.write;
  2119. begin
  2120. { here we cannot get a real good value so just give something }
  2121. { plausible (PM) }
  2122. { a more secure way would be
  2123. to allways store in a temp }
  2124. if is_fpu(retdef) then
  2125. fpu_used:=2
  2126. else
  2127. fpu_used:=0;
  2128. inherited write;
  2129. current_ppu^.writeentry(ibprocvardef);
  2130. end;
  2131. function tprocvardef.size : longint;
  2132. begin
  2133. if (options and pomethodpointer)=0 then
  2134. size:=target_os.size_of_pointer
  2135. else
  2136. size:=2*target_os.size_of_pointer;
  2137. end;
  2138. {$ifdef GDB}
  2139. function tprocvardef.stabstring : pchar;
  2140. var
  2141. nss : pchar;
  2142. i : word;
  2143. param : pdefcoll;
  2144. begin
  2145. i := 0;
  2146. param := para1;
  2147. while assigned(param) do
  2148. begin
  2149. inc(i);
  2150. param := param^.next;
  2151. end;
  2152. getmem(nss,1024);
  2153. strpcopy(nss,'f'+retdef^.numberstring{+','+tostr(i)}+';');
  2154. param := para1;
  2155. i := 0;
  2156. { this confuses gdb !!
  2157. we should use 'F' instead of 'f' but
  2158. as we use c++ language mode
  2159. it does not like that either
  2160. Please do not remove this part
  2161. might be used once
  2162. gdb for pascal is ready PM }
  2163. (* while assigned(param) do
  2164. begin
  2165. inc(i);
  2166. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2167. {Here we have lost the parameter names !!}
  2168. pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
  2169. strcat(nss,pst);
  2170. strdispose(pst);
  2171. param := param^.next;
  2172. end; *)
  2173. {strpcopy(strend(nss),';');}
  2174. stabstring := strnew(nss);
  2175. freemem(nss,1024);
  2176. end;
  2177. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2178. begin
  2179. if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2180. and not is_def_stab_written then
  2181. inherited concatstabto(asmlist);
  2182. is_def_stab_written:=true;
  2183. end;
  2184. {$endif GDB}
  2185. procedure tprocvardef.write_rtti_data;
  2186. begin
  2187. {!!!!!!!}
  2188. end;
  2189. procedure tprocvardef.write_child_rtti_data;
  2190. begin
  2191. {!!!!!!!!}
  2192. end;
  2193. function tprocvardef.is_publishable : boolean;
  2194. begin
  2195. is_publishable:=(options and pomethodpointer)<>0;
  2196. end;
  2197. {***************************************************************************
  2198. TOBJECTDEF
  2199. ***************************************************************************}
  2200. {$ifdef GDB}
  2201. const
  2202. vtabletype : word = 0;
  2203. vtableassigned : boolean = false;
  2204. {$endif GDB}
  2205. constructor tobjectdef.init(const n : string;c : pobjectdef);
  2206. begin
  2207. tdef.init;
  2208. deftype:=objectdef;
  2209. options:=0;
  2210. childof:=nil;
  2211. publicsyms:=new(psymtable,init(objectsymtable));
  2212. publicsyms^.name := stringdup(n);
  2213. { create space for vmt !! }
  2214. {$ifdef OLDVMTSTYLE}
  2215. publicsyms^.datasize:=target_os.size_of_pointer;
  2216. options:=oo_hasvmt;
  2217. vmt_offset:=0;
  2218. {$else }
  2219. options:=0;
  2220. vmt_offset:=0;
  2221. publicsyms^.datasize:=0;
  2222. {$endif }
  2223. publicsyms^.defowner:=@self;
  2224. set_parent(c);
  2225. name:=stringdup(n);
  2226. end;
  2227. procedure tobjectdef.set_parent( c : pobjectdef);
  2228. begin
  2229. { nothing to do if the parent was not forward !}
  2230. if assigned(childof) then
  2231. exit;
  2232. childof:=c;
  2233. { some options are inherited !! }
  2234. if assigned(c) then
  2235. begin
  2236. options:= options or (c^.options and
  2237. (oo_hasvirtual or oo_hasprivate or
  2238. oo_hasprotected or
  2239. oo_hasconstructor or oo_hasdestructor
  2240. ));
  2241. { add the data of the anchestor class }
  2242. publicsyms^.datasize:=publicsyms^.datasize
  2243. +childof^.publicsyms^.datasize;
  2244. if ((options and oo_hasvmt)<>0) and
  2245. ((c^.options and oo_hasvmt)<>0) then
  2246. publicsyms^.datasize:=publicsyms^.datasize-target_os.size_of_pointer;
  2247. { if parent has a vmt field then
  2248. the offset is the same for the child PM }
  2249. if ((c^.options and oo_hasvmt)<>0) or isclass then
  2250. begin
  2251. vmt_offset:=c^.vmt_offset;
  2252. options:=options or oo_hasvmt;
  2253. end;
  2254. end;
  2255. savesize := publicsyms^.datasize;
  2256. end;
  2257. constructor tobjectdef.load;
  2258. var
  2259. oldread_member : boolean;
  2260. begin
  2261. tdef.load;
  2262. deftype:=objectdef;
  2263. savesize:=readlong;
  2264. vmt_offset:=readlong;
  2265. name:=stringdup(readstring);
  2266. childof:=pobjectdef(readdefref);
  2267. options:=readlong;
  2268. oldread_member:=read_member;
  2269. read_member:=true;
  2270. object_options:=true;
  2271. publicsyms:=new(psymtable,loadasstruct(objectsymtable));
  2272. object_options:=false;
  2273. read_member:=oldread_member;
  2274. publicsyms^.defowner:=@self;
  2275. { publicsyms^.datasize:=savesize; }
  2276. publicsyms^.name := stringdup(name^);
  2277. { handles the predefined class tobject }
  2278. { the last TOBJECT which is loaded gets }
  2279. { it ! }
  2280. if (name^='TOBJECT') and not(cs_compilesystem in aktmoduleswitches) and
  2281. isclass and (childof=pointer($ffffffff)) then
  2282. class_tobject:=@self;
  2283. has_rtti:=true;
  2284. end;
  2285. procedure tobjectdef.insertvmt;
  2286. begin
  2287. if (options and oo_hasvmt)<>0 then
  2288. internalerror(12345)
  2289. else
  2290. begin
  2291. { first round up to multiple of 4 }
  2292. if (aktpackrecords=2) then
  2293. begin
  2294. if (publicsyms^.datasize and 1)<>0 then
  2295. inc(publicsyms^.datasize);
  2296. end;
  2297. if (aktpackrecords>=4) then
  2298. begin
  2299. if (publicsyms^.datasize mod 4) <> 0 then
  2300. publicsyms^.datasize:=publicsyms^.datasize+4-(publicsyms^.datasize mod 4);
  2301. end;
  2302. vmt_offset:=publicsyms^.datasize;
  2303. publicsyms^.datasize:=publicsyms^.datasize+target_os.size_of_pointer;
  2304. options:=options or oo_hasvmt;
  2305. end;
  2306. end;
  2307. procedure tobjectdef.check_forwards;
  2308. begin
  2309. publicsyms^.check_forwards;
  2310. if (options and oo_isforward)<>0 then
  2311. begin
  2312. { ok, in future, the forward can be resolved }
  2313. Message1(sym_e_class_forward_not_resolved,name^);
  2314. options:=options and not(oo_isforward);
  2315. end;
  2316. end;
  2317. destructor tobjectdef.done;
  2318. begin
  2319. {!!!!
  2320. if assigned(privatesyms) then
  2321. dispose(privatesyms,done);
  2322. if assigned(protectedsyms) then
  2323. dispose(protectedsyms,done); }
  2324. if assigned(publicsyms) then
  2325. dispose(publicsyms,done);
  2326. if (options and oo_isforward)<>0 then
  2327. Message1(sym_e_class_forward_not_resolved,name^);
  2328. stringdispose(name);
  2329. tdef.done;
  2330. end;
  2331. { true, if self inherits from d (or if they are equal) }
  2332. function tobjectdef.isrelated(d : pobjectdef) : boolean;
  2333. var
  2334. hp : pobjectdef;
  2335. begin
  2336. hp:=@self;
  2337. while assigned(hp) do
  2338. begin
  2339. if hp=d then
  2340. begin
  2341. isrelated:=true;
  2342. exit;
  2343. end;
  2344. hp:=hp^.childof;
  2345. end;
  2346. isrelated:=false;
  2347. end;
  2348. function tobjectdef.size : longint;
  2349. begin
  2350. if (options and oo_is_class)<>0 then
  2351. size:=target_os.size_of_pointer
  2352. else
  2353. size:=publicsyms^.datasize;
  2354. end;
  2355. procedure tobjectdef.deref;
  2356. var
  2357. hp : pdef;
  2358. oldrecsyms : psymtable;
  2359. begin
  2360. resolvedef(pdef(childof));
  2361. oldrecsyms:=aktrecordsymtable;
  2362. aktrecordsymtable:=publicsyms;
  2363. { nun die Definitionen dereferenzieren }
  2364. hp:=publicsyms^.rootdef;
  2365. while assigned(hp) do
  2366. begin
  2367. hp^.deref;
  2368. { set owner }
  2369. hp^.owner:=publicsyms;
  2370. hp:=hp^.next;
  2371. end;
  2372. {$ifdef tp}
  2373. publicsyms^.foreach(derefsym);
  2374. {$else}
  2375. publicsyms^.foreach(@derefsym);
  2376. {$endif}
  2377. aktrecordsymtable:=oldrecsyms;
  2378. end;
  2379. function tobjectdef.vmt_mangledname : string;
  2380. {DM: I get a nil pointer on the owner name. I don't know if this
  2381. mayhappen, and I have therefore fixed the problem by doing nil pointer
  2382. checks.}
  2383. var
  2384. s1,s2:string;
  2385. begin
  2386. if (options and oo_hasvmt)=0 then
  2387. internalerror(12346);
  2388. if owner^.name=nil then
  2389. s1:=''
  2390. else
  2391. s1:=owner^.name^;
  2392. if name=nil then
  2393. s2:=''
  2394. else
  2395. s2:=name^;
  2396. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  2397. end;
  2398. function tobjectdef.rtti_name : string;
  2399. var
  2400. s1,s2:string;
  2401. begin
  2402. if owner^.name=nil then
  2403. s1:=''
  2404. else
  2405. s1:=owner^.name^;
  2406. if name=nil then
  2407. s2:=''
  2408. else
  2409. s2:=name^;
  2410. rtti_name:='RTTI_'+s1+'$_'+s2;
  2411. end;
  2412. function tobjectdef.isclass : boolean;
  2413. begin
  2414. isclass:=(options and oo_is_class)<>0;
  2415. end;
  2416. procedure tobjectdef.write;
  2417. var
  2418. oldread_member : boolean;
  2419. begin
  2420. tdef.write;
  2421. writelong(size);
  2422. writelong(vmt_offset);
  2423. writestring(name^);
  2424. writedefref(childof);
  2425. writelong(options);
  2426. current_ppu^.writeentry(ibobjectdef);
  2427. oldread_member:=read_member;
  2428. read_member:=true;
  2429. object_options:=true;
  2430. publicsyms^.writeasstruct;
  2431. object_options:=false;
  2432. read_member:=oldread_member;
  2433. end;
  2434. {$ifdef GDB}
  2435. procedure addprocname(p :psym);
  2436. var virtualind,argnames : string;
  2437. news, newrec : pchar;
  2438. pd,ipd : pprocdef;
  2439. lindex : longint;
  2440. para : pdefcoll;
  2441. arglength : byte;
  2442. sp : char;
  2443. begin
  2444. If p^.typ = procsym then
  2445. begin
  2446. pd := pprocsym(p)^.definition;
  2447. { this will be used for full implementation of object stabs
  2448. not yet done }
  2449. ipd := pd;
  2450. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2451. if (pd^.options and povirtualmethod) <> 0 then
  2452. begin
  2453. lindex := pd^.extnumber;
  2454. {doesnt seem to be necessary
  2455. lindex := lindex or $80000000;}
  2456. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2457. end else virtualind := '.';
  2458. { arguments are not listed here }
  2459. {we don't need another definition}
  2460. para := pd^.para1;
  2461. { used by gdbpas to recognize constructor and destructors }
  2462. if (pd^.options and poconstructor) <> 0 then
  2463. argnames:='__ct__'
  2464. else if (pd^.options and podestructor) <> 0 then
  2465. argnames:='__dt__'
  2466. else
  2467. argnames := '';
  2468. while assigned(para) do
  2469. begin
  2470. if para^.data^.deftype = formaldef then
  2471. begin
  2472. if para^.paratyp=vs_var then
  2473. argnames := argnames+'3var'
  2474. else if para^.paratyp=vs_const then
  2475. argnames:=argnames+'5const';
  2476. end
  2477. else
  2478. begin
  2479. { if the arg definition is like (v: ^byte;..
  2480. there is no sym attached to data !!! }
  2481. if assigned(para^.data^.sym) then
  2482. begin
  2483. arglength := length(para^.data^.sym^.name);
  2484. argnames := argnames + tostr(arglength)+para^.data^.sym^.name;
  2485. end
  2486. else
  2487. begin
  2488. argnames:=argnames+'11unnamedtype';
  2489. end;
  2490. end;
  2491. para := para^.next;
  2492. end;
  2493. ipd^.is_def_stab_written := true;
  2494. { here 2A must be changed for private and protected }
  2495. { 0 is private 1 protected and 2 public }
  2496. if (p^.properties and sp_private)<>0 then sp:='0'
  2497. else if (p^.properties and sp_protected)<>0 then sp:='1'
  2498. else sp:='2';
  2499. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  2500. +'=##'+pd^.retdef^.numberstring+';:'+argnames+';'+sp+'A'
  2501. +virtualind+';');
  2502. { get spare place for a string at the end }
  2503. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2504. begin
  2505. getmem(news,stabrecsize+memsizeinc);
  2506. strcopy(news,stabrecstring);
  2507. freemem(stabrecstring,stabrecsize);
  2508. stabrecsize:=stabrecsize+memsizeinc;
  2509. stabrecstring:=news;
  2510. end;
  2511. strcat(StabRecstring,newrec);
  2512. {freemem(newrec,memsizeinc); }
  2513. strdispose(newrec);
  2514. {This should be used for case !!}
  2515. RecOffset := RecOffset + pd^.size;
  2516. end;
  2517. end;
  2518. function tobjectdef.stabstring : pchar;
  2519. var anc : pobjectdef;
  2520. oldrec : pchar;
  2521. oldrecsize : longint;
  2522. str_end : string;
  2523. {$ifndef nonextfield}
  2524. cur : psym;
  2525. {$endif nonextfield}
  2526. begin
  2527. oldrec := stabrecstring;
  2528. oldrecsize:=stabrecsize;
  2529. stabrecsize:=memsizeinc;
  2530. GetMem(stabrecstring,stabrecsize);
  2531. strpcopy(stabRecString,'s'+tostr(size));
  2532. if assigned(childof) then
  2533. {only one ancestor not virtual, public, at base offset 0 }
  2534. { !1 , 0 2 0 , }
  2535. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  2536. {virtual table to implement yet}
  2537. RecOffset := 0;
  2538. {$ifdef nonextfield}
  2539. {$ifdef tp}
  2540. publicsyms^.foreach(addname);
  2541. {$else}
  2542. publicsyms^.foreach(@addname);
  2543. {$endif}
  2544. {$else nonextfield}
  2545. cur:=publicsyms^.root;
  2546. while assigned(cur) do
  2547. begin
  2548. addname(cur);
  2549. cur:=cur^.nextsym;
  2550. end;
  2551. {$endif nonextfield}
  2552. if (options and oo_hasvmt) <> 0 then
  2553. if not assigned(childof) or ((childof^.options and oo_hasvmt) = 0) then
  2554. begin
  2555. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')
  2556. +','+tostr(vmt_offset*8)+';');
  2557. end;
  2558. {$ifdef nonextfield}
  2559. {$ifdef tp}
  2560. publicsyms^.foreach(addprocname);
  2561. {$else}
  2562. publicsyms^.foreach(@addprocname);
  2563. {$endif tp }
  2564. {$else nonextfield}
  2565. cur:=publicsyms^.root;
  2566. while assigned(cur) do
  2567. begin
  2568. addprocname(cur);
  2569. cur:=cur^.nextsym;
  2570. end;
  2571. {$endif nonextfield}
  2572. if (options and oo_hasvmt) <> 0 then
  2573. begin
  2574. anc := @self;
  2575. while assigned(anc^.childof) and ((anc^.childof^.options and oo_hasvmt) <> 0) do
  2576. anc := anc^.childof;
  2577. str_end:=';~%'+anc^.numberstring+';';
  2578. end
  2579. else
  2580. str_end:=';';
  2581. strpcopy(strend(stabrecstring),str_end);
  2582. stabstring := strnew(StabRecString);
  2583. freemem(stabrecstring,stabrecsize);
  2584. stabrecstring := oldrec;
  2585. stabrecsize:=oldrecsize;
  2586. end;
  2587. {$endif GDB}
  2588. procedure tobjectdef.write_child_init_data;
  2589. begin
  2590. end;
  2591. procedure tobjectdef.write_init_data;
  2592. begin
  2593. if isclass then
  2594. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2595. else
  2596. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2597. { generate the name }
  2598. rttilist^.concat(new(pai_const,init_8bit(length(name^))));
  2599. rttilist^.concat(new(pai_string,init(name^)));
  2600. rttilist^.concat(new(pai_const,init_32bit(size)));
  2601. count:=0;
  2602. publicsyms^.foreach(count_inittable_fields);
  2603. rttilist^.concat(new(pai_const,init_32bit(count)));
  2604. publicsyms^.foreach(write_field_inittable);
  2605. end;
  2606. function tobjectdef.needs_inittable : boolean;
  2607. var
  2608. oldb : boolean;
  2609. begin
  2610. { there are recursive calls to needs_inittable possible, }
  2611. { so we have to change to old value how else should }
  2612. { we do that ? check_rec_rtti can't be a nested }
  2613. { procedure of needs_rtti ! }
  2614. oldb:=binittable;
  2615. binittable:=false;
  2616. publicsyms^.foreach(check_rec_inittable);
  2617. needs_inittable:=binittable;
  2618. binittable:=oldb;
  2619. end;
  2620. procedure count_published_properties(sym : psym);{$ifndef fpc}far;{$endif}
  2621. begin
  2622. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2623. inc(count);
  2624. end;
  2625. procedure write_property_info(sym : psym);{$ifndef fpc}far;{$endif}
  2626. var
  2627. proctypesinfo : byte;
  2628. procedure writeproc(sym : psym;def : pdef;shiftvalue : byte);
  2629. var
  2630. typvalue : byte;
  2631. begin
  2632. if not(assigned(sym)) then
  2633. begin
  2634. rttilist^.concat(new(pai_const,init_32bit(1)));
  2635. typvalue:=3;
  2636. end
  2637. else if sym^.typ=varsym then
  2638. begin
  2639. rttilist^.concat(new(pai_const,init_32bit(
  2640. pvarsym(sym)^.address)));
  2641. typvalue:=0;
  2642. end
  2643. else
  2644. begin
  2645. if (pprocdef(def)^.options and povirtualmethod)=0 then
  2646. begin
  2647. rttilist^.concat(new(pai_const,init_symbol(strpnew(pprocdef(def)^.mangledname))));
  2648. typvalue:=1;
  2649. end
  2650. else
  2651. begin
  2652. { virtual method, write vmt offset }
  2653. rttilist^.concat(new(pai_const,init_32bit(pprocdef(def)^.extnumber*4+12)));
  2654. typvalue:=2;
  2655. end;
  2656. end;
  2657. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  2658. end;
  2659. begin
  2660. if (ppropertysym(sym)^.options and ppo_indexed)<>0 then
  2661. proctypesinfo:=$40
  2662. else
  2663. proctypesinfo:=0;
  2664. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2665. begin
  2666. rttilist^.concat(new(pai_const,init_symbol(strpnew(ppropertysym(sym)^.proptype^.get_rtti_label))));
  2667. writeproc(ppropertysym(sym)^.readaccesssym,ppropertysym(sym)^.readaccessdef,0);
  2668. writeproc(ppropertysym(sym)^.writeaccesssym,ppropertysym(sym)^.writeaccessdef,2);
  2669. { isn't it stored ? }
  2670. if (ppropertysym(sym)^.options and ppo_stored)=0 then
  2671. begin
  2672. rttilist^.concat(new(pai_const,init_32bit(1)));
  2673. proctypesinfo:=proctypesinfo or (3 shl 4);
  2674. end
  2675. else
  2676. writeproc(ppropertysym(sym)^.storedsym,ppropertysym(sym)^.storeddef,4);
  2677. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.index)));
  2678. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.default)));
  2679. rttilist^.concat(new(pai_const,init_16bit(count)));
  2680. inc(count);
  2681. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  2682. rttilist^.concat(new(pai_const,init_8bit(length(ppropertysym(sym)^.name))));
  2683. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  2684. end;
  2685. end;
  2686. procedure generate_published_child_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  2687. begin
  2688. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2689. ppropertysym(sym)^.proptype^.get_rtti_label;
  2690. end;
  2691. procedure tobjectdef.write_child_rtti_data;
  2692. begin
  2693. publicsyms^.foreach(generate_published_child_rtti);
  2694. end;
  2695. procedure tobjectdef.generate_rtti;
  2696. begin
  2697. has_rtti:=true;
  2698. getlabel(rtti_label);
  2699. write_child_rtti_data;
  2700. rttilist^.concat(new(pai_symbol,init_global(rtti_name)));
  2701. rttilist^.concat(new(pai_label,init(rtti_label)));
  2702. write_rtti_data;
  2703. end;
  2704. function tobjectdef.next_free_name_index : longint;
  2705. var
  2706. i : longint;
  2707. begin
  2708. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2709. i:=childof^.next_free_name_index
  2710. else
  2711. i:=0;
  2712. count:=0;
  2713. publicsyms^.foreach(count_published_properties);
  2714. next_free_name_index:=i+count;
  2715. end;
  2716. procedure tobjectdef.write_rtti_data;
  2717. begin
  2718. if isclass then
  2719. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2720. else
  2721. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2722. { generate the name }
  2723. rttilist^.concat(new(pai_const,init_8bit(length(name^))));
  2724. rttilist^.concat(new(pai_string,init(name^)));
  2725. { write class type }
  2726. rttilist^.concat(new(pai_const,init_symbol(strpnew(vmt_mangledname))));
  2727. { write owner typeinfo }
  2728. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2729. rttilist^.concat(new(pai_const,init_symbol(strpnew(childof^.get_rtti_label))))
  2730. else
  2731. rttilist^.concat(new(pai_const,init_32bit(0)));
  2732. { count total number of properties }
  2733. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2734. count:=childof^.next_free_name_index
  2735. else
  2736. count:=0;
  2737. { write it }
  2738. publicsyms^.foreach(count_published_properties);
  2739. rttilist^.concat(new(pai_const,init_16bit(count)));
  2740. { write unit name }
  2741. if assigned(owner^.name) then
  2742. begin
  2743. rttilist^.concat(new(pai_const,init_8bit(length(owner^.name^))));
  2744. rttilist^.concat(new(pai_string,init(owner^.name^)));
  2745. end
  2746. else
  2747. rttilist^.concat(new(pai_const,init_8bit(0)));
  2748. { write published properties count }
  2749. count:=0;
  2750. publicsyms^.foreach(count_published_properties);
  2751. rttilist^.concat(new(pai_const,init_16bit(count)));
  2752. { count is used to write nameindex }
  2753. { but we need an offset of the owner }
  2754. { to give each property an own slot }
  2755. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2756. count:=childof^.next_free_name_index
  2757. else
  2758. count:=0;
  2759. publicsyms^.foreach(write_property_info);
  2760. end;
  2761. function tobjectdef.is_publishable : boolean;
  2762. begin
  2763. is_publishable:=isclass;
  2764. end;
  2765. function tobjectdef.get_rtti_label : string;
  2766. begin
  2767. get_rtti_label:=rtti_name;
  2768. end;
  2769. {****************************************************************************
  2770. TERRORDEF
  2771. ****************************************************************************}
  2772. constructor terrordef.init;
  2773. begin
  2774. inherited init;
  2775. deftype:=errordef;
  2776. end;
  2777. {$ifdef GDB}
  2778. function terrordef.stabstring : pchar;
  2779. begin
  2780. stabstring:=strpnew('error'+numberstring);
  2781. end;
  2782. {$endif GDB}
  2783. {
  2784. $Log$
  2785. Revision 1.79 1998-12-08 10:18:12 peter
  2786. + -gh for heaptrc unit
  2787. Revision 1.78 1998/12/08 09:06:30 pierre
  2788. + constructor destructor info for gdbpas
  2789. Revision 1.77 1998/12/01 23:37:39 pierre
  2790. * function type problem for gdb fix
  2791. Revision 1.76 1998/11/29 21:45:48 florian
  2792. * problem with arrays with init tables fixed
  2793. Revision 1.75 1998/11/29 12:45:59 peter
  2794. * hack for arraydef.size overflow
  2795. Revision 1.74 1998/11/27 14:50:47 peter
  2796. + open strings, $P switch support
  2797. Revision 1.73 1998/11/26 14:47:00 michael
  2798. + Fixed RTTI constants
  2799. Revision 1.72 1998/11/25 14:35:28 florian
  2800. * writting of rtti for properties fixed
  2801. Revision 1.71 1998/11/20 15:35:59 florian
  2802. * problems with rtti fixed, hope it works
  2803. Revision 1.70 1998/11/18 15:44:16 peter
  2804. * VALUEPARA for tp7 compatible value parameters
  2805. Revision 1.69 1998/11/10 17:54:56 peter
  2806. * removed warning
  2807. Revision 1.68 1998/11/05 23:34:36 peter
  2808. * don't dispose staticsymtable (caused crash under tp7 after a fatal
  2809. error)
  2810. Revision 1.67 1998/11/05 12:02:56 peter
  2811. * released useansistring
  2812. * removed -Sv, its now available in fpc modes
  2813. Revision 1.66 1998/10/26 22:58:22 florian
  2814. * new introduded problem with classes fix, the parent class wasn't set
  2815. correct, if the class was defined forward before
  2816. Revision 1.65 1998/10/26 14:19:28 pierre
  2817. + added options -lS and -lT for source and target os output
  2818. (to have a easier way to test OS_SOURCE abd OS_TARGET in makefiles)
  2819. * several problems with rtti data
  2820. (type of sym was not checked)
  2821. assumed to be varsym when they could be procsym or property syms !!
  2822. Revision 1.64 1998/10/22 17:11:21 pierre
  2823. + terminated the include exclude implementation for i386
  2824. * enums inside records fixed
  2825. Revision 1.63 1998/10/20 09:32:56 peter
  2826. * removed some unused vars
  2827. Revision 1.62 1998/10/20 08:06:58 pierre
  2828. * several memory corruptions due to double freemem solved
  2829. => never use p^.loc.location:=p^.left^.loc.location;
  2830. + finally I added now by default
  2831. that ra386dir translates global and unit symbols
  2832. + added a first field in tsymtable and
  2833. a nextsym field in tsym
  2834. (this allows to obtain ordered type info for
  2835. records and objects in gdb !)
  2836. Revision 1.61 1998/10/19 08:55:05 pierre
  2837. * wrong stabs info corrected once again !!
  2838. + variable vmt offset with vmt field only if required
  2839. implemented now !!!
  2840. Revision 1.60 1998/10/16 13:12:53 pierre
  2841. * added vmt_offsets in destructors code also !!!
  2842. * vmt_offset code for m68k
  2843. Revision 1.59 1998/10/16 08:51:51 peter
  2844. + target_os.stackalignment
  2845. + stack can be aligned at 2 or 4 byte boundaries
  2846. Revision 1.58 1998/10/15 15:13:30 pierre
  2847. + added oo_hasconstructor and oo_hasdestructor
  2848. for objects options
  2849. Revision 1.57 1998/10/14 15:54:20 pierre
  2850. * smallsets are not entirely implemented for
  2851. m68k added a ifdef usesmallset
  2852. that is allways defined for i386
  2853. (enables testing for m68k)
  2854. Revision 1.56 1998/10/09 11:47:56 pierre
  2855. * still more memory leaks fixes !!
  2856. Revision 1.55 1998/10/06 17:16:55 pierre
  2857. * some memory leaks fixed (thanks to Peter for heaptrc !)
  2858. Revision 1.54 1998/10/05 21:33:28 peter
  2859. * fixed 161,165,166,167,168
  2860. Revision 1.53 1998/10/05 12:48:39 pierre
  2861. * wrong handling of range check for arrays fixed
  2862. Revision 1.52 1998/10/02 07:20:38 florian
  2863. * range checking in units doesn't work if the units are smartlinked, fixed
  2864. Revision 1.51 1998/09/25 12:01:41 florian
  2865. * tobjectdef.publicsyms.datasize was set to savesize, this is wrong now
  2866. because the symtable size is read from the ppu file
  2867. Revision 1.50 1998/09/23 15:46:40 florian
  2868. * problem with with and classes fixed
  2869. Revision 1.49 1998/09/23 12:03:55 peter
  2870. * overloading fix for array of const
  2871. Revision 1.48 1998/09/22 15:37:23 peter
  2872. + array of const start
  2873. Revision 1.47 1998/09/21 15:46:01 michael
  2874. Applied florians fix for check_rec_inittable
  2875. Revision 1.46 1998/09/21 08:45:21 pierre
  2876. + added vmt_offset in tobjectdef.write for fututre use
  2877. (first steps to have objects without vmt if no virtual !!)
  2878. + added fpu_used field for tabstractprocdef :
  2879. sets this level to 2 if the functions return with value in FPU
  2880. (is then set to correct value at parsing of implementation)
  2881. THIS MIGHT refuse some code with FPU expression too complex
  2882. that were accepted before and even in some cases
  2883. that don't overflow in fact
  2884. ( like if f : float; is a forward that finally in implementation
  2885. only uses one fpu register !!)
  2886. Nevertheless I think that it will improve security on
  2887. FPU operations !!
  2888. * most other changes only for UseBrowser code
  2889. (added symtable references for record and objects)
  2890. local switch for refs to args and local of each function
  2891. (static symtable still missing)
  2892. UseBrowser still not stable and probably broken by
  2893. the definition hash array !!
  2894. Revision 1.45 1998/09/20 08:31:29 florian
  2895. + bit 6 of tpropinfo.propprocs is set, if the property contains a
  2896. constant index
  2897. Revision 1.44 1998/09/19 15:23:58 florian
  2898. * rtti for ordtypes corrected
  2899. Revision 1.43 1998/09/18 17:12:40 florian
  2900. * problem with writing of class references fixed
  2901. Revision 1.42 1998/09/17 13:41:20 pierre
  2902. sizeof(TPOINT) problem
  2903. Revision 1.40.2.2 1998/09/17 08:42:33 pierre
  2904. TPOINT sizeof fix
  2905. Revision 1.41 1998/09/15 17:39:30 jonas
  2906. + bugfix from bugfix branch
  2907. Revision 1.40.2.1 1998/09/15 17:35:32 jonas
  2908. * chenged string_typ in tstringdef.wideload from ansistring to widestring
  2909. Revision 1.40 1998/09/09 15:34:00 peter
  2910. * removed warnings
  2911. Revision 1.39 1998/09/08 10:23:44 pierre
  2912. * name field of filedef corrected
  2913. Revision 1.38 1998/09/07 23:10:23 florian
  2914. * a lot of stuff fixed regarding rtti and publishing of properties,
  2915. basics should now work
  2916. Revision 1.37 1998/09/07 19:33:24 florian
  2917. + some stuff for property rtti added:
  2918. - NameIndex of the TPropInfo record is now written correctly
  2919. - the DEFAULT/NODEFAULT keyword is supported now
  2920. - the default value and the storedsym/def are now written to
  2921. the PPU fiel
  2922. Revision 1.36 1998/09/07 17:37:01 florian
  2923. * first fixes for published properties
  2924. Revision 1.35 1998/09/06 22:42:02 florian
  2925. + rtti genreation for properties added
  2926. Revision 1.34 1998/09/04 18:15:02 peter
  2927. * filedef updated
  2928. Revision 1.33 1998/09/03 17:08:49 pierre
  2929. * better lines for stabs
  2930. (no scroll back to if before else part
  2931. no return to case line at jump outside case)
  2932. + source lines also if not in order
  2933. Revision 1.32 1998/09/03 16:03:20 florian
  2934. + rtti generation
  2935. * init table generation changed
  2936. Revision 1.31 1998/09/02 15:14:28 peter
  2937. * enum packing changed from len to max
  2938. Revision 1.30 1998/09/01 17:37:29 peter
  2939. * removed debug writeln :(
  2940. Revision 1.29 1998/09/01 12:53:25 peter
  2941. + aktpackenum
  2942. Revision 1.28 1998/09/01 07:54:22 pierre
  2943. * UseBrowser a little updated (might still be buggy !!)
  2944. * bug in psub.pas in function specifier removed
  2945. * stdcall allowed in interface and in implementation
  2946. (FPC will not yet complain if it is missing in either part
  2947. because stdcall is only a dummy !!)
  2948. Revision 1.27 1998/08/28 12:51:43 florian
  2949. + ansistring to pchar type cast fixed
  2950. Revision 1.26 1998/08/25 12:42:44 pierre
  2951. * CDECL changed to CVAR for variables
  2952. specifications are read in structures also
  2953. + started adding GPC compatibility mode ( option -Sp)
  2954. * names changed to lowercase
  2955. Revision 1.25 1998/08/23 21:04:38 florian
  2956. + rtti generation for classes added
  2957. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  2958. Revision 1.24 1998/08/20 12:53:26 peter
  2959. * object_options are always written for object syms
  2960. Revision 1.23 1998/08/19 00:42:42 peter
  2961. + subrange types for enums
  2962. + checking for bounds type with ranges
  2963. Revision 1.22 1998/08/17 10:10:10 peter
  2964. - removed OLDPPU
  2965. Revision 1.21 1998/08/10 14:50:28 peter
  2966. + localswitches, moduleswitches, globalswitches splitting
  2967. Revision 1.20 1998/07/18 22:54:30 florian
  2968. * some ansi/wide/longstring support fixed:
  2969. o parameter passing
  2970. o returning as result from functions
  2971. Revision 1.19 1998/07/14 14:47:05 peter
  2972. * released NEWINPUT
  2973. Revision 1.18 1998/07/10 10:51:04 peter
  2974. * m68k updates
  2975. Revision 1.16 1998/07/07 11:20:13 peter
  2976. + NEWINPUT for a better inputfile and scanner object
  2977. Revision 1.15 1998/06/24 14:48:37 peter
  2978. * ifdef newppu -> ifndef oldppu
  2979. Revision 1.14 1998/06/16 08:56:31 peter
  2980. + targetcpu
  2981. * cleaner pmodules for newppu
  2982. Revision 1.13 1998/06/15 15:38:09 pierre
  2983. * small bug in systems.pas corrected
  2984. + operators in different units better hanlded
  2985. Revision 1.12 1998/06/15 14:30:12 daniel
  2986. * Reverted my changes.
  2987. Revision 1.10 1998/06/13 00:10:16 peter
  2988. * working browser and newppu
  2989. * some small fixes against crashes which occured in bp7 (but not in
  2990. fpc?!)
  2991. Revision 1.9 1998/06/12 14:10:37 michael
  2992. * Fixed wrong code for ansistring
  2993. Revision 1.8 1998/06/11 10:11:58 peter
  2994. * -gb works again
  2995. Revision 1.7 1998/06/07 15:30:25 florian
  2996. + first working rtti
  2997. + data init/final. for local variables
  2998. Revision 1.6 1998/06/05 14:37:37 pierre
  2999. * fixes for inline for operators
  3000. * inline procedure more correctly restricted
  3001. Revision 1.5 1998/06/04 23:52:01 peter
  3002. * m68k compiles
  3003. + .def file creation moved to gendef.pas so it could also be used
  3004. for win32
  3005. Revision 1.4 1998/06/04 09:55:45 pierre
  3006. * demangled name of procsym reworked to become independant of the mangling
  3007. scheme
  3008. Revision 1.3 1998/06/03 22:49:03 peter
  3009. + wordbool,longbool
  3010. * rename bis,von -> high,low
  3011. * moved some systemunit loading/creating to psystem.pas
  3012. Revision 1.2 1998/05/31 14:13:37 peter
  3013. * fixed call bugs with assembler readers
  3014. + OPR_SYMBOL to hold a symbol in the asm parser
  3015. * fixed staticsymtable vars which were acessed through %ebp instead of
  3016. name
  3017. Revision 1.1 1998/05/27 19:45:09 peter
  3018. * symtable.pas splitted into includefiles
  3019. * symtable adapted for $ifndef OLDPPU
  3020. }