symdef.inc 73 KB

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