symsym.pas 78 KB

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