pdecvar.pas 54 KB

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