symdef.inc 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376
  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. von:=v;
  486. bis:=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. von:=readlong;
  496. bis:=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 bis<0 and von>=0 }
  505. if (von>=0) and (bis<0) then
  506. begin
  507. savesize:=4;
  508. typ:=u32bit;
  509. end
  510. else if (von>=0) and (bis<=255) then
  511. begin
  512. savesize:=1;
  513. typ:=u8bit;
  514. end
  515. else if (von>=-128) and (bis<=127) then
  516. begin
  517. savesize:=1;
  518. typ:=s8bit;
  519. end
  520. else if (von>=0) and (bis<=65536) then
  521. begin
  522. savesize:=2;
  523. typ:=u16bit;
  524. end
  525. else if (von>=-32768) and (bis<=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. case typ of
  538. uchar,u8bit,bool8bit,s8bit : savesize:=1;
  539. u16bit,s16bit : savesize:=2;
  540. s32bit,u32bit : savesize:=4;
  541. else savesize:=0;
  542. end;
  543. { there are no entrys for range checking }
  544. rangenr:=0;
  545. end;
  546. procedure torddef.genrangecheck;
  547. begin
  548. if rangenr=0 then
  549. begin
  550. { generate two constant for bounds }
  551. getlabelnr(rangenr);
  552. if (cs_smartlink in aktswitches) then
  553. datasegment^.concat(new(pai_symbol,init_global('R_'+current_module^.mainsource^+tostr(rangenr))))
  554. else
  555. datasegment^.concat(new(pai_symbol,init('R_'+tostr(rangenr))));
  556. if von<=bis then
  557. begin
  558. datasegment^.concat(new(pai_const,init_32bit(von)));
  559. datasegment^.concat(new(pai_const,init_32bit(bis)));
  560. end
  561. { for u32bit we need two bounds }
  562. else
  563. begin
  564. datasegment^.concat(new(pai_const,init_32bit(von)));
  565. datasegment^.concat(new(pai_const,init_32bit($7fffffff)));
  566. inc(nextlabelnr);
  567. if (cs_smartlink in aktswitches) then
  568. datasegment^.concat(new(pai_symbol,init_global('R_'+current_module^.mainsource^+tostr(rangenr+1))))
  569. else
  570. datasegment^.concat(new(pai_symbol,init('R_'+tostr(rangenr+1))));
  571. datasegment^.concat(new(pai_const,init_32bit($80000000)));
  572. datasegment^.concat(new(pai_const,init_32bit(bis)));
  573. end;
  574. end;
  575. end;
  576. procedure torddef.write;
  577. begin
  578. {$ifndef NEWPPU}
  579. writebyte(iborddef);
  580. {$endif}
  581. tdef.write;
  582. writebyte(byte(typ));
  583. writelong(von);
  584. writelong(bis);
  585. {$ifdef NEWPPU}
  586. ppufile.writeentry(iborddef);
  587. {$endif}
  588. end;
  589. {$ifdef GDB}
  590. function torddef.stabstring : pchar;
  591. begin
  592. case typ of
  593. uvoid : stabstring := strpnew(numberstring+';');
  594. {GDB 4.12 for go32 doesn't like boolean as range for 0 to 1 !!!}
  595. bool8bit : stabstring := strpnew('r'+numberstring+';0;255;');
  596. { u32bit : stabstring := strpnew('r'+
  597. s32bitdef^.numberstring+';0;-1;'); }
  598. else
  599. stabstring := strpnew('r'+s32bitdef^.numberstring+';'+tostr(von)+';'+tostr(bis)+';');
  600. end;
  601. end;
  602. {$endif GDB}
  603. {*************************************************************************************************************************
  604. TFLOATDEF
  605. ****************************************************************************}
  606. constructor tfloatdef.init(t : tfloattype);
  607. begin
  608. tdef.init;
  609. deftype:=floatdef;
  610. typ:=t;
  611. setsize;
  612. end;
  613. constructor tfloatdef.load;
  614. begin
  615. tdef.load;
  616. deftype:=floatdef;
  617. typ:=tfloattype(readbyte);
  618. setsize;
  619. end;
  620. procedure tfloatdef.setsize;
  621. begin
  622. case typ of
  623. f16bit:
  624. savesize:=2;
  625. f32bit,s32real:
  626. savesize:=4;
  627. s64real:
  628. savesize:=8;
  629. s64bit:
  630. savesize:=8;
  631. s80real:
  632. savesize:=extended_size;
  633. else savesize:=0;
  634. end;
  635. end;
  636. procedure tfloatdef.write;
  637. begin
  638. {$ifndef NEWPPU}
  639. writebyte(ibfloatdef);
  640. {$endif}
  641. tdef.write;
  642. writebyte(byte(typ));
  643. {$ifdef NEWPPU}
  644. ppufile.writeentry(ibfloatdef);
  645. {$endif}
  646. end;
  647. {$ifdef GDB}
  648. function tfloatdef.stabstring : pchar;
  649. begin
  650. case typ of
  651. s32real,
  652. s64real : stabstring := strpnew('r'+
  653. s32bitdef^.numberstring+';'+tostr(savesize)+';0;');
  654. { for fixed real use longint instead to be able to }
  655. { debug something at least }
  656. f32bit:
  657. stabstring := s32bitdef^.stabstring;
  658. f16bit:
  659. stabstring := strpnew('r'+s32bitdef^.numberstring+';0;'+
  660. tostr($ffff)+';');
  661. { found this solution in stabsread.c from GDB v4.16 }
  662. s64bit : stabstring := strpnew('r'+
  663. s32bitdef^.numberstring+';-'+tostr(savesize)+';0;');
  664. {$ifdef i386}
  665. { under dos at least you must give a size of twelve instead of 10 !! }
  666. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  667. s80real : stabstring := strpnew('r'+s32bitdef^.numberstring+';12;0;');
  668. {$endif i386}
  669. else
  670. internalerror(10005);
  671. end;
  672. end;
  673. {$endif GDB}
  674. {*************************************************************************************************************************
  675. TFILEDEF
  676. ****************************************************************************}
  677. constructor tfiledef.init(ft : tfiletype;tas : pdef);
  678. begin
  679. inherited init;
  680. deftype:=filedef;
  681. filetype:=ft;
  682. typed_as:=tas;
  683. setsize;
  684. end;
  685. constructor tfiledef.load;
  686. begin
  687. tdef.load;
  688. deftype:=filedef;
  689. filetype:=tfiletype(readbyte);
  690. if filetype=ft_typed then
  691. typed_as:=readdefref
  692. else
  693. typed_as:=nil;
  694. setsize;
  695. end;
  696. procedure tfiledef.deref;
  697. begin
  698. if filetype=ft_typed then
  699. resolvedef(typed_as);
  700. end;
  701. procedure tfiledef.setsize;
  702. begin
  703. case target_info.target of
  704. target_LINUX:
  705. begin
  706. case filetype of
  707. ft_text : savesize:=432;
  708. ft_typed,ft_untyped : savesize:=304;
  709. end;
  710. end;
  711. target_Win32:
  712. begin
  713. case filetype of
  714. ft_text : savesize:=434;
  715. ft_typed,ft_untyped : savesize:=306;
  716. end;
  717. end
  718. else
  719. begin
  720. case filetype of
  721. ft_text : savesize:=256;
  722. ft_typed,ft_untyped : savesize:=128;
  723. end;
  724. end;
  725. end;
  726. end;
  727. procedure tfiledef.write;
  728. begin
  729. {$ifndef NEWPPU}
  730. writebyte(ibfiledef);
  731. {$endif}
  732. tdef.write;
  733. writebyte(byte(filetype));
  734. if filetype=ft_typed then
  735. writedefref(typed_as);
  736. {$ifdef NEWPPU}
  737. ppufile.writeentry(ibfiledef);
  738. {$endif}
  739. end;
  740. {$ifdef GDB}
  741. function tfiledef.stabstring : pchar;
  742. var Handlebitsize,namesize : longint;
  743. Handledef :string;
  744. begin
  745. {$IfDef GDBknowsfiles}
  746. case filetyp of
  747. ft_typed : stabstring := strpnew('d'+typed_as^.numberstring{+';'});
  748. ft_untyped : stabstring := strpnew('d'+voiddef^.numberstring{+';'});
  749. ft_text : stabstring := strpnew('d'+cchardef^.numberstring{+';'});
  750. end;
  751. {$Else }
  752. {based on
  753. filerec = record
  754. handle : word;
  755. mode : word;
  756. recsize : word;
  757. _private : array[1..26] of byte;
  758. userdata : array[1..16] of byte;
  759. name : string[79 or 255 for linux]; }
  760. if (target_info.target=target_GO32V1) or
  761. (target_info.target=target_GO32V2) then
  762. namesize:=79
  763. else
  764. namesize:=255;
  765. if (target_info.target=target_Win32) then
  766. begin
  767. Handledef:='longint';
  768. Handlebitsize:=32;
  769. end
  770. else
  771. begin
  772. Handledef:='word';
  773. HandleBitSize:=16;
  774. end;
  775. { the buffer part is still missing !! (PM) }
  776. { but the string could become too long !! }
  777. stabstring := strpnew('s'+tostr(savesize)+
  778. 'HANDLE:'+typeglobalnumber(Handledef)+',0,'+tostr(HandleBitSize)+';'+
  779. 'MODE:'+typeglobalnumber('word')+','+tostr(HandleBitSize)+',16;'+
  780. 'RECSIZE:'+typeglobalnumber('word')+','+tostr(HandleBitSize+16)+',16;'+
  781. '_PRIVATE:ar'+typeglobalnumber('word')+';1;26;'+typeglobalnumber('byte')
  782. +','+tostr(HandleBitSize+32)+',208;'+
  783. 'USERDATA:ar'+typeglobalnumber('word')+';1;16;'+typeglobalnumber('byte')
  784. +','+tostr(HandleBitSize+240)+',128;'+
  785. { 'NAME:s'+tostr(namesize+1)+
  786. 'length:'+typeglobalnumber('byte')+',0,8;'+
  787. 'st:ar'+typeglobalnumber('word')+';1;'
  788. +tostr(namesize)+';'+typeglobalnumber('char')+',8,'+tostr(8*namesize)+';;'+}
  789. 'NAME:ar'+typeglobalnumber('word')+';0;'
  790. +tostr(namesize)+';'+typeglobalnumber('char')+
  791. ','+tostr(HandleBitSize+368)+','+tostr(8*(namesize+1))+';;');
  792. {$EndIf}
  793. end;
  794. procedure tfiledef.concatstabto(asmlist : paasmoutput);
  795. begin
  796. { most file defs are unnamed !!! }
  797. if ((sym = nil) or sym^.isusedinstab or use_dbx) and not is_def_stab_written then
  798. begin
  799. if assigned(typed_as) then forcestabto(asmlist,typed_as);
  800. inherited concatstabto(asmlist);
  801. end;
  802. end;
  803. {$endif GDB}
  804. {*************************************************************************************************************************
  805. TPOINTERDEF
  806. ****************************************************************************}
  807. constructor tpointerdef.init(def : pdef);
  808. begin
  809. inherited init;
  810. deftype:=pointerdef;
  811. definition:=def;
  812. savesize:=Sizeof(pointer);
  813. end;
  814. constructor tpointerdef.load;
  815. begin
  816. tdef.load;
  817. deftype:=pointerdef;
  818. { the real address in memory is calculated later (deref) }
  819. definition:=readdefref;
  820. savesize:=Sizeof(pointer);
  821. end;
  822. procedure tpointerdef.deref;
  823. begin
  824. resolvedef(definition);
  825. end;
  826. procedure tpointerdef.write;
  827. begin
  828. {$ifndef NEWPPU}
  829. writebyte(ibpointerdef);
  830. {$endif}
  831. tdef.write;
  832. writedefref(definition);
  833. {$ifdef NEWPPU}
  834. ppufile.writeentry(ibpointerdef);
  835. {$endif}
  836. end;
  837. {$ifdef GDB}
  838. function tpointerdef.stabstring : pchar;
  839. begin
  840. stabstring := strpnew('*'+definition^.numberstring);
  841. end;
  842. procedure tpointerdef.concatstabto(asmlist : paasmoutput);
  843. var st,nb : string;
  844. sym_line_no : longint;
  845. begin
  846. if ( (sym=nil) or sym^.isusedinstab or use_dbx) and not is_def_stab_written then
  847. begin
  848. if assigned(definition) then
  849. if definition^.deftype in [recorddef,objectdef] then
  850. begin
  851. is_def_stab_written := true;
  852. {to avoid infinite recursion in record with next-like fields }
  853. nb := definition^.numberstring;
  854. is_def_stab_written := false;
  855. if not definition^.is_def_stab_written then
  856. begin
  857. if assigned(definition^.sym) then
  858. begin
  859. if assigned(sym) then
  860. begin
  861. st := sym^.name;
  862. sym_line_no:=sym^.line_no;
  863. end
  864. else
  865. begin
  866. st := ' ';
  867. sym_line_no:=0;
  868. end;
  869. st := '"'+st+':t'+numberstring+'=*'+definition^.numberstring
  870. +'=xs'+definition^.sym^.name+':",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0';
  871. if asmlist = debuglist then do_count_dbx := true;
  872. asmlist^.concat(new(pai_stabs,init(strpnew(st))));
  873. end;
  874. end else inherited concatstabto(asmlist);
  875. is_def_stab_written := true;
  876. end else
  877. begin
  878. forcestabto(asmlist,definition);
  879. inherited concatstabto(asmlist);
  880. end;
  881. end;
  882. end;
  883. {$endif GDB}
  884. {*************************************************************************************************************************
  885. TCLASSREFDEF
  886. ****************************************************************************}
  887. constructor tclassrefdef.init(def : pdef);
  888. begin
  889. inherited init(def);
  890. deftype:=classrefdef;
  891. definition:=def;
  892. savesize:=Sizeof(pointer);
  893. end;
  894. constructor tclassrefdef.load;
  895. begin
  896. inherited load;
  897. deftype:=classrefdef;
  898. end;
  899. procedure tclassrefdef.write;
  900. begin
  901. {$ifndef NEWPPU}
  902. writebyte(ibclassrefdef);
  903. {$endif}
  904. tdef.write;
  905. writedefref(definition);
  906. {$ifdef NEWPPU}
  907. ppufile.writeentry(ibclassrefdef);
  908. {$endif}
  909. end;
  910. {$ifdef GDB}
  911. function tclassrefdef.stabstring : pchar;
  912. begin
  913. stabstring:=strpnew('');
  914. end;
  915. procedure tclassrefdef.concatstabto(asmlist : paasmoutput);
  916. begin
  917. end;
  918. {$endif GDB}
  919. {***********************************************************************************
  920. TSETDEF
  921. ***************************************************************************}
  922. constructor tsetdef.init(s : pdef;high : longint);
  923. begin
  924. inherited init;
  925. deftype:=setdef;
  926. setof:=s;
  927. if high<32 then
  928. begin
  929. settype:=smallset;
  930. savesize:=Sizeof(longint);
  931. end
  932. else
  933. if high<256 then
  934. begin
  935. settype:=normset;
  936. savesize:=32;
  937. end
  938. else
  939. {$ifdef testvarsets}
  940. if high<$10000 then
  941. begin
  942. settype:=varset;
  943. savesize:=4*((high+31) div 32);
  944. end
  945. else
  946. {$endif testvarsets}
  947. Message(sym_e_ill_type_decl_set);
  948. end;
  949. constructor tsetdef.load;
  950. begin
  951. tdef.load;
  952. deftype:=setdef;
  953. setof:=readdefref;
  954. settype:=tsettype(readbyte);
  955. case settype of
  956. normset : savesize:=32;
  957. varset : savesize:=readlong;
  958. smallset : savesize:=Sizeof(longint);
  959. end;
  960. end;
  961. procedure tsetdef.write;
  962. begin
  963. {$ifndef NEWPPU}
  964. writebyte(ibsetdef);
  965. {$endif}
  966. tdef.write;
  967. writedefref(setof);
  968. writebyte(byte(settype));
  969. if settype=varset then
  970. writelong(savesize);
  971. {$ifdef NEWPPU}
  972. ppufile.writeentry(ibsetdef);
  973. {$endif}
  974. end;
  975. {$ifdef GDB}
  976. function tsetdef.stabstring : pchar;
  977. begin
  978. stabstring := strpnew('S'+setof^.numberstring);
  979. end;
  980. procedure tsetdef.concatstabto(asmlist : paasmoutput);
  981. begin
  982. if ( not assigned(sym) or sym^.isusedinstab or use_dbx) and
  983. not is_def_stab_written then
  984. begin
  985. if assigned(setof) then
  986. forcestabto(asmlist,setof);
  987. inherited concatstabto(asmlist);
  988. end;
  989. end;
  990. {$endif GDB}
  991. procedure tsetdef.deref;
  992. begin
  993. resolvedef(setof);
  994. end;
  995. {***********************************************************************************
  996. TFORMALDEF
  997. ***************************************************************************}
  998. constructor tformaldef.init;
  999. begin
  1000. inherited init;
  1001. deftype:=formaldef;
  1002. savesize:=Sizeof(pointer);
  1003. end;
  1004. constructor tformaldef.load;
  1005. begin
  1006. tdef.load;
  1007. deftype:=formaldef;
  1008. savesize:=Sizeof(pointer);
  1009. end;
  1010. procedure tformaldef.write;
  1011. begin
  1012. {$ifndef NEWPPU}
  1013. writebyte(ibformaldef);
  1014. {$endif}
  1015. tdef.write;
  1016. {$ifdef NEWPPU}
  1017. ppufile.writeentry(ibformaldef);
  1018. {$endif}
  1019. end;
  1020. {$ifdef GDB}
  1021. function tformaldef.stabstring : pchar;
  1022. begin
  1023. stabstring := strpnew('formal'+numberstring+';');
  1024. end;
  1025. procedure tformaldef.concatstabto(asmlist : paasmoutput);
  1026. begin
  1027. { formaldef can't be stab'ed !}
  1028. end;
  1029. {$endif GDB}
  1030. {***********************************************************************************
  1031. TARRAYDEF
  1032. ***************************************************************************}
  1033. constructor tarraydef.init(l,h : longint;rd : pdef);
  1034. begin
  1035. tdef.init;
  1036. deftype:=arraydef;
  1037. lowrange:=l;
  1038. highrange:=h;
  1039. rangedef:=rd;
  1040. rangenr:=0;
  1041. definition:=nil;
  1042. end;
  1043. constructor tarraydef.load;
  1044. begin
  1045. tdef.load;
  1046. deftype:=arraydef;
  1047. { the addresses are calculated later }
  1048. definition:=readdefref;
  1049. rangedef:=readdefref;
  1050. lowrange:=readlong;
  1051. highrange:=readlong;
  1052. rangenr:=0;
  1053. end;
  1054. procedure tarraydef.genrangecheck;
  1055. begin
  1056. if rangenr=0 then
  1057. begin
  1058. { generates the data for range checking }
  1059. getlabelnr(rangenr);
  1060. datasegment^.concat(new(pai_symbol,init('R_'+tostr(rangenr))));
  1061. datasegment^.concat(new(pai_const,init_32bit(lowrange)));
  1062. datasegment^.concat(new(pai_const,init_32bit(highrange)));
  1063. end;
  1064. end;
  1065. procedure tarraydef.deref;
  1066. begin
  1067. resolvedef(definition);
  1068. resolvedef(rangedef);
  1069. end;
  1070. procedure tarraydef.write;
  1071. begin
  1072. {$ifndef NEWPPU}
  1073. writebyte(ibarraydef);
  1074. {$endif}
  1075. tdef.write;
  1076. writedefref(definition);
  1077. writedefref(rangedef);
  1078. writelong(lowrange);
  1079. writelong(highrange);
  1080. {$ifdef NEWPPU}
  1081. ppufile.writeentry(ibarraydef);
  1082. {$endif}
  1083. end;
  1084. {$ifdef GDB}
  1085. function tarraydef.stabstring : pchar;
  1086. begin
  1087. stabstring := strpnew('ar'+rangedef^.numberstring+';'
  1088. +tostr(lowrange)+';'+tostr(highrange)+';'+definition^.numberstring);
  1089. end;
  1090. procedure tarraydef.concatstabto(asmlist : paasmoutput);
  1091. begin
  1092. if (not assigned(sym) or sym^.isusedinstab or use_dbx)
  1093. and not is_def_stab_written then
  1094. begin
  1095. {when array are inserted they have no definition yet !!}
  1096. if assigned(definition) then
  1097. inherited concatstabto(asmlist);
  1098. end;
  1099. end;
  1100. {$endif GDB}
  1101. function tarraydef.elesize : longint;
  1102. begin
  1103. elesize:=definition^.size;
  1104. end;
  1105. function tarraydef.size : longint;
  1106. begin
  1107. size:=(highrange-lowrange+1)*elesize;
  1108. end;
  1109. function tarraydef.needs_rtti : boolean;
  1110. begin
  1111. needs_rtti:=definition^.needs_rtti;
  1112. end;
  1113. {***********************************************************************************
  1114. TRECDEF
  1115. ***************************************************************************}
  1116. constructor trecdef.init(p : psymtable);
  1117. begin
  1118. tdef.init;
  1119. deftype:=recorddef;
  1120. symtable:=p;
  1121. savesize:=symtable^.datasize;
  1122. symtable^.defowner := @self;
  1123. end;
  1124. constructor trecdef.load;
  1125. var
  1126. oldread_member : boolean;
  1127. begin
  1128. tdef.load;
  1129. deftype:=recorddef;
  1130. savesize:=readlong;
  1131. oldread_member:=read_member;
  1132. read_member:=true;
  1133. symtable:=new(psymtable,loadasstruct(recordsymtable));
  1134. read_member:=oldread_member;
  1135. symtable^.defowner := @self;
  1136. end;
  1137. destructor trecdef.done;
  1138. begin
  1139. if assigned(symtable) then dispose(symtable,done);
  1140. inherited done;
  1141. end;
  1142. var
  1143. brtti : boolean;
  1144. procedure check_rec_rtti(s : psym);
  1145. begin
  1146. if (s^.typ=varsym) and (pvarsym(s)^.definition^.needs_rtti) then
  1147. brtti:=true;
  1148. end;
  1149. function trecdef.needs_rtti : boolean;
  1150. var
  1151. oldb : boolean;
  1152. begin
  1153. { there are recursive calls to needs_rtti possible, }
  1154. { so we have to change to old value how else should }
  1155. { we do that ? check_rec_rtti can't be a nested }
  1156. { procedure of needs_rtti ! }
  1157. oldb:=brtti;
  1158. brtti:=false;
  1159. symtable^.foreach(check_rec_rtti);
  1160. needs_rtti:=brtti;
  1161. brtti:=oldb;
  1162. end;
  1163. procedure trecdef.deref;
  1164. var
  1165. hp : pdef;
  1166. oldrecsyms : psymtable;
  1167. begin
  1168. oldrecsyms:=aktrecordsymtable;
  1169. aktrecordsymtable:=symtable;
  1170. { now dereference the definitions }
  1171. hp:=symtable^.rootdef;
  1172. while assigned(hp) do
  1173. begin
  1174. hp^.deref;
  1175. { set owner }
  1176. hp^.owner:=symtable;
  1177. hp:=hp^.next;
  1178. end;
  1179. {$ifdef tp}
  1180. symtable^.foreach(derefsym);
  1181. {$else}
  1182. symtable^.foreach(@derefsym);
  1183. {$endif}
  1184. aktrecordsymtable:=oldrecsyms;
  1185. end;
  1186. procedure trecdef.write;
  1187. var
  1188. oldread_member : boolean;
  1189. begin
  1190. oldread_member:=read_member;
  1191. read_member:=true;
  1192. {$ifndef NEWPPU}
  1193. writebyte(ibrecorddef);
  1194. {$endif}
  1195. tdef.write;
  1196. writelong(savesize);
  1197. {$ifdef NEWPPU}
  1198. ppufile.writeentry(ibrecorddef);
  1199. {$endif}
  1200. self.symtable^.writeasstruct;
  1201. read_member:=oldread_member;
  1202. end;
  1203. {$ifdef GDB}
  1204. Const StabRecString : pchar = Nil;
  1205. StabRecSize : longint = 0;
  1206. RecOffset : Longint = 0;
  1207. procedure addname(p : psym);
  1208. var
  1209. news, newrec : pchar;
  1210. begin
  1211. { static variables from objects are like global objects }
  1212. if ((p^.properties and sp_static)<>0) then
  1213. exit;
  1214. If p^.typ = varsym then
  1215. begin
  1216. newrec := strpnew(p^.name+':'+pvarsym(p)^.definition^.numberstring
  1217. +','+tostr(pvarsym(p)^.address*8)+','
  1218. +tostr(pvarsym(p)^.definition^.size*8)+';');
  1219. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1220. begin
  1221. getmem(news,stabrecsize+memsizeinc);
  1222. strcopy(news,stabrecstring);
  1223. freemem(stabrecstring,stabrecsize);
  1224. stabrecsize:=stabrecsize+memsizeinc;
  1225. stabrecstring:=news;
  1226. end;
  1227. strcat(StabRecstring,newrec);
  1228. strdispose(newrec);
  1229. {This should be used for case !!}
  1230. RecOffset := RecOffset + pvarsym(p)^.definition^.size;
  1231. end;
  1232. end;
  1233. function trecdef.stabstring : pchar;
  1234. Var oldrec : pchar;
  1235. oldsize : longint;
  1236. begin
  1237. oldrec := stabrecstring;
  1238. oldsize:=stabrecsize;
  1239. GetMem(stabrecstring,memsizeinc);
  1240. stabrecsize:=memsizeinc;
  1241. strpcopy(stabRecString,'s'+tostr(savesize));
  1242. RecOffset := 0;
  1243. {$ifdef tp}
  1244. symtable^.foreach(addname);
  1245. {$else}
  1246. symtable^.foreach(@addname);
  1247. {$endif}
  1248. { FPC doesn't want to convert a char to a pchar}
  1249. { is this a bug ? }
  1250. strpcopy(strend(StabRecString),';');
  1251. stabstring := strnew(StabRecString);
  1252. Freemem(stabrecstring,stabrecsize);
  1253. stabrecstring := oldrec;
  1254. stabrecsize:=oldsize;
  1255. end;
  1256. procedure trecdef.concatstabto(asmlist : paasmoutput);
  1257. begin
  1258. if (not assigned(sym) or sym^.isusedinstab or use_dbx) and
  1259. (not is_def_stab_written) then
  1260. inherited concatstabto(asmlist);
  1261. end;
  1262. {$endif GDB}
  1263. {***********************************************************************************
  1264. TABSTRACTPROCDEF
  1265. ***************************************************************************}
  1266. constructor tabstractprocdef.init;
  1267. begin
  1268. inherited init;
  1269. para1:=nil;
  1270. {$ifdef StoreFPULevel}
  1271. fpu_used:=255;
  1272. {$endif StoreFPULevel}
  1273. options:=0;
  1274. retdef:=voiddef;
  1275. savesize:=Sizeof(pointer);
  1276. end;
  1277. destructor tabstractprocdef.done;
  1278. var
  1279. hp : pdefcoll;
  1280. begin
  1281. hp:=para1;
  1282. while assigned(hp) do
  1283. begin
  1284. para1:=hp^.next;
  1285. dispose(hp);
  1286. hp:=para1;
  1287. end;
  1288. inherited done;
  1289. end;
  1290. procedure tabstractprocdef.concatdef(p : pdef;vsp : tvarspez);
  1291. var
  1292. hp : pdefcoll;
  1293. begin
  1294. new(hp);
  1295. hp^.paratyp:=vsp;
  1296. hp^.data:=p;
  1297. hp^.next:=para1;
  1298. para1:=hp;
  1299. end;
  1300. procedure tabstractprocdef.deref;
  1301. var
  1302. hp : pdefcoll;
  1303. begin
  1304. inherited deref;
  1305. resolvedef(retdef);
  1306. hp:=para1;
  1307. while assigned(hp) do
  1308. begin
  1309. resolvedef(hp^.data);
  1310. hp:=hp^.next;
  1311. end;
  1312. end;
  1313. constructor tabstractprocdef.load;
  1314. var
  1315. last,hp : pdefcoll;
  1316. count,i : word;
  1317. begin
  1318. tdef.load;
  1319. retdef:=readdefref;
  1320. {$ifdef StoreFPULevel}
  1321. fpu_used:=readbyte;
  1322. {$endif StoreFPULevel}
  1323. options:=readlong;
  1324. count:=readword;
  1325. para1:=nil;
  1326. savesize:=Sizeof(pointer);
  1327. for i:=1 to count do
  1328. begin
  1329. new(hp);
  1330. hp^.paratyp:=tvarspez(readbyte);
  1331. hp^.data:=readdefref;
  1332. hp^.next:=nil;
  1333. if para1=nil then
  1334. para1:=hp
  1335. else
  1336. last^.next:=hp;
  1337. last:=hp;
  1338. end;
  1339. end;
  1340. function tabstractprocdef.para_size : longint;
  1341. var
  1342. pdc : pdefcoll;
  1343. l : longint;
  1344. begin
  1345. l:=0;
  1346. pdc:=para1;
  1347. while assigned(pdc) do
  1348. begin
  1349. case pdc^.paratyp of
  1350. vs_value : l:=l+pdc^.data^.size+(pdc^.data^.size mod 2);
  1351. vs_var : l:=l+sizeof(pointer);
  1352. vs_const : if dont_copy_const_param(pdc^.data) then
  1353. l:=l+sizeof(pointer)
  1354. else
  1355. l:=l+pdc^.data^.size+(pdc^.data^.size mod 2);
  1356. end;
  1357. pdc:=pdc^.next;
  1358. end;
  1359. para_size:=l;
  1360. end;
  1361. procedure tabstractprocdef.write;
  1362. var
  1363. count : word;
  1364. hp : pdefcoll;
  1365. begin
  1366. tdef.write;
  1367. writedefref(retdef);
  1368. {$ifdef StoreFPULevel}
  1369. writebyte(FPU_used);
  1370. {$endif StoreFPULevel}
  1371. writelong(options);
  1372. hp:=para1;
  1373. count:=0;
  1374. while assigned(hp) do
  1375. begin
  1376. inc(count);
  1377. hp:=hp^.next;
  1378. end;
  1379. writeword(count);
  1380. hp:=para1;
  1381. while assigned(hp) do
  1382. begin
  1383. writebyte(byte(hp^.paratyp));
  1384. writedefref(hp^.data);
  1385. hp:=hp^.next;
  1386. end;
  1387. end;
  1388. {$ifdef GDB}
  1389. function tabstractprocdef.stabstring : pchar;
  1390. begin
  1391. stabstring := strpnew('abstractproc'+numberstring+';');
  1392. end;
  1393. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  1394. begin
  1395. if (not assigned(sym) or sym^.isusedinstab or use_dbx)
  1396. and not is_def_stab_written then
  1397. begin
  1398. if assigned(retdef) then forcestabto(asmlist,retdef);
  1399. inherited concatstabto(asmlist);
  1400. end;
  1401. end;
  1402. {$endif GDB}
  1403. {***********************************************************************************
  1404. TPROCDEF
  1405. ***************************************************************************}
  1406. constructor tprocdef.init;
  1407. begin
  1408. inherited init;
  1409. deftype:=procdef;
  1410. _mangledname:=nil;
  1411. nextoverloaded:=nil;
  1412. extnumber:=-1;
  1413. localst:=new(psymtable,init(localsymtable));
  1414. parast:=new(psymtable,init(parasymtable));
  1415. { this is used by insert
  1416. to check same names in parast and localst }
  1417. localst^.next:=parast;
  1418. {$ifdef UseBrowser}
  1419. defref:=nil;
  1420. if make_ref then
  1421. add_new_ref(defref,@tokenpos);
  1422. lastref:=defref;
  1423. lastwritten:=nil;
  1424. refcount:=1;
  1425. {$endif UseBrowser}
  1426. { first, we assume, that all registers are used }
  1427. {$ifdef i386}
  1428. usedregisters:=$ff;
  1429. {$endif i386}
  1430. {$ifdef m68k}
  1431. usedregisters:=$FFFF;
  1432. {$endif}
  1433. {$ifdef alpha}
  1434. usedregisters_int:=$ffffffff;
  1435. usedregisters_fpu:=$ffffffff;
  1436. {$endif alpha}
  1437. forwarddef:=true;
  1438. _class := nil;
  1439. end;
  1440. constructor tprocdef.load;
  1441. var
  1442. s : string;
  1443. begin
  1444. { deftype:=procdef; this is at the wrong place !! }
  1445. inherited load;
  1446. deftype:=procdef;
  1447. {$ifdef i386}
  1448. usedregisters:=readbyte;
  1449. {$endif i386}
  1450. {$ifdef m68k}
  1451. usedregisters:=readword;
  1452. {$endif}
  1453. {$ifdef alpha}
  1454. usedregisters_int:=readlong;
  1455. usedregisters_fpu:=readlong;
  1456. {$endif alpha}
  1457. s:=readstring;
  1458. setstring(_mangledname,s);
  1459. extnumber:=readlong;
  1460. nextoverloaded:=pprocdef(readdefref);
  1461. _class := pobjectdef(readdefref);
  1462. if gendeffile and ((options and poexports)<>0) then
  1463. writeln(deffile,#9+mangledname);
  1464. parast:=nil;
  1465. localst:=nil;
  1466. forwarddef:=false;
  1467. {$ifdef UseBrowser}
  1468. if (current_module^.flags and uf_uses_browser)<>0 then
  1469. load_references
  1470. else
  1471. begin
  1472. lastref:=nil;
  1473. lastwritten:=nil;
  1474. defref:=nil;
  1475. refcount:=0;
  1476. end;
  1477. {$endif UseBrowser}
  1478. end;
  1479. {$ifdef UseBrowser}
  1480. procedure tprocdef.load_references;
  1481. var fileindex : word;
  1482. b : byte;
  1483. l,c : longint;
  1484. begin
  1485. b:=readbyte;
  1486. refcount:=0;
  1487. lastref:=nil;
  1488. lastwritten:=nil;
  1489. defref:=nil;
  1490. while b=ibref do
  1491. begin
  1492. fileindex:=readword;
  1493. l:=readlong;
  1494. c:=readword;
  1495. inc(refcount);
  1496. lastref:=new(pref,load(lastref,fileindex,l,c));
  1497. if refcount=1 then defref:=lastref;
  1498. b:=readbyte;
  1499. end;
  1500. if b <> ibend then
  1501. { Message(unit_f_ppu_read);
  1502. message disappeared ?? }
  1503. Comment(V_fatal,'error in load_reference');
  1504. end;
  1505. procedure tprocdef.write_references;
  1506. var ref : pref;
  1507. begin
  1508. { references do not change the ppu caracteristics }
  1509. { this only save the references to variables/functions }
  1510. { defined in the unit what about the others }
  1511. ppufile.do_crc:=false;
  1512. if assigned(lastwritten) then
  1513. ref:=lastwritten
  1514. else
  1515. ref:=defref;
  1516. while assigned(ref) do
  1517. begin
  1518. writebyte(ibref);
  1519. writeword(ref^.posinfo.fileindex);
  1520. writelong(ref^.posinfo.line);
  1521. writeword(ref^.posinfo.column);
  1522. ref:=ref^.nextref;
  1523. end;
  1524. lastwritten:=lastref;
  1525. writebyte(ibend);
  1526. ppufile.do_crc:=true;
  1527. end;
  1528. procedure tprocdef.write_external_references;
  1529. var ref : pref;
  1530. begin
  1531. ppufile.do_crc:=false;
  1532. if lastwritten=lastref then exit;
  1533. writebyte(ibextdefref);
  1534. writedefref(@self);
  1535. if assigned(lastwritten) then
  1536. ref:=lastwritten
  1537. else
  1538. ref:=defref;
  1539. while assigned(ref) do
  1540. begin
  1541. writebyte(ibref);
  1542. writeword(ref^.posinfo.fileindex);
  1543. writelong(ref^.posinfo.line);
  1544. writeword(ref^.posinfo.column);
  1545. ref:=ref^.nextref;
  1546. end;
  1547. lastwritten:=lastref;
  1548. writebyte(ibend);
  1549. ppufile.do_crc:=true;
  1550. end;
  1551. procedure tprocdef.write_ref_to_file(var f : text);
  1552. var ref : pref;
  1553. i : longint;
  1554. begin
  1555. ref:=defref;
  1556. if assigned(ref) then
  1557. begin
  1558. for i:=1 to reffile_indent do
  1559. system.write(f,' ');
  1560. writeln(f,'***',mangledname);
  1561. end;
  1562. inc(reffile_indent,2);
  1563. while assigned(ref) do
  1564. begin
  1565. for i:=1 to reffile_indent do
  1566. system.write(f,' ');
  1567. writeln(f,ref^.get_file_line);
  1568. ref:=ref^.nextref;
  1569. end;
  1570. dec(reffile_indent,2);
  1571. end;
  1572. {$endif UseBrowser}
  1573. destructor tprocdef.done;
  1574. begin
  1575. if assigned(parast) then
  1576. dispose(parast,done);
  1577. if assigned(localst) then
  1578. dispose(localst,done);
  1579. if
  1580. {$ifdef tp}
  1581. not(use_big) and
  1582. {$endif}
  1583. assigned(_mangledname) then
  1584. strdispose(_mangledname);
  1585. inherited done;
  1586. end;
  1587. procedure tprocdef.write;
  1588. begin
  1589. {$ifndef NEWPPU}
  1590. writebyte(ibprocdef);
  1591. {$endif}
  1592. inherited write;
  1593. {$ifdef i386}
  1594. writebyte(usedregisters);
  1595. {$endif i386}
  1596. {$ifdef m68k}
  1597. writeword(usedregisters);
  1598. {$endif}
  1599. {$ifdef alpha}
  1600. writelong(usedregisters_int);
  1601. writelong(usedregisters_fpu);
  1602. {$endif alpha}
  1603. writestring(mangledname);
  1604. writelong(extnumber);
  1605. writedefref(nextoverloaded);
  1606. writedefref(_class);
  1607. {$ifdef NEWPPU}
  1608. ppufile.writeentry(ibprocdef);
  1609. {$endif}
  1610. {$ifdef UseBrowser}
  1611. if (current_module^.flags and uf_uses_browser)<>0 then
  1612. write_references;
  1613. {$endif UseBrowser}
  1614. end;
  1615. {$ifdef GDB}
  1616. procedure addparaname(p : psym);
  1617. var vs : char;
  1618. begin
  1619. if pvarsym(p)^.varspez = vs_value then vs := '1'
  1620. else vs := '0';
  1621. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.definition^.numberstring+','+vs+';');
  1622. end;
  1623. function tprocdef.stabstring : pchar;
  1624. var param : pdefcoll;
  1625. i : word;
  1626. vartyp : char;
  1627. oldrec : pchar;
  1628. begin
  1629. oldrec := stabrecstring;
  1630. getmem(StabRecString,1024);
  1631. param := para1;
  1632. i := 0;
  1633. while assigned(param) do
  1634. begin
  1635. inc(i);
  1636. param := param^.next;
  1637. end;
  1638. strpcopy(StabRecString,'f'+retdef^.numberstring);
  1639. if i>0 then
  1640. begin
  1641. strpcopy(strend(StabRecString),','+tostr(i)+';');
  1642. if assigned(parast) then
  1643. {$IfDef TP}
  1644. parast^.foreach(addparaname)
  1645. {$Else}
  1646. parast^.foreach(@addparaname)
  1647. {$EndIf}
  1648. else
  1649. begin
  1650. param := para1;
  1651. i := 0;
  1652. while assigned(param) do
  1653. begin
  1654. inc(i);
  1655. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  1656. {Here we have lost the parameter names !!}
  1657. {using lower case parameters }
  1658. strpcopy(strend(stabrecstring),'p'+tostr(i)
  1659. +':'+param^.data^.numberstring+','+vartyp+';');
  1660. param := param^.next;
  1661. end;
  1662. end;
  1663. {strpcopy(strend(StabRecString),';');}
  1664. end;
  1665. stabstring := strnew(stabrecstring);
  1666. freemem(stabrecstring,1024);
  1667. stabrecstring := oldrec;
  1668. end;
  1669. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  1670. begin
  1671. end;
  1672. {$endif GDB}
  1673. procedure tprocdef.deref;
  1674. begin
  1675. inherited deref;
  1676. resolvedef(pdef(nextoverloaded));
  1677. resolvedef(pdef(_class));
  1678. end;
  1679. function tprocdef.mangledname : string;
  1680. {$ifdef tp}
  1681. var
  1682. oldpos : longint;
  1683. s : string;
  1684. b : byte;
  1685. {$endif tp}
  1686. begin
  1687. {$ifdef tp}
  1688. if use_big then
  1689. begin
  1690. symbolstream.seek(longint(_mangledname));
  1691. symbolstream.read(b,1);
  1692. symbolstream.read(s[1],b);
  1693. s[0]:=chr(b);
  1694. mangledname:=s;
  1695. end
  1696. else
  1697. {$endif}
  1698. mangledname:=strpas(_mangledname);
  1699. end;
  1700. {$IfDef GDB}
  1701. function tprocdef.cplusplusmangledname : string;
  1702. var
  1703. s,s2 : string;
  1704. param : pdefcoll;
  1705. begin
  1706. s := sym^.name;
  1707. if _class <> nil then
  1708. begin
  1709. s2 := _class^.name^;
  1710. s := s+'__'+tostr(length(s2))+s2;
  1711. end else s := s + '_';
  1712. param := para1;
  1713. while assigned(param) do
  1714. begin
  1715. s2 := param^.data^.sym^.name;
  1716. s := s+tostr(length(s2))+s2;
  1717. param := param^.next;
  1718. end;
  1719. cplusplusmangledname:=s;
  1720. end;
  1721. {$EndIf GDB}
  1722. procedure tprocdef.setmangledname(const s : string);
  1723. begin
  1724. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  1725. strdispose(_mangledname);
  1726. setstring(_mangledname,s);
  1727. {$ifdef UseBrowser}
  1728. if assigned(parast) then
  1729. begin
  1730. stringdispose(parast^.name);
  1731. parast^.name:=stringdup('args of '+s);
  1732. end;
  1733. if assigned(localst) then
  1734. begin
  1735. stringdispose(localst^.name);
  1736. localst^.name:=stringdup('locals of '+s);
  1737. end;
  1738. {$endif UseBrowser}
  1739. end;
  1740. {***********************************************************************************
  1741. TPROCVARDEF
  1742. ***************************************************************************}
  1743. constructor tprocvardef.init;
  1744. begin
  1745. inherited init;
  1746. deftype:=procvardef;
  1747. end;
  1748. constructor tprocvardef.load;
  1749. begin
  1750. inherited load;
  1751. deftype:=procvardef;
  1752. end;
  1753. procedure tprocvardef.write;
  1754. begin
  1755. {$ifndef NEWPPU}
  1756. writebyte(ibprocvardef);
  1757. {$endif}
  1758. { here we cannot get a real good value so just give something }
  1759. { plausible (PM) }
  1760. {$ifdef StoreFPULevel}
  1761. if is_fpu(retdef) then
  1762. fpu_used:=3
  1763. else
  1764. fpu_used:=0;
  1765. {$endif StoreFPULevel}
  1766. inherited write;
  1767. {$ifdef NEWPPU}
  1768. ppufile.writeentry(ibprocvardef);
  1769. {$endif}
  1770. end;
  1771. function tprocvardef.size : longint;
  1772. begin
  1773. if (options and pomethodpointer)=0 then
  1774. size:=sizeof(pointer)
  1775. else
  1776. size:=2*sizeof(pointer);
  1777. end;
  1778. {$ifdef GDB}
  1779. function tprocvardef.stabstring : pchar;
  1780. var
  1781. nss : pchar;
  1782. i : word;
  1783. vartyp : char;
  1784. pst : pchar;
  1785. param : pdefcoll;
  1786. begin
  1787. i := 0;
  1788. param := para1;
  1789. while assigned(param) do
  1790. begin
  1791. inc(i);
  1792. param := param^.next;
  1793. end;
  1794. getmem(nss,1024);
  1795. strpcopy(nss,'f'+retdef^.numberstring+','+tostr(i)+';');
  1796. param := para1;
  1797. i := 0;
  1798. while assigned(param) do
  1799. begin
  1800. inc(i);
  1801. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  1802. {Here we have lost the parameter names !!}
  1803. pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
  1804. strcat(nss,pst);
  1805. strdispose(pst);
  1806. param := param^.next;
  1807. end;
  1808. {strpcopy(strend(nss),';');}
  1809. stabstring := strnew(nss);
  1810. freemem(nss,1024);
  1811. end;
  1812. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  1813. begin
  1814. if ( not assigned(sym) or sym^.isusedinstab or use_dbx)
  1815. and not is_def_stab_written then
  1816. inherited concatstabto(asmlist);
  1817. is_def_stab_written:=true;
  1818. end;
  1819. {$endif GDB}
  1820. {***************************************************************************
  1821. TOBJECTDEF
  1822. ***************************************************************************}
  1823. {$ifdef GDB}
  1824. const
  1825. vtabletype : word = 0;
  1826. vtableassigned : boolean = false;
  1827. {$endif GDB}
  1828. constructor tobjectdef.init(const n : string;c : pobjectdef);
  1829. begin
  1830. tdef.init;
  1831. deftype:=objectdef;
  1832. childof:=c;
  1833. options:=0;
  1834. { privatesyms:=new(psymtable,init(objectsymtable));
  1835. protectedsyms:=new(psymtable,init(objectsymtable)); }
  1836. publicsyms:=new(psymtable,init(objectsymtable));
  1837. publicsyms^.name := stringdup(n);
  1838. { add the data of the anchestor class }
  1839. if assigned(childof) then
  1840. begin
  1841. publicsyms^.datasize:=
  1842. publicsyms^.datasize-4+childof^.publicsyms^.datasize;
  1843. end;
  1844. name:=stringdup(n);
  1845. savesize := publicsyms^.datasize;
  1846. publicsyms^.defowner:=@self;
  1847. end;
  1848. constructor tobjectdef.load;
  1849. var
  1850. oldread_member : boolean;
  1851. begin
  1852. tdef.load;
  1853. deftype:=objectdef;
  1854. savesize:=readlong;
  1855. name:=stringdup(readstring);
  1856. childof:=pobjectdef(readdefref);
  1857. options:=readlong;
  1858. oldread_member:=read_member;
  1859. read_member:=true;
  1860. if (options and (oo_hasprivate or oo_hasprotected))<>0 then
  1861. object_options:=true;
  1862. publicsyms:=new(psymtable,loadasstruct(objectsymtable));
  1863. object_options:=false;
  1864. publicsyms^.defowner:=@self;
  1865. publicsyms^.datasize:=savesize;
  1866. publicsyms^.name := stringdup(name^);
  1867. read_member:=oldread_member;
  1868. { handles the predefined class tobject }
  1869. { the last TOBJECT which is loaded gets }
  1870. { it ! }
  1871. if (name^='TOBJECT') and not(cs_compilesystem in aktswitches) and
  1872. isclass and (childof=pointer($ffffffff)) then
  1873. class_tobject:=@self;
  1874. end;
  1875. procedure tobjectdef.check_forwards;
  1876. begin
  1877. publicsyms^.check_forwards;
  1878. if (options and oo_isforward)<>0 then
  1879. begin
  1880. { ok, in future, the forward can be resolved }
  1881. Message1(sym_e_class_forward_not_resolved,name^);
  1882. options:=options and not(oo_isforward);
  1883. end;
  1884. end;
  1885. destructor tobjectdef.done;
  1886. begin
  1887. {!!!!
  1888. if assigned(privatesyms) then
  1889. dispose(privatesyms,done);
  1890. if assigned(protectedsyms) then
  1891. dispose(protectedsyms,done); }
  1892. if assigned(publicsyms) then
  1893. dispose(publicsyms,done);
  1894. if (options and oo_isforward)<>0 then
  1895. Message1(sym_e_class_forward_not_resolved,name^);
  1896. stringdispose(name);
  1897. tdef.done;
  1898. end;
  1899. { true, if self inherits from d (or if they are equal) }
  1900. function tobjectdef.isrelated(d : pobjectdef) : boolean;
  1901. var
  1902. hp : pobjectdef;
  1903. begin
  1904. hp:=@self;
  1905. while assigned(hp) do
  1906. begin
  1907. if hp=d then
  1908. begin
  1909. isrelated:=true;
  1910. exit;
  1911. end;
  1912. hp:=hp^.childof;
  1913. end;
  1914. isrelated:=false;
  1915. end;
  1916. function tobjectdef.size : longint;
  1917. begin
  1918. if (options and oois_class)<>0 then
  1919. size:=sizeof(pointer)
  1920. else
  1921. size:=publicsyms^.datasize;
  1922. end;
  1923. procedure tobjectdef.deref;
  1924. var
  1925. hp : pdef;
  1926. oldrecsyms : psymtable;
  1927. begin
  1928. resolvedef(pdef(childof));
  1929. oldrecsyms:=aktrecordsymtable;
  1930. aktrecordsymtable:=publicsyms;
  1931. { nun die Definitionen dereferenzieren }
  1932. hp:=publicsyms^.rootdef;
  1933. while assigned(hp) do
  1934. begin
  1935. hp^.deref;
  1936. {Besitzer setzen }
  1937. hp^.owner:=publicsyms;
  1938. hp:=hp^.next;
  1939. end;
  1940. {$ifdef tp}
  1941. publicsyms^.foreach(derefsym);
  1942. {$else}
  1943. publicsyms^.foreach(@derefsym);
  1944. {$endif}
  1945. aktrecordsymtable:=oldrecsyms;
  1946. end;
  1947. function tobjectdef.vmt_mangledname : string;
  1948. {DM: I get a nil pointer on the owner name. I don't know if this
  1949. mayhappen, and I have therefore fixed the problem by doing nil pointer
  1950. checks.}
  1951. var s1,s2:string;
  1952. begin
  1953. if owner^.name=nil then
  1954. s1:=''
  1955. else
  1956. s1:=owner^.name^;
  1957. if name=nil then
  1958. s2:=''
  1959. else
  1960. s2:=name^;
  1961. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  1962. end;
  1963. function tobjectdef.isclass : boolean;
  1964. begin
  1965. isclass:=(options and oois_class)<>0;
  1966. end;
  1967. procedure tobjectdef.write;
  1968. var
  1969. oldread_member : boolean;
  1970. begin
  1971. oldread_member:=read_member;
  1972. read_member:=true;
  1973. {$ifndef NEWPPU}
  1974. writebyte(ibobjectdef);
  1975. {$endif}
  1976. tdef.write;
  1977. writelong(size);
  1978. writestring(name^);
  1979. writedefref(childof);
  1980. writelong(options);
  1981. {$ifdef NEWPPU}
  1982. ppufile.writeentry(ibobjectdef);
  1983. {$endif}
  1984. if (options and (oo_hasprivate or oo_hasprotected))<>0 then
  1985. object_options:=true;
  1986. publicsyms^.writeasstruct;
  1987. object_options:=false;
  1988. read_member:=oldread_member;
  1989. end;
  1990. {$ifdef GDB}
  1991. procedure addprocname(p :psym);
  1992. var virtualind,argnames : string;
  1993. news, newrec : pchar;
  1994. pd,ipd : pprocdef;
  1995. lindex : longint;
  1996. para : pdefcoll;
  1997. arglength : byte;
  1998. sp : char;
  1999. begin
  2000. If p^.typ = procsym then
  2001. begin
  2002. pd := pprocsym(p)^.definition;
  2003. { this will be used for full implementation of object stabs
  2004. not yet done }
  2005. ipd := pd;
  2006. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2007. if (pd^.options and povirtualmethod) <> 0 then
  2008. begin
  2009. lindex := pd^.extnumber;
  2010. {doesnt seem to be necessary
  2011. lindex := lindex or $80000000;}
  2012. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2013. end else virtualind := '.';
  2014. { arguments are not listed here }
  2015. {we don't need another definition}
  2016. para := pd^.para1;
  2017. argnames := '';
  2018. while assigned(para) do
  2019. begin
  2020. if para^.data^.deftype = formaldef then
  2021. argnames := argnames+'3var'
  2022. else
  2023. begin
  2024. { if the arg definition is like (v: ^byte;..
  2025. there is no sym attached to data !!! }
  2026. if assigned(para^.data^.sym) then
  2027. begin
  2028. arglength := length(para^.data^.sym^.name);
  2029. argnames := argnames + tostr(arglength)+para^.data^.sym^.name;
  2030. end
  2031. else
  2032. begin
  2033. argnames:=argnames+'11unnamedtype';
  2034. end;
  2035. end;
  2036. para := para^.next;
  2037. end;
  2038. ipd^.is_def_stab_written := true;
  2039. { here 2A must be changed for private and protected }
  2040. { 0 is private 1 protected and 2 public }
  2041. if (p^.properties and sp_private)<>0 then sp:='0'
  2042. else if (p^.properties and sp_protected)<>0 then sp:='1'
  2043. else sp:='2';
  2044. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  2045. +'=##'+pd^.retdef^.numberstring+';:'+argnames+';'+sp+'A'
  2046. +virtualind+';');
  2047. { get spare place for a string at the end }
  2048. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2049. begin
  2050. getmem(news,stabrecsize+memsizeinc);
  2051. strcopy(news,stabrecstring);
  2052. freemem(stabrecstring,stabrecsize);
  2053. stabrecsize:=stabrecsize+memsizeinc;
  2054. stabrecstring:=news;
  2055. end;
  2056. strcat(StabRecstring,newrec);
  2057. {freemem(newrec,memsizeinc); }
  2058. strdispose(newrec);
  2059. {This should be used for case !!}
  2060. RecOffset := RecOffset + pd^.size;
  2061. end;
  2062. end;
  2063. function tobjectdef.stabstring : pchar;
  2064. var anc : pobjectdef;
  2065. oldrec : pchar;
  2066. oldrecsize : longint;
  2067. str_end : string;
  2068. begin
  2069. oldrec := stabrecstring;
  2070. oldrecsize:=stabrecsize;
  2071. stabrecsize:=memsizeinc;
  2072. GetMem(stabrecstring,stabrecsize);
  2073. strpcopy(stabRecString,'s'+tostr(size));
  2074. if assigned(childof) then
  2075. {only one ancestor not virtual, public, at base offset 0 }
  2076. { !1 , 0 2 0 , }
  2077. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  2078. {virtual table to implement yet}
  2079. RecOffset := 0;
  2080. {$ifdef tp}
  2081. publicsyms^.foreach(addname);
  2082. {$else}
  2083. publicsyms^.foreach(@addname);
  2084. {$endif tp}
  2085. if (options and oo_hasvirtual) <> 0 then
  2086. if not assigned(childof) or ((childof^.options and oo_hasvirtual) = 0) then
  2087. begin
  2088. str_end:='$vf'+numberstring+':'+typeglobalnumber('vtblarray')+',0;';
  2089. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')+',0;');
  2090. end;
  2091. {$ifdef tp}
  2092. publicsyms^.foreach(addprocname);
  2093. {$else}
  2094. publicsyms^.foreach(@addprocname);
  2095. {$endif tp }
  2096. if (options and oo_hasvirtual) <> 0 then
  2097. begin
  2098. anc := @self;
  2099. while assigned(anc^.childof) and ((anc^.childof^.options and oo_hasvirtual) <> 0) do
  2100. anc := anc^.childof;
  2101. str_end:=';~%'+anc^.numberstring+';';
  2102. end
  2103. else
  2104. str_end:=';';
  2105. strpcopy(strend(stabrecstring),str_end);
  2106. stabstring := strnew(StabRecString);
  2107. freemem(stabrecstring,stabrecsize);
  2108. stabrecstring := oldrec;
  2109. stabrecsize:=oldrecsize;
  2110. end;
  2111. {$endif GDB}
  2112. {****************************************************************************
  2113. TERRORDEF
  2114. ****************************************************************************}
  2115. constructor terrordef.init;
  2116. begin
  2117. tdef.init;
  2118. deftype:=errordef;
  2119. end;
  2120. {$ifdef GDB}
  2121. function terrordef.stabstring : pchar;
  2122. begin
  2123. stabstring:=strpnew('error'+numberstring);
  2124. end;
  2125. {$endif GDB}
  2126. {
  2127. $Log$
  2128. Revision 1.1 1998-05-27 19:45:09 peter
  2129. * symtable.pas splitted into includefiles
  2130. * symtable adapted for $ifdef NEWPPU
  2131. }