pdecvar.pas 54 KB

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