pdecvar.pas 53 KB

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