symsym.pas 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666
  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;var besteq:tequaltype):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;var besteq:tequaltype):Tprocdef;
  884. var
  885. convtyp : tconverttype;
  886. pd : pprocdeflist;
  887. bestpd : tprocdef;
  888. eq : tequaltype;
  889. hpd : tprocdef;
  890. i : byte;
  891. begin
  892. result:=nil;
  893. bestpd:=nil;
  894. besteq:=te_incompatible;
  895. pd:=pdlistfirst;
  896. while assigned(pd) do
  897. begin
  898. if equal_defs(todef,pd^.def.rettype.def) and
  899. { the result type must be always really equal and not an alias,
  900. if you mess with this code, check tw4093 }
  901. ((todef=pd^.def.rettype.def) or
  902. (
  903. not(df_unique in todef.defoptions) and
  904. not(df_unique in pd^.def.rettype.def.defoptions)
  905. )
  906. ) then
  907. begin
  908. i:=0;
  909. { ignore vs_hidden parameters }
  910. while assigned(pd^.def.paras[i]) and
  911. (vo_is_hidden_para in tparavarsym(pd^.def.paras[i]).varoptions) do
  912. inc(i);
  913. if assigned(pd^.def.paras[i]) then
  914. begin
  915. eq:=compare_defs_ext(fromdef,tparavarsym(pd^.def.paras[i]).vartype.def,nothingn,convtyp,hpd,[]);
  916. { alias? if yes, only l1 choice,
  917. if you mess with this code, check tw4093 }
  918. if (eq=te_exact) and
  919. (fromdef<>tparavarsym(pd^.def.paras[i]).vartype.def) and
  920. ((df_unique in fromdef.defoptions) or
  921. (df_unique in tparavarsym(pd^.def.paras[i]).vartype.def.defoptions)) then
  922. eq:=te_convert_l1;
  923. if eq=te_exact then
  924. begin
  925. besteq:=eq;
  926. result:=pd^.def;
  927. exit;
  928. end;
  929. if eq>besteq then
  930. begin
  931. bestpd:=pd^.def;
  932. besteq:=eq;
  933. end;
  934. end;
  935. end;
  936. pd:=pd^.next;
  937. end;
  938. result:=bestpd;
  939. end;
  940. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  941. var
  942. p : pprocdeflist;
  943. begin
  944. write_references:=false;
  945. if not inherited write_references(ppufile,locals) then
  946. exit;
  947. write_references:=true;
  948. p:=pdlistfirst;
  949. while assigned(p) do
  950. begin
  951. if p^.own then
  952. p^.def.write_references(ppufile,locals);
  953. p:=p^.next;
  954. end;
  955. end;
  956. procedure tprocsym.unchain_overload;
  957. var
  958. p,hp : pprocdeflist;
  959. begin
  960. { remove all overloaded procdefs from the
  961. procdeflist that are not in the current symtable }
  962. overloadchecked:=false;
  963. p:=pdlistfirst;
  964. { reset new lists }
  965. pdlistfirst:=nil;
  966. pdlistlast:=nil;
  967. while assigned(p) do
  968. begin
  969. hp:=p^.next;
  970. if p^.own then
  971. begin
  972. { keep, add to list }
  973. if assigned(pdlistlast) then
  974. begin
  975. pdlistlast^.next:=p;
  976. pdlistlast:=p;
  977. end
  978. else
  979. begin
  980. pdlistfirst:=p;
  981. pdlistlast:=p;
  982. end;
  983. p^.next:=nil;
  984. end
  985. else
  986. begin
  987. { remove }
  988. dispose(p);
  989. dec(procdef_count);
  990. end;
  991. p:=hp;
  992. end;
  993. end;
  994. function tprocsym.is_visible_for_object(currobjdef:tdef):boolean;
  995. var
  996. p : pprocdeflist;
  997. begin
  998. { This procsym is visible, when there is at least
  999. one of the procdefs visible }
  1000. result:=false;
  1001. p:=pdlistfirst;
  1002. while assigned(p) do
  1003. begin
  1004. if p^.own and
  1005. p^.def.is_visible_for_object(tobjectdef(currobjdef)) then
  1006. begin
  1007. result:=true;
  1008. exit;
  1009. end;
  1010. p:=p^.next;
  1011. end;
  1012. end;
  1013. {$ifdef GDB}
  1014. function tprocsym.stabstring : pchar;
  1015. begin
  1016. internalerror(200111171);
  1017. result:=nil;
  1018. end;
  1019. {$endif GDB}
  1020. {****************************************************************************
  1021. TERRORSYM
  1022. ****************************************************************************}
  1023. constructor terrorsym.create;
  1024. begin
  1025. inherited create('');
  1026. typ:=errorsym;
  1027. end;
  1028. {****************************************************************************
  1029. TPROPERTYSYM
  1030. ****************************************************************************}
  1031. constructor tpropertysym.create(const n : string);
  1032. begin
  1033. inherited create(n);
  1034. typ:=propertysym;
  1035. propoptions:=[];
  1036. index:=0;
  1037. default:=0;
  1038. proptype.reset;
  1039. indextype.reset;
  1040. readaccess:=tsymlist.create;
  1041. writeaccess:=tsymlist.create;
  1042. storedaccess:=tsymlist.create;
  1043. end;
  1044. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1045. begin
  1046. inherited ppuload(ppufile);
  1047. typ:=propertysym;
  1048. ppufile.getsmallset(propoptions);
  1049. if (ppo_is_override in propoptions) then
  1050. begin
  1051. ppufile.getderef(propoverridenderef);
  1052. { we need to have these objects initialized }
  1053. readaccess:=tsymlist.create;
  1054. writeaccess:=tsymlist.create;
  1055. storedaccess:=tsymlist.create;
  1056. end
  1057. else
  1058. begin
  1059. ppufile.gettype(proptype);
  1060. index:=ppufile.getlongint;
  1061. default:=ppufile.getlongint;
  1062. ppufile.gettype(indextype);
  1063. readaccess:=ppufile.getsymlist;
  1064. writeaccess:=ppufile.getsymlist;
  1065. storedaccess:=ppufile.getsymlist;
  1066. end;
  1067. end;
  1068. destructor tpropertysym.destroy;
  1069. begin
  1070. readaccess.free;
  1071. writeaccess.free;
  1072. storedaccess.free;
  1073. inherited destroy;
  1074. end;
  1075. function tpropertysym.gettypedef:tdef;
  1076. begin
  1077. gettypedef:=proptype.def;
  1078. end;
  1079. procedure tpropertysym.buildderef;
  1080. begin
  1081. if (ppo_is_override in propoptions) then
  1082. begin
  1083. propoverridenderef.build(propoverriden);
  1084. end
  1085. else
  1086. begin
  1087. proptype.buildderef;
  1088. indextype.buildderef;
  1089. readaccess.buildderef;
  1090. writeaccess.buildderef;
  1091. storedaccess.buildderef;
  1092. end;
  1093. end;
  1094. procedure tpropertysym.deref;
  1095. begin
  1096. if (ppo_is_override in propoptions) then
  1097. begin
  1098. propoverriden:=tpropertysym(propoverridenderef.resolve);
  1099. dooverride(propoverriden);
  1100. end
  1101. else
  1102. begin
  1103. proptype.resolve;
  1104. indextype.resolve;
  1105. readaccess.resolve;
  1106. writeaccess.resolve;
  1107. storedaccess.resolve;
  1108. end;
  1109. end;
  1110. function tpropertysym.getsize : longint;
  1111. begin
  1112. getsize:=0;
  1113. end;
  1114. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1115. begin
  1116. inherited ppuwrite(ppufile);
  1117. ppufile.putsmallset(propoptions);
  1118. if (ppo_is_override in propoptions) then
  1119. ppufile.putderef(propoverridenderef)
  1120. else
  1121. begin
  1122. ppufile.puttype(proptype);
  1123. ppufile.putlongint(index);
  1124. ppufile.putlongint(default);
  1125. ppufile.puttype(indextype);
  1126. ppufile.putsymlist(readaccess);
  1127. ppufile.putsymlist(writeaccess);
  1128. ppufile.putsymlist(storedaccess);
  1129. end;
  1130. ppufile.writeentry(ibpropertysym);
  1131. end;
  1132. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1133. begin
  1134. propoverriden:=overriden;
  1135. proptype:=overriden.proptype;
  1136. propoptions:=overriden.propoptions+[ppo_is_override];
  1137. index:=overriden.index;
  1138. default:=overriden.default;
  1139. indextype:=overriden.indextype;
  1140. readaccess.free;
  1141. readaccess:=overriden.readaccess.getcopy;
  1142. writeaccess.free;
  1143. writeaccess:=overriden.writeaccess.getcopy;
  1144. storedaccess.free;
  1145. storedaccess:=overriden.storedaccess.getcopy;
  1146. end;
  1147. {****************************************************************************
  1148. TABSTRACTVARSYM
  1149. ****************************************************************************}
  1150. constructor tabstractvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1151. begin
  1152. inherited create(n);
  1153. vartype:=tt;
  1154. varspez:=vsp;
  1155. varstate:=vs_declared;
  1156. varoptions:=vopts;
  1157. end;
  1158. constructor tabstractvarsym.ppuload(ppufile:tcompilerppufile);
  1159. begin
  1160. inherited ppuload(ppufile);
  1161. varstate:=vs_used;
  1162. varspez:=tvarspez(ppufile.getbyte);
  1163. varregable:=tvarregable(ppufile.getbyte);
  1164. ppufile.gettype(_vartype);
  1165. ppufile.getsmallset(varoptions);
  1166. end;
  1167. destructor tabstractvarsym.destroy;
  1168. begin
  1169. if assigned(notifications) then
  1170. notifications.destroy;
  1171. inherited destroy;
  1172. end;
  1173. procedure tabstractvarsym.buildderef;
  1174. begin
  1175. vartype.buildderef;
  1176. end;
  1177. procedure tabstractvarsym.deref;
  1178. begin
  1179. vartype.resolve;
  1180. end;
  1181. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1182. var
  1183. oldintfcrc : boolean;
  1184. begin
  1185. inherited ppuwrite(ppufile);
  1186. ppufile.putbyte(byte(varspez));
  1187. oldintfcrc:=ppufile.do_crc;
  1188. ppufile.do_crc:=false;
  1189. ppufile.putbyte(byte(varregable));
  1190. ppufile.do_crc:=oldintfcrc;
  1191. ppufile.puttype(vartype);
  1192. ppufile.putsmallset(varoptions);
  1193. end;
  1194. function tabstractvarsym.getsize : longint;
  1195. begin
  1196. if assigned(vartype.def) and
  1197. ((vartype.def.deftype<>arraydef) or
  1198. tarraydef(vartype.def).isDynamicArray or
  1199. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1200. result:=vartype.def.size
  1201. else
  1202. result:=0;
  1203. end;
  1204. function tabstractvarsym.is_regvar:boolean;
  1205. begin
  1206. { Register variables are not allowed in the following cases:
  1207. - regvars are disabled
  1208. - exceptions are used (after an exception is raised the contents of the
  1209. registers is not valid anymore)
  1210. - it has a local copy
  1211. - the value needs to be in memory (i.e. reference counted) }
  1212. result:=(cs_regvars in aktglobalswitches) and
  1213. not(pi_has_assembler_block in current_procinfo.flags) and
  1214. not(pi_uses_exceptions in current_procinfo.flags) and
  1215. not(vo_has_local_copy in varoptions) and
  1216. (varregable<>vr_none);
  1217. end;
  1218. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1219. var n:Tnotification;
  1220. begin
  1221. if assigned(notifications) then
  1222. begin
  1223. n:=Tnotification(notifications.first);
  1224. while assigned(n) do
  1225. begin
  1226. if what in n.flags then
  1227. n.callback(what,self);
  1228. n:=Tnotification(n.next);
  1229. end;
  1230. end;
  1231. end;
  1232. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1233. Tnotification_callback):cardinal;
  1234. var n:Tnotification;
  1235. begin
  1236. if not assigned(notifications) then
  1237. notifications:=Tlinkedlist.create;
  1238. n:=Tnotification.create(flags,callback);
  1239. register_notification:=n.id;
  1240. notifications.concat(n);
  1241. end;
  1242. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1243. var n:Tnotification;
  1244. begin
  1245. if not assigned(notifications) then
  1246. internalerror(200212311)
  1247. else
  1248. begin
  1249. n:=Tnotification(notifications.first);
  1250. while assigned(n) do
  1251. begin
  1252. if n.id=id then
  1253. begin
  1254. notifications.remove(n);
  1255. n.destroy;
  1256. exit;
  1257. end;
  1258. n:=Tnotification(n.next);
  1259. end;
  1260. internalerror(200212311)
  1261. end;
  1262. end;
  1263. procedure tabstractvarsym.setvartype(const newtype: ttype);
  1264. begin
  1265. _vartype := newtype;
  1266. { can we load the value into a register ? }
  1267. if not assigned(owner) or
  1268. (owner.symtabletype in [localsymtable,parasymtable]) or
  1269. (
  1270. (owner.symtabletype=staticsymtable) and
  1271. not(cs_create_pic in aktmoduleswitches)
  1272. ) then
  1273. begin
  1274. if tstoreddef(vartype.def).is_intregable then
  1275. varregable:=vr_intreg
  1276. else
  1277. {$warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0}
  1278. if (
  1279. not assigned(owner) or
  1280. (owner.symtabletype<>staticsymtable)
  1281. ) and
  1282. tstoreddef(vartype.def).is_fpuregable then
  1283. varregable:=vr_fpureg;
  1284. end;
  1285. end;
  1286. {****************************************************************************
  1287. TFIELDVARSYM
  1288. ****************************************************************************}
  1289. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1290. begin
  1291. inherited create(n,vsp,tt,vopts);
  1292. typ:=fieldvarsym;
  1293. fieldoffset:=0;
  1294. end;
  1295. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1296. begin
  1297. inherited ppuload(ppufile);
  1298. typ:=fieldvarsym;
  1299. fieldoffset:=ppufile.getaint;
  1300. end;
  1301. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1302. begin
  1303. inherited ppuwrite(ppufile);
  1304. ppufile.putaint(fieldoffset);
  1305. ppufile.writeentry(ibfieldvarsym);
  1306. end;
  1307. {$ifdef GDB}
  1308. function tfieldvarsym.stabstring:Pchar;
  1309. var
  1310. st : string;
  1311. begin
  1312. stabstring:=nil;
  1313. case owner.symtabletype of
  1314. objectsymtable :
  1315. begin
  1316. if (sp_static in symoptions) then
  1317. begin
  1318. st:=tstoreddef(vartype.def).numberstring;
  1319. if (cs_gdb_gsym in aktglobalswitches) then
  1320. st:='G'+st
  1321. else
  1322. st:='S'+st;
  1323. stabstring:=stabstr_evaluate('"${ownername}__${name}:$1",${N_LCSYM},0,${line},${mangledname}',[st]);
  1324. end;
  1325. end;
  1326. end;
  1327. end;
  1328. {$endif GDB}
  1329. {****************************************************************************
  1330. TABSTRACTNORMALVARSYM
  1331. ****************************************************************************}
  1332. constructor tabstractnormalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1333. begin
  1334. inherited create(n,vsp,tt,vopts);
  1335. fillchar(localloc,sizeof(localloc),0);
  1336. defaultconstsym:=nil;
  1337. end;
  1338. constructor tabstractnormalvarsym.ppuload(ppufile:tcompilerppufile);
  1339. begin
  1340. inherited ppuload(ppufile);
  1341. fillchar(localloc,sizeof(localloc),0);
  1342. ppufile.getderef(defaultconstsymderef);
  1343. end;
  1344. procedure tabstractnormalvarsym.buildderef;
  1345. begin
  1346. inherited buildderef;
  1347. defaultconstsymderef.build(defaultconstsym);
  1348. end;
  1349. procedure tabstractnormalvarsym.deref;
  1350. begin
  1351. inherited deref;
  1352. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1353. end;
  1354. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1355. begin
  1356. inherited ppuwrite(ppufile);
  1357. ppufile.putderef(defaultconstsymderef);
  1358. end;
  1359. {****************************************************************************
  1360. TGLOBALVARSYM
  1361. ****************************************************************************}
  1362. constructor tglobalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1363. begin
  1364. inherited create(n,vsp,tt,vopts);
  1365. typ:=globalvarsym;
  1366. _mangledname:=nil;
  1367. end;
  1368. constructor tglobalvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1369. begin
  1370. tglobalvarsym(self).create(n,vsp,tt,[vo_is_dll_var]);
  1371. end;
  1372. constructor tglobalvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1373. begin
  1374. tglobalvarsym(self).create(n,vsp,tt,[]);
  1375. set_mangledname(mangled);
  1376. end;
  1377. constructor tglobalvarsym.ppuload(ppufile:tcompilerppufile);
  1378. begin
  1379. inherited ppuload(ppufile);
  1380. typ:=globalvarsym;
  1381. if vo_has_mangledname in varoptions then
  1382. _mangledname:=stringdup(ppufile.getstring)
  1383. else
  1384. _mangledname:=nil;
  1385. end;
  1386. destructor tglobalvarsym.destroy;
  1387. begin
  1388. if assigned(_mangledname) then
  1389. begin
  1390. {$ifdef MEMDEBUG}
  1391. memmanglednames.start;
  1392. {$endif MEMDEBUG}
  1393. stringdispose(_mangledname);
  1394. {$ifdef MEMDEBUG}
  1395. memmanglednames.stop;
  1396. {$endif MEMDEBUG}
  1397. end;
  1398. inherited destroy;
  1399. end;
  1400. procedure tglobalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1401. begin
  1402. inherited ppuwrite(ppufile);
  1403. if vo_has_mangledname in varoptions then
  1404. ppufile.putstring(_mangledname^);
  1405. ppufile.writeentry(ibglobalvarsym);
  1406. end;
  1407. function tglobalvarsym.mangledname:string;
  1408. begin
  1409. if not assigned(_mangledname) then
  1410. begin
  1411. {$ifdef compress}
  1412. _mangledname:=stringdup(minilzw_encode(make_mangledname('U',owner,name)));
  1413. {$else}
  1414. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1415. {$endif}
  1416. end;
  1417. result:=_mangledname^;
  1418. end;
  1419. procedure tglobalvarsym.set_mangledname(const s:string);
  1420. begin
  1421. stringdispose(_mangledname);
  1422. {$ifdef compress}
  1423. _mangledname:=stringdup(minilzw_encode(s));
  1424. {$else}
  1425. _mangledname:=stringdup(s);
  1426. {$endif}
  1427. include(varoptions,vo_has_mangledname);
  1428. end;
  1429. {$ifdef GDB}
  1430. function Tglobalvarsym.stabstring:Pchar;
  1431. var st:string;
  1432. threadvaroffset:string;
  1433. regidx:Tregisterindex;
  1434. begin
  1435. result:=nil;
  1436. st:=tstoreddef(vartype.def).numberstring;
  1437. case localloc.loc of
  1438. LOC_REGISTER,
  1439. LOC_CREGISTER,
  1440. LOC_MMREGISTER,
  1441. LOC_CMMREGISTER,
  1442. LOC_FPUREGISTER,
  1443. LOC_CFPUREGISTER :
  1444. begin
  1445. regidx:=findreg_by_number(localloc.register);
  1446. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1447. { this is the register order for GDB}
  1448. if regidx<>0 then
  1449. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1450. end;
  1451. else
  1452. begin
  1453. if (vo_is_thread_var in varoptions) then
  1454. threadvaroffset:='+'+tostr(sizeof(aint))
  1455. else
  1456. threadvaroffset:='';
  1457. { Here we used S instead of
  1458. because with G GDB doesn't look at the address field
  1459. but searches the same name or with a leading underscore
  1460. but these names don't exist in pascal !}
  1461. if (cs_gdb_gsym in aktglobalswitches) then
  1462. st:='G'+st
  1463. else
  1464. st:='S'+st;
  1465. stabstring:=stabstr_evaluate('"${name}:$1",${N_LCSYM},0,${line},${mangledname}$2',[st,threadvaroffset]);
  1466. end;
  1467. end;
  1468. end;
  1469. {$endif GDB}
  1470. {****************************************************************************
  1471. TLOCALVARSYM
  1472. ****************************************************************************}
  1473. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1474. begin
  1475. inherited create(n,vsp,tt,vopts);
  1476. typ:=localvarsym;
  1477. end;
  1478. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1479. begin
  1480. inherited ppuload(ppufile);
  1481. typ:=localvarsym;
  1482. end;
  1483. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1484. begin
  1485. inherited ppuwrite(ppufile);
  1486. ppufile.writeentry(iblocalvarsym);
  1487. end;
  1488. {$ifdef GDB}
  1489. function tlocalvarsym.stabstring:Pchar;
  1490. var st:string;
  1491. regidx:Tregisterindex;
  1492. begin
  1493. stabstring:=nil;
  1494. { There is no space allocated for not referenced locals }
  1495. if (owner.symtabletype=localsymtable) and (refs=0) then
  1496. exit;
  1497. st:=tstoreddef(vartype.def).numberstring;
  1498. case localloc.loc of
  1499. LOC_REGISTER,
  1500. LOC_CREGISTER,
  1501. LOC_MMREGISTER,
  1502. LOC_CMMREGISTER,
  1503. LOC_FPUREGISTER,
  1504. LOC_CFPUREGISTER :
  1505. begin
  1506. regidx:=findreg_by_number(localloc.register);
  1507. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1508. { this is the register order for GDB}
  1509. if regidx<>0 then
  1510. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(regstabs_table[regidx])]);
  1511. end;
  1512. LOC_REFERENCE :
  1513. { offset to ebp => will not work if the framepointer is esp
  1514. so some optimizing will make things harder to debug }
  1515. stabstring:=stabstr_evaluate('"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(localloc.reference.offset)])
  1516. else
  1517. internalerror(2003091814);
  1518. end;
  1519. end;
  1520. {$endif GDB}
  1521. {****************************************************************************
  1522. TPARAVARSYM
  1523. ****************************************************************************}
  1524. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;const tt : ttype;vopts:tvaroptions);
  1525. begin
  1526. inherited create(n,vsp,tt,vopts);
  1527. typ:=paravarsym;
  1528. paranr:=nr;
  1529. paraloc[calleeside].init;
  1530. paraloc[callerside].init;
  1531. end;
  1532. destructor tparavarsym.destroy;
  1533. begin
  1534. paraloc[calleeside].done;
  1535. paraloc[callerside].done;
  1536. inherited destroy;
  1537. end;
  1538. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1539. var
  1540. b : byte;
  1541. begin
  1542. inherited ppuload(ppufile);
  1543. paranr:=ppufile.getword;
  1544. paraloc[calleeside].init;
  1545. paraloc[callerside].init;
  1546. if vo_has_explicit_paraloc in varoptions then
  1547. begin
  1548. b:=ppufile.getbyte;
  1549. if b<>sizeof(paraloc[callerside].location^) then
  1550. internalerror(200411154);
  1551. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1552. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1553. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1554. end;
  1555. typ:=paravarsym;
  1556. end;
  1557. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1558. begin
  1559. inherited ppuwrite(ppufile);
  1560. ppufile.putword(paranr);
  1561. if vo_has_explicit_paraloc in varoptions then
  1562. begin
  1563. paraloc[callerside].check_simple_location;
  1564. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1565. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1566. end;
  1567. ppufile.writeentry(ibparavarsym);
  1568. end;
  1569. {$ifdef GDB}
  1570. function tparavarsym.stabstring:Pchar;
  1571. var st:string;
  1572. regidx:Tregisterindex;
  1573. c:char;
  1574. begin
  1575. result:=nil;
  1576. { set loc to LOC_REFERENCE to get somewhat usable debugging info for -Or }
  1577. { while stabs aren't adapted for regvars yet }
  1578. if (vo_is_self in varoptions) then
  1579. begin
  1580. case localloc.loc of
  1581. LOC_REGISTER,
  1582. LOC_CREGISTER:
  1583. regidx:=findreg_by_number(localloc.register);
  1584. LOC_REFERENCE: ;
  1585. else
  1586. internalerror(2003091815);
  1587. end;
  1588. if (po_classmethod in current_procinfo.procdef.procoptions) or
  1589. (po_staticmethod in current_procinfo.procdef.procoptions) then
  1590. begin
  1591. if (localloc.loc=LOC_REFERENCE) then
  1592. stabstring:=stabstr_evaluate('"pvmt:p$1",${N_TSYM},0,0,$2',
  1593. [Tstoreddef(pvmttype.def).numberstring,tostr(localloc.reference.offset)]);
  1594. (* else
  1595. stabstring:=stabstr_evaluate('"pvmt:r$1",${N_RSYM},0,0,$2',
  1596. [Tstoreddef(pvmttype.def).numberstring,tostr(regstabs_table[regidx])]) *)
  1597. end
  1598. else
  1599. begin
  1600. if not(is_class(current_procinfo.procdef._class)) then
  1601. c:='v'
  1602. else
  1603. c:='p';
  1604. if (localloc.loc=LOC_REFERENCE) then
  1605. stabstring:=stabstr_evaluate('"$$t:$1",${N_TSYM},0,0,$2',
  1606. [c+current_procinfo.procdef._class.numberstring,tostr(localloc.reference.offset)]);
  1607. (* else
  1608. stabstring:=stabstr_evaluate('"$$t:r$1",${N_RSYM},0,0,$2',
  1609. [c+current_procinfo.procdef._class.numberstring,tostr(regstabs_table[regidx])]); *)
  1610. end;
  1611. end
  1612. else
  1613. begin
  1614. st:=tstoreddef(vartype.def).numberstring;
  1615. if paramanager.push_addr_param(varspez,vartype.def,tprocdef(owner.defowner).proccalloption) and
  1616. not(vo_has_local_copy in varoptions) and
  1617. not is_open_string(vartype.def) then
  1618. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1619. else
  1620. st := 'p'+st;
  1621. case localloc.loc of
  1622. LOC_REGISTER,
  1623. LOC_CREGISTER,
  1624. LOC_MMREGISTER,
  1625. LOC_CMMREGISTER,
  1626. LOC_FPUREGISTER,
  1627. LOC_CFPUREGISTER :
  1628. begin
  1629. regidx:=findreg_by_number(localloc.register);
  1630. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1631. { this is the register order for GDB}
  1632. if regidx<>0 then
  1633. stabstring:=stabstr_evaluate('"${name}:r$1",${N_RSYM},0,${line},$2',[st,tostr(longint(regstabs_table[regidx]))]);
  1634. end;
  1635. LOC_REFERENCE :
  1636. { offset to ebp => will not work if the framepointer is esp
  1637. so some optimizing will make things harder to debug }
  1638. stabstring:=stabstr_evaluate('"${name}:$1",${N_TSYM},0,${line},$2',[st,tostr(localloc.reference.offset)])
  1639. else
  1640. internalerror(2003091814);
  1641. end;
  1642. end;
  1643. end;
  1644. {$endif GDB}
  1645. {****************************************************************************
  1646. TABSOLUTEVARSYM
  1647. ****************************************************************************}
  1648. constructor tabsolutevarsym.create(const n : string;const tt : ttype);
  1649. begin
  1650. inherited create(n,vs_value,tt,[]);
  1651. typ:=absolutevarsym;
  1652. ref:=nil;
  1653. end;
  1654. constructor tabsolutevarsym.create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  1655. begin
  1656. inherited create(n,vs_value,tt,[]);
  1657. typ:=absolutevarsym;
  1658. ref:=_ref;
  1659. end;
  1660. destructor tabsolutevarsym.destroy;
  1661. begin
  1662. if assigned(ref) then
  1663. ref.free;
  1664. inherited destroy;
  1665. end;
  1666. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1667. begin
  1668. inherited ppuload(ppufile);
  1669. typ:=absolutevarsym;
  1670. ref:=nil;
  1671. asmname:=nil;
  1672. abstyp:=absolutetyp(ppufile.getbyte);
  1673. {$ifdef i386}
  1674. absseg:=false;
  1675. {$endif i386}
  1676. case abstyp of
  1677. tovar :
  1678. ref:=ppufile.getsymlist;
  1679. toasm :
  1680. asmname:=stringdup(ppufile.getstring);
  1681. toaddr :
  1682. begin
  1683. addroffset:=ppufile.getaint;
  1684. {$ifdef i386}
  1685. absseg:=boolean(ppufile.getbyte);
  1686. {$endif i386}
  1687. end;
  1688. end;
  1689. end;
  1690. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1691. begin
  1692. inherited ppuwrite(ppufile);
  1693. ppufile.putbyte(byte(abstyp));
  1694. case abstyp of
  1695. tovar :
  1696. ppufile.putsymlist(ref);
  1697. toasm :
  1698. ppufile.putstring(asmname^);
  1699. toaddr :
  1700. begin
  1701. ppufile.putaint(addroffset);
  1702. {$ifdef i386}
  1703. ppufile.putbyte(byte(absseg));
  1704. {$endif i386}
  1705. end;
  1706. end;
  1707. ppufile.writeentry(ibabsolutevarsym);
  1708. end;
  1709. procedure tabsolutevarsym.buildderef;
  1710. begin
  1711. inherited buildderef;
  1712. if (abstyp=tovar) then
  1713. ref.buildderef;
  1714. end;
  1715. procedure tabsolutevarsym.deref;
  1716. begin
  1717. inherited deref;
  1718. { own absolute deref }
  1719. if (abstyp=tovar) then
  1720. ref.resolve;
  1721. end;
  1722. function tabsolutevarsym.mangledname : string;
  1723. begin
  1724. case abstyp of
  1725. toasm :
  1726. mangledname:=asmname^;
  1727. toaddr :
  1728. mangledname:='$'+tostr(addroffset);
  1729. else
  1730. internalerror(200411061);
  1731. end;
  1732. end;
  1733. {$ifdef GDB}
  1734. function tabsolutevarsym.stabstring:Pchar;
  1735. begin
  1736. stabstring:=nil;
  1737. end;
  1738. {$endif GDB}
  1739. {****************************************************************************
  1740. TTYPEDCONSTSYM
  1741. *****************************************************************************}
  1742. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1743. begin
  1744. inherited create(n);
  1745. typ:=typedconstsym;
  1746. typedconsttype.setdef(p);
  1747. is_writable:=writable;
  1748. end;
  1749. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1750. begin
  1751. inherited create(n);
  1752. typ:=typedconstsym;
  1753. typedconsttype:=tt;
  1754. is_writable:=writable;
  1755. end;
  1756. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1757. begin
  1758. inherited ppuload(ppufile);
  1759. typ:=typedconstsym;
  1760. ppufile.gettype(typedconsttype);
  1761. is_writable:=boolean(ppufile.getbyte);
  1762. end;
  1763. destructor ttypedconstsym.destroy;
  1764. begin
  1765. if assigned(_mangledname) then
  1766. begin
  1767. {$ifdef MEMDEBUG}
  1768. memmanglednames.start;
  1769. {$endif MEMDEBUG}
  1770. stringdispose(_mangledname);
  1771. {$ifdef MEMDEBUG}
  1772. memmanglednames.stop;
  1773. {$endif MEMDEBUG}
  1774. end;
  1775. inherited destroy;
  1776. end;
  1777. function ttypedconstsym.mangledname:string;
  1778. begin
  1779. if not assigned(_mangledname) then
  1780. begin
  1781. {$ifdef compress}
  1782. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1783. {$else}
  1784. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1785. {$endif}
  1786. end;
  1787. result:=_mangledname^;
  1788. end;
  1789. function ttypedconstsym.getsize : longint;
  1790. begin
  1791. if assigned(typedconsttype.def) then
  1792. getsize:=typedconsttype.def.size
  1793. else
  1794. getsize:=0;
  1795. end;
  1796. procedure ttypedconstsym.buildderef;
  1797. begin
  1798. typedconsttype.buildderef;
  1799. end;
  1800. procedure ttypedconstsym.deref;
  1801. begin
  1802. typedconsttype.resolve;
  1803. end;
  1804. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1805. begin
  1806. inherited ppuwrite(ppufile);
  1807. ppufile.puttype(typedconsttype);
  1808. ppufile.putbyte(byte(is_writable));
  1809. ppufile.writeentry(ibtypedconstsym);
  1810. end;
  1811. {$ifdef GDB}
  1812. function ttypedconstsym.stabstring : pchar;
  1813. var st:char;
  1814. begin
  1815. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1816. st:='G'
  1817. else
  1818. st:='S';
  1819. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_STSYM},0,${line},${mangledname}',
  1820. [st,Tstoreddef(typedconsttype.def).numberstring]);
  1821. end;
  1822. {$endif GDB}
  1823. {****************************************************************************
  1824. TCONSTSYM
  1825. ****************************************************************************}
  1826. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1827. begin
  1828. inherited create(n);
  1829. fillchar(value, sizeof(value), #0);
  1830. typ:=constsym;
  1831. consttyp:=t;
  1832. value.valueord:=v;
  1833. ResStrIndex:=0;
  1834. consttype:=tt;
  1835. end;
  1836. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1837. begin
  1838. inherited create(n);
  1839. fillchar(value, sizeof(value), #0);
  1840. typ:=constsym;
  1841. consttyp:=t;
  1842. value.valueordptr:=v;
  1843. ResStrIndex:=0;
  1844. consttype:=tt;
  1845. end;
  1846. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1847. begin
  1848. inherited create(n);
  1849. fillchar(value, sizeof(value), #0);
  1850. typ:=constsym;
  1851. consttyp:=t;
  1852. value.valueptr:=v;
  1853. ResStrIndex:=0;
  1854. consttype:=tt;
  1855. end;
  1856. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1857. begin
  1858. inherited create(n);
  1859. fillchar(value, sizeof(value), #0);
  1860. typ:=constsym;
  1861. consttyp:=t;
  1862. value.valueptr:=str;
  1863. consttype.reset;
  1864. value.len:=l;
  1865. if t=constresourcestring then
  1866. ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
  1867. end;
  1868. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1869. var
  1870. pd : pbestreal;
  1871. ps : pnormalset;
  1872. pc : pchar;
  1873. begin
  1874. inherited ppuload(ppufile);
  1875. typ:=constsym;
  1876. consttype.reset;
  1877. consttyp:=tconsttyp(ppufile.getbyte);
  1878. fillchar(value, sizeof(value), #0);
  1879. case consttyp of
  1880. constord :
  1881. begin
  1882. ppufile.gettype(consttype);
  1883. value.valueord:=ppufile.getexprint;
  1884. end;
  1885. constpointer :
  1886. begin
  1887. ppufile.gettype(consttype);
  1888. value.valueordptr:=ppufile.getptruint;
  1889. end;
  1890. conststring,
  1891. constresourcestring :
  1892. begin
  1893. value.len:=ppufile.getlongint;
  1894. getmem(pc,value.len+1);
  1895. ppufile.getdata(pc^,value.len);
  1896. if consttyp=constresourcestring then
  1897. ResStrIndex:=ppufile.getlongint;
  1898. value.valueptr:=pc;
  1899. end;
  1900. constreal :
  1901. begin
  1902. new(pd);
  1903. pd^:=ppufile.getreal;
  1904. value.valueptr:=pd;
  1905. end;
  1906. constset :
  1907. begin
  1908. ppufile.gettype(consttype);
  1909. new(ps);
  1910. ppufile.getnormalset(ps^);
  1911. value.valueptr:=ps;
  1912. end;
  1913. constguid :
  1914. begin
  1915. new(pguid(value.valueptr));
  1916. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1917. end;
  1918. constnil : ;
  1919. else
  1920. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1921. end;
  1922. end;
  1923. destructor tconstsym.destroy;
  1924. begin
  1925. case consttyp of
  1926. conststring,
  1927. constresourcestring :
  1928. freemem(pchar(value.valueptr),value.len+1);
  1929. constreal :
  1930. dispose(pbestreal(value.valueptr));
  1931. constset :
  1932. dispose(pnormalset(value.valueptr));
  1933. constguid :
  1934. dispose(pguid(value.valueptr));
  1935. end;
  1936. inherited destroy;
  1937. end;
  1938. procedure tconstsym.buildderef;
  1939. begin
  1940. if consttyp in [constord,constpointer,constset] then
  1941. consttype.buildderef;
  1942. end;
  1943. procedure tconstsym.deref;
  1944. begin
  1945. if consttyp in [constord,constpointer,constset] then
  1946. consttype.resolve;
  1947. end;
  1948. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1949. begin
  1950. inherited ppuwrite(ppufile);
  1951. ppufile.putbyte(byte(consttyp));
  1952. case consttyp of
  1953. constnil : ;
  1954. constord :
  1955. begin
  1956. ppufile.puttype(consttype);
  1957. ppufile.putexprint(value.valueord);
  1958. end;
  1959. constpointer :
  1960. begin
  1961. ppufile.puttype(consttype);
  1962. ppufile.putptruint(value.valueordptr);
  1963. end;
  1964. conststring,
  1965. constresourcestring :
  1966. begin
  1967. ppufile.putlongint(value.len);
  1968. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1969. if consttyp=constresourcestring then
  1970. ppufile.putlongint(ResStrIndex);
  1971. end;
  1972. constreal :
  1973. ppufile.putreal(pbestreal(value.valueptr)^);
  1974. constset :
  1975. begin
  1976. ppufile.puttype(consttype);
  1977. ppufile.putnormalset(value.valueptr^);
  1978. end;
  1979. constguid :
  1980. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1981. else
  1982. internalerror(13);
  1983. end;
  1984. ppufile.writeentry(ibconstsym);
  1985. end;
  1986. {$ifdef GDB}
  1987. function Tconstsym.stabstring:Pchar;
  1988. var st : string;
  1989. begin
  1990. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1991. case consttyp of
  1992. conststring:
  1993. st:='s'''+backspace_quote(octal_quote(strpas(pchar(value.valueptr)),[#0..#9,#11,#12,#14..#31,'''']),['"','\',#10,#13])+'''';
  1994. constord:
  1995. st:='i'+tostr(value.valueord);
  1996. constpointer:
  1997. st:='i'+tostr(value.valueordptr);
  1998. constreal:
  1999. begin
  2000. system.str(pbestreal(value.valueptr)^,st);
  2001. st := 'r'+st;
  2002. end;
  2003. { if we don't know just put zero !! }
  2004. else st:='i0';
  2005. {***SETCONST}
  2006. {constset:;} {*** I don't know what to do with a set.}
  2007. { sets are not recognized by GDB}
  2008. {***}
  2009. end;
  2010. { valgrind does not support constants }
  2011. if cs_gdb_valgrind in aktglobalswitches then
  2012. stabstring:=nil
  2013. else
  2014. stabstring:=stabstr_evaluate('"${name}:c=$1;",${N_FUNCTION},0,${line},0',[st]);
  2015. end;
  2016. {$endif GDB}
  2017. {****************************************************************************
  2018. TENUMSYM
  2019. ****************************************************************************}
  2020. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2021. begin
  2022. inherited create(n);
  2023. typ:=enumsym;
  2024. definition:=def;
  2025. value:=v;
  2026. { First entry? Then we need to set the minval }
  2027. if def.firstenum=nil then
  2028. begin
  2029. if v>0 then
  2030. def.has_jumps:=true;
  2031. def.setmin(v);
  2032. def.setmax(v);
  2033. end
  2034. else
  2035. begin
  2036. { check for jumps }
  2037. if v>def.max+1 then
  2038. def.has_jumps:=true;
  2039. { update low and high }
  2040. if def.min>v then
  2041. def.setmin(v);
  2042. if def.max<v then
  2043. def.setmax(v);
  2044. end;
  2045. order;
  2046. end;
  2047. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2048. begin
  2049. inherited ppuload(ppufile);
  2050. typ:=enumsym;
  2051. ppufile.getderef(definitionderef);
  2052. value:=ppufile.getlongint;
  2053. nextenum := Nil;
  2054. end;
  2055. procedure tenumsym.buildderef;
  2056. begin
  2057. definitionderef.build(definition);
  2058. end;
  2059. procedure tenumsym.deref;
  2060. begin
  2061. definition:=tenumdef(definitionderef.resolve);
  2062. order;
  2063. end;
  2064. procedure tenumsym.order;
  2065. var
  2066. sym : tenumsym;
  2067. begin
  2068. sym := tenumsym(definition.firstenum);
  2069. if sym = nil then
  2070. begin
  2071. definition.firstenum := self;
  2072. nextenum := nil;
  2073. exit;
  2074. end;
  2075. { reorder the symbols in increasing value }
  2076. if value < sym.value then
  2077. begin
  2078. nextenum := sym;
  2079. definition.firstenum := self;
  2080. end
  2081. else
  2082. begin
  2083. while (sym.value <= value) and assigned(sym.nextenum) do
  2084. sym := sym.nextenum;
  2085. nextenum := sym.nextenum;
  2086. sym.nextenum := self;
  2087. end;
  2088. end;
  2089. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2090. begin
  2091. inherited ppuwrite(ppufile);
  2092. ppufile.putderef(definitionderef);
  2093. ppufile.putlongint(value);
  2094. ppufile.writeentry(ibenumsym);
  2095. end;
  2096. {****************************************************************************
  2097. TTYPESYM
  2098. ****************************************************************************}
  2099. constructor ttypesym.create(const n : string;const tt : ttype);
  2100. begin
  2101. inherited create(n);
  2102. typ:=typesym;
  2103. restype:=tt;
  2104. { register the typesym for the definition }
  2105. if assigned(restype.def) and
  2106. (restype.def.deftype<>errordef) and
  2107. not(assigned(restype.def.typesym)) then
  2108. restype.def.typesym:=self;
  2109. end;
  2110. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2111. begin
  2112. inherited ppuload(ppufile);
  2113. typ:=typesym;
  2114. ppufile.gettype(restype);
  2115. end;
  2116. function ttypesym.gettypedef:tdef;
  2117. begin
  2118. gettypedef:=restype.def;
  2119. end;
  2120. procedure ttypesym.buildderef;
  2121. begin
  2122. restype.buildderef;
  2123. end;
  2124. procedure ttypesym.deref;
  2125. begin
  2126. restype.resolve;
  2127. end;
  2128. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2129. begin
  2130. inherited ppuwrite(ppufile);
  2131. ppufile.puttype(restype);
  2132. ppufile.writeentry(ibtypesym);
  2133. end;
  2134. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  2135. begin
  2136. inherited load_references(ppufile,locals);
  2137. if (restype.def.deftype=recorddef) then
  2138. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  2139. if (restype.def.deftype=objectdef) then
  2140. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  2141. end;
  2142. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  2143. var
  2144. d : tderef;
  2145. begin
  2146. d.reset;
  2147. if not inherited write_references(ppufile,locals) then
  2148. begin
  2149. { write address of this symbol if record or object
  2150. even if no real refs are there
  2151. because we need it for the symtable }
  2152. if (restype.def.deftype in [recorddef,objectdef]) then
  2153. begin
  2154. d.build(self);
  2155. ppufile.putderef(d);
  2156. ppufile.writeentry(ibsymref);
  2157. end;
  2158. end;
  2159. write_references:=true;
  2160. if (restype.def.deftype=recorddef) then
  2161. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  2162. if (restype.def.deftype=objectdef) then
  2163. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  2164. end;
  2165. {$ifdef GDB}
  2166. function ttypesym.stabstring : pchar;
  2167. var stabchar:string[2];
  2168. begin
  2169. stabstring:=nil;
  2170. if restype.def<>nil then
  2171. begin
  2172. if restype.def.deftype in tagtypes then
  2173. stabchar:='Tt'
  2174. else
  2175. stabchar:='t';
  2176. stabstring:=stabstr_evaluate('"${name}:$1$2",${N_LSYM},0,${line},0',[stabchar,tstoreddef(restype.def).numberstring]);
  2177. end;
  2178. end;
  2179. {$endif GDB}
  2180. {****************************************************************************
  2181. TSYSSYM
  2182. ****************************************************************************}
  2183. constructor tsyssym.create(const n : string;l : longint);
  2184. begin
  2185. inherited create(n);
  2186. typ:=syssym;
  2187. number:=l;
  2188. end;
  2189. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2190. begin
  2191. inherited ppuload(ppufile);
  2192. typ:=syssym;
  2193. number:=ppufile.getlongint;
  2194. end;
  2195. destructor tsyssym.destroy;
  2196. begin
  2197. inherited destroy;
  2198. end;
  2199. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2200. begin
  2201. inherited ppuwrite(ppufile);
  2202. ppufile.putlongint(number);
  2203. ppufile.writeentry(ibsyssym);
  2204. end;
  2205. {*****************************************************************************
  2206. TMacro
  2207. *****************************************************************************}
  2208. constructor tmacro.create(const n : string);
  2209. begin
  2210. inherited create(n);
  2211. typ:= macrosym;
  2212. owner:= nil;
  2213. defined:=false;
  2214. is_used:=false;
  2215. is_compiler_var:= false;
  2216. buftext:=nil;
  2217. buflen:=0;
  2218. end;
  2219. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2220. begin
  2221. inherited ppuload(ppufile);
  2222. typ:=macrosym;
  2223. name:=ppufile.getstring;
  2224. defined:=boolean(ppufile.getbyte);
  2225. is_compiler_var:=boolean(ppufile.getbyte);
  2226. is_used:=false;
  2227. buflen:= ppufile.getlongint;
  2228. if buflen > 0 then
  2229. begin
  2230. getmem(buftext, buflen);
  2231. ppufile.getdata(buftext^, buflen)
  2232. end
  2233. else
  2234. buftext:=nil;
  2235. end;
  2236. destructor tmacro.destroy;
  2237. begin
  2238. if assigned(buftext) then
  2239. freemem(buftext,buflen);
  2240. inherited destroy;
  2241. end;
  2242. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2243. begin
  2244. inherited ppuwrite(ppufile);
  2245. ppufile.putstring(name);
  2246. ppufile.putbyte(byte(defined));
  2247. ppufile.putbyte(byte(is_compiler_var));
  2248. ppufile.putlongint(buflen);
  2249. if buflen > 0 then
  2250. ppufile.putdata(buftext^,buflen);
  2251. ppufile.writeentry(ibmacrosym);
  2252. end;
  2253. {****************************************************************************
  2254. TRTTISYM
  2255. ****************************************************************************}
  2256. constructor trttisym.create(const n:string;rt:trttitype);
  2257. const
  2258. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2259. begin
  2260. inherited create(prefix[rt]+n);
  2261. include(symoptions,sp_internal);
  2262. typ:=rttisym;
  2263. lab:=nil;
  2264. rttityp:=rt;
  2265. end;
  2266. destructor trttisym.destroy;
  2267. begin
  2268. if assigned(_mangledname) then
  2269. begin
  2270. {$ifdef MEMDEBUG}
  2271. memmanglednames.start;
  2272. {$endif MEMDEBUG}
  2273. stringdispose(_mangledname);
  2274. {$ifdef MEMDEBUG}
  2275. memmanglednames.stop;
  2276. {$endif MEMDEBUG}
  2277. end;
  2278. inherited destroy;
  2279. end;
  2280. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2281. begin
  2282. inherited ppuload(ppufile);
  2283. typ:=rttisym;
  2284. lab:=nil;
  2285. rttityp:=trttitype(ppufile.getbyte);
  2286. end;
  2287. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2288. begin
  2289. inherited ppuwrite(ppufile);
  2290. ppufile.putbyte(byte(rttityp));
  2291. ppufile.writeentry(ibrttisym);
  2292. end;
  2293. function trttisym.mangledname : string;
  2294. const
  2295. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2296. begin
  2297. if not assigned(_mangledname) then
  2298. _mangledname:=stringdup(make_mangledname(prefix[rttityp],owner,Copy(name,5,255)));
  2299. result:=_mangledname^;
  2300. end;
  2301. function trttisym.get_label:tasmsymbol;
  2302. begin
  2303. { the label is always a global label }
  2304. if not assigned(lab) then
  2305. lab:=objectlibrary.newasmsymbol(mangledname,AB_EXTERNAL,AT_DATA);
  2306. get_label:=lab;
  2307. end;
  2308. end.