pdecvar.pas 54 KB

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