pdecvar.pas 56 KB

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