symsym.pas 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. Implementation for the symbols types of the symtable
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symsym;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,
  23. { target }
  24. globtype,globals,widestr,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,symdef,defcmp,
  27. { ppu }
  28. ppu,finput,
  29. cclasses,symnot,
  30. { aasm }
  31. aasmbase,
  32. cpuinfo,cpubase,cgbase,cgutils,parabase
  33. ;
  34. type
  35. { this class is the base for all symbol objects }
  36. tstoredsym = class(tsym)
  37. public
  38. constructor create(st:tsymtyp;const n : string);
  39. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  40. destructor destroy;override;
  41. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  42. end;
  43. tlabelsym = class(tstoredsym)
  44. used,
  45. defined,
  46. nonlocal : boolean;
  47. { points to the matching node, only valid resultdef pass is run and
  48. the goto<->label relation in the node tree is created, should
  49. be a tnode }
  50. code : pointer;
  51. { points to the jump buffer }
  52. jumpbuf : tstoredsym;
  53. { when the label is defined in an asm block, this points to the
  54. generated asmlabel }
  55. asmblocklabel : tasmlabel;
  56. constructor create(const n : string);
  57. constructor ppuload(ppufile:tcompilerppufile);
  58. procedure ppuwrite(ppufile:tcompilerppufile);override;
  59. function mangledname:TSymStr;override;
  60. end;
  61. tunitsym = class(Tstoredsym)
  62. module : tobject; { tmodule }
  63. constructor create(const n : string;amodule : tobject);
  64. constructor ppuload(ppufile:tcompilerppufile);
  65. destructor destroy;override;
  66. procedure ppuwrite(ppufile:tcompilerppufile);override;
  67. end;
  68. tnamespacesym = class(Tstoredsym)
  69. unitsym:tsym;
  70. unitsymderef:tderef;
  71. constructor create(const n : string);
  72. constructor ppuload(ppufile:tcompilerppufile);
  73. procedure ppuwrite(ppufile:tcompilerppufile);override;
  74. procedure buildderef;override;
  75. procedure deref;override;
  76. end;
  77. terrorsym = class(Tsym)
  78. constructor create;
  79. end;
  80. { tprocsym }
  81. tprocsym = class(tstoredsym)
  82. protected
  83. FProcdefList : TFPObjectList;
  84. FProcdefDerefList : TFPList;
  85. public
  86. constructor create(const n : string);
  87. constructor ppuload(ppufile:tcompilerppufile);
  88. destructor destroy;override;
  89. { writes all declarations except the specified one }
  90. procedure write_parameter_lists(skipdef:tprocdef);
  91. { tests, if all procedures definitions are defined and not }
  92. { only forward }
  93. procedure check_forward;
  94. procedure ppuwrite(ppufile:tcompilerppufile);override;
  95. procedure buildderef;override;
  96. procedure deref;override;
  97. function find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  98. function find_bytype_parameterless(pt:Tproctypeoption):Tprocdef;
  99. function find_procdef_bypara(para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  100. function find_procdef_bytype_and_para(pt:Tproctypeoption;para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  101. function find_procdef_byoptions(ops:tprocoptions): Tprocdef;
  102. function find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  103. function find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  104. function find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  105. property ProcdefList:TFPObjectList read FProcdefList;
  106. end;
  107. ttypesym = class(Tstoredsym)
  108. public
  109. typedef : tdef;
  110. typedefderef : tderef;
  111. fprettyname : ansistring;
  112. constructor create(const n : string;def:tdef);
  113. destructor destroy;override;
  114. constructor ppuload(ppufile:tcompilerppufile);
  115. procedure ppuwrite(ppufile:tcompilerppufile);override;
  116. procedure buildderef;override;
  117. procedure deref;override;
  118. function prettyname : string;override;
  119. end;
  120. tabstractvarsym = class(tstoredsym)
  121. varoptions : tvaroptions;
  122. notifications : Tlinkedlist;
  123. varspez : tvarspez; { sets the type of access }
  124. varregable : tvarregable;
  125. varstate : tvarstate;
  126. { Has the address of this variable potentially escaped the }
  127. { block in which is was declared? }
  128. { could also be part of tabstractnormalvarsym, but there's }
  129. { one byte left here till the next 4 byte alignment }
  130. addr_taken : boolean;
  131. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  132. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  133. destructor destroy;override;
  134. procedure ppuwrite(ppufile:tcompilerppufile);override;
  135. procedure buildderef;override;
  136. procedure deref;override;
  137. function getsize : asizeint;
  138. function getpackedbitsize : longint;
  139. function is_regvar(refpara: boolean):boolean;
  140. procedure trigger_notifications(what:Tnotification_flag);
  141. function register_notification(flags:Tnotification_flags;
  142. callback:Tnotification_callback):cardinal;
  143. procedure unregister_notification(id:cardinal);
  144. private
  145. _vardef : tdef;
  146. vardefderef : tderef;
  147. procedure setvardef(def:tdef);
  148. public
  149. property vardef: tdef read _vardef write setvardef;
  150. end;
  151. tfieldvarsym = class(tabstractvarsym)
  152. { offset in record/object, for bitpacked fields the offset is
  153. given in bit, else in bytes }
  154. fieldoffset : asizeint;
  155. externalname : pshortstring;
  156. {$ifdef symansistr}
  157. cachedmangledname: TSymStr; { mangled name for ObjC or Java }
  158. {$else symansistr}
  159. cachedmangledname: pshortstring; { mangled name for ObjC or Java }
  160. {$endif symansistr}
  161. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  162. constructor ppuload(ppufile:tcompilerppufile);
  163. procedure ppuwrite(ppufile:tcompilerppufile);override;
  164. procedure set_externalname(const s:string);
  165. function mangledname:TSymStr;override;
  166. destructor destroy;override;
  167. end;
  168. tabstractnormalvarsym = class(tabstractvarsym)
  169. defaultconstsym : tsym;
  170. defaultconstsymderef : tderef;
  171. localloc : TLocation; { register/reference for local var }
  172. initialloc : TLocation; { initial location so it can still be initialized later after the location was changed by SSA }
  173. currentregloc : TLocation; { current registers for register variables with moving register numbers }
  174. inparentfpstruct : boolean; { migrated to a parentfpstruct because of nested access (not written to ppu, because not important and would change interface crc) }
  175. constructor create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  176. constructor ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  177. function globalasmsym: boolean;
  178. procedure ppuwrite(ppufile:tcompilerppufile);override;
  179. procedure buildderef;override;
  180. procedure deref;override;
  181. end;
  182. tlocalvarsym = class(tabstractnormalvarsym)
  183. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  184. constructor ppuload(ppufile:tcompilerppufile);
  185. procedure ppuwrite(ppufile:tcompilerppufile);override;
  186. end;
  187. tparavarsym = class(tabstractnormalvarsym)
  188. paraloc : array[tcallercallee] of TCGPara;
  189. paranr : word; { position of this parameter }
  190. { in MacPas mode, "univ" parameters mean that type checking should
  191. be disabled, except that the size of the passed parameter must
  192. match the size of the formal parameter }
  193. univpara : boolean;
  194. {$ifdef EXTDEBUG}
  195. eqval : tequaltype;
  196. {$endif EXTDEBUG}
  197. constructor create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  198. constructor ppuload(ppufile:tcompilerppufile);
  199. destructor destroy;override;
  200. procedure ppuwrite(ppufile:tcompilerppufile);override;
  201. function needs_finalization: boolean;
  202. end;
  203. tstaticvarsym = class(tabstractnormalvarsym)
  204. private
  205. {$ifdef symansistr}
  206. _mangledbasename,
  207. _mangledname : TSymStr;
  208. {$else symansistr}
  209. _mangledbasename,
  210. _mangledname : pshortstring;
  211. {$endif symansistr}
  212. public
  213. section : ansistring;
  214. constructor create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  215. constructor create_dll(const n : string;vsp:tvarspez;def:tdef);
  216. constructor create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  217. constructor ppuload(ppufile:tcompilerppufile);
  218. destructor destroy;override;
  219. procedure ppuwrite(ppufile:tcompilerppufile);override;
  220. function mangledname:TSymStr;override;
  221. procedure set_mangledbasename(const s: TSymStr);
  222. function mangledbasename: TSymStr;
  223. procedure set_mangledname(const s:TSymStr);
  224. procedure set_raw_mangledname(const s:TSymStr);
  225. end;
  226. tabsolutevarsym = class(tabstractvarsym)
  227. public
  228. abstyp : absolutetyp;
  229. {$if defined(i386) or defined(i8086)}
  230. absseg : boolean;
  231. {$endif defined(i386) or defined(i8086)}
  232. asmname : pshortstring;
  233. addroffset : aword;
  234. {$if defined(i8086)}
  235. addrsegment : aword;
  236. {$endif defined(i8086)}
  237. ref : tpropaccesslist;
  238. constructor create(const n : string;def:tdef);
  239. constructor create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  240. destructor destroy;override;
  241. constructor ppuload(ppufile:tcompilerppufile);
  242. procedure buildderef;override;
  243. procedure deref;override;
  244. function mangledname : TSymStr;override;
  245. procedure ppuwrite(ppufile:tcompilerppufile);override;
  246. end;
  247. tpropaccesslisttypes=(palt_none,palt_read,palt_write,palt_stored);
  248. tpropertysym = class(Tstoredsym)
  249. propoptions : tpropertyoptions;
  250. overriddenpropsym : tpropertysym;
  251. overriddenpropsymderef : tderef;
  252. propdef : tdef;
  253. propdefderef : tderef;
  254. indexdef : tdef;
  255. indexdefderef : tderef;
  256. index,
  257. default : longint;
  258. dispid : longint;
  259. propaccesslist: array[tpropaccesslisttypes] of tpropaccesslist;
  260. parast : tsymtable;
  261. constructor create(const n : string);
  262. destructor destroy;override;
  263. constructor ppuload(ppufile:tcompilerppufile);
  264. function getsize : asizeint;
  265. procedure ppuwrite(ppufile:tcompilerppufile);override;
  266. procedure buildderef;override;
  267. procedure deref;override;
  268. function getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  269. { copies the settings of the current propertysym to p; a bit like
  270. a form of getcopy, but without the name }
  271. procedure makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  272. procedure add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  273. procedure add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  274. end;
  275. tconstvalue = record
  276. case integer of
  277. 0: (valueord : tconstexprint);
  278. 1: (valueordptr : tconstptruint);
  279. 2: (valueptr : pointer; len : longint);
  280. end;
  281. tconstsym = class(tstoredsym)
  282. constdef : tdef;
  283. constdefderef : tderef;
  284. consttyp : tconsttyp;
  285. value : tconstvalue;
  286. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  287. constructor create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  288. constructor create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  289. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint;def:tdef);
  290. constructor create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  291. constructor ppuload(ppufile:tcompilerppufile);
  292. destructor destroy;override;
  293. procedure buildderef;override;
  294. procedure deref;override;
  295. procedure ppuwrite(ppufile:tcompilerppufile);override;
  296. end;
  297. tenumsym = class(Tstoredsym)
  298. value : longint;
  299. definition : tenumdef;
  300. definitionderef : tderef;
  301. constructor create(const n : string;def : tenumdef;v : longint);
  302. constructor ppuload(ppufile:tcompilerppufile);
  303. procedure ppuwrite(ppufile:tcompilerppufile);override;
  304. procedure buildderef;override;
  305. procedure deref;override;
  306. end;
  307. tsyssym = class(Tstoredsym)
  308. number : longint;
  309. constructor create(const n : string;l : longint);
  310. constructor ppuload(ppufile:tcompilerppufile);
  311. destructor destroy;override;
  312. procedure ppuwrite(ppufile:tcompilerppufile);override;
  313. end;
  314. const
  315. maxmacrolen=16*1024;
  316. type
  317. pmacrobuffer = ^tmacrobuffer;
  318. tmacrobuffer = array[0..maxmacrolen-1] of char;
  319. tmacro = class(tstoredsym)
  320. {Normally true, but false when a previously defined macro is undef-ed}
  321. defined : boolean;
  322. {True if this is a mac style compiler variable, in which case no macro
  323. substitutions shall be done.}
  324. is_compiler_var : boolean;
  325. {Whether the macro was used. NOTE: A use of a macro which was never defined}
  326. {e. g. an IFDEF which returns false, will not be registered as used,}
  327. {since there is no place to register its use. }
  328. is_used : boolean;
  329. buftext : pchar;
  330. buflen : longint;
  331. constructor create(const n : string);
  332. constructor ppuload(ppufile:tcompilerppufile);
  333. procedure ppuwrite(ppufile:tcompilerppufile);override;
  334. destructor destroy;override;
  335. function GetCopy:tmacro;
  336. end;
  337. var
  338. generrorsym : tsym;
  339. { generate internal static field name based on regular field name }
  340. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  341. function get_high_value_sym(vs: tparavarsym):tsym; { marking it as inline causes IE 200311075 during loading from ppu file }
  342. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  343. implementation
  344. uses
  345. { global }
  346. verbose,
  347. { target }
  348. systems,
  349. { symtable }
  350. defutil,symtable,
  351. {$ifdef jvm}
  352. jvmdef,
  353. {$endif}
  354. fmodule,
  355. { tree }
  356. node,
  357. { aasm }
  358. aasmtai,aasmdata,
  359. { codegen }
  360. paramgr,
  361. procinfo
  362. ;
  363. {****************************************************************************
  364. Helpers
  365. ****************************************************************************}
  366. function internal_static_field_name(const fieldname: TSymStr): TSymStr;
  367. begin
  368. result:='$_static_'+fieldname;
  369. end;
  370. function get_high_value_sym(vs: tparavarsym):tsym;
  371. begin
  372. result := tsym(vs.owner.Find('high'+vs.name));
  373. end;
  374. procedure check_hints(const srsym: tsym; const symoptions: tsymoptions; const deprecatedmsg : pshortstring);
  375. begin
  376. if not assigned(srsym) then
  377. internalerror(200602051);
  378. if sp_hint_deprecated in symoptions then
  379. if (sp_has_deprecated_msg in symoptions) and (deprecatedmsg <> nil) then
  380. Message2(sym_w_deprecated_symbol_with_msg,srsym.realname,deprecatedmsg^)
  381. else
  382. Message1(sym_w_deprecated_symbol,srsym.realname);
  383. if sp_hint_experimental in symoptions then
  384. Message1(sym_w_experimental_symbol,srsym.realname);
  385. if sp_hint_platform in symoptions then
  386. Message1(sym_w_non_portable_symbol,srsym.realname);
  387. if sp_hint_library in symoptions then
  388. Message1(sym_w_library_symbol,srsym.realname);
  389. if sp_hint_unimplemented in symoptions then
  390. Message1(sym_w_non_implemented_symbol,srsym.realname);
  391. end;
  392. {****************************************************************************
  393. TSYM (base for all symtypes)
  394. ****************************************************************************}
  395. constructor tstoredsym.create(st:tsymtyp;const n : string);
  396. begin
  397. inherited create(st,n);
  398. { Register in current_module }
  399. if assigned(current_module) then
  400. begin
  401. current_module.symlist.Add(self);
  402. SymId:=current_module.symlist.Count-1;
  403. end;
  404. end;
  405. constructor tstoredsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  406. begin
  407. SymId:=ppufile.getlongint;
  408. inherited Create(st,ppufile.getstring);
  409. { Register symbol }
  410. current_module.symlist[SymId]:=self;
  411. ppufile.getposinfo(fileinfo);
  412. visibility:=tvisibility(ppufile.getbyte);
  413. ppufile.getsmallset(symoptions);
  414. if sp_has_deprecated_msg in symoptions then
  415. deprecatedmsg:=stringdup(ppufile.getstring)
  416. else
  417. deprecatedmsg:=nil;
  418. end;
  419. procedure tstoredsym.ppuwrite(ppufile:tcompilerppufile);
  420. var
  421. oldintfcrc : boolean;
  422. begin
  423. ppufile.putlongint(SymId);
  424. ppufile.putstring(realname);
  425. ppufile.putposinfo(fileinfo);
  426. ppufile.putbyte(byte(visibility));
  427. { symoptions can differ between interface and implementation, except
  428. for overload (this is checked in pdecsub.proc_add_definition() )
  429. These differences can lead to compiler crashes, so ignore them.
  430. This does mean that changing e.g. the "deprecated" state of a symbol
  431. by itself will not trigger a recompilation of dependent units.
  432. }
  433. oldintfcrc:=ppufile.do_interface_crc;
  434. ppufile.do_interface_crc:=false;
  435. ppufile.putsmallset(symoptions);
  436. if sp_has_deprecated_msg in symoptions then
  437. ppufile.putstring(deprecatedmsg^);
  438. ppufile.do_interface_crc:=oldintfcrc;
  439. end;
  440. destructor tstoredsym.destroy;
  441. begin
  442. inherited destroy;
  443. end;
  444. {****************************************************************************
  445. TLABELSYM
  446. ****************************************************************************}
  447. constructor tlabelsym.create(const n : string);
  448. begin
  449. inherited create(labelsym,n);
  450. used:=false;
  451. defined:=false;
  452. nonlocal:=false;
  453. code:=nil;
  454. end;
  455. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  456. begin
  457. inherited ppuload(labelsym,ppufile);
  458. code:=nil;
  459. used:=false;
  460. nonlocal:=false;
  461. defined:=true;
  462. end;
  463. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  464. begin
  465. if owner.symtabletype=globalsymtable then
  466. Message(sym_e_ill_label_decl)
  467. else
  468. begin
  469. inherited ppuwrite(ppufile);
  470. ppufile.writeentry(iblabelsym);
  471. end;
  472. end;
  473. function tlabelsym.mangledname:TSymStr;
  474. begin
  475. if not(defined) then
  476. begin
  477. defined:=true;
  478. if nonlocal then
  479. current_asmdata.getglobaljumplabel(asmblocklabel)
  480. else
  481. current_asmdata.getjumplabel(asmblocklabel);
  482. end;
  483. result:=asmblocklabel.name;
  484. end;
  485. {****************************************************************************
  486. TUNITSYM
  487. ****************************************************************************}
  488. constructor tunitsym.create(const n : string;amodule : tobject);
  489. begin
  490. inherited create(unitsym,n);
  491. module:=amodule;
  492. end;
  493. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  494. begin
  495. inherited ppuload(unitsym,ppufile);
  496. module:=nil;
  497. end;
  498. destructor tunitsym.destroy;
  499. begin
  500. inherited destroy;
  501. end;
  502. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  503. begin
  504. inherited ppuwrite(ppufile);
  505. ppufile.writeentry(ibunitsym);
  506. end;
  507. {****************************************************************************
  508. TNAMESPACESYM
  509. ****************************************************************************}
  510. constructor tnamespacesym.create(const n : string);
  511. begin
  512. inherited create(namespacesym,n);
  513. unitsym:=nil;
  514. end;
  515. constructor tnamespacesym.ppuload(ppufile:tcompilerppufile);
  516. begin
  517. inherited ppuload(namespacesym,ppufile);
  518. ppufile.getderef(unitsymderef);
  519. end;
  520. procedure tnamespacesym.ppuwrite(ppufile:tcompilerppufile);
  521. begin
  522. inherited ppuwrite(ppufile);
  523. ppufile.putderef(unitsymderef);
  524. ppufile.writeentry(ibnamespacesym);
  525. end;
  526. procedure tnamespacesym.buildderef;
  527. begin
  528. inherited buildderef;
  529. unitsymderef.build(unitsym);
  530. end;
  531. procedure tnamespacesym.deref;
  532. begin
  533. inherited deref;
  534. unitsym:=tsym(unitsymderef.resolve);
  535. end;
  536. {****************************************************************************
  537. TPROCSYM
  538. ****************************************************************************}
  539. constructor tprocsym.create(const n : string);
  540. var
  541. i: longint;
  542. begin
  543. if not(ts_lowercase_proc_start in current_settings.targetswitches) or
  544. (n='') then
  545. inherited create(procsym,n)
  546. else
  547. begin
  548. { YToX -> yToX
  549. RC64Encode -> rc64Encode
  550. Test -> test
  551. }
  552. i:=2;
  553. while i<=length(n) do
  554. begin
  555. if not(n[i] in ['A'..'Z']) then
  556. begin
  557. if (i>2) and
  558. (n[i] in ['a'..'z']) then
  559. dec(i);
  560. break;
  561. end;
  562. inc(i);
  563. end;
  564. inherited create(procsym,lower(copy(n,1,i-1))+copy(n,i,length(n)));
  565. end;
  566. FProcdefList:=TFPObjectList.Create(false);
  567. FProcdefderefList:=nil;
  568. { the tprocdef have their own symoptions, make the procsym
  569. always visible }
  570. visibility:=vis_public;
  571. end;
  572. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  573. var
  574. pdderef : tderef;
  575. i,
  576. pdcnt : longint;
  577. begin
  578. inherited ppuload(procsym,ppufile);
  579. FProcdefList:=TFPObjectList.Create(false);
  580. FProcdefDerefList:=TFPList.Create;
  581. pdcnt:=ppufile.getword;
  582. for i:=1 to pdcnt do
  583. begin
  584. ppufile.getderef(pdderef);
  585. FProcdefDerefList.Add(Pointer(PtrInt(pdderef.dataidx)));
  586. end;
  587. end;
  588. destructor tprocsym.destroy;
  589. begin
  590. FProcdefList.Free;
  591. if assigned(FProcdefDerefList) then
  592. FProcdefDerefList.Free;
  593. inherited destroy;
  594. end;
  595. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  596. var
  597. i : longint;
  598. d : tderef;
  599. begin
  600. inherited ppuwrite(ppufile);
  601. if fprocdefdereflist=nil then
  602. internalerror(2013121801);
  603. ppufile.putword(FProcdefDerefList.Count);
  604. for i:=0 to FProcdefDerefList.Count-1 do
  605. begin
  606. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  607. ppufile.putderef(d);
  608. end;
  609. ppufile.writeentry(ibprocsym);
  610. end;
  611. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  612. var
  613. i : longint;
  614. pd : tprocdef;
  615. begin
  616. for i:=0 to ProcdefList.Count-1 do
  617. begin
  618. pd:=tprocdef(ProcdefList[i]);
  619. if pd<>skipdef then
  620. MessagePos1(pd.fileinfo,sym_h_param_list,pd.fullprocname(false));
  621. end;
  622. end;
  623. procedure tprocsym.check_forward;
  624. var
  625. i : longint;
  626. pd : tprocdef;
  627. begin
  628. for i:=0 to ProcdefList.Count-1 do
  629. begin
  630. pd:=tprocdef(ProcdefList[i]);
  631. if (pd.owner=owner) and (pd.forwarddef) then
  632. begin
  633. { For mode macpas. Make implicit externals (procedures declared in the interface
  634. section which do not have a counterpart in the implementation)
  635. to be an imported procedure }
  636. if (m_mac in current_settings.modeswitches) and
  637. (pd.interfacedef) then
  638. begin
  639. pd.setmangledname(target_info.CPrefix+tprocdef(pd).procsym.realname);
  640. if (not current_module.interface_only) then
  641. MessagePos1(pd.fileinfo,sym_w_forward_not_resolved,pd.fullprocname(false));
  642. end
  643. else
  644. begin
  645. MessagePos1(pd.fileinfo,sym_e_forward_not_resolved,pd.fullprocname(false));
  646. end;
  647. { Turn further error messages off }
  648. pd.forwarddef:=false;
  649. end;
  650. end;
  651. end;
  652. procedure tprocsym.buildderef;
  653. var
  654. i : longint;
  655. pd : tprocdef;
  656. d : tderef;
  657. begin
  658. if not assigned(FProcdefDerefList) then
  659. FProcdefDerefList:=TFPList.Create
  660. else
  661. FProcdefDerefList.Clear;
  662. for i:=0 to ProcdefList.Count-1 do
  663. begin
  664. pd:=tprocdef(ProcdefList[i]);
  665. { only write the proc definitions that belong
  666. to this procsym and are in the global symtable }
  667. if pd.owner=owner then
  668. begin
  669. d.build(pd);
  670. FProcdefDerefList.Add(Pointer(PtrInt(d.dataidx)));
  671. end;
  672. end;
  673. end;
  674. procedure tprocsym.deref;
  675. var
  676. i : longint;
  677. pd : tprocdef;
  678. d : tderef;
  679. begin
  680. { Clear all procdefs }
  681. ProcdefList.Clear;
  682. if not assigned(FProcdefDerefList) then
  683. internalerror(200611031);
  684. for i:=0 to FProcdefDerefList.Count-1 do
  685. begin
  686. d.dataidx:=PtrInt(FProcdefDerefList[i]);
  687. pd:=tprocdef(d.resolve);
  688. ProcdefList.Add(pd);
  689. end;
  690. end;
  691. function Tprocsym.Find_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  692. var
  693. i : longint;
  694. pd : tprocdef;
  695. begin
  696. result:=nil;
  697. for i:=0 to ProcdefList.Count-1 do
  698. begin
  699. pd:=tprocdef(ProcdefList[i]);
  700. if pd.proctypeoption=pt then
  701. begin
  702. result:=pd;
  703. exit;
  704. end;
  705. end;
  706. end;
  707. function tprocsym.find_bytype_parameterless(pt: Tproctypeoption): Tprocdef;
  708. var
  709. i,j : longint;
  710. pd : tprocdef;
  711. found : boolean;
  712. begin
  713. result:=nil;
  714. for i:=0 to ProcdefList.Count-1 do
  715. begin
  716. pd:=tprocdef(ProcdefList[i]);
  717. if (pd.proctypeoption=pt) then
  718. begin
  719. found:=true;
  720. for j:=0 to pd.paras.count-1 do
  721. begin
  722. if not(vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  723. begin
  724. found:=false;
  725. break;
  726. end;
  727. end;
  728. if found then
  729. begin
  730. result:=pd;
  731. exit;
  732. end;
  733. end;
  734. end;
  735. end;
  736. function check_procdef_paras(pd:tprocdef;para:TFPObjectList;retdef:tdef;
  737. cpoptions:tcompare_paras_options): tprocdef;
  738. var
  739. eq: tequaltype;
  740. begin
  741. result:=nil;
  742. if assigned(retdef) then
  743. eq:=compare_defs(retdef,pd.returndef,nothingn)
  744. else
  745. eq:=te_equal;
  746. if (eq>=te_equal) or
  747. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  748. begin
  749. eq:=compare_paras(para,pd.paras,cp_value_equal_const,cpoptions);
  750. if (eq>=te_equal) or
  751. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  752. begin
  753. result:=pd;
  754. exit;
  755. end;
  756. end;
  757. end;
  758. function Tprocsym.Find_procdef_bypara(para:TFPObjectList;retdef:tdef;
  759. cpoptions:tcompare_paras_options):Tprocdef;
  760. var
  761. i : longint;
  762. pd : tprocdef;
  763. begin
  764. result:=nil;
  765. for i:=0 to ProcdefList.Count-1 do
  766. begin
  767. pd:=tprocdef(ProcdefList[i]);
  768. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  769. if assigned(result) then
  770. exit;
  771. end;
  772. end;
  773. function Tprocsym.find_procdef_bytype_and_para(pt:Tproctypeoption;
  774. para:TFPObjectList;retdef:tdef;cpoptions:tcompare_paras_options):Tprocdef;
  775. var
  776. i : longint;
  777. pd : tprocdef;
  778. begin
  779. result:=nil;
  780. for i:=0 to ProcdefList.Count-1 do
  781. begin
  782. pd:=tprocdef(ProcdefList[i]);
  783. if pd.proctypeoption=pt then
  784. begin
  785. result:=check_procdef_paras(pd,para,retdef,cpoptions);
  786. if assigned(result) then
  787. exit;
  788. end;
  789. end;
  790. end;
  791. function tprocsym.find_procdef_byoptions(ops: tprocoptions): Tprocdef;
  792. var
  793. i : longint;
  794. pd : tprocdef;
  795. begin
  796. result:=nil;
  797. for i:=0 to ProcdefList.Count-1 do
  798. begin
  799. pd:=tprocdef(ProcdefList[i]);
  800. if ops * pd.procoptions = ops then
  801. begin
  802. result:=pd;
  803. exit;
  804. end;
  805. end;
  806. end;
  807. function Tprocsym.Find_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  808. var
  809. i : longint;
  810. bestpd,
  811. pd : tprocdef;
  812. eq,besteq : tequaltype;
  813. sym: tsym;
  814. ps: tprocsym;
  815. begin
  816. { This function will return the pprocdef of pprocsym that
  817. is the best match for procvardef. When there are multiple
  818. matches it returns nil.}
  819. result:=nil;
  820. bestpd:=nil;
  821. besteq:=te_incompatible;
  822. ps:=self;
  823. repeat
  824. for i:=0 to ps.ProcdefList.Count-1 do
  825. begin
  826. pd:=tprocdef(ps.ProcdefList[i]);
  827. eq:=proc_to_procvar_equal(pd,d,false);
  828. if eq>=te_convert_l1 then
  829. begin
  830. { multiple procvars with the same equal level }
  831. if assigned(bestpd) and
  832. (besteq=eq) then
  833. exit;
  834. if eq>besteq then
  835. begin
  836. besteq:=eq;
  837. bestpd:=pd;
  838. end;
  839. end;
  840. end;
  841. { maybe TODO: also search class helpers? -- this code is similar to
  842. what happens in htypechk in
  843. tcallcandidates.collect_overloads_in_struct: keep searching in
  844. parent types in case the currently found procdef is marked as
  845. "overload" and we haven't found a proper match yet }
  846. if assigned(ps.owner.defowner) and
  847. (ps.owner.defowner.typ=objectdef) and
  848. assigned(tobjectdef(ps.owner.defowner).childof) and
  849. (not assigned(bestpd) or
  850. (po_overload in bestpd.procoptions)) then
  851. begin
  852. sym:=tsym(tobjectdef(ps.owner.defowner).childof.symtable.find(ps.name));
  853. if assigned(sym) and
  854. (sym.typ=procsym) then
  855. ps:=tprocsym(sym)
  856. else
  857. ps:=nil;
  858. end
  859. else
  860. ps:=nil;
  861. until (besteq>=te_equal) or
  862. not assigned(ps);
  863. result:=bestpd;
  864. end;
  865. function Tprocsym.Find_procdef_assignment_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  866. var
  867. paraidx, realparamcount,
  868. i, j : longint;
  869. bestpd,
  870. hpd,
  871. pd : tprocdef;
  872. convtyp : tconverttype;
  873. eq : tequaltype;
  874. begin
  875. { This function will return the pprocdef of pprocsym that
  876. is the best match for fromdef and todef. }
  877. result:=nil;
  878. bestpd:=nil;
  879. besteq:=te_incompatible;
  880. for i:=0 to ProcdefList.Count-1 do
  881. begin
  882. pd:=tprocdef(ProcdefList[i]);
  883. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  884. continue;
  885. if (equal_defs(todef,pd.returndef) or
  886. { shortstrings of different lengths are ok as result }
  887. (is_shortstring(todef) and is_shortstring(pd.returndef))) and
  888. { the result type must be always really equal and not an alias,
  889. if you mess with this code, check tw4093 }
  890. ((todef=pd.returndef) or
  891. (
  892. not(df_unique in todef.defoptions) and
  893. not(df_unique in pd.returndef.defoptions)
  894. )
  895. ) then
  896. begin
  897. paraidx:=0;
  898. { ignore vs_hidden parameters }
  899. while (paraidx<pd.paras.count) and
  900. assigned(pd.paras[paraidx]) and
  901. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  902. inc(paraidx);
  903. realparamcount:=0;
  904. for j := 0 to pd.paras.Count-1 do
  905. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  906. inc(realparamcount);
  907. if (paraidx<pd.paras.count) and
  908. assigned(pd.paras[paraidx]) and
  909. (realparamcount = 1) then
  910. begin
  911. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  912. { alias? if yes, only l1 choice,
  913. if you mess with this code, check tw4093 }
  914. if (eq=te_exact) and
  915. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  916. ((df_unique in fromdef.defoptions) or
  917. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  918. eq:=te_convert_l1;
  919. if eq=te_exact then
  920. begin
  921. besteq:=eq;
  922. result:=pd;
  923. exit;
  924. end;
  925. if eq>besteq then
  926. begin
  927. bestpd:=pd;
  928. besteq:=eq;
  929. end;
  930. end;
  931. end;
  932. end;
  933. result:=bestpd;
  934. end;
  935. function Tprocsym.find_procdef_enumerator_operator(fromdef,todef:tdef;var besteq:tequaltype):Tprocdef;
  936. var
  937. paraidx, realparamcount,
  938. i, j : longint;
  939. bestpd,
  940. hpd,
  941. pd : tprocdef;
  942. current : tpropertysym;
  943. convtyp : tconverttype;
  944. eq : tequaltype;
  945. begin
  946. { This function will return the pprocdef of pprocsym that
  947. is the best match for fromdef and todef. }
  948. result:=nil;
  949. bestpd:=nil;
  950. besteq:=te_incompatible;
  951. for i:=0 to ProcdefList.Count-1 do
  952. begin
  953. pd:=tprocdef(ProcdefList[i]);
  954. if (pd.owner.symtabletype=staticsymtable) and not pd.owner.iscurrentunit then
  955. continue;
  956. if not (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) then
  957. continue;
  958. current := tpropertysym(tabstractrecorddef(pd.returndef).search_enumerator_current);
  959. if (current = nil) then
  960. continue;
  961. // compare current result def with the todef
  962. if (equal_defs(todef, current.propdef) or
  963. { shortstrings of different lengths are ok as result }
  964. (is_shortstring(todef) and is_shortstring(current.propdef))) and
  965. { the result type must be always really equal and not an alias,
  966. if you mess with this code, check tw4093 }
  967. ((todef=current.propdef) or
  968. (
  969. not(df_unique in todef.defoptions) and
  970. not(df_unique in current.propdef.defoptions)
  971. )
  972. ) then
  973. begin
  974. paraidx:=0;
  975. { ignore vs_hidden parameters }
  976. while (paraidx<pd.paras.count) and
  977. assigned(pd.paras[paraidx]) and
  978. (vo_is_hidden_para in tparavarsym(pd.paras[paraidx]).varoptions) do
  979. inc(paraidx);
  980. realparamcount:=0;
  981. for j := 0 to pd.paras.Count-1 do
  982. if assigned(pd.paras[j]) and not (vo_is_hidden_para in tparavarsym(pd.paras[j]).varoptions) then
  983. inc(realparamcount);
  984. if (paraidx<pd.paras.count) and
  985. assigned(pd.paras[paraidx]) and
  986. (realparamcount = 1) then
  987. begin
  988. eq:=compare_defs_ext(fromdef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
  989. { alias? if yes, only l1 choice,
  990. if you mess with this code, check tw4093 }
  991. if (eq=te_exact) and
  992. (fromdef<>tparavarsym(pd.paras[paraidx]).vardef) and
  993. ((df_unique in fromdef.defoptions) or
  994. (df_unique in tparavarsym(pd.paras[paraidx]).vardef.defoptions)) then
  995. eq:=te_convert_l1;
  996. if eq=te_exact then
  997. begin
  998. besteq:=eq;
  999. result:=pd;
  1000. exit;
  1001. end;
  1002. if eq>besteq then
  1003. begin
  1004. bestpd:=pd;
  1005. besteq:=eq;
  1006. end;
  1007. end;
  1008. end;
  1009. end;
  1010. result:=bestpd;
  1011. end;
  1012. {****************************************************************************
  1013. TERRORSYM
  1014. ****************************************************************************}
  1015. constructor terrorsym.create;
  1016. begin
  1017. inherited create(errorsym,'');
  1018. end;
  1019. {****************************************************************************
  1020. TPROPERTYSYM
  1021. ****************************************************************************}
  1022. constructor tpropertysym.create(const n : string);
  1023. var
  1024. pap : tpropaccesslisttypes;
  1025. begin
  1026. inherited create(propertysym,n);
  1027. propoptions:=[];
  1028. index:=0;
  1029. default:=0;
  1030. propdef:=nil;
  1031. indexdef:=nil;
  1032. parast:=nil;
  1033. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1034. propaccesslist[pap]:=tpropaccesslist.create;
  1035. end;
  1036. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1037. var
  1038. pap : tpropaccesslisttypes;
  1039. begin
  1040. inherited ppuload(propertysym,ppufile);
  1041. ppufile.getsmallset(propoptions);
  1042. if ppo_overrides in propoptions then
  1043. ppufile.getderef(overriddenpropsymderef);
  1044. ppufile.getderef(propdefderef);
  1045. index:=ppufile.getlongint;
  1046. default:=ppufile.getlongint;
  1047. ppufile.getderef(indexdefderef);
  1048. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1049. propaccesslist[pap]:=ppufile.getpropaccesslist;
  1050. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1051. begin
  1052. parast:=tparasymtable.create(nil,0);
  1053. tparasymtable(parast).ppuload(ppufile);
  1054. end
  1055. else
  1056. parast:=nil;
  1057. end;
  1058. destructor tpropertysym.destroy;
  1059. var
  1060. pap : tpropaccesslisttypes;
  1061. begin
  1062. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1063. propaccesslist[pap].free;
  1064. parast.free;
  1065. inherited destroy;
  1066. end;
  1067. procedure tpropertysym.buildderef;
  1068. var
  1069. pap : tpropaccesslisttypes;
  1070. begin
  1071. propdefderef.build(propdef);
  1072. indexdefderef.build(indexdef);
  1073. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1074. propaccesslist[pap].buildderef;
  1075. if ppo_overrides in propoptions then
  1076. overriddenpropsymderef.build(overriddenpropsym)
  1077. else
  1078. if ppo_hasparameters in propoptions then
  1079. tparasymtable(parast).buildderef;
  1080. end;
  1081. procedure tpropertysym.deref;
  1082. var
  1083. pap : tpropaccesslisttypes;
  1084. begin
  1085. indexdef:=tdef(indexdefderef.resolve);
  1086. propdef:=tdef(propdefderef.resolve);
  1087. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1088. propaccesslist[pap].resolve;
  1089. if ppo_overrides in propoptions then
  1090. begin
  1091. overriddenpropsym:=tpropertysym(overriddenpropsymderef.resolve);
  1092. if ppo_hasparameters in propoptions then
  1093. parast:=overriddenpropsym.parast.getcopy;
  1094. end
  1095. else
  1096. if ppo_hasparameters in propoptions then
  1097. tparasymtable(parast).deref
  1098. end;
  1099. function tpropertysym.getpropaccesslist(pap:tpropaccesslisttypes;out plist:tpropaccesslist):boolean;
  1100. var
  1101. hpropsym : tpropertysym;
  1102. begin
  1103. result:=false;
  1104. { find property in the overridden list }
  1105. hpropsym:=self;
  1106. repeat
  1107. plist:=hpropsym.propaccesslist[pap];
  1108. if not plist.empty then
  1109. begin
  1110. result:=true;
  1111. exit;
  1112. end;
  1113. hpropsym:=hpropsym.overriddenpropsym;
  1114. until not assigned(hpropsym);
  1115. end;
  1116. procedure tpropertysym.add_accessor_parameters(readprocdef, writeprocdef: tprocdef);
  1117. var
  1118. i: integer;
  1119. orig, hparavs: tparavarsym;
  1120. begin
  1121. for i := 0 to parast.SymList.Count - 1 do
  1122. begin
  1123. orig:=tparavarsym(parast.SymList[i]);
  1124. if assigned(readprocdef) then
  1125. begin
  1126. hparavs:=tparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1127. readprocdef.parast.insert(hparavs);
  1128. end;
  1129. if assigned(writeprocdef) then
  1130. begin
  1131. hparavs:=tparavarsym.create(orig.RealName,orig.paranr,orig.varspez,orig.vardef,[]);
  1132. writeprocdef.parast.insert(hparavs);
  1133. end;
  1134. end;
  1135. end;
  1136. procedure tpropertysym.add_index_parameter(var paranr: word; readprocdef, writeprocdef: tprocdef);
  1137. var
  1138. hparavs: tparavarsym;
  1139. begin
  1140. inc(paranr);
  1141. if assigned(readprocdef) then
  1142. begin
  1143. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1144. readprocdef.parast.insert(hparavs);
  1145. end;
  1146. if assigned(writeprocdef) then
  1147. begin
  1148. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,indexdef,[]);
  1149. writeprocdef.parast.insert(hparavs);
  1150. end;
  1151. end;
  1152. procedure tpropertysym.makeduplicate(p: tpropertysym; readprocdef, writeprocdef: tprocdef; out paranr: word);
  1153. begin
  1154. { inherit all type related entries }
  1155. p.indexdef:=indexdef;
  1156. p.propdef:=propdef;
  1157. p.index:=index;
  1158. p.default:=default;
  1159. p.propoptions:=propoptions;
  1160. paranr:=0;
  1161. if ppo_hasparameters in propoptions then
  1162. begin
  1163. p.parast:=parast.getcopy;
  1164. p.add_accessor_parameters(readprocdef,writeprocdef);
  1165. paranr:=p.parast.SymList.Count;
  1166. end;
  1167. if ppo_indexed in p.propoptions then
  1168. p.add_index_parameter(paranr,readprocdef,writeprocdef);
  1169. end;
  1170. function tpropertysym.getsize : asizeint;
  1171. begin
  1172. getsize:=0;
  1173. end;
  1174. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1175. var
  1176. pap : tpropaccesslisttypes;
  1177. begin
  1178. inherited ppuwrite(ppufile);
  1179. ppufile.putsmallset(propoptions);
  1180. if ppo_overrides in propoptions then
  1181. ppufile.putderef(overriddenpropsymderef);
  1182. ppufile.putderef(propdefderef);
  1183. ppufile.putlongint(index);
  1184. ppufile.putlongint(default);
  1185. ppufile.putderef(indexdefderef);
  1186. for pap:=low(tpropaccesslisttypes) to high(tpropaccesslisttypes) do
  1187. ppufile.putpropaccesslist(propaccesslist[pap]);
  1188. ppufile.writeentry(ibpropertysym);
  1189. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  1190. tparasymtable(parast).ppuwrite(ppufile);
  1191. end;
  1192. {****************************************************************************
  1193. TABSTRACTVARSYM
  1194. ****************************************************************************}
  1195. constructor tabstractvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1196. begin
  1197. inherited create(st,n);
  1198. vardef:=def;
  1199. varspez:=vsp;
  1200. varstate:=vs_declared;
  1201. varoptions:=vopts;
  1202. end;
  1203. constructor tabstractvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1204. begin
  1205. inherited ppuload(st,ppufile);
  1206. varstate:=vs_readwritten;
  1207. varspez:=tvarspez(ppufile.getbyte);
  1208. varregable:=tvarregable(ppufile.getbyte);
  1209. addr_taken:=boolean(ppufile.getbyte);
  1210. ppufile.getderef(vardefderef);
  1211. ppufile.getsmallset(varoptions);
  1212. end;
  1213. destructor tabstractvarsym.destroy;
  1214. begin
  1215. if assigned(notifications) then
  1216. notifications.destroy;
  1217. inherited destroy;
  1218. end;
  1219. procedure tabstractvarsym.buildderef;
  1220. begin
  1221. vardefderef.build(vardef);
  1222. end;
  1223. procedure tabstractvarsym.deref;
  1224. var
  1225. oldvarregable: tvarregable;
  1226. begin
  1227. { setting the vardef also updates varregable. We just loaded this }
  1228. { value from a ppu, so it must not be changed (e.g. tw7817a.pp/ }
  1229. { tw7817b.pp: the address is taken of a local variable in an }
  1230. { inlined procedure -> must remain non-regable when inlining) }
  1231. oldvarregable:=varregable;
  1232. vardef:=tdef(vardefderef.resolve);
  1233. varregable:=oldvarregable;
  1234. end;
  1235. procedure tabstractvarsym.ppuwrite(ppufile:tcompilerppufile);
  1236. var
  1237. oldintfcrc : boolean;
  1238. begin
  1239. inherited ppuwrite(ppufile);
  1240. ppufile.putbyte(byte(varspez));
  1241. oldintfcrc:=ppufile.do_crc;
  1242. ppufile.do_crc:=false;
  1243. ppufile.putbyte(byte(varregable));
  1244. ppufile.putbyte(byte(addr_taken));
  1245. ppufile.do_crc:=oldintfcrc;
  1246. ppufile.putderef(vardefderef);
  1247. ppufile.putsmallset(varoptions);
  1248. end;
  1249. function tabstractvarsym.getsize : asizeint;
  1250. begin
  1251. if assigned(vardef) and
  1252. ((vardef.typ<>arraydef) or
  1253. is_dynamic_array(vardef) or
  1254. (tarraydef(vardef).highrange>=tarraydef(vardef).lowrange)) then
  1255. result:=vardef.size
  1256. else
  1257. result:=0;
  1258. end;
  1259. function tabstractvarsym.getpackedbitsize : longint;
  1260. begin
  1261. { bitpacking is only done for ordinals }
  1262. if not is_ordinal(vardef) then
  1263. internalerror(2006082010);
  1264. result:=vardef.packedbitsize;
  1265. end;
  1266. function tabstractvarsym.is_regvar(refpara: boolean):boolean;
  1267. begin
  1268. { Register variables are not allowed in the following cases:
  1269. - regvars are disabled
  1270. - exceptions are used (after an exception is raised the contents of the
  1271. registers is not valid anymore)
  1272. - it has a local copy
  1273. - the value needs to be in memory (i.e. reference counted) }
  1274. result:=(cs_opt_regvar in current_settings.optimizerswitches) and
  1275. not(pi_has_assembler_block in current_procinfo.flags) and
  1276. not(pi_uses_exceptions in current_procinfo.flags) and
  1277. not(pi_has_interproclabel in current_procinfo.flags) and
  1278. not(vo_has_local_copy in varoptions) and
  1279. ((refpara and
  1280. (varregable <> vr_none)) or
  1281. (not refpara and
  1282. not(varregable in [vr_none,vr_addr])))
  1283. {$if not defined(powerpc) and not defined(powerpc64)}
  1284. and ((vardef.typ <> recorddef) or
  1285. (varregable = vr_addr) or
  1286. not(varstate in [vs_written,vs_readwritten]));
  1287. {$endif}
  1288. end;
  1289. procedure tabstractvarsym.trigger_notifications(what:Tnotification_flag);
  1290. var n:Tnotification;
  1291. begin
  1292. if assigned(notifications) then
  1293. begin
  1294. n:=Tnotification(notifications.first);
  1295. while assigned(n) do
  1296. begin
  1297. if what in n.flags then
  1298. n.callback(what,self);
  1299. n:=Tnotification(n.next);
  1300. end;
  1301. end;
  1302. end;
  1303. function Tabstractvarsym.register_notification(flags:Tnotification_flags;callback:
  1304. Tnotification_callback):cardinal;
  1305. var n:Tnotification;
  1306. begin
  1307. if not assigned(notifications) then
  1308. notifications:=Tlinkedlist.create;
  1309. n:=Tnotification.create(flags,callback);
  1310. register_notification:=n.id;
  1311. notifications.concat(n);
  1312. end;
  1313. procedure Tabstractvarsym.unregister_notification(id:cardinal);
  1314. var n:Tnotification;
  1315. begin
  1316. if not assigned(notifications) then
  1317. internalerror(200212311)
  1318. else
  1319. begin
  1320. n:=Tnotification(notifications.first);
  1321. while assigned(n) do
  1322. begin
  1323. if n.id=id then
  1324. begin
  1325. notifications.remove(n);
  1326. n.destroy;
  1327. exit;
  1328. end;
  1329. n:=Tnotification(n.next);
  1330. end;
  1331. internalerror(200212311)
  1332. end;
  1333. end;
  1334. procedure tabstractvarsym.setvardef(def:tdef);
  1335. begin
  1336. _vardef := def;
  1337. { can we load the value into a register ? }
  1338. if not assigned(owner) or
  1339. (owner.symtabletype in [localsymtable,parasymtable]) or
  1340. (
  1341. (owner.symtabletype=staticsymtable) and
  1342. not(cs_create_pic in current_settings.moduleswitches)
  1343. ) then
  1344. begin
  1345. if (tstoreddef(vardef).is_intregable and
  1346. { we could keep all aint*2 records in registers, but this causes
  1347. too much spilling for CPUs with 8-16 registers so keep only
  1348. parameters and function results of this type in register because they are normally
  1349. passed by register anyways
  1350. This can be changed, as soon as we have full ssa (FK) }
  1351. ((typ=paravarsym) or
  1352. (vo_is_funcret in varoptions) or
  1353. (tstoreddef(vardef).typ<>recorddef) or
  1354. (tstoreddef(vardef).size<=sizeof(aint)))) or
  1355. { const parameters can be put into registers if the def fits into a register }
  1356. (tstoreddef(vardef).is_const_intregable and
  1357. (typ=paravarsym) and
  1358. (varspez=vs_const)) then
  1359. varregable:=vr_intreg
  1360. else
  1361. { $warning TODO: no fpu regvar in staticsymtable yet, need initialization with 0 }
  1362. if {(
  1363. not assigned(owner) or
  1364. (owner.symtabletype<>staticsymtable)
  1365. ) and }
  1366. tstoreddef(vardef).is_fpuregable then
  1367. begin
  1368. if use_vectorfpu(vardef) then
  1369. varregable:=vr_mmreg
  1370. else
  1371. varregable:=vr_fpureg;
  1372. end;
  1373. end;
  1374. end;
  1375. {****************************************************************************
  1376. TFIELDVARSYM
  1377. ****************************************************************************}
  1378. constructor tfieldvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1379. begin
  1380. inherited create(fieldvarsym,n,vsp,def,vopts);
  1381. fieldoffset:=-1;
  1382. end;
  1383. constructor tfieldvarsym.ppuload(ppufile:tcompilerppufile);
  1384. begin
  1385. inherited ppuload(fieldvarsym,ppufile);
  1386. fieldoffset:=ppufile.getaint;
  1387. if (vo_has_mangledname in varoptions) then
  1388. externalname:=stringdup(ppufile.getstring)
  1389. else
  1390. externalname:=nil;
  1391. end;
  1392. procedure tfieldvarsym.ppuwrite(ppufile:tcompilerppufile);
  1393. begin
  1394. inherited ppuwrite(ppufile);
  1395. ppufile.putaint(fieldoffset);
  1396. if (vo_has_mangledname in varoptions) then
  1397. ppufile.putstring(externalname^);
  1398. ppufile.writeentry(ibfieldvarsym);
  1399. end;
  1400. procedure tfieldvarsym.set_externalname(const s: string);
  1401. begin
  1402. { make sure it is recalculated }
  1403. {$ifdef symansistr}
  1404. cachedmangledname:='';
  1405. {$else symansistr}
  1406. stringdispose(cachedmangledname);
  1407. {$endif symansistr}
  1408. {$ifdef jvm}
  1409. if is_java_class_or_interface(tdef(owner.defowner)) then
  1410. begin
  1411. externalname:=stringdup(s);
  1412. include(varoptions,vo_has_mangledname);
  1413. end
  1414. else
  1415. {$endif jvm}
  1416. internalerror(2011031201);
  1417. end;
  1418. function tfieldvarsym.mangledname:TSymStr;
  1419. var
  1420. srsym : tsym;
  1421. srsymtable : tsymtable;
  1422. begin
  1423. {$ifdef jvm}
  1424. if is_java_class_or_interface(tdef(owner.defowner)) or
  1425. (tdef(owner.defowner).typ=recorddef) then
  1426. begin
  1427. if cachedmangledname<>'' then
  1428. result:=cachedmangledname
  1429. else
  1430. begin
  1431. result:=jvmmangledbasename(self,false);
  1432. jvmaddtypeownerprefix(owner,result);
  1433. cachedmangledname:=result;
  1434. end;
  1435. end
  1436. else
  1437. {$endif jvm}
  1438. if sp_static in symoptions then
  1439. begin
  1440. if searchsym(lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1441. result:=srsym.mangledname
  1442. { when generating the debug info for the module in which the }
  1443. { symbol is defined, the localsymtable of that module is }
  1444. { already popped from the symtablestack }
  1445. else if searchsym_in_module(current_module,lower(owner.name^)+'_'+name,srsym,srsymtable) then
  1446. result:=srsym.mangledname
  1447. else
  1448. internalerror(2007012501);
  1449. end
  1450. else if is_objcclass(tdef(owner.defowner)) then
  1451. begin
  1452. {$ifdef symansistr}
  1453. if cachedmangledname<>'' then
  1454. result:=cachedmangledname
  1455. {$else symansistr}
  1456. if assigned(cachedmangledname) then
  1457. result:=cachedmangledname^
  1458. {$endif symansistr}
  1459. else
  1460. begin
  1461. result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
  1462. {$ifdef symansistr}
  1463. cachedmangledname:=result;
  1464. {$else symansistr}
  1465. cachedmangledname:=stringdup(result);
  1466. {$endif symansistr}
  1467. end;
  1468. end
  1469. else
  1470. result:=inherited mangledname;
  1471. end;
  1472. destructor tfieldvarsym.destroy;
  1473. begin
  1474. {$ifndef symansistr}
  1475. stringdispose(cachedmangledname);
  1476. {$endif symansistr}
  1477. stringdispose(externalname);
  1478. inherited destroy;
  1479. end;
  1480. {****************************************************************************
  1481. TABSTRACTNORMALVARSYM
  1482. ****************************************************************************}
  1483. constructor tabstractnormalvarsym.create(st:tsymtyp;const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1484. begin
  1485. inherited create(st,n,vsp,def,vopts);
  1486. fillchar(localloc,sizeof(localloc),0);
  1487. fillchar(currentregloc,sizeof(localloc),0);
  1488. fillchar(initialloc,sizeof(initialloc),0);
  1489. defaultconstsym:=nil;
  1490. end;
  1491. constructor tabstractnormalvarsym.ppuload(st:tsymtyp;ppufile:tcompilerppufile);
  1492. begin
  1493. inherited ppuload(st,ppufile);
  1494. fillchar(localloc,sizeof(localloc),0);
  1495. fillchar(currentregloc,sizeof(localloc),0);
  1496. fillchar(initialloc,sizeof(initialloc),0);
  1497. ppufile.getderef(defaultconstsymderef);
  1498. end;
  1499. function tabstractnormalvarsym.globalasmsym: boolean;
  1500. begin
  1501. result:=
  1502. (owner.symtabletype=globalsymtable) or
  1503. (create_smartlink and
  1504. not(tf_smartlink_sections in target_info.flags)) or
  1505. DLLSource or
  1506. (assigned(current_procinfo) and
  1507. ((po_inline in current_procinfo.procdef.procoptions) or
  1508. { globalasmsym is called normally before the body of a subroutine is parsed
  1509. so we cannot know if it will be auto inlined, so make all symbols of it
  1510. global if asked }
  1511. (cs_opt_autoinline in current_settings.optimizerswitches))
  1512. ) or
  1513. (vo_is_public in varoptions);
  1514. end;
  1515. procedure tabstractnormalvarsym.buildderef;
  1516. begin
  1517. inherited buildderef;
  1518. defaultconstsymderef.build(defaultconstsym);
  1519. end;
  1520. procedure tabstractnormalvarsym.deref;
  1521. begin
  1522. inherited deref;
  1523. defaultconstsym:=tsym(defaultconstsymderef.resolve);
  1524. end;
  1525. procedure tabstractnormalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1526. begin
  1527. inherited ppuwrite(ppufile);
  1528. ppufile.putderef(defaultconstsymderef);
  1529. end;
  1530. {****************************************************************************
  1531. Tstaticvarsym
  1532. ****************************************************************************}
  1533. constructor tstaticvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1534. begin
  1535. inherited create(staticvarsym,n,vsp,def,vopts);
  1536. {$ifdef symansistr}
  1537. _mangledname:='';
  1538. {$else symansistr}
  1539. _mangledname:=nil;
  1540. {$endif symansistr}
  1541. end;
  1542. constructor tstaticvarsym.create_dll(const n : string;vsp:tvarspez;def:tdef);
  1543. begin
  1544. tstaticvarsym(self).create(n,vsp,def,[vo_is_dll_var]);
  1545. end;
  1546. constructor tstaticvarsym.create_C(const n: string; const mangled : TSymStr;vsp:tvarspez;def:tdef);
  1547. begin
  1548. tstaticvarsym(self).create(n,vsp,def,[]);
  1549. set_mangledname(mangled);
  1550. end;
  1551. constructor tstaticvarsym.ppuload(ppufile:tcompilerppufile);
  1552. begin
  1553. inherited ppuload(staticvarsym,ppufile);
  1554. {$ifdef symansistr}
  1555. if vo_has_mangledname in varoptions then
  1556. _mangledname:=ppufile.getansistring
  1557. else
  1558. _mangledname:='';
  1559. {$else symansistr}
  1560. if vo_has_mangledname in varoptions then
  1561. _mangledname:=stringdup(ppufile.getstring)
  1562. else
  1563. _mangledname:=nil;
  1564. if vo_has_section in varoptions then
  1565. section:=ppufile.getansistring;
  1566. {$endif symansistr}
  1567. end;
  1568. destructor tstaticvarsym.destroy;
  1569. begin
  1570. {$ifndef symansistr}
  1571. if assigned(_mangledname) then
  1572. begin
  1573. {$ifdef MEMDEBUG}
  1574. memmanglednames.start;
  1575. {$endif MEMDEBUG}
  1576. stringdispose(_mangledname);
  1577. {$ifdef MEMDEBUG}
  1578. memmanglednames.stop;
  1579. {$endif MEMDEBUG}
  1580. end;
  1581. stringdispose(_mangledbasename);
  1582. {$endif}
  1583. inherited destroy;
  1584. end;
  1585. procedure tstaticvarsym.ppuwrite(ppufile:tcompilerppufile);
  1586. begin
  1587. inherited ppuwrite(ppufile);
  1588. { write mangledname rather than _mangledname in case the mangledname
  1589. has not been calculated yet (can happen in case only the
  1590. mangledbasename has been set) }
  1591. if vo_has_mangledname in varoptions then
  1592. {$ifdef symansistr}
  1593. ppufile.putansistring(mangledname);
  1594. {$else symansistr}
  1595. ppufile.putstring(mangledname);
  1596. {$endif symansistr}
  1597. if vo_has_section in varoptions then
  1598. ppufile.putansistring(section);
  1599. ppufile.writeentry(ibstaticvarsym);
  1600. end;
  1601. function tstaticvarsym.mangledname:TSymStr;
  1602. {$ifndef jvm}
  1603. var
  1604. usename,
  1605. prefix : TSymStr;
  1606. {$endif jvm}
  1607. begin
  1608. {$ifdef symansistr}
  1609. if _mangledname='' then
  1610. {$else symansistr}
  1611. if not assigned(_mangledname) then
  1612. {$endif symansistr}
  1613. begin
  1614. {$ifdef jvm}
  1615. if _mangledbasename='' then
  1616. _mangledname:=jvmmangledbasename(self,false)
  1617. else
  1618. _mangledname:=jvmmangledbasename(self,_mangledbasename,false);
  1619. jvmaddtypeownerprefix(owner,_mangledname);
  1620. {$else jvm}
  1621. if (vo_is_typed_const in varoptions) then
  1622. prefix:='TC'
  1623. else
  1624. prefix:='U';
  1625. {$ifdef symansistr}
  1626. if _mangledbasename='' then
  1627. usename:=name
  1628. else
  1629. usename:=_mangledbasename;
  1630. {$else symansistr}
  1631. if not assigned(_mangledbasename) then
  1632. usename:=name
  1633. else
  1634. usename:=_mangledbasename^;
  1635. {$endif symansistr}
  1636. {$ifdef compress}
  1637. {$error add ansistring support for symansistr}
  1638. _mangledname:=stringdup(minilzw_encode(make_mangledname(prefix,owner,usename)));
  1639. {$else compress}
  1640. {$ifdef symansistr}
  1641. _mangledname:=make_mangledname(prefix,owner,usename);
  1642. {$else symansistr}
  1643. _mangledname:=stringdup(make_mangledname(prefix,owner,usename));
  1644. {$endif symansistr}
  1645. {$endif compress}
  1646. {$endif jvm}
  1647. end;
  1648. {$ifdef symansistr}
  1649. result:=_mangledname;
  1650. {$else symansistr}
  1651. result:=_mangledname^;
  1652. {$endif symansistr}
  1653. end;
  1654. procedure tstaticvarsym.set_mangledbasename(const s: TSymStr);
  1655. begin
  1656. {$ifdef symansistr}
  1657. _mangledbasename:=s;
  1658. _mangledname:='';
  1659. {$else symansistr}
  1660. stringdispose(_mangledname);
  1661. stringdispose(_mangledbasename);
  1662. _mangledbasename:=stringdup(s);
  1663. {$endif symansistr}
  1664. include(varoptions,vo_has_mangledname);
  1665. end;
  1666. function tstaticvarsym.mangledbasename: TSymStr;
  1667. begin
  1668. {$ifdef symansistr}
  1669. result:=_mangledbasename;
  1670. {$else symansistr}
  1671. if assigned(_mangledbasename) then
  1672. result:=_mangledbasename^
  1673. else
  1674. result:='';
  1675. {$endif symansistr}
  1676. end;
  1677. procedure tstaticvarsym.set_mangledname(const s:TSymStr);
  1678. begin
  1679. {$ifndef symansistr}
  1680. stringdispose(_mangledname);
  1681. {$endif}
  1682. {$if defined(jvm)}
  1683. _mangledname:=jvmmangledbasename(self,s,false);
  1684. jvmaddtypeownerprefix(owner,_mangledname);
  1685. {$elseif defined(compress)}
  1686. _mangledname:=stringdup(minilzw_encode(s));
  1687. {$else}
  1688. {$ifdef symansistr}
  1689. _mangledname:=s;
  1690. {$else symansistr}
  1691. _mangledname:=stringdup(s);
  1692. {$endif symansistr}
  1693. {$endif}
  1694. include(varoptions,vo_has_mangledname);
  1695. end;
  1696. procedure tstaticvarsym.set_raw_mangledname(const s: TSymStr);
  1697. begin
  1698. {$ifndef symansistr}
  1699. stringdispose(_mangledname);
  1700. _mangledname:=stringdup(s);
  1701. {$else}
  1702. _mangledname:=s;
  1703. {$endif}
  1704. include(varoptions,vo_has_mangledname);
  1705. end;
  1706. {****************************************************************************
  1707. TLOCALVARSYM
  1708. ****************************************************************************}
  1709. constructor tlocalvarsym.create(const n : string;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1710. begin
  1711. inherited create(localvarsym,n,vsp,def,vopts);
  1712. end;
  1713. constructor tlocalvarsym.ppuload(ppufile:tcompilerppufile);
  1714. begin
  1715. inherited ppuload(localvarsym,ppufile);
  1716. end;
  1717. procedure tlocalvarsym.ppuwrite(ppufile:tcompilerppufile);
  1718. begin
  1719. inherited ppuwrite(ppufile);
  1720. ppufile.writeentry(iblocalvarsym);
  1721. end;
  1722. {****************************************************************************
  1723. TPARAVARSYM
  1724. ****************************************************************************}
  1725. constructor tparavarsym.create(const n : string;nr:word;vsp:tvarspez;def:tdef;vopts:tvaroptions);
  1726. begin
  1727. inherited create(paravarsym,n,vsp,def,vopts);
  1728. if (vsp in [vs_var,vs_value,vs_const,vs_constref]) and
  1729. not(vo_is_funcret in vopts) then
  1730. varstate := vs_initialised;
  1731. paranr:=nr;
  1732. paraloc[calleeside].init;
  1733. paraloc[callerside].init;
  1734. end;
  1735. destructor tparavarsym.destroy;
  1736. begin
  1737. paraloc[calleeside].done;
  1738. paraloc[callerside].done;
  1739. inherited destroy;
  1740. end;
  1741. constructor tparavarsym.ppuload(ppufile:tcompilerppufile);
  1742. var
  1743. b : byte;
  1744. begin
  1745. inherited ppuload(paravarsym,ppufile);
  1746. paranr:=ppufile.getword;
  1747. univpara:=boolean(ppufile.getbyte);
  1748. { The var state of parameter symbols is fixed after writing them so
  1749. we write them to the unit file.
  1750. This enables constant folding for inline procedures loaded from units
  1751. }
  1752. varstate:=tvarstate(ppufile.getbyte);
  1753. { read usage info }
  1754. refs:=ppufile.getbyte;
  1755. paraloc[calleeside].init;
  1756. paraloc[callerside].init;
  1757. if vo_has_explicit_paraloc in varoptions then
  1758. begin
  1759. paraloc[callerside].alignment:=ppufile.getbyte;
  1760. b:=ppufile.getbyte;
  1761. if b<>sizeof(paraloc[callerside].location^) then
  1762. internalerror(200411154);
  1763. ppufile.getdata(paraloc[callerside].add_location^,sizeof(paraloc[callerside].location^));
  1764. paraloc[callerside].size:=paraloc[callerside].location^.size;
  1765. paraloc[callerside].intsize:=tcgsize2size[paraloc[callerside].size];
  1766. end;
  1767. end;
  1768. procedure tparavarsym.ppuwrite(ppufile:tcompilerppufile);
  1769. var
  1770. oldintfcrc : boolean;
  1771. begin
  1772. inherited ppuwrite(ppufile);
  1773. ppufile.putword(paranr);
  1774. ppufile.putbyte(byte(univpara));
  1775. { The var state of parameter symbols is fixed after writing them so
  1776. we write them to the unit file.
  1777. This enables constant folding for inline procedures loaded from units
  1778. }
  1779. oldintfcrc:=ppufile.do_crc;
  1780. ppufile.do_crc:=false;
  1781. ppufile.putbyte(ord(varstate));
  1782. { write also info about the usage of parameters,
  1783. the absolute usage does not matter }
  1784. ppufile.putbyte(min(1,refs));
  1785. ppufile.do_crc:=oldintfcrc;
  1786. if vo_has_explicit_paraloc in varoptions then
  1787. begin
  1788. paraloc[callerside].check_simple_location;
  1789. ppufile.putbyte(sizeof(paraloc[callerside].alignment));
  1790. ppufile.putbyte(sizeof(paraloc[callerside].location^));
  1791. ppufile.putdata(paraloc[callerside].location^,sizeof(paraloc[callerside].location^));
  1792. end;
  1793. ppufile.writeentry(ibparavarsym);
  1794. end;
  1795. function tparavarsym.needs_finalization:boolean;
  1796. begin
  1797. result:=(varspez=vs_value) and
  1798. (is_managed_type(vardef) or
  1799. (
  1800. (not (tabstractprocdef(owner.defowner).proccalloption in cdecl_pocalls)) and
  1801. (not paramanager.use_stackalloc) and
  1802. (is_open_array(vardef) or is_array_of_const(vardef))
  1803. )
  1804. );
  1805. end;
  1806. {****************************************************************************
  1807. TABSOLUTEVARSYM
  1808. ****************************************************************************}
  1809. constructor tabsolutevarsym.create(const n : string;def:tdef);
  1810. begin
  1811. inherited create(absolutevarsym,n,vs_value,def,[]);
  1812. ref:=nil;
  1813. end;
  1814. constructor tabsolutevarsym.create_ref(const n : string;def:tdef;_ref:tpropaccesslist);
  1815. begin
  1816. inherited create(absolutevarsym,n,vs_value,def,[]);
  1817. ref:=_ref;
  1818. end;
  1819. destructor tabsolutevarsym.destroy;
  1820. begin
  1821. if assigned(ref) then
  1822. ref.free;
  1823. inherited destroy;
  1824. end;
  1825. constructor tabsolutevarsym.ppuload(ppufile:tcompilerppufile);
  1826. begin
  1827. inherited ppuload(absolutevarsym,ppufile);
  1828. ref:=nil;
  1829. asmname:=nil;
  1830. abstyp:=absolutetyp(ppufile.getbyte);
  1831. {$if defined(i386) or defined(i8086)}
  1832. absseg:=false;
  1833. {$endif i386 or i8086}
  1834. case abstyp of
  1835. tovar :
  1836. ref:=ppufile.getpropaccesslist;
  1837. toasm :
  1838. asmname:=stringdup(ppufile.getstring);
  1839. toaddr :
  1840. begin
  1841. addroffset:=ppufile.getaword;
  1842. {$if defined(i386)}
  1843. absseg:=boolean(ppufile.getbyte);
  1844. {$elseif defined(i8086)}
  1845. absseg:=boolean(ppufile.getbyte);
  1846. if absseg then
  1847. addrsegment:=ppufile.getaword;
  1848. {$endif}
  1849. end;
  1850. end;
  1851. end;
  1852. procedure tabsolutevarsym.ppuwrite(ppufile:tcompilerppufile);
  1853. begin
  1854. inherited ppuwrite(ppufile);
  1855. ppufile.putbyte(byte(abstyp));
  1856. case abstyp of
  1857. tovar :
  1858. ppufile.putpropaccesslist(ref);
  1859. toasm :
  1860. ppufile.putstring(asmname^);
  1861. toaddr :
  1862. begin
  1863. ppufile.putaword(addroffset);
  1864. {$if defined(i386)}
  1865. ppufile.putbyte(byte(absseg));
  1866. {$elseif defined(i8086)}
  1867. ppufile.putbyte(byte(absseg));
  1868. if absseg then
  1869. ppufile.putaword(addrsegment);
  1870. {$endif}
  1871. end;
  1872. end;
  1873. ppufile.writeentry(ibabsolutevarsym);
  1874. end;
  1875. procedure tabsolutevarsym.buildderef;
  1876. begin
  1877. inherited buildderef;
  1878. if (abstyp=tovar) then
  1879. ref.buildderef;
  1880. end;
  1881. procedure tabsolutevarsym.deref;
  1882. begin
  1883. inherited deref;
  1884. { own absolute deref }
  1885. if (abstyp=tovar) then
  1886. ref.resolve;
  1887. end;
  1888. function tabsolutevarsym.mangledname : TSymStr;
  1889. begin
  1890. case abstyp of
  1891. toasm :
  1892. mangledname:=asmname^;
  1893. toaddr :
  1894. mangledname:='$'+tostr(addroffset);
  1895. else
  1896. internalerror(200411062);
  1897. end;
  1898. end;
  1899. {****************************************************************************
  1900. TCONSTSYM
  1901. ****************************************************************************}
  1902. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : tconstexprint;def:tdef);
  1903. begin
  1904. inherited create(constsym,n);
  1905. fillchar(value, sizeof(value), #0);
  1906. consttyp:=t;
  1907. value.valueord:=v;
  1908. constdef:=def;
  1909. end;
  1910. constructor tconstsym.create_ordptr(const n : string;t : tconsttyp;v : tconstptruint;def:tdef);
  1911. begin
  1912. inherited create(constsym,n);
  1913. fillchar(value, sizeof(value), #0);
  1914. consttyp:=t;
  1915. value.valueordptr:=v;
  1916. constdef:=def;
  1917. end;
  1918. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer;def:tdef);
  1919. begin
  1920. inherited create(constsym,n);
  1921. fillchar(value, sizeof(value), #0);
  1922. consttyp:=t;
  1923. value.valueptr:=v;
  1924. constdef:=def;
  1925. end;
  1926. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint;def: tdef);
  1927. begin
  1928. inherited create(constsym,n);
  1929. fillchar(value, sizeof(value), #0);
  1930. consttyp:=t;
  1931. value.valueptr:=str;
  1932. if assigned(def) then
  1933. constdef:=def
  1934. else
  1935. constdef:=getarraydef(cansichartype,l);
  1936. value.len:=l;
  1937. end;
  1938. constructor tconstsym.create_wstring(const n : string;t : tconsttyp;pw:pcompilerwidestring);
  1939. begin
  1940. inherited create(constsym,n);
  1941. fillchar(value, sizeof(value), #0);
  1942. consttyp:=t;
  1943. pcompilerwidestring(value.valueptr):=pw;
  1944. constdef:=getarraydef(cwidechartype,getlengthwidestring(pw));
  1945. value.len:=getlengthwidestring(pw);
  1946. end;
  1947. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1948. var
  1949. pd : pbestreal;
  1950. ps : pnormalset;
  1951. pc : pchar;
  1952. pw : pcompilerwidestring;
  1953. i : longint;
  1954. begin
  1955. inherited ppuload(constsym,ppufile);
  1956. constdef:=nil;
  1957. consttyp:=tconsttyp(ppufile.getbyte);
  1958. fillchar(value, sizeof(value), #0);
  1959. case consttyp of
  1960. constord :
  1961. begin
  1962. ppufile.getderef(constdefderef);
  1963. value.valueord:=ppufile.getexprint;
  1964. end;
  1965. constpointer :
  1966. begin
  1967. ppufile.getderef(constdefderef);
  1968. value.valueordptr:=ppufile.getptruint;
  1969. end;
  1970. constwstring :
  1971. begin
  1972. initwidestring(pw);
  1973. setlengthwidestring(pw,ppufile.getlongint);
  1974. { don't use getdata, because the compilerwidechars may have to
  1975. be byteswapped
  1976. }
  1977. {$if sizeof(tcompilerwidechar) = 2}
  1978. for i:=0 to pw^.len-1 do
  1979. pw^.data[i]:=ppufile.getword;
  1980. {$elseif sizeof(tcompilerwidechar) = 4}
  1981. for i:=0 to pw^.len-1 do
  1982. pw^.data[i]:=cardinal(ppufile.getlongint);
  1983. {$else}
  1984. {$error Unsupported tcompilerwidechar size}
  1985. {$endif}
  1986. pcompilerwidestring(value.valueptr):=pw;
  1987. end;
  1988. conststring,
  1989. constresourcestring :
  1990. begin
  1991. value.len:=ppufile.getlongint;
  1992. getmem(pc,value.len+1);
  1993. ppufile.getdata(pc^,value.len);
  1994. pc[value.len]:=#0;
  1995. value.valueptr:=pc;
  1996. end;
  1997. constreal :
  1998. begin
  1999. ppufile.getderef(constdefderef);
  2000. new(pd);
  2001. pd^:=ppufile.getreal;
  2002. value.valueptr:=pd;
  2003. end;
  2004. constset :
  2005. begin
  2006. ppufile.getderef(constdefderef);
  2007. new(ps);
  2008. ppufile.getnormalset(ps^);
  2009. value.valueptr:=ps;
  2010. end;
  2011. constguid :
  2012. begin
  2013. new(pguid(value.valueptr));
  2014. ppufile.getdata(value.valueptr^,sizeof(tguid));
  2015. end;
  2016. constnil : ;
  2017. else
  2018. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  2019. end;
  2020. end;
  2021. destructor tconstsym.destroy;
  2022. begin
  2023. case consttyp of
  2024. conststring,
  2025. constresourcestring :
  2026. freemem(pchar(value.valueptr),value.len+1);
  2027. constwstring :
  2028. donewidestring(pcompilerwidestring(value.valueptr));
  2029. constreal :
  2030. dispose(pbestreal(value.valueptr));
  2031. constset :
  2032. dispose(pnormalset(value.valueptr));
  2033. constguid :
  2034. dispose(pguid(value.valueptr));
  2035. end;
  2036. inherited destroy;
  2037. end;
  2038. procedure tconstsym.buildderef;
  2039. begin
  2040. if consttyp in [constord,constreal,constpointer,constset] then
  2041. constdefderef.build(constdef);
  2042. end;
  2043. procedure tconstsym.deref;
  2044. begin
  2045. if consttyp in [constord,constreal,constpointer,constset] then
  2046. constdef:=tdef(constdefderef.resolve);
  2047. end;
  2048. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  2049. begin
  2050. inherited ppuwrite(ppufile);
  2051. ppufile.putbyte(byte(consttyp));
  2052. case consttyp of
  2053. constnil : ;
  2054. constord :
  2055. begin
  2056. ppufile.putderef(constdefderef);
  2057. ppufile.putexprint(value.valueord);
  2058. end;
  2059. constpointer :
  2060. begin
  2061. ppufile.putderef(constdefderef);
  2062. ppufile.putptruint(value.valueordptr);
  2063. end;
  2064. constwstring :
  2065. begin
  2066. ppufile.putlongint(getlengthwidestring(pcompilerwidestring(value.valueptr)));
  2067. ppufile.putdata(pcompilerwidestring(value.valueptr)^.data^,pcompilerwidestring(value.valueptr)^.len*sizeof(tcompilerwidechar));
  2068. end;
  2069. conststring,
  2070. constresourcestring :
  2071. begin
  2072. ppufile.putlongint(value.len);
  2073. ppufile.putdata(pchar(value.valueptr)^,value.len);
  2074. end;
  2075. constreal :
  2076. begin
  2077. ppufile.putderef(constdefderef);
  2078. ppufile.putreal(pbestreal(value.valueptr)^);
  2079. end;
  2080. constset :
  2081. begin
  2082. ppufile.putderef(constdefderef);
  2083. ppufile.putnormalset(value.valueptr^);
  2084. end;
  2085. constguid :
  2086. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2087. else
  2088. internalerror(13);
  2089. end;
  2090. ppufile.writeentry(ibconstsym);
  2091. end;
  2092. {****************************************************************************
  2093. TENUMSYM
  2094. ****************************************************************************}
  2095. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2096. begin
  2097. inherited create(enumsym,n);
  2098. definition:=def;
  2099. value:=v;
  2100. end;
  2101. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2102. begin
  2103. inherited ppuload(enumsym,ppufile);
  2104. ppufile.getderef(definitionderef);
  2105. value:=ppufile.getlongint;
  2106. end;
  2107. procedure tenumsym.buildderef;
  2108. begin
  2109. definitionderef.build(definition);
  2110. end;
  2111. procedure tenumsym.deref;
  2112. begin
  2113. definition:=tenumdef(definitionderef.resolve);
  2114. end;
  2115. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2116. begin
  2117. inherited ppuwrite(ppufile);
  2118. ppufile.putderef(definitionderef);
  2119. ppufile.putlongint(value);
  2120. ppufile.writeentry(ibenumsym);
  2121. end;
  2122. {****************************************************************************
  2123. TTYPESYM
  2124. ****************************************************************************}
  2125. constructor ttypesym.create(const n : string;def:tdef);
  2126. begin
  2127. inherited create(typesym,n);
  2128. typedef:=def;
  2129. { register the typesym for the definition }
  2130. if assigned(typedef) and
  2131. (typedef.typ<>errordef) and
  2132. not(assigned(typedef.typesym)) then
  2133. typedef.typesym:=self;
  2134. end;
  2135. destructor ttypesym.destroy;
  2136. begin
  2137. inherited destroy;
  2138. end;
  2139. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2140. begin
  2141. inherited ppuload(typesym,ppufile);
  2142. ppufile.getderef(typedefderef);
  2143. fprettyname:=ppufile.getansistring;
  2144. end;
  2145. procedure ttypesym.buildderef;
  2146. begin
  2147. typedefderef.build(typedef);
  2148. end;
  2149. procedure ttypesym.deref;
  2150. begin
  2151. typedef:=tdef(typedefderef.resolve);
  2152. end;
  2153. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2154. begin
  2155. inherited ppuwrite(ppufile);
  2156. ppufile.putderef(typedefderef);
  2157. ppufile.putansistring(fprettyname);
  2158. ppufile.writeentry(ibtypesym);
  2159. end;
  2160. function ttypesym.prettyname : string;
  2161. begin
  2162. if fprettyname<>'' then
  2163. result:=fprettyname
  2164. else
  2165. result:=inherited prettyname;
  2166. end;
  2167. {****************************************************************************
  2168. TSYSSYM
  2169. ****************************************************************************}
  2170. constructor tsyssym.create(const n : string;l : longint);
  2171. begin
  2172. inherited create(syssym,n);
  2173. number:=l;
  2174. end;
  2175. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2176. begin
  2177. inherited ppuload(syssym,ppufile);
  2178. number:=ppufile.getlongint;
  2179. end;
  2180. destructor tsyssym.destroy;
  2181. begin
  2182. inherited destroy;
  2183. end;
  2184. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2185. begin
  2186. inherited ppuwrite(ppufile);
  2187. ppufile.putlongint(number);
  2188. ppufile.writeentry(ibsyssym);
  2189. end;
  2190. {*****************************************************************************
  2191. TMacro
  2192. *****************************************************************************}
  2193. constructor tmacro.create(const n : string);
  2194. begin
  2195. inherited create(macrosym,n);
  2196. owner:=nil;
  2197. defined:=false;
  2198. is_used:=false;
  2199. is_compiler_var:=false;
  2200. buftext:=nil;
  2201. buflen:=0;
  2202. end;
  2203. constructor tmacro.ppuload(ppufile:tcompilerppufile);
  2204. begin
  2205. inherited ppuload(macrosym,ppufile);
  2206. defined:=boolean(ppufile.getbyte);
  2207. is_compiler_var:=boolean(ppufile.getbyte);
  2208. is_used:=false;
  2209. buflen:= ppufile.getlongint;
  2210. if buflen > 0 then
  2211. begin
  2212. getmem(buftext, buflen);
  2213. ppufile.getdata(buftext^, buflen)
  2214. end
  2215. else
  2216. buftext:=nil;
  2217. end;
  2218. destructor tmacro.destroy;
  2219. begin
  2220. if assigned(buftext) then
  2221. freemem(buftext);
  2222. inherited destroy;
  2223. end;
  2224. procedure tmacro.ppuwrite(ppufile:tcompilerppufile);
  2225. begin
  2226. inherited ppuwrite(ppufile);
  2227. ppufile.putbyte(byte(defined));
  2228. ppufile.putbyte(byte(is_compiler_var));
  2229. ppufile.putlongint(buflen);
  2230. if buflen > 0 then
  2231. ppufile.putdata(buftext^,buflen);
  2232. ppufile.writeentry(ibmacrosym);
  2233. end;
  2234. function tmacro.GetCopy:tmacro;
  2235. var
  2236. p : tmacro;
  2237. begin
  2238. p:=tmacro.create(realname);
  2239. p.defined:=defined;
  2240. p.is_used:=is_used;
  2241. p.is_compiler_var:=is_compiler_var;
  2242. p.buflen:=buflen;
  2243. if assigned(buftext) then
  2244. begin
  2245. getmem(p.buftext,buflen);
  2246. move(buftext^,p.buftext^,buflen);
  2247. end;
  2248. Result:=p;
  2249. end;
  2250. end.