symsym.pas 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. Implementation for the symbols types of the symtable
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symsym;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,
  23. { target }
  24. globtype,globals,
  25. { symtable }
  26. symconst,symbase,symtype,symdef,defcmp,
  27. { ppu }
  28. ppu,
  29. cclasses,symnot,
  30. { aasm }
  31. aasmbase,aasmtai,
  32. cpuinfo,cpubase,cgbase,cgutils,parabase
  33. ;
  34. type
  35. { this class is the base for all symbol objects }
  36. tstoredsym = class(tsym)
  37. public
  38. constructor create(const n : string);
  39. constructor ppuload(ppufile:tcompilerppufile);
  40. destructor destroy;override;
  41. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  42. {$ifdef GDB}
  43. function get_var_value(const s:string):string;
  44. function stabstr_evaluate(const s:string;vars:array of string):Pchar;
  45. procedure concatstabto(asmlist : taasmoutput);
  46. {$endif GDB}
  47. function mangledname : string; virtual;
  48. end;
  49. tlabelsym = class(tstoredsym)
  50. lab : tasmlabel;
  51. used,
  52. defined : boolean;
  53. code : pointer; { should be tnode }
  54. constructor create(const n : string; l : tasmlabel);
  55. constructor ppuload(ppufile:tcompilerppufile);
  56. function mangledname:string;override;
  57. procedure ppuwrite(ppufile:tcompilerppufile);override;
  58. {$ifdef GDB}
  59. function stabstring : pchar;override;
  60. {$endif GDB}
  61. end;
  62. tunitsym = class(Tstoredsym)
  63. unitsymtable : tsymtable;
  64. constructor create(const n : string;ref : tsymtable);
  65. constructor ppuload(ppufile:tcompilerppufile);
  66. destructor destroy;override;
  67. procedure ppuwrite(ppufile:tcompilerppufile);override;
  68. end;
  69. terrorsym = class(Tsym)
  70. constructor create;
  71. end;
  72. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  73. tprocsym = class(tstoredsym)
  74. protected
  75. pdlistfirst,
  76. pdlistlast : pprocdeflist; { linked list of overloaded procdefs }
  77. function getprocdef(nr:cardinal):Tprocdef;
  78. public
  79. procdef_count : byte;
  80. {$ifdef GDB}
  81. is_global : boolean;
  82. {$endif GDB}
  83. overloadchecked : boolean;
  84. property procdef[nr:cardinal]:Tprocdef read getprocdef;
  85. constructor create(const n : string);
  86. constructor ppuload(ppufile:tcompilerppufile);
  87. destructor destroy;override;
  88. { writes all declarations except the specified one }
  89. procedure write_parameter_lists(skipdef:tprocdef);
  90. { tests, if all procedures definitions are defined and not }
  91. { only forward }
  92. procedure check_forward;
  93. procedure unchain_overload;
  94. procedure ppuwrite(ppufile:tcompilerppufile);override;
  95. procedure buildderef;override;
  96. procedure deref;override;
  97. procedure addprocdef(p:tprocdef);
  98. procedure addprocdef_deref(const d:tderef);
  99. procedure add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  100. procedure concat_procdefs_to(s:Tprocsym);
  101. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  102. function first_procdef:Tprocdef;
  103. function last_procdef:Tprocdef;
  104. function search_procdef_nopara_boolret:Tprocdef;
  105. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  106. function search_procdef_bypara(para:tlist;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  107. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  108. function search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  109. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  110. function is_visible_for_object(currobjdef:tdef):boolean;override;
  111. {$ifdef GDB}
  112. function stabstring : pchar;override;
  113. {$endif GDB}
  114. end;
  115. ttypesym = class(Tstoredsym)
  116. restype : ttype;
  117. constructor create(const n : string;const tt : ttype);
  118. constructor ppuload(ppufile:tcompilerppufile);
  119. procedure ppuwrite(ppufile:tcompilerppufile);override;
  120. procedure buildderef;override;
  121. procedure deref;override;
  122. function gettypedef:tdef;override;
  123. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  124. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  125. {$ifdef GDB}
  126. function stabstring : pchar;override;
  127. {$endif GDB}
  128. end;
  129. tabstractvarsym = class(tstoredsym)
  130. varoptions : tvaroptions;
  131. varspez : tvarspez; { sets the type of access }
  132. varregable : tvarregable;
  133. varstate : tvarstate;
  134. notifications : Tlinkedlist;
  135. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  136. constructor ppuload(ppufile:tcompilerppufile);
  137. destructor destroy;override;
  138. procedure ppuwrite(ppufile:tcompilerppufile);override;
  139. procedure buildderef;override;
  140. procedure deref;override;
  141. function getsize : longint;
  142. function is_regvar:boolean;
  143. procedure trigger_notifications(what:Tnotification_flag);
  144. function register_notification(flags:Tnotification_flags;
  145. callback:Tnotification_callback):cardinal;
  146. procedure unregister_notification(id:cardinal);
  147. private
  148. procedure setvartype(const newtype: ttype);
  149. _vartype : ttype;
  150. public
  151. property vartype: ttype read _vartype write setvartype;
  152. end;
  153. tfieldvarsym = class(tabstractvarsym)
  154. fieldoffset : aint; { offset in record/object }
  155. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  156. constructor ppuload(ppufile:tcompilerppufile);
  157. procedure ppuwrite(ppufile:tcompilerppufile);override;
  158. {$ifdef GDB}
  159. function stabstring : pchar;override;
  160. {$endif GDB}
  161. end;
  162. tabstractnormalvarsym = class(tabstractvarsym)
  163. defaultconstsym : tsym;
  164. defaultconstsymderef : tderef;
  165. localloc : TLocation; { register/reference for local var }
  166. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  167. constructor ppuload(ppufile:tcompilerppufile);
  168. procedure ppuwrite(ppufile:tcompilerppufile);override;
  169. procedure buildderef;override;
  170. procedure deref;override;
  171. end;
  172. tlocalvarsym = class(tabstractnormalvarsym)
  173. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  174. constructor ppuload(ppufile:tcompilerppufile);
  175. procedure ppuwrite(ppufile:tcompilerppufile);override;
  176. {$ifdef GDB}
  177. function stabstring : pchar;override;
  178. {$endif GDB}
  179. end;
  180. tparavarsym = class(tabstractnormalvarsym)
  181. paraloc : array[tcallercallee] of TCGPara;
  182. paranr : word; { position of this parameter }
  183. {$ifdef EXTDEBUG}
  184. eqval : tequaltype;
  185. {$endif EXTDEBUG}
  186. constructor create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  187. constructor ppuload(ppufile:tcompilerppufile);
  188. destructor destroy;override;
  189. procedure ppuwrite(ppufile:tcompilerppufile);override;
  190. {$ifdef GDB}
  191. function stabstring : pchar;override;
  192. {$endif GDB}
  193. end;
  194. tglobalvarsym = class(tabstractnormalvarsym)
  195. private
  196. _mangledname : pstring;
  197. public
  198. constructor create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  199. constructor create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  200. constructor create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  201. constructor ppuload(ppufile:tcompilerppufile);
  202. destructor destroy;override;
  203. procedure ppuwrite(ppufile:tcompilerppufile);override;
  204. function mangledname:string;override;
  205. procedure set_mangledname(const s:string);
  206. {$ifdef GDB}
  207. function stabstring : pchar;override;
  208. {$endif GDB}
  209. end;
  210. tabsolutevarsym = class(tabstractvarsym)
  211. public
  212. abstyp : absolutetyp;
  213. {$ifdef i386}
  214. absseg : boolean;
  215. {$endif i386}
  216. asmname : pstring;
  217. addroffset : aint;
  218. ref : tsymlist;
  219. constructor create(const n : string;const tt : ttype);
  220. constructor create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  221. destructor destroy;override;
  222. constructor ppuload(ppufile:tcompilerppufile);
  223. procedure buildderef;override;
  224. procedure deref;override;
  225. function mangledname : string;override;
  226. procedure ppuwrite(ppufile:tcompilerppufile);override;
  227. {$ifdef gdb}
  228. function stabstring:Pchar;override;
  229. {$endif gdb}
  230. end;
  231. tpropertysym = class(Tstoredsym)
  232. propoptions : tpropertyoptions;
  233. propoverriden : tpropertysym;
  234. propoverridenderef : tderef;
  235. proptype,
  236. indextype : ttype;
  237. index,
  238. default : longint;
  239. readaccess,
  240. writeaccess,
  241. storedaccess : tsymlist;
  242. constructor create(const n : string);
  243. destructor destroy;override;
  244. constructor ppuload(ppufile:tcompilerppufile);
  245. function getsize : longint;
  246. procedure ppuwrite(ppufile:tcompilerppufile);override;
  247. function gettypedef:tdef;override;
  248. procedure buildderef;override;
  249. procedure deref;override;
  250. procedure dooverride(overriden:tpropertysym);
  251. end;
  252. ttypedconstsym = class(tstoredsym)
  253. private
  254. _mangledname : pstring;
  255. public
  256. typedconsttype : ttype;
  257. is_writable : boolean;
  258. constructor create(const n : string;p : tdef;writable : boolean);
  259. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  260. constructor ppuload(ppufile:tcompilerppufile);
  261. destructor destroy;override;
  262. function mangledname : string;override;
  263. procedure ppuwrite(ppufile:tcompilerppufile);override;
  264. procedure buildderef;override;
  265. procedure deref;override;
  266. function getsize:longint;
  267. {$ifdef GDB}
  268. function stabstring : pchar;override;
  269. {$endif GDB}
  270. end;
  271. tconstvalue = record
  272. case integer of
  273. 0: (valueord : tconstexprint);
  274. 1: (valueordptr : tconstptruint);
  275. 2: (valueptr : pointer; len : longint);
  276. end;
  277. tconstsym = class(tstoredsym)
  278. consttype : ttype;
  279. consttyp : tconsttyp;
  280. value : tconstvalue;
  281. resstrindex : longint; { needed for resource strings }
  282. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  283. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  284. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  285. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  286. constructor ppuload(ppufile:tcompilerppufile);
  287. destructor destroy;override;
  288. procedure buildderef;override;
  289. procedure deref;override;
  290. procedure ppuwrite(ppufile:tcompilerppufile);override;
  291. {$ifdef GDB}
  292. function stabstring : pchar;override;
  293. {$endif GDB}
  294. end;
  295. tenumsym = class(Tstoredsym)
  296. value : longint;
  297. definition : tenumdef;
  298. definitionderef : tderef;
  299. nextenum : tenumsym;
  300. constructor create(const n : string;def : tenumdef;v : longint);
  301. constructor ppuload(ppufile:tcompilerppufile);
  302. procedure ppuwrite(ppufile:tcompilerppufile);override;
  303. procedure buildderef;override;
  304. procedure deref;override;
  305. procedure order;
  306. end;
  307. tsyssym = class(Tstoredsym)
  308. number : longint;
  309. constructor create(const n : string;l : longint);
  310. constructor ppuload(ppufile:tcompilerppufile);
  311. destructor destroy;override;
  312. procedure ppuwrite(ppufile:tcompilerppufile);override;
  313. end;
  314. const
  315. maxmacrolen=16*1024;
  316. type
  317. pmacrobuffer = ^tmacrobuffer;
  318. tmacrobuffer = array[0..maxmacrolen-1] of char;
  319. tmacro = class(tstoredsym)
  320. {Normally true, but false when a previously defined macro is undef-ed}
  321. defined : boolean;
  322. {True if this is a mac style compiler variable, in which case no macro
  323. substitutions shall be done.}
  324. is_compiler_var : boolean;
  325. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  326. {e. g. an IFDEF which returns false, will not be registered as used,}
  327. {since there is no place to register its use. }
  328. is_used : boolean;
  329. buftext : pchar;
  330. buflen : longint;
  331. constructor create(const n : string);
  332. constructor ppuload(ppufile:tcompilerppufile);
  333. procedure ppuwrite(ppufile:tcompilerppufile);override;
  334. destructor destroy;override;
  335. end;
  336. { compiler generated symbol to point to rtti and init/finalize tables }
  337. trttisym = class(tstoredsym)
  338. private
  339. _mangledname : pstring;
  340. public
  341. lab : tasmsymbol;
  342. rttityp : trttitype;
  343. constructor create(const n:string;rt:trttitype);
  344. constructor ppuload(ppufile:tcompilerppufile);
  345. destructor destroy;override;
  346. procedure ppuwrite(ppufile:tcompilerppufile);override;
  347. function mangledname:string;override;
  348. function get_label:tasmsymbol;
  349. end;
  350. var
  351. generrorsym : tsym;
  352. implementation
  353. uses
  354. { global }
  355. verbose,
  356. { target }
  357. systems,
  358. { symtable }
  359. defutil,symtable,
  360. { tree }
  361. node,
  362. { aasm }
  363. {$ifdef gdb}
  364. gdb,
  365. {$endif gdb}
  366. { codegen }
  367. paramgr,cresstr,
  368. procinfo
  369. ;
  370. {****************************************************************************
  371. Helpers
  372. ****************************************************************************}
  373. {****************************************************************************
  374. TSYM (base for all symtypes)
  375. ****************************************************************************}
  376. constructor tstoredsym.create(const n : string);
  377. begin
  378. inherited create(n);
  379. end;
  380. constructor tstoredsym.ppuload(ppufile:tcompilerppufile);
  381. var
  382. nr : word;
  383. s : string;
  384. begin
  385. nr:=ppufile.getword;
  386. s:=ppufile.getstring;
  387. if s[1]='$' then
  388. inherited createname(copy(s,2,255))
  389. else
  390. inherited createname(upper(s));
  391. _realname:=stringdup(s);
  392. typ:=abstractsym;
  393. { force the correct indexnr. must be after create! }
  394. indexnr:=nr;
  395. ppufile.getposinfo(fileinfo);
  396. ppufile.getsmallset(symoptions);
  397. lastref:=nil;
  398. defref:=nil;
  399. refs:=0;
  400. lastwritten:=nil;
  401. refcount:=0;
  402. {$ifdef GDB}
  403. isstabwritten := false;
  404. {$endif GDB}
  405. end;
  406. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  407. begin
  408. ppufile.putword(indexnr);
  409. ppufile.putstring(_realname^);
  410. ppufile.putposinfo(fileinfo);
  411. ppufile.putsmallset(symoptions);
  412. end;
  413. destructor tstoredsym.destroy;
  414. begin
  415. if assigned(defref) then
  416. begin
  417. {$ifdef MEMDEBUG}
  418. membrowser.start;
  419. {$endif MEMDEBUG}
  420. defref.freechain;
  421. defref.free;
  422. {$ifdef MEMDEBUG}
  423. membrowser.stop;
  424. {$endif MEMDEBUG}
  425. end;
  426. inherited destroy;
  427. end;
  428. {$ifdef GDB}
  429. function Tstoredsym.get_var_value(const s:string):string;
  430. begin
  431. if s='mangledname' then
  432. get_var_value:=mangledname
  433. else
  434. get_var_value:=inherited get_var_value(s);
  435. end;
  436. function Tstoredsym.stabstr_evaluate(const s:string;vars:array of string):Pchar;
  437. begin
  438. stabstr_evaluate:=string_evaluate(s,@get_var_value,vars);
  439. end;
  440. procedure tstoredsym.concatstabto(asmlist : taasmoutput);
  441. var
  442. stabstr : Pchar;
  443. begin
  444. stabstr:=stabstring;
  445. if stabstr<>nil then
  446. asmlist.concat(Tai_stabs.create(stabstr));
  447. end;
  448. {$endif GDB}
  449. function tstoredsym.mangledname : string;
  450. begin
  451. internalerror(200204171);
  452. end;
  453. {****************************************************************************
  454. TLABELSYM
  455. ****************************************************************************}
  456. constructor tlabelsym.create(const n : string; l : tasmlabel);
  457. begin
  458. inherited create(n);
  459. typ:=labelsym;
  460. lab:=l;
  461. used:=false;
  462. defined:=false;
  463. code:=nil;
  464. end;
  465. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  466. begin
  467. inherited ppuload(ppufile);
  468. typ:=labelsym;
  469. { this is all dummy
  470. it is only used for local browsing }
  471. lab:=nil;
  472. code:=nil;
  473. used:=false;
  474. defined:=true;
  475. end;
  476. function tlabelsym.mangledname:string;
  477. begin
  478. result:=lab.name;
  479. end;
  480. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  481. begin
  482. if owner.symtabletype=globalsymtable then
  483. Message(sym_e_ill_label_decl)
  484. else
  485. begin
  486. inherited ppuwrite(ppufile);
  487. ppufile.writeentry(iblabelsym);
  488. end;
  489. end;
  490. {$ifdef GDB}
  491. function Tlabelsym.stabstring : pchar;
  492. begin
  493. stabstring:=stabstr_evaluate('"${name}",${N_LSYM},0,${line},0',[]);
  494. end;
  495. {$endif GDB}
  496. {****************************************************************************
  497. TUNITSYM
  498. ****************************************************************************}
  499. constructor tunitsym.create(const n : string;ref : tsymtable);
  500. var
  501. old_make_ref : boolean;
  502. begin
  503. old_make_ref:=make_ref;
  504. make_ref:=false;
  505. inherited create(n);
  506. make_ref:=old_make_ref;
  507. typ:=unitsym;
  508. unitsymtable:=ref;
  509. end;
  510. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  511. begin
  512. inherited ppuload(ppufile);
  513. typ:=unitsym;
  514. unitsymtable:=nil;
  515. end;
  516. destructor tunitsym.destroy;
  517. begin
  518. inherited destroy;
  519. end;
  520. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  521. begin
  522. inherited ppuwrite(ppufile);
  523. ppufile.writeentry(ibunitsym);
  524. end;
  525. {****************************************************************************
  526. TPROCSYM
  527. ****************************************************************************}
  528. constructor tprocsym.create(const n : string);
  529. begin
  530. inherited create(n);
  531. typ:=procsym;
  532. pdlistfirst:=nil;
  533. pdlistlast:=nil;
  534. owner:=nil;
  535. {$ifdef GDB}
  536. is_global:=false;
  537. {$endif GDB}
  538. { the tprocdef have their own symoptions, make the procsym
  539. always visible }
  540. symoptions:=[sp_public];
  541. overloadchecked:=false;
  542. procdef_count:=0;
  543. end;
  544. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  545. var
  546. pdderef : tderef;
  547. i,n : longint;
  548. begin
  549. inherited ppuload(ppufile);
  550. typ:=procsym;
  551. pdlistfirst:=nil;
  552. pdlistlast:=nil;
  553. procdef_count:=0;
  554. n:=ppufile.getword;
  555. for i:=1to n do
  556. begin
  557. ppufile.getderef(pdderef);
  558. addprocdef_deref(pdderef);
  559. end;
  560. {$ifdef GDB}
  561. is_global:=false;
  562. {$endif GDB}
  563. overloadchecked:=false;
  564. end;
  565. destructor tprocsym.destroy;
  566. var
  567. hp,p : pprocdeflist;
  568. begin
  569. p:=pdlistfirst;
  570. while assigned(p) do
  571. begin
  572. hp:=p^.next;
  573. dispose(p);
  574. p:=hp;
  575. end;
  576. inherited destroy;
  577. end;
  578. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  579. var
  580. p : pprocdeflist;
  581. n : word;
  582. begin
  583. inherited ppuwrite(ppufile);
  584. { count procdefs }
  585. n:=0;
  586. p:=pdlistfirst;
  587. while assigned(p) do
  588. begin
  589. { only write the proc definitions that belong
  590. to this procsym and are in the global symtable }
  591. if p^.own and
  592. (p^.def.owner.symtabletype in [globalsymtable,objectsymtable]) then
  593. inc(n);
  594. p:=p^.next;
  595. end;
  596. ppufile.putword(n);
  597. { write procdefs }
  598. p:=pdlistfirst;
  599. while assigned(p) do
  600. begin
  601. { only write the proc definitions that belong
  602. to this procsym and are in the global symtable }
  603. if p^.own and
  604. (p^.def.owner.symtabletype in [globalsymtable,objectsymtable]) then
  605. ppufile.putderef(p^.defderef);
  606. p:=p^.next;
  607. end;
  608. ppufile.writeentry(ibprocsym);
  609. end;
  610. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  611. var
  612. p : pprocdeflist;
  613. begin
  614. p:=pdlistfirst;
  615. while assigned(p) do
  616. begin
  617. if p^.def<>skipdef then
  618. MessagePos1(p^.def.fileinfo,sym_h_param_list,p^.def.fullprocname(false));
  619. p:=p^.next;
  620. end;
  621. end;
  622. {Makes implicit externals (procedures declared in the interface
  623. section which do not have a counterpart in the implementation)
  624. to be an imported procedure. For mode macpas.}
  625. procedure import_implict_external(pd:tabstractprocdef);
  626. begin
  627. tprocdef(pd).forwarddef:=false;
  628. tprocdef(pd).setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  629. end;
  630. procedure tprocsym.check_forward;
  631. var
  632. p : pprocdeflist;
  633. begin
  634. p:=pdlistfirst;
  635. while assigned(p) do
  636. begin
  637. if p^.own and (p^.def.forwarddef) then
  638. begin
  639. if (m_mac in aktmodeswitches) and (p^.def.interfacedef) then
  640. import_implict_external(p^.def)
  641. else
  642. begin
  643. MessagePos1(p^.def.fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname(false));
  644. { Turn further error messages off }
  645. p^.def.forwarddef:=false;
  646. end
  647. end;
  648. p:=p^.next;
  649. end;
  650. end;
  651. procedure tprocsym.buildderef;
  652. var
  653. p : pprocdeflist;
  654. begin
  655. p:=pdlistfirst;
  656. while assigned(p) do
  657. begin
  658. if p^.own then
  659. p^.defderef.build(p^.def);
  660. p:=p^.next;
  661. end;
  662. end;
  663. procedure tprocsym.deref;
  664. var
  665. p : pprocdeflist;
  666. begin
  667. { We have removed the overloaded entries, because they
  668. are not valid anymore and we can't deref them because
  669. the unit were they come from is not necessary in
  670. our uses clause (PFV) }
  671. unchain_overload;
  672. { Deref our own procdefs }
  673. p:=pdlistfirst;
  674. while assigned(p) do
  675. begin
  676. if not p^.own then
  677. internalerror(200310291);
  678. p^.def:=tprocdef(p^.defderef.resolve);
  679. p:=p^.next;
  680. end;
  681. end;
  682. procedure tprocsym.addprocdef(p:tprocdef);
  683. var
  684. pd : pprocdeflist;
  685. begin
  686. new(pd);
  687. pd^.def:=p;
  688. pd^.defderef.reset;
  689. pd^.next:=nil;
  690. pd^.own:=(pd^.def.procsym=self);
  691. { Add at end of list to keep always
  692. a correct order, also after loading from ppu }
  693. if assigned(pdlistlast) then
  694. begin
  695. pdlistlast^.next:=pd;
  696. pdlistlast:=pd;
  697. end
  698. else
  699. begin
  700. pdlistfirst:=pd;
  701. pdlistlast:=pd;
  702. end;
  703. inc(procdef_count);
  704. end;
  705. procedure tprocsym.addprocdef_deref(const d:tderef);
  706. var
  707. pd : pprocdeflist;
  708. begin
  709. new(pd);
  710. pd^.def:=nil;
  711. pd^.defderef:=d;
  712. pd^.next:=nil;
  713. pd^.own:=true;
  714. { Add at end of list to keep always
  715. a correct order, also after loading from ppu }
  716. if assigned(pdlistlast) then
  717. begin
  718. pdlistlast^.next:=pd;
  719. pdlistlast:=pd;
  720. end
  721. else
  722. begin
  723. pdlistfirst:=pd;
  724. pdlistlast:=pd;
  725. end;
  726. inc(procdef_count);
  727. end;
  728. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  729. var
  730. i : cardinal;
  731. pd : pprocdeflist;
  732. begin
  733. pd:=pdlistfirst;
  734. for i:=2 to nr do
  735. begin
  736. if not assigned(pd) then
  737. internalerror(200209051);
  738. pd:=pd^.next;
  739. end;
  740. getprocdef:=pd^.def;
  741. end;
  742. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  743. var
  744. pd:pprocdeflist;
  745. begin
  746. pd:=pdlistfirst;
  747. while assigned(pd) do
  748. begin
  749. if Aprocsym.search_procdef_bypara(pd^.def.paras,nil,cpoptions)=nil then
  750. Aprocsym.addprocdef(pd^.def);
  751. pd:=pd^.next;
  752. end;
  753. end;
  754. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  755. var
  756. pd : pprocdeflist;
  757. begin
  758. pd:=pdlistfirst;
  759. while assigned(pd) do
  760. begin
  761. s.addprocdef(pd^.def);
  762. pd:=pd^.next;
  763. end;
  764. end;
  765. function Tprocsym.first_procdef:Tprocdef;
  766. begin
  767. if assigned(pdlistfirst) then
  768. first_procdef:=pdlistfirst^.def
  769. else
  770. first_procdef:=nil;
  771. end;
  772. function Tprocsym.last_procdef:Tprocdef;
  773. begin
  774. if assigned(pdlistlast) then
  775. last_procdef:=pdlistlast^.def
  776. else
  777. last_procdef:=nil;
  778. end;
  779. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  780. var
  781. p : pprocdeflist;
  782. begin
  783. p:=pdlistfirst;
  784. while assigned(p) do
  785. begin
  786. proc2call(p^.def,arg);
  787. p:=p^.next;
  788. end;
  789. end;
  790. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  791. var
  792. p : pprocdeflist;
  793. begin
  794. search_procdef_nopara_boolret:=nil;
  795. p:=pdlistfirst;
  796. while p<>nil do
  797. begin
  798. if (p^.def.maxparacount=0) and
  799. is_boolean(p^.def.rettype.def) then
  800. begin
  801. search_procdef_nopara_boolret:=p^.def;
  802. break;
  803. end;
  804. p:=p^.next;
  805. end;
  806. end;
  807. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  808. var
  809. p : pprocdeflist;
  810. begin
  811. search_procdef_bytype:=nil;
  812. p:=pdlistfirst;
  813. while p<>nil do
  814. begin
  815. if p^.def.proctypeoption=pt then
  816. begin
  817. search_procdef_bytype:=p^.def;
  818. break;
  819. end;
  820. p:=p^.next;
  821. end;
  822. end;
  823. function Tprocsym.search_procdef_bypara(para:tlist;retdef:tdef;
  824. cpoptions:tcompare_paras_options):Tprocdef;
  825. var
  826. pd : pprocdeflist;
  827. eq : tequaltype;
  828. begin
  829. search_procdef_bypara:=nil;
  830. pd:=pdlistfirst;
  831. while assigned(pd) do
  832. begin
  833. if assigned(retdef) then
  834. eq:=compare_defs(retdef,pd^.def.rettype.def,nothingn)
  835. else
  836. eq:=te_equal;
  837. if (eq>=te_equal) or
  838. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  839. begin
  840. eq:=compare_paras(para,pd^.def.paras,cp_value_equal_const,cpoptions);
  841. if (eq>=te_equal) or
  842. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  843. begin
  844. search_procdef_bypara:=pd^.def;
  845. break;
  846. end;
  847. end;
  848. pd:=pd^.next;
  849. end;
  850. end;
  851. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  852. var
  853. pd : pprocdeflist;
  854. eq,besteq : tequaltype;
  855. bestpd : tprocdef;
  856. begin
  857. { This function will return the pprocdef of pprocsym that
  858. is the best match for procvardef. When there are multiple
  859. matches it returns nil.}
  860. search_procdef_byprocvardef:=nil;
  861. bestpd:=nil;
  862. besteq:=te_incompatible;
  863. pd:=pdlistfirst;
  864. while assigned(pd) do
  865. begin
  866. eq:=proc_to_procvar_equal(pd^.def,d,false);
  867. if eq>=te_equal then
  868. begin
  869. { multiple procvars with the same equal level }
  870. if assigned(bestpd) and
  871. (besteq=eq) then
  872. exit;
  873. if eq>besteq then
  874. begin
  875. besteq:=eq;
  876. bestpd:=pd^.def;
  877. end;
  878. end;
  879. pd:=pd^.next;
  880. end;
  881. search_procdef_byprocvardef:=bestpd;
  882. end;
  883. function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  884. var
  885. convtyp : tconverttype;
  886. pd : pprocdeflist;
  887. bestpd : tprocdef;
  888. eq,
  889. besteq : tequaltype;
  890. hpd : tprocdef;
  891. i : byte;
  892. begin
  893. result:=nil;
  894. bestpd:=nil;
  895. besteq:=te_incompatible;
  896. pd:=pdlistfirst;
  897. while assigned(pd) do
  898. begin
  899. if equal_defs(todef,pd^.def.rettype.def) then
  900. begin
  901. i:=0;
  902. { ignore vs_hidden parameters }
  903. while assigned(pd^.def.paras[i]) and
  904. (vo_is_hidden_para in tparavarsym(pd^.def.paras[i]).varoptions) do
  905. inc(i);
  906. if assigned(pd^.def.paras[i]) then
  907. begin
  908. eq:=compare_defs_ext(fromdef,tparavarsym(pd^.def.paras[i]).vartype.def,nothingn,convtyp,hpd,[]);
  909. if eq=te_exact then
  910. begin
  911. result:=pd^.def;
  912. exit;
  913. end;
  914. if eq>besteq then
  915. begin
  916. bestpd:=pd^.def;
  917. besteq:=eq;
  918. end;
  919. end;
  920. end;
  921. pd:=pd^.next;
  922. end;
  923. result:=bestpd;
  924. end;
  925. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  926. var
  927. p : pprocdeflist;
  928. begin
  929. write_references:=false;
  930. if not inherited write_references(ppufile,locals) then
  931. exit;
  932. write_references:=true;
  933. p:=pdlistfirst;
  934. while assigned(p) do
  935. begin
  936. if p^.own then
  937. p^.def.write_references(ppufile,locals);
  938. p:=p^.next;
  939. end;
  940. end;
  941. procedure tprocsym.unchain_overload;
  942. var
  943. p,hp : pprocdeflist;
  944. begin
  945. { remove all overloaded procdefs from the
  946. procdeflist that are not in the current symtable }
  947. overloadchecked:=false;
  948. p:=pdlistfirst;
  949. { reset new lists }
  950. pdlistfirst:=nil;
  951. pdlistlast:=nil;
  952. while assigned(p) do
  953. begin
  954. hp:=p^.next;
  955. if p^.own then
  956. begin
  957. { keep, add to list }
  958. if assigned(pdlistlast) then
  959. begin
  960. pdlistlast^.next:=p;
  961. pdlistlast:=p;
  962. end
  963. else
  964. begin
  965. pdlistfirst:=p;
  966. pdlistlast:=p;
  967. end;
  968. p^.next:=nil;
  969. end
  970. else
  971. begin
  972. { remove }
  973. dispose(p);
  974. dec(procdef_count);
  975. end;
  976. p:=hp;
  977. end;
  978. end;
  979. function tprocsym.is_visible_for_object(currobjdef:tdef):boolean;
  980. var
  981. p : pprocdeflist;
  982. begin
  983. { This procsym is visible, when there is at least
  984. one of the procdefs visible }
  985. result:=false;
  986. p:=pdlistfirst;
  987. while assigned(p) do
  988. begin
  989. if p^.own and
  990. p^.def.is_visible_for_object(tobjectdef(currobjdef)) then
  991. begin
  992. result:=true;
  993. exit;
  994. end;
  995. p:=p^.next;
  996. end;
  997. end;
  998. {$ifdef GDB}
  999. function tprocsym.stabstring : pchar;
  1000. begin
  1001. internalerror(200111171);
  1002. result:=nil;
  1003. end;
  1004. {$endif GDB}
  1005. {****************************************************************************
  1006. TERRORSYM
  1007. ****************************************************************************}
  1008. constructor terrorsym.create;
  1009. begin
  1010. inherited create('');
  1011. typ:=errorsym;
  1012. end;
  1013. {****************************************************************************
  1014. TPROPERTYSYM
  1015. ****************************************************************************}
  1016. constructor tpropertysym.create(const n : string);
  1017. begin
  1018. inherited create(n);
  1019. typ:=propertysym;
  1020. propoptions:=[];
  1021. index:=0;
  1022. default:=0;
  1023. proptype.reset;
  1024. indextype.reset;
  1025. readaccess:=tsymlist.create;
  1026. writeaccess:=tsymlist.create;
  1027. storedaccess:=tsymlist.create;
  1028. end;
  1029. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1030. begin
  1031. inherited ppuload(ppufile);
  1032. typ:=propertysym;
  1033. ppufile.getsmallset(propoptions);
  1034. if (ppo_is_override in propoptions) then
  1035. begin
  1036. ppufile.getderef(propoverridenderef);
  1037. { we need to have these objects initialized }
  1038. readaccess:=tsymlist.create;
  1039. writeaccess:=tsymlist.create;
  1040. storedaccess:=tsymlist.create;
  1041. end
  1042. else
  1043. begin
  1044. ppufile.gettype(proptype);
  1045. index:=ppufile.getlongint;
  1046. default:=ppufile.getlongint;
  1047. ppufile.gettype(indextype);
  1048. readaccess:=ppufile.getsymlist;
  1049. writeaccess:=ppufile.getsymlist;
  1050. storedaccess:=ppufile.getsymlist;
  1051. end;
  1052. end;
  1053. destructor tpropertysym.destroy;
  1054. begin
  1055. readaccess.free;
  1056. writeaccess.free;
  1057. storedaccess.free;
  1058. inherited destroy;
  1059. end;
  1060. function tpropertysym.gettypedef:tdef;
  1061. begin
  1062. gettypedef:=proptype.def;
  1063. end;
  1064. procedure tpropertysym.buildderef;
  1065. begin
  1066. if (ppo_is_override in propoptions) then
  1067. begin
  1068. propoverridenderef.build(propoverriden);
  1069. end
  1070. else
  1071. begin
  1072. proptype.buildderef;
  1073. indextype.buildderef;
  1074. readaccess.buildderef;
  1075. writeaccess.buildderef;
  1076. storedaccess.buildderef;
  1077. end;
  1078. end;
  1079. procedure tpropertysym.deref;
  1080. begin
  1081. if (ppo_is_override in propoptions) then
  1082. begin
  1083. propoverriden:=tpropertysym(propoverridenderef.resolve);
  1084. dooverride(propoverriden);
  1085. end
  1086. else
  1087. begin
  1088. proptype.resolve;
  1089. indextype.resolve;
  1090. readaccess.resolve;
  1091. writeaccess.resolve;
  1092. storedaccess.resolve;
  1093. end;
  1094. end;
  1095. function tpropertysym.getsize : longint;
  1096. begin
  1097. getsize:=0;
  1098. end;
  1099. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1100. begin
  1101. inherited ppuwrite(ppufile);
  1102. ppufile.putsmallset(propoptions);
  1103. if (ppo_is_override in propoptions) then
  1104. ppufile.putderef(propoverridenderef)
  1105. else
  1106. begin
  1107. ppufile.puttype(proptype);
  1108. ppufile.putlongint(index);
  1109. ppufile.putlongint(default);
  1110. ppufile.puttype(indextype);
  1111. ppufile.putsymlist(readaccess);
  1112. ppufile.putsymlist(writeaccess);
  1113. ppufile.putsymlist(storedaccess);
  1114. end;
  1115. ppufile.writeentry(ibpropertysym);
  1116. end;
  1117. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1118. begin
  1119. propoverriden:=overriden;
  1120. proptype:=overriden.proptype;
  1121. propoptions:=overriden.propoptions+[ppo_is_override];
  1122. index:=overriden.index;
  1123. default:=overriden.default;
  1124. indextype:=overriden.indextype;
  1125. readaccess.free;
  1126. readaccess:=overriden.readaccess.getcopy;
  1127. writeaccess.free;
  1128. writeaccess:=overriden.writeaccess.getcopy;
  1129. storedaccess.free;
  1130. storedaccess:=overriden.storedaccess.getcopy;
  1131. end;
  1132. {****************************************************************************
  1133. TABSTRACTVARSYM
  1134. ****************************************************************************}
  1135. constructor tabstractvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1136. begin
  1137. inherited create(n);
  1138. vartype:=tt;
  1139. varspez:=vsp;
  1140. varstate:=vs_declared;
  1141. varoptions:=vopts;
  1142. end;
  1143. constructor tabstractvarsym.ppuload(ppufile:tcompilerppufile);
  1144. begin
  1145. inherited ppuload(ppufile);
  1146. varstate:=vs_used;
  1147. varspez:=tvarspez(ppufile.getbyte);
  1148. varregable:=tvarregable(ppufile.getbyte);
  1149. ppufile.gettype(_vartype);
  1150. ppufile.getsmallset(varoptions);
  1151. end;
  1152. destructor tabstractvarsym.destroy;
  1153. begin
  1154. if assigned(notifications) then
  1155. notifications.destroy;
  1156. inherited destroy;
  1157. end;
  1158. procedure tabstractvarsym.buildderef;
  1159. begin
  1160. vartype.buildderef;
  1161. end;
  1162. procedure tabstractvarsym.deref;
  1163. begin
  1164. vartype.resolve;
  1165. end;
  1166. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1167. var
  1168. oldintfcrc : boolean;
  1169. begin
  1170. inherited ppuwrite(ppufile);
  1171. ppufile.putbyte(byte(varspez));
  1172. oldintfcrc:=ppufile.do_crc;
  1173. ppufile.do_crc:=false;
  1174. ppufile.putbyte(byte(varregable));
  1175. ppufile.do_crc:=oldintfcrc;
  1176. ppufile.puttype(vartype);
  1177. ppufile.putsmallset(varoptions);
  1178. end;
  1179. function tabstractvarsym.getsize : longint;
  1180. begin
  1181. if assigned(vartype.def) and
  1182. ((vartype.def.deftype<>arraydef) or
  1183. tarraydef(vartype.def).isDynamicArray or
  1184. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1185. result:=vartype.def.size
  1186. else
  1187. result:=0;
  1188. end;
  1189. function tabstractvarsym.is_regvar:boolean;
  1190. begin
  1191. { Register variables are not allowed in the following cases:
  1192. - regvars are disabled
  1193. - exceptions are used (after an exception is raised the contents of the
  1194. registers is not valid anymore)
  1195. - it has a local copy
  1196. - the value needs to be in memory (i.e. reference counted) }
  1197. result:=(cs_regvars in aktglobalswitches) and
  1198. not(pi_has_assembler_block in current_procinfo.flags) and
  1199. not(pi_uses_exceptions in current_procinfo.flags) and
  1200. not(vo_has_local_copy in varoptions) and
  1201. (varregable<>vr_none);
  1202. end;
  1203. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1204. var n:Tnotification;
  1205. begin
  1206. if assigned(notifications) then
  1207. begin
  1208. n:=Tnotification(notifications.first);
  1209. while assigned(n) do
  1210. begin
  1211. if what in n.flags then
  1212. n.callback(what,self);
  1213. n:=Tnotification(n.next);
  1214. end;
  1215. end;
  1216. end;
  1217. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1218. Tnotification_callback):cardinal;
  1219. var n:Tnotification;
  1220. begin
  1221. if not assigned(notifications) then
  1222. notifications:=Tlinkedlist.create;
  1223. n:=Tnotification.create(flags,callback);
  1224. register_notification:=n.id;
  1225. notifications.concat(n);
  1226. end;
  1227. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1228. var n:Tnotification;
  1229. begin
  1230. if not assigned(notifications) then
  1231. internalerror(200212311)
  1232. else
  1233. begin
  1234. n:=Tnotification(notifications.first);
  1235. while assigned(n) do
  1236. begin
  1237. if n.id=id then
  1238. begin
  1239. notifications.remove(n);
  1240. n.destroy;
  1241. exit;
  1242. end;
  1243. n:=Tnotification(n.next);
  1244. end;
  1245. internalerror(200212311)
  1246. end;
  1247. end;
  1248. procedure tabstractvarsym.setvartype(const newtype: ttype);
  1249. begin
  1250. _vartype := newtype;
  1251. { can we load the value into a register ? }
  1252. if not assigned(owner) or
  1253. (owner.symtabletype in [localsymtable,parasymtable]) or
  1254. (
  1255. (owner.symtabletype=staticsymtable) and
  1256. not(cs_create_pic in aktmoduleswitches)
  1257. ) then
  1258. begin
  1259. if tstoreddef(vartype.def).is_intregable then
  1260. varregable:=vr_intreg
  1261. else
  1262. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1263. if {(
  1264. not assigned(owner) or
  1265. (owner.symtabletype<>staticsymtable)
  1266. ) and }
  1267. tstoreddef(vartype.def).is_fpuregable then
  1268. begin
  1269. {$ifdef x86}
  1270. if use_sse(vartype.def) then
  1271. varregable:=vr_mmreg
  1272. else
  1273. {$else x86}
  1274. varregable:=vr_fpureg;
  1275. {$endif x86}
  1276. end;
  1277. end;
  1278. end;
  1279. {****************************************************************************
  1280. TFIELDVARSYM
  1281. ****************************************************************************}
  1282. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1283. begin
  1284. inherited create(n,vsp,tt,vopts);
  1285. typ:=fieldvarsym;
  1286. fieldoffset:=0;
  1287. end;
  1288. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1289. begin
  1290. inherited ppuload(ppufile);
  1291. typ:=fieldvarsym;
  1292. fieldoffset:=ppufile.getaint;
  1293. end;
  1294. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1295. begin
  1296. inherited ppuwrite(ppufile);
  1297. ppufile.putaint(fieldoffset);
  1298. ppufile.writeentry(ibfieldvarsym);
  1299. end;
  1300. {$ifdef GDB}
  1301. function tfieldvarsym.stabstring:Pchar;
  1302. var
  1303. st : string;
  1304. begin
  1305. stabstring:=nil;
  1306. case owner.symtabletype of
  1307. objectsymtable :
  1308. begin
  1309. if (sp_static in symoptions) then
  1310. begin
  1311. st:=tstoreddef(vartype.def).numberstring;
  1312. if (cs_gdb_gsym in aktglobalswitches) then
  1313. st:='G'+st
  1314. else
  1315. st:='S'+st;
  1316. stabstring:=stabstr_evaluate('"${ownername}__${name}:$1",${N_LCSYM},0,${line},${mangledname}',[st]);
  1317. end;
  1318. end;
  1319. end;
  1320. end;
  1321. {$endif GDB}
  1322. {****************************************************************************
  1323. TABSTRACTNORMALVARSYM
  1324. ****************************************************************************}
  1325. constructor tabstractnormalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1326. begin
  1327. inherited create(n,vsp,tt,vopts);
  1328. fillchar(localloc,sizeof(localloc),0);
  1329. defaultconstsym:=nil;
  1330. end;
  1331. constructor tabstractnormalvarsym.ppuload(ppufile:tcompilerppufile);
  1332. begin
  1333. inherited ppuload(ppufile);
  1334. fillchar(localloc,sizeof(localloc),0);
  1335. ppufile.getderef(defaultconstsymderef);
  1336. end;
  1337. procedure tabstractnormalvarsym.buildderef;
  1338. begin
  1339. inherited buildderef;
  1340. defaultconstsymderef.build(defaultconstsym);
  1341. end;
  1342. procedure tabstractnormalvarsym.deref;
  1343. begin
  1344. inherited deref;
  1345. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1346. end;
  1347. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1348. begin
  1349. inherited ppuwrite(ppufile);
  1350. ppufile.putderef(defaultconstsymderef);
  1351. end;
  1352. {****************************************************************************
  1353. TGLOBALVARSYM
  1354. ****************************************************************************}
  1355. constructor tglobalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1356. begin
  1357. inherited create(n,vsp,tt,vopts);
  1358. typ:=globalvarsym;
  1359. _mangledname:=nil;
  1360. end;
  1361. constructor tglobalvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1362. begin
  1363. tglobalvarsym(self).create(n,vsp,tt,[vo_is_dll_var]);
  1364. end;
  1365. constructor tglobalvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1366. begin
  1367. tglobalvarsym(self).create(n,vsp,tt,[]);
  1368. set_mangledname(mangled);
  1369. end;
  1370. constructor tglobalvarsym.ppuload(ppufile:tcompilerppufile);
  1371. begin
  1372. inherited ppuload(ppufile);
  1373. typ:=globalvarsym;
  1374. if vo_has_mangledname in varoptions then
  1375. _mangledname:=stringdup(ppufile.getstring)
  1376. else
  1377. _mangledname:=nil;
  1378. end;
  1379. destructor tglobalvarsym.destroy;
  1380. begin
  1381. if assigned(_mangledname) then
  1382. begin
  1383. {$ifdef MEMDEBUG}
  1384. memmanglednames.start;
  1385. {$endif MEMDEBUG}
  1386. stringdispose(_mangledname);
  1387. {$ifdef MEMDEBUG}
  1388. memmanglednames.stop;
  1389. {$endif MEMDEBUG}
  1390. end;
  1391. inherited destroy;
  1392. end;
  1393. procedure tglobalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1394. begin
  1395. inherited ppuwrite(ppufile);
  1396. if vo_has_mangledname in varoptions then
  1397. ppufile.putstring(_mangledname^);
  1398. ppufile.writeentry(ibglobalvarsym);
  1399. end;
  1400. function tglobalvarsym.mangledname:string;
  1401. begin
  1402. if not assigned(_mangledname) then
  1403. begin
  1404. {$ifdef compress}
  1405. _mangledname:=stringdup(minilzw_encode(make_mangledname('U',owner,name)));
  1406. {$else}
  1407. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1408. {$endif}
  1409. end;
  1410. result:=_mangledname^;
  1411. end;
  1412. procedure tglobalvarsym.set_mangledname(const s:string);
  1413. begin
  1414. stringdispose(_mangledname);
  1415. {$ifdef compress}
  1416. _mangledname:=stringdup(minilzw_encode(s));
  1417. {$else}
  1418. _mangledname:=stringdup(s);
  1419. {$endif}
  1420. include(varoptions,vo_has_mangledname);
  1421. end;
  1422. {$ifdef GDB}
  1423. function Tglobalvarsym.stabstring:Pchar;
  1424. var st:string;
  1425. threadvaroffset:string;
  1426. regidx:Tregisterindex;
  1427. begin
  1428. result:=nil;
  1429. st:=tstoreddef(vartype.def).numberstring;
  1430. case localloc.loc of
  1431. LOC_REGISTER,
  1432. LOC_CREGISTER,
  1433. LOC_MMREGISTER,
  1434. LOC_CMMREGISTER,
  1435. LOC_FPUREGISTER,
  1436. LOC_CFPUREGISTER :
  1437. begin
  1438. regidx:=findreg_by_number(localloc.register);
  1439. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1440. { this is the register order for GDB}
  1441. if regidx<>0 then
  1442. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1443. end;
  1444. else
  1445. begin
  1446. if (vo_is_thread_var in varoptions) then
  1447. threadvaroffset:='+'+tostr(sizeof(aint))
  1448. else
  1449. threadvaroffset:='';
  1450. { Here we used S instead of
  1451. because with G GDB doesn't look at the address field
  1452. but searches the same name or with a leading underscore
  1453. but these names don't exist in pascal !}
  1454. if (cs_gdb_gsym in aktglobalswitches) then
  1455. st:='G'+st
  1456. else
  1457. st:='S'+st;
  1458. stabstring:=stabstr_evaluate('"${name}:$1",${N_LCSYM},0,${line},${mangledname}$2',[st,threadvaroffset]);
  1459. end;
  1460. end;
  1461. end;
  1462. {$endif GDB}
  1463. {****************************************************************************
  1464. TLOCALVARSYM
  1465. ****************************************************************************}
  1466. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1467. begin
  1468. inherited create(n,vsp,tt,vopts);
  1469. typ:=localvarsym;
  1470. end;
  1471. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1472. begin
  1473. inherited ppuload(ppufile);
  1474. typ:=localvarsym;
  1475. end;
  1476. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1477. begin
  1478. inherited ppuwrite(ppufile);
  1479. ppufile.writeentry(iblocalvarsym);
  1480. end;
  1481. {$ifdef GDB}
  1482. function tlocalvarsym.stabstring:Pchar;
  1483. var st:string;
  1484. regidx:Tregisterindex;
  1485. begin
  1486. stabstring:=nil;
  1487. { There is no space allocated for not referenced locals }
  1488. if (owner.symtabletype=localsymtable) and (refs=0) then
  1489. exit;
  1490. st:=tstoreddef(vartype.def).numberstring;
  1491. case localloc.loc of
  1492. LOC_REGISTER,
  1493. LOC_CREGISTER,
  1494. LOC_MMREGISTER,
  1495. LOC_CMMREGISTER,
  1496. LOC_FPUREGISTER,
  1497. LOC_CFPUREGISTER :
  1498. begin
  1499. regidx:=findreg_by_number(localloc.register);
  1500. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1501. { this is the register order for GDB}
  1502. if regidx<>0 then
  1503. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1504. end;
  1505. LOC_REFERENCE :
  1506. { offset to ebp => will not work if the framepointer is esp
  1507. so some optimizing will make things harder to debug }
  1508. stabstring:=stabstr_evaluate('"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(localloc.reference.offset)])
  1509. else
  1510. internalerror(2003091814);
  1511. end;
  1512. end;
  1513. {$endif GDB}
  1514. {****************************************************************************
  1515. TPARAVARSYM
  1516. ****************************************************************************}
  1517. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1518. begin
  1519. inherited create(n,vsp,tt,vopts);
  1520. typ:=paravarsym;
  1521. paranr:=nr;
  1522. paraloc[calleeside].init;
  1523. paraloc[callerside].init;
  1524. end;
  1525. destructor tparavarsym.destroy;
  1526. begin
  1527. paraloc[calleeside].done;
  1528. paraloc[callerside].done;
  1529. inherited destroy;
  1530. end;
  1531. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1532. var
  1533. b : byte;
  1534. begin
  1535. inherited ppuload(ppufile);
  1536. paranr:=ppufile.getword;
  1537. paraloc[calleeside].init;
  1538. paraloc[callerside].init;
  1539. if vo_has_explicit_paraloc in varoptions then
  1540. begin
  1541. b:=ppufile.getbyte;
  1542. if b<>sizeof(paraloc[callerside].location^) then
  1543. internalerror(200411154);
  1544. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1545. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1546. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1547. end;
  1548. typ:=paravarsym;
  1549. end;
  1550. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1551. begin
  1552. inherited ppuwrite(ppufile);
  1553. ppufile.putword(paranr);
  1554. if vo_has_explicit_paraloc in varoptions then
  1555. begin
  1556. paraloc[callerside].check_simple_location;
  1557. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1558. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1559. end;
  1560. ppufile.writeentry(ibparavarsym);
  1561. end;
  1562. {$ifdef GDB}
  1563. function tparavarsym.stabstring:Pchar;
  1564. var st:string;
  1565. regidx:Tregisterindex;
  1566. c:char;
  1567. begin
  1568. result:=nil;
  1569. { set loc to LOC_REFERENCE to get somewhat usable debugging info for -Or }
  1570. { while stabs aren't adapted for regvars yet }
  1571. if (vo_is_self in varoptions) then
  1572. begin
  1573. case localloc.loc of
  1574. LOC_REGISTER,
  1575. LOC_CREGISTER:
  1576. regidx:=findreg_by_number(localloc.register);
  1577. LOC_REFERENCE: ;
  1578. else
  1579. internalerror(2003091815);
  1580. end;
  1581. if (po_classmethod in current_procinfo.procdef.procoptions) or
  1582. (po_staticmethod in current_procinfo.procdef.procoptions) then
  1583. begin
  1584. if (localloc.loc=LOC_REFERENCE) then
  1585. stabstring:=stabstr_evaluate('"pvmt:p$1",${N_TSYM},0,0,$2',
  1586. [Tstoreddef(pvmttype.def).numberstring,tostr(localloc.reference.offset)]);
  1587. (* else
  1588. stabstring:=stabstr_evaluate('"pvmt:r$1",${N_RSYM},0,0,$2',
  1589. [Tstoreddef(pvmttype.def).numberstring,tostr(regstabs_table[regidx])]) *)
  1590. end
  1591. else
  1592. begin
  1593. if not(is_class(current_procinfo.procdef._class)) then
  1594. c:='v'
  1595. else
  1596. c:='p';
  1597. if (localloc.loc=LOC_REFERENCE) then
  1598. stabstring:=stabstr_evaluate('"$$t:$1",${N_TSYM},0,0,$2',
  1599. [c+current_procinfo.procdef._class.numberstring,tostr(localloc.reference.offset)]);
  1600. (* else
  1601. stabstring:=stabstr_evaluate('"$$t:r$1",${N_RSYM},0,0,$2',
  1602. [c+current_procinfo.procdef._class.numberstring,tostr(regstabs_table[regidx])]); *)
  1603. end;
  1604. end
  1605. else
  1606. begin
  1607. st:=tstoreddef(vartype.def).numberstring;
  1608. if paramanager.push_addr_param(varspez,vartype.def,tprocdef(owner.defowner).proccalloption) and
  1609. not(vo_has_local_copy in varoptions) and
  1610. not is_open_string(vartype.def) then
  1611. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1612. else
  1613. st := 'p'+st;
  1614. case localloc.loc of
  1615. LOC_REGISTER,
  1616. LOC_CREGISTER,
  1617. LOC_MMREGISTER,
  1618. LOC_CMMREGISTER,
  1619. LOC_FPUREGISTER,
  1620. LOC_CFPUREGISTER :
  1621. begin
  1622. regidx:=findreg_by_number(localloc.register);
  1623. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1624. { this is the register order for GDB}
  1625. if regidx<>0 then
  1626. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(longint(regstabs_table[regidx]))]);
  1627. end;
  1628. LOC_REFERENCE :
  1629. { offset to ebp => will not work if the framepointer is esp
  1630. so some optimizing will make things harder to debug }
  1631. stabstring:=stabstr_evaluate('"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(localloc.reference.offset)])
  1632. else
  1633. internalerror(2003091814);
  1634. end;
  1635. end;
  1636. end;
  1637. {$endif GDB}
  1638. {****************************************************************************
  1639. TABSOLUTEVARSYM
  1640. ****************************************************************************}
  1641. constructor tabsolutevarsym.create(const n : string;const tt : ttype);
  1642. begin
  1643. inherited create(n,vs_value,tt,[]);
  1644. typ:=absolutevarsym;
  1645. ref:=nil;
  1646. end;
  1647. constructor tabsolutevarsym.create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  1648. begin
  1649. inherited create(n,vs_value,tt,[]);
  1650. typ:=absolutevarsym;
  1651. ref:=_ref;
  1652. end;
  1653. destructor tabsolutevarsym.destroy;
  1654. begin
  1655. if assigned(ref) then
  1656. ref.free;
  1657. inherited destroy;
  1658. end;
  1659. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1660. begin
  1661. inherited ppuload(ppufile);
  1662. typ:=absolutevarsym;
  1663. ref:=nil;
  1664. asmname:=nil;
  1665. abstyp:=absolutetyp(ppufile.getbyte);
  1666. {$ifdef i386}
  1667. absseg:=false;
  1668. {$endif i386}
  1669. case abstyp of
  1670. tovar :
  1671. ref:=ppufile.getsymlist;
  1672. toasm :
  1673. asmname:=stringdup(ppufile.getstring);
  1674. toaddr :
  1675. begin
  1676. addroffset:=ppufile.getaint;
  1677. {$ifdef i386}
  1678. absseg:=boolean(ppufile.getbyte);
  1679. {$endif i386}
  1680. end;
  1681. end;
  1682. end;
  1683. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1684. begin
  1685. inherited ppuwrite(ppufile);
  1686. ppufile.putbyte(byte(abstyp));
  1687. case abstyp of
  1688. tovar :
  1689. ppufile.putsymlist(ref);
  1690. toasm :
  1691. ppufile.putstring(asmname^);
  1692. toaddr :
  1693. begin
  1694. ppufile.putaint(addroffset);
  1695. {$ifdef i386}
  1696. ppufile.putbyte(byte(absseg));
  1697. {$endif i386}
  1698. end;
  1699. end;
  1700. ppufile.writeentry(ibabsolutevarsym);
  1701. end;
  1702. procedure tabsolutevarsym.buildderef;
  1703. begin
  1704. inherited buildderef;
  1705. if (abstyp=tovar) then
  1706. ref.buildderef;
  1707. end;
  1708. procedure tabsolutevarsym.deref;
  1709. begin
  1710. inherited deref;
  1711. { own absolute deref }
  1712. if (abstyp=tovar) then
  1713. ref.resolve;
  1714. end;
  1715. function tabsolutevarsym.mangledname : string;
  1716. begin
  1717. case abstyp of
  1718. toasm :
  1719. mangledname:=asmname^;
  1720. toaddr :
  1721. mangledname:='$'+tostr(addroffset);
  1722. else
  1723. internalerror(200411061);
  1724. end;
  1725. end;
  1726. {$ifdef GDB}
  1727. function tabsolutevarsym.stabstring:Pchar;
  1728. begin
  1729. stabstring:=nil;
  1730. end;
  1731. {$endif GDB}
  1732. {****************************************************************************
  1733. TTYPEDCONSTSYM
  1734. *****************************************************************************}
  1735. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1736. begin
  1737. inherited create(n);
  1738. typ:=typedconstsym;
  1739. typedconsttype.setdef(p);
  1740. is_writable:=writable;
  1741. end;
  1742. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1743. begin
  1744. inherited create(n);
  1745. typ:=typedconstsym;
  1746. typedconsttype:=tt;
  1747. is_writable:=writable;
  1748. end;
  1749. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1750. begin
  1751. inherited ppuload(ppufile);
  1752. typ:=typedconstsym;
  1753. ppufile.gettype(typedconsttype);
  1754. is_writable:=boolean(ppufile.getbyte);
  1755. end;
  1756. destructor ttypedconstsym.destroy;
  1757. begin
  1758. if assigned(_mangledname) then
  1759. begin
  1760. {$ifdef MEMDEBUG}
  1761. memmanglednames.start;
  1762. {$endif MEMDEBUG}
  1763. stringdispose(_mangledname);
  1764. {$ifdef MEMDEBUG}
  1765. memmanglednames.stop;
  1766. {$endif MEMDEBUG}
  1767. end;
  1768. inherited destroy;
  1769. end;
  1770. function ttypedconstsym.mangledname:string;
  1771. begin
  1772. if not assigned(_mangledname) then
  1773. begin
  1774. {$ifdef compress}
  1775. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1776. {$else}
  1777. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1778. {$endif}
  1779. end;
  1780. result:=_mangledname^;
  1781. end;
  1782. function ttypedconstsym.getsize : longint;
  1783. begin
  1784. if assigned(typedconsttype.def) then
  1785. getsize:=typedconsttype.def.size
  1786. else
  1787. getsize:=0;
  1788. end;
  1789. procedure ttypedconstsym.buildderef;
  1790. begin
  1791. typedconsttype.buildderef;
  1792. end;
  1793. procedure ttypedconstsym.deref;
  1794. begin
  1795. typedconsttype.resolve;
  1796. end;
  1797. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1798. begin
  1799. inherited ppuwrite(ppufile);
  1800. ppufile.puttype(typedconsttype);
  1801. ppufile.putbyte(byte(is_writable));
  1802. ppufile.writeentry(ibtypedconstsym);
  1803. end;
  1804. {$ifdef GDB}
  1805. function ttypedconstsym.stabstring : pchar;
  1806. var st:char;
  1807. begin
  1808. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1809. st:='G'
  1810. else
  1811. st:='S';
  1812. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_STSYM},0,${line},${mangledname}',
  1813. [st,Tstoreddef(typedconsttype.def).numberstring]);
  1814. end;
  1815. {$endif GDB}
  1816. {****************************************************************************
  1817. TCONSTSYM
  1818. ****************************************************************************}
  1819. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1820. begin
  1821. inherited create(n);
  1822. fillchar(value, sizeof(value), #0);
  1823. typ:=constsym;
  1824. consttyp:=t;
  1825. value.valueord:=v;
  1826. ResStrIndex:=0;
  1827. consttype:=tt;
  1828. end;
  1829. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1830. begin
  1831. inherited create(n);
  1832. fillchar(value, sizeof(value), #0);
  1833. typ:=constsym;
  1834. consttyp:=t;
  1835. value.valueordptr:=v;
  1836. ResStrIndex:=0;
  1837. consttype:=tt;
  1838. end;
  1839. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1840. begin
  1841. inherited create(n);
  1842. fillchar(value, sizeof(value), #0);
  1843. typ:=constsym;
  1844. consttyp:=t;
  1845. value.valueptr:=v;
  1846. ResStrIndex:=0;
  1847. consttype:=tt;
  1848. end;
  1849. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1850. begin
  1851. inherited create(n);
  1852. fillchar(value, sizeof(value), #0);
  1853. typ:=constsym;
  1854. consttyp:=t;
  1855. value.valueptr:=str;
  1856. consttype.reset;
  1857. value.len:=l;
  1858. if t=constresourcestring then
  1859. ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
  1860. end;
  1861. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1862. var
  1863. pd : pbestreal;
  1864. ps : pnormalset;
  1865. pc : pchar;
  1866. begin
  1867. inherited ppuload(ppufile);
  1868. typ:=constsym;
  1869. consttype.reset;
  1870. consttyp:=tconsttyp(ppufile.getbyte);
  1871. fillchar(value, sizeof(value), #0);
  1872. case consttyp of
  1873. constord :
  1874. begin
  1875. ppufile.gettype(consttype);
  1876. value.valueord:=ppufile.getexprint;
  1877. end;
  1878. constpointer :
  1879. begin
  1880. ppufile.gettype(consttype);
  1881. value.valueordptr:=ppufile.getptruint;
  1882. end;
  1883. conststring,
  1884. constresourcestring :
  1885. begin
  1886. value.len:=ppufile.getlongint;
  1887. getmem(pc,value.len+1);
  1888. ppufile.getdata(pc^,value.len);
  1889. if consttyp=constresourcestring then
  1890. ResStrIndex:=ppufile.getlongint;
  1891. value.valueptr:=pc;
  1892. end;
  1893. constreal :
  1894. begin
  1895. new(pd);
  1896. pd^:=ppufile.getreal;
  1897. value.valueptr:=pd;
  1898. end;
  1899. constset :
  1900. begin
  1901. ppufile.gettype(consttype);
  1902. new(ps);
  1903. ppufile.getnormalset(ps^);
  1904. value.valueptr:=ps;
  1905. end;
  1906. constguid :
  1907. begin
  1908. new(pguid(value.valueptr));
  1909. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1910. end;
  1911. constnil : ;
  1912. else
  1913. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1914. end;
  1915. end;
  1916. destructor tconstsym.destroy;
  1917. begin
  1918. case consttyp of
  1919. conststring,
  1920. constresourcestring :
  1921. freemem(pchar(value.valueptr),value.len+1);
  1922. constreal :
  1923. dispose(pbestreal(value.valueptr));
  1924. constset :
  1925. dispose(pnormalset(value.valueptr));
  1926. constguid :
  1927. dispose(pguid(value.valueptr));
  1928. end;
  1929. inherited destroy;
  1930. end;
  1931. procedure tconstsym.buildderef;
  1932. begin
  1933. if consttyp in [constord,constpointer,constset] then
  1934. consttype.buildderef;
  1935. end;
  1936. procedure tconstsym.deref;
  1937. begin
  1938. if consttyp in [constord,constpointer,constset] then
  1939. consttype.resolve;
  1940. end;
  1941. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1942. begin
  1943. inherited ppuwrite(ppufile);
  1944. ppufile.putbyte(byte(consttyp));
  1945. case consttyp of
  1946. constnil : ;
  1947. constord :
  1948. begin
  1949. ppufile.puttype(consttype);
  1950. ppufile.putexprint(value.valueord);
  1951. end;
  1952. constpointer :
  1953. begin
  1954. ppufile.puttype(consttype);
  1955. ppufile.putptruint(value.valueordptr);
  1956. end;
  1957. conststring,
  1958. constresourcestring :
  1959. begin
  1960. ppufile.putlongint(value.len);
  1961. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1962. if consttyp=constresourcestring then
  1963. ppufile.putlongint(ResStrIndex);
  1964. end;
  1965. constreal :
  1966. ppufile.putreal(pbestreal(value.valueptr)^);
  1967. constset :
  1968. begin
  1969. ppufile.puttype(consttype);
  1970. ppufile.putnormalset(value.valueptr^);
  1971. end;
  1972. constguid :
  1973. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1974. else
  1975. internalerror(13);
  1976. end;
  1977. ppufile.writeentry(ibconstsym);
  1978. end;
  1979. {$ifdef GDB}
  1980. function Tconstsym.stabstring:Pchar;
  1981. var st : string;
  1982. begin
  1983. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1984. case consttyp of
  1985. conststring:
  1986. st:='s'''+backspace_quote(octal_quote(strpas(pchar(value.valueptr)),[#0..#9,#11,#12,#14..#31,'''']),['"','\',#10,#13])+'''';
  1987. constord:
  1988. st:='i'+tostr(value.valueord);
  1989. constpointer:
  1990. st:='i'+tostr(value.valueordptr);
  1991. constreal:
  1992. begin
  1993. system.str(pbestreal(value.valueptr)^,st);
  1994. st := 'r'+st;
  1995. end;
  1996. { if we don't know just put zero !! }
  1997. else st:='i0';
  1998. {***SETCONST}
  1999. {constset:;} {*** I don't know what to do with a set.}
  2000. { sets are not recognized by GDB}
  2001. {***}
  2002. end;
  2003. { valgrind does not support constants }
  2004. if cs_gdb_valgrind in aktglobalswitches then
  2005. stabstring:=nil
  2006. else
  2007. stabstring:=stabstr_evaluate('"${name}:c=$1;",${N_FUNCTION},0,${line},0',[st]);
  2008. end;
  2009. {$endif GDB}
  2010. {****************************************************************************
  2011. TENUMSYM
  2012. ****************************************************************************}
  2013. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2014. begin
  2015. inherited create(n);
  2016. typ:=enumsym;
  2017. definition:=def;
  2018. value:=v;
  2019. { First entry? Then we need to set the minval }
  2020. if def.firstenum=nil then
  2021. begin
  2022. if v>0 then
  2023. def.has_jumps:=true;
  2024. def.setmin(v);
  2025. def.setmax(v);
  2026. end
  2027. else
  2028. begin
  2029. { check for jumps }
  2030. if v>def.max+1 then
  2031. def.has_jumps:=true;
  2032. { update low and high }
  2033. if def.min>v then
  2034. def.setmin(v);
  2035. if def.max<v then
  2036. def.setmax(v);
  2037. end;
  2038. order;
  2039. end;
  2040. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2041. begin
  2042. inherited ppuload(ppufile);
  2043. typ:=enumsym;
  2044. ppufile.getderef(definitionderef);
  2045. value:=ppufile.getlongint;
  2046. nextenum := Nil;
  2047. end;
  2048. procedure tenumsym.buildderef;
  2049. begin
  2050. definitionderef.build(definition);
  2051. end;
  2052. procedure tenumsym.deref;
  2053. begin
  2054. definition:=tenumdef(definitionderef.resolve);
  2055. order;
  2056. end;
  2057. procedure tenumsym.order;
  2058. var
  2059. sym : tenumsym;
  2060. begin
  2061. sym := tenumsym(definition.firstenum);
  2062. if sym = nil then
  2063. begin
  2064. definition.firstenum := self;
  2065. nextenum := nil;
  2066. exit;
  2067. end;
  2068. { reorder the symbols in increasing value }
  2069. if value < sym.value then
  2070. begin
  2071. nextenum := sym;
  2072. definition.firstenum := self;
  2073. end
  2074. else
  2075. begin
  2076. while (sym.value <= value) and assigned(sym.nextenum) do
  2077. sym := sym.nextenum;
  2078. nextenum := sym.nextenum;
  2079. sym.nextenum := self;
  2080. end;
  2081. end;
  2082. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2083. begin
  2084. inherited ppuwrite(ppufile);
  2085. ppufile.putderef(definitionderef);
  2086. ppufile.putlongint(value);
  2087. ppufile.writeentry(ibenumsym);
  2088. end;
  2089. {****************************************************************************
  2090. TTYPESYM
  2091. ****************************************************************************}
  2092. constructor ttypesym.create(const n : string;const tt : ttype);
  2093. begin
  2094. inherited create(n);
  2095. typ:=typesym;
  2096. restype:=tt;
  2097. { register the typesym for the definition }
  2098. if assigned(restype.def) and
  2099. (restype.def.deftype<>errordef) and
  2100. not(assigned(restype.def.typesym)) then
  2101. restype.def.typesym:=self;
  2102. end;
  2103. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2104. begin
  2105. inherited ppuload(ppufile);
  2106. typ:=typesym;
  2107. ppufile.gettype(restype);
  2108. end;
  2109. function ttypesym.gettypedef:tdef;
  2110. begin
  2111. gettypedef:=restype.def;
  2112. end;
  2113. procedure ttypesym.buildderef;
  2114. begin
  2115. restype.buildderef;
  2116. end;
  2117. procedure ttypesym.deref;
  2118. begin
  2119. restype.resolve;
  2120. end;
  2121. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2122. begin
  2123. inherited ppuwrite(ppufile);
  2124. ppufile.puttype(restype);
  2125. ppufile.writeentry(ibtypesym);
  2126. end;
  2127. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  2128. begin
  2129. inherited load_references(ppufile,locals);
  2130. if (restype.def.deftype=recorddef) then
  2131. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  2132. if (restype.def.deftype=objectdef) then
  2133. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  2134. end;
  2135. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  2136. var
  2137. d : tderef;
  2138. begin
  2139. d.reset;
  2140. if not inherited write_references(ppufile,locals) then
  2141. begin
  2142. { write address of this symbol if record or object
  2143. even if no real refs are there
  2144. because we need it for the symtable }
  2145. if (restype.def.deftype in [recorddef,objectdef]) then
  2146. begin
  2147. d.build(self);
  2148. ppufile.putderef(d);
  2149. ppufile.writeentry(ibsymref);
  2150. end;
  2151. end;
  2152. write_references:=true;
  2153. if (restype.def.deftype=recorddef) then
  2154. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  2155. if (restype.def.deftype=objectdef) then
  2156. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  2157. end;
  2158. {$ifdef GDB}
  2159. function ttypesym.stabstring : pchar;
  2160. var stabchar:string[2];
  2161. begin
  2162. stabstring:=nil;
  2163. if restype.def<>nil then
  2164. begin
  2165. if restype.def.deftype in tagtypes then
  2166. stabchar:='Tt'
  2167. else
  2168. stabchar:='t';
  2169. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,tstoreddef(restype.def).numberstring]);
  2170. end;
  2171. end;
  2172. {$endif GDB}
  2173. {****************************************************************************
  2174. TSYSSYM
  2175. ****************************************************************************}
  2176. constructor tsyssym.create(const n : string;l : longint);
  2177. begin
  2178. inherited create(n);
  2179. typ:=syssym;
  2180. number:=l;
  2181. end;
  2182. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2183. begin
  2184. inherited ppuload(ppufile);
  2185. typ:=syssym;
  2186. number:=ppufile.getlongint;
  2187. end;
  2188. destructor tsyssym.destroy;
  2189. begin
  2190. inherited destroy;
  2191. end;
  2192. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2193. begin
  2194. inherited ppuwrite(ppufile);
  2195. ppufile.putlongint(number);
  2196. ppufile.writeentry(ibsyssym);
  2197. end;
  2198. {*****************************************************************************
  2199. TMacro
  2200. *****************************************************************************}
  2201. constructor tmacro.create(const n : string);
  2202. begin
  2203. inherited create(n);
  2204. typ:= macrosym;
  2205. owner:= nil;
  2206. defined:=false;
  2207. is_used:=false;
  2208. is_compiler_var:= false;
  2209. buftext:=nil;
  2210. buflen:=0;
  2211. end;
  2212. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2213. begin
  2214. inherited ppuload(ppufile);
  2215. typ:=macrosym;
  2216. name:=ppufile.getstring;
  2217. defined:=boolean(ppufile.getbyte);
  2218. is_compiler_var:=boolean(ppufile.getbyte);
  2219. is_used:=false;
  2220. buflen:= ppufile.getlongint;
  2221. if buflen > 0 then
  2222. begin
  2223. getmem(buftext, buflen);
  2224. ppufile.getdata(buftext^, buflen)
  2225. end
  2226. else
  2227. buftext:=nil;
  2228. end;
  2229. destructor tmacro.destroy;
  2230. begin
  2231. if assigned(buftext) then
  2232. freemem(buftext,buflen);
  2233. inherited destroy;
  2234. end;
  2235. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2236. begin
  2237. inherited ppuwrite(ppufile);
  2238. ppufile.putstring(name);
  2239. ppufile.putbyte(byte(defined));
  2240. ppufile.putbyte(byte(is_compiler_var));
  2241. ppufile.putlongint(buflen);
  2242. if buflen > 0 then
  2243. ppufile.putdata(buftext^,buflen);
  2244. ppufile.writeentry(ibmacrosym);
  2245. end;
  2246. {****************************************************************************
  2247. TRTTISYM
  2248. ****************************************************************************}
  2249. constructor trttisym.create(const n:string;rt:trttitype);
  2250. const
  2251. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2252. begin
  2253. inherited create(prefix[rt]+n);
  2254. include(symoptions,sp_internal);
  2255. typ:=rttisym;
  2256. lab:=nil;
  2257. rttityp:=rt;
  2258. end;
  2259. destructor trttisym.destroy;
  2260. begin
  2261. if assigned(_mangledname) then
  2262. begin
  2263. {$ifdef MEMDEBUG}
  2264. memmanglednames.start;
  2265. {$endif MEMDEBUG}
  2266. stringdispose(_mangledname);
  2267. {$ifdef MEMDEBUG}
  2268. memmanglednames.stop;
  2269. {$endif MEMDEBUG}
  2270. end;
  2271. inherited destroy;
  2272. end;
  2273. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2274. begin
  2275. inherited ppuload(ppufile);
  2276. typ:=rttisym;
  2277. lab:=nil;
  2278. rttityp:=trttitype(ppufile.getbyte);
  2279. end;
  2280. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2281. begin
  2282. inherited ppuwrite(ppufile);
  2283. ppufile.putbyte(byte(rttityp));
  2284. ppufile.writeentry(ibrttisym);
  2285. end;
  2286. function trttisym.mangledname : string;
  2287. const
  2288. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2289. begin
  2290. if not assigned(_mangledname) then
  2291. _mangledname:=stringdup(make_mangledname(prefix[rttityp],owner,Copy(name,5,255)));
  2292. result:=_mangledname^;
  2293. end;
  2294. function trttisym.get_label:tasmsymbol;
  2295. begin
  2296. { the label is always a global label }
  2297. if not assigned(lab) then
  2298. lab:=objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA);
  2299. get_label:=lab;
  2300. end;
  2301. end.