pdecvar.pas 54 KB

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