symdef.inc 90 KB

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