pdecvar.pas 55 KB

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