symsym.pas 80 KB

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