symsym.pas 71 KB

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