symsym.pas 80 KB

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