pdecvar.pas 56 KB

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