pdecvar.pas 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  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. varspez : tvarspez;
  191. tt : ttype;
  192. arraytype : ttype;
  193. def : tdef;
  194. pt : tnode;
  195. propname : stringid;
  196. sc : tsinglelist;
  197. paranr : word;
  198. oldregisterdef : boolean;
  199. hreadparavs,
  200. hparavs : tparavarsym;
  201. readprocdef,
  202. writeprocdef : tprocvardef;
  203. oldsymtablestack : tsymtable;
  204. begin
  205. { Generate temp procvardefs to search for matching read/write
  206. procedures. the readprocdef will store all definitions }
  207. oldregisterdef:=registerdef;
  208. registerdef:=false;
  209. paranr:=0;
  210. readprocdef:=tprocvardef.create(normal_function_level);
  211. writeprocdef:=tprocvardef.create(normal_function_level);
  212. registerdef:=oldregisterdef;
  213. { make it method pointers }
  214. if assigned(aclass) then
  215. begin
  216. include(readprocdef.procoptions,po_methodpointer);
  217. include(writeprocdef.procoptions,po_methodpointer);
  218. end;
  219. if token<>_ID then
  220. begin
  221. consume(_ID);
  222. consume(_SEMICOLON);
  223. exit;
  224. end;
  225. { Generate propertysym and insert in symtablestack }
  226. p:=tpropertysym.create(orgpattern);
  227. symtablestack.insert(p);
  228. propname:=pattern;
  229. consume(_ID);
  230. { Set the symtablestack to the parast of readprop so
  231. temp defs will be destroyed after declaration }
  232. readprocdef.parast.next:=symtablestack;
  233. symtablestack:=readprocdef.parast;
  234. { property parameters ? }
  235. if token=_LECKKLAMMER then
  236. begin
  237. if (sp_published in current_object_option) then
  238. Message(parser_e_cant_publish_that_property);
  239. { create a list of the parameters }
  240. sc:=tsinglelist.create;
  241. consume(_LECKKLAMMER);
  242. inc(testcurobject);
  243. repeat
  244. if token=_VAR then
  245. begin
  246. consume(_VAR);
  247. varspez:=vs_var;
  248. end
  249. else if token=_CONST then
  250. begin
  251. consume(_CONST);
  252. varspez:=vs_const;
  253. end
  254. else if (idtoken=_OUT) and (m_out in aktmodeswitches) then
  255. begin
  256. consume(_OUT);
  257. varspez:=vs_out;
  258. end
  259. else
  260. varspez:=vs_value;
  261. sc.reset;
  262. repeat
  263. inc(paranr);
  264. hreadparavs:=tparavarsym.create(orgpattern,10*paranr,varspez,generrortype,[]);
  265. readprocdef.parast.insert(hreadparavs);
  266. sc.insert(hreadparavs);
  267. consume(_ID);
  268. until not try_to_consume(_COMMA);
  269. if try_to_consume(_COLON) then
  270. begin
  271. { for records, don't search the recordsymtable for
  272. the symbols of the types }
  273. oldsymtablestack:=symtablestack;
  274. symtablestack:=symtablestack.next;
  275. if try_to_consume(_ARRAY) then
  276. begin
  277. consume(_OF);
  278. { define range and type of range }
  279. tt.setdef(tarraydef.create(0,-1,s32inttype));
  280. { define field type }
  281. single_type(arraytype,false);
  282. tarraydef(tt.def).setelementtype(arraytype);
  283. end
  284. else
  285. single_type(tt,false);
  286. symtablestack:=oldsymtablestack;
  287. end
  288. else
  289. tt:=cformaltype;
  290. hreadparavs:=tparavarsym(sc.first);
  291. while assigned(hreadparavs) do
  292. begin
  293. hreadparavs.vartype:=tt;
  294. { also update the writeprocdef }
  295. hparavs:=tparavarsym.create(hreadparavs.realname,hreadparavs.paranr,vs_value,tt,[]);
  296. writeprocdef.parast.insert(hparavs);
  297. hreadparavs:=tparavarsym(hreadparavs.listnext);
  298. end;
  299. until not try_to_consume(_SEMICOLON);
  300. sc.free;
  301. dec(testcurobject);
  302. consume(_RECKKLAMMER);
  303. { the parser need to know if a property has parameters, the
  304. index parameter doesn't count (PFV) }
  305. if paranr>0 then
  306. include(p.propoptions,ppo_hasparameters);
  307. end;
  308. { overriden property ? }
  309. { force property interface
  310. there is a property parameter
  311. a global property }
  312. if (token=_COLON) or (paranr>0) or (aclass=nil) then
  313. begin
  314. consume(_COLON);
  315. { insert types in global symtable }
  316. oldsymtablestack:=symtablestack;
  317. while not(symtablestack.symtabletype in [globalsymtable,staticsymtable]) do
  318. symtablestack:=symtablestack.next;
  319. single_type(p.proptype,false);
  320. symtablestack:=oldsymtablestack;
  321. if (idtoken=_INDEX) then
  322. begin
  323. consume(_INDEX);
  324. pt:=comp_expr(true);
  325. if is_constnode(pt) and
  326. is_ordinal(pt.resulttype.def)
  327. {$ifndef cpu64bit}
  328. and (not is_64bitint(pt.resulttype.def))
  329. {$endif}
  330. then
  331. p.index:=tordconstnode(pt).value
  332. else
  333. begin
  334. Message(parser_e_invalid_property_index_value);
  335. p.index:=0;
  336. end;
  337. p.indextype.setdef(pt.resulttype.def);
  338. include(p.propoptions,ppo_indexed);
  339. { concat a longint to the para templates }
  340. inc(paranr);
  341. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,p.indextype,[]);
  342. readprocdef.parast.insert(hparavs);
  343. hparavs:=tparavarsym.create('$index',10*paranr,vs_value,p.indextype,[]);
  344. writeprocdef.parast.insert(hparavs);
  345. pt.free;
  346. end;
  347. end
  348. else
  349. begin
  350. { do an property override }
  351. overriden:=search_class_member(aclass.childof,propname);
  352. if assigned(overriden) and (overriden.typ=propertysym) then
  353. begin
  354. p.dooverride(tpropertysym(overriden));
  355. end
  356. else
  357. begin
  358. p.proptype:=generrortype;
  359. message(parser_e_no_property_found_to_override);
  360. end;
  361. end;
  362. if (sp_published in current_object_option) and
  363. not(p.proptype.def.is_publishable) then
  364. Message(parser_e_cant_publish_that_property);
  365. if try_to_consume(_READ) then
  366. begin
  367. p.readaccess.clear;
  368. if parse_symlist(p.readaccess,def) then
  369. begin
  370. sym:=p.readaccess.firstsym^.sym;
  371. case sym.typ of
  372. procsym :
  373. begin
  374. { read is function returning the type of the property }
  375. readprocdef.rettype:=p.proptype;
  376. { Insert hidden parameters }
  377. handle_calling_convention(readprocdef);
  378. { search procdefs matching readprocdef }
  379. { we ignore hidden stuff here because the property access symbol might have
  380. non default calling conventions which might change the hidden stuff;
  381. see tw3216.pp (FK) }
  382. p.readaccess.procdef:=Tprocsym(sym).search_procdef_bypara(readprocdef.paras,p.proptype.def,[cpo_allowdefaults,cpo_ignorehidden,cpo_allowconvert]);
  383. if not assigned(p.readaccess.procdef) then
  384. Message(parser_e_ill_property_access_sym);
  385. end;
  386. fieldvarsym :
  387. begin
  388. if not assigned(def) then
  389. internalerror(200310071);
  390. if compare_defs(def,p.proptype.def,nothingn)>=te_equal then
  391. begin
  392. { property parameters are allowed if this is
  393. an indexed property, because the index is then
  394. the parameter.
  395. Note: In the help of Kylix it is written
  396. that it isn't allowed, but the compiler accepts it (PFV) }
  397. if (ppo_hasparameters in p.propoptions) then
  398. Message(parser_e_ill_property_access_sym);
  399. end
  400. else
  401. IncompatibleTypes(def,p.proptype.def);
  402. end;
  403. else
  404. Message(parser_e_ill_property_access_sym);
  405. end;
  406. end;
  407. end;
  408. if try_to_consume(_WRITE) then
  409. begin
  410. p.writeaccess.clear;
  411. if parse_symlist(p.writeaccess,def) then
  412. begin
  413. sym:=p.writeaccess.firstsym^.sym;
  414. case sym.typ of
  415. procsym :
  416. begin
  417. { write is a procedure with an extra value parameter
  418. of the of the property }
  419. writeprocdef.rettype:=voidtype;
  420. inc(paranr);
  421. hparavs:=tparavarsym.create('$value',10*paranr,vs_value,p.proptype,[]);
  422. writeprocdef.parast.insert(hparavs);
  423. { Insert hidden parameters }
  424. handle_calling_convention(writeprocdef);
  425. { search procdefs matching writeprocdef }
  426. p.writeaccess.procdef:=Tprocsym(sym).search_procdef_bypara(writeprocdef.paras,writeprocdef.rettype.def,[cpo_allowdefaults,cpo_allowconvert]);
  427. if not assigned(p.writeaccess.procdef) then
  428. Message(parser_e_ill_property_access_sym);
  429. end;
  430. fieldvarsym :
  431. begin
  432. if not assigned(def) then
  433. internalerror(200310072);
  434. if compare_defs(def,p.proptype.def,nothingn)>=te_equal then
  435. begin
  436. { property parameters are allowed if this is
  437. an indexed property, because the index is then
  438. the parameter.
  439. Note: In the help of Kylix it is written
  440. that it isn't allowed, but the compiler accepts it (PFV) }
  441. if (ppo_hasparameters in p.propoptions) then
  442. Message(parser_e_ill_property_access_sym);
  443. end
  444. else
  445. IncompatibleTypes(def,p.proptype.def);
  446. end;
  447. else
  448. Message(parser_e_ill_property_access_sym);
  449. end;
  450. end;
  451. end;
  452. if assigned(aclass) then
  453. begin
  454. include(p.propoptions,ppo_stored);
  455. if try_to_consume(_STORED) then
  456. begin
  457. p.storedaccess.clear;
  458. case token of
  459. _ID:
  460. begin
  461. { in the case that idtoken=_DEFAULT }
  462. { we have to do nothing except }
  463. { setting ppo_stored, it's the same }
  464. { as stored true }
  465. if idtoken<>_DEFAULT then
  466. begin
  467. if parse_symlist(p.storedaccess,def) then
  468. begin
  469. sym:=p.storedaccess.firstsym^.sym;
  470. case sym.typ of
  471. procsym :
  472. begin
  473. p.storedaccess.procdef:=Tprocsym(sym).search_procdef_nopara_boolret;
  474. if not assigned(p.storedaccess.procdef) then
  475. message(parser_e_ill_property_storage_sym);
  476. end;
  477. fieldvarsym :
  478. begin
  479. if not assigned(def) then
  480. internalerror(200310073);
  481. if (ppo_hasparameters in p.propoptions) or
  482. not(is_boolean(def)) then
  483. Message(parser_e_stored_property_must_be_boolean);
  484. end;
  485. else
  486. Message(parser_e_ill_property_access_sym);
  487. end;
  488. end;
  489. end;
  490. end;
  491. _FALSE:
  492. begin
  493. consume(_FALSE);
  494. exclude(p.propoptions,ppo_stored);
  495. end;
  496. _TRUE:
  497. consume(_TRUE);
  498. end;
  499. end;
  500. end;
  501. if try_to_consume(_DEFAULT) then
  502. begin
  503. if not(is_ordinal(p.proptype.def) or
  504. {$ifndef cpu64bit}
  505. is_64bitint(p.proptype.def) or
  506. {$endif cpu64bit}
  507. is_class(p.proptype.def) or
  508. is_single(p.proptype.def) or
  509. (p.proptype.def.deftype in [classrefdef,pointerdef]) or
  510. ((p.proptype.def.deftype=setdef) and
  511. (tsetdef(p.proptype.def).settype=smallset))) or
  512. ((p.proptype.def.deftype=arraydef) and
  513. (ppo_indexed in p.propoptions)) or
  514. (ppo_hasparameters in p.propoptions) then
  515. begin
  516. Message(parser_e_property_cant_have_a_default_value);
  517. { Error recovery }
  518. pt:=comp_expr(true);
  519. pt.free;
  520. end
  521. else
  522. begin
  523. { Get the result of the default, the firstpass is
  524. needed to support values like -1 }
  525. pt:=comp_expr(true);
  526. if (p.proptype.def.deftype=setdef) and
  527. (pt.nodetype=arrayconstructorn) then
  528. begin
  529. arrayconstructor_to_set(pt);
  530. do_resulttypepass(pt);
  531. end;
  532. inserttypeconv(pt,p.proptype);
  533. if not(is_constnode(pt)) then
  534. Message(parser_e_property_default_value_must_const);
  535. { Set default value }
  536. case pt.nodetype of
  537. setconstn :
  538. p.default:=plongint(tsetconstnode(pt).value_set)^;
  539. ordconstn :
  540. p.default:=tordconstnode(pt).value;
  541. niln :
  542. p.default:=0;
  543. realconstn:
  544. p.default:=longint(single(trealconstnode(pt).value_real));
  545. end;
  546. pt.free;
  547. end;
  548. end
  549. else if try_to_consume(_NODEFAULT) then
  550. begin
  551. p.default:=0;
  552. end;
  553. { remove temporary procvardefs }
  554. symtablestack:=symtablestack.next;
  555. readprocdef.free;
  556. writeprocdef.free;
  557. result:=p;
  558. end;
  559. const
  560. variantrecordlevel : longint = 0;
  561. procedure read_var_decs(is_record,is_object,is_threadvar:boolean);
  562. { reads the filed of a record into a }
  563. { symtablestack, if record=false }
  564. { variants are forbidden, so this procedure }
  565. { can be used to read object fields }
  566. { if absolute is true, ABSOLUTE and file }
  567. { types are allowed }
  568. { => the procedure is also used to read }
  569. { a sequence of variable declaration }
  570. procedure insert_syms(sc : tsinglelist;tt : ttype;is_threadvar : boolean; addsymopts : tsymoptions);
  571. { inserts the symbols of sc in st with def as definition or sym as ttypesym, sc is disposed }
  572. var
  573. vs : tabstractvarsym;
  574. hstaticvs : tglobalvarsym;
  575. begin
  576. vs:=tabstractvarsym(sc.first);
  577. while assigned(vs) do
  578. begin
  579. vs.vartype:=tt;
  580. { insert any additional hint directives }
  581. vs.symoptions := vs.symoptions + addsymopts;
  582. if (sp_static in current_object_option) then
  583. include(vs.symoptions,sp_static);
  584. if is_threadvar then
  585. include(vs.varoptions,vo_is_thread_var);
  586. { static data fields are inserted in the globalsymtable }
  587. if (symtablestack.symtabletype=objectsymtable) and
  588. (sp_static in current_object_option) then
  589. begin
  590. hstaticvs:=tglobalvarsym.create('$'+lower(symtablestack.name^)+'_'+vs.name,vs_value,tt,[]);
  591. symtablestack.defowner.owner.insert(hstaticvs);
  592. insertbssdata(hstaticvs);
  593. end
  594. else
  595. begin
  596. { external data is not possible here }
  597. case symtablestack.symtabletype of
  598. globalsymtable,
  599. staticsymtable :
  600. insertbssdata(tglobalvarsym(vs));
  601. recordsymtable,
  602. objectsymtable :
  603. tabstractrecordsymtable(symtablestack).insertfield(tfieldvarsym(vs),false);
  604. end;
  605. end;
  606. vs:=tabstractvarsym(vs.listnext);
  607. end;
  608. end;
  609. procedure read_default_value(sc : tsinglelist;tt : ttype;is_threadvar : boolean);
  610. var
  611. vs : tabstractnormalvarsym;
  612. tcsym : ttypedconstsym;
  613. begin
  614. vs:=tabstractnormalvarsym(sc.first);
  615. if assigned(vs.listnext) then
  616. Message(parser_e_initialized_only_one_var);
  617. if is_threadvar then
  618. Message(parser_e_initialized_not_for_threadvar);
  619. if symtablestack.symtabletype=localsymtable then
  620. begin
  621. consume(_EQUAL);
  622. tcsym:=ttypedconstsym.createtype('default'+vs.realname,tt,false);
  623. vs.defaultconstsym:=tcsym;
  624. symtablestack.insert(tcsym);
  625. insertconstdata(tcsym);
  626. readtypedconst(tt,tcsym,false);
  627. { The variable has a value assigned }
  628. vs.varstate:=vs_assigned;
  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,semicoloneaten: 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. semicoloneaten:=false;
  700. hasdefaultvalue:=false;
  701. symdone:=false;
  702. sc.reset;
  703. repeat
  704. case symtablestack.symtabletype of
  705. localsymtable :
  706. vs:=tlocalvarsym.create(orgpattern,vs_value,generrortype,[]);
  707. staticsymtable,
  708. globalsymtable :
  709. vs:=tglobalvarsym.create(orgpattern,vs_value,generrortype,[]);
  710. recordsymtable,
  711. objectsymtable :
  712. vs:=tfieldvarsym.create(orgpattern,vs_value,generrortype,[]);
  713. else
  714. internalerror(200411064);
  715. end;
  716. symtablestack.insert(vs);
  717. if assigned(vs.owner) then
  718. sc.insert(vs)
  719. else
  720. vs.free;
  721. consume(_ID);
  722. until not try_to_consume(_COMMA);
  723. consume(_COLON);
  724. if (m_gpc in aktmodeswitches) and
  725. not(is_record or is_object or is_threadvar) and
  726. (token=_ID) and (orgpattern='__asmname__') then
  727. begin
  728. consume(_ID);
  729. C_name:=get_stringconst;
  730. Is_gpc_name:=true;
  731. end;
  732. { this is needed for Delphi mode at least
  733. but should be OK for all modes !! (PM) }
  734. ignore_equal:=true;
  735. if is_record or is_object then
  736. begin
  737. { for records, don't search the recordsymtable for
  738. the symbols of the types }
  739. oldsymtablestack:=symtablestack;
  740. symtablestack:=symtablestack.next;
  741. read_type(tt,'',false);
  742. symtablestack:=oldsymtablestack;
  743. end
  744. else
  745. read_type(tt,'',false);
  746. ignore_equal:=false;
  747. { Process procvar directives }
  748. if (tt.def.deftype=procvardef) and
  749. (tt.def.typesym=nil) and
  750. check_proc_directive(true) then
  751. begin
  752. newtype:=ttypesym.create('unnamed',tt);
  753. parse_var_proc_directives(tsym(newtype));
  754. semicoloneaten:=true;
  755. newtype.restype.def:=nil;
  756. tt.def.typesym:=nil;
  757. newtype.free;
  758. end;
  759. {$ifdef powerpc}
  760. { from gcc/gcc/config/rs6000/rs6000.h:
  761. /* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
  762. /* Return the alignment of a struct based on the Macintosh PowerPC
  763. alignment rules. In general the alignment of a struct is
  764. determined by the greatest alignment of its elements. However, the
  765. PowerPC rules cause the alignment of a struct to peg at word
  766. alignment except when the first field has greater than word
  767. (32-bit) alignment, in which case the alignment is determined by
  768. the alignment of the first field. */
  769. }
  770. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  771. is_record and
  772. is_first_field and
  773. (trecordsymtable(symtablestack).usefieldalignment = -1) then
  774. begin
  775. tempdef := tt.def;
  776. while tempdef.deftype = arraydef do
  777. tempdef := tarraydef(tempdef).elementtype.def;
  778. if tempdef.deftype <> recorddef then
  779. maxpadalign := tempdef.alignment
  780. else
  781. maxpadalign := trecorddef(tempdef).padalignment;
  782. if (maxpadalign > 4) and
  783. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  784. trecordsymtable(symtablestack).padalignment := maxpadalign;
  785. is_first_field := false;
  786. end;
  787. {$endif powerpc}
  788. { types that use init/final are not allowed in variant parts, but
  789. classes are allowed }
  790. if (variantrecordlevel>0) and
  791. (tt.def.needs_inittable and not is_class(tt.def)) then
  792. Message(parser_e_cant_use_inittable_here);
  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]) and
  920. not(semicoloneaten) then
  921. consume(_SEMICOLON);
  922. end
  923. else
  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. { Add calling convention for procvar }
  930. if (tt.def.deftype=procvardef) and
  931. (tt.def.typesym=nil) then
  932. handle_calling_convention(tprocvardef(tt.def));
  933. read_default_value(sc,tt,is_threadvar);
  934. consume(_SEMICOLON);
  935. { for locals we've created typedconstsym with a different name }
  936. if symtablestack.symtabletype<>localsymtable then
  937. symdone:=true;
  938. hasdefaultvalue:=true;
  939. end
  940. else
  941. begin
  942. if not(semicoloneaten) then
  943. consume(_SEMICOLON);
  944. end;
  945. { Support calling convention for procvars after semicolon }
  946. if not(hasdefaultvalue) and
  947. (tt.def.deftype=procvardef) and
  948. (tt.def.typesym=nil) then
  949. begin
  950. { Parse procvar directives after ; }
  951. if check_proc_directive(true) then
  952. begin
  953. newtype:=ttypesym.create('unnamed',tt);
  954. parse_var_proc_directives(tsym(newtype));
  955. newtype.restype.def:=nil;
  956. tt.def.typesym:=nil;
  957. newtype.free;
  958. end;
  959. { Add calling convention for procvar }
  960. handle_calling_convention(tprocvardef(tt.def));
  961. { Handling of Delphi typed const = initialized vars }
  962. if (token=_EQUAL) and
  963. not(is_record or is_object) and
  964. not(m_tp7 in aktmodeswitches) and
  965. (symtablestack.symtabletype<>parasymtable) then
  966. begin
  967. read_default_value(sc,tt,is_threadvar);
  968. consume(_SEMICOLON);
  969. symdone:=true;
  970. hasdefaultvalue:=true;
  971. end;
  972. end;
  973. { Check for EXTERNAL etc directives or, in macpas, if cs_external_var is set}
  974. if not symdone and not(is_record or is_object or is_threadvar) then
  975. begin
  976. if (
  977. (token=_ID) and
  978. (m_cvar_support in aktmodeswitches) and
  979. (idtoken in [_EXPORT,_EXTERNAL,_PUBLIC,_CVAR])
  980. ) or
  981. (
  982. (m_mac in aktmodeswitches) and
  983. ((cs_external_var in aktlocalswitches) or (cs_externally_visible in aktlocalswitches))
  984. ) then
  985. begin
  986. { only allowed for one var }
  987. vs:=tabstractvarsym(sc.first);
  988. if assigned(vs.listnext) then
  989. Message(parser_e_absolute_only_one_var);
  990. { set type of the var }
  991. vs.vartype:=tt;
  992. vs.symoptions := vs.symoptions + dummysymoptions;
  993. { defaults }
  994. is_dll:=false;
  995. is_cdecl:=false;
  996. extern_var:=false;
  997. export_var:=false;
  998. C_name:=sorg;
  999. semicolonatend:= false;
  1000. { cdecl }
  1001. if idtoken=_CVAR then
  1002. begin
  1003. consume(_CVAR);
  1004. consume(_SEMICOLON);
  1005. is_cdecl:=true;
  1006. C_name:=target_info.Cprefix+sorg;
  1007. end;
  1008. { external }
  1009. if idtoken=_EXTERNAL then
  1010. begin
  1011. consume(_EXTERNAL);
  1012. extern_var:=true;
  1013. semicolonatend:= true;
  1014. end;
  1015. { macpas specific handling due to some switches}
  1016. if (m_mac in aktmodeswitches) then
  1017. begin
  1018. if (cs_external_var in aktlocalswitches) then
  1019. begin {The effect of this is the same as if cvar; external; has been given as directives.}
  1020. is_cdecl:=true;
  1021. C_name:=target_info.Cprefix+sorg;
  1022. extern_var:=true;
  1023. end
  1024. else if (cs_externally_visible in aktlocalswitches) then
  1025. begin {The effect of this is the same as if cvar has been given as directives.}
  1026. is_cdecl:=true;
  1027. C_name:=target_info.Cprefix+sorg;
  1028. end;
  1029. vs.varregable := vr_none;
  1030. end;
  1031. { export }
  1032. if idtoken in [_EXPORT,_PUBLIC] then
  1033. begin
  1034. consume(_ID);
  1035. if extern_var then
  1036. Message(parser_e_not_external_and_export)
  1037. else
  1038. begin
  1039. export_var:=true;
  1040. semicolonatend:= true;
  1041. end;
  1042. end;
  1043. { external and export need a name after when no cdecl is used }
  1044. if not is_cdecl then
  1045. begin
  1046. { dll name ? }
  1047. if (extern_var) and (idtoken<>_NAME) then
  1048. begin
  1049. is_dll:=true;
  1050. dll_name:=get_stringconst;
  1051. end;
  1052. if try_to_consume(_NAME) then
  1053. C_name:=get_stringconst
  1054. else
  1055. C_name:=sorg;
  1056. end;
  1057. { consume the ; when export or external is used }
  1058. if semicolonatend then
  1059. consume(_SEMICOLON);
  1060. { set some vars options }
  1061. if is_dll then
  1062. include(vs.varoptions,vo_is_dll_var)
  1063. else
  1064. include(vs.varoptions,vo_is_C_var);
  1065. if (is_dll) and
  1066. (target_info.system = system_powerpc_darwin) then
  1067. C_Name := target_info.Cprefix+C_Name;
  1068. if export_var then
  1069. begin
  1070. inc(vs.refs);
  1071. include(vs.varoptions,vo_is_exported);
  1072. end;
  1073. if extern_var then
  1074. include(vs.varoptions,vo_is_external);
  1075. if vs.typ=globalvarsym then
  1076. begin
  1077. tglobalvarsym(vs).set_mangledname(C_Name);
  1078. { insert in the datasegment when it is not external }
  1079. if (not extern_var) then
  1080. insertbssdata(tglobalvarsym(vs));
  1081. { now we can insert it in the import lib if its a dll, or
  1082. add it to the externals }
  1083. if extern_var then
  1084. begin
  1085. vs.varregable := vr_none;
  1086. if is_dll then
  1087. begin
  1088. if not(current_module.uses_imports) then
  1089. begin
  1090. current_module.uses_imports:=true;
  1091. importlib.preparelib(current_module.realmodulename^);
  1092. end;
  1093. importlib.importvariable(tglobalvarsym(vs),C_name,dll_name);
  1094. end
  1095. else
  1096. if target_info.DllScanSupported then
  1097. current_module.Externals.insert(tExternalsItem.create(vs.mangledname));
  1098. end;
  1099. end
  1100. else
  1101. Message(parser_e_no_local_var_external);
  1102. symdone:=true;
  1103. end;
  1104. end;
  1105. { Check for STATIC directive }
  1106. if not symdone and (is_object) and
  1107. (cs_static_keyword in aktmoduleswitches) and (idtoken=_STATIC) then
  1108. begin
  1109. include(current_object_option,sp_static);
  1110. insert_syms(sc,tt,false,dummysymoptions);
  1111. exclude(current_object_option,sp_static);
  1112. consume(_STATIC);
  1113. consume(_SEMICOLON);
  1114. symdone:=true;
  1115. end;
  1116. { insert it in the symtable, if not done yet }
  1117. if not symdone then
  1118. begin
  1119. { save object option, because we can turn of the sp_published }
  1120. if (sp_published in current_object_option) and
  1121. not(is_class(tt.def)) then
  1122. begin
  1123. Message(parser_e_cant_publish_that);
  1124. exclude(current_object_option,sp_published);
  1125. { recover by changing access type to public }
  1126. vs2:=tabstractvarsym(sc.first);
  1127. while assigned (vs2) do
  1128. begin
  1129. exclude(vs2.symoptions,sp_published);
  1130. include(vs2.symoptions,sp_public);
  1131. vs2:=tabstractvarsym(vs2.listnext);
  1132. end;
  1133. end
  1134. else
  1135. if (sp_published in current_object_option) and
  1136. not(oo_can_have_published in tobjectdef(tt.def).objectoptions) then
  1137. begin
  1138. Message(parser_e_only_publishable_classes_can__be_published);
  1139. exclude(current_object_option,sp_published);
  1140. end;
  1141. insert_syms(sc,tt,is_threadvar,dummysymoptions);
  1142. current_object_option:=old_current_object_option;
  1143. end;
  1144. end;
  1145. { Check for Case }
  1146. if is_record and (token=_CASE) then
  1147. begin
  1148. maxsize:=0;
  1149. maxalignment:=0;
  1150. maxpadalign:=0;
  1151. consume(_CASE);
  1152. sorg:=orgpattern;
  1153. hs:=pattern;
  1154. searchsym(hs,srsym,srsymtable);
  1155. { may be only a type: }
  1156. if assigned(srsym) and (srsym.typ in [typesym,unitsym]) then
  1157. begin
  1158. { for records, don't search the recordsymtable for
  1159. the symbols of the types }
  1160. oldsymtablestack:=symtablestack;
  1161. symtablestack:=symtablestack.next;
  1162. read_type(casetype,'',true);
  1163. symtablestack:=oldsymtablestack;
  1164. end
  1165. else
  1166. begin
  1167. consume(_ID);
  1168. consume(_COLON);
  1169. { for records, don't search the recordsymtable for
  1170. the symbols of the types }
  1171. oldsymtablestack:=symtablestack;
  1172. symtablestack:=symtablestack.next;
  1173. read_type(casetype,'',true);
  1174. symtablestack:=oldsymtablestack;
  1175. fieldvs:=tfieldvarsym.create(sorg,vs_value,casetype,[]);
  1176. tabstractrecordsymtable(symtablestack).insertfield(fieldvs,true);
  1177. end;
  1178. if not(is_ordinal(casetype.def))
  1179. {$ifndef cpu64bit}
  1180. or is_64bitint(casetype.def)
  1181. {$endif cpu64bit}
  1182. then
  1183. Message(type_e_ordinal_expr_expected);
  1184. consume(_OF);
  1185. UnionSymtable:=trecordsymtable.create(aktpackrecords);
  1186. Unionsymtable.next:=symtablestack;
  1187. registerdef:=false;
  1188. UnionDef:=trecorddef.create(unionsymtable);
  1189. uniondef.isunion:=true;
  1190. if assigned(symtablestack.defowner) then
  1191. Uniondef.owner:=symtablestack.defowner.owner;
  1192. registerdef:=true;
  1193. startvarrecsize:=UnionSymtable.datasize;
  1194. startvarrecalign:=UnionSymtable.fieldalignment;
  1195. startpadalign:=Unionsymtable.padalignment;
  1196. symtablestack:=UnionSymtable;
  1197. repeat
  1198. repeat
  1199. pt:=comp_expr(true);
  1200. if not(pt.nodetype=ordconstn) then
  1201. Message(parser_e_illegal_expression);
  1202. pt.free;
  1203. if token=_COMMA then
  1204. consume(_COMMA)
  1205. else
  1206. break;
  1207. until false;
  1208. consume(_COLON);
  1209. { read the vars }
  1210. consume(_LKLAMMER);
  1211. inc(variantrecordlevel);
  1212. if token<>_RKLAMMER then
  1213. read_var_decs(true,false,false);
  1214. dec(variantrecordlevel);
  1215. consume(_RKLAMMER);
  1216. { calculates maximal variant size }
  1217. maxsize:=max(maxsize,unionsymtable.datasize);
  1218. maxalignment:=max(maxalignment,unionsymtable.fieldalignment);
  1219. maxpadalign:=max(maxpadalign,unionsymtable.padalignment);
  1220. { the items of the next variant are overlayed }
  1221. unionsymtable.datasize:=startvarrecsize;
  1222. unionsymtable.fieldalignment:=startvarrecalign;
  1223. unionsymtable.padalignment:=startpadalign;
  1224. if (token<>_END) and (token<>_RKLAMMER) then
  1225. consume(_SEMICOLON)
  1226. else
  1227. break;
  1228. until (token=_END) or (token=_RKLAMMER);
  1229. { at last set the record size to that of the biggest variant }
  1230. unionsymtable.datasize:=maxsize;
  1231. unionsymtable.fieldalignment:=maxalignment;
  1232. uniontype.def:=uniondef;
  1233. uniontype.sym:=nil;
  1234. UnionSym:=tfieldvarsym.create('$case',vs_value,uniontype,[]);
  1235. symtablestack:=symtablestack.next;
  1236. unionsymtable.addalignmentpadding;
  1237. {$ifdef powerpc}
  1238. { parent inherits the alignment padding if the variant is the first "field" of the parent record/variant }
  1239. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos]) and
  1240. is_first_field and
  1241. (trecordsymtable(symtablestack).usefieldalignment = -1) and
  1242. (maxpadalign > trecordsymtable(symtablestack).padalignment) then
  1243. trecordsymtable(symtablestack).padalignment:=maxpadalign;
  1244. {$endif powerpc}
  1245. { Align the offset where the union symtable is added }
  1246. if (trecordsymtable(symtablestack).usefieldalignment=-1) then
  1247. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.maxCrecordalign)
  1248. else
  1249. usedalign:=used_align(unionsymtable.recordalignment,aktalignment.recordalignmin,aktalignment.recordalignmax);
  1250. offset:=align(trecordsymtable(symtablestack).datasize,usedalign);
  1251. trecordsymtable(symtablestack).datasize:=offset+unionsymtable.datasize;
  1252. if unionsymtable.recordalignment>trecordsymtable(symtablestack).fieldalignment then
  1253. trecordsymtable(symtablestack).fieldalignment:=unionsymtable.recordalignment;
  1254. trecordsymtable(symtablestack).insertunionst(Unionsymtable,offset);
  1255. Unionsym.owner:=nil;
  1256. unionsym.free;
  1257. uniondef.owner:=nil;
  1258. uniondef.free;
  1259. end;
  1260. block_type:=old_block_type;
  1261. current_object_option:=old_current_object_option;
  1262. { free the list }
  1263. sc.free;
  1264. {$ifdef powerpc}
  1265. is_first_field := false;
  1266. {$endif powerpc}
  1267. end;
  1268. end.
  1269. {
  1270. $Log$
  1271. Revision 1.98 2005-03-09 23:44:18 peter
  1272. support external <dllname>; also for variables
  1273. Revision 1.97 2005/02/14 17:13:07 peter
  1274. * truncate log
  1275. Revision 1.96 2005/02/03 17:11:40 peter
  1276. * more procvar directive fixes
  1277. Revision 1.95 2005/02/02 19:03:27 florian
  1278. * fixed proc. vars with calling specifiers in usual var declarations
  1279. Revision 1.94 2005/02/01 23:18:54 florian
  1280. * fixed:
  1281. r1 = record
  1282. p : procedure stdcall;
  1283. i : longint;
  1284. end;
  1285. Revision 1.93 2005/02/01 08:46:13 michael
  1286. * Patch from peter: fix macpas anonymous function procvar
  1287. Revision 1.92 2005/01/30 17:17:19 florian
  1288. * variables exported by $J/$Z in macpas mode are never regable
  1289. Revision 1.91 2005/01/06 13:30:41 florian
  1290. * widechararray patch from Peter
  1291. Revision 1.90 2005/01/04 16:52:07 peter
  1292. * don't typecast index of indexed properties
  1293. Revision 1.89 2005/01/04 16:37:38 peter
  1294. * give error when property doesn't reference a method or field
  1295. }