pdecvar.pas 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Parses variable declarations. Used for var statement and record
  4. definitions
  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 pdecvar;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symsym,symdef;
  23. type Tvar_dec_option=(vd_record,vd_object,vd_threadvar);
  24. Tvar_dec_options=set of Tvar_dec_option;
  25. function read_property_dec(aclass:tobjectdef):tpropertysym;
  26. procedure read_var_decs(options:Tvar_dec_options);
  27. implementation
  28. uses
  29. { common }
  30. cutils,cclasses,
  31. { global }
  32. globtype,globals,tokens,verbose,
  33. systems,
  34. { symtable }
  35. symconst,symbase,symtype,symtable,defutil,defcmp,
  36. fmodule,
  37. { pass 1 }
  38. node,pass_1,
  39. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,nmem,
  40. { codegen }
  41. ncgutil,
  42. { parser }
  43. scanner,
  44. pbase,pexpr,ptype,ptconst,pdecsub,
  45. { link }
  46. import
  47. ;
  48. function read_property_dec(aclass:tobjectdef):tpropertysym;
  49. { convert a node tree to symlist and return the last
  50. symbol }
  51. function parse_symlist(pl:tsymlist;var def:tdef):boolean;
  52. var
  53. idx : longint;
  54. sym : tsym;
  55. srsymtable : tsymtable;
  56. st : tsymtable;
  57. p : tnode;
  58. begin
  59. result:=true;
  60. def:=nil;
  61. if token=_ID then
  62. begin
  63. if assigned(aclass) then
  64. sym:=search_class_member(aclass,pattern)
  65. else
  66. searchsym(pattern,sym,srsymtable);
  67. if assigned(sym) then
  68. begin
  69. case sym.typ of
  70. fieldvarsym :
  71. begin
  72. pl.addsym(sl_load,sym);
  73. def:=tfieldvarsym(sym).vartype.def;
  74. end;
  75. procsym :
  76. begin
  77. pl.addsym(sl_call,sym);
  78. end;
  79. else
  80. begin
  81. Message1(parser_e_illegal_field_or_method,orgpattern);
  82. result:=false;
  83. end;
  84. end;
  85. end
  86. else
  87. begin
  88. Message1(parser_e_illegal_field_or_method,orgpattern);
  89. result:=false;
  90. end;
  91. consume(_ID);
  92. repeat
  93. case token of
  94. _ID,
  95. _SEMICOLON :
  96. begin
  97. break;
  98. end;
  99. _POINT :
  100. begin
  101. consume(_POINT);
  102. if assigned(def) then
  103. begin
  104. st:=def.getsymtable(gs_record);
  105. if assigned(st) then
  106. begin
  107. sym:=searchsymonlyin(st,pattern);
  108. if assigned(sym) then
  109. begin
  110. pl.addsym(sl_subscript,sym);
  111. case sym.typ of
  112. fieldvarsym :
  113. def:=tfieldvarsym(sym).vartype.def;
  114. else
  115. begin
  116. Message1(sym_e_illegal_field,orgpattern);
  117. result:=false;
  118. end;
  119. end;
  120. end
  121. else
  122. begin
  123. Message1(sym_e_illegal_field,orgpattern);
  124. result:=false;
  125. end;
  126. end
  127. else
  128. begin
  129. Message(parser_e_invalid_qualifier);
  130. result:=false;
  131. end;
  132. end
  133. else
  134. begin
  135. Message(parser_e_invalid_qualifier);
  136. result:=false;
  137. end;
  138. consume(_ID);
  139. end;
  140. _LECKKLAMMER :
  141. begin
  142. consume(_LECKKLAMMER);
  143. repeat
  144. if def.deftype=arraydef then
  145. begin
  146. idx:=0;
  147. p:=comp_expr(true);
  148. if (not codegenerror) then
  149. begin
  150. if (p.nodetype=ordconstn) then
  151. begin
  152. if compare_defs(p.resulttype.def,tarraydef(def).rangetype.def,nothingn)>=te_equal then
  153. idx:=tordconstnode(p).value
  154. else
  155. IncompatibleTypes(p.resulttype.def,tarraydef(def).rangetype.def);
  156. end
  157. else
  158. Message(type_e_ordinal_expr_expected)
  159. end;
  160. p.free;
  161. pl.addconst(sl_vec,idx);
  162. def:=tarraydef(def).elementtype.def;
  163. end
  164. else
  165. begin
  166. Message(parser_e_invalid_qualifier);
  167. result:=false;
  168. end;
  169. until not try_to_consume(_COMMA);
  170. consume(_RECKKLAMMER);
  171. end;
  172. else
  173. begin
  174. Message(parser_e_ill_property_access_sym);
  175. result:=false;
  176. break;
  177. end;
  178. end;
  179. until false;
  180. end
  181. else
  182. begin
  183. Message(parser_e_ill_property_access_sym);
  184. result:=false;
  185. end;
  186. end;
  187. var
  188. sym : tsym;
  189. p : tpropertysym;
  190. overriden : tsym;
  191. varspez : tvarspez;
  192. tt : ttype;
  193. arraytype : ttype;
  194. def : tdef;
  195. pt : tnode;
  196. propname : stringid;
  197. sc : tsinglelist;
  198. paranr : word;
  199. oldregisterdef : boolean;
  200. hreadparavs,
  201. hparavs : tparavarsym;
  202. readprocdef,
  203. writeprocdef : tprocvardef;
  204. oldsymtablestack : tsymtable;
  205. begin
  206. { Generate temp procvardefs to search for matching read/write
  207. procedures. the readprocdef will store all definitions }
  208. oldregisterdef:=registerdef;
  209. registerdef:=false;
  210. paranr:=0;
  211. readprocdef:=tprocvardef.create(normal_function_level);
  212. writeprocdef:=tprocvardef.create(normal_function_level);
  213. registerdef:=oldregisterdef;
  214. { make it method pointers }
  215. if assigned(aclass) then
  216. begin
  217. include(readprocdef.procoptions,po_methodpointer);
  218. include(writeprocdef.procoptions,po_methodpointer);
  219. end;
  220. if token<>_ID then
  221. begin
  222. consume(_ID);
  223. consume(_SEMICOLON);
  224. exit;
  225. end;
  226. { Generate propertysym and insert in symtablestack }
  227. p:=tpropertysym.create(orgpattern);
  228. symtablestack.insert(p);
  229. propname:=pattern;
  230. consume(_ID);
  231. { Set the symtablestack to the parast of readprop so
  232. temp defs will be destroyed after declaration }
  233. readprocdef.parast.next:=symtablestack;
  234. symtablestack:=readprocdef.parast;
  235. { property parameters ? }
  236. if token=_LECKKLAMMER then
  237. begin
  238. if (sp_published in current_object_option) then
  239. Message(parser_e_cant_publish_that_property);
  240. { create a list of the parameters }
  241. sc:=tsinglelist.create;
  242. consume(_LECKKLAMMER);
  243. inc(testcurobject);
  244. repeat
  245. if token=_VAR then
  246. begin
  247. consume(_VAR);
  248. varspez:=vs_var;
  249. end
  250. else if token=_CONST then
  251. begin
  252. consume(_CONST);
  253. varspez:=vs_const;
  254. end
  255. else if (idtoken=_OUT) and (m_out in aktmodeswitches) then
  256. begin
  257. consume(_OUT);
  258. varspez:=vs_out;
  259. end
  260. else
  261. varspez:=vs_value;
  262. sc.reset;
  263. repeat
  264. inc(paranr);
  265. hreadparavs:=tparavarsym.create(orgpattern,10*paranr,varspez,generrortype,[]);
  266. readprocdef.parast.insert(hreadparavs);
  267. sc.insert(hreadparavs);
  268. consume(_ID);
  269. until not try_to_consume(_COMMA);
  270. if try_to_consume(_COLON) then
  271. begin
  272. { for records, don't search the recordsymtable for
  273. the symbols of the types }
  274. oldsymtablestack:=symtablestack;
  275. symtablestack:=symtablestack.next;
  276. if try_to_consume(_ARRAY) then
  277. begin
  278. consume(_OF);
  279. { define range and type of range }
  280. tt.setdef(tarraydef.create(0,-1,s32inttype));
  281. { define field type }
  282. single_type(arraytype,false);
  283. tarraydef(tt.def).setelementtype(arraytype);
  284. end
  285. else
  286. single_type(tt,false);
  287. symtablestack:=oldsymtablestack;
  288. end
  289. else
  290. tt:=cformaltype;
  291. hreadparavs:=tparavarsym(sc.first);
  292. while assigned(hreadparavs) do
  293. begin
  294. hreadparavs.vartype:=tt;
  295. { also update the writeprocdef }
  296. hparavs:=tparavarsym.create(hreadparavs.realname,hreadparavs.paranr,vs_value,tt,[]);
  297. writeprocdef.parast.insert(hparavs);
  298. hreadparavs:=tparavarsym(hreadparavs.listnext);
  299. end;
  300. until not try_to_consume(_SEMICOLON);
  301. sc.free;
  302. dec(testcurobject);
  303. consume(_RECKKLAMMER);
  304. { the parser need to know if a property has parameters, the
  305. index parameter doesn't count (PFV) }
  306. if paranr>0 then
  307. include(p.propoptions,ppo_hasparameters);
  308. end;
  309. { overriden property ? }
  310. { force property interface
  311. there is a property parameter
  312. a global property }
  313. if (token=_COLON) or (paranr>0) or (aclass=nil) then
  314. begin
  315. consume(_COLON);
  316. { insert types in global symtable }
  317. oldsymtablestack:=symtablestack;
  318. while not(symtablestack.symtabletype in [globalsymtable,staticsymtable]) do
  319. symtablestack:=symtablestack.next;
  320. single_type(p.proptype,false);
  321. symtablestack:=oldsymtablestack;
  322. if (idtoken=_INDEX) then
  323. begin
  324. consume(_INDEX);
  325. pt:=comp_expr(true);
  326. if is_constnode(pt) and
  327. is_ordinal(pt.resulttype.def)
  328. {$ifndef cpu64bit}
  329. and (not is_64bitint(pt.resulttype.def))
  330. {$endif}
  331. then
  332. p.index:=tordconstnode(pt).value
  333. else
  334. begin
  335. Message(parser_e_invalid_property_index_value);
  336. p.index:=0;
  337. end;
  338. p.indextype.setdef(pt.resulttype.def);
  339. include(p.propoptions,ppo_indexed);
  340. { concat a longint to the para templates }
  341. inc(paranr);
  342. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,p.indextype,[]);
  343. readprocdef.parast.insert(hparavs);
  344. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,p.indextype,[]);
  345. writeprocdef.parast.insert(hparavs);
  346. pt.free;
  347. end;
  348. end
  349. else
  350. begin
  351. { do an property override }
  352. overriden:=search_class_member(aclass.childof,propname);
  353. if assigned(overriden) and (overriden.typ=propertysym) then
  354. begin
  355. p.dooverride(tpropertysym(overriden));
  356. end
  357. else
  358. begin
  359. p.proptype:=generrortype;
  360. message(parser_e_no_property_found_to_override);
  361. end;
  362. end;
  363. if (sp_published in current_object_option) and
  364. not(p.proptype.def.is_publishable) then
  365. Message(parser_e_cant_publish_that_property);
  366. if try_to_consume(_READ) then
  367. begin
  368. p.readaccess.clear;
  369. if parse_symlist(p.readaccess,def) then
  370. begin
  371. sym:=p.readaccess.firstsym^.sym;
  372. case sym.typ of
  373. procsym :
  374. begin
  375. { read is function returning the type of the property }
  376. readprocdef.rettype:=p.proptype;
  377. { Insert hidden parameters }
  378. handle_calling_convention(readprocdef);
  379. { search procdefs matching readprocdef }
  380. { we ignore hidden stuff here because the property access symbol might have
  381. non default calling conventions which might change the hidden stuff;
  382. see tw3216.pp (FK) }
  383. p.readaccess.procdef:=Tprocsym(sym).search_procdef_bypara(readprocdef.paras,p.proptype.def,[cpo_allowdefaults,cpo_ignorehidden,cpo_allowconvert]);
  384. if not assigned(p.readaccess.procdef) then
  385. Message(parser_e_ill_property_access_sym);
  386. end;
  387. fieldvarsym :
  388. begin
  389. if not assigned(def) then
  390. internalerror(200310071);
  391. if compare_defs(def,p.proptype.def,nothingn)>=te_equal then
  392. begin
  393. { property parameters are allowed if this is
  394. an indexed property, because the index is then
  395. the parameter.
  396. Note: In the help of Kylix it is written
  397. that it isn't allowed, but the compiler accepts it (PFV) }
  398. if (ppo_hasparameters in p.propoptions) then
  399. Message(parser_e_ill_property_access_sym);
  400. end
  401. else
  402. IncompatibleTypes(def,p.proptype.def);
  403. end;
  404. else
  405. Message(parser_e_ill_property_access_sym);
  406. end;
  407. end;
  408. end;
  409. if try_to_consume(_WRITE) then
  410. begin
  411. p.writeaccess.clear;
  412. if parse_symlist(p.writeaccess,def) then
  413. begin
  414. sym:=p.writeaccess.firstsym^.sym;
  415. case sym.typ of
  416. procsym :
  417. begin
  418. { write is a procedure with an extra value parameter
  419. of the of the property }
  420. writeprocdef.rettype:=voidtype;
  421. inc(paranr);
  422. hparavs:=tparavarsym.create('$value',10*paranr,vs_value,p.proptype,[]);
  423. writeprocdef.parast.insert(hparavs);
  424. { Insert hidden parameters }
  425. handle_calling_convention(writeprocdef);
  426. { search procdefs matching writeprocdef }
  427. p.writeaccess.procdef:=Tprocsym(sym).search_procdef_bypara(writeprocdef.paras,writeprocdef.rettype.def,[cpo_allowdefaults,cpo_allowconvert]);
  428. if not assigned(p.writeaccess.procdef) then
  429. Message(parser_e_ill_property_access_sym);
  430. end;
  431. fieldvarsym :
  432. begin
  433. if not assigned(def) then
  434. internalerror(200310072);
  435. if compare_defs(def,p.proptype.def,nothingn)>=te_equal then
  436. begin
  437. { property parameters are allowed if this is
  438. an indexed property, because the index is then
  439. the parameter.
  440. Note: In the help of Kylix it is written
  441. that it isn't allowed, but the compiler accepts it (PFV) }
  442. if (ppo_hasparameters in p.propoptions) then
  443. Message(parser_e_ill_property_access_sym);
  444. end
  445. else
  446. IncompatibleTypes(def,p.proptype.def);
  447. end;
  448. else
  449. Message(parser_e_ill_property_access_sym);
  450. end;
  451. end;
  452. end;
  453. if assigned(aclass) then
  454. begin
  455. include(p.propoptions,ppo_stored);
  456. if try_to_consume(_STORED) then
  457. begin
  458. p.storedaccess.clear;
  459. case token of
  460. _ID:
  461. begin
  462. { in the case that idtoken=_DEFAULT }
  463. { we have to do nothing except }
  464. { setting ppo_stored, it's the same }
  465. { as stored true }
  466. if idtoken<>_DEFAULT then
  467. begin
  468. if parse_symlist(p.storedaccess,def) then
  469. begin
  470. sym:=p.storedaccess.firstsym^.sym;
  471. case sym.typ of
  472. procsym :
  473. begin
  474. p.storedaccess.procdef:=Tprocsym(sym).search_procdef_nopara_boolret;
  475. if not assigned(p.storedaccess.procdef) then
  476. message(parser_e_ill_property_storage_sym);
  477. end;
  478. fieldvarsym :
  479. begin
  480. if not assigned(def) then
  481. internalerror(200310073);
  482. if (ppo_hasparameters in p.propoptions) or
  483. not(is_boolean(def)) then
  484. Message(parser_e_stored_property_must_be_boolean);
  485. end;
  486. else
  487. Message(parser_e_ill_property_access_sym);
  488. end;
  489. end;
  490. end;
  491. end;
  492. _FALSE:
  493. begin
  494. consume(_FALSE);
  495. exclude(p.propoptions,ppo_stored);
  496. end;
  497. _TRUE:
  498. consume(_TRUE);
  499. end;
  500. end;
  501. end;
  502. if try_to_consume(_DEFAULT) then
  503. begin
  504. if not(is_ordinal(p.proptype.def) or
  505. {$ifndef cpu64bit}
  506. is_64bitint(p.proptype.def) or
  507. {$endif cpu64bit}
  508. is_class(p.proptype.def) or
  509. is_single(p.proptype.def) or
  510. (p.proptype.def.deftype in [classrefdef,pointerdef]) or
  511. ((p.proptype.def.deftype=setdef) and
  512. (tsetdef(p.proptype.def).settype=smallset))) or
  513. ((p.proptype.def.deftype=arraydef) and
  514. (ppo_indexed in p.propoptions)) or
  515. (ppo_hasparameters in p.propoptions) then
  516. begin
  517. Message(parser_e_property_cant_have_a_default_value);
  518. { Error recovery }
  519. pt:=comp_expr(true);
  520. pt.free;
  521. end
  522. else
  523. begin
  524. { Get the result of the default, the firstpass is
  525. needed to support values like -1 }
  526. pt:=comp_expr(true);
  527. if (p.proptype.def.deftype=setdef) and
  528. (pt.nodetype=arrayconstructorn) then
  529. begin
  530. arrayconstructor_to_set(pt);
  531. do_resulttypepass(pt);
  532. end;
  533. inserttypeconv(pt,p.proptype);
  534. if not(is_constnode(pt)) then
  535. Message(parser_e_property_default_value_must_const);
  536. { Set default value }
  537. case pt.nodetype of
  538. setconstn :
  539. p.default:=plongint(tsetconstnode(pt).value_set)^;
  540. ordconstn :
  541. p.default:=tordconstnode(pt).value;
  542. niln :
  543. p.default:=0;
  544. realconstn:
  545. p.default:=longint(single(trealconstnode(pt).value_real));
  546. end;
  547. pt.free;
  548. end;
  549. end
  550. else if try_to_consume(_NODEFAULT) then
  551. begin
  552. p.default:=0;
  553. end;
  554. { remove temporary procvardefs }
  555. symtablestack:=symtablestack.next;
  556. readprocdef.free;
  557. writeprocdef.free;
  558. result:=p;
  559. end;
  560. const
  561. variantrecordlevel : longint = 0;
  562. procedure read_var_decs(options:Tvar_dec_options);
  563. { reads the filed of a record into a }
  564. { symtablestack, if record=false }
  565. { variants are forbidden, so this procedure }
  566. { can be used to read object fields }
  567. { if absolute is true, ABSOLUTE and file }
  568. { types are allowed }
  569. { => the procedure is also used to read }
  570. { a sequence of variable declaration }
  571. procedure insert_syms(sc : tsinglelist;tt : ttype;is_threadvar : boolean; addsymopts : tsymoptions);
  572. { inserts the symbols of sc in st with def as definition or sym as ttypesym, sc is disposed }
  573. var
  574. vs : tabstractvarsym;
  575. hstaticvs : tglobalvarsym;
  576. begin
  577. vs:=tabstractvarsym(sc.first);
  578. while assigned(vs) do
  579. begin
  580. vs.vartype:=tt;
  581. { insert any additional hint directives }
  582. vs.symoptions := vs.symoptions + addsymopts;
  583. if (sp_static in current_object_option) then
  584. include(vs.symoptions,sp_static);
  585. if is_threadvar then
  586. include(vs.varoptions,vo_is_thread_var);
  587. { static data fields are inserted in the globalsymtable }
  588. if (symtablestack.symtabletype=objectsymtable) and
  589. (sp_static in current_object_option) then
  590. begin
  591. hstaticvs:=tglobalvarsym.create('$'+lower(symtablestack.name^)+'_'+vs.name,vs_value,tt,[]);
  592. symtablestack.defowner.owner.insert(hstaticvs);
  593. insertbssdata(hstaticvs);
  594. end
  595. else
  596. begin
  597. { external data is not possible here }
  598. case symtablestack.symtabletype of
  599. globalsymtable,
  600. staticsymtable :
  601. insertbssdata(tglobalvarsym(vs));
  602. recordsymtable,
  603. objectsymtable :
  604. tabstractrecordsymtable(symtablestack).insertfield(tfieldvarsym(vs),false);
  605. end;
  606. end;
  607. vs:=tabstractvarsym(vs.listnext);
  608. end;
  609. end;
  610. procedure read_default_value(sc : tsinglelist;tt : ttype;is_threadvar : boolean);
  611. var
  612. vs : tabstractnormalvarsym;
  613. tcsym : ttypedconstsym;
  614. begin
  615. vs:=tabstractnormalvarsym(sc.first);
  616. if assigned(vs.listnext) then
  617. Message(parser_e_initialized_only_one_var);
  618. if is_threadvar then
  619. Message(parser_e_initialized_not_for_threadvar);
  620. if symtablestack.symtabletype=localsymtable then
  621. begin
  622. consume(_EQUAL);
  623. tcsym:=ttypedconstsym.createtype('default'+vs.realname,tt,false);
  624. vs.defaultconstsym:=tcsym;
  625. symtablestack.insert(tcsym);
  626. insertconstdata(tcsym);
  627. readtypedconst(tt,tcsym,false);
  628. { The variable has a value assigned }
  629. vs.varstate:=vs_assigned;
  630. end
  631. else
  632. begin
  633. tcsym:=ttypedconstsym.createtype(vs.realname,tt,true);
  634. tcsym.fileinfo:=vs.fileinfo;
  635. symtablestack.replace(vs,tcsym);
  636. vs.free;
  637. insertconstdata(tcsym);
  638. consume(_EQUAL);
  639. readtypedconst(tt,tcsym,true);
  640. end;
  641. end;
  642. var
  643. sc : tsinglelist;
  644. old_block_type : tblock_type;
  645. symdone : boolean;
  646. { to handle absolute }
  647. abssym : tabsolutevarsym;
  648. { c var }
  649. newtype : ttypesym;
  650. is_dll,
  651. hasdefaultvalue,
  652. is_gpc_name,is_cdecl,
  653. extern_var,export_var : boolean;
  654. old_current_object_option : tsymoptions;
  655. hs,sorg,C_name,dll_name : string;
  656. tt,casetype : ttype;
  657. { maxsize contains the max. size of a variant }
  658. { startvarrec contains the start of the variant part of a record }
  659. maxsize, startvarrecsize : longint;
  660. usedalign,
  661. maxalignment,startvarrecalign,
  662. maxpadalign, startpadalign: shortint;
  663. hp,pt : tnode;
  664. fieldvs : tfieldvarsym;
  665. vs,vs2 : tabstractvarsym;
  666. srsym : tsym;
  667. oldsymtablestack,
  668. srsymtable : tsymtable;
  669. unionsymtable : trecordsymtable;
  670. offset : longint;
  671. uniondef : trecorddef;
  672. unionsym : tfieldvarsym;
  673. uniontype : ttype;
  674. dummysymoptions : tsymoptions;
  675. semicolonatend,semicoloneaten: boolean;
  676. {$ifdef powerpc}
  677. tempdef: tdef;
  678. is_first_field: boolean;
  679. {$endif powerpc}
  680. begin
  681. {$ifdef powerpc}
  682. is_first_field := true;
  683. {$endif powerpc}
  684. old_current_object_option:=current_object_option;
  685. { all variables are public if not in a object declaration }
  686. if not(vd_object in options) then
  687. current_object_option:=[sp_public];
  688. old_block_type:=block_type;
  689. block_type:=bt_type;
  690. is_gpc_name:=false;
  691. { Force an expected ID error message }
  692. if not (token in [_ID,_CASE,_END]) then
  693. consume(_ID);
  694. { read vars }
  695. sc:=tsinglelist.create;
  696. while (token=_ID) and
  697. not((vd_object in options) and
  698. (idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED,_STRICT])) do
  699. begin
  700. sorg:=orgpattern;
  701. semicoloneaten:=false;
  702. hasdefaultvalue:=false;
  703. symdone:=false;
  704. sc.reset;
  705. repeat
  706. case symtablestack.symtabletype of
  707. localsymtable :
  708. vs:=tlocalvarsym.create(orgpattern,vs_value,generrortype,[]);
  709. staticsymtable,
  710. globalsymtable :
  711. vs:=tglobalvarsym.create(orgpattern,vs_value,generrortype,[]);
  712. recordsymtable,
  713. objectsymtable :
  714. vs:=tfieldvarsym.create(orgpattern,vs_value,generrortype,[]);
  715. else
  716. internalerror(200411064);
  717. end;
  718. symtablestack.insert(vs);
  719. if assigned(vs.owner) then
  720. sc.insert(vs)
  721. else
  722. vs.free;
  723. consume(_ID);
  724. until not try_to_consume(_COMMA);
  725. consume(_COLON);
  726. if (m_gpc in aktmodeswitches) and (options=[]) and
  727. (token=_ID) and (orgpattern='__asmname__') then
  728. begin
  729. consume(_ID);
  730. C_name:=get_stringconst;
  731. Is_gpc_name:=true;
  732. end;
  733. { this is needed for Delphi mode at least
  734. but should be OK for all modes !! (PM) }
  735. ignore_equal:=true;
  736. if options*[vd_record,vd_object]<>[] then
  737. begin
  738. { for records, don't search the recordsymtable for
  739. the symbols of the types }
  740. oldsymtablestack:=symtablestack;
  741. symtablestack:=symtablestack.next;
  742. read_type(tt,'',false);
  743. symtablestack:=oldsymtablestack;
  744. end
  745. else
  746. read_type(tt,'',false);
  747. ignore_equal:=false;
  748. { Process procvar directives }
  749. if (tt.def.deftype=procvardef) and
  750. (tt.def.typesym=nil) and
  751. check_proc_directive(true) then
  752. begin
  753. newtype:=ttypesym.create('unnamed',tt);
  754. parse_var_proc_directives(tsym(newtype));
  755. semicoloneaten:=true;
  756. newtype.restype.def:=nil;
  757. tt.def.typesym:=nil;
  758. newtype.free;
  759. end;
  760. {$ifdef powerpc}
  761. { from gcc/gcc/config/rs6000/rs6000.h:
  762. /* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
  763. /* Return the alignment of a struct based on the Macintosh PowerPC
  764. alignment rules. In general the alignment of a struct is
  765. determined by the greatest alignment of its elements. However, the
  766. PowerPC rules cause the alignment of a struct to peg at word
  767. alignment except when the first field has greater than word
  768. (32-bit) alignment, in which case the alignment is determined by
  769. the alignment of the first field. */
  770. }
  771. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  772. (vd_record in options) and
  773. is_first_field and
  774. (trecordsymtable(symtablestack).usefieldalignment = -1) then
  775. begin
  776. tempdef := tt.def;
  777. while tempdef.deftype = arraydef do
  778. tempdef := tarraydef(tempdef).elementtype.def;
  779. if tempdef.deftype <> recorddef then
  780. maxpadalign := tempdef.alignment
  781. else
  782. maxpadalign := trecorddef(tempdef).padalignment;
  783. if (maxpadalign > 4) and
  784. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  785. trecordsymtable(symtablestack).padalignment := maxpadalign;
  786. is_first_field := false;
  787. end;
  788. {$endif powerpc}
  789. { types that use init/final are not allowed in variant parts, but
  790. classes are allowed }
  791. if (variantrecordlevel>0) and
  792. (tt.def.needs_inittable and not is_class(tt.def)) then
  793. Message(parser_e_cant_use_inittable_here);
  794. if is_gpc_name then
  795. begin
  796. vs:=tabstractvarsym(sc.first);
  797. if assigned(vs.listnext) then
  798. Message(parser_e_absolute_only_one_var);
  799. vs.vartype:=tt;
  800. if vs.typ=globalvarsym then
  801. begin
  802. tglobalvarsym(vs).set_mangledname(target_info.Cprefix+sorg);
  803. include(vs.varoptions,vo_is_C_var);
  804. include(vs.varoptions,vo_is_external);
  805. end
  806. else
  807. Message(parser_e_no_local_var_external);
  808. symdone:=true;
  809. end;
  810. { check for absolute }
  811. if not symdone and (idtoken=_ABSOLUTE) and (options=[]) then
  812. begin
  813. consume(_ABSOLUTE);
  814. abssym:=nil;
  815. { only allowed for one var }
  816. vs:=tabstractvarsym(sc.first);
  817. if assigned(vs.listnext) then
  818. Message(parser_e_absolute_only_one_var);
  819. { parse the rest }
  820. pt:=expr;
  821. { check allowed absolute types }
  822. if (pt.nodetype=stringconstn) or
  823. (is_constcharnode(pt)) then
  824. begin
  825. abssym:=tabsolutevarsym.create(vs.realname,tt);
  826. abssym.fileinfo:=vs.fileinfo;
  827. if pt.nodetype=stringconstn then
  828. hs:=strpas(tstringconstnode(pt).value_str)
  829. else
  830. hs:=chr(tordconstnode(pt).value);
  831. consume(token);
  832. abssym.abstyp:=toasm;
  833. abssym.asmname:=stringdup(hs);
  834. { replace the varsym }
  835. symtablestack.replace(vs,abssym);
  836. vs.free;
  837. end
  838. { address }
  839. else if is_constintnode(pt) and
  840. ((target_info.system in [system_i386_go32v2,system_i386_watcom,
  841. system_i386_wdosx,system_i386_win32,system_arm_wince,system_i386_wince]) or
  842. (m_objfpc in aktmodeswitches) or
  843. (m_delphi in aktmodeswitches)) then
  844. begin
  845. abssym:=tabsolutevarsym.create(vs.realname,tt);
  846. abssym.fileinfo:=vs.fileinfo;
  847. abssym.abstyp:=toaddr;
  848. abssym.addroffset:=tordconstnode(pt).value;
  849. {$ifdef i386}
  850. abssym.absseg:=false;
  851. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  852. try_to_consume(_COLON) then
  853. begin
  854. pt.free;
  855. pt:=expr;
  856. if is_constintnode(pt) then
  857. begin
  858. abssym.addroffset:=abssym.addroffset shl 4+tordconstnode(pt).value;
  859. abssym.absseg:=true;
  860. end
  861. else
  862. Message(type_e_ordinal_expr_expected);
  863. end;
  864. {$endif i386}
  865. symtablestack.replace(vs,abssym);
  866. vs.free;
  867. end
  868. { variable }
  869. else
  870. begin
  871. { remove subscriptn before checking for loadn }
  872. hp:=pt;
  873. while (hp.nodetype in [subscriptn,typeconvn,vecn]) do
  874. hp:=tunarynode(hp).left;
  875. if (hp.nodetype=loadn) then
  876. begin
  877. { we should check the result type of loadn }
  878. if not (tloadnode(hp).symtableentry.typ in [fieldvarsym,globalvarsym,localvarsym,
  879. paravarsym,typedconstsym]) then
  880. Message(parser_e_absolute_only_to_var_or_const);
  881. abssym:=tabsolutevarsym.create(vs.realname,tt);
  882. abssym.fileinfo:=vs.fileinfo;
  883. abssym.abstyp:=tovar;
  884. abssym.ref:=node_to_symlist(pt);
  885. symtablestack.replace(vs,abssym);
  886. vs.free;
  887. end
  888. else
  889. Message(parser_e_absolute_only_to_var_or_const);
  890. end;
  891. if assigned(abssym) then
  892. begin
  893. { try to consume the hint directives with absolute symbols }
  894. dummysymoptions:=[];
  895. try_consume_hintdirective(dummysymoptions);
  896. abssym.symoptions := abssym.symoptions + dummysymoptions;
  897. end;
  898. pt.free;
  899. symdone:=true;
  900. end;
  901. { Process procvar directives before = and ; }
  902. if (tt.def.deftype=procvardef) and
  903. (tt.def.typesym=nil) and
  904. check_proc_directive(true) then
  905. begin
  906. newtype:=ttypesym.create('unnamed',tt);
  907. parse_var_proc_directives(tsym(newtype));
  908. newtype.restype.def:=nil;
  909. tt.def.typesym:=nil;
  910. newtype.free;
  911. end;
  912. { try to parse the hint directives }
  913. dummysymoptions:=[];
  914. try_consume_hintdirective(dummysymoptions);
  915. { Records and objects can't have default values }
  916. if options*[vd_record,vd_object]<>[] then
  917. begin
  918. { for a record there doesn't need to be a ; before the END or ) }
  919. if not(token in [_END,_RKLAMMER]) and
  920. not(semicoloneaten) then
  921. consume(_SEMICOLON);
  922. end
  923. else
  924. { Handling of Delphi typed const = initialized vars }
  925. if (token=_EQUAL) and
  926. not(m_tp7 in aktmodeswitches) and
  927. (symtablestack.symtabletype<>parasymtable) then
  928. begin
  929. { Add calling convention for procvar }
  930. if (tt.def.deftype=procvardef) and
  931. (tt.def.typesym=nil) then
  932. handle_calling_convention(tprocvardef(tt.def));
  933. read_default_value(sc,tt,vd_threadvar in options);
  934. consume(_SEMICOLON);
  935. { for locals we've created typedconstsym with a different name }
  936. if symtablestack.symtabletype<>localsymtable then
  937. symdone:=true;
  938. hasdefaultvalue:=true;
  939. end
  940. else
  941. begin
  942. if not(semicoloneaten) then
  943. consume(_SEMICOLON);
  944. end;
  945. { Support calling convention for procvars after semicolon }
  946. if not(hasdefaultvalue) and
  947. (tt.def.deftype=procvardef) and
  948. (tt.def.typesym=nil) then
  949. begin
  950. { Parse procvar directives after ; }
  951. if check_proc_directive(true) then
  952. begin
  953. newtype:=ttypesym.create('unnamed',tt);
  954. parse_var_proc_directives(tsym(newtype));
  955. newtype.restype.def:=nil;
  956. tt.def.typesym:=nil;
  957. newtype.free;
  958. end;
  959. { Add calling convention for procvar }
  960. handle_calling_convention(tprocvardef(tt.def));
  961. { Handling of Delphi typed const = initialized vars }
  962. if (token=_EQUAL) and (options*[vd_record,vd_object]=[]) and
  963. not(m_tp7 in aktmodeswitches) and
  964. (symtablestack.symtabletype<>parasymtable) then
  965. begin
  966. read_default_value(sc,tt,vd_threadvar in options);
  967. consume(_SEMICOLON);
  968. symdone:=true;
  969. hasdefaultvalue:=true;
  970. end;
  971. end;
  972. { Check for EXTERNAL etc directives or, in macpas, if cs_external_var is set}
  973. if not symdone and (options=[]) then
  974. begin
  975. if (
  976. (token=_ID) and
  977. (m_cvar_support in aktmodeswitches) and
  978. (idtoken in [_EXPORT,_EXTERNAL,_PUBLIC,_CVAR])
  979. ) or
  980. (
  981. (m_mac in aktmodeswitches) and
  982. ((cs_external_var in aktlocalswitches) or (cs_externally_visible in aktlocalswitches))
  983. ) then
  984. begin
  985. { only allowed for one var }
  986. vs:=tabstractvarsym(sc.first);
  987. if assigned(vs.listnext) then
  988. Message(parser_e_absolute_only_one_var);
  989. { set type of the var }
  990. vs.vartype:=tt;
  991. vs.symoptions := vs.symoptions + dummysymoptions;
  992. { defaults }
  993. is_dll:=false;
  994. is_cdecl:=false;
  995. extern_var:=false;
  996. export_var:=false;
  997. C_name:=sorg;
  998. semicolonatend:= false;
  999. { cdecl }
  1000. if idtoken=_CVAR then
  1001. begin
  1002. consume(_CVAR);
  1003. consume(_SEMICOLON);
  1004. is_cdecl:=true;
  1005. C_name:=target_info.Cprefix+sorg;
  1006. end;
  1007. { external }
  1008. if idtoken=_EXTERNAL then
  1009. begin
  1010. consume(_EXTERNAL);
  1011. extern_var:=true;
  1012. semicolonatend:= true;
  1013. end;
  1014. { macpas specific handling due to some switches}
  1015. if (m_mac in aktmodeswitches) then
  1016. begin
  1017. if (cs_external_var in aktlocalswitches) then
  1018. begin {The effect of this is the same as if cvar; external; has been given as directives.}
  1019. is_cdecl:=true;
  1020. C_name:=target_info.Cprefix+sorg;
  1021. extern_var:=true;
  1022. end
  1023. else if (cs_externally_visible in aktlocalswitches) then
  1024. begin {The effect of this is the same as if cvar has been given as directives.}
  1025. is_cdecl:=true;
  1026. C_name:=target_info.Cprefix+sorg;
  1027. end;
  1028. vs.varregable := vr_none;
  1029. end;
  1030. { export }
  1031. if idtoken in [_EXPORT,_PUBLIC] then
  1032. begin
  1033. consume(_ID);
  1034. if extern_var then
  1035. Message(parser_e_not_external_and_export)
  1036. else
  1037. begin
  1038. export_var:=true;
  1039. semicolonatend:= true;
  1040. end;
  1041. end;
  1042. { external and export need a name after when no cdecl is used }
  1043. if not is_cdecl then
  1044. begin
  1045. { dll name ? }
  1046. if (extern_var) and (idtoken<>_NAME) then
  1047. begin
  1048. is_dll:=true;
  1049. dll_name:=get_stringconst;
  1050. end;
  1051. if try_to_consume(_NAME) then
  1052. C_name:=get_stringconst
  1053. else
  1054. C_name:=sorg;
  1055. end;
  1056. { consume the ; when export or external is used }
  1057. if semicolonatend then
  1058. consume(_SEMICOLON);
  1059. { set some vars options }
  1060. if is_dll then
  1061. include(vs.varoptions,vo_is_dll_var)
  1062. else
  1063. include(vs.varoptions,vo_is_C_var);
  1064. if (is_dll) and
  1065. (target_info.system = system_powerpc_darwin) then
  1066. C_Name := target_info.Cprefix+C_Name;
  1067. if export_var then
  1068. begin
  1069. inc(vs.refs);
  1070. include(vs.varoptions,vo_is_exported);
  1071. end;
  1072. if extern_var then
  1073. include(vs.varoptions,vo_is_external);
  1074. if vs.typ=globalvarsym then
  1075. begin
  1076. tglobalvarsym(vs).set_mangledname(C_Name);
  1077. { insert in the datasegment when it is not external }
  1078. if (not extern_var) then
  1079. insertbssdata(tglobalvarsym(vs));
  1080. { now we can insert it in the import lib if its a dll, or
  1081. add it to the externals }
  1082. if extern_var then
  1083. begin
  1084. vs.varregable := vr_none;
  1085. if is_dll then
  1086. begin
  1087. if not(current_module.uses_imports) then
  1088. begin
  1089. current_module.uses_imports:=true;
  1090. importlib.preparelib(current_module.realmodulename^);
  1091. end;
  1092. importlib.importvariable(tglobalvarsym(vs),C_name,dll_name);
  1093. end
  1094. else
  1095. if target_info.DllScanSupported then
  1096. current_module.Externals.insert(tExternalsItem.create(vs.mangledname));
  1097. end;
  1098. end
  1099. else
  1100. Message(parser_e_no_local_var_external);
  1101. symdone:=true;
  1102. end;
  1103. end;
  1104. { Check for STATIC directive }
  1105. if not symdone and (vd_object in options) and
  1106. (cs_static_keyword in aktmoduleswitches) and (idtoken=_STATIC) then
  1107. begin
  1108. include(current_object_option,sp_static);
  1109. insert_syms(sc,tt,false,dummysymoptions);
  1110. exclude(current_object_option,sp_static);
  1111. consume(_STATIC);
  1112. consume(_SEMICOLON);
  1113. symdone:=true;
  1114. end;
  1115. { insert it in the symtable, if not done yet }
  1116. if not symdone then
  1117. begin
  1118. { save object option, because we can turn of the sp_published }
  1119. if (sp_published in current_object_option) and
  1120. not(is_class(tt.def)) then
  1121. begin
  1122. Message(parser_e_cant_publish_that);
  1123. exclude(current_object_option,sp_published);
  1124. { recover by changing access type to public }
  1125. vs2:=tabstractvarsym(sc.first);
  1126. while assigned (vs2) do
  1127. begin
  1128. exclude(vs2.symoptions,sp_published);
  1129. include(vs2.symoptions,sp_public);
  1130. vs2:=tabstractvarsym(vs2.listnext);
  1131. end;
  1132. end
  1133. else
  1134. if (sp_published in current_object_option) and
  1135. not(oo_can_have_published in tobjectdef(tt.def).objectoptions) then
  1136. begin
  1137. Message(parser_e_only_publishable_classes_can__be_published);
  1138. exclude(current_object_option,sp_published);
  1139. end;
  1140. insert_syms(sc,tt,vd_threadvar in options,dummysymoptions);
  1141. current_object_option:=old_current_object_option;
  1142. end;
  1143. end;
  1144. { Check for Case }
  1145. if (vd_record in options) and (token=_CASE) then
  1146. begin
  1147. maxsize:=0;
  1148. maxalignment:=0;
  1149. maxpadalign:=0;
  1150. consume(_CASE);
  1151. sorg:=orgpattern;
  1152. hs:=pattern;
  1153. searchsym(hs,srsym,srsymtable);
  1154. { may be only a type: }
  1155. if assigned(srsym) and (srsym.typ in [typesym,unitsym]) then
  1156. begin
  1157. { for records, don't search the recordsymtable for
  1158. the symbols of the types }
  1159. oldsymtablestack:=symtablestack;
  1160. symtablestack:=symtablestack.next;
  1161. read_type(casetype,'',true);
  1162. symtablestack:=oldsymtablestack;
  1163. end
  1164. else
  1165. begin
  1166. consume(_ID);
  1167. consume(_COLON);
  1168. { for records, don't search the recordsymtable for
  1169. the symbols of the types }
  1170. oldsymtablestack:=symtablestack;
  1171. symtablestack:=symtablestack.next;
  1172. read_type(casetype,'',true);
  1173. symtablestack:=oldsymtablestack;
  1174. fieldvs:=tfieldvarsym.create(sorg,vs_value,casetype,[]);
  1175. tabstractrecordsymtable(symtablestack).insertfield(fieldvs,true);
  1176. end;
  1177. if not(is_ordinal(casetype.def))
  1178. {$ifndef cpu64bit}
  1179. or is_64bitint(casetype.def)
  1180. {$endif cpu64bit}
  1181. then
  1182. Message(type_e_ordinal_expr_expected);
  1183. consume(_OF);
  1184. UnionSymtable:=trecordsymtable.create(aktpackrecords);
  1185. Unionsymtable.next:=symtablestack;
  1186. registerdef:=false;
  1187. UnionDef:=trecorddef.create(unionsymtable);
  1188. uniondef.isunion:=true;
  1189. if assigned(symtablestack.defowner) then
  1190. Uniondef.owner:=symtablestack.defowner.owner;
  1191. registerdef:=true;
  1192. startvarrecsize:=UnionSymtable.datasize;
  1193. startvarrecalign:=UnionSymtable.fieldalignment;
  1194. startpadalign:=Unionsymtable.padalignment;
  1195. symtablestack:=UnionSymtable;
  1196. repeat
  1197. repeat
  1198. pt:=comp_expr(true);
  1199. if not(pt.nodetype=ordconstn) then
  1200. Message(parser_e_illegal_expression);
  1201. pt.free;
  1202. if token=_COMMA then
  1203. consume(_COMMA)
  1204. else
  1205. break;
  1206. until false;
  1207. consume(_COLON);
  1208. { read the vars }
  1209. consume(_LKLAMMER);
  1210. inc(variantrecordlevel);
  1211. if token<>_RKLAMMER then
  1212. read_var_decs([vd_record]);
  1213. dec(variantrecordlevel);
  1214. consume(_RKLAMMER);
  1215. { calculates maximal variant size }
  1216. maxsize:=max(maxsize,unionsymtable.datasize);
  1217. maxalignment:=max(maxalignment,unionsymtable.fieldalignment);
  1218. maxpadalign:=max(maxpadalign,unionsymtable.padalignment);
  1219. { the items of the next variant are overlayed }
  1220. unionsymtable.datasize:=startvarrecsize;
  1221. unionsymtable.fieldalignment:=startvarrecalign;
  1222. unionsymtable.padalignment:=startpadalign;
  1223. if (token<>_END) and (token<>_RKLAMMER) then
  1224. consume(_SEMICOLON)
  1225. else
  1226. break;
  1227. until (token=_END) or (token=_RKLAMMER);
  1228. { at last set the record size to that of the biggest variant }
  1229. unionsymtable.datasize:=maxsize;
  1230. unionsymtable.fieldalignment:=maxalignment;
  1231. uniontype.def:=uniondef;
  1232. uniontype.sym:=nil;
  1233. UnionSym:=tfieldvarsym.create('$case',vs_value,uniontype,[]);
  1234. symtablestack:=symtablestack.next;
  1235. unionsymtable.addalignmentpadding;
  1236. {$ifdef powerpc}
  1237. { parent inherits the alignment padding if the variant is the first "field" of the parent record/variant }
  1238. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  1239. is_first_field and
  1240. (trecordsymtable(symtablestack).usefieldalignment = -1) and
  1241. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  1242. trecordsymtable(symtablestack).padalignment:=maxpadalign;
  1243. {$endif powerpc}
  1244. { Align the offset where the union symtable is added }
  1245. if (trecordsymtable(symtablestack).usefieldalignment=-1) then
  1246. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.maxCrecordalign)
  1247. else
  1248. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.recordalignmax);
  1249. offset:=align(trecordsymtable(symtablestack).datasize,usedalign);
  1250. trecordsymtable(symtablestack).datasize:=offset+unionsymtable.datasize;
  1251. if unionsymtable.recordalignment>trecordsymtable(symtablestack).fieldalignment then
  1252. trecordsymtable(symtablestack).fieldalignment:=unionsymtable.recordalignment;
  1253. trecordsymtable(symtablestack).insertunionst(Unionsymtable,offset);
  1254. Unionsym.owner:=nil;
  1255. unionsym.free;
  1256. uniondef.owner:=nil;
  1257. uniondef.free;
  1258. end;
  1259. block_type:=old_block_type;
  1260. current_object_option:=old_current_object_option;
  1261. { free the list }
  1262. sc.free;
  1263. {$ifdef powerpc}
  1264. is_first_field := false;
  1265. {$endif powerpc}
  1266. end;
  1267. end.