symsym.pas 79 KB

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