symsym.pas 92 KB

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