symsym.pas 80 KB

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