symdef.inc 75 KB

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