symsym.pas 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490
  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,cobjects,
  24. { target }
  25. cpuinfo,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,
  28. { aasm }
  29. aasm,cpubase
  30. ;
  31. type
  32. {************************************************
  33. TSym
  34. ************************************************}
  35. { this object is the base for all symbol objects }
  36. pstoredsym = ^tstoredsym;
  37. tstoredsym = object(tsym)
  38. {$ifdef GDB}
  39. isstabwritten : boolean;
  40. {$endif GDB}
  41. refs : longint;
  42. lastref,
  43. defref,
  44. lastwritten : pref;
  45. refcount : longint;
  46. constructor init(const n : string);
  47. constructor load;
  48. destructor done;virtual;
  49. procedure write;virtual;
  50. function mangledname : string;virtual;
  51. procedure insert_in_data;virtual;
  52. {$ifdef GDB}
  53. function stabstring : pchar;virtual;
  54. procedure concatstabto(asmlist : paasmoutput);virtual;
  55. {$endif GDB}
  56. procedure load_references;virtual;
  57. function write_references : boolean;virtual;
  58. end;
  59. plabelsym = ^tlabelsym;
  60. tlabelsym = object(tstoredsym)
  61. lab : pasmlabel;
  62. used,
  63. defined : boolean;
  64. code : pointer; { should be ptree! }
  65. constructor init(const n : string; l : pasmlabel);
  66. destructor done;virtual;
  67. constructor load;
  68. function mangledname : string;virtual;
  69. procedure write;virtual;
  70. end;
  71. punitsym = ^tunitsym;
  72. tunitsym = object(tstoredsym)
  73. unitsymtable : psymtable;
  74. prevsym : punitsym;
  75. constructor init(const n : string;ref : psymtable);
  76. constructor load;
  77. destructor done;virtual;
  78. procedure write;virtual;
  79. procedure restoreunitsym;
  80. {$ifdef GDB}
  81. procedure concatstabto(asmlist : paasmoutput);virtual;
  82. {$endif GDB}
  83. end;
  84. perrorsym = ^terrorsym;
  85. terrorsym = object(tstoredsym)
  86. constructor init;
  87. end;
  88. pprocsym = ^tprocsym;
  89. tprocsym = object(tstoredsym)
  90. definition : pprocdef;
  91. {$ifdef CHAINPROCSYMS}
  92. nextprocsym : pprocsym;
  93. {$endif CHAINPROCSYMS}
  94. is_global : boolean;
  95. constructor init(const n : string);
  96. constructor load;
  97. destructor done;virtual;
  98. function mangledname : string;virtual;
  99. { writes all declarations except the specified one }
  100. procedure write_parameter_lists(skipdef:pprocdef);
  101. { tests, if all procedures definitions are defined and not }
  102. { only forward }
  103. procedure check_forward;
  104. procedure order_overloaded;
  105. procedure write;virtual;
  106. procedure deref;virtual;
  107. procedure load_references;virtual;
  108. function write_references : boolean;virtual;
  109. {$ifdef GDB}
  110. function stabstring : pchar;virtual;
  111. procedure concatstabto(asmlist : paasmoutput);virtual;
  112. {$endif GDB}
  113. end;
  114. ptypesym = ^ttypesym;
  115. ttypesym = object(tstoredsym)
  116. {$ifdef SYNONYM}
  117. synonym : ptypesym;
  118. {$endif}
  119. restype : ttype;
  120. {$ifdef GDB}
  121. isusedinstab : boolean;
  122. {$endif GDB}
  123. constructor init(const n : string;const tt : ttype);
  124. constructor initdef(const n : string;d : pdef);
  125. constructor load;
  126. {$ifdef SYNONYM}
  127. destructor done;virtual;
  128. {$endif}
  129. procedure write;virtual;
  130. function gettypedef:pdef;virtual;
  131. procedure prederef;virtual;
  132. procedure load_references;virtual;
  133. function write_references : boolean;virtual;
  134. {$ifdef GDB}
  135. function stabstring : pchar;virtual;
  136. procedure concatstabto(asmlist : paasmoutput);virtual;
  137. {$endif GDB}
  138. end;
  139. pvarsym = ^tvarsym;
  140. tvarsym = object(tstoredsym)
  141. address : longint;
  142. localvarsym : pvarsym;
  143. vartype : ttype;
  144. varoptions : tvaroptions;
  145. reg : tregister; { if reg<>R_NO, then the variable is an register variable }
  146. varspez : tvarspez; { sets the type of access }
  147. varstate : tvarstate;
  148. constructor init(const n : string;const tt : ttype);
  149. constructor init_dll(const n : string;const tt : ttype);
  150. constructor init_C(const n,mangled : string;const tt : ttype);
  151. constructor initdef(const n : string;p : pdef);
  152. constructor load;
  153. destructor done;virtual;
  154. procedure write;virtual;
  155. procedure deref;virtual;
  156. procedure setmangledname(const s : string);
  157. function mangledname : string;virtual;
  158. procedure insert_in_data;virtual;
  159. function getsize : longint;
  160. function getvaluesize : longint;
  161. function getpushsize : longint;
  162. {$ifdef GDB}
  163. function stabstring : pchar;virtual;
  164. procedure concatstabto(asmlist : paasmoutput);virtual;
  165. {$endif GDB}
  166. private
  167. _mangledname : pchar;
  168. end;
  169. ppropertysym = ^tpropertysym;
  170. tpropertysym = object(tstoredsym)
  171. propoptions : tpropertyoptions;
  172. propoverriden : ppropertysym;
  173. proptype,
  174. indextype : ttype;
  175. index,
  176. default : longint;
  177. readaccess,
  178. writeaccess,
  179. storedaccess : psymlist;
  180. constructor init(const n : string);
  181. destructor done;virtual;
  182. constructor load;
  183. function getsize : longint;virtual;
  184. procedure write;virtual;
  185. function gettypedef:pdef;virtual;
  186. procedure deref;virtual;
  187. procedure dooverride(overriden:ppropertysym);
  188. {$ifdef GDB}
  189. function stabstring : pchar;virtual;
  190. procedure concatstabto(asmlist : paasmoutput);virtual;
  191. {$endif GDB}
  192. end;
  193. pfuncretsym = ^tfuncretsym;
  194. tfuncretsym = object(tstoredsym)
  195. funcretprocinfo : pointer{ should be pprocinfo};
  196. rettype : ttype;
  197. address : longint;
  198. constructor init(const n : string;approcinfo : pointer{pprocinfo});
  199. constructor load;
  200. destructor done;virtual;
  201. procedure write;virtual;
  202. procedure deref;virtual;
  203. procedure insert_in_data;virtual;
  204. {$ifdef GDB}
  205. procedure concatstabto(asmlist : paasmoutput);virtual;
  206. {$endif GDB}
  207. end;
  208. pabsolutesym = ^tabsolutesym;
  209. tabsolutesym = object(tvarsym)
  210. abstyp : absolutetyp;
  211. absseg : boolean;
  212. ref : pstoredsym;
  213. asmname : pstring;
  214. constructor init(const n : string;const tt : ttype);
  215. constructor initdef(const n : string;p : pdef);
  216. constructor load;
  217. procedure deref;virtual;
  218. function mangledname : string;virtual;
  219. procedure write;virtual;
  220. procedure insert_in_data;virtual;
  221. {$ifdef GDB}
  222. procedure concatstabto(asmlist : paasmoutput);virtual;
  223. {$endif GDB}
  224. end;
  225. ptypedconstsym = ^ttypedconstsym;
  226. ttypedconstsym = object(tstoredsym)
  227. prefix : pstring;
  228. typedconsttype : ttype;
  229. is_really_const : boolean;
  230. constructor init(const n : string;p : pdef;really_const : boolean);
  231. constructor inittype(const n : string;const tt : ttype;really_const : boolean);
  232. constructor load;
  233. destructor done;virtual;
  234. function mangledname : string;virtual;
  235. procedure write;virtual;
  236. procedure deref;virtual;
  237. function getsize:longint;
  238. procedure insert_in_data;virtual;
  239. {$ifdef GDB}
  240. function stabstring : pchar;virtual;
  241. {$endif GDB}
  242. end;
  243. pconstsym = ^tconstsym;
  244. tconstsym = object(tstoredsym)
  245. consttype : ttype;
  246. consttyp : tconsttyp;
  247. resstrindex, { needed for resource strings }
  248. value : tconstexprint;
  249. len : longint; { len is needed for string length }
  250. constructor init(const n : string;t : tconsttyp;v : tconstexprint);
  251. constructor init_def(const n : string;t : tconsttyp;v : tconstexprint;def : pdef);
  252. constructor init_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  253. constructor load;
  254. destructor done;virtual;
  255. function mangledname : string;virtual;
  256. procedure deref;virtual;
  257. procedure write;virtual;
  258. {$ifdef GDB}
  259. function stabstring : pchar;virtual;
  260. procedure concatstabto(asmlist : paasmoutput);virtual;
  261. {$endif GDB}
  262. end;
  263. penumsym = ^tenumsym;
  264. tenumsym = object(tstoredsym)
  265. value : longint;
  266. definition : penumdef;
  267. nextenum : penumsym;
  268. constructor init(const n : string;def : penumdef;v : longint);
  269. constructor load;
  270. procedure write;virtual;
  271. procedure deref;virtual;
  272. procedure order;
  273. {$ifdef GDB}
  274. procedure concatstabto(asmlist : paasmoutput);virtual;
  275. {$endif GDB}
  276. end;
  277. psyssym = ^tsyssym;
  278. tsyssym = object(tstoredsym)
  279. number : longint;
  280. constructor init(const n : string;l : longint);
  281. constructor load;
  282. destructor done;virtual;
  283. procedure write;virtual;
  284. {$ifdef GDB}
  285. procedure concatstabto(asmlist : paasmoutput);virtual;
  286. {$endif GDB}
  287. end;
  288. { register variables }
  289. pregvarinfo = ^tregvarinfo;
  290. tregvarinfo = record
  291. regvars : array[1..maxvarregs] of pvarsym;
  292. regvars_para : array[1..maxvarregs] of boolean;
  293. regvars_refs : array[1..maxvarregs] of longint;
  294. fpuregvars : array[1..maxfpuvarregs] of pvarsym;
  295. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  296. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  297. end;
  298. var
  299. aktprocsym : pprocsym; { pointer to the symbol for the
  300. currently be parsed procedure }
  301. aktcallprocsym : pprocsym; { pointer to the symbol for the
  302. currently be called procedure,
  303. only set/unset in firstcall }
  304. aktvarsym : pvarsym; { pointer to the symbol for the
  305. currently read var, only used
  306. for variable directives }
  307. generrorsym : psym;
  308. procprefix : string; { prefix generated for the current compiled proc }
  309. const
  310. current_object_option : tsymoptions = [sp_public];
  311. implementation
  312. uses
  313. {$ifdef Delphi}
  314. sysutils,
  315. {$else Delphi}
  316. strings,
  317. {$endif Delphi}
  318. { global }
  319. globtype,globals,verbose,
  320. { target }
  321. systems,
  322. { symtable }
  323. symtable,types,
  324. {$ifdef GDB}
  325. gdb,
  326. {$endif GDB}
  327. { aasm }
  328. cpuasm,
  329. { module }
  330. fmodule,
  331. { ppu }
  332. symppu,ppu,
  333. { codegen }
  334. hcodegen,cresstr
  335. ;
  336. {****************************************************************************
  337. TSYM (base for all symtypes)
  338. ****************************************************************************}
  339. constructor tstoredsym.init(const n : string);
  340. begin
  341. inherited init(n);
  342. symoptions:=current_object_option;
  343. {$ifdef GDB}
  344. isstabwritten := false;
  345. {$endif GDB}
  346. fileinfo:=akttokenpos;
  347. defref:=nil;
  348. refs:=0;
  349. lastwritten:=nil;
  350. refcount:=0;
  351. if (cs_browser in aktmoduleswitches) and make_ref then
  352. begin
  353. defref:=new(pref,init(defref,@akttokenpos));
  354. inc(refcount);
  355. end;
  356. lastref:=defref;
  357. end;
  358. constructor tstoredsym.load;
  359. var
  360. s : string;
  361. begin
  362. indexnr:=readword;
  363. s:=readstring;
  364. inherited init(s);
  365. readsmallset(symoptions);
  366. readposinfo(fileinfo);
  367. lastref:=nil;
  368. defref:=nil;
  369. refs:=0;
  370. lastwritten:=nil;
  371. refcount:=0;
  372. {$ifdef GDB}
  373. isstabwritten := false;
  374. {$endif GDB}
  375. end;
  376. procedure tstoredsym.load_references;
  377. var
  378. pos : tfileposinfo;
  379. move_last : boolean;
  380. begin
  381. move_last:=lastwritten=lastref;
  382. while (not current_ppu^.endofentry) do
  383. begin
  384. readposinfo(pos);
  385. inc(refcount);
  386. lastref:=new(pref,init(lastref,@pos));
  387. lastref^.is_written:=true;
  388. if refcount=1 then
  389. defref:=lastref;
  390. end;
  391. if move_last then
  392. lastwritten:=lastref;
  393. end;
  394. { big problem here :
  395. wrong refs were written because of
  396. interface parsing of other units PM
  397. moduleindex must be checked !! }
  398. function tstoredsym.write_references : boolean;
  399. var
  400. ref : pref;
  401. symref_written,move_last : boolean;
  402. begin
  403. write_references:=false;
  404. if lastwritten=lastref then
  405. exit;
  406. { should we update lastref }
  407. move_last:=true;
  408. symref_written:=false;
  409. { write symbol refs }
  410. if assigned(lastwritten) then
  411. ref:=lastwritten
  412. else
  413. ref:=defref;
  414. while assigned(ref) do
  415. begin
  416. if ref^.moduleindex=current_module^.unit_index then
  417. begin
  418. { write address to this symbol }
  419. if not symref_written then
  420. begin
  421. writederef(@self);
  422. symref_written:=true;
  423. end;
  424. writeposinfo(ref^.posinfo);
  425. ref^.is_written:=true;
  426. if move_last then
  427. lastwritten:=ref;
  428. end
  429. else if not ref^.is_written then
  430. move_last:=false
  431. else if move_last then
  432. lastwritten:=ref;
  433. ref:=ref^.nextref;
  434. end;
  435. if symref_written then
  436. current_ppu^.writeentry(ibsymref);
  437. write_references:=symref_written;
  438. end;
  439. destructor tstoredsym.done;
  440. begin
  441. if assigned(defref) then
  442. begin
  443. defref^.freechain;
  444. dispose(defref,done);
  445. end;
  446. inherited done;
  447. end;
  448. procedure tstoredsym.write;
  449. begin
  450. writeword(indexnr);
  451. writestring(_realname^);
  452. writesmallset(symoptions);
  453. writeposinfo(fileinfo);
  454. end;
  455. function tstoredsym.mangledname : string;
  456. begin
  457. mangledname:=name;
  458. end;
  459. { for most symbol types there is nothing to do at all }
  460. procedure tstoredsym.insert_in_data;
  461. begin
  462. end;
  463. {$ifdef GDB}
  464. function tstoredsym.stabstring : pchar;
  465. begin
  466. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  467. tostr(fileinfo.line)+',0');
  468. end;
  469. procedure tstoredsym.concatstabto(asmlist : paasmoutput);
  470. var stab_str : pchar;
  471. begin
  472. if not isstabwritten then
  473. begin
  474. stab_str := stabstring;
  475. { count_dbx(stab_str); moved to GDB.PAS }
  476. asmlist^.concat(new(pai_stabs,init(stab_str)));
  477. isstabwritten:=true;
  478. end;
  479. end;
  480. {$endif GDB}
  481. {****************************************************************************
  482. TLABELSYM
  483. ****************************************************************************}
  484. constructor tlabelsym.init(const n : string; l : pasmlabel);
  485. begin
  486. inherited init(n);
  487. typ:=labelsym;
  488. lab:=l;
  489. used:=false;
  490. defined:=false;
  491. code:=nil;
  492. end;
  493. constructor tlabelsym.load;
  494. begin
  495. inherited load;
  496. typ:=labelsym;
  497. { this is all dummy
  498. it is only used for local browsing }
  499. lab:=nil;
  500. code:=nil;
  501. used:=false;
  502. defined:=true;
  503. end;
  504. destructor tlabelsym.done;
  505. begin
  506. inherited done;
  507. end;
  508. function tlabelsym.mangledname : string;
  509. begin
  510. mangledname:=lab^.name;
  511. end;
  512. procedure tlabelsym.write;
  513. begin
  514. if owner^.symtabletype in [unitsymtable,globalsymtable] then
  515. Message(sym_e_ill_label_decl)
  516. else
  517. begin
  518. inherited write;
  519. current_ppu^.writeentry(iblabelsym);
  520. end;
  521. end;
  522. {****************************************************************************
  523. TUNITSYM
  524. ****************************************************************************}
  525. constructor tunitsym.init(const n : string;ref : psymtable);
  526. var
  527. old_make_ref : boolean;
  528. begin
  529. old_make_ref:=make_ref;
  530. make_ref:=false;
  531. inherited init(n);
  532. make_ref:=old_make_ref;
  533. typ:=unitsym;
  534. unitsymtable:=ref;
  535. prevsym:=punitsymtable(ref)^.unitsym;
  536. punitsymtable(ref)^.unitsym:=@self;
  537. refs:=0;
  538. end;
  539. constructor tunitsym.load;
  540. begin
  541. inherited load;
  542. typ:=unitsym;
  543. unitsymtable:=punitsymtable(current_module^.globalsymtable);
  544. prevsym:=nil;
  545. end;
  546. { we need to remove it from the prevsym chain ! }
  547. procedure tunitsym.restoreunitsym;
  548. var pus,ppus : punitsym;
  549. begin
  550. if assigned(unitsymtable) then
  551. begin
  552. ppus:=nil;
  553. pus:=punitsymtable(unitsymtable)^.unitsym;
  554. if pus=@self then
  555. punitsymtable(unitsymtable)^.unitsym:=prevsym
  556. else while assigned(pus) do
  557. begin
  558. if pus=@self then
  559. begin
  560. ppus^.prevsym:=prevsym;
  561. break;
  562. end
  563. else
  564. begin
  565. ppus:=pus;
  566. pus:=ppus^.prevsym;
  567. end;
  568. end;
  569. end;
  570. prevsym:=nil;
  571. end;
  572. destructor tunitsym.done;
  573. begin
  574. restoreunitsym;
  575. inherited done;
  576. end;
  577. procedure tunitsym.write;
  578. begin
  579. inherited write;
  580. current_ppu^.writeentry(ibunitsym);
  581. end;
  582. {$ifdef GDB}
  583. procedure tunitsym.concatstabto(asmlist : paasmoutput);
  584. begin
  585. {Nothing to write to stabs !}
  586. end;
  587. {$endif GDB}
  588. {****************************************************************************
  589. TPROCSYM
  590. ****************************************************************************}
  591. constructor tprocsym.init(const n : string);
  592. begin
  593. inherited init(n);
  594. typ:=procsym;
  595. definition:=nil;
  596. owner:=nil;
  597. is_global := false;
  598. end;
  599. constructor tprocsym.load;
  600. begin
  601. inherited load;
  602. typ:=procsym;
  603. definition:=pprocdef(readderef);
  604. is_global := false;
  605. end;
  606. destructor tprocsym.done;
  607. begin
  608. { don't check if errors !! }
  609. if Errorcount=0 then
  610. check_forward;
  611. inherited done;
  612. end;
  613. function tprocsym.mangledname : string;
  614. begin
  615. mangledname:=definition^.mangledname;
  616. end;
  617. procedure tprocsym.write_parameter_lists(skipdef:pprocdef);
  618. var
  619. p : pprocdef;
  620. begin
  621. p:=definition;
  622. while assigned(p) do
  623. begin
  624. if p<>skipdef then
  625. MessagePos1(p^.fileinfo,sym_b_param_list,p^.fullprocname);
  626. p:=p^.nextoverloaded;
  627. end;
  628. end;
  629. procedure tprocsym.check_forward;
  630. var
  631. pd : pprocdef;
  632. begin
  633. pd:=definition;
  634. while assigned(pd) do
  635. begin
  636. if pd^.forwarddef then
  637. begin
  638. MessagePos1(fileinfo,sym_e_forward_not_resolved,pd^.fullprocname);
  639. { Turn futher error messages off }
  640. pd^.forwarddef:=false;
  641. end;
  642. pd:=pd^.nextoverloaded;
  643. { do not check defs of operators in other units }
  644. if assigned(pd) and (pd^.procsym<>@self) then
  645. pd:=nil;
  646. end;
  647. end;
  648. procedure tprocsym.deref;
  649. var
  650. {$ifdef DONOTCHAINOPERATORS}
  651. t : ttoken;
  652. last : pprocdef;
  653. {$endif DONOTCHAINOPERATORS}
  654. pd : pprocdef;
  655. begin
  656. resolvedef(pdef(definition));
  657. pd:=definition;
  658. while assigned(pd) do
  659. begin
  660. pd^.procsym:=@self;
  661. pd:=pd^.nextoverloaded;
  662. end;
  663. {$ifdef DONOTCHAINOPERATORS}
  664. if (definition^.proctypeoption=potype_operator) then
  665. begin
  666. last:=definition;
  667. while assigned(last^.nextoverloaded) do
  668. last:=last^.nextoverloaded;
  669. for t:=first_overloaded to last_overloaded do
  670. if (name=overloaded_names[t]) then
  671. begin
  672. if assigned(overloaded_operators[t]) then
  673. begin
  674. pd:=overloaded_operators[t]^.definition;
  675. { test if not already in list, bug report by KC Wong PM }
  676. while assigned(pd) do
  677. if pd=last then
  678. break
  679. else
  680. pd:=pd^.nextoverloaded;
  681. if pd=last then
  682. break;
  683. last^.nextoverloaded:=overloaded_operators[t]^.definition;
  684. end;
  685. overloaded_operators[t]:=@self;
  686. break;
  687. end;
  688. end;
  689. {$endif DONOTCHAINOPERATORS}
  690. end;
  691. procedure tprocsym.order_overloaded;
  692. var firstdef,currdef,lastdef,nextopdef : pprocdef;
  693. begin
  694. if not assigned(definition) then
  695. exit;
  696. firstdef:=definition;
  697. currdef:=definition;
  698. while assigned(currdef) and (currdef^.owner=firstdef^.owner) do
  699. begin
  700. currdef^.count:=false;
  701. currdef:=currdef^.nextoverloaded;
  702. end;
  703. nextopdef:=currdef;
  704. definition:=definition^.nextoverloaded;
  705. firstdef^.nextoverloaded:=nil;
  706. while (definition<>nextopdef) do
  707. begin
  708. currdef:=firstdef;
  709. lastdef:=definition;
  710. definition:=definition^.nextoverloaded;
  711. if lastdef^.mangledname<firstdef^.mangledname then
  712. begin
  713. lastdef^.nextoverloaded:=firstdef;
  714. firstdef:=lastdef;
  715. end
  716. else
  717. begin
  718. while assigned(currdef^.nextoverloaded) and
  719. (lastdef^.mangledname>currdef^.nextoverloaded^.mangledname) do
  720. currdef:=currdef^.nextoverloaded;
  721. lastdef^.nextoverloaded:=currdef^.nextoverloaded;
  722. currdef^.nextoverloaded:=lastdef;
  723. end;
  724. end;
  725. definition:=firstdef;
  726. currdef:=definition;
  727. while assigned(currdef) do
  728. begin
  729. currdef^.count:=true;
  730. lastdef:=currdef;
  731. currdef:=currdef^.nextoverloaded;
  732. end;
  733. lastdef^.nextoverloaded:=nextopdef;
  734. end;
  735. procedure tprocsym.write;
  736. begin
  737. inherited write;
  738. writederef(definition);
  739. current_ppu^.writeentry(ibprocsym);
  740. end;
  741. procedure tprocsym.load_references;
  742. (*var
  743. prdef,prdef2 : pprocdef;
  744. b : byte; *)
  745. begin
  746. inherited load_references;
  747. (*prdef:=definition;
  748. done in tsymtable.load_browser (PM)
  749. { take care about operators !! }
  750. if (current_module^.flags and uf_has_browser) <>0 then
  751. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  752. begin
  753. b:=current_ppu^.readentry;
  754. if b<>ibdefref then
  755. Message(unit_f_ppu_read_error);
  756. prdef2:=pprocdef(readdefref);
  757. resolvedef(prdef2);
  758. if prdef<>prdef2 then
  759. Message(unit_f_ppu_read_error);
  760. prdef^.load_references;
  761. prdef:=prdef^.nextoverloaded;
  762. end; *)
  763. end;
  764. function tprocsym.write_references : boolean;
  765. var
  766. prdef : pprocdef;
  767. begin
  768. write_references:=false;
  769. if not inherited write_references then
  770. exit;
  771. write_references:=true;
  772. prdef:=definition;
  773. while assigned(prdef) and (prdef^.owner=definition^.owner) do
  774. begin
  775. prdef^.write_references;
  776. prdef:=prdef^.nextoverloaded;
  777. end;
  778. end;
  779. {$ifdef GDB}
  780. function tprocsym.stabstring : pchar;
  781. Var RetType : Char;
  782. Obj,Info : String;
  783. stabsstr : string;
  784. p : pchar;
  785. begin
  786. obj := name;
  787. info := '';
  788. if is_global then
  789. RetType := 'F'
  790. else
  791. RetType := 'f';
  792. if assigned(owner) then
  793. begin
  794. if (owner^.symtabletype = objectsymtable) then
  795. obj := upper(owner^.name^)+'__'+name;
  796. { this code was correct only as long as the local symboltable
  797. of the parent had the same name as the function
  798. but this is no true anymore !! PM
  799. if (owner^.symtabletype=localsymtable) and assigned(owner^.name) then
  800. info := ','+name+','+owner^.name^; }
  801. if (owner^.symtabletype=localsymtable) and assigned(owner^.defowner) and
  802. assigned(pprocdef(owner^.defowner)^.procsym) then
  803. info := ','+name+','+pprocdef(owner^.defowner)^.procsym^.name;
  804. end;
  805. stabsstr:=definition^.mangledname;
  806. getmem(p,length(stabsstr)+255);
  807. strpcopy(p,'"'+obj+':'+RetType
  808. +pstoreddef(definition^.rettype.def)^.numberstring+info+'",'+tostr(n_function)
  809. +',0,'+
  810. tostr(aktfilepos.line)
  811. +',');
  812. strpcopy(strend(p),stabsstr);
  813. stabstring:=strnew(p);
  814. freemem(p,length(stabsstr)+255);
  815. end;
  816. procedure tprocsym.concatstabto(asmlist : paasmoutput);
  817. begin
  818. if (pocall_internproc in definition^.proccalloptions) then exit;
  819. if not isstabwritten then
  820. asmlist^.concat(new(pai_stabs,init(stabstring)));
  821. isstabwritten := true;
  822. if assigned(definition^.parast) then
  823. pstoredsymtable(definition^.parast)^.concatstabto(asmlist);
  824. { local type defs and vars should not be written
  825. inside the main proc stab }
  826. if assigned(definition^.localst) and
  827. (lexlevel>main_program_level) then
  828. pstoredsymtable(definition^.localst)^.concatstabto(asmlist);
  829. definition^.is_def_stab_written := written;
  830. end;
  831. {$endif GDB}
  832. {****************************************************************************
  833. TERRORSYM
  834. ****************************************************************************}
  835. constructor terrorsym.init;
  836. begin
  837. inherited init('');
  838. typ:=errorsym;
  839. end;
  840. {****************************************************************************
  841. TPROPERTYSYM
  842. ****************************************************************************}
  843. constructor tpropertysym.init(const n : string);
  844. begin
  845. inherited init(n);
  846. typ:=propertysym;
  847. propoptions:=[];
  848. index:=0;
  849. default:=0;
  850. proptype.reset;
  851. indextype.reset;
  852. new(readaccess,init);
  853. new(writeaccess,init);
  854. new(storedaccess,init);
  855. end;
  856. constructor tpropertysym.load;
  857. begin
  858. inherited load;
  859. typ:=propertysym;
  860. readsmallset(propoptions);
  861. if (ppo_is_override in propoptions) then
  862. begin
  863. propoverriden:=ppropertysym(readderef);
  864. { we need to have these objects initialized }
  865. new(readaccess,init);
  866. new(writeaccess,init);
  867. new(storedaccess,init);
  868. end
  869. else
  870. begin
  871. proptype.load;
  872. index:=readlong;
  873. default:=readlong;
  874. indextype.load;
  875. new(readaccess,load);
  876. new(writeaccess,load);
  877. new(storedaccess,load);
  878. end;
  879. end;
  880. destructor tpropertysym.done;
  881. begin
  882. dispose(readaccess,done);
  883. dispose(writeaccess,done);
  884. dispose(storedaccess,done);
  885. inherited done;
  886. end;
  887. function tpropertysym.gettypedef:pdef;
  888. begin
  889. gettypedef:=proptype.def;
  890. end;
  891. procedure tpropertysym.deref;
  892. begin
  893. if (ppo_is_override in propoptions) then
  894. begin
  895. resolvesym(psym(propoverriden));
  896. dooverride(propoverriden);
  897. end
  898. else
  899. begin
  900. proptype.resolve;
  901. indextype.resolve;
  902. readaccess^.resolve;
  903. writeaccess^.resolve;
  904. storedaccess^.resolve;
  905. end;
  906. end;
  907. function tpropertysym.getsize : longint;
  908. begin
  909. getsize:=0;
  910. end;
  911. procedure tpropertysym.write;
  912. begin
  913. inherited write;
  914. writesmallset(propoptions);
  915. if (ppo_is_override in propoptions) then
  916. writederef(propoverriden)
  917. else
  918. begin
  919. proptype.write;
  920. writelong(index);
  921. writelong(default);
  922. indextype.write;
  923. readaccess^.write;
  924. writeaccess^.write;
  925. storedaccess^.write;
  926. end;
  927. current_ppu^.writeentry(ibpropertysym);
  928. end;
  929. procedure tpropertysym.dooverride(overriden:ppropertysym);
  930. begin
  931. propoverriden:=overriden;
  932. proptype:=overriden^.proptype;
  933. propoptions:=overriden^.propoptions+[ppo_is_override];
  934. index:=overriden^.index;
  935. default:=overriden^.default;
  936. indextype:=overriden^.indextype;
  937. readaccess^.clear;
  938. readaccess:=overriden^.readaccess^.getcopy;
  939. writeaccess^.clear;
  940. writeaccess:=overriden^.writeaccess^.getcopy;
  941. storedaccess^.clear;
  942. storedaccess:=overriden^.storedaccess^.getcopy;
  943. end;
  944. {$ifdef GDB}
  945. function tpropertysym.stabstring : pchar;
  946. begin
  947. { !!!! don't know how to handle }
  948. stabstring:=strpnew('');
  949. end;
  950. procedure tpropertysym.concatstabto(asmlist : paasmoutput);
  951. begin
  952. { !!!! don't know how to handle }
  953. end;
  954. {$endif GDB}
  955. {****************************************************************************
  956. TFUNCRETSYM
  957. ****************************************************************************}
  958. constructor tfuncretsym.init(const n : string;approcinfo : pointer{pprocinfo});
  959. begin
  960. inherited init(n);
  961. typ:=funcretsym;
  962. funcretprocinfo:=approcinfo;
  963. rettype:=pprocinfo(approcinfo)^.returntype;
  964. { address valid for ret in param only }
  965. { otherwise set by insert }
  966. address:=pprocinfo(approcinfo)^.return_offset;
  967. end;
  968. constructor tfuncretsym.load;
  969. begin
  970. inherited load;
  971. rettype.load;
  972. address:=readlong;
  973. funcretprocinfo:=nil;
  974. typ:=funcretsym;
  975. end;
  976. destructor tfuncretsym.done;
  977. begin
  978. inherited done;
  979. end;
  980. procedure tfuncretsym.write;
  981. begin
  982. inherited write;
  983. rettype.write;
  984. writelong(address);
  985. current_ppu^.writeentry(ibfuncretsym);
  986. end;
  987. procedure tfuncretsym.deref;
  988. begin
  989. rettype.resolve;
  990. end;
  991. {$ifdef GDB}
  992. procedure tfuncretsym.concatstabto(asmlist : paasmoutput);
  993. begin
  994. { Nothing to do here, it is done in genexitcode }
  995. end;
  996. {$endif GDB}
  997. procedure tfuncretsym.insert_in_data;
  998. var
  999. l : longint;
  1000. begin
  1001. { if retoffset is already set then reuse it, this is needed
  1002. when inserting the result variable }
  1003. if procinfo^.return_offset<>0 then
  1004. address:=procinfo^.return_offset
  1005. else
  1006. begin
  1007. { allocate space in local if ret in acc or in fpu }
  1008. if ret_in_acc(procinfo^.returntype.def) or (procinfo^.returntype.def^.deftype=floatdef) then
  1009. begin
  1010. l:=rettype.def^.size;
  1011. inc(owner^.datasize,l);
  1012. {$ifdef m68k}
  1013. { word alignment required for motorola }
  1014. if (l=1) then
  1015. inc(owner^.datasize,1)
  1016. else
  1017. {$endif}
  1018. if (l>=4) and ((owner^.datasize and 3)<>0) then
  1019. inc(owner^.datasize,4-(owner^.datasize and 3))
  1020. else if (l>=2) and ((owner^.datasize and 1)<>0) then
  1021. inc(owner^.datasize,2-(owner^.datasize and 1));
  1022. address:=owner^.datasize;
  1023. procinfo^.return_offset:=-owner^.datasize;
  1024. end;
  1025. end;
  1026. end;
  1027. {****************************************************************************
  1028. TABSOLUTESYM
  1029. ****************************************************************************}
  1030. constructor tabsolutesym.init(const n : string;const tt : ttype);
  1031. begin
  1032. inherited init(n,tt);
  1033. typ:=absolutesym;
  1034. end;
  1035. constructor tabsolutesym.initdef(const n : string;p : pdef);
  1036. var
  1037. t : ttype;
  1038. begin
  1039. t.setdef(p);
  1040. tabsolutesym.init(n,t);
  1041. end;
  1042. constructor tabsolutesym.load;
  1043. begin
  1044. tvarsym.load;
  1045. typ:=absolutesym;
  1046. ref:=nil;
  1047. address:=0;
  1048. asmname:=nil;
  1049. abstyp:=absolutetyp(readbyte);
  1050. absseg:=false;
  1051. case abstyp of
  1052. tovar :
  1053. begin
  1054. asmname:=stringdup(readstring);
  1055. ref:=pstoredsym(srsym);
  1056. end;
  1057. toasm :
  1058. asmname:=stringdup(readstring);
  1059. toaddr :
  1060. begin
  1061. address:=readlong;
  1062. absseg:=boolean(readbyte);
  1063. end;
  1064. end;
  1065. end;
  1066. procedure tabsolutesym.write;
  1067. var
  1068. hvo : tvaroptions;
  1069. begin
  1070. { Note: This needs to write everything of tvarsym.write }
  1071. tstoredsym.write;
  1072. writebyte(byte(varspez));
  1073. if read_member then
  1074. writelong(address);
  1075. { write only definition or definitionsym }
  1076. vartype.write;
  1077. hvo:=varoptions-[vo_regable];
  1078. writesmallset(hvo);
  1079. writebyte(byte(abstyp));
  1080. case abstyp of
  1081. tovar :
  1082. writestring(ref^.name);
  1083. toasm :
  1084. writestring(asmname^);
  1085. toaddr :
  1086. begin
  1087. writelong(address);
  1088. writebyte(byte(absseg));
  1089. end;
  1090. end;
  1091. current_ppu^.writeentry(ibabsolutesym);
  1092. end;
  1093. procedure tabsolutesym.deref;
  1094. begin
  1095. tvarsym.deref;
  1096. if (abstyp=tovar) and (asmname<>nil) then
  1097. begin
  1098. { search previous loaded symtables }
  1099. getsym(asmname^,false);
  1100. if not(assigned(srsym)) then
  1101. getsymonlyin(owner,asmname^);
  1102. if not(assigned(srsym)) then
  1103. srsym:=generrorsym;
  1104. ref:=pstoredsym(srsym);
  1105. stringdispose(asmname);
  1106. end;
  1107. end;
  1108. function tabsolutesym.mangledname : string;
  1109. begin
  1110. case abstyp of
  1111. tovar :
  1112. mangledname:=ref^.mangledname;
  1113. toasm :
  1114. mangledname:=asmname^;
  1115. toaddr :
  1116. mangledname:='$'+tostr(address);
  1117. else
  1118. internalerror(10002);
  1119. end;
  1120. end;
  1121. procedure tabsolutesym.insert_in_data;
  1122. begin
  1123. end;
  1124. {$ifdef GDB}
  1125. procedure tabsolutesym.concatstabto(asmlist : paasmoutput);
  1126. begin
  1127. { I don't know how to handle this !! }
  1128. end;
  1129. {$endif GDB}
  1130. {****************************************************************************
  1131. TVARSYM
  1132. ****************************************************************************}
  1133. constructor tvarsym.init(const n : string;const tt : ttype);
  1134. begin
  1135. inherited init(n);
  1136. typ:=varsym;
  1137. vartype:=tt;
  1138. _mangledname:=nil;
  1139. varspez:=vs_value;
  1140. address:=0;
  1141. localvarsym:=nil;
  1142. refs:=0;
  1143. varstate:=vs_used;
  1144. varoptions:=[];
  1145. { can we load the value into a register ? }
  1146. if pstoreddef(tt.def)^.is_intregable then
  1147. include(varoptions,vo_regable)
  1148. else
  1149. exclude(varoptions,vo_regable);
  1150. if pstoreddef(tt.def)^.is_fpuregable then
  1151. include(varoptions,vo_fpuregable)
  1152. else
  1153. exclude(varoptions,vo_fpuregable);
  1154. reg:=R_NO;
  1155. end;
  1156. constructor tvarsym.init_dll(const n : string;const tt : ttype);
  1157. begin
  1158. tvarsym.init(n,tt);
  1159. include(varoptions,vo_is_dll_var);
  1160. end;
  1161. constructor tvarsym.init_C(const n,mangled : string;const tt : ttype);
  1162. begin
  1163. tvarsym.init(n,tt);
  1164. include(varoptions,vo_is_C_var);
  1165. setmangledname(mangled);
  1166. end;
  1167. constructor tvarsym.initdef(const n : string;p : pdef);
  1168. var
  1169. t : ttype;
  1170. begin
  1171. t.setdef(p);
  1172. tvarsym.init(n,t);
  1173. end;
  1174. constructor tvarsym.load;
  1175. begin
  1176. inherited load;
  1177. typ:=varsym;
  1178. _mangledname:=nil;
  1179. reg:=R_NO;
  1180. refs := 0;
  1181. varstate:=vs_used;
  1182. varspez:=tvarspez(readbyte);
  1183. if read_member then
  1184. address:=readlong
  1185. else
  1186. address:=0;
  1187. localvarsym:=nil;
  1188. vartype.load;
  1189. readsmallset(varoptions);
  1190. if (vo_is_C_var in varoptions) then
  1191. setmangledname(readstring);
  1192. end;
  1193. destructor tvarsym.done;
  1194. begin
  1195. strdispose(_mangledname);
  1196. inherited done;
  1197. end;
  1198. procedure tvarsym.deref;
  1199. begin
  1200. vartype.resolve;
  1201. end;
  1202. procedure tvarsym.write;
  1203. var
  1204. hvo : tvaroptions;
  1205. begin
  1206. inherited write;
  1207. writebyte(byte(varspez));
  1208. if read_member then
  1209. writelong(address);
  1210. vartype.write;
  1211. { symbols which are load are never candidates for a register,
  1212. turn off the regable }
  1213. hvo:=varoptions-[vo_regable];
  1214. writesmallset(hvo);
  1215. if (vo_is_C_var in varoptions) then
  1216. writestring(mangledname);
  1217. current_ppu^.writeentry(ibvarsym);
  1218. end;
  1219. procedure tvarsym.setmangledname(const s : string);
  1220. begin
  1221. _mangledname:=strpnew(s);
  1222. end;
  1223. function tvarsym.mangledname : string;
  1224. var
  1225. prefix : string;
  1226. begin
  1227. if assigned(_mangledname) then
  1228. begin
  1229. mangledname:=strpas(_mangledname);
  1230. exit;
  1231. end;
  1232. case owner^.symtabletype of
  1233. staticsymtable :
  1234. if (cs_create_smart in aktmoduleswitches) then
  1235. prefix:='_'+upper(owner^.name^)+'$$$_'
  1236. else
  1237. prefix:='_';
  1238. unitsymtable,
  1239. globalsymtable :
  1240. prefix:=
  1241. 'U_'+upper(owner^.name^)+'_';
  1242. else
  1243. Message(sym_e_invalid_call_tvarsymmangledname);
  1244. end;
  1245. mangledname:=prefix+name;
  1246. end;
  1247. function tvarsym.getsize : longint;
  1248. begin
  1249. if assigned(vartype.def) then
  1250. getsize:=vartype.def^.size
  1251. else
  1252. getsize:=0;
  1253. end;
  1254. function tvarsym.getvaluesize : longint;
  1255. begin
  1256. if assigned(vartype.def) and
  1257. (varspez=vs_value) and
  1258. ((vartype.def^.deftype<>arraydef) or
  1259. (Parraydef(vartype.def)^.highrange>=Parraydef(vartype.def)^.lowrange)) then
  1260. getvaluesize:=vartype.def^.size
  1261. else
  1262. getvaluesize:=0;
  1263. end;
  1264. function tvarsym.getpushsize : longint;
  1265. begin
  1266. if assigned(vartype.def) then
  1267. begin
  1268. case varspez of
  1269. vs_out,
  1270. vs_var :
  1271. getpushsize:=target_os.size_of_pointer;
  1272. vs_value,
  1273. vs_const :
  1274. begin
  1275. if push_addr_param(vartype.def) then
  1276. getpushsize:=target_os.size_of_pointer
  1277. else
  1278. getpushsize:=vartype.def^.size;
  1279. end;
  1280. end;
  1281. end
  1282. else
  1283. getpushsize:=0;
  1284. end;
  1285. function data_align(length : longint) : longint;
  1286. begin
  1287. (* this is useless under go32v2 at least
  1288. because the section are only align to dword
  1289. if length>8 then
  1290. data_align:=16
  1291. else if length>4 then
  1292. data_align:=8
  1293. else *)
  1294. if length>2 then
  1295. data_align:=4
  1296. else
  1297. if length>1 then
  1298. data_align:=2
  1299. else
  1300. data_align:=1;
  1301. end;
  1302. procedure tvarsym.insert_in_data;
  1303. var
  1304. varalign,
  1305. l,ali,modulo : longint;
  1306. storefilepos : tfileposinfo;
  1307. begin
  1308. if (vo_is_external in varoptions) then
  1309. exit;
  1310. { handle static variables of objects especially }
  1311. if read_member and (owner^.symtabletype=objectsymtable) and
  1312. (sp_static in symoptions) then
  1313. begin
  1314. { the data filed is generated in parser.pas
  1315. with a tobject_FIELDNAME variable }
  1316. { this symbol can't be loaded to a register }
  1317. exclude(varoptions,vo_regable);
  1318. exclude(varoptions,vo_fpuregable);
  1319. end
  1320. else
  1321. if not(read_member) then
  1322. begin
  1323. { made problems with parameters etc. ! (FK) }
  1324. { check for instance of an abstract object or class }
  1325. {
  1326. if (pvarsym(sym)^.definition^.deftype=objectdef) and
  1327. ((pobjectdef(pvarsym(sym)^.definition)^.options and oo_is_abstract)<>0) then
  1328. Message(sym_e_no_instance_of_abstract_object);
  1329. }
  1330. storefilepos:=aktfilepos;
  1331. aktfilepos:=akttokenpos;
  1332. if (vo_is_thread_var in varoptions) then
  1333. l:=4
  1334. else
  1335. l:=getvaluesize;
  1336. case owner^.symtabletype of
  1337. stt_exceptsymtable:
  1338. { can contain only one symbol, address calculated later }
  1339. ;
  1340. localsymtable :
  1341. begin
  1342. varstate:=vs_declared;
  1343. modulo:=owner^.datasize and 3;
  1344. {$ifdef m68k}
  1345. { word alignment required for motorola }
  1346. if (l=1) then
  1347. l:=2
  1348. else
  1349. {$endif}
  1350. {
  1351. if (cs_optimize in aktglobalswitches) and
  1352. (aktoptprocessor in [classp5,classp6]) and
  1353. (l>=8) and ((owner^.datasize and 7)<>0) then
  1354. inc(owner^.datasize,8-(owner^.datasize and 7))
  1355. else
  1356. }
  1357. begin
  1358. if (l>=4) and (modulo<>0) then
  1359. inc(l,4-modulo)
  1360. else
  1361. if (l>=2) and ((modulo and 1)<>0) then
  1362. inc(l,2-(modulo and 1));
  1363. end;
  1364. inc(owner^.datasize,l);
  1365. address:=owner^.datasize;
  1366. end;
  1367. staticsymtable :
  1368. begin
  1369. { enable unitialized warning for local symbols }
  1370. varstate:=vs_declared;
  1371. if (cs_create_smart in aktmoduleswitches) then
  1372. bsssegment^.concat(new(pai_cut,init));
  1373. ali:=data_align(l);
  1374. if ali>1 then
  1375. begin
  1376. modulo:=owner^.datasize mod ali;
  1377. if modulo>0 then
  1378. inc(owner^.datasize,ali-modulo);
  1379. end;
  1380. {$ifdef GDB}
  1381. if cs_debuginfo in aktmoduleswitches then
  1382. concatstabto(bsssegment);
  1383. {$endif GDB}
  1384. if (cs_create_smart in aktmoduleswitches) or
  1385. DLLSource or
  1386. (vo_is_exported in varoptions) or
  1387. (vo_is_C_var in varoptions) then
  1388. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)))
  1389. else
  1390. bsssegment^.concat(new(pai_datablock,init(mangledname,l)));
  1391. { increase datasize }
  1392. inc(owner^.datasize,l);
  1393. { this symbol can't be loaded to a register }
  1394. exclude(varoptions,vo_regable);
  1395. exclude(varoptions,vo_fpuregable);
  1396. end;
  1397. globalsymtable :
  1398. begin
  1399. if (cs_create_smart in aktmoduleswitches) then
  1400. bsssegment^.concat(new(pai_cut,init));
  1401. ali:=data_align(l);
  1402. if ali>1 then
  1403. begin
  1404. modulo:=owner^.datasize mod ali;
  1405. if modulo>0 then
  1406. inc(owner^.datasize,ali-modulo);
  1407. end;
  1408. {$ifdef GDB}
  1409. if cs_debuginfo in aktmoduleswitches then
  1410. concatstabto(bsssegment);
  1411. {$endif GDB}
  1412. bsssegment^.concat(new(pai_datablock,init_global(mangledname,l)));
  1413. inc(owner^.datasize,l);
  1414. { this symbol can't be loaded to a register }
  1415. exclude(varoptions,vo_regable);
  1416. exclude(varoptions,vo_fpuregable);
  1417. end;
  1418. recordsymtable,
  1419. objectsymtable :
  1420. begin
  1421. { this symbol can't be loaded to a register }
  1422. exclude(varoptions,vo_regable);
  1423. exclude(varoptions,vo_fpuregable);
  1424. { get the alignment size }
  1425. if (aktpackrecords=packrecord_C) then
  1426. begin
  1427. varalign:=vartype.def^.alignment;
  1428. if (varalign>4) and ((varalign mod 4)<>0) and
  1429. (vartype.def^.deftype=arraydef) then
  1430. begin
  1431. Message1(sym_w_wrong_C_pack,vartype.def^.typename);
  1432. end;
  1433. if varalign=0 then
  1434. varalign:=l;
  1435. if (owner^.dataalignment<target_os.maxCrecordalignment) then
  1436. begin
  1437. if (varalign>16) and (owner^.dataalignment<32) then
  1438. owner^.dataalignment:=32
  1439. else if (varalign>12) and (owner^.dataalignment<16) then
  1440. owner^.dataalignment:=16
  1441. { 12 is needed for long double }
  1442. else if (varalign>8) and (owner^.dataalignment<12) then
  1443. owner^.dataalignment:=12
  1444. else if (varalign>4) and (owner^.dataalignment<8) then
  1445. owner^.dataalignment:=8
  1446. else if (varalign>2) and (owner^.dataalignment<4) then
  1447. owner^.dataalignment:=4
  1448. else if (varalign>1) and (owner^.dataalignment<2) then
  1449. owner^.dataalignment:=2;
  1450. end;
  1451. if owner^.dataalignment>target_os.maxCrecordalignment then
  1452. owner^.dataalignment:=target_os.maxCrecordalignment;
  1453. end
  1454. else
  1455. varalign:=vartype.def^.alignment;
  1456. if varalign=0 then
  1457. varalign:=l;
  1458. { align record and object fields }
  1459. if (varalign=1) or (owner^.dataalignment=1) then
  1460. begin
  1461. address:=owner^.datasize;
  1462. inc(owner^.datasize,l)
  1463. end
  1464. else if (varalign=2) or (owner^.dataalignment=2) then
  1465. begin
  1466. owner^.datasize:=(owner^.datasize+1) and (not 1);
  1467. address:=owner^.datasize;
  1468. inc(owner^.datasize,l)
  1469. end
  1470. else if (varalign<=4) or (owner^.dataalignment=4) then
  1471. begin
  1472. owner^.datasize:=(owner^.datasize+3) and (not 3);
  1473. address:=owner^.datasize;
  1474. inc(owner^.datasize,l);
  1475. end
  1476. else if (varalign<=8) or (owner^.dataalignment=8) then
  1477. begin
  1478. owner^.datasize:=(owner^.datasize+7) and (not 7);
  1479. address:=owner^.datasize;
  1480. inc(owner^.datasize,l);
  1481. end
  1482. { 12 is needed for C long double support }
  1483. else if (varalign<=12) and (owner^.dataalignment=12) then
  1484. begin
  1485. owner^.datasize:=((owner^.datasize+11) div 12) * 12;
  1486. address:=owner^.datasize;
  1487. inc(owner^.datasize,l);
  1488. end
  1489. else if (varalign<=16) or (owner^.dataalignment=16) then
  1490. begin
  1491. owner^.datasize:=(owner^.datasize+15) and (not 15);
  1492. address:=owner^.datasize;
  1493. inc(owner^.datasize,l);
  1494. end
  1495. else if (varalign<=32) or (owner^.dataalignment=32) then
  1496. begin
  1497. owner^.datasize:=(owner^.datasize+31) and (not 31);
  1498. address:=owner^.datasize;
  1499. inc(owner^.datasize,l);
  1500. end
  1501. else
  1502. internalerror(1000022);
  1503. end;
  1504. parasymtable :
  1505. begin
  1506. { here we need the size of a push instead of the
  1507. size of the data }
  1508. l:=getpushsize;
  1509. varstate:=vs_assigned;
  1510. address:=owner^.datasize;
  1511. owner^.datasize:=align(owner^.datasize+l,target_os.stackalignment);
  1512. end
  1513. else
  1514. begin
  1515. modulo:=owner^.datasize and 3;
  1516. if (l>=4) and (modulo<>0) then
  1517. inc(owner^.datasize,4-modulo)
  1518. else
  1519. if (l>=2) and ((modulo and 1)<>0) then
  1520. inc(owner^.datasize);
  1521. address:=owner^.datasize;
  1522. inc(owner^.datasize,l);
  1523. end;
  1524. end;
  1525. aktfilepos:=storefilepos;
  1526. end;
  1527. end;
  1528. {$ifdef GDB}
  1529. function tvarsym.stabstring : pchar;
  1530. var
  1531. st : string;
  1532. begin
  1533. st:=pstoreddef(vartype.def)^.numberstring;
  1534. if (owner^.symtabletype = objectsymtable) and
  1535. (sp_static in symoptions) then
  1536. begin
  1537. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1538. stabstring := strpnew('"'+upper(owner^.name^)+'__'+name+':'+st+
  1539. '",'+
  1540. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1541. end
  1542. else if (owner^.symtabletype = globalsymtable) or
  1543. (owner^.symtabletype = unitsymtable) then
  1544. begin
  1545. { Here we used S instead of
  1546. because with G GDB doesn't look at the address field
  1547. but searches the same name or with a leading underscore
  1548. but these names don't exist in pascal !}
  1549. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1550. stabstring := strpnew('"'+name+':'+st+'",'+
  1551. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1552. end
  1553. else if owner^.symtabletype = staticsymtable then
  1554. begin
  1555. stabstring := strpnew('"'+name+':S'+st+'",'+
  1556. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1557. end
  1558. else if (owner^.symtabletype in [parasymtable,inlineparasymtable]) then
  1559. begin
  1560. case varspez of
  1561. vs_out,
  1562. vs_var : st := 'v'+st;
  1563. vs_value,
  1564. vs_const : if push_addr_param(vartype.def) then
  1565. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1566. else
  1567. st := 'p'+st;
  1568. end;
  1569. stabstring := strpnew('"'+name+':'+st+'",'+
  1570. tostr(N_PSYM)+',0,'+tostr(fileinfo.line)+','+
  1571. tostr(address+owner^.address_fixup));
  1572. {offset to ebp => will not work if the framepointer is esp
  1573. so some optimizing will make things harder to debug }
  1574. end
  1575. else if (owner^.symtabletype in [localsymtable,inlinelocalsymtable]) then
  1576. {$ifdef i386}
  1577. if reg<>R_NO then
  1578. begin
  1579. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1580. { this is the register order for GDB}
  1581. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1582. tostr(N_RSYM)+',0,'+
  1583. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1584. end
  1585. else
  1586. {$endif i386}
  1587. { I don't know if this will work (PM) }
  1588. if (vo_is_C_var in varoptions) then
  1589. stabstring := strpnew('"'+name+':S'+st+'",'+
  1590. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1591. else
  1592. stabstring := strpnew('"'+name+':'+st+'",'+
  1593. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner^.address_fixup))
  1594. else
  1595. stabstring := inherited stabstring;
  1596. end;
  1597. procedure tvarsym.concatstabto(asmlist : paasmoutput);
  1598. {$ifdef i386}
  1599. var stab_str : pchar;
  1600. {$endif i386}
  1601. begin
  1602. inherited concatstabto(asmlist);
  1603. {$ifdef i386}
  1604. if (owner^.symtabletype=parasymtable) and
  1605. (reg<>R_NO) then
  1606. begin
  1607. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1608. { this is the register order for GDB}
  1609. stab_str:=strpnew('"'+name+':r'
  1610. +pstoreddef(vartype.def)^.numberstring+'",'+
  1611. tostr(N_RSYM)+',0,'+
  1612. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1613. asmlist^.concat(new(pai_stabs,init(stab_str)));
  1614. end;
  1615. {$endif i386}
  1616. end;
  1617. {$endif GDB}
  1618. {****************************************************************************
  1619. TTYPEDCONSTSYM
  1620. *****************************************************************************}
  1621. constructor ttypedconstsym.init(const n : string;p : pdef;really_const : boolean);
  1622. begin
  1623. inherited init(n);
  1624. typ:=typedconstsym;
  1625. typedconsttype.setdef(p);
  1626. is_really_const:=really_const;
  1627. prefix:=stringdup(procprefix);
  1628. end;
  1629. constructor ttypedconstsym.inittype(const n : string;const tt : ttype;really_const : boolean);
  1630. begin
  1631. ttypedconstsym.init(n,nil,really_const);
  1632. typedconsttype:=tt;
  1633. end;
  1634. constructor ttypedconstsym.load;
  1635. begin
  1636. inherited load;
  1637. typ:=typedconstsym;
  1638. typedconsttype.load;
  1639. prefix:=stringdup(readstring);
  1640. is_really_const:=boolean(readbyte);
  1641. end;
  1642. destructor ttypedconstsym.done;
  1643. begin
  1644. stringdispose(prefix);
  1645. inherited done;
  1646. end;
  1647. function ttypedconstsym.mangledname : string;
  1648. begin
  1649. mangledname:='TC_'+prefix^+'_'+name;
  1650. end;
  1651. function ttypedconstsym.getsize : longint;
  1652. begin
  1653. if assigned(typedconsttype.def) then
  1654. getsize:=typedconsttype.def^.size
  1655. else
  1656. getsize:=0;
  1657. end;
  1658. procedure ttypedconstsym.deref;
  1659. begin
  1660. typedconsttype.resolve;
  1661. end;
  1662. procedure ttypedconstsym.write;
  1663. begin
  1664. inherited write;
  1665. typedconsttype.write;
  1666. writestring(prefix^);
  1667. writebyte(byte(is_really_const));
  1668. current_ppu^.writeentry(ibtypedconstsym);
  1669. end;
  1670. procedure ttypedconstsym.insert_in_data;
  1671. var
  1672. curconstsegment : paasmoutput;
  1673. l,ali,modulo : longint;
  1674. storefilepos : tfileposinfo;
  1675. begin
  1676. storefilepos:=aktfilepos;
  1677. aktfilepos:=akttokenpos;
  1678. if is_really_const then
  1679. curconstsegment:=consts
  1680. else
  1681. curconstsegment:=datasegment;
  1682. if (cs_create_smart in aktmoduleswitches) then
  1683. curconstsegment^.concat(new(pai_cut,init));
  1684. l:=getsize;
  1685. ali:=data_align(l);
  1686. if ali>1 then
  1687. begin
  1688. curconstsegment^.concat(new(pai_align,init(ali)));
  1689. modulo:=owner^.datasize mod ali;
  1690. if modulo>0 then
  1691. inc(owner^.datasize,ali-modulo);
  1692. end;
  1693. { Why was there no owner size update here ??? }
  1694. inc(owner^.datasize,l);
  1695. {$ifdef GDB}
  1696. if cs_debuginfo in aktmoduleswitches then
  1697. concatstabto(curconstsegment);
  1698. {$endif GDB}
  1699. if owner^.symtabletype=globalsymtable then
  1700. begin
  1701. curconstsegment^.concat(new(pai_symbol,initdataname_global(mangledname,getsize)));
  1702. end
  1703. else
  1704. if owner^.symtabletype<>unitsymtable then
  1705. begin
  1706. if (cs_create_smart in aktmoduleswitches) or
  1707. DLLSource then
  1708. curconstsegment^.concat(new(pai_symbol,initdataname_global(mangledname,getsize)))
  1709. else
  1710. curconstsegment^.concat(new(pai_symbol,initdataname(mangledname,getsize)));
  1711. end;
  1712. aktfilepos:=storefilepos;
  1713. end;
  1714. {$ifdef GDB}
  1715. function ttypedconstsym.stabstring : pchar;
  1716. var
  1717. st : char;
  1718. begin
  1719. if (cs_gdb_gsym in aktglobalswitches) and (owner^.symtabletype in [unitsymtable,globalsymtable]) then
  1720. st := 'G'
  1721. else
  1722. st := 'S';
  1723. stabstring := strpnew('"'+name+':'+st+
  1724. pstoreddef(typedconsttype.def)^.numberstring+'",'+tostr(n_STSYM)+',0,'+
  1725. tostr(fileinfo.line)+','+mangledname);
  1726. end;
  1727. {$endif GDB}
  1728. {****************************************************************************
  1729. TCONSTSYM
  1730. ****************************************************************************}
  1731. constructor tconstsym.init(const n : string;t : tconsttyp;v : TConstExprInt);
  1732. begin
  1733. inherited init(n);
  1734. typ:=constsym;
  1735. consttyp:=t;
  1736. value:=v;
  1737. ResStrIndex:=0;
  1738. consttype.reset;
  1739. len:=0;
  1740. end;
  1741. constructor tconstsym.init_def(const n : string;t : tconsttyp;v : TConstExprInt;def : pdef);
  1742. begin
  1743. inherited init(n);
  1744. typ:=constsym;
  1745. consttyp:=t;
  1746. value:=v;
  1747. consttype.setdef(def);
  1748. len:=0;
  1749. end;
  1750. constructor tconstsym.init_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1751. begin
  1752. inherited init(n);
  1753. typ:=constsym;
  1754. consttyp:=t;
  1755. value:=longint(str);
  1756. consttype.reset;
  1757. len:=l;
  1758. if t=constresourcestring then
  1759. ResStrIndex:=ResourceStrings^.Register(name,
  1760. pchar(tpointerord(value)),len);
  1761. end;
  1762. constructor tconstsym.load;
  1763. var
  1764. pd : pbestreal;
  1765. ps : pnormalset;
  1766. pc : pchar;
  1767. l1,l2 : longint;
  1768. begin
  1769. inherited load;
  1770. typ:=constsym;
  1771. consttype.reset;
  1772. consttyp:=tconsttyp(readbyte);
  1773. case consttyp of
  1774. constint:
  1775. if sizeof(tconstexprint)=8 then
  1776. begin
  1777. l1:=readlong;
  1778. l2:=readlong;
  1779. {$ifopt R+}
  1780. {$define Range_check_on}
  1781. {$endif opt R+}
  1782. {$R- needed here }
  1783. value:=qword(l1)+(int64(l2) shl 32);
  1784. {$ifdef Range_check_on}
  1785. {$R+}
  1786. {$undef Range_check_on}
  1787. {$endif Range_check_on}
  1788. end
  1789. else
  1790. value:=readlong;
  1791. constbool,
  1792. constchar :
  1793. value:=readlong;
  1794. constpointer,
  1795. constord :
  1796. begin
  1797. consttype.load;
  1798. if sizeof(TConstExprInt)=8 then
  1799. begin
  1800. l1:=readlong;
  1801. l2:=readlong;
  1802. {$ifopt R+}
  1803. {$define Range_check_on}
  1804. {$endif opt R+}
  1805. {$R- needed here }
  1806. value:=qword(l1)+(int64(l2) shl 32);
  1807. {$ifdef Range_check_on}
  1808. {$R+}
  1809. {$undef Range_check_on}
  1810. {$endif Range_check_on}
  1811. end
  1812. else
  1813. value:=readlong;
  1814. end;
  1815. conststring,constresourcestring :
  1816. begin
  1817. len:=readlong;
  1818. getmem(pc,len+1);
  1819. current_ppu^.getdata(pc^,len);
  1820. if consttyp=constresourcestring then
  1821. ResStrIndex:=readlong;
  1822. value:=tpointerord(pc);
  1823. end;
  1824. constreal :
  1825. begin
  1826. new(pd);
  1827. pd^:=readreal;
  1828. value:=tpointerord(pd);
  1829. end;
  1830. constset :
  1831. begin
  1832. consttype.load;
  1833. new(ps);
  1834. readnormalset(ps^);
  1835. value:=tpointerord(ps);
  1836. end;
  1837. constnil : ;
  1838. else
  1839. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1840. end;
  1841. end;
  1842. destructor tconstsym.done;
  1843. begin
  1844. case consttyp of
  1845. conststring,constresourcestring :
  1846. freemem(pchar(tpointerord(value)),len+1);
  1847. constreal :
  1848. dispose(pbestreal(tpointerord(value)));
  1849. constset :
  1850. dispose(pnormalset(tpointerord(value)));
  1851. end;
  1852. inherited done;
  1853. end;
  1854. function tconstsym.mangledname : string;
  1855. begin
  1856. mangledname:=name;
  1857. end;
  1858. procedure tconstsym.deref;
  1859. begin
  1860. if consttyp in [constord,constpointer,constset] then
  1861. consttype.resolve;
  1862. end;
  1863. procedure tconstsym.write;
  1864. begin
  1865. inherited write;
  1866. writebyte(byte(consttyp));
  1867. case consttyp of
  1868. constnil : ;
  1869. constint:
  1870. if sizeof(TConstExprInt)=8 then
  1871. begin
  1872. writelong(longint(lo(value)));
  1873. writelong(longint(hi(value)));
  1874. end
  1875. else
  1876. writelong(value);
  1877. constbool,
  1878. constchar :
  1879. writelong(value);
  1880. constpointer,
  1881. constord :
  1882. begin
  1883. consttype.write;
  1884. if sizeof(TConstExprInt)=8 then
  1885. begin
  1886. writelong(longint(lo(value)));
  1887. writelong(longint(hi(value)));
  1888. end
  1889. else
  1890. writelong(value);
  1891. end;
  1892. conststring,constresourcestring :
  1893. begin
  1894. writelong(len);
  1895. current_ppu^.putdata(pchar(TPointerOrd(value))^,len);
  1896. if consttyp=constresourcestring then
  1897. writelong(ResStrIndex);
  1898. end;
  1899. constreal :
  1900. writereal(pbestreal(TPointerOrd(value))^);
  1901. constset :
  1902. begin
  1903. consttype.write;
  1904. writenormalset(pointer(TPointerOrd(value))^);
  1905. end;
  1906. else
  1907. internalerror(13);
  1908. end;
  1909. current_ppu^.writeentry(ibconstsym);
  1910. end;
  1911. {$ifdef GDB}
  1912. function tconstsym.stabstring : pchar;
  1913. var st : string;
  1914. begin
  1915. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1916. case consttyp of
  1917. conststring : begin
  1918. { I had to remove ibm2ascii !! }
  1919. st := pstring(TPointerOrd(value))^;
  1920. {st := ibm2ascii(pstring(value)^);}
  1921. st := 's'''+st+'''';
  1922. end;
  1923. constbool,
  1924. constint,
  1925. constpointer,
  1926. constord,
  1927. constchar : st := 'i'+tostr(value);
  1928. constreal : begin
  1929. system.str(pbestreal(TPointerOrd(value))^,st);
  1930. st := 'r'+st;
  1931. end;
  1932. { if we don't know just put zero !! }
  1933. else st:='i0';
  1934. {***SETCONST}
  1935. {constset:;} {*** I don't know what to do with a set.}
  1936. { sets are not recognized by GDB}
  1937. {***}
  1938. end;
  1939. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1940. tostr(fileinfo.line)+',0');
  1941. end;
  1942. procedure tconstsym.concatstabto(asmlist : paasmoutput);
  1943. begin
  1944. if consttyp <> conststring then
  1945. inherited concatstabto(asmlist);
  1946. end;
  1947. {$endif GDB}
  1948. {****************************************************************************
  1949. TENUMSYM
  1950. ****************************************************************************}
  1951. constructor tenumsym.init(const n : string;def : penumdef;v : longint);
  1952. begin
  1953. inherited init(n);
  1954. typ:=enumsym;
  1955. definition:=def;
  1956. value:=v;
  1957. if def^.min>v then
  1958. def^.setmin(v);
  1959. if def^.max<v then
  1960. def^.setmax(v);
  1961. order;
  1962. end;
  1963. constructor tenumsym.load;
  1964. begin
  1965. inherited load;
  1966. typ:=enumsym;
  1967. definition:=penumdef(readderef);
  1968. value:=readlong;
  1969. nextenum := Nil;
  1970. end;
  1971. procedure tenumsym.deref;
  1972. begin
  1973. resolvedef(pdef(definition));
  1974. order;
  1975. end;
  1976. procedure tenumsym.order;
  1977. var
  1978. sym : penumsym;
  1979. begin
  1980. sym := penumsym(definition^.firstenum);
  1981. if sym = nil then
  1982. begin
  1983. definition^.firstenum := @self;
  1984. nextenum := nil;
  1985. exit;
  1986. end;
  1987. { reorder the symbols in increasing value }
  1988. if value < sym^.value then
  1989. begin
  1990. nextenum := sym;
  1991. definition^.firstenum := @self;
  1992. end
  1993. else
  1994. begin
  1995. while (sym^.value <= value) and assigned(sym^.nextenum) do
  1996. sym := sym^.nextenum;
  1997. nextenum := sym^.nextenum;
  1998. sym^.nextenum := @self;
  1999. end;
  2000. end;
  2001. procedure tenumsym.write;
  2002. begin
  2003. inherited write;
  2004. writederef(definition);
  2005. writelong(value);
  2006. current_ppu^.writeentry(ibenumsym);
  2007. end;
  2008. {$ifdef GDB}
  2009. procedure tenumsym.concatstabto(asmlist : paasmoutput);
  2010. begin
  2011. {enum elements have no stab !}
  2012. end;
  2013. {$EndIf GDB}
  2014. {****************************************************************************
  2015. TTYPESYM
  2016. ****************************************************************************}
  2017. constructor ttypesym.init(const n : string;const tt : ttype);
  2018. begin
  2019. inherited init(n);
  2020. typ:=typesym;
  2021. restype:=tt;
  2022. {$ifdef GDB}
  2023. isusedinstab := false;
  2024. {$endif GDB}
  2025. {$ifdef SYNONYM}
  2026. if assigned(restype.def) then
  2027. begin
  2028. if not(assigned(restype.def^.typesym)) then
  2029. begin
  2030. restype.def^.typesym:=@self;
  2031. synonym:=nil;
  2032. include(symoptions,sp_primary_typesym);
  2033. end
  2034. else
  2035. begin
  2036. synonym:=restype.def^.typesym^.synonym;
  2037. restype.def^.typesym^.synonym:=@self;
  2038. end;
  2039. end;
  2040. {$else}
  2041. { register the typesym for the definition }
  2042. if assigned(restype.def) and
  2043. not(assigned(restype.def^.typesym)) then
  2044. restype.def^.typesym:=@self;
  2045. {$endif}
  2046. end;
  2047. constructor ttypesym.initdef(const n : string;d : pdef);
  2048. var
  2049. t : ttype;
  2050. begin
  2051. t.setdef(d);
  2052. ttypesym.init(n,t);
  2053. end;
  2054. constructor ttypesym.load;
  2055. begin
  2056. inherited load;
  2057. typ:=typesym;
  2058. {$ifdef SYNONYM}
  2059. synonym:=nil;
  2060. {$endif}
  2061. {$ifdef GDB}
  2062. isusedinstab := false;
  2063. {$endif GDB}
  2064. restype.load;
  2065. end;
  2066. {$ifdef SYNONYM}
  2067. destructor ttypesym.done;
  2068. var
  2069. prevsym : ptypesym;
  2070. begin
  2071. if assigned(restype.def) then
  2072. begin
  2073. prevsym:=restype.def^.typesym;
  2074. if prevsym=@self then
  2075. restype.def^.typesym:=synonym;
  2076. while assigned(prevsym) do
  2077. begin
  2078. if (prevsym^.synonym=@self) then
  2079. begin
  2080. prevsym^.synonym:=synonym;
  2081. break;
  2082. end;
  2083. prevsym:=prevsym^.synonym;
  2084. end;
  2085. end;
  2086. synonym:=nil;
  2087. inherited done;
  2088. end;
  2089. {$endif}
  2090. function ttypesym.gettypedef:pdef;
  2091. begin
  2092. gettypedef:=restype.def;
  2093. end;
  2094. procedure ttypesym.prederef;
  2095. begin
  2096. restype.resolve;
  2097. {$ifdef SYNONYM}
  2098. if assigned(restype.def) then
  2099. begin
  2100. if (sp_primary_typesym in symoptions) then
  2101. begin
  2102. if restype.def^.typesym<>@self then
  2103. synonym:=restype.def^.typesym;
  2104. restype.def^.typesym:=@self;
  2105. end
  2106. else
  2107. begin
  2108. if assigned(restype.def^.typesym) then
  2109. begin
  2110. synonym:=restype.def^.typesym^.synonym;
  2111. if restype.def^.typesym<>@self then
  2112. restype.def^.typesym^.synonym:=@self;
  2113. end
  2114. else
  2115. restype.def^.typesym:=@self;
  2116. end;
  2117. if (restype.def^.deftype=recorddef) and assigned(precorddef(restype.def)^.symtable) and
  2118. (restype.def^.typesym=@self) then
  2119. precorddef(restype.def)^.symtable^.name:=stringdup('record '+name);
  2120. end;
  2121. {$endif}
  2122. end;
  2123. procedure ttypesym.write;
  2124. begin
  2125. inherited write;
  2126. restype.write;
  2127. current_ppu^.writeentry(ibtypesym);
  2128. end;
  2129. procedure ttypesym.load_references;
  2130. begin
  2131. inherited load_references;
  2132. if (restype.def^.deftype=recorddef) then
  2133. pstoredsymtable(precorddef(restype.def)^.symtable)^.load_browser;
  2134. if (restype.def^.deftype=objectdef) then
  2135. pstoredsymtable(pobjectdef(restype.def)^.symtable)^.load_browser;
  2136. end;
  2137. function ttypesym.write_references : boolean;
  2138. begin
  2139. if not inherited write_references then
  2140. { write address of this symbol if record or object
  2141. even if no real refs are there
  2142. because we need it for the symtable }
  2143. if (restype.def^.deftype=recorddef) or
  2144. (restype.def^.deftype=objectdef) then
  2145. begin
  2146. writederef(@self);
  2147. current_ppu^.writeentry(ibsymref);
  2148. end;
  2149. write_references:=true;
  2150. if (restype.def^.deftype=recorddef) then
  2151. pstoredsymtable(precorddef(restype.def)^.symtable)^.write_browser;
  2152. if (restype.def^.deftype=objectdef) then
  2153. pstoredsymtable(pobjectdef(restype.def)^.symtable)^.write_browser;
  2154. end;
  2155. {$ifdef GDB}
  2156. function ttypesym.stabstring : pchar;
  2157. var
  2158. stabchar : string[2];
  2159. short : string;
  2160. begin
  2161. if restype.def^.deftype in tagtypes then
  2162. stabchar := 'Tt'
  2163. else
  2164. stabchar := 't';
  2165. short := '"'+name+':'+stabchar+pstoreddef(restype.def)^.numberstring
  2166. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  2167. stabstring := strpnew(short);
  2168. end;
  2169. procedure ttypesym.concatstabto(asmlist : paasmoutput);
  2170. begin
  2171. {not stabs for forward defs }
  2172. if assigned(restype.def) then
  2173. if (restype.def^.typesym = @self) then
  2174. pstoreddef(restype.def)^.concatstabto(asmlist)
  2175. else
  2176. inherited concatstabto(asmlist);
  2177. end;
  2178. {$endif GDB}
  2179. {****************************************************************************
  2180. TSYSSYM
  2181. ****************************************************************************}
  2182. constructor tsyssym.init(const n : string;l : longint);
  2183. begin
  2184. inherited init(n);
  2185. typ:=syssym;
  2186. number:=l;
  2187. end;
  2188. constructor tsyssym.load;
  2189. begin
  2190. inherited load;
  2191. typ:=syssym;
  2192. number:=readlong;
  2193. end;
  2194. destructor tsyssym.done;
  2195. begin
  2196. inherited done;
  2197. end;
  2198. procedure tsyssym.write;
  2199. begin
  2200. inherited write;
  2201. writelong(number);
  2202. current_ppu^.writeentry(ibsyssym);
  2203. end;
  2204. {$ifdef GDB}
  2205. procedure tsyssym.concatstabto(asmlist : paasmoutput);
  2206. begin
  2207. end;
  2208. {$endif GDB}
  2209. end.
  2210. {
  2211. $Log$
  2212. Revision 1.5 2000-11-13 14:44:35 jonas
  2213. * fixes so no more range errors with improved range checking code
  2214. Revision 1.4 2000/11/08 23:15:17 florian
  2215. * tprocdef.procsym must be set also when a tprocdef is loaded from a PPU
  2216. Revision 1.3 2000/11/06 23:13:53 peter
  2217. * uppercase manglednames
  2218. Revision 1.2 2000/11/01 23:04:38 peter
  2219. * tprocdef.fullprocname added for better casesensitve writing of
  2220. procedures
  2221. Revision 1.1 2000/10/31 22:02:52 peter
  2222. * symtable splitted, no real code changes
  2223. }