pdecvar.pas 55 KB

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