symsym.pas 78 KB

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