symsym.pas 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606
  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. aktvarsym : tvarsym; { pointer to the symbol for the
  329. currently read var, only used
  330. for variable directives }
  331. generrorsym : tsym;
  332. otsym : tvarsym;
  333. const
  334. current_object_option : tsymoptions = [sp_public];
  335. { rtti and init/final }
  336. procedure generate_rtti(p:tsym);
  337. procedure generate_inittable(p:tsym);
  338. implementation
  339. uses
  340. {$ifdef Delphi}
  341. sysutils,
  342. {$else Delphi}
  343. strings,
  344. {$endif Delphi}
  345. { global }
  346. globtype,verbose,
  347. { target }
  348. systems,
  349. { symtable }
  350. symtable,defbase,
  351. {$ifdef GDB}
  352. gdb,
  353. {$endif GDB}
  354. { tree }
  355. node,
  356. { aasm }
  357. aasmcpu,
  358. { module }
  359. fmodule,
  360. { codegen }
  361. paramgr,cgbase,cresstr
  362. ;
  363. {****************************************************************************
  364. Helpers
  365. ****************************************************************************}
  366. {****************************************************************************
  367. TSYM (base for all symtypes)
  368. ****************************************************************************}
  369. constructor tstoredsym.create(const n : string);
  370. begin
  371. inherited create(n);
  372. symoptions:=current_object_option;
  373. {$ifdef GDB}
  374. isstabwritten := false;
  375. {$endif GDB}
  376. fileinfo:=akttokenpos;
  377. defref:=nil;
  378. refs:=0;
  379. lastwritten:=nil;
  380. refcount:=0;
  381. if (cs_browser in aktmoduleswitches) and make_ref then
  382. begin
  383. defref:=tref.create(defref,@akttokenpos);
  384. inc(refcount);
  385. end;
  386. lastref:=defref;
  387. _mangledname:=nil;
  388. end;
  389. constructor tstoredsym.loadsym(ppufile:tcompilerppufile);
  390. var
  391. s : string;
  392. nr : word;
  393. begin
  394. nr:=ppufile.getword;
  395. s:=ppufile.getstring;
  396. inherited create(s);
  397. { force the correct indexnr. must be after create! }
  398. indexnr:=nr;
  399. ppufile.getsmallset(symoptions);
  400. ppufile.getposinfo(fileinfo);
  401. lastref:=nil;
  402. defref:=nil;
  403. refs:=0;
  404. lastwritten:=nil;
  405. refcount:=0;
  406. _mangledname:=nil;
  407. {$ifdef GDB}
  408. isstabwritten := false;
  409. {$endif GDB}
  410. end;
  411. procedure tstoredsym.deref;
  412. begin
  413. end;
  414. procedure tstoredsym.load_references(ppufile:tcompilerppufile;locals:boolean);
  415. var
  416. pos : tfileposinfo;
  417. move_last : boolean;
  418. begin
  419. move_last:=lastwritten=lastref;
  420. while (not ppufile.endofentry) do
  421. begin
  422. ppufile.getposinfo(pos);
  423. inc(refcount);
  424. lastref:=tref.create(lastref,@pos);
  425. lastref.is_written:=true;
  426. if refcount=1 then
  427. defref:=lastref;
  428. end;
  429. if move_last then
  430. lastwritten:=lastref;
  431. end;
  432. { big problem here :
  433. wrong refs were written because of
  434. interface parsing of other units PM
  435. moduleindex must be checked !! }
  436. function tstoredsym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  437. var
  438. ref : tref;
  439. symref_written,move_last : boolean;
  440. begin
  441. write_references:=false;
  442. if lastwritten=lastref then
  443. exit;
  444. { should we update lastref }
  445. move_last:=true;
  446. symref_written:=false;
  447. { write symbol refs }
  448. if assigned(lastwritten) then
  449. ref:=lastwritten
  450. else
  451. ref:=defref;
  452. while assigned(ref) do
  453. begin
  454. if ref.moduleindex=current_module.unit_index then
  455. begin
  456. { write address to this symbol }
  457. if not symref_written then
  458. begin
  459. ppufile.putderef(self);
  460. symref_written:=true;
  461. end;
  462. ppufile.putposinfo(ref.posinfo);
  463. ref.is_written:=true;
  464. if move_last then
  465. lastwritten:=ref;
  466. end
  467. else if not ref.is_written then
  468. move_last:=false
  469. else if move_last then
  470. lastwritten:=ref;
  471. ref:=ref.nextref;
  472. end;
  473. if symref_written then
  474. ppufile.writeentry(ibsymref);
  475. write_references:=symref_written;
  476. end;
  477. destructor tstoredsym.destroy;
  478. begin
  479. if assigned(_mangledname) then
  480. begin
  481. {$ifdef MEMDEBUG}
  482. memmanglednames.start;
  483. {$endif MEMDEBUG}
  484. stringdispose(_mangledname);
  485. {$ifdef MEMDEBUG}
  486. memmanglednames.stop;
  487. {$endif MEMDEBUG}
  488. end;
  489. if assigned(defref) then
  490. begin
  491. {$ifdef MEMDEBUG}
  492. membrowser.start;
  493. {$endif MEMDEBUG}
  494. defref.freechain;
  495. defref.free;
  496. {$ifdef MEMDEBUG}
  497. membrowser.stop;
  498. {$endif MEMDEBUG}
  499. end;
  500. inherited destroy;
  501. end;
  502. procedure tstoredsym.writesym(ppufile:tcompilerppufile);
  503. begin
  504. ppufile.putword(indexnr);
  505. ppufile.putstring(_realname^);
  506. ppufile.putsmallset(symoptions);
  507. ppufile.putposinfo(fileinfo);
  508. end;
  509. {$ifdef GDB}
  510. function tstoredsym.stabstring : pchar;
  511. begin
  512. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  513. tostr(fileinfo.line)+',0');
  514. end;
  515. procedure tstoredsym.concatstabto(asmlist : taasmoutput);
  516. var
  517. stab_str : pchar;
  518. begin
  519. if not isstabwritten then
  520. begin
  521. stab_str := stabstring;
  522. { count_dbx(stab_str); moved to GDB.PAS }
  523. asmList.concat(Tai_stabs.Create(stab_str));
  524. isstabwritten:=true;
  525. end;
  526. end;
  527. {$endif GDB}
  528. function tstoredsym.is_visible_for_proc(currprocdef:tprocdef):boolean;
  529. begin
  530. is_visible_for_proc:=false;
  531. { private symbols are allowed when we are in the same
  532. module as they are defined }
  533. if (sp_private in symoptions) and
  534. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  535. (owner.defowner.owner.unitid<>0) then
  536. exit;
  537. { protected symbols are vissible in the module that defines them and
  538. also visible to related objects }
  539. if (sp_protected in symoptions) and
  540. (
  541. (
  542. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  543. (owner.defowner.owner.unitid<>0)
  544. ) and
  545. not(
  546. assigned(currprocdef) and
  547. assigned(currprocdef._class) and
  548. currprocdef._class.is_related(tobjectdef(owner.defowner))
  549. )
  550. ) then
  551. exit;
  552. is_visible_for_proc:=true;
  553. end;
  554. function tstoredsym.is_visible_for_object(currobjdef:tobjectdef):boolean;
  555. begin
  556. is_visible_for_object:=false;
  557. { private symbols are allowed when we are in the same
  558. module as they are defined }
  559. if (sp_private in symoptions) and
  560. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  561. (owner.defowner.owner.unitid<>0) then
  562. exit;
  563. { protected symbols are vissible in the module that defines them and
  564. also visible to related objects }
  565. if (sp_protected in symoptions) and
  566. (
  567. (
  568. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  569. (owner.defowner.owner.unitid<>0)
  570. ) and
  571. not(
  572. assigned(currobjdef) and
  573. currobjdef.is_related(tobjectdef(owner.defowner))
  574. )
  575. ) then
  576. exit;
  577. is_visible_for_object:=true;
  578. end;
  579. function tstoredsym.mangledname : string;
  580. begin
  581. if not assigned(_mangledname) then
  582. begin
  583. generate_mangledname;
  584. if not assigned(_mangledname) then
  585. internalerror(200204171);
  586. end;
  587. mangledname:=_mangledname^
  588. end;
  589. {****************************************************************************
  590. TLABELSYM
  591. ****************************************************************************}
  592. constructor tlabelsym.create(const n : string; l : tasmlabel);
  593. begin
  594. inherited create(n);
  595. typ:=labelsym;
  596. lab:=l;
  597. used:=false;
  598. defined:=false;
  599. code:=nil;
  600. end;
  601. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  602. begin
  603. inherited loadsym(ppufile);
  604. typ:=labelsym;
  605. { this is all dummy
  606. it is only used for local browsing }
  607. lab:=nil;
  608. code:=nil;
  609. used:=false;
  610. defined:=true;
  611. end;
  612. destructor tlabelsym.destroy;
  613. begin
  614. inherited destroy;
  615. end;
  616. procedure tlabelsym.generate_mangledname;
  617. begin
  618. _mangledname:=stringdup(lab.name);
  619. end;
  620. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  621. begin
  622. if owner.symtabletype=globalsymtable then
  623. Message(sym_e_ill_label_decl)
  624. else
  625. begin
  626. inherited writesym(ppufile);
  627. ppufile.writeentry(iblabelsym);
  628. end;
  629. end;
  630. {****************************************************************************
  631. TUNITSYM
  632. ****************************************************************************}
  633. constructor tunitsym.create(const n : string;ref : tsymtable);
  634. var
  635. old_make_ref : boolean;
  636. begin
  637. old_make_ref:=make_ref;
  638. make_ref:=false;
  639. inherited create(n);
  640. make_ref:=old_make_ref;
  641. typ:=unitsym;
  642. unitsymtable:=ref;
  643. if assigned(ref) and
  644. (ref.symtabletype=globalsymtable) then
  645. begin
  646. prevsym:=tglobalsymtable(ref).unitsym;
  647. tglobalsymtable(ref).unitsym:=self;
  648. end;
  649. end;
  650. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  651. begin
  652. inherited loadsym(ppufile);
  653. typ:=unitsym;
  654. unitsymtable:=nil;
  655. prevsym:=nil;
  656. refs:=0;
  657. end;
  658. { we need to remove it from the prevsym chain ! }
  659. procedure tunitsym.restoreunitsym;
  660. var pus,ppus : tunitsym;
  661. begin
  662. if assigned(unitsymtable) and
  663. (unitsymtable.symtabletype=globalsymtable) then
  664. begin
  665. ppus:=nil;
  666. pus:=tglobalsymtable(unitsymtable).unitsym;
  667. if pus=self then
  668. tglobalsymtable(unitsymtable).unitsym:=prevsym
  669. else while assigned(pus) do
  670. begin
  671. if pus=self then
  672. begin
  673. ppus.prevsym:=prevsym;
  674. break;
  675. end
  676. else
  677. begin
  678. ppus:=pus;
  679. pus:=ppus.prevsym;
  680. end;
  681. end;
  682. end;
  683. unitsymtable:=nil;
  684. prevsym:=nil;
  685. end;
  686. destructor tunitsym.destroy;
  687. begin
  688. restoreunitsym;
  689. inherited destroy;
  690. end;
  691. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  692. begin
  693. inherited writesym(ppufile);
  694. ppufile.writeentry(ibunitsym);
  695. end;
  696. {$ifdef GDB}
  697. procedure tunitsym.concatstabto(asmlist : taasmoutput);
  698. begin
  699. {Nothing to write to stabs !}
  700. end;
  701. {$endif GDB}
  702. {****************************************************************************
  703. TPROCSYM
  704. ****************************************************************************}
  705. constructor tprocsym.create(const n : string);
  706. begin
  707. inherited create(n);
  708. typ:=procsym;
  709. defs:=nil;
  710. owner:=nil;
  711. is_global:=false;
  712. overloadchecked:=false;
  713. overloadcount:=0;
  714. procdef_count:=0;
  715. end;
  716. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  717. var
  718. pd : tprocdef;
  719. begin
  720. inherited loadsym(ppufile);
  721. typ:=procsym;
  722. defs:=nil;
  723. procdef_count:=0;
  724. repeat
  725. pd:=tprocdef(ppufile.getderef);
  726. if pd=nil then
  727. break;
  728. addprocdef(pd);
  729. until false;
  730. is_global:=false;
  731. overloadchecked:=false;
  732. overloadcount:=-1; { invalid, not used anymore }
  733. end;
  734. destructor tprocsym.destroy;
  735. var
  736. hp,p : pprocdeflist;
  737. begin
  738. p:=defs;
  739. while assigned(p) do
  740. begin
  741. hp:=p^.next;
  742. dispose(p);
  743. p:=hp;
  744. end;
  745. inherited destroy;
  746. end;
  747. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  748. var
  749. p : pprocdeflist;
  750. begin
  751. p:=defs;
  752. while assigned(p) do
  753. begin
  754. if p^.def<>skipdef then
  755. MessagePos1(p^.def.fileinfo,sym_b_param_list,p^.def.fullprocname);
  756. p:=p^.next;
  757. end;
  758. end;
  759. procedure tprocsym.check_forward;
  760. var
  761. p : pprocdeflist;
  762. begin
  763. p:=defs;
  764. while assigned(p) do
  765. begin
  766. if (p^.def.procsym=self) and
  767. (p^.def.forwarddef) then
  768. begin
  769. MessagePos1(fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname);
  770. { Turn futher error messages off }
  771. p^.def.forwarddef:=false;
  772. end;
  773. p:=p^.next;
  774. end;
  775. end;
  776. procedure tprocsym.deref;
  777. var
  778. p : pprocdeflist;
  779. begin
  780. p:=defs;
  781. while assigned(p) do
  782. begin
  783. resolvedef(pointer(p^.def));
  784. p:=p^.next;
  785. end;
  786. end;
  787. procedure tprocsym.addprocdef(p:tprocdef);
  788. var
  789. pd : pprocdeflist;
  790. begin
  791. new(pd);
  792. pd^.def:=p;
  793. pd^.next:=defs;
  794. defs:=pd;
  795. inc(procdef_count);
  796. end;
  797. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  798. var
  799. i : cardinal;
  800. pd : Pprocdeflist;
  801. begin
  802. pd:=defs;
  803. for i:=2 to nr do
  804. begin
  805. if not assigned(pd) then
  806. internalerror(200209051);
  807. pd:=pd^.next;
  808. end;
  809. getprocdef:=pd^.def;
  810. end;
  811. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym);
  812. var pd:Pprocdeflist;
  813. begin
  814. pd:=defs;
  815. while assigned(pd) do
  816. begin
  817. if Aprocsym.search_procdef_bypara(pd^.def.para,false)=nil then
  818. Aprocsym.addprocdef(pd^.def);
  819. pd:=pd^.next;
  820. end;
  821. end;
  822. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  823. var pd:Pprocdeflist;
  824. begin
  825. pd:=defs;
  826. while assigned(pd) do
  827. begin
  828. s.addprocdef(pd^.def);
  829. pd:=pd^.next;
  830. end;
  831. end;
  832. function Tprocsym.first_procdef:Tprocdef;
  833. begin
  834. first_procdef:=defs^.def;
  835. end;
  836. function Tprocsym.last_procdef:Tprocdef;
  837. var pd:Pprocdeflist;
  838. begin
  839. pd:=defs;
  840. while assigned(pd) do
  841. begin
  842. last_procdef:=pd^.def;
  843. pd:=pd^.next;
  844. end;
  845. end;
  846. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  847. var p:Pprocdeflist;
  848. begin
  849. p:=defs;
  850. while assigned(p) do
  851. begin
  852. proc2call(p^.def,arg);
  853. p:=p^.next;
  854. end;
  855. end;
  856. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  857. var p:Pprocdeflist;
  858. begin
  859. search_procdef_nopara_boolret:=nil;
  860. p:=defs;
  861. while p<>nil do
  862. begin
  863. if p^.def.para.empty and is_boolean(p^.def.rettype.def) then
  864. begin
  865. search_procdef_nopara_boolret:=p^.def;
  866. break;
  867. end;
  868. p:=p^.next;
  869. end;
  870. end;
  871. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  872. var p:Pprocdeflist;
  873. begin
  874. search_procdef_bytype:=nil;
  875. p:=defs;
  876. while p<>nil do
  877. begin
  878. if p^.def.proctypeoption=pt then
  879. begin
  880. search_procdef_bytype:=p^.def;
  881. break;
  882. end;
  883. p:=p^.next;
  884. end;
  885. end;
  886. function Tprocsym.search_procdef_bypara(params:Tparalinkedlist;
  887. allowconvert: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) 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. include(varoptions,vo_is_C_var);
  1384. stringdispose(_mangledname);
  1385. _mangledname:=stringdup(mangled);
  1386. end;
  1387. constructor tvarsym.ppuload(ppufile:tcompilerppufile);
  1388. begin
  1389. inherited loadsym(ppufile);
  1390. typ:=varsym;
  1391. reg:=R_NO;
  1392. refs := 0;
  1393. varstate:=vs_used;
  1394. varspez:=tvarspez(ppufile.getbyte);
  1395. address:=ppufile.getlongint;
  1396. localvarsym:=nil;
  1397. ppufile.gettype(vartype);
  1398. ppufile.getsmallset(varoptions);
  1399. if (vo_is_C_var in varoptions) then
  1400. _mangledname:=stringdup(ppufile.getstring);
  1401. end;
  1402. destructor tvarsym.destroy;
  1403. begin
  1404. {$ifdef var_notification}
  1405. if assigned(notifications) then
  1406. notifications.destroy;
  1407. {$endif}
  1408. inherited destroy;
  1409. end;
  1410. procedure tvarsym.deref;
  1411. begin
  1412. vartype.resolve;
  1413. end;
  1414. procedure tvarsym.ppuwrite(ppufile:tcompilerppufile);
  1415. var
  1416. hvo : tvaroptions;
  1417. begin
  1418. inherited writesym(ppufile);
  1419. ppufile.putbyte(byte(varspez));
  1420. ppufile.putlongint(address);
  1421. ppufile.puttype(vartype);
  1422. { symbols which are load are never candidates for a register,
  1423. turn off the regable }
  1424. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1425. ppufile.putsmallset(hvo);
  1426. if (vo_is_C_var in varoptions) then
  1427. ppufile.putstring(mangledname);
  1428. ppufile.writeentry(ibvarsym);
  1429. end;
  1430. procedure tvarsym.generate_mangledname;
  1431. begin
  1432. _mangledname:=stringdup(mangledname_prefix('U',owner)+name);
  1433. end;
  1434. procedure tvarsym.set_mangledname(const s:string);
  1435. begin
  1436. stringdispose(_mangledname);
  1437. _mangledname:=stringdup(s);
  1438. end;
  1439. function tvarsym.getsize : longint;
  1440. begin
  1441. if assigned(vartype.def) then
  1442. getsize:=vartype.def.size
  1443. else
  1444. getsize:=0;
  1445. end;
  1446. function tvarsym.getvaluesize : longint;
  1447. begin
  1448. if assigned(vartype.def) and
  1449. (varspez=vs_value) and
  1450. ((vartype.def.deftype<>arraydef) or
  1451. tarraydef(vartype.def).isDynamicArray or
  1452. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1453. getvaluesize:=vartype.def.size
  1454. else
  1455. getvaluesize:=0;
  1456. end;
  1457. function tvarsym.getpushsize(is_cdecl:boolean) : longint;
  1458. begin
  1459. getpushsize:=-1;
  1460. if assigned(vartype.def) then
  1461. begin
  1462. case varspez of
  1463. vs_out,
  1464. vs_var :
  1465. getpushsize:=pointer_size;
  1466. vs_value,
  1467. vs_const :
  1468. begin
  1469. if paramanager.push_addr_param(vartype.def,is_cdecl) then
  1470. getpushsize:=pointer_size
  1471. else
  1472. getpushsize:=vartype.def.size;
  1473. end;
  1474. end;
  1475. end;
  1476. end;
  1477. {$ifdef var_notification}
  1478. function Tvarsym.register_notification(flags:Tnotification_flags;callback:
  1479. Tnotification_callback):cardinal;
  1480. var n:Tnotification;
  1481. begin
  1482. if not assigned(notifications) then
  1483. notifications:=Tlinkedlist.create;
  1484. n:=Tnotification.create(flags,callback);
  1485. register_notification:=n.id;
  1486. notifications.concat(n);
  1487. end;
  1488. {$endif}
  1489. {$ifdef GDB}
  1490. function tvarsym.stabstring : pchar;
  1491. var
  1492. st : string;
  1493. is_cdecl : boolean;
  1494. begin
  1495. st:=tstoreddef(vartype.def).numberstring;
  1496. if (owner.symtabletype = objectsymtable) and
  1497. (sp_static in symoptions) then
  1498. begin
  1499. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1500. stabstring := strpnew('"'+upper(owner.name^)+'__'+name+':'+st+
  1501. '",'+
  1502. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1503. end
  1504. else if (owner.symtabletype = globalsymtable) then
  1505. begin
  1506. { Here we used S instead of
  1507. because with G GDB doesn't look at the address field
  1508. but searches the same name or with a leading underscore
  1509. but these names don't exist in pascal !}
  1510. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1511. stabstring := strpnew('"'+name+':'+st+'",'+
  1512. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1513. end
  1514. else if owner.symtabletype = staticsymtable then
  1515. begin
  1516. stabstring := strpnew('"'+name+':S'+st+'",'+
  1517. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1518. end
  1519. else if (owner.symtabletype in [parasymtable,inlineparasymtable]) then
  1520. begin
  1521. is_cdecl:=(tprocdef(owner.defowner).proccalloption in [pocall_cdecl,pocall_cppdecl]);
  1522. case varspez of
  1523. vs_out,
  1524. vs_var : st := 'v'+st;
  1525. vs_value,
  1526. vs_const : if paramanager.push_addr_param(vartype.def,is_cdecl) then
  1527. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1528. else
  1529. st := 'p'+st;
  1530. end;
  1531. stabstring := strpnew('"'+name+':'+st+'",'+
  1532. tostr(N_tsym)+',0,'+tostr(fileinfo.line)+','+
  1533. tostr(address+owner.address_fixup));
  1534. {offset to ebp => will not work if the framepointer is esp
  1535. so some optimizing will make things harder to debug }
  1536. end
  1537. else if (owner.symtabletype in [localsymtable,inlinelocalsymtable]) then
  1538. if reg<>R_NO then
  1539. begin
  1540. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1541. { this is the register order for GDB}
  1542. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1543. tostr(N_RSYM)+',0,'+
  1544. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1545. end
  1546. else
  1547. { I don't know if this will work (PM) }
  1548. if (vo_is_C_var in varoptions) then
  1549. stabstring := strpnew('"'+name+':S'+st+'",'+
  1550. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1551. else
  1552. stabstring := strpnew('"'+name+':'+st+'",'+
  1553. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner.address_fixup))
  1554. else
  1555. stabstring := inherited stabstring;
  1556. end;
  1557. procedure tvarsym.concatstabto(asmlist : taasmoutput);
  1558. var stab_str : pchar;
  1559. begin
  1560. inherited concatstabto(asmlist);
  1561. if (owner.symtabletype=parasymtable) and
  1562. (reg<>R_NO) then
  1563. begin
  1564. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1565. { this is the register order for GDB}
  1566. stab_str:=strpnew('"'+name+':r'
  1567. +tstoreddef(vartype.def).numberstring+'",'+
  1568. tostr(N_RSYM)+',0,'+
  1569. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1570. asmList.concat(Tai_stabs.Create(stab_str));
  1571. end;
  1572. end;
  1573. {$endif GDB}
  1574. {****************************************************************************
  1575. TTYPEDCONSTSYM
  1576. *****************************************************************************}
  1577. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1578. begin
  1579. inherited create(n);
  1580. typ:=typedconstsym;
  1581. typedconsttype.setdef(p);
  1582. is_writable:=writable;
  1583. end;
  1584. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1585. begin
  1586. inherited create(n);
  1587. typ:=typedconstsym;
  1588. typedconsttype:=tt;
  1589. is_writable:=writable;
  1590. end;
  1591. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1592. begin
  1593. inherited loadsym(ppufile);
  1594. typ:=typedconstsym;
  1595. ppufile.gettype(typedconsttype);
  1596. is_writable:=boolean(ppufile.getbyte);
  1597. end;
  1598. destructor ttypedconstsym.destroy;
  1599. begin
  1600. inherited destroy;
  1601. end;
  1602. procedure ttypedconstsym.generate_mangledname;
  1603. begin
  1604. _mangledname:=stringdup(mangledname_prefix('TC',owner)+name);
  1605. end;
  1606. function ttypedconstsym.getsize : longint;
  1607. begin
  1608. if assigned(typedconsttype.def) then
  1609. getsize:=typedconsttype.def.size
  1610. else
  1611. getsize:=0;
  1612. end;
  1613. procedure ttypedconstsym.deref;
  1614. begin
  1615. typedconsttype.resolve;
  1616. end;
  1617. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1618. begin
  1619. inherited writesym(ppufile);
  1620. ppufile.puttype(typedconsttype);
  1621. ppufile.putbyte(byte(is_writable));
  1622. ppufile.writeentry(ibtypedconstsym);
  1623. end;
  1624. {$ifdef GDB}
  1625. function ttypedconstsym.stabstring : pchar;
  1626. var
  1627. st : char;
  1628. begin
  1629. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1630. st := 'G'
  1631. else
  1632. st := 'S';
  1633. stabstring := strpnew('"'+name+':'+st+
  1634. tstoreddef(typedconsttype.def).numberstring+'",'+tostr(n_STSYM)+',0,'+
  1635. tostr(fileinfo.line)+','+mangledname);
  1636. end;
  1637. {$endif GDB}
  1638. {****************************************************************************
  1639. TCONSTSYM
  1640. ****************************************************************************}
  1641. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt);
  1642. begin
  1643. inherited create(n);
  1644. typ:=constsym;
  1645. consttyp:=t;
  1646. valueord:=v;
  1647. valueordptr:=0;
  1648. valueptr:=nil;
  1649. ResStrIndex:=0;
  1650. consttype.reset;
  1651. len:=0;
  1652. end;
  1653. constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1654. begin
  1655. inherited create(n);
  1656. typ:=constsym;
  1657. consttyp:=t;
  1658. valueord:=v;
  1659. valueordptr:=0;
  1660. valueptr:=nil;
  1661. ResStrIndex:=0;
  1662. consttype:=tt;
  1663. len:=0;
  1664. end;
  1665. constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1666. begin
  1667. inherited create(n);
  1668. typ:=constsym;
  1669. consttyp:=t;
  1670. valueord:=0;
  1671. valueordptr:=v;
  1672. valueptr:=nil;
  1673. ResStrIndex:=0;
  1674. consttype:=tt;
  1675. len:=0;
  1676. end;
  1677. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer);
  1678. begin
  1679. inherited create(n);
  1680. typ:=constsym;
  1681. consttyp:=t;
  1682. valueord:=0;
  1683. valueordptr:=0;
  1684. valueptr:=v;
  1685. ResStrIndex:=0;
  1686. consttype.reset;
  1687. len:=0;
  1688. end;
  1689. constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1690. begin
  1691. inherited create(n);
  1692. typ:=constsym;
  1693. consttyp:=t;
  1694. valueord:=0;
  1695. valueordptr:=0;
  1696. valueptr:=v;
  1697. ResStrIndex:=0;
  1698. consttype:=tt;
  1699. len:=0;
  1700. end;
  1701. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1702. begin
  1703. inherited create(n);
  1704. typ:=constsym;
  1705. consttyp:=t;
  1706. valueord:=0;
  1707. valueordptr:=0;
  1708. valueptr:=str;
  1709. consttype.reset;
  1710. len:=l;
  1711. if t=constresourcestring then
  1712. ResStrIndex:=ResourceStrings.Register(name,pchar(valueptr),len);
  1713. end;
  1714. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1715. var
  1716. pd : pbestreal;
  1717. ps : pnormalset;
  1718. pc : pchar;
  1719. begin
  1720. inherited loadsym(ppufile);
  1721. typ:=constsym;
  1722. consttype.reset;
  1723. consttyp:=tconsttyp(ppufile.getbyte);
  1724. valueord:=0;
  1725. valueordptr:=0;
  1726. valueptr:=nil;
  1727. case consttyp of
  1728. constint:
  1729. valueord:=ppufile.getexprint;
  1730. constwchar,
  1731. constbool,
  1732. constchar :
  1733. valueord:=ppufile.getlongint;
  1734. constord :
  1735. begin
  1736. ppufile.gettype(consttype);
  1737. valueord:=ppufile.getexprint;
  1738. end;
  1739. constpointer :
  1740. begin
  1741. ppufile.gettype(consttype);
  1742. valueordptr:=ppufile.getptruint;
  1743. end;
  1744. conststring,
  1745. constresourcestring :
  1746. begin
  1747. len:=ppufile.getlongint;
  1748. getmem(pc,len+1);
  1749. ppufile.getdata(pc^,len);
  1750. if consttyp=constresourcestring then
  1751. ResStrIndex:=ppufile.getlongint;
  1752. valueptr:=pc;
  1753. end;
  1754. constreal :
  1755. begin
  1756. new(pd);
  1757. pd^:=ppufile.getreal;
  1758. valueptr:=pd;
  1759. end;
  1760. constset :
  1761. begin
  1762. ppufile.gettype(consttype);
  1763. new(ps);
  1764. ppufile.getnormalset(ps^);
  1765. valueptr:=ps;
  1766. end;
  1767. constnil : ;
  1768. else
  1769. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1770. end;
  1771. end;
  1772. destructor tconstsym.destroy;
  1773. begin
  1774. case consttyp of
  1775. conststring,
  1776. constresourcestring :
  1777. freemem(pchar(valueptr),len+1);
  1778. constreal :
  1779. dispose(pbestreal(valueptr));
  1780. constset :
  1781. dispose(pnormalset(valueptr));
  1782. end;
  1783. inherited destroy;
  1784. end;
  1785. function tconstsym.mangledname : string;
  1786. begin
  1787. mangledname:=name;
  1788. end;
  1789. procedure tconstsym.deref;
  1790. begin
  1791. if consttyp in [constord,constpointer,constset] then
  1792. consttype.resolve;
  1793. end;
  1794. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1795. begin
  1796. inherited writesym(ppufile);
  1797. ppufile.putbyte(byte(consttyp));
  1798. case consttyp of
  1799. constnil : ;
  1800. constint:
  1801. ppufile.putexprint(valueord);
  1802. constbool,
  1803. constchar :
  1804. ppufile.putlongint(valueord);
  1805. constord :
  1806. begin
  1807. ppufile.puttype(consttype);
  1808. ppufile.putexprint(valueord);
  1809. end;
  1810. constpointer :
  1811. begin
  1812. ppufile.puttype(consttype);
  1813. ppufile.putptruint(valueordptr);
  1814. end;
  1815. conststring,
  1816. constresourcestring :
  1817. begin
  1818. ppufile.putlongint(len);
  1819. ppufile.putdata(pchar(valueptr)^,len);
  1820. if consttyp=constresourcestring then
  1821. ppufile.putlongint(ResStrIndex);
  1822. end;
  1823. constreal :
  1824. ppufile.putreal(pbestreal(valueptr)^);
  1825. constset :
  1826. begin
  1827. ppufile.puttype(consttype);
  1828. ppufile.putnormalset(valueptr^);
  1829. end;
  1830. else
  1831. internalerror(13);
  1832. end;
  1833. ppufile.writeentry(ibconstsym);
  1834. end;
  1835. {$ifdef GDB}
  1836. function tconstsym.stabstring : pchar;
  1837. var st : string;
  1838. begin
  1839. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1840. case consttyp of
  1841. conststring : begin
  1842. st := 's'''+strpas(pchar(valueptr))+'''';
  1843. end;
  1844. constbool,
  1845. constint,
  1846. constord,
  1847. constchar : st := 'i'+int64tostr(valueord);
  1848. constpointer :
  1849. st := 'i'+int64tostr(valueordptr);
  1850. constreal : begin
  1851. system.str(pbestreal(valueptr)^,st);
  1852. st := 'r'+st;
  1853. end;
  1854. { if we don't know just put zero !! }
  1855. else st:='i0';
  1856. {***SETCONST}
  1857. {constset:;} {*** I don't know what to do with a set.}
  1858. { sets are not recognized by GDB}
  1859. {***}
  1860. end;
  1861. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1862. tostr(fileinfo.line)+',0');
  1863. end;
  1864. procedure tconstsym.concatstabto(asmlist : taasmoutput);
  1865. begin
  1866. if consttyp <> conststring then
  1867. inherited concatstabto(asmlist);
  1868. end;
  1869. {$endif GDB}
  1870. {****************************************************************************
  1871. TENUMSYM
  1872. ****************************************************************************}
  1873. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1874. begin
  1875. inherited create(n);
  1876. typ:=enumsym;
  1877. definition:=def;
  1878. value:=v;
  1879. { check for jumps }
  1880. if v>def.max+1 then
  1881. def.has_jumps:=true;
  1882. { update low and high }
  1883. if def.min>v then
  1884. def.setmin(v);
  1885. if def.max<v then
  1886. def.setmax(v);
  1887. order;
  1888. end;
  1889. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1890. begin
  1891. inherited loadsym(ppufile);
  1892. typ:=enumsym;
  1893. definition:=tenumdef(ppufile.getderef);
  1894. value:=ppufile.getlongint;
  1895. nextenum := Nil;
  1896. end;
  1897. procedure tenumsym.deref;
  1898. begin
  1899. resolvedef(pointer(definition));
  1900. order;
  1901. end;
  1902. procedure tenumsym.order;
  1903. var
  1904. sym : tenumsym;
  1905. begin
  1906. sym := tenumsym(definition.firstenum);
  1907. if sym = nil then
  1908. begin
  1909. definition.firstenum := self;
  1910. nextenum := nil;
  1911. exit;
  1912. end;
  1913. { reorder the symbols in increasing value }
  1914. if value < sym.value then
  1915. begin
  1916. nextenum := sym;
  1917. definition.firstenum := self;
  1918. end
  1919. else
  1920. begin
  1921. while (sym.value <= value) and assigned(sym.nextenum) do
  1922. sym := sym.nextenum;
  1923. nextenum := sym.nextenum;
  1924. sym.nextenum := self;
  1925. end;
  1926. end;
  1927. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1928. begin
  1929. inherited writesym(ppufile);
  1930. ppufile.putderef(definition);
  1931. ppufile.putlongint(value);
  1932. ppufile.writeentry(ibenumsym);
  1933. end;
  1934. {$ifdef GDB}
  1935. procedure tenumsym.concatstabto(asmlist : taasmoutput);
  1936. begin
  1937. {enum elements have no stab !}
  1938. end;
  1939. {$EndIf GDB}
  1940. {****************************************************************************
  1941. TTYPESYM
  1942. ****************************************************************************}
  1943. constructor ttypesym.create(const n : string;const tt : ttype);
  1944. begin
  1945. inherited create(n);
  1946. typ:=typesym;
  1947. restype:=tt;
  1948. {$ifdef GDB}
  1949. isusedinstab := false;
  1950. {$endif GDB}
  1951. { register the typesym for the definition }
  1952. if assigned(restype.def) and
  1953. (restype.def.deftype<>errordef) and
  1954. not(assigned(restype.def.typesym)) then
  1955. restype.def.typesym:=self;
  1956. end;
  1957. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1958. begin
  1959. inherited loadsym(ppufile);
  1960. typ:=typesym;
  1961. {$ifdef GDB}
  1962. isusedinstab := false;
  1963. {$endif GDB}
  1964. ppufile.gettype(restype);
  1965. end;
  1966. function ttypesym.gettypedef:tdef;
  1967. begin
  1968. gettypedef:=restype.def;
  1969. end;
  1970. procedure ttypesym.deref;
  1971. begin
  1972. restype.resolve;
  1973. end;
  1974. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1975. begin
  1976. inherited writesym(ppufile);
  1977. ppufile.puttype(restype);
  1978. ppufile.writeentry(ibtypesym);
  1979. end;
  1980. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1981. begin
  1982. inherited load_references(ppufile,locals);
  1983. if (restype.def.deftype=recorddef) then
  1984. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1985. if (restype.def.deftype=objectdef) then
  1986. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1987. end;
  1988. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1989. begin
  1990. if not inherited write_references(ppufile,locals) then
  1991. begin
  1992. { write address of this symbol if record or object
  1993. even if no real refs are there
  1994. because we need it for the symtable }
  1995. if (restype.def.deftype in [recorddef,objectdef]) then
  1996. begin
  1997. ppufile.putderef(self);
  1998. ppufile.writeentry(ibsymref);
  1999. end;
  2000. end;
  2001. write_references:=true;
  2002. if (restype.def.deftype=recorddef) then
  2003. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  2004. if (restype.def.deftype=objectdef) then
  2005. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  2006. end;
  2007. {$ifdef GDB}
  2008. function ttypesym.stabstring : pchar;
  2009. var
  2010. stabchar : string[2];
  2011. short : string;
  2012. begin
  2013. if restype.def.deftype in tagtypes then
  2014. stabchar := 'Tt'
  2015. else
  2016. stabchar := 't';
  2017. short := '"'+name+':'+stabchar+tstoreddef(restype.def).numberstring
  2018. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  2019. stabstring := strpnew(short);
  2020. end;
  2021. procedure ttypesym.concatstabto(asmlist : taasmoutput);
  2022. begin
  2023. {not stabs for forward defs }
  2024. if assigned(restype.def) then
  2025. if (restype.def.typesym = self) then
  2026. tstoreddef(restype.def).concatstabto(asmlist)
  2027. else
  2028. inherited concatstabto(asmlist);
  2029. end;
  2030. {$endif GDB}
  2031. {****************************************************************************
  2032. TSYSSYM
  2033. ****************************************************************************}
  2034. constructor tsyssym.create(const n : string;l : longint);
  2035. begin
  2036. inherited create(n);
  2037. typ:=syssym;
  2038. number:=l;
  2039. end;
  2040. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2041. begin
  2042. inherited loadsym(ppufile);
  2043. typ:=syssym;
  2044. number:=ppufile.getlongint;
  2045. end;
  2046. destructor tsyssym.destroy;
  2047. begin
  2048. inherited destroy;
  2049. end;
  2050. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2051. begin
  2052. inherited writesym(ppufile);
  2053. ppufile.putlongint(number);
  2054. ppufile.writeentry(ibsyssym);
  2055. end;
  2056. {$ifdef GDB}
  2057. procedure tsyssym.concatstabto(asmlist : taasmoutput);
  2058. begin
  2059. end;
  2060. {$endif GDB}
  2061. {****************************************************************************
  2062. TRTTISYM
  2063. ****************************************************************************}
  2064. constructor trttisym.create(const n:string;rt:trttitype);
  2065. const
  2066. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2067. begin
  2068. inherited create(prefix[rt]+n);
  2069. typ:=rttisym;
  2070. lab:=nil;
  2071. rttityp:=rt;
  2072. end;
  2073. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2074. begin
  2075. inherited loadsym(ppufile);
  2076. typ:=rttisym;
  2077. lab:=nil;
  2078. rttityp:=trttitype(ppufile.getbyte);
  2079. end;
  2080. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2081. begin
  2082. inherited writesym(ppufile);
  2083. ppufile.putbyte(byte(rttityp));
  2084. ppufile.writeentry(ibrttisym);
  2085. end;
  2086. function trttisym.mangledname : string;
  2087. const
  2088. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2089. var
  2090. s : string;
  2091. p : tsymtable;
  2092. begin
  2093. s:='';
  2094. p:=owner;
  2095. while assigned(p) and (p.symtabletype=localsymtable) do
  2096. begin
  2097. s:=s+'_'+p.defowner.name;
  2098. p:=p.defowner.owner;
  2099. end;
  2100. if not(p.symtabletype in [globalsymtable,staticsymtable]) then
  2101. internalerror(200108265);
  2102. mangledname:=prefix[rttityp]+p.name^+s+'$_'+Copy(name,5,255);
  2103. end;
  2104. function trttisym.get_label:tasmsymbol;
  2105. begin
  2106. { the label is always a global label }
  2107. if not assigned(lab) then
  2108. lab:=objectlibrary.newasmsymboltype(mangledname,AB_GLOBAL,AT_DATA);
  2109. get_label:=lab;
  2110. end;
  2111. { persistent rtti generation }
  2112. procedure generate_rtti(p:tsym);
  2113. var
  2114. rsym : trttisym;
  2115. def : tstoreddef;
  2116. begin
  2117. { rtti can only be generated for classes that are always typesyms }
  2118. if not(p.typ=typesym) then
  2119. internalerror(200108261);
  2120. def:=tstoreddef(ttypesym(p).restype.def);
  2121. { only create rtti once for each definition }
  2122. if not(df_has_rttitable in def.defoptions) then
  2123. begin
  2124. { definition should be in the same symtable as the symbol }
  2125. if p.owner<>def.owner then
  2126. internalerror(200108262);
  2127. { create rttisym }
  2128. rsym:=trttisym.create(p.name,fullrtti);
  2129. p.owner.insert(rsym);
  2130. { register rttisym in definition }
  2131. include(def.defoptions,df_has_rttitable);
  2132. def.rttitablesym:=rsym;
  2133. { write rtti data }
  2134. def.write_child_rtti_data(fullrtti);
  2135. if (cs_create_smart in aktmoduleswitches) then
  2136. rttiList.concat(Tai_cut.Create);
  2137. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2138. def.write_rtti_data(fullrtti);
  2139. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2140. end;
  2141. end;
  2142. { persistent init table generation }
  2143. procedure generate_inittable(p:tsym);
  2144. var
  2145. rsym : trttisym;
  2146. def : tstoreddef;
  2147. begin
  2148. { anonymous types are also allowed for records that can be varsym }
  2149. case p.typ of
  2150. typesym :
  2151. def:=tstoreddef(ttypesym(p).restype.def);
  2152. varsym :
  2153. def:=tstoreddef(tvarsym(p).vartype.def);
  2154. else
  2155. internalerror(200108263);
  2156. end;
  2157. { only create inittable once for each definition }
  2158. if not(df_has_inittable in def.defoptions) then
  2159. begin
  2160. { definition should be in the same symtable as the symbol }
  2161. if p.owner<>def.owner then
  2162. internalerror(200108264);
  2163. { create rttisym }
  2164. rsym:=trttisym.create(p.name,initrtti);
  2165. p.owner.insert(rsym);
  2166. { register rttisym in definition }
  2167. include(def.defoptions,df_has_inittable);
  2168. def.inittablesym:=rsym;
  2169. { write inittable data }
  2170. def.write_child_rtti_data(initrtti);
  2171. if (cs_create_smart in aktmoduleswitches) then
  2172. rttiList.concat(Tai_cut.Create);
  2173. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2174. def.write_rtti_data(initrtti);
  2175. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2176. end;
  2177. end;
  2178. end.
  2179. {
  2180. $Log$
  2181. Revision 1.64 2002-09-08 11:10:17 carl
  2182. * bugfix 2109 (bad imho, but only way)
  2183. Revision 1.63 2002/09/07 18:17:41 florian
  2184. + tvarsym.paraitem added
  2185. Revision 1.62 2002/09/07 15:25:10 peter
  2186. * old logs removed and tabs fixed
  2187. Revision 1.61 2002/09/05 19:29:45 peter
  2188. * memdebug enhancements
  2189. Revision 1.60 2002/09/05 14:51:42 peter
  2190. * internalerror instead of crash in getprocdef
  2191. Revision 1.59 2002/09/03 16:26:27 daniel
  2192. * Make Tprocdef.defs protected
  2193. Revision 1.58 2002/09/01 08:01:16 daniel
  2194. * Removed sets from Tcallnode.det_resulttype
  2195. + Added read/write notifications of variables. These will be usefull
  2196. for providing information for several optimizations. For example
  2197. the value of the loop variable of a for loop does matter is the
  2198. variable is read after the for loop, but if it's no longer used
  2199. or written, it doesn't matter and this can be used to optimize
  2200. the loop code generation.
  2201. Revision 1.57 2002/08/25 19:25:21 peter
  2202. * sym.insert_in_data removed
  2203. * symtable.insertvardata/insertconstdata added
  2204. * removed insert_in_data call from symtable.insert, it needs to be
  2205. called separatly. This allows to deref the address calculation
  2206. * procedures now calculate the parast addresses after the procedure
  2207. directives are parsed. This fixes the cdecl parast problem
  2208. * push_addr_param has an extra argument that specifies if cdecl is used
  2209. or not
  2210. Revision 1.56 2002/08/25 09:06:21 peter
  2211. * fixed loop in concat_procdefs
  2212. Revision 1.55 2002/08/20 16:54:40 peter
  2213. * write address of varsym always
  2214. Revision 1.54 2002/08/20 10:31:26 daniel
  2215. * Tcallnode.det_resulttype rewritten
  2216. Revision 1.53 2002/08/18 20:06:27 peter
  2217. * inlining is now also allowed in interface
  2218. * renamed write/load to ppuwrite/ppuload
  2219. * tnode storing in ppu
  2220. * nld,ncon,nbas are already updated for storing in ppu
  2221. Revision 1.52 2002/08/17 09:23:42 florian
  2222. * first part of procinfo rewrite
  2223. Revision 1.51 2002/08/16 14:24:59 carl
  2224. * issameref() to test if two references are the same (then emit no opcodes)
  2225. + ret_in_reg to replace ret_in_acc
  2226. (fix some register allocation bugs at the same time)
  2227. + save_std_register now has an extra parameter which is the
  2228. usedinproc registers
  2229. Revision 1.50 2002/08/13 21:40:57 florian
  2230. * more fixes for ppc calling conventions
  2231. Revision 1.49 2002/08/12 15:08:40 carl
  2232. + stab register indexes for powerpc (moved from gdb to cpubase)
  2233. + tprocessor enumeration moved to cpuinfo
  2234. + linker in target_info is now a class
  2235. * many many updates for m68k (will soon start to compile)
  2236. - removed some ifdef or correct them for correct cpu
  2237. Revision 1.48 2002/08/11 14:32:28 peter
  2238. * renamed current_library to objectlibrary
  2239. Revision 1.47 2002/08/11 13:24:14 peter
  2240. * saving of asmsymbols in ppu supported
  2241. * asmsymbollist global is removed and moved into a new class
  2242. tasmlibrarydata that will hold the info of a .a file which
  2243. corresponds with a single module. Added librarydata to tmodule
  2244. to keep the library info stored for the module. In the future the
  2245. objectfiles will also be stored to the tasmlibrarydata class
  2246. * all getlabel/newasmsymbol and friends are moved to the new class
  2247. Revision 1.46 2002/07/23 10:13:23 daniel
  2248. * Added important comment
  2249. Revision 1.45 2002/07/23 09:51:26 daniel
  2250. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2251. are worth comitting.
  2252. Revision 1.44 2002/07/20 17:45:29 daniel
  2253. * Register variables are now possible for global variables too. This is
  2254. important for small programs without procedures.
  2255. Revision 1.43 2002/07/20 11:57:58 florian
  2256. * types.pas renamed to defbase.pas because D6 contains a types
  2257. unit so this would conflicts if D6 programms are compiled
  2258. + Willamette/SSE2 instructions to assembler added
  2259. Revision 1.42 2002/07/11 14:41:31 florian
  2260. * start of the new generic parameter handling
  2261. }