pdecvar.pas 52 KB

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