symsym.pas 78 KB

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