symsym.pas 79 KB

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