symdef.inc 75 KB

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