symsym.pas 92 KB

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