pdecvar.pas 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. if (token = _ID) then
  705. begin
  706. case symtablestack.symtabletype of
  707. localsymtable :
  708. vs:=tlocalvarsym.create(orgpattern,vs_value,generrortype,[]);
  709. staticsymtable,
  710. globalsymtable :
  711. vs:=tglobalvarsym.create(orgpattern,vs_value,generrortype,[]);
  712. recordsymtable,
  713. objectsymtable :
  714. vs:=tfieldvarsym.create(orgpattern,vs_value,generrortype,[]);
  715. else
  716. internalerror(200411064);
  717. end;
  718. symtablestack.insert(vs);
  719. if assigned(vs.owner) then
  720. sc.insert(vs)
  721. else
  722. vs.free;
  723. end;
  724. consume(_ID);
  725. until not try_to_consume(_COMMA);
  726. consume(_COLON);
  727. if (m_gpc in aktmodeswitches) and (options=[]) and
  728. (token=_ID) and (orgpattern='__asmname__') then
  729. begin
  730. consume(_ID);
  731. C_name:=get_stringconst;
  732. Is_gpc_name:=true;
  733. end;
  734. { this is needed for Delphi mode at least
  735. but should be OK for all modes !! (PM) }
  736. ignore_equal:=true;
  737. if options*[vd_record,vd_object]<>[] then
  738. begin
  739. { for records, don't search the recordsymtable for
  740. the symbols of the types }
  741. oldsymtablestack:=symtablestack;
  742. symtablestack:=symtablestack.next;
  743. read_type(tt,'',false);
  744. symtablestack:=oldsymtablestack;
  745. end
  746. else
  747. read_type(tt,'',false);
  748. ignore_equal:=false;
  749. { Process procvar directives }
  750. if (tt.def.deftype=procvardef) and
  751. (tt.def.typesym=nil) and
  752. check_proc_directive(true) then
  753. begin
  754. newtype:=ttypesym.create('unnamed',tt);
  755. parse_var_proc_directives(tsym(newtype));
  756. semicoloneaten:=true;
  757. newtype.restype.def:=nil;
  758. tt.def.typesym:=nil;
  759. newtype.free;
  760. end;
  761. {$ifdef powerpc}
  762. { from gcc/gcc/config/rs6000/rs6000.h:
  763. /* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
  764. /* Return the alignment of a struct based on the Macintosh PowerPC
  765. alignment rules. In general the alignment of a struct is
  766. determined by the greatest alignment of its elements. However, the
  767. PowerPC rules cause the alignment of a struct to peg at word
  768. alignment except when the first field has greater than word
  769. (32-bit) alignment, in which case the alignment is determined by
  770. the alignment of the first field. */
  771. }
  772. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  773. (vd_record in options) and
  774. is_first_field and
  775. (trecordsymtable(symtablestack).usefieldalignment = -1) then
  776. begin
  777. tempdef := tt.def;
  778. while tempdef.deftype = arraydef do
  779. tempdef := tarraydef(tempdef).elementtype.def;
  780. if tempdef.deftype <> recorddef then
  781. maxpadalign := tempdef.alignment
  782. else
  783. maxpadalign := trecorddef(tempdef).padalignment;
  784. if (maxpadalign > 4) and
  785. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  786. trecordsymtable(symtablestack).padalignment := maxpadalign;
  787. is_first_field := false;
  788. end;
  789. {$endif powerpc}
  790. { types that use init/final are not allowed in variant parts, but
  791. classes are allowed }
  792. if (variantrecordlevel>0) and
  793. (tt.def.needs_inittable and not is_class(tt.def)) then
  794. Message(parser_e_cant_use_inittable_here);
  795. if is_gpc_name then
  796. begin
  797. vs:=tabstractvarsym(sc.first);
  798. if assigned(vs.listnext) then
  799. Message(parser_e_absolute_only_one_var);
  800. vs.vartype:=tt;
  801. if vs.typ=globalvarsym then
  802. begin
  803. tglobalvarsym(vs).set_mangledname(target_info.Cprefix+sorg);
  804. include(vs.varoptions,vo_is_C_var);
  805. include(vs.varoptions,vo_is_external);
  806. end
  807. else
  808. Message(parser_e_no_local_var_external);
  809. symdone:=true;
  810. end;
  811. { check for absolute }
  812. if not symdone and (idtoken=_ABSOLUTE) and (options=[]) then
  813. begin
  814. consume(_ABSOLUTE);
  815. abssym:=nil;
  816. { only allowed for one var }
  817. vs:=tabstractvarsym(sc.first);
  818. if assigned(vs.listnext) then
  819. Message(parser_e_absolute_only_one_var);
  820. { parse the rest }
  821. pt:=expr;
  822. { check allowed absolute types }
  823. if (pt.nodetype=stringconstn) or
  824. (is_constcharnode(pt)) then
  825. begin
  826. abssym:=tabsolutevarsym.create(vs.realname,tt);
  827. abssym.fileinfo:=vs.fileinfo;
  828. if pt.nodetype=stringconstn then
  829. hs:=strpas(tstringconstnode(pt).value_str)
  830. else
  831. hs:=chr(tordconstnode(pt).value);
  832. consume(token);
  833. abssym.abstyp:=toasm;
  834. abssym.asmname:=stringdup(hs);
  835. { replace the varsym }
  836. symtablestack.replace(vs,abssym);
  837. vs.free;
  838. end
  839. { address }
  840. else if is_constintnode(pt) and
  841. ((target_info.system in [system_i386_go32v2,system_i386_watcom,
  842. system_i386_wdosx,system_i386_win32,system_arm_wince,system_i386_wince]) or
  843. (m_objfpc in aktmodeswitches) or
  844. (m_delphi in aktmodeswitches)) then
  845. begin
  846. abssym:=tabsolutevarsym.create(vs.realname,tt);
  847. abssym.fileinfo:=vs.fileinfo;
  848. abssym.abstyp:=toaddr;
  849. abssym.addroffset:=tordconstnode(pt).value;
  850. {$ifdef i386}
  851. abssym.absseg:=false;
  852. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  853. try_to_consume(_COLON) then
  854. begin
  855. pt.free;
  856. pt:=expr;
  857. if is_constintnode(pt) then
  858. begin
  859. abssym.addroffset:=abssym.addroffset shl 4+tordconstnode(pt).value;
  860. abssym.absseg:=true;
  861. end
  862. else
  863. Message(type_e_ordinal_expr_expected);
  864. end;
  865. {$endif i386}
  866. symtablestack.replace(vs,abssym);
  867. vs.free;
  868. end
  869. { variable }
  870. else
  871. begin
  872. { remove subscriptn before checking for loadn }
  873. hp:=pt;
  874. while (hp.nodetype in [subscriptn,typeconvn,vecn]) do
  875. hp:=tunarynode(hp).left;
  876. if (hp.nodetype=loadn) then
  877. begin
  878. { we should check the result type of loadn }
  879. if not (tloadnode(hp).symtableentry.typ in [fieldvarsym,globalvarsym,localvarsym,
  880. paravarsym,typedconstsym]) then
  881. Message(parser_e_absolute_only_to_var_or_const);
  882. abssym:=tabsolutevarsym.create(vs.realname,tt);
  883. abssym.fileinfo:=vs.fileinfo;
  884. abssym.abstyp:=tovar;
  885. abssym.ref:=node_to_symlist(pt);
  886. symtablestack.replace(vs,abssym);
  887. vs.free;
  888. end
  889. else
  890. Message(parser_e_absolute_only_to_var_or_const);
  891. end;
  892. if assigned(abssym) then
  893. begin
  894. { try to consume the hint directives with absolute symbols }
  895. dummysymoptions:=[];
  896. try_consume_hintdirective(dummysymoptions);
  897. abssym.symoptions := abssym.symoptions + dummysymoptions;
  898. end;
  899. pt.free;
  900. symdone:=true;
  901. end;
  902. { Process procvar directives before = and ; }
  903. if (tt.def.deftype=procvardef) and
  904. (tt.def.typesym=nil) and
  905. check_proc_directive(true) then
  906. begin
  907. newtype:=ttypesym.create('unnamed',tt);
  908. parse_var_proc_directives(tsym(newtype));
  909. newtype.restype.def:=nil;
  910. tt.def.typesym:=nil;
  911. newtype.free;
  912. end;
  913. { try to parse the hint directives }
  914. dummysymoptions:=[];
  915. try_consume_hintdirective(dummysymoptions);
  916. { Records and objects can't have default values }
  917. if options*[vd_record,vd_object]<>[] then
  918. begin
  919. { for a record there doesn't need to be a ; before the END or ) }
  920. if not(token in [_END,_RKLAMMER]) and
  921. not(semicoloneaten) then
  922. consume(_SEMICOLON);
  923. end
  924. else
  925. { Handling of Delphi typed const = initialized vars }
  926. if (token=_EQUAL) and
  927. not(m_tp7 in aktmodeswitches) and
  928. (symtablestack.symtabletype<>parasymtable) then
  929. begin
  930. { Add calling convention for procvar }
  931. if (tt.def.deftype=procvardef) and
  932. (tt.def.typesym=nil) then
  933. handle_calling_convention(tprocvardef(tt.def));
  934. read_default_value(sc,tt,vd_threadvar in options);
  935. consume(_SEMICOLON);
  936. { for locals we've created typedconstsym with a different name }
  937. if symtablestack.symtabletype<>localsymtable then
  938. symdone:=true;
  939. hasdefaultvalue:=true;
  940. end
  941. else
  942. begin
  943. if not(semicoloneaten) then
  944. consume(_SEMICOLON);
  945. end;
  946. { Support calling convention for procvars after semicolon }
  947. if not(hasdefaultvalue) and
  948. (tt.def.deftype=procvardef) and
  949. (tt.def.typesym=nil) then
  950. begin
  951. { Parse procvar directives after ; }
  952. if check_proc_directive(true) then
  953. begin
  954. newtype:=ttypesym.create('unnamed',tt);
  955. parse_var_proc_directives(tsym(newtype));
  956. newtype.restype.def:=nil;
  957. tt.def.typesym:=nil;
  958. newtype.free;
  959. end;
  960. { Add calling convention for procvar }
  961. handle_calling_convention(tprocvardef(tt.def));
  962. { Handling of Delphi typed const = initialized vars }
  963. if (token=_EQUAL) and (options*[vd_record,vd_object]=[]) and
  964. not(m_tp7 in aktmodeswitches) and
  965. (symtablestack.symtabletype<>parasymtable) then
  966. begin
  967. read_default_value(sc,tt,vd_threadvar in options);
  968. consume(_SEMICOLON);
  969. symdone:=true;
  970. hasdefaultvalue:=true;
  971. end;
  972. end;
  973. { Check for EXTERNAL etc directives or, in macpas, if cs_external_var is set}
  974. if not symdone and (options=[]) then
  975. begin
  976. if (
  977. (token=_ID) and
  978. (m_cvar_support in aktmodeswitches) and
  979. (idtoken in [_EXPORT,_EXTERNAL,_PUBLIC,_CVAR])
  980. ) or
  981. (
  982. (m_mac in aktmodeswitches) and
  983. ((cs_external_var in aktlocalswitches) or (cs_externally_visible in aktlocalswitches))
  984. ) then
  985. begin
  986. { only allowed for one var }
  987. vs:=tabstractvarsym(sc.first);
  988. if assigned(vs.listnext) then
  989. Message(parser_e_absolute_only_one_var);
  990. { set type of the var }
  991. vs.vartype:=tt;
  992. vs.symoptions := vs.symoptions + dummysymoptions;
  993. { defaults }
  994. is_dll:=false;
  995. is_cdecl:=false;
  996. extern_var:=false;
  997. export_var:=false;
  998. C_name:=sorg;
  999. semicolonatend:= false;
  1000. { cdecl }
  1001. if idtoken=_CVAR then
  1002. begin
  1003. consume(_CVAR);
  1004. consume(_SEMICOLON);
  1005. is_cdecl:=true;
  1006. C_name:=target_info.Cprefix+sorg;
  1007. end;
  1008. { external }
  1009. if idtoken=_EXTERNAL then
  1010. begin
  1011. consume(_EXTERNAL);
  1012. extern_var:=true;
  1013. semicolonatend:= true;
  1014. end;
  1015. { macpas specific handling due to some switches}
  1016. if (m_mac in aktmodeswitches) then
  1017. begin
  1018. if (cs_external_var in aktlocalswitches) then
  1019. begin {The effect of this is the same as if cvar; external; has been given as directives.}
  1020. is_cdecl:=true;
  1021. C_name:=target_info.Cprefix+sorg;
  1022. extern_var:=true;
  1023. end
  1024. else if (cs_externally_visible in aktlocalswitches) then
  1025. begin {The effect of this is the same as if cvar has been given as directives.}
  1026. is_cdecl:=true;
  1027. C_name:=target_info.Cprefix+sorg;
  1028. end;
  1029. vs.varregable := vr_none;
  1030. end;
  1031. { export }
  1032. if idtoken in [_EXPORT,_PUBLIC] then
  1033. begin
  1034. consume(_ID);
  1035. if extern_var then
  1036. Message(parser_e_not_external_and_export)
  1037. else
  1038. begin
  1039. export_var:=true;
  1040. semicolonatend:= true;
  1041. end;
  1042. end;
  1043. { external and export need a name after when no cdecl is used }
  1044. if not is_cdecl then
  1045. begin
  1046. { dll name ? }
  1047. if (extern_var) and (idtoken<>_NAME) then
  1048. begin
  1049. is_dll:=true;
  1050. dll_name:=get_stringconst;
  1051. end;
  1052. if try_to_consume(_NAME) then
  1053. C_name:=get_stringconst
  1054. else
  1055. C_name:=sorg;
  1056. end;
  1057. { consume the ; when export or external is used }
  1058. if semicolonatend then
  1059. consume(_SEMICOLON);
  1060. { set some vars options }
  1061. if is_dll then
  1062. include(vs.varoptions,vo_is_dll_var)
  1063. else
  1064. include(vs.varoptions,vo_is_C_var);
  1065. if (is_dll) and
  1066. (target_info.system = system_powerpc_darwin) then
  1067. C_Name := target_info.Cprefix+C_Name;
  1068. if export_var then
  1069. begin
  1070. inc(vs.refs);
  1071. include(vs.varoptions,vo_is_exported);
  1072. end;
  1073. if extern_var then
  1074. include(vs.varoptions,vo_is_external);
  1075. if vs.typ=globalvarsym then
  1076. begin
  1077. tglobalvarsym(vs).set_mangledname(C_Name);
  1078. { insert in the al_globals when it is not external }
  1079. if (not extern_var) then
  1080. insertbssdata(tglobalvarsym(vs));
  1081. { now we can insert it in the import lib if its a dll, or
  1082. add it to the externals }
  1083. if extern_var then
  1084. begin
  1085. vs.varregable := vr_none;
  1086. if is_dll then
  1087. begin
  1088. if not(current_module.uses_imports) then
  1089. begin
  1090. current_module.uses_imports:=true;
  1091. importlib.preparelib(current_module.realmodulename^);
  1092. end;
  1093. importlib.importvariable(tglobalvarsym(vs),C_name,dll_name);
  1094. end
  1095. else
  1096. if target_info.DllScanSupported then
  1097. current_module.Externals.insert(tExternalsItem.create(vs.mangledname));
  1098. end;
  1099. end
  1100. else
  1101. Message(parser_e_no_local_var_external);
  1102. symdone:=true;
  1103. end;
  1104. end;
  1105. { Check for STATIC directive }
  1106. if not symdone and (vd_object in options) and
  1107. (cs_static_keyword in aktmoduleswitches) and (idtoken=_STATIC) then
  1108. begin
  1109. include(current_object_option,sp_static);
  1110. consume(_STATIC);
  1111. consume(_SEMICOLON);
  1112. end;
  1113. { insert it in the symtable, if not done yet }
  1114. if not symdone then
  1115. begin
  1116. { save object option, because we can turn of the sp_published }
  1117. if (sp_published in current_object_option) and
  1118. not(is_class(tt.def)) then
  1119. begin
  1120. Message(parser_e_cant_publish_that);
  1121. exclude(current_object_option,sp_published);
  1122. { recover by changing access type to public }
  1123. vs2:=tabstractvarsym(sc.first);
  1124. while assigned (vs2) do
  1125. begin
  1126. exclude(vs2.symoptions,sp_published);
  1127. include(vs2.symoptions,sp_public);
  1128. vs2:=tabstractvarsym(vs2.listnext);
  1129. end;
  1130. end
  1131. else
  1132. if (sp_published in current_object_option) and
  1133. not(oo_can_have_published in tobjectdef(tt.def).objectoptions) then
  1134. begin
  1135. Message(parser_e_only_publishable_classes_can__be_published);
  1136. exclude(current_object_option,sp_published);
  1137. end;
  1138. insert_syms(sc,tt,vd_threadvar in options,dummysymoptions);
  1139. current_object_option:=old_current_object_option;
  1140. end;
  1141. end;
  1142. { Check for Case }
  1143. if (vd_record in options) and (token=_CASE) then
  1144. begin
  1145. maxsize:=0;
  1146. maxalignment:=0;
  1147. maxpadalign:=0;
  1148. consume(_CASE);
  1149. sorg:=orgpattern;
  1150. hs:=pattern;
  1151. searchsym(hs,srsym,srsymtable);
  1152. { may be only a type: }
  1153. if assigned(srsym) and (srsym.typ in [typesym,unitsym]) then
  1154. begin
  1155. { for records, don't search the recordsymtable for
  1156. the symbols of the types }
  1157. oldsymtablestack:=symtablestack;
  1158. symtablestack:=symtablestack.next;
  1159. read_type(casetype,'',true);
  1160. symtablestack:=oldsymtablestack;
  1161. end
  1162. else
  1163. begin
  1164. consume(_ID);
  1165. consume(_COLON);
  1166. { for records, don't search the recordsymtable for
  1167. the symbols of the types }
  1168. oldsymtablestack:=symtablestack;
  1169. symtablestack:=symtablestack.next;
  1170. read_type(casetype,'',true);
  1171. symtablestack:=oldsymtablestack;
  1172. fieldvs:=tfieldvarsym.create(sorg,vs_value,casetype,[]);
  1173. tabstractrecordsymtable(symtablestack).insertfield(fieldvs,true);
  1174. end;
  1175. if not(is_ordinal(casetype.def))
  1176. {$ifndef cpu64bit}
  1177. or is_64bitint(casetype.def)
  1178. {$endif cpu64bit}
  1179. then
  1180. Message(type_e_ordinal_expr_expected);
  1181. consume(_OF);
  1182. UnionSymtable:=trecordsymtable.create(aktpackrecords);
  1183. Unionsymtable.next:=symtablestack;
  1184. registerdef:=false;
  1185. UnionDef:=trecorddef.create(unionsymtable);
  1186. uniondef.isunion:=true;
  1187. if assigned(symtablestack.defowner) then
  1188. Uniondef.owner:=symtablestack.defowner.owner;
  1189. registerdef:=true;
  1190. startvarrecsize:=UnionSymtable.datasize;
  1191. startvarrecalign:=UnionSymtable.fieldalignment;
  1192. startpadalign:=Unionsymtable.padalignment;
  1193. symtablestack:=UnionSymtable;
  1194. repeat
  1195. repeat
  1196. pt:=comp_expr(true);
  1197. if not(pt.nodetype=ordconstn) then
  1198. Message(parser_e_illegal_expression);
  1199. pt.free;
  1200. if token=_COMMA then
  1201. consume(_COMMA)
  1202. else
  1203. break;
  1204. until false;
  1205. consume(_COLON);
  1206. { read the vars }
  1207. consume(_LKLAMMER);
  1208. inc(variantrecordlevel);
  1209. if token<>_RKLAMMER then
  1210. read_var_decs([vd_record]);
  1211. dec(variantrecordlevel);
  1212. consume(_RKLAMMER);
  1213. { calculates maximal variant size }
  1214. maxsize:=max(maxsize,unionsymtable.datasize);
  1215. maxalignment:=max(maxalignment,unionsymtable.fieldalignment);
  1216. maxpadalign:=max(maxpadalign,unionsymtable.padalignment);
  1217. { the items of the next variant are overlayed }
  1218. unionsymtable.datasize:=startvarrecsize;
  1219. unionsymtable.fieldalignment:=startvarrecalign;
  1220. unionsymtable.padalignment:=startpadalign;
  1221. if (token<>_END) and (token<>_RKLAMMER) then
  1222. consume(_SEMICOLON)
  1223. else
  1224. break;
  1225. until (token=_END) or (token=_RKLAMMER);
  1226. { at last set the record size to that of the biggest variant }
  1227. unionsymtable.datasize:=maxsize;
  1228. unionsymtable.fieldalignment:=maxalignment;
  1229. uniontype.def:=uniondef;
  1230. uniontype.sym:=nil;
  1231. UnionSym:=tfieldvarsym.create('$case',vs_value,uniontype,[]);
  1232. symtablestack:=symtablestack.next;
  1233. unionsymtable.addalignmentpadding;
  1234. {$ifdef powerpc}
  1235. { parent inherits the alignment padding if the variant is the first "field" of the parent record/variant }
  1236. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  1237. is_first_field and
  1238. (trecordsymtable(symtablestack).usefieldalignment = -1) and
  1239. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  1240. trecordsymtable(symtablestack).padalignment:=maxpadalign;
  1241. {$endif powerpc}
  1242. { Align the offset where the union symtable is added }
  1243. if (trecordsymtable(symtablestack).usefieldalignment=-1) then
  1244. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.maxCrecordalign)
  1245. else
  1246. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.recordalignmax);
  1247. offset:=align(trecordsymtable(symtablestack).datasize,usedalign);
  1248. trecordsymtable(symtablestack).datasize:=offset+unionsymtable.datasize;
  1249. if unionsymtable.recordalignment>trecordsymtable(symtablestack).fieldalignment then
  1250. trecordsymtable(symtablestack).fieldalignment:=unionsymtable.recordalignment;
  1251. trecordsymtable(symtablestack).insertunionst(Unionsymtable,offset);
  1252. Unionsym.owner:=nil;
  1253. unionsym.free;
  1254. uniondef.owner:=nil;
  1255. uniondef.free;
  1256. end;
  1257. block_type:=old_block_type;
  1258. current_object_option:=old_current_object_option;
  1259. { free the list }
  1260. sc.free;
  1261. {$ifdef powerpc}
  1262. is_first_field := false;
  1263. {$endif powerpc}
  1264. end;
  1265. end.