symdef.inc 68 KB

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