pdecvar.pas 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  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. end
  630. else
  631. begin
  632. tcsym:=ttypedconstsym.createtype(vs.realname,tt,true);
  633. tcsym.fileinfo:=vs.fileinfo;
  634. symtablestack.replace(vs,tcsym);
  635. vs.free;
  636. insertconstdata(tcsym);
  637. consume(_EQUAL);
  638. readtypedconst(tt,tcsym,true);
  639. end;
  640. end;
  641. var
  642. sc : tsinglelist;
  643. old_block_type : tblock_type;
  644. symdone : boolean;
  645. { to handle absolute }
  646. abssym : tabsolutevarsym;
  647. { c var }
  648. newtype : ttypesym;
  649. is_dll,
  650. hasdefaultvalue,
  651. is_gpc_name,is_cdecl,
  652. extern_var,export_var : boolean;
  653. old_current_object_option : tsymoptions;
  654. hs,sorg,C_name,dll_name : string;
  655. tt,casetype : ttype;
  656. { maxsize contains the max. size of a variant }
  657. { startvarrec contains the start of the variant part of a record }
  658. maxsize, startvarrecsize : longint;
  659. usedalign,
  660. maxalignment,startvarrecalign,
  661. maxpadalign, startpadalign: shortint;
  662. hp,pt : tnode;
  663. fieldvs : tfieldvarsym;
  664. vs,vs2 : tabstractvarsym;
  665. srsym : tsym;
  666. oldsymtablestack,
  667. srsymtable : tsymtable;
  668. unionsymtable : trecordsymtable;
  669. offset : longint;
  670. uniondef : trecorddef;
  671. unionsym : tfieldvarsym;
  672. uniontype : ttype;
  673. dummysymoptions : tsymoptions;
  674. semicolonatend: boolean;
  675. {$ifdef powerpc}
  676. tempdef: tdef;
  677. is_first_field: boolean;
  678. {$endif powerpc}
  679. begin
  680. {$ifdef powerpc}
  681. is_first_field := true;
  682. {$endif powerpc}
  683. old_current_object_option:=current_object_option;
  684. { all variables are public if not in a object declaration }
  685. if not is_object then
  686. current_object_option:=[sp_public];
  687. old_block_type:=block_type;
  688. block_type:=bt_type;
  689. is_gpc_name:=false;
  690. { Force an expected ID error message }
  691. if not (token in [_ID,_CASE,_END]) then
  692. consume(_ID);
  693. { read vars }
  694. sc:=tsinglelist.create;
  695. while (token=_ID) and
  696. not(is_object and (idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED])) do
  697. begin
  698. sorg:=orgpattern;
  699. sc.reset;
  700. repeat
  701. case symtablestack.symtabletype of
  702. localsymtable :
  703. vs:=tlocalvarsym.create(orgpattern,vs_value,generrortype,[]);
  704. staticsymtable,
  705. globalsymtable :
  706. vs:=tglobalvarsym.create(orgpattern,vs_value,generrortype,[]);
  707. recordsymtable,
  708. objectsymtable :
  709. vs:=tfieldvarsym.create(orgpattern,vs_value,generrortype,[]);
  710. else
  711. internalerror(200411064);
  712. end;
  713. symtablestack.insert(vs);
  714. if assigned(vs.owner) then
  715. sc.insert(vs)
  716. else
  717. vs.free;
  718. consume(_ID);
  719. until not try_to_consume(_COMMA);
  720. consume(_COLON);
  721. if (m_gpc in aktmodeswitches) and
  722. not(is_record or is_object or is_threadvar) and
  723. (token=_ID) and (orgpattern='__asmname__') then
  724. begin
  725. consume(_ID);
  726. C_name:=get_stringconst;
  727. Is_gpc_name:=true;
  728. end;
  729. { this is needed for Delphi mode at least
  730. but should be OK for all modes !! (PM) }
  731. ignore_equal:=true;
  732. if is_record or is_object then
  733. begin
  734. { for records, don't search the recordsymtable for
  735. the symbols of the types }
  736. oldsymtablestack:=symtablestack;
  737. symtablestack:=symtablestack.next;
  738. read_type(tt,'',false);
  739. symtablestack:=oldsymtablestack;
  740. end
  741. else
  742. read_type(tt,'',false);
  743. { Process procvar directives }
  744. if (tt.def.deftype=procvardef) and
  745. (tt.def.typesym=nil) and
  746. check_proc_directive(true) then
  747. begin
  748. newtype:=ttypesym.create('unnamed',tt);
  749. parse_var_proc_directives(tsym(newtype));
  750. newtype.restype.def:=nil;
  751. tt.def.typesym:=nil;
  752. newtype.free;
  753. end;
  754. {$ifdef powerpc}
  755. { from gcc/gcc/config/rs6000/rs6000.h:
  756. /* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
  757. /* Return the alignment of a struct based on the Macintosh PowerPC
  758. alignment rules. In general the alignment of a struct is
  759. determined by the greatest alignment of its elements. However, the
  760. PowerPC rules cause the alignment of a struct to peg at word
  761. alignment except when the first field has greater than word
  762. (32-bit) alignment, in which case the alignment is determined by
  763. the alignment of the first field. */
  764. }
  765. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  766. is_record and
  767. is_first_field and
  768. (trecordsymtable(symtablestack).usefieldalignment = -1) then
  769. begin
  770. tempdef := tt.def;
  771. while tempdef.deftype = arraydef do
  772. tempdef := tarraydef(tempdef).elementtype.def;
  773. if tempdef.deftype <> recorddef then
  774. maxpadalign := tempdef.alignment
  775. else
  776. maxpadalign := trecorddef(tempdef).padalignment;
  777. if (maxpadalign > 4) and
  778. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  779. trecordsymtable(symtablestack).padalignment := maxpadalign;
  780. is_first_field := false;
  781. end;
  782. {$endif powerpc}
  783. { types that use init/final are not allowed in variant parts, but
  784. classes are allowed }
  785. if (variantrecordlevel>0) and
  786. (tt.def.needs_inittable and not is_class(tt.def)) then
  787. Message(parser_e_cant_use_inittable_here);
  788. ignore_equal:=false;
  789. hasdefaultvalue:=false;
  790. symdone:=false;
  791. if is_gpc_name then
  792. begin
  793. vs:=tabstractvarsym(sc.first);
  794. if assigned(vs.listnext) then
  795. Message(parser_e_absolute_only_one_var);
  796. vs.vartype:=tt;
  797. if vs.typ=globalvarsym then
  798. begin
  799. tglobalvarsym(vs).set_mangledname(target_info.Cprefix+sorg);
  800. include(vs.varoptions,vo_is_C_var);
  801. include(vs.varoptions,vo_is_external);
  802. end
  803. else
  804. Message(parser_e_no_local_var_external);
  805. symdone:=true;
  806. end;
  807. { check for absolute }
  808. if not symdone and
  809. (idtoken=_ABSOLUTE) and not(is_record or is_object or is_threadvar) then
  810. begin
  811. consume(_ABSOLUTE);
  812. abssym:=nil;
  813. { only allowed for one var }
  814. vs:=tabstractvarsym(sc.first);
  815. if assigned(vs.listnext) then
  816. Message(parser_e_absolute_only_one_var);
  817. { parse the rest }
  818. pt:=expr;
  819. { check allowed absolute types }
  820. if (pt.nodetype=stringconstn) or
  821. (is_constcharnode(pt)) then
  822. begin
  823. abssym:=tabsolutevarsym.create(vs.realname,tt);
  824. abssym.fileinfo:=vs.fileinfo;
  825. if pt.nodetype=stringconstn then
  826. hs:=strpas(tstringconstnode(pt).value_str)
  827. else
  828. hs:=chr(tordconstnode(pt).value);
  829. consume(token);
  830. abssym.abstyp:=toasm;
  831. abssym.asmname:=stringdup(hs);
  832. { replace the varsym }
  833. symtablestack.replace(vs,abssym);
  834. vs.free;
  835. end
  836. { address }
  837. else if is_constintnode(pt) and
  838. ((target_info.system in [system_i386_go32v2,system_i386_watcom,
  839. system_i386_wdosx,system_i386_win32]) or
  840. (m_objfpc in aktmodeswitches) or
  841. (m_delphi in aktmodeswitches)) then
  842. begin
  843. abssym:=tabsolutevarsym.create(vs.realname,tt);
  844. abssym.fileinfo:=vs.fileinfo;
  845. abssym.abstyp:=toaddr;
  846. abssym.addroffset:=tordconstnode(pt).value;
  847. {$ifdef i386}
  848. abssym.absseg:=false;
  849. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  850. try_to_consume(_COLON) then
  851. begin
  852. pt.free;
  853. pt:=expr;
  854. if is_constintnode(pt) then
  855. begin
  856. abssym.addroffset:=abssym.addroffset shl 4+tordconstnode(pt).value;
  857. abssym.absseg:=true;
  858. end
  859. else
  860. Message(type_e_ordinal_expr_expected);
  861. end;
  862. {$endif i386}
  863. symtablestack.replace(vs,abssym);
  864. vs.free;
  865. end
  866. { variable }
  867. else
  868. begin
  869. { remove subscriptn before checking for loadn }
  870. hp:=pt;
  871. while (hp.nodetype in [subscriptn,typeconvn,vecn]) do
  872. hp:=tunarynode(hp).left;
  873. if (hp.nodetype=loadn) then
  874. begin
  875. { we should check the result type of loadn }
  876. if not (tloadnode(hp).symtableentry.typ in [fieldvarsym,globalvarsym,localvarsym,
  877. paravarsym,typedconstsym]) then
  878. Message(parser_e_absolute_only_to_var_or_const);
  879. abssym:=tabsolutevarsym.create(vs.realname,tt);
  880. abssym.fileinfo:=vs.fileinfo;
  881. abssym.abstyp:=tovar;
  882. abssym.ref:=node_to_symlist(pt);
  883. symtablestack.replace(vs,abssym);
  884. vs.free;
  885. end
  886. else
  887. Message(parser_e_absolute_only_to_var_or_const);
  888. end;
  889. if assigned(abssym) then
  890. begin
  891. { try to consume the hint directives with absolute symbols }
  892. dummysymoptions:=[];
  893. try_consume_hintdirective(dummysymoptions);
  894. abssym.symoptions := abssym.symoptions + dummysymoptions;
  895. end;
  896. pt.free;
  897. symdone:=true;
  898. end;
  899. { Process procvar directives before = and ; }
  900. if (tt.def.deftype=procvardef) and
  901. (tt.def.typesym=nil) and
  902. check_proc_directive(true) then
  903. begin
  904. newtype:=ttypesym.create('unnamed',tt);
  905. parse_var_proc_directives(tsym(newtype));
  906. newtype.restype.def:=nil;
  907. tt.def.typesym:=nil;
  908. newtype.free;
  909. end;
  910. { try to parse the hint directives }
  911. dummysymoptions:=[];
  912. try_consume_hintdirective(dummysymoptions);
  913. { Records and objects can't have default values }
  914. if is_record or is_object then
  915. begin
  916. { for a record there doesn't need to be a ; before the END or ) }
  917. if not(token in [_END,_RKLAMMER]) then
  918. consume(_SEMICOLON);
  919. end
  920. else
  921. begin
  922. { Handling of Delphi typed const = initialized vars }
  923. if (token=_EQUAL) and
  924. not(m_tp7 in aktmodeswitches) and
  925. (symtablestack.symtabletype<>parasymtable) then
  926. begin
  927. if (tt.def.deftype=procvardef) and
  928. (tt.def.typesym=nil) then
  929. begin
  930. { Add calling convention for procvar }
  931. handle_calling_convention(tprocvardef(tt.def));
  932. end;
  933. read_default_value(sc,tt,is_threadvar);
  934. { for locals we've created typedconstsym with a different name }
  935. if symtablestack.symtabletype<>localsymtable then
  936. symdone:=true;
  937. hasdefaultvalue:=true;
  938. end;
  939. consume(_SEMICOLON);
  940. end;
  941. { Support calling convention for procvars after semicolon }
  942. if not(hasdefaultvalue) and
  943. (tt.def.deftype=procvardef) and
  944. (tt.def.typesym=nil) then
  945. begin
  946. { Parse procvar directives after ; }
  947. if check_proc_directive(true) then
  948. begin
  949. newtype:=ttypesym.create('unnamed',tt);
  950. parse_var_proc_directives(tsym(newtype));
  951. newtype.restype.def:=nil;
  952. tt.def.typesym:=nil;
  953. newtype.free;
  954. end;
  955. { Add calling convention for procvar }
  956. handle_calling_convention(tprocvardef(tt.def));
  957. { Handling of Delphi typed const = initialized vars }
  958. if (token=_EQUAL) and
  959. not(is_record or is_object) and
  960. not(m_tp7 in aktmodeswitches) and
  961. (symtablestack.symtabletype<>parasymtable) then
  962. begin
  963. read_default_value(sc,tt,is_threadvar);
  964. consume(_SEMICOLON);
  965. symdone:=true;
  966. hasdefaultvalue:=true;
  967. end;
  968. end;
  969. { Check for EXTERNAL etc directives or, in macpas, if cs_external_var is set}
  970. if not symdone and not(is_record or is_object or is_threadvar) then
  971. begin
  972. if (
  973. (token=_ID) and
  974. (m_cvar_support in aktmodeswitches) and
  975. (idtoken in [_EXPORT,_EXTERNAL,_PUBLIC,_CVAR])
  976. ) or
  977. (
  978. (m_mac in aktmodeswitches) and
  979. ((cs_external_var in aktlocalswitches) or (cs_externally_visible in aktlocalswitches))
  980. ) then
  981. begin
  982. { only allowed for one var }
  983. vs:=tabstractvarsym(sc.first);
  984. if assigned(vs.listnext) then
  985. Message(parser_e_absolute_only_one_var);
  986. { set type of the var }
  987. vs.vartype:=tt;
  988. vs.symoptions := vs.symoptions + dummysymoptions;
  989. { defaults }
  990. is_dll:=false;
  991. is_cdecl:=false;
  992. extern_var:=false;
  993. export_var:=false;
  994. C_name:=sorg;
  995. semicolonatend:= false;
  996. { cdecl }
  997. if idtoken=_CVAR then
  998. begin
  999. consume(_CVAR);
  1000. consume(_SEMICOLON);
  1001. is_cdecl:=true;
  1002. C_name:=target_info.Cprefix+sorg;
  1003. end;
  1004. { external }
  1005. if idtoken=_EXTERNAL then
  1006. begin
  1007. consume(_EXTERNAL);
  1008. extern_var:=true;
  1009. semicolonatend:= true;
  1010. end;
  1011. { macpas specific handling due to some switches}
  1012. if (m_mac in aktmodeswitches) then
  1013. begin
  1014. if (cs_external_var in aktlocalswitches) then
  1015. begin {The effect of this is the same as if cvar; external; has been given as directives.}
  1016. is_cdecl:=true;
  1017. C_name:=target_info.Cprefix+sorg;
  1018. extern_var:=true;
  1019. end
  1020. else if (cs_externally_visible in aktlocalswitches) then
  1021. begin {The effect of this is the same as if cvar has been given as directives.}
  1022. is_cdecl:=true;
  1023. C_name:=target_info.Cprefix+sorg;
  1024. end;
  1025. end;
  1026. { export }
  1027. if idtoken in [_EXPORT,_PUBLIC] then
  1028. begin
  1029. consume(_ID);
  1030. if extern_var then
  1031. Message(parser_e_not_external_and_export)
  1032. else
  1033. begin
  1034. export_var:=true;
  1035. semicolonatend:= true;
  1036. end;
  1037. end;
  1038. { external and export need a name after when no cdecl is used }
  1039. if not is_cdecl then
  1040. begin
  1041. { dll name ? }
  1042. if (extern_var) and (idtoken<>_NAME) then
  1043. begin
  1044. is_dll:=true;
  1045. dll_name:=get_stringconst;
  1046. end;
  1047. consume(_NAME);
  1048. C_name:=get_stringconst;
  1049. end;
  1050. { consume the ; when export or external is used }
  1051. if semicolonatend then
  1052. consume(_SEMICOLON);
  1053. { set some vars options }
  1054. if is_dll then
  1055. include(vs.varoptions,vo_is_dll_var)
  1056. else
  1057. include(vs.varoptions,vo_is_C_var);
  1058. if (is_dll) and
  1059. (target_info.system = system_powerpc_darwin) then
  1060. C_Name := target_info.Cprefix+C_Name;
  1061. if export_var then
  1062. begin
  1063. inc(vs.refs);
  1064. include(vs.varoptions,vo_is_exported);
  1065. end;
  1066. if extern_var then
  1067. include(vs.varoptions,vo_is_external);
  1068. if vs.typ=globalvarsym then
  1069. begin
  1070. tglobalvarsym(vs).set_mangledname(C_Name);
  1071. { insert in the datasegment when it is not external }
  1072. if (not extern_var) then
  1073. insertbssdata(tglobalvarsym(vs));
  1074. { now we can insert it in the import lib if its a dll, or
  1075. add it to the externals }
  1076. if extern_var then
  1077. begin
  1078. vs.varregable := vr_none;
  1079. if is_dll then
  1080. begin
  1081. if not(current_module.uses_imports) then
  1082. begin
  1083. current_module.uses_imports:=true;
  1084. importlib.preparelib(current_module.realmodulename^);
  1085. end;
  1086. importlib.importvariable(tglobalvarsym(vs),C_name,dll_name);
  1087. end
  1088. else
  1089. if target_info.DllScanSupported then
  1090. current_module.Externals.insert(tExternalsItem.create(vs.mangledname));
  1091. end;
  1092. end
  1093. else
  1094. Message(parser_e_no_local_var_external);
  1095. symdone:=true;
  1096. end;
  1097. end;
  1098. { Check for STATIC directive }
  1099. if not symdone and (is_object) and
  1100. (cs_static_keyword in aktmoduleswitches) and (idtoken=_STATIC) then
  1101. begin
  1102. include(current_object_option,sp_static);
  1103. insert_syms(sc,tt,false,dummysymoptions);
  1104. exclude(current_object_option,sp_static);
  1105. consume(_STATIC);
  1106. consume(_SEMICOLON);
  1107. symdone:=true;
  1108. end;
  1109. { insert it in the symtable, if not done yet }
  1110. if not symdone then
  1111. begin
  1112. { save object option, because we can turn of the sp_published }
  1113. if (sp_published in current_object_option) and
  1114. not(is_class(tt.def)) then
  1115. begin
  1116. Message(parser_e_cant_publish_that);
  1117. exclude(current_object_option,sp_published);
  1118. { recover by changing access type to public }
  1119. vs2:=tabstractvarsym(sc.first);
  1120. while assigned (vs2) do
  1121. begin
  1122. exclude(vs2.symoptions,sp_published);
  1123. include(vs2.symoptions,sp_public);
  1124. vs2:=tabstractvarsym(vs2.listnext);
  1125. end;
  1126. end
  1127. else
  1128. if (sp_published in current_object_option) and
  1129. not(oo_can_have_published in tobjectdef(tt.def).objectoptions) then
  1130. begin
  1131. Message(parser_e_only_publishable_classes_can__be_published);
  1132. exclude(current_object_option,sp_published);
  1133. end;
  1134. insert_syms(sc,tt,is_threadvar,dummysymoptions);
  1135. current_object_option:=old_current_object_option;
  1136. end;
  1137. end;
  1138. { Check for Case }
  1139. if is_record and (token=_CASE) then
  1140. begin
  1141. maxsize:=0;
  1142. maxalignment:=0;
  1143. maxpadalign:=0;
  1144. consume(_CASE);
  1145. sorg:=orgpattern;
  1146. hs:=pattern;
  1147. searchsym(hs,srsym,srsymtable);
  1148. { may be only a type: }
  1149. if assigned(srsym) and (srsym.typ in [typesym,unitsym]) then
  1150. begin
  1151. { for records, don't search the recordsymtable for
  1152. the symbols of the types }
  1153. oldsymtablestack:=symtablestack;
  1154. symtablestack:=symtablestack.next;
  1155. read_type(casetype,'',true);
  1156. symtablestack:=oldsymtablestack;
  1157. end
  1158. else
  1159. begin
  1160. consume(_ID);
  1161. consume(_COLON);
  1162. { for records, don't search the recordsymtable for
  1163. the symbols of the types }
  1164. oldsymtablestack:=symtablestack;
  1165. symtablestack:=symtablestack.next;
  1166. read_type(casetype,'',true);
  1167. symtablestack:=oldsymtablestack;
  1168. fieldvs:=tfieldvarsym.create(sorg,vs_value,casetype,[]);
  1169. tabstractrecordsymtable(symtablestack).insertfield(fieldvs,true);
  1170. end;
  1171. if not(is_ordinal(casetype.def))
  1172. {$ifndef cpu64bit}
  1173. or is_64bitint(casetype.def)
  1174. {$endif cpu64bit}
  1175. then
  1176. Message(type_e_ordinal_expr_expected);
  1177. consume(_OF);
  1178. UnionSymtable:=trecordsymtable.create(aktpackrecords);
  1179. Unionsymtable.next:=symtablestack;
  1180. registerdef:=false;
  1181. UnionDef:=trecorddef.create(unionsymtable);
  1182. uniondef.isunion:=true;
  1183. if assigned(symtablestack.defowner) then
  1184. Uniondef.owner:=symtablestack.defowner.owner;
  1185. registerdef:=true;
  1186. startvarrecsize:=UnionSymtable.datasize;
  1187. startvarrecalign:=UnionSymtable.fieldalignment;
  1188. startpadalign:=Unionsymtable.padalignment;
  1189. symtablestack:=UnionSymtable;
  1190. repeat
  1191. repeat
  1192. pt:=comp_expr(true);
  1193. if not(pt.nodetype=ordconstn) then
  1194. Message(parser_e_illegal_expression);
  1195. pt.free;
  1196. if token=_COMMA then
  1197. consume(_COMMA)
  1198. else
  1199. break;
  1200. until false;
  1201. consume(_COLON);
  1202. { read the vars }
  1203. consume(_LKLAMMER);
  1204. inc(variantrecordlevel);
  1205. if token<>_RKLAMMER then
  1206. read_var_decs(true,false,false);
  1207. dec(variantrecordlevel);
  1208. consume(_RKLAMMER);
  1209. { calculates maximal variant size }
  1210. maxsize:=max(maxsize,unionsymtable.datasize);
  1211. maxalignment:=max(maxalignment,unionsymtable.fieldalignment);
  1212. maxpadalign:=max(maxpadalign,unionsymtable.padalignment);
  1213. { the items of the next variant are overlayed }
  1214. unionsymtable.datasize:=startvarrecsize;
  1215. unionsymtable.fieldalignment:=startvarrecalign;
  1216. unionsymtable.padalignment:=startpadalign;
  1217. if (token<>_END) and (token<>_RKLAMMER) then
  1218. consume(_SEMICOLON)
  1219. else
  1220. break;
  1221. until (token=_END) or (token=_RKLAMMER);
  1222. { at last set the record size to that of the biggest variant }
  1223. unionsymtable.datasize:=maxsize;
  1224. unionsymtable.fieldalignment:=maxalignment;
  1225. uniontype.def:=uniondef;
  1226. uniontype.sym:=nil;
  1227. UnionSym:=tfieldvarsym.create('$case',vs_value,uniontype,[]);
  1228. symtablestack:=symtablestack.next;
  1229. unionsymtable.addalignmentpadding;
  1230. {$ifdef powerpc}
  1231. { parent inherits the alignment padding if the variant is the first "field" of the parent record/variant }
  1232. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  1233. is_first_field and
  1234. (trecordsymtable(symtablestack).usefieldalignment = -1) and
  1235. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  1236. trecordsymtable(symtablestack).padalignment:=maxpadalign;
  1237. {$endif powerpc}
  1238. { Align the offset where the union symtable is added }
  1239. if (trecordsymtable(symtablestack).usefieldalignment=-1) then
  1240. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.maxCrecordalign)
  1241. else
  1242. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.recordalignmax);
  1243. offset:=align(trecordsymtable(symtablestack).datasize,usedalign);
  1244. trecordsymtable(symtablestack).datasize:=offset+unionsymtable.datasize;
  1245. if unionsymtable.recordalignment>trecordsymtable(symtablestack).fieldalignment then
  1246. trecordsymtable(symtablestack).fieldalignment:=unionsymtable.recordalignment;
  1247. trecordsymtable(symtablestack).insertunionst(Unionsymtable,offset);
  1248. Unionsym.owner:=nil;
  1249. unionsym.free;
  1250. uniondef.owner:=nil;
  1251. uniondef.free;
  1252. end;
  1253. block_type:=old_block_type;
  1254. current_object_option:=old_current_object_option;
  1255. { free the list }
  1256. sc.free;
  1257. {$ifdef powerpc}
  1258. is_first_field := false;
  1259. {$endif powerpc}
  1260. end;
  1261. end.
  1262. {
  1263. $Log$
  1264. Revision 1.90 2005-01-04 16:52:07 peter
  1265. * don't typecast index of indexed properties
  1266. Revision 1.89 2005/01/04 16:37:38 peter
  1267. * give error when property doesn't reference a method or field
  1268. Revision 1.88 2004/12/11 15:19:08 jonas
  1269. * external vars are not regable
  1270. Revision 1.87 2004/12/07 16:11:52 peter
  1271. * set vo_explicit_paraloc flag
  1272. Revision 1.86 2004/11/29 18:50:15 peter
  1273. * os2 fixes for import
  1274. * asmsymtype support for intel reader
  1275. Revision 1.85 2004/11/16 20:32:40 peter
  1276. * fixes for win32 mangledname
  1277. Revision 1.84 2004/11/15 23:35:31 peter
  1278. * tparaitem removed, use tparavarsym instead
  1279. * parameter order is now calculated from paranr value in tparavarsym
  1280. Revision 1.83 2004/11/09 22:32:59 peter
  1281. * small m68k updates to bring it up2date
  1282. * give better error for external local variable
  1283. Revision 1.82 2004/11/08 22:09:59 peter
  1284. * tvarsym splitted
  1285. Revision 1.81 2004/10/15 09:14:17 mazen
  1286. - remove $IFDEF DELPHI and related code
  1287. - remove $IFDEF FPCPROCVAR and related code
  1288. Revision 1.80 2004/10/12 14:36:38 peter
  1289. * gen high tree makes copy in temp when there is a calln
  1290. Revision 1.79 2004/08/17 16:29:21 jonas
  1291. + padalgingment field for recordsymtables (saved by recorddefs)
  1292. + support for Macintosh PowerPC alignment (if the first field of a record
  1293. or union has an alignment > 4, then the record or union size must be
  1294. padded to a multiple of this size)
  1295. Revision 1.78 2004/08/15 13:30:18 florian
  1296. * fixed alignment of variant records
  1297. * more alignment problems fixed
  1298. Revision 1.77 2004/08/07 19:14:50 florian
  1299. * fixed problem with explicit specified calling conventions for property symbols
  1300. Revision 1.76 2004/07/14 23:19:22 olle
  1301. + added external facilities for macpas
  1302. Revision 1.75 2004/06/20 08:55:30 florian
  1303. * logs truncated
  1304. Revision 1.74 2004/06/16 20:07:09 florian
  1305. * dwarf branch merged
  1306. Revision 1.73 2004/04/11 12:38:16 peter
  1307. * fix calling convention problem when parsing default value before
  1308. the semicolon
  1309. Revision 1.72.2.5 2004/05/02 20:54:04 peter
  1310. * allow convert when choosing property function with index
  1311. Revision 1.72.2.4 2004/05/01 20:51:20 peter
  1312. * fix val code parameter
  1313. Revision 1.72.2.3 2004/04/28 19:55:52 peter
  1314. * new warning for ordinal-pointer when size is different
  1315. * fixed some cg_e_ messages to the correct section type_e_ or parser_e_
  1316. }