symsym.pas 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Implementation for the symbols types of the symtable
  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. unit symsym;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,
  24. { target }
  25. cpuinfo,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,
  28. { ppu }
  29. ppu,symppu,
  30. { aasm }
  31. aasmbase,aasmtai,cpubase,
  32. globals
  33. ;
  34. type
  35. {************************************************
  36. TSym
  37. ************************************************}
  38. { this object is the base for all symbol objects }
  39. tstoredsym = class(tsym)
  40. protected
  41. _mangledname : pstring;
  42. public
  43. {$ifdef GDB}
  44. isstabwritten : boolean;
  45. {$endif GDB}
  46. refs : longint;
  47. lastref,
  48. defref,
  49. lastwritten : tref;
  50. refcount : longint;
  51. constructor create(const n : string);
  52. constructor loadsym(ppufile:tcompilerppufile);
  53. destructor destroy;override;
  54. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  55. procedure writesym(ppufile:tcompilerppufile);
  56. procedure deref;override;
  57. {$ifdef GDB}
  58. function stabstring : pchar;virtual;
  59. procedure concatstabto(asmlist : taasmoutput);virtual;
  60. {$endif GDB}
  61. procedure load_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  62. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;virtual;
  63. function is_visible_for_proc(currprocdef:tprocdef):boolean;
  64. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  65. function mangledname : string;
  66. procedure generate_mangledname;virtual;abstract;
  67. end;
  68. tlabelsym = class(tstoredsym)
  69. lab : tasmlabel;
  70. used,
  71. defined : boolean;
  72. code : pointer; { should be tnode }
  73. constructor create(const n : string; l : tasmlabel);
  74. destructor destroy;override;
  75. constructor ppuload(ppufile:tcompilerppufile);
  76. procedure generate_mangledname;override;
  77. procedure ppuwrite(ppufile:tcompilerppufile);override;
  78. end;
  79. tunitsym = class(tstoredsym)
  80. unitsymtable : tsymtable;
  81. prevsym : tunitsym;
  82. constructor create(const n : string;ref : tsymtable);
  83. constructor ppuload(ppufile:tcompilerppufile);
  84. destructor destroy;override;
  85. procedure ppuwrite(ppufile:tcompilerppufile);override;
  86. procedure restoreunitsym;
  87. {$ifdef GDB}
  88. procedure concatstabto(asmlist : taasmoutput);override;
  89. {$endif GDB}
  90. end;
  91. terrorsym = class(tstoredsym)
  92. constructor create;
  93. end;
  94. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  95. tprocsym = class(tstoredsym)
  96. { protected}
  97. defs : pprocdeflist; { linked list of overloaded procdefs }
  98. public
  99. is_global : boolean;
  100. overloadchecked : boolean;
  101. overloadcount : longint; { amount of overloaded functions in this module }
  102. constructor create(const n : string);
  103. constructor ppuload(ppufile:tcompilerppufile);
  104. destructor destroy;override;
  105. { writes all declarations except the specified one }
  106. procedure write_parameter_lists(skipdef:tprocdef);
  107. { tests, if all procedures definitions are defined and not }
  108. { only forward }
  109. procedure check_forward;
  110. procedure unchain_overload;
  111. procedure ppuwrite(ppufile:tcompilerppufile);override;
  112. procedure deref;override;
  113. procedure addprocdef(p:tprocdef);
  114. function procdef_count:byte;
  115. function procdef(nr:byte):Tprocdef;
  116. procedure add_para_match_to(Aprocsym:Tprocsym);
  117. procedure concat_procdefs_to(s:Tprocsym);
  118. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  119. function first_procdef:Tprocdef;
  120. function last_procdef:Tprocdef;
  121. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  122. function search_procdef_bypara(params:Tparalinkedlist):Tprocdef;
  123. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  124. function search_procdef_byretdef_by1paradef(retdef,firstpara:Tdef;
  125. matchtype:Tdefmatch):Tprocdef;
  126. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  127. {$ifdef GDB}
  128. function stabstring : pchar;override;
  129. procedure concatstabto(asmlist : taasmoutput);override;
  130. {$endif GDB}
  131. end;
  132. ttypesym = class(tstoredsym)
  133. restype : ttype;
  134. {$ifdef GDB}
  135. isusedinstab : boolean;
  136. {$endif GDB}
  137. constructor create(const n : string;const tt : ttype);
  138. constructor ppuload(ppufile:tcompilerppufile);
  139. procedure ppuwrite(ppufile:tcompilerppufile);override;
  140. procedure deref;override;
  141. function gettypedef:tdef;override;
  142. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  143. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  144. {$ifdef GDB}
  145. function stabstring : pchar;override;
  146. procedure concatstabto(asmlist : taasmoutput);override;
  147. {$endif GDB}
  148. end;
  149. tvarsym = class(tstoredsym)
  150. address : longint;
  151. localvarsym : tvarsym;
  152. vartype : ttype;
  153. varoptions : tvaroptions;
  154. reg : tregister; { if reg<>R_NO, then the variable is an register variable }
  155. varspez : tvarspez; { sets the type of access }
  156. varstate : tvarstate;
  157. constructor create(const n : string;const tt : ttype);
  158. constructor create_dll(const n : string;const tt : ttype);
  159. constructor create_C(const n,mangled : string;const tt : ttype);
  160. constructor ppuload(ppufile:tcompilerppufile);
  161. destructor destroy;override;
  162. procedure ppuwrite(ppufile:tcompilerppufile);override;
  163. procedure deref;override;
  164. procedure generate_mangledname;override;
  165. procedure set_mangledname(const s:string);
  166. function getsize : longint;
  167. function getvaluesize : longint;
  168. function getpushsize(is_cdecl:boolean): longint;
  169. {$ifdef GDB}
  170. function stabstring : pchar;override;
  171. procedure concatstabto(asmlist : taasmoutput);override;
  172. {$endif GDB}
  173. end;
  174. tpropertysym = class(tstoredsym)
  175. propoptions : tpropertyoptions;
  176. propoverriden : tpropertysym;
  177. proptype,
  178. indextype : ttype;
  179. index,
  180. default : longint;
  181. readaccess,
  182. writeaccess,
  183. storedaccess : tsymlist;
  184. constructor create(const n : string);
  185. destructor destroy;override;
  186. constructor ppuload(ppufile:tcompilerppufile);
  187. function getsize : longint;
  188. procedure ppuwrite(ppufile:tcompilerppufile);override;
  189. function gettypedef:tdef;override;
  190. procedure deref;override;
  191. procedure dooverride(overriden:tpropertysym);
  192. {$ifdef GDB}
  193. function stabstring : pchar;override;
  194. procedure concatstabto(asmlist : taasmoutput);override;
  195. {$endif GDB}
  196. end;
  197. tfuncretsym = class(tstoredsym)
  198. returntype : ttype;
  199. address : longint;
  200. funcretstate : tvarstate;
  201. constructor create(const n : string;const tt : ttype);
  202. constructor ppuload(ppufile:tcompilerppufile);
  203. destructor destroy;override;
  204. procedure ppuwrite(ppufile:tcompilerppufile);override;
  205. procedure deref;override;
  206. {$ifdef GDB}
  207. procedure concatstabto(asmlist : taasmoutput);override;
  208. {$endif GDB}
  209. end;
  210. tabsolutesym = class(tvarsym)
  211. abstyp : absolutetyp;
  212. absseg : boolean;
  213. ref : tstoredsym;
  214. asmname : pstring;
  215. constructor create(const n : string;const tt : ttype);
  216. constructor ppuload(ppufile:tcompilerppufile);
  217. procedure deref;override;
  218. function mangledname : string;
  219. procedure ppuwrite(ppufile:tcompilerppufile);override;
  220. {$ifdef GDB}
  221. procedure concatstabto(asmlist : taasmoutput);override;
  222. {$endif GDB}
  223. end;
  224. ttypedconstsym = class(tstoredsym)
  225. typedconsttype : ttype;
  226. is_writable : boolean;
  227. constructor create(const n : string;p : tdef;writable : boolean);
  228. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  229. constructor ppuload(ppufile:tcompilerppufile);
  230. destructor destroy;override;
  231. procedure generate_mangledname;override;
  232. procedure ppuwrite(ppufile:tcompilerppufile);override;
  233. procedure deref;override;
  234. function getsize:longint;
  235. {$ifdef GDB}
  236. function stabstring : pchar;override;
  237. {$endif GDB}
  238. end;
  239. tconstsym = class(tstoredsym)
  240. consttype : ttype;
  241. consttyp : tconsttyp;
  242. resstrindex, { needed for resource strings }
  243. valueord : tconstexprint; { used for ordinal values }
  244. valueordptr : TConstPtrUInt; { used for pointer values }
  245. valueptr : pointer; { used for string, set, real values }
  246. len : longint; { len is needed for string length }
  247. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint);
  248. constructor create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  249. constructor create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  250. constructor create_ptr(const n : string;t : tconsttyp;v : pointer);
  251. constructor create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  252. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  253. constructor ppuload(ppufile:tcompilerppufile);
  254. destructor destroy;override;
  255. function mangledname : string;
  256. procedure deref;override;
  257. procedure ppuwrite(ppufile:tcompilerppufile);override;
  258. {$ifdef GDB}
  259. function stabstring : pchar;override;
  260. procedure concatstabto(asmlist : taasmoutput);override;
  261. {$endif GDB}
  262. end;
  263. tenumsym = class(tstoredsym)
  264. value : longint;
  265. definition : tenumdef;
  266. nextenum : tenumsym;
  267. constructor create(const n : string;def : tenumdef;v : longint);
  268. constructor ppuload(ppufile:tcompilerppufile);
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;
  270. procedure deref;override;
  271. procedure order;
  272. {$ifdef GDB}
  273. procedure concatstabto(asmlist : taasmoutput);override;
  274. {$endif GDB}
  275. end;
  276. tsyssym = class(tstoredsym)
  277. number : longint;
  278. constructor create(const n : string;l : longint);
  279. constructor ppuload(ppufile:tcompilerppufile);
  280. destructor destroy;override;
  281. procedure ppuwrite(ppufile:tcompilerppufile);override;
  282. {$ifdef GDB}
  283. procedure concatstabto(asmlist : taasmoutput);override;
  284. {$endif GDB}
  285. end;
  286. { compiler generated symbol to point to rtti and init/finalize tables }
  287. trttisym = class(tstoredsym)
  288. lab : tasmsymbol;
  289. rttityp : trttitype;
  290. constructor create(const n:string;rt:trttitype);
  291. constructor ppuload(ppufile:tcompilerppufile);
  292. procedure ppuwrite(ppufile:tcompilerppufile);override;
  293. function mangledname:string;
  294. function get_label:tasmsymbol;
  295. end;
  296. { register variables }
  297. pregvarinfo = ^tregvarinfo;
  298. tregvarinfo = record
  299. regvars : array[1..maxvarregs] of tvarsym;
  300. regvars_para : array[1..maxvarregs] of boolean;
  301. regvars_refs : array[1..maxvarregs] of longint;
  302. fpuregvars : array[1..maxfpuvarregs] of tvarsym;
  303. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  304. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  305. end;
  306. var
  307. aktprocsym : tprocsym; { pointer to the symbol for the
  308. currently be parsed procedure }
  309. aktprocdef : tprocdef;
  310. aktcallprocdef : tabstractprocdef; { pointer to the definition of the
  311. currently called procedure,
  312. only set/unset in ncal }
  313. aktvarsym : tvarsym; { pointer to the symbol for the
  314. currently read var, only used
  315. for variable directives }
  316. generrorsym : tsym;
  317. otsym : tvarsym;
  318. const
  319. current_object_option : tsymoptions = [sp_public];
  320. { rtti and init/final }
  321. procedure generate_rtti(p:tsym);
  322. procedure generate_inittable(p:tsym);
  323. implementation
  324. uses
  325. {$ifdef Delphi}
  326. sysutils,
  327. {$else Delphi}
  328. strings,
  329. {$endif Delphi}
  330. { global }
  331. globtype,verbose,
  332. { target }
  333. systems,
  334. { symtable }
  335. symtable,defbase,
  336. {$ifdef GDB}
  337. gdb,
  338. {$endif GDB}
  339. { tree }
  340. node,
  341. { aasm }
  342. aasmcpu,
  343. { module }
  344. fmodule,
  345. { codegen }
  346. paramgr,cgbase,cresstr
  347. ;
  348. {****************************************************************************
  349. Helpers
  350. ****************************************************************************}
  351. {****************************************************************************
  352. TSYM (base for all symtypes)
  353. ****************************************************************************}
  354. constructor tstoredsym.create(const n : string);
  355. begin
  356. inherited create(n);
  357. symoptions:=current_object_option;
  358. {$ifdef GDB}
  359. isstabwritten := false;
  360. {$endif GDB}
  361. fileinfo:=akttokenpos;
  362. defref:=nil;
  363. refs:=0;
  364. lastwritten:=nil;
  365. refcount:=0;
  366. if (cs_browser in aktmoduleswitches) and make_ref then
  367. begin
  368. defref:=tref.create(defref,@akttokenpos);
  369. inc(refcount);
  370. end;
  371. lastref:=defref;
  372. _mangledname:=nil;
  373. end;
  374. constructor tstoredsym.loadsym(ppufile:tcompilerppufile);
  375. var
  376. s : string;
  377. nr : word;
  378. begin
  379. nr:=ppufile.getword;
  380. s:=ppufile.getstring;
  381. inherited create(s);
  382. { force the correct indexnr. must be after create! }
  383. indexnr:=nr;
  384. ppufile.getsmallset(symoptions);
  385. ppufile.getposinfo(fileinfo);
  386. lastref:=nil;
  387. defref:=nil;
  388. refs:=0;
  389. lastwritten:=nil;
  390. refcount:=0;
  391. _mangledname:=nil;
  392. {$ifdef GDB}
  393. isstabwritten := false;
  394. {$endif GDB}
  395. end;
  396. procedure tstoredsym.deref;
  397. begin
  398. end;
  399. procedure tstoredsym.load_references(ppufile:tcompilerppufile;locals:boolean);
  400. var
  401. pos : tfileposinfo;
  402. move_last : boolean;
  403. begin
  404. move_last:=lastwritten=lastref;
  405. while (not ppufile.endofentry) do
  406. begin
  407. ppufile.getposinfo(pos);
  408. inc(refcount);
  409. lastref:=tref.create(lastref,@pos);
  410. lastref.is_written:=true;
  411. if refcount=1 then
  412. defref:=lastref;
  413. end;
  414. if move_last then
  415. lastwritten:=lastref;
  416. end;
  417. { big problem here :
  418. wrong refs were written because of
  419. interface parsing of other units PM
  420. moduleindex must be checked !! }
  421. function tstoredsym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  422. var
  423. ref : tref;
  424. symref_written,move_last : boolean;
  425. begin
  426. write_references:=false;
  427. if lastwritten=lastref then
  428. exit;
  429. { should we update lastref }
  430. move_last:=true;
  431. symref_written:=false;
  432. { write symbol refs }
  433. if assigned(lastwritten) then
  434. ref:=lastwritten
  435. else
  436. ref:=defref;
  437. while assigned(ref) do
  438. begin
  439. if ref.moduleindex=current_module.unit_index then
  440. begin
  441. { write address to this symbol }
  442. if not symref_written then
  443. begin
  444. ppufile.putderef(self);
  445. symref_written:=true;
  446. end;
  447. ppufile.putposinfo(ref.posinfo);
  448. ref.is_written:=true;
  449. if move_last then
  450. lastwritten:=ref;
  451. end
  452. else if not ref.is_written then
  453. move_last:=false
  454. else if move_last then
  455. lastwritten:=ref;
  456. ref:=ref.nextref;
  457. end;
  458. if symref_written then
  459. ppufile.writeentry(ibsymref);
  460. write_references:=symref_written;
  461. end;
  462. destructor tstoredsym.destroy;
  463. begin
  464. if assigned(_mangledname) then
  465. stringdispose(_mangledname);
  466. if assigned(defref) then
  467. begin
  468. defref.freechain;
  469. defref.free;
  470. end;
  471. inherited destroy;
  472. end;
  473. procedure tstoredsym.writesym(ppufile:tcompilerppufile);
  474. begin
  475. ppufile.putword(indexnr);
  476. ppufile.putstring(_realname^);
  477. ppufile.putsmallset(symoptions);
  478. ppufile.putposinfo(fileinfo);
  479. end;
  480. {$ifdef GDB}
  481. function tstoredsym.stabstring : pchar;
  482. begin
  483. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  484. tostr(fileinfo.line)+',0');
  485. end;
  486. procedure tstoredsym.concatstabto(asmlist : taasmoutput);
  487. var
  488. stab_str : pchar;
  489. begin
  490. if not isstabwritten then
  491. begin
  492. stab_str := stabstring;
  493. { count_dbx(stab_str); moved to GDB.PAS }
  494. asmList.concat(Tai_stabs.Create(stab_str));
  495. isstabwritten:=true;
  496. end;
  497. end;
  498. {$endif GDB}
  499. function tstoredsym.is_visible_for_proc(currprocdef:tprocdef):boolean;
  500. begin
  501. is_visible_for_proc:=false;
  502. { private symbols are allowed when we are in the same
  503. module as they are defined }
  504. if (sp_private in symoptions) and
  505. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  506. (owner.defowner.owner.unitid<>0) then
  507. exit;
  508. { protected symbols are vissible in the module that defines them and
  509. also visible to related objects }
  510. if (sp_protected in symoptions) and
  511. (
  512. (
  513. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  514. (owner.defowner.owner.unitid<>0)
  515. ) and
  516. not(
  517. assigned(currprocdef) and
  518. assigned(currprocdef._class) and
  519. currprocdef._class.is_related(tobjectdef(owner.defowner))
  520. )
  521. ) then
  522. exit;
  523. is_visible_for_proc:=true;
  524. end;
  525. function tstoredsym.is_visible_for_object(currobjdef:tobjectdef):boolean;
  526. begin
  527. is_visible_for_object:=false;
  528. { private symbols are allowed when we are in the same
  529. module as they are defined }
  530. if (sp_private in symoptions) and
  531. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  532. (owner.defowner.owner.unitid<>0) then
  533. exit;
  534. { protected symbols are vissible in the module that defines them and
  535. also visible to related objects }
  536. if (sp_protected in symoptions) and
  537. (
  538. (
  539. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  540. (owner.defowner.owner.unitid<>0)
  541. ) and
  542. not(
  543. assigned(currobjdef) and
  544. currobjdef.is_related(tobjectdef(owner.defowner))
  545. )
  546. ) then
  547. exit;
  548. is_visible_for_object:=true;
  549. end;
  550. function tstoredsym.mangledname : string;
  551. begin
  552. if not assigned(_mangledname) then
  553. begin
  554. generate_mangledname;
  555. if not assigned(_mangledname) then
  556. internalerror(200204171);
  557. end;
  558. mangledname:=_mangledname^
  559. end;
  560. {****************************************************************************
  561. TLABELSYM
  562. ****************************************************************************}
  563. constructor tlabelsym.create(const n : string; l : tasmlabel);
  564. begin
  565. inherited create(n);
  566. typ:=labelsym;
  567. lab:=l;
  568. used:=false;
  569. defined:=false;
  570. code:=nil;
  571. end;
  572. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  573. begin
  574. inherited loadsym(ppufile);
  575. typ:=labelsym;
  576. { this is all dummy
  577. it is only used for local browsing }
  578. lab:=nil;
  579. code:=nil;
  580. used:=false;
  581. defined:=true;
  582. end;
  583. destructor tlabelsym.destroy;
  584. begin
  585. inherited destroy;
  586. end;
  587. procedure tlabelsym.generate_mangledname;
  588. begin
  589. _mangledname:=stringdup(lab.name);
  590. end;
  591. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  592. begin
  593. if owner.symtabletype=globalsymtable then
  594. Message(sym_e_ill_label_decl)
  595. else
  596. begin
  597. inherited writesym(ppufile);
  598. ppufile.writeentry(iblabelsym);
  599. end;
  600. end;
  601. {****************************************************************************
  602. TUNITSYM
  603. ****************************************************************************}
  604. constructor tunitsym.create(const n : string;ref : tsymtable);
  605. var
  606. old_make_ref : boolean;
  607. begin
  608. old_make_ref:=make_ref;
  609. make_ref:=false;
  610. inherited create(n);
  611. make_ref:=old_make_ref;
  612. typ:=unitsym;
  613. unitsymtable:=ref;
  614. if assigned(ref) and
  615. (ref.symtabletype=globalsymtable) then
  616. begin
  617. prevsym:=tglobalsymtable(ref).unitsym;
  618. tglobalsymtable(ref).unitsym:=self;
  619. end;
  620. end;
  621. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  622. begin
  623. inherited loadsym(ppufile);
  624. typ:=unitsym;
  625. unitsymtable:=nil;
  626. prevsym:=nil;
  627. refs:=0;
  628. end;
  629. { we need to remove it from the prevsym chain ! }
  630. procedure tunitsym.restoreunitsym;
  631. var pus,ppus : tunitsym;
  632. begin
  633. if assigned(unitsymtable) and
  634. (unitsymtable.symtabletype=globalsymtable) then
  635. begin
  636. ppus:=nil;
  637. pus:=tglobalsymtable(unitsymtable).unitsym;
  638. if pus=self then
  639. tglobalsymtable(unitsymtable).unitsym:=prevsym
  640. else while assigned(pus) do
  641. begin
  642. if pus=self then
  643. begin
  644. ppus.prevsym:=prevsym;
  645. break;
  646. end
  647. else
  648. begin
  649. ppus:=pus;
  650. pus:=ppus.prevsym;
  651. end;
  652. end;
  653. end;
  654. unitsymtable:=nil;
  655. prevsym:=nil;
  656. end;
  657. destructor tunitsym.destroy;
  658. begin
  659. restoreunitsym;
  660. inherited destroy;
  661. end;
  662. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  663. begin
  664. inherited writesym(ppufile);
  665. ppufile.writeentry(ibunitsym);
  666. end;
  667. {$ifdef GDB}
  668. procedure tunitsym.concatstabto(asmlist : taasmoutput);
  669. begin
  670. {Nothing to write to stabs !}
  671. end;
  672. {$endif GDB}
  673. {****************************************************************************
  674. TPROCSYM
  675. ****************************************************************************}
  676. constructor tprocsym.create(const n : string);
  677. begin
  678. inherited create(n);
  679. typ:=procsym;
  680. defs:=nil;
  681. owner:=nil;
  682. is_global:=false;
  683. overloadchecked:=false;
  684. overloadcount:=0;
  685. end;
  686. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  687. var
  688. pd : tprocdef;
  689. begin
  690. inherited loadsym(ppufile);
  691. typ:=procsym;
  692. defs:=nil;
  693. repeat
  694. pd:=tprocdef(ppufile.getderef);
  695. if pd=nil then
  696. break;
  697. addprocdef(pd);
  698. until false;
  699. is_global:=false;
  700. overloadchecked:=false;
  701. overloadcount:=-1; { invalid, not used anymore }
  702. end;
  703. destructor tprocsym.destroy;
  704. var
  705. hp,p : pprocdeflist;
  706. begin
  707. p:=defs;
  708. while assigned(p) do
  709. begin
  710. hp:=p^.next;
  711. dispose(p);
  712. p:=hp;
  713. end;
  714. inherited destroy;
  715. end;
  716. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  717. var
  718. p : pprocdeflist;
  719. begin
  720. p:=defs;
  721. while assigned(p) do
  722. begin
  723. if p^.def<>skipdef then
  724. MessagePos1(p^.def.fileinfo,sym_b_param_list,p^.def.fullprocname);
  725. p:=p^.next;
  726. end;
  727. end;
  728. procedure tprocsym.check_forward;
  729. var
  730. p : pprocdeflist;
  731. begin
  732. p:=defs;
  733. while assigned(p) do
  734. begin
  735. if (p^.def.procsym=self) and
  736. (p^.def.forwarddef) then
  737. begin
  738. MessagePos1(fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname);
  739. { Turn futher error messages off }
  740. p^.def.forwarddef:=false;
  741. end;
  742. p:=p^.next;
  743. end;
  744. end;
  745. procedure tprocsym.deref;
  746. var
  747. p : pprocdeflist;
  748. begin
  749. p:=defs;
  750. while assigned(p) do
  751. begin
  752. resolvedef(pointer(p^.def));
  753. p:=p^.next;
  754. end;
  755. end;
  756. procedure tprocsym.addprocdef(p:tprocdef);
  757. var
  758. pd : pprocdeflist;
  759. begin
  760. new(pd);
  761. pd^.def:=p;
  762. pd^.next:=defs;
  763. defs:=pd;
  764. end;
  765. function Tprocsym.procdef_count:byte;
  766. var pd:Pprocdeflist;
  767. begin
  768. procdef_count:=0;
  769. pd:=defs;
  770. while assigned(pd) do
  771. begin
  772. inc(procdef_count);
  773. pd:=pd^.next;
  774. end;
  775. end;
  776. function Tprocsym.procdef(nr:byte):Tprocdef;
  777. var i:byte;
  778. pd:Pprocdeflist;
  779. begin
  780. pd:=defs;
  781. for i:=2 to nr do
  782. pd:=pd^.next;
  783. procdef:=pd^.def;
  784. end;
  785. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym);
  786. var pd:Pprocdeflist;
  787. begin
  788. pd:=defs;
  789. while assigned(pd) do
  790. begin
  791. if Aprocsym.search_procdef_bypara(pd^.def.para)=nil then
  792. Aprocsym.addprocdef(pd^.def);
  793. pd:=pd^.next;
  794. end;
  795. end;
  796. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  797. var pd:Pprocdeflist;
  798. begin
  799. pd:=defs;
  800. while assigned(pd) do
  801. begin
  802. s.addprocdef(pd^.def);
  803. pd:=pd^.next;
  804. end;
  805. end;
  806. function Tprocsym.first_procdef:Tprocdef;
  807. begin
  808. first_procdef:=defs^.def;
  809. end;
  810. function Tprocsym.last_procdef:Tprocdef;
  811. var pd:Pprocdeflist;
  812. begin
  813. pd:=defs;
  814. while assigned(pd) do
  815. begin
  816. last_procdef:=pd^.def;
  817. pd:=pd^.next;
  818. end;
  819. end;
  820. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  821. var p:Pprocdeflist;
  822. begin
  823. p:=defs;
  824. while assigned(p) do
  825. begin
  826. proc2call(p^.def,arg);
  827. p:=p^.next;
  828. end;
  829. end;
  830. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  831. var p:Pprocdeflist;
  832. begin
  833. search_procdef_bytype:=nil;
  834. p:=defs;
  835. while p<>nil do
  836. begin
  837. if p^.def.proctypeoption=pt then
  838. begin
  839. search_procdef_bytype:=p^.def;
  840. break;
  841. end;
  842. p:=p^.next;
  843. end;
  844. end;
  845. function Tprocsym.search_procdef_bypara(params:Tparalinkedlist):Tprocdef;
  846. var pd:Pprocdeflist;
  847. begin
  848. search_procdef_bypara:=nil;
  849. pd:=defs;
  850. while assigned(pd) do
  851. begin
  852. if equal_paras(pd^.def.para,params,cp_value_equal_const) then
  853. begin
  854. search_procdef_bypara:=pd^.def;
  855. break;
  856. end;
  857. pd:=pd^.next;
  858. end;
  859. end;
  860. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  861. var pd:Pprocdeflist;
  862. begin
  863. {This function will return the pprocdef of pprocsym that
  864. is the best match for procvardef. When there are multiple
  865. matches it returns nil.}
  866. {Try to find an exact match first.}
  867. search_procdef_byprocvardef:=nil;
  868. pd:=defs;
  869. while assigned(pd) do
  870. begin
  871. if proc_to_procvar_equal(pd^.def,d,true) then
  872. begin
  873. { already found a match ? Then stop and return nil }
  874. if assigned(search_procdef_byprocvardef) then
  875. begin
  876. search_procdef_byprocvardef:=nil;
  877. break;
  878. end;
  879. search_procdef_byprocvardef:=pd^.def;
  880. end;
  881. pd:=pd^.next;
  882. end;
  883. {Try a convertable match, if no exact match was found.}
  884. if not assigned(search_procdef_byprocvardef) and not assigned(pd) then
  885. begin
  886. pd:=defs;
  887. while assigned(pd) do
  888. begin
  889. if proc_to_procvar_equal(pd^.def,d,false) then
  890. begin
  891. { already found a match ? Then stop and return nil }
  892. if assigned(search_procdef_byprocvardef) then
  893. begin
  894. search_procdef_byprocvardef:=nil;
  895. break;
  896. end;
  897. search_procdef_byprocvardef:=pd^.def;
  898. end;
  899. pd:=pd^.next;
  900. end;
  901. end;
  902. end;
  903. function Tprocsym.search_procdef_byretdef_by1paradef(retdef,firstpara:Tdef;
  904. matchtype:Tdefmatch):Tprocdef;
  905. var pd:Pprocdeflist;
  906. convtyp:Tconverttype;
  907. a,b:boolean;
  908. begin
  909. search_procdef_byretdef_by1paradef:=nil;
  910. pd:=defs;
  911. while assigned(pd) do
  912. begin
  913. a:=is_equal(retdef,pd^.def.rettype.def);
  914. {Alert alert alert alert alert alert alert!!!
  915. Make sure you never call isconvertable when a=false. You get
  916. endless recursion then. Originally a and b were placed in a
  917. single if statement. There was only one reason that it worked:
  918. short circuit boolean eval.}
  919. if a then
  920. case matchtype of
  921. dm_exact:
  922. b:=TParaItem(pd^.def.para.first).paratype.def=firstpara;
  923. dm_equal:
  924. b:=is_equal(Tparaitem(pd^.def.para.first).paratype.def,firstpara);
  925. dm_convertl1:
  926. b:=isconvertable(firstpara,Tparaitem(pd^.def.para.first).paratype.def,
  927. convtyp,ordconstn,false)=1;
  928. end;
  929. if a and b then
  930. begin
  931. search_procdef_byretdef_by1paradef:=pd^.def;
  932. break;
  933. end;
  934. pd:=pd^.next;
  935. end;
  936. end;
  937. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  938. var
  939. p : pprocdeflist;
  940. begin
  941. inherited writesym(ppufile);
  942. p:=defs;
  943. while assigned(p) do
  944. begin
  945. { only write the proc definitions that belong
  946. to this procsym }
  947. if (p^.def.procsym=self) then
  948. ppufile.putderef(p^.def);
  949. p:=p^.next;
  950. end;
  951. ppufile.putderef(nil);
  952. ppufile.writeentry(ibprocsym);
  953. end;
  954. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  955. var
  956. p : pprocdeflist;
  957. begin
  958. write_references:=false;
  959. if not inherited write_references(ppufile,locals) then
  960. exit;
  961. write_references:=true;
  962. p:=defs;
  963. while assigned(p) do
  964. begin
  965. if (p^.def.procsym=self) then
  966. p^.def.write_references(ppufile,locals);
  967. p:=p^.next;
  968. end;
  969. end;
  970. procedure tprocsym.unchain_overload;
  971. var
  972. p,hp,
  973. first,
  974. last : pprocdeflist;
  975. begin
  976. { remove all overloaded procdefs from the
  977. procdeflist that are not in the current symtable }
  978. first:=nil;
  979. last:=nil;
  980. p:=defs;
  981. while assigned(p) do
  982. begin
  983. hp:=p^.next;
  984. if (p^.def.procsym=self) then
  985. begin
  986. { keep in list }
  987. if not assigned(first) then
  988. begin
  989. first:=p;
  990. last:=p;
  991. end
  992. else
  993. last^.next:=p;
  994. last:=p;
  995. p^.next:=nil;
  996. end
  997. else
  998. begin
  999. { remove }
  1000. dispose(p);
  1001. end;
  1002. p:=hp;
  1003. end;
  1004. defs:=first;
  1005. end;
  1006. {$ifdef GDB}
  1007. function tprocsym.stabstring : pchar;
  1008. begin
  1009. internalerror(200111171);
  1010. stabstring:=nil;
  1011. end;
  1012. procedure tprocsym.concatstabto(asmlist : taasmoutput);
  1013. begin
  1014. internalerror(200111172);
  1015. end;
  1016. {$endif GDB}
  1017. {****************************************************************************
  1018. TERRORSYM
  1019. ****************************************************************************}
  1020. constructor terrorsym.create;
  1021. begin
  1022. inherited create('');
  1023. typ:=errorsym;
  1024. end;
  1025. {****************************************************************************
  1026. TPROPERTYSYM
  1027. ****************************************************************************}
  1028. constructor tpropertysym.create(const n : string);
  1029. begin
  1030. inherited create(n);
  1031. typ:=propertysym;
  1032. propoptions:=[];
  1033. index:=0;
  1034. default:=0;
  1035. proptype.reset;
  1036. indextype.reset;
  1037. readaccess:=tsymlist.create;
  1038. writeaccess:=tsymlist.create;
  1039. storedaccess:=tsymlist.create;
  1040. end;
  1041. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1042. begin
  1043. inherited loadsym(ppufile);
  1044. typ:=propertysym;
  1045. ppufile.getsmallset(propoptions);
  1046. if (ppo_is_override in propoptions) then
  1047. begin
  1048. propoverriden:=tpropertysym(ppufile.getderef);
  1049. { we need to have these objects initialized }
  1050. readaccess:=tsymlist.create;
  1051. writeaccess:=tsymlist.create;
  1052. storedaccess:=tsymlist.create;
  1053. end
  1054. else
  1055. begin
  1056. ppufile.gettype(proptype);
  1057. index:=ppufile.getlongint;
  1058. default:=ppufile.getlongint;
  1059. ppufile.gettype(indextype);
  1060. readaccess:=ppufile.getsymlist;
  1061. writeaccess:=ppufile.getsymlist;
  1062. storedaccess:=ppufile.getsymlist;
  1063. end;
  1064. end;
  1065. destructor tpropertysym.destroy;
  1066. begin
  1067. readaccess.free;
  1068. writeaccess.free;
  1069. storedaccess.free;
  1070. inherited destroy;
  1071. end;
  1072. function tpropertysym.gettypedef:tdef;
  1073. begin
  1074. gettypedef:=proptype.def;
  1075. end;
  1076. procedure tpropertysym.deref;
  1077. begin
  1078. if (ppo_is_override in propoptions) then
  1079. begin
  1080. resolvesym(pointer(propoverriden));
  1081. dooverride(propoverriden);
  1082. end
  1083. else
  1084. begin
  1085. proptype.resolve;
  1086. indextype.resolve;
  1087. readaccess.resolve;
  1088. writeaccess.resolve;
  1089. storedaccess.resolve;
  1090. end;
  1091. end;
  1092. function tpropertysym.getsize : longint;
  1093. begin
  1094. getsize:=0;
  1095. end;
  1096. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1097. begin
  1098. inherited writesym(ppufile);
  1099. ppufile.putsmallset(propoptions);
  1100. if (ppo_is_override in propoptions) then
  1101. ppufile.putderef(propoverriden)
  1102. else
  1103. begin
  1104. ppufile.puttype(proptype);
  1105. ppufile.putlongint(index);
  1106. ppufile.putlongint(default);
  1107. ppufile.puttype(indextype);
  1108. ppufile.putsymlist(readaccess);
  1109. ppufile.putsymlist(writeaccess);
  1110. ppufile.putsymlist(storedaccess);
  1111. end;
  1112. ppufile.writeentry(ibpropertysym);
  1113. end;
  1114. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1115. begin
  1116. propoverriden:=overriden;
  1117. proptype:=overriden.proptype;
  1118. propoptions:=overriden.propoptions+[ppo_is_override];
  1119. index:=overriden.index;
  1120. default:=overriden.default;
  1121. indextype:=overriden.indextype;
  1122. readaccess.free;
  1123. readaccess:=overriden.readaccess.getcopy;
  1124. writeaccess.free;
  1125. writeaccess:=overriden.writeaccess.getcopy;
  1126. storedaccess.free;
  1127. storedaccess:=overriden.storedaccess.getcopy;
  1128. end;
  1129. {$ifdef GDB}
  1130. function tpropertysym.stabstring : pchar;
  1131. begin
  1132. { !!!! don't know how to handle }
  1133. stabstring:=strpnew('');
  1134. end;
  1135. procedure tpropertysym.concatstabto(asmlist : taasmoutput);
  1136. begin
  1137. { !!!! don't know how to handle }
  1138. end;
  1139. {$endif GDB}
  1140. {****************************************************************************
  1141. TFUNCRETSYM
  1142. ****************************************************************************}
  1143. constructor tfuncretsym.create(const n : string;const tt:ttype);
  1144. begin
  1145. inherited create(n);
  1146. typ:=funcretsym;
  1147. returntype:=tt;
  1148. funcretstate:=vs_declared;
  1149. { address valid for ret in param only }
  1150. { otherwise set by insert }
  1151. address:=procinfo.return_offset;
  1152. end;
  1153. constructor tfuncretsym.ppuload(ppufile:tcompilerppufile);
  1154. begin
  1155. inherited loadsym(ppufile);
  1156. ppufile.gettype(returntype);
  1157. address:=ppufile.getlongint;
  1158. typ:=funcretsym;
  1159. end;
  1160. destructor tfuncretsym.destroy;
  1161. begin
  1162. inherited destroy;
  1163. end;
  1164. procedure tfuncretsym.ppuwrite(ppufile:tcompilerppufile);
  1165. begin
  1166. inherited writesym(ppufile);
  1167. ppufile.puttype(returntype);
  1168. ppufile.putlongint(address);
  1169. ppufile.writeentry(ibfuncretsym);
  1170. funcretstate:=vs_used;
  1171. end;
  1172. procedure tfuncretsym.deref;
  1173. begin
  1174. returntype.resolve;
  1175. end;
  1176. {$ifdef GDB}
  1177. procedure tfuncretsym.concatstabto(asmlist : taasmoutput);
  1178. begin
  1179. { Nothing to do here, it is done in genexitcode }
  1180. end;
  1181. {$endif GDB}
  1182. {****************************************************************************
  1183. TABSOLUTESYM
  1184. ****************************************************************************}
  1185. constructor tabsolutesym.create(const n : string;const tt : ttype);
  1186. begin
  1187. inherited create(n,tt);
  1188. typ:=absolutesym;
  1189. end;
  1190. constructor tabsolutesym.ppuload(ppufile:tcompilerppufile);
  1191. begin
  1192. { Note: This needs to load everything of tvarsym.write }
  1193. inherited ppuload(ppufile);
  1194. { load absolute }
  1195. typ:=absolutesym;
  1196. ref:=nil;
  1197. address:=0;
  1198. asmname:=nil;
  1199. abstyp:=absolutetyp(ppufile.getbyte);
  1200. absseg:=false;
  1201. case abstyp of
  1202. tovar :
  1203. asmname:=stringdup(ppufile.getstring);
  1204. toasm :
  1205. asmname:=stringdup(ppufile.getstring);
  1206. toaddr :
  1207. begin
  1208. address:=ppufile.getlongint;
  1209. absseg:=boolean(ppufile.getbyte);
  1210. end;
  1211. end;
  1212. end;
  1213. procedure tabsolutesym.ppuwrite(ppufile:tcompilerppufile);
  1214. var
  1215. hvo : tvaroptions;
  1216. begin
  1217. { Note: This needs to write everything of tvarsym.write }
  1218. inherited writesym(ppufile);
  1219. ppufile.putbyte(byte(varspez));
  1220. ppufile.putlongint(address);
  1221. { write only definition or definitionsym }
  1222. ppufile.puttype(vartype);
  1223. hvo:=varoptions-[vo_regable];
  1224. ppufile.putsmallset(hvo);
  1225. ppufile.putbyte(byte(abstyp));
  1226. case abstyp of
  1227. tovar :
  1228. ppufile.putstring(ref.name);
  1229. toasm :
  1230. ppufile.putstring(asmname^);
  1231. toaddr :
  1232. begin
  1233. ppufile.putlongint(address);
  1234. ppufile.putbyte(byte(absseg));
  1235. end;
  1236. end;
  1237. ppufile.writeentry(ibabsolutesym);
  1238. end;
  1239. procedure tabsolutesym.deref;
  1240. var
  1241. srsym : tsym;
  1242. srsymtable : tsymtable;
  1243. begin
  1244. { inheritance of varsym.deref ! }
  1245. vartype.resolve;
  1246. { own absolute deref }
  1247. if (abstyp=tovar) and (asmname<>nil) then
  1248. begin
  1249. { search previous loaded symtables }
  1250. searchsym(asmname^,srsym,srsymtable);
  1251. if not assigned(srsym) then
  1252. srsym:=searchsymonlyin(owner,asmname^);
  1253. if not assigned(srsym) then
  1254. srsym:=generrorsym;
  1255. ref:=tstoredsym(srsym);
  1256. stringdispose(asmname);
  1257. end;
  1258. end;
  1259. function tabsolutesym.mangledname : string;
  1260. begin
  1261. case abstyp of
  1262. tovar :
  1263. begin
  1264. case ref.typ of
  1265. varsym :
  1266. mangledname:=tvarsym(ref).mangledname;
  1267. else
  1268. internalerror(200111011);
  1269. end;
  1270. end;
  1271. toasm :
  1272. mangledname:=asmname^;
  1273. toaddr :
  1274. mangledname:='$'+tostr(address);
  1275. else
  1276. internalerror(10002);
  1277. end;
  1278. end;
  1279. {$ifdef GDB}
  1280. procedure tabsolutesym.concatstabto(asmlist : taasmoutput);
  1281. begin
  1282. { I don't know how to handle this !! }
  1283. end;
  1284. {$endif GDB}
  1285. {****************************************************************************
  1286. TVARSYM
  1287. ****************************************************************************}
  1288. constructor tvarsym.create(const n : string;const tt : ttype);
  1289. begin
  1290. inherited create(n);
  1291. typ:=varsym;
  1292. vartype:=tt;
  1293. _mangledname:=nil;
  1294. varspez:=vs_value;
  1295. address:=0;
  1296. localvarsym:=nil;
  1297. refs:=0;
  1298. varstate:=vs_used;
  1299. varoptions:=[];
  1300. { can we load the value into a register ? }
  1301. if tstoreddef(tt.def).is_intregable then
  1302. include(varoptions,vo_regable)
  1303. else
  1304. exclude(varoptions,vo_regable);
  1305. if tstoreddef(tt.def).is_fpuregable then
  1306. include(varoptions,vo_fpuregable)
  1307. else
  1308. exclude(varoptions,vo_fpuregable);
  1309. reg:=R_NO;
  1310. end;
  1311. constructor tvarsym.create_dll(const n : string;const tt : ttype);
  1312. begin
  1313. tvarsym(self).create(n,tt);
  1314. include(varoptions,vo_is_dll_var);
  1315. end;
  1316. constructor tvarsym.create_C(const n,mangled : string;const tt : ttype);
  1317. begin
  1318. tvarsym(self).create(n,tt);
  1319. include(varoptions,vo_is_C_var);
  1320. stringdispose(_mangledname);
  1321. _mangledname:=stringdup(mangled);
  1322. end;
  1323. constructor tvarsym.ppuload(ppufile:tcompilerppufile);
  1324. begin
  1325. inherited loadsym(ppufile);
  1326. typ:=varsym;
  1327. reg:=R_NO;
  1328. refs := 0;
  1329. varstate:=vs_used;
  1330. varspez:=tvarspez(ppufile.getbyte);
  1331. address:=ppufile.getlongint;
  1332. localvarsym:=nil;
  1333. ppufile.gettype(vartype);
  1334. ppufile.getsmallset(varoptions);
  1335. if (vo_is_C_var in varoptions) then
  1336. _mangledname:=stringdup(ppufile.getstring);
  1337. end;
  1338. destructor tvarsym.destroy;
  1339. begin
  1340. inherited destroy;
  1341. end;
  1342. procedure tvarsym.deref;
  1343. begin
  1344. vartype.resolve;
  1345. end;
  1346. procedure tvarsym.ppuwrite(ppufile:tcompilerppufile);
  1347. var
  1348. hvo : tvaroptions;
  1349. begin
  1350. inherited writesym(ppufile);
  1351. ppufile.putbyte(byte(varspez));
  1352. ppufile.putlongint(address);
  1353. ppufile.puttype(vartype);
  1354. { symbols which are load are never candidates for a register,
  1355. turn off the regable }
  1356. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1357. ppufile.putsmallset(hvo);
  1358. if (vo_is_C_var in varoptions) then
  1359. ppufile.putstring(mangledname);
  1360. ppufile.writeentry(ibvarsym);
  1361. end;
  1362. procedure tvarsym.generate_mangledname;
  1363. begin
  1364. _mangledname:=stringdup(mangledname_prefix('U',owner)+name);
  1365. end;
  1366. procedure tvarsym.set_mangledname(const s:string);
  1367. begin
  1368. stringdispose(_mangledname);
  1369. _mangledname:=stringdup(s);
  1370. end;
  1371. function tvarsym.getsize : longint;
  1372. begin
  1373. if assigned(vartype.def) then
  1374. getsize:=vartype.def.size
  1375. else
  1376. getsize:=0;
  1377. end;
  1378. function tvarsym.getvaluesize : longint;
  1379. begin
  1380. if assigned(vartype.def) and
  1381. (varspez=vs_value) and
  1382. ((vartype.def.deftype<>arraydef) or
  1383. tarraydef(vartype.def).isDynamicArray or
  1384. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1385. getvaluesize:=vartype.def.size
  1386. else
  1387. getvaluesize:=0;
  1388. end;
  1389. function tvarsym.getpushsize(is_cdecl:boolean) : longint;
  1390. begin
  1391. getpushsize:=-1;
  1392. if assigned(vartype.def) then
  1393. begin
  1394. case varspez of
  1395. vs_out,
  1396. vs_var :
  1397. getpushsize:=pointer_size;
  1398. vs_value,
  1399. vs_const :
  1400. begin
  1401. if paramanager.push_addr_param(vartype.def,is_cdecl) then
  1402. getpushsize:=pointer_size
  1403. else
  1404. getpushsize:=vartype.def.size;
  1405. end;
  1406. end;
  1407. end;
  1408. end;
  1409. {$ifdef GDB}
  1410. function tvarsym.stabstring : pchar;
  1411. var
  1412. st : string;
  1413. is_cdecl : boolean;
  1414. begin
  1415. st:=tstoreddef(vartype.def).numberstring;
  1416. if (owner.symtabletype = objectsymtable) and
  1417. (sp_static in symoptions) then
  1418. begin
  1419. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1420. stabstring := strpnew('"'+upper(owner.name^)+'__'+name+':'+st+
  1421. '",'+
  1422. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1423. end
  1424. else if (owner.symtabletype = globalsymtable) then
  1425. begin
  1426. { Here we used S instead of
  1427. because with G GDB doesn't look at the address field
  1428. but searches the same name or with a leading underscore
  1429. but these names don't exist in pascal !}
  1430. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1431. stabstring := strpnew('"'+name+':'+st+'",'+
  1432. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1433. end
  1434. else if owner.symtabletype = staticsymtable then
  1435. begin
  1436. stabstring := strpnew('"'+name+':S'+st+'",'+
  1437. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1438. end
  1439. else if (owner.symtabletype in [parasymtable,inlineparasymtable]) then
  1440. begin
  1441. is_cdecl:=(tprocdef(owner.defowner).proccalloption in [pocall_cdecl,pocall_cppdecl]);
  1442. case varspez of
  1443. vs_out,
  1444. vs_var : st := 'v'+st;
  1445. vs_value,
  1446. vs_const : if paramanager.push_addr_param(vartype.def,is_cdecl) then
  1447. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1448. else
  1449. st := 'p'+st;
  1450. end;
  1451. stabstring := strpnew('"'+name+':'+st+'",'+
  1452. tostr(N_tsym)+',0,'+tostr(fileinfo.line)+','+
  1453. tostr(address+owner.address_fixup));
  1454. {offset to ebp => will not work if the framepointer is esp
  1455. so some optimizing will make things harder to debug }
  1456. end
  1457. else if (owner.symtabletype in [localsymtable,inlinelocalsymtable]) then
  1458. if reg<>R_NO then
  1459. begin
  1460. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1461. { this is the register order for GDB}
  1462. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1463. tostr(N_RSYM)+',0,'+
  1464. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1465. end
  1466. else
  1467. { I don't know if this will work (PM) }
  1468. if (vo_is_C_var in varoptions) then
  1469. stabstring := strpnew('"'+name+':S'+st+'",'+
  1470. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1471. else
  1472. stabstring := strpnew('"'+name+':'+st+'",'+
  1473. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner.address_fixup))
  1474. else
  1475. stabstring := inherited stabstring;
  1476. end;
  1477. procedure tvarsym.concatstabto(asmlist : taasmoutput);
  1478. var stab_str : pchar;
  1479. begin
  1480. inherited concatstabto(asmlist);
  1481. if (owner.symtabletype=parasymtable) and
  1482. (reg<>R_NO) then
  1483. begin
  1484. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1485. { this is the register order for GDB}
  1486. stab_str:=strpnew('"'+name+':r'
  1487. +tstoreddef(vartype.def).numberstring+'",'+
  1488. tostr(N_RSYM)+',0,'+
  1489. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1490. asmList.concat(Tai_stabs.Create(stab_str));
  1491. end;
  1492. end;
  1493. {$endif GDB}
  1494. {****************************************************************************
  1495. TTYPEDCONSTSYM
  1496. *****************************************************************************}
  1497. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1498. begin
  1499. inherited create(n);
  1500. typ:=typedconstsym;
  1501. typedconsttype.setdef(p);
  1502. is_writable:=writable;
  1503. end;
  1504. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1505. begin
  1506. inherited create(n);
  1507. typ:=typedconstsym;
  1508. typedconsttype:=tt;
  1509. is_writable:=writable;
  1510. end;
  1511. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1512. begin
  1513. inherited loadsym(ppufile);
  1514. typ:=typedconstsym;
  1515. ppufile.gettype(typedconsttype);
  1516. is_writable:=boolean(ppufile.getbyte);
  1517. end;
  1518. destructor ttypedconstsym.destroy;
  1519. begin
  1520. inherited destroy;
  1521. end;
  1522. procedure ttypedconstsym.generate_mangledname;
  1523. begin
  1524. _mangledname:=stringdup(mangledname_prefix('TC',owner)+name);
  1525. end;
  1526. function ttypedconstsym.getsize : longint;
  1527. begin
  1528. if assigned(typedconsttype.def) then
  1529. getsize:=typedconsttype.def.size
  1530. else
  1531. getsize:=0;
  1532. end;
  1533. procedure ttypedconstsym.deref;
  1534. begin
  1535. typedconsttype.resolve;
  1536. end;
  1537. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1538. begin
  1539. inherited writesym(ppufile);
  1540. ppufile.puttype(typedconsttype);
  1541. ppufile.putbyte(byte(is_writable));
  1542. ppufile.writeentry(ibtypedconstsym);
  1543. end;
  1544. {$ifdef GDB}
  1545. function ttypedconstsym.stabstring : pchar;
  1546. var
  1547. st : char;
  1548. begin
  1549. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1550. st := 'G'
  1551. else
  1552. st := 'S';
  1553. stabstring := strpnew('"'+name+':'+st+
  1554. tstoreddef(typedconsttype.def).numberstring+'",'+tostr(n_STSYM)+',0,'+
  1555. tostr(fileinfo.line)+','+mangledname);
  1556. end;
  1557. {$endif GDB}
  1558. {****************************************************************************
  1559. TCONSTSYM
  1560. ****************************************************************************}
  1561. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt);
  1562. begin
  1563. inherited create(n);
  1564. typ:=constsym;
  1565. consttyp:=t;
  1566. valueord:=v;
  1567. valueordptr:=0;
  1568. valueptr:=nil;
  1569. ResStrIndex:=0;
  1570. consttype.reset;
  1571. len:=0;
  1572. end;
  1573. constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1574. begin
  1575. inherited create(n);
  1576. typ:=constsym;
  1577. consttyp:=t;
  1578. valueord:=v;
  1579. valueordptr:=0;
  1580. valueptr:=nil;
  1581. ResStrIndex:=0;
  1582. consttype:=tt;
  1583. len:=0;
  1584. end;
  1585. constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1586. begin
  1587. inherited create(n);
  1588. typ:=constsym;
  1589. consttyp:=t;
  1590. valueord:=0;
  1591. valueordptr:=v;
  1592. valueptr:=nil;
  1593. ResStrIndex:=0;
  1594. consttype:=tt;
  1595. len:=0;
  1596. end;
  1597. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer);
  1598. begin
  1599. inherited create(n);
  1600. typ:=constsym;
  1601. consttyp:=t;
  1602. valueord:=0;
  1603. valueordptr:=0;
  1604. valueptr:=v;
  1605. ResStrIndex:=0;
  1606. consttype.reset;
  1607. len:=0;
  1608. end;
  1609. constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1610. begin
  1611. inherited create(n);
  1612. typ:=constsym;
  1613. consttyp:=t;
  1614. valueord:=0;
  1615. valueordptr:=0;
  1616. valueptr:=v;
  1617. ResStrIndex:=0;
  1618. consttype:=tt;
  1619. len:=0;
  1620. end;
  1621. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1622. begin
  1623. inherited create(n);
  1624. typ:=constsym;
  1625. consttyp:=t;
  1626. valueord:=0;
  1627. valueordptr:=0;
  1628. valueptr:=str;
  1629. consttype.reset;
  1630. len:=l;
  1631. if t=constresourcestring then
  1632. ResStrIndex:=ResourceStrings.Register(name,pchar(valueptr),len);
  1633. end;
  1634. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1635. var
  1636. pd : pbestreal;
  1637. ps : pnormalset;
  1638. pc : pchar;
  1639. begin
  1640. inherited loadsym(ppufile);
  1641. typ:=constsym;
  1642. consttype.reset;
  1643. consttyp:=tconsttyp(ppufile.getbyte);
  1644. valueord:=0;
  1645. valueordptr:=0;
  1646. valueptr:=nil;
  1647. case consttyp of
  1648. constint:
  1649. valueord:=ppufile.getexprint;
  1650. constwchar,
  1651. constbool,
  1652. constchar :
  1653. valueord:=ppufile.getlongint;
  1654. constord :
  1655. begin
  1656. ppufile.gettype(consttype);
  1657. valueord:=ppufile.getexprint;
  1658. end;
  1659. constpointer :
  1660. begin
  1661. ppufile.gettype(consttype);
  1662. valueordptr:=ppufile.getptruint;
  1663. end;
  1664. conststring,
  1665. constresourcestring :
  1666. begin
  1667. len:=ppufile.getlongint;
  1668. getmem(pc,len+1);
  1669. ppufile.getdata(pc^,len);
  1670. if consttyp=constresourcestring then
  1671. ResStrIndex:=ppufile.getlongint;
  1672. valueptr:=pc;
  1673. end;
  1674. constreal :
  1675. begin
  1676. new(pd);
  1677. pd^:=ppufile.getreal;
  1678. valueptr:=pd;
  1679. end;
  1680. constset :
  1681. begin
  1682. ppufile.gettype(consttype);
  1683. new(ps);
  1684. ppufile.getnormalset(ps^);
  1685. valueptr:=ps;
  1686. end;
  1687. constnil : ;
  1688. else
  1689. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1690. end;
  1691. end;
  1692. destructor tconstsym.destroy;
  1693. begin
  1694. case consttyp of
  1695. conststring,
  1696. constresourcestring :
  1697. freemem(pchar(valueptr),len+1);
  1698. constreal :
  1699. dispose(pbestreal(valueptr));
  1700. constset :
  1701. dispose(pnormalset(valueptr));
  1702. end;
  1703. inherited destroy;
  1704. end;
  1705. function tconstsym.mangledname : string;
  1706. begin
  1707. mangledname:=name;
  1708. end;
  1709. procedure tconstsym.deref;
  1710. begin
  1711. if consttyp in [constord,constpointer,constset] then
  1712. consttype.resolve;
  1713. end;
  1714. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1715. begin
  1716. inherited writesym(ppufile);
  1717. ppufile.putbyte(byte(consttyp));
  1718. case consttyp of
  1719. constnil : ;
  1720. constint:
  1721. ppufile.putexprint(valueord);
  1722. constbool,
  1723. constchar :
  1724. ppufile.putlongint(valueord);
  1725. constord :
  1726. begin
  1727. ppufile.puttype(consttype);
  1728. ppufile.putexprint(valueord);
  1729. end;
  1730. constpointer :
  1731. begin
  1732. ppufile.puttype(consttype);
  1733. ppufile.putptruint(valueordptr);
  1734. end;
  1735. conststring,
  1736. constresourcestring :
  1737. begin
  1738. ppufile.putlongint(len);
  1739. ppufile.putdata(pchar(valueptr)^,len);
  1740. if consttyp=constresourcestring then
  1741. ppufile.putlongint(ResStrIndex);
  1742. end;
  1743. constreal :
  1744. ppufile.putreal(pbestreal(valueptr)^);
  1745. constset :
  1746. begin
  1747. ppufile.puttype(consttype);
  1748. ppufile.putnormalset(valueptr^);
  1749. end;
  1750. else
  1751. internalerror(13);
  1752. end;
  1753. ppufile.writeentry(ibconstsym);
  1754. end;
  1755. {$ifdef GDB}
  1756. function tconstsym.stabstring : pchar;
  1757. var st : string;
  1758. begin
  1759. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1760. case consttyp of
  1761. conststring : begin
  1762. st := 's'''+strpas(pchar(valueptr))+'''';
  1763. end;
  1764. constbool,
  1765. constint,
  1766. constord,
  1767. constchar : st := 'i'+int64tostr(valueord);
  1768. constpointer :
  1769. st := 'i'+int64tostr(valueordptr);
  1770. constreal : begin
  1771. system.str(pbestreal(valueptr)^,st);
  1772. st := 'r'+st;
  1773. end;
  1774. { if we don't know just put zero !! }
  1775. else st:='i0';
  1776. {***SETCONST}
  1777. {constset:;} {*** I don't know what to do with a set.}
  1778. { sets are not recognized by GDB}
  1779. {***}
  1780. end;
  1781. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1782. tostr(fileinfo.line)+',0');
  1783. end;
  1784. procedure tconstsym.concatstabto(asmlist : taasmoutput);
  1785. begin
  1786. if consttyp <> conststring then
  1787. inherited concatstabto(asmlist);
  1788. end;
  1789. {$endif GDB}
  1790. {****************************************************************************
  1791. TENUMSYM
  1792. ****************************************************************************}
  1793. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1794. begin
  1795. inherited create(n);
  1796. typ:=enumsym;
  1797. definition:=def;
  1798. value:=v;
  1799. { check for jumps }
  1800. if v>def.max+1 then
  1801. def.has_jumps:=true;
  1802. { update low and high }
  1803. if def.min>v then
  1804. def.setmin(v);
  1805. if def.max<v then
  1806. def.setmax(v);
  1807. order;
  1808. end;
  1809. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1810. begin
  1811. inherited loadsym(ppufile);
  1812. typ:=enumsym;
  1813. definition:=tenumdef(ppufile.getderef);
  1814. value:=ppufile.getlongint;
  1815. nextenum := Nil;
  1816. end;
  1817. procedure tenumsym.deref;
  1818. begin
  1819. resolvedef(pointer(definition));
  1820. order;
  1821. end;
  1822. procedure tenumsym.order;
  1823. var
  1824. sym : tenumsym;
  1825. begin
  1826. sym := tenumsym(definition.firstenum);
  1827. if sym = nil then
  1828. begin
  1829. definition.firstenum := self;
  1830. nextenum := nil;
  1831. exit;
  1832. end;
  1833. { reorder the symbols in increasing value }
  1834. if value < sym.value then
  1835. begin
  1836. nextenum := sym;
  1837. definition.firstenum := self;
  1838. end
  1839. else
  1840. begin
  1841. while (sym.value <= value) and assigned(sym.nextenum) do
  1842. sym := sym.nextenum;
  1843. nextenum := sym.nextenum;
  1844. sym.nextenum := self;
  1845. end;
  1846. end;
  1847. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1848. begin
  1849. inherited writesym(ppufile);
  1850. ppufile.putderef(definition);
  1851. ppufile.putlongint(value);
  1852. ppufile.writeentry(ibenumsym);
  1853. end;
  1854. {$ifdef GDB}
  1855. procedure tenumsym.concatstabto(asmlist : taasmoutput);
  1856. begin
  1857. {enum elements have no stab !}
  1858. end;
  1859. {$EndIf GDB}
  1860. {****************************************************************************
  1861. TTYPESYM
  1862. ****************************************************************************}
  1863. constructor ttypesym.create(const n : string;const tt : ttype);
  1864. begin
  1865. inherited create(n);
  1866. typ:=typesym;
  1867. restype:=tt;
  1868. {$ifdef GDB}
  1869. isusedinstab := false;
  1870. {$endif GDB}
  1871. { register the typesym for the definition }
  1872. if assigned(restype.def) and
  1873. (restype.def.deftype<>errordef) and
  1874. not(assigned(restype.def.typesym)) then
  1875. restype.def.typesym:=self;
  1876. end;
  1877. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1878. begin
  1879. inherited loadsym(ppufile);
  1880. typ:=typesym;
  1881. {$ifdef GDB}
  1882. isusedinstab := false;
  1883. {$endif GDB}
  1884. ppufile.gettype(restype);
  1885. end;
  1886. function ttypesym.gettypedef:tdef;
  1887. begin
  1888. gettypedef:=restype.def;
  1889. end;
  1890. procedure ttypesym.deref;
  1891. begin
  1892. restype.resolve;
  1893. end;
  1894. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1895. begin
  1896. inherited writesym(ppufile);
  1897. ppufile.puttype(restype);
  1898. ppufile.writeentry(ibtypesym);
  1899. end;
  1900. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1901. begin
  1902. inherited load_references(ppufile,locals);
  1903. if (restype.def.deftype=recorddef) then
  1904. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1905. if (restype.def.deftype=objectdef) then
  1906. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1907. end;
  1908. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1909. begin
  1910. if not inherited write_references(ppufile,locals) then
  1911. begin
  1912. { write address of this symbol if record or object
  1913. even if no real refs are there
  1914. because we need it for the symtable }
  1915. if (restype.def.deftype in [recorddef,objectdef]) then
  1916. begin
  1917. ppufile.putderef(self);
  1918. ppufile.writeentry(ibsymref);
  1919. end;
  1920. end;
  1921. write_references:=true;
  1922. if (restype.def.deftype=recorddef) then
  1923. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  1924. if (restype.def.deftype=objectdef) then
  1925. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  1926. end;
  1927. {$ifdef GDB}
  1928. function ttypesym.stabstring : pchar;
  1929. var
  1930. stabchar : string[2];
  1931. short : string;
  1932. begin
  1933. if restype.def.deftype in tagtypes then
  1934. stabchar := 'Tt'
  1935. else
  1936. stabchar := 't';
  1937. short := '"'+name+':'+stabchar+tstoreddef(restype.def).numberstring
  1938. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  1939. stabstring := strpnew(short);
  1940. end;
  1941. procedure ttypesym.concatstabto(asmlist : taasmoutput);
  1942. begin
  1943. {not stabs for forward defs }
  1944. if assigned(restype.def) then
  1945. if (restype.def.typesym = self) then
  1946. tstoreddef(restype.def).concatstabto(asmlist)
  1947. else
  1948. inherited concatstabto(asmlist);
  1949. end;
  1950. {$endif GDB}
  1951. {****************************************************************************
  1952. TSYSSYM
  1953. ****************************************************************************}
  1954. constructor tsyssym.create(const n : string;l : longint);
  1955. begin
  1956. inherited create(n);
  1957. typ:=syssym;
  1958. number:=l;
  1959. end;
  1960. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  1961. begin
  1962. inherited loadsym(ppufile);
  1963. typ:=syssym;
  1964. number:=ppufile.getlongint;
  1965. end;
  1966. destructor tsyssym.destroy;
  1967. begin
  1968. inherited destroy;
  1969. end;
  1970. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  1971. begin
  1972. inherited writesym(ppufile);
  1973. ppufile.putlongint(number);
  1974. ppufile.writeentry(ibsyssym);
  1975. end;
  1976. {$ifdef GDB}
  1977. procedure tsyssym.concatstabto(asmlist : taasmoutput);
  1978. begin
  1979. end;
  1980. {$endif GDB}
  1981. {****************************************************************************
  1982. TRTTISYM
  1983. ****************************************************************************}
  1984. constructor trttisym.create(const n:string;rt:trttitype);
  1985. const
  1986. prefix : array[trttitype] of string[5]=('$rtti','$init');
  1987. begin
  1988. inherited create(prefix[rt]+n);
  1989. typ:=rttisym;
  1990. lab:=nil;
  1991. rttityp:=rt;
  1992. end;
  1993. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  1994. begin
  1995. inherited loadsym(ppufile);
  1996. typ:=rttisym;
  1997. lab:=nil;
  1998. rttityp:=trttitype(ppufile.getbyte);
  1999. end;
  2000. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2001. begin
  2002. inherited writesym(ppufile);
  2003. ppufile.putbyte(byte(rttityp));
  2004. ppufile.writeentry(ibrttisym);
  2005. end;
  2006. function trttisym.mangledname : string;
  2007. const
  2008. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2009. var
  2010. s : string;
  2011. p : tsymtable;
  2012. begin
  2013. s:='';
  2014. p:=owner;
  2015. while assigned(p) and (p.symtabletype=localsymtable) do
  2016. begin
  2017. s:=s+'_'+p.defowner.name;
  2018. p:=p.defowner.owner;
  2019. end;
  2020. if not(p.symtabletype in [globalsymtable,staticsymtable]) then
  2021. internalerror(200108265);
  2022. mangledname:=prefix[rttityp]+p.name^+s+'$_'+Copy(name,5,255);
  2023. end;
  2024. function trttisym.get_label:tasmsymbol;
  2025. begin
  2026. { the label is always a global label }
  2027. if not assigned(lab) then
  2028. lab:=objectlibrary.newasmsymboltype(mangledname,AB_GLOBAL,AT_DATA);
  2029. get_label:=lab;
  2030. end;
  2031. { persistent rtti generation }
  2032. procedure generate_rtti(p:tsym);
  2033. var
  2034. rsym : trttisym;
  2035. def : tstoreddef;
  2036. begin
  2037. { rtti can only be generated for classes that are always typesyms }
  2038. if not(p.typ=typesym) then
  2039. internalerror(200108261);
  2040. def:=tstoreddef(ttypesym(p).restype.def);
  2041. { only create rtti once for each definition }
  2042. if not(df_has_rttitable in def.defoptions) then
  2043. begin
  2044. { definition should be in the same symtable as the symbol }
  2045. if p.owner<>def.owner then
  2046. internalerror(200108262);
  2047. { create rttisym }
  2048. rsym:=trttisym.create(p.name,fullrtti);
  2049. p.owner.insert(rsym);
  2050. { register rttisym in definition }
  2051. include(def.defoptions,df_has_rttitable);
  2052. def.rttitablesym:=rsym;
  2053. { write rtti data }
  2054. def.write_child_rtti_data(fullrtti);
  2055. if (cs_create_smart in aktmoduleswitches) then
  2056. rttiList.concat(Tai_cut.Create);
  2057. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2058. def.write_rtti_data(fullrtti);
  2059. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2060. end;
  2061. end;
  2062. { persistent init table generation }
  2063. procedure generate_inittable(p:tsym);
  2064. var
  2065. rsym : trttisym;
  2066. def : tstoreddef;
  2067. begin
  2068. { anonymous types are also allowed for records that can be varsym }
  2069. case p.typ of
  2070. typesym :
  2071. def:=tstoreddef(ttypesym(p).restype.def);
  2072. varsym :
  2073. def:=tstoreddef(tvarsym(p).vartype.def);
  2074. else
  2075. internalerror(200108263);
  2076. end;
  2077. { only create inittable once for each definition }
  2078. if not(df_has_inittable in def.defoptions) then
  2079. begin
  2080. { definition should be in the same symtable as the symbol }
  2081. if p.owner<>def.owner then
  2082. internalerror(200108264);
  2083. { create rttisym }
  2084. rsym:=trttisym.create(p.name,initrtti);
  2085. p.owner.insert(rsym);
  2086. { register rttisym in definition }
  2087. include(def.defoptions,df_has_inittable);
  2088. def.inittablesym:=rsym;
  2089. { write inittable data }
  2090. def.write_child_rtti_data(initrtti);
  2091. if (cs_create_smart in aktmoduleswitches) then
  2092. rttiList.concat(Tai_cut.Create);
  2093. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2094. def.write_rtti_data(initrtti);
  2095. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2096. end;
  2097. end;
  2098. end.
  2099. {
  2100. $Log$
  2101. Revision 1.57 2002-08-25 19:25:21 peter
  2102. * sym.insert_in_data removed
  2103. * symtable.insertvardata/insertconstdata added
  2104. * removed insert_in_data call from symtable.insert, it needs to be
  2105. called separatly. This allows to deref the address calculation
  2106. * procedures now calculate the parast addresses after the procedure
  2107. directives are parsed. This fixes the cdecl parast problem
  2108. * push_addr_param has an extra argument that specifies if cdecl is used
  2109. or not
  2110. Revision 1.56 2002/08/25 09:06:21 peter
  2111. * fixed loop in concat_procdefs
  2112. Revision 1.55 2002/08/20 16:54:40 peter
  2113. * write address of varsym always
  2114. Revision 1.54 2002/08/20 10:31:26 daniel
  2115. * Tcallnode.det_resulttype rewritten
  2116. Revision 1.53 2002/08/18 20:06:27 peter
  2117. * inlining is now also allowed in interface
  2118. * renamed write/load to ppuwrite/ppuload
  2119. * tnode storing in ppu
  2120. * nld,ncon,nbas are already updated for storing in ppu
  2121. Revision 1.52 2002/08/17 09:23:42 florian
  2122. * first part of procinfo rewrite
  2123. Revision 1.51 2002/08/16 14:24:59 carl
  2124. * issameref() to test if two references are the same (then emit no opcodes)
  2125. + ret_in_reg to replace ret_in_acc
  2126. (fix some register allocation bugs at the same time)
  2127. + save_std_register now has an extra parameter which is the
  2128. usedinproc registers
  2129. Revision 1.50 2002/08/13 21:40:57 florian
  2130. * more fixes for ppc calling conventions
  2131. Revision 1.49 2002/08/12 15:08:40 carl
  2132. + stab register indexes for powerpc (moved from gdb to cpubase)
  2133. + tprocessor enumeration moved to cpuinfo
  2134. + linker in target_info is now a class
  2135. * many many updates for m68k (will soon start to compile)
  2136. - removed some ifdef or correct them for correct cpu
  2137. Revision 1.48 2002/08/11 14:32:28 peter
  2138. * renamed current_library to objectlibrary
  2139. Revision 1.47 2002/08/11 13:24:14 peter
  2140. * saving of asmsymbols in ppu supported
  2141. * asmsymbollist global is removed and moved into a new class
  2142. tasmlibrarydata that will hold the info of a .a file which
  2143. corresponds with a single module. Added librarydata to tmodule
  2144. to keep the library info stored for the module. In the future the
  2145. objectfiles will also be stored to the tasmlibrarydata class
  2146. * all getlabel/newasmsymbol and friends are moved to the new class
  2147. Revision 1.46 2002/07/23 10:13:23 daniel
  2148. * Added important comment
  2149. Revision 1.45 2002/07/23 09:51:26 daniel
  2150. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2151. are worth comitting.
  2152. Revision 1.44 2002/07/20 17:45:29 daniel
  2153. * Register variables are now possible for global variables too. This is
  2154. important for small programs without procedures.
  2155. Revision 1.43 2002/07/20 11:57:58 florian
  2156. * types.pas renamed to defbase.pas because D6 contains a types
  2157. unit so this would conflicts if D6 programms are compiled
  2158. + Willamette/SSE2 instructions to assembler added
  2159. Revision 1.42 2002/07/11 14:41:31 florian
  2160. * start of the new generic parameter handling
  2161. Revision 1.41 2002/07/10 07:24:40 jonas
  2162. * memory leak fixes from Sergey Korshunoff
  2163. Revision 1.40 2002/07/01 18:46:27 peter
  2164. * internal linker
  2165. * reorganized aasm layer
  2166. Revision 1.39 2002/05/18 13:34:18 peter
  2167. * readded missing revisions
  2168. Revision 1.38 2002/05/16 19:46:45 carl
  2169. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2170. + try to fix temp allocation (still in ifdef)
  2171. + generic constructor calls
  2172. + start of tassembler / tmodulebase class cleanup
  2173. Revision 1.36 2002/05/12 16:53:15 peter
  2174. * moved entry and exitcode to ncgutil and cgobj
  2175. * foreach gets extra argument for passing local data to the
  2176. iterator function
  2177. * -CR checks also class typecasts at runtime by changing them
  2178. into as
  2179. * fixed compiler to cycle with the -CR option
  2180. * fixed stabs with elf writer, finally the global variables can
  2181. be watched
  2182. * removed a lot of routines from cga unit and replaced them by
  2183. calls to cgobj
  2184. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2185. u32bit then the other is typecasted also to u32bit without giving
  2186. a rangecheck warning/error.
  2187. * fixed pascal calling method with reversing also the high tree in
  2188. the parast, detected by tcalcst3 test
  2189. Revision 1.35 2002/04/19 15:46:03 peter
  2190. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  2191. in most cases and not written to the ppu
  2192. * add mangeledname_prefix() routine to generate the prefix of
  2193. manglednames depending on the current procedure, object and module
  2194. * removed static procprefix since the mangledname is now build only
  2195. on demand from tprocdef.mangledname
  2196. Revision 1.34 2002/04/16 16:12:47 peter
  2197. * give error when using enums with jumps as array index
  2198. * allow char as enum value
  2199. Revision 1.33 2002/04/15 19:08:22 carl
  2200. + target_info.size_of_pointer -> pointer_size
  2201. + some cleanup of unused types/variables
  2202. Revision 1.32 2002/04/07 13:37:29 carl
  2203. + change unit use
  2204. Revision 1.31 2002/02/03 09:30:04 peter
  2205. * more fixes for protected handling
  2206. }