symsym.pas 93 KB

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