symsym.pas 95 KB

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