pdecvar.pas 52 KB

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