pdecvar.pas 54 KB

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