symsym.pas 77 KB

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