symdef.inc 74 KB

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