symsym.pas 94 KB

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