pdecvar.pas 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Parses variable declarations. Used for var statement and record
  4. definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pdecvar;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. symtable,symsym,symdef;
  24. type
  25. tvar_dec_option=(vd_record,vd_object,vd_threadvar,vd_class,vd_final,vd_canreorder);
  26. tvar_dec_options=set of tvar_dec_option;
  27. function read_property_dec(is_classproperty:boolean;astruct:tabstractrecorddef):tpropertysym;
  28. procedure read_var_decls(options:Tvar_dec_options);
  29. procedure read_record_fields(options:Tvar_dec_options; reorderlist: TFPObjectList; variantdesc: ppvariantrecdesc);
  30. procedure read_public_and_external(vs: tabstractvarsym);
  31. procedure try_consume_sectiondirective(var asection: ansistring);
  32. implementation
  33. uses
  34. SysUtils,
  35. { common }
  36. cutils,
  37. { global }
  38. globtype,globals,tokens,verbose,constexp,
  39. systems,
  40. { symtable }
  41. symconst,symbase,symtype,defutil,defcmp,symcreat,
  42. {$if defined(i386) or defined(i8086)}
  43. symcpu,
  44. {$endif}
  45. {$ifdef jvm}
  46. jvmdef,
  47. {$endif}
  48. fmodule,htypechk,
  49. { pass 1 }
  50. node,pass_1,aasmdata,
  51. ncon,nmat,nadd,ncal,nset,ncnv,ninl,nld,nflw,nmem,nutils,
  52. { codegen }
  53. ncgutil,ngenutil,
  54. { parser }
  55. scanner,
  56. pbase,pexpr,ptype,ptconst,pdecsub,
  57. {$ifdef jvm}
  58. pjvm,
  59. {$endif}
  60. { link }
  61. import
  62. ;
  63. function read_property_dec(is_classproperty:boolean;astruct:tabstractrecorddef):tpropertysym;
  64. { convert a node tree to symlist and return the last
  65. symbol }
  66. function parse_symlist(pl:tpropaccesslist;out def:tdef):boolean;
  67. var
  68. idx : longint;
  69. sym : tsym;
  70. srsymtable : TSymtable;
  71. st : TSymtable;
  72. p : tnode;
  73. begin
  74. result:=true;
  75. def:=nil;
  76. if token=_ID then
  77. begin
  78. if assigned(astruct) then
  79. sym:=search_struct_member(astruct,pattern)
  80. else
  81. searchsym(pattern,sym,srsymtable);
  82. if assigned(sym) then
  83. begin
  84. if assigned(astruct) and
  85. not is_visible_for_object(sym,astruct) then
  86. Message(parser_e_cant_access_private_member);
  87. case sym.typ of
  88. fieldvarsym :
  89. begin
  90. addsymref(sym);
  91. pl.addsym(sl_load,sym);
  92. def:=tfieldvarsym(sym).vardef;
  93. end;
  94. procsym :
  95. begin
  96. addsymref(sym);
  97. pl.addsym(sl_call,sym);
  98. end;
  99. else
  100. begin
  101. Message1(parser_e_illegal_field_or_method,orgpattern);
  102. def:=generrordef;
  103. result:=false;
  104. end;
  105. end;
  106. end
  107. else
  108. begin
  109. Message1(parser_e_illegal_field_or_method,orgpattern);
  110. def:=generrordef;
  111. result:=false;
  112. end;
  113. consume(_ID);
  114. repeat
  115. case token of
  116. _ID,
  117. _SEMICOLON :
  118. begin
  119. break;
  120. end;
  121. _POINT :
  122. begin
  123. consume(_POINT);
  124. if assigned(def) then
  125. begin
  126. st:=def.GetSymtable(gs_record);
  127. if assigned(st) then
  128. begin
  129. sym:=tsym(st.Find(pattern));
  130. if not(assigned(sym)) and is_object(def) then
  131. sym:=search_struct_member(tobjectdef(def),pattern);
  132. if assigned(sym) then
  133. begin
  134. pl.addsym(sl_subscript,sym);
  135. case sym.typ of
  136. fieldvarsym :
  137. def:=tfieldvarsym(sym).vardef;
  138. else
  139. begin
  140. Message1(sym_e_illegal_field,orgpattern);
  141. result:=false;
  142. end;
  143. end;
  144. end
  145. else
  146. begin
  147. Message1(sym_e_illegal_field,orgpattern);
  148. result:=false;
  149. end;
  150. end
  151. else
  152. begin
  153. Message(parser_e_invalid_qualifier);
  154. result:=false;
  155. end;
  156. end
  157. else
  158. begin
  159. Message(parser_e_invalid_qualifier);
  160. result:=false;
  161. end;
  162. consume(_ID);
  163. end;
  164. _LECKKLAMMER :
  165. begin
  166. consume(_LECKKLAMMER);
  167. repeat
  168. if def.typ=arraydef then
  169. begin
  170. idx:=0;
  171. p:=comp_expr(true,false);
  172. if (not codegenerror) then
  173. begin
  174. if (p.nodetype=ordconstn) then
  175. begin
  176. { type/range checking }
  177. inserttypeconv(p,tarraydef(def).rangedef);
  178. if (Tordconstnode(p).value<int64(low(longint))) or
  179. (Tordconstnode(p).value>int64(high(longint))) then
  180. message(parser_e_array_range_out_of_bounds)
  181. else
  182. idx:=Tordconstnode(p).value.svalue
  183. end
  184. else
  185. Message(type_e_ordinal_expr_expected)
  186. end;
  187. pl.addconst(sl_vec,idx,p.resultdef);
  188. p.free;
  189. def:=tarraydef(def).elementdef;
  190. end
  191. else
  192. begin
  193. Message(parser_e_invalid_qualifier);
  194. result:=false;
  195. end;
  196. until not try_to_consume(_COMMA);
  197. consume(_RECKKLAMMER);
  198. end;
  199. else
  200. begin
  201. Message(parser_e_ill_property_access_sym);
  202. result:=false;
  203. break;
  204. end;
  205. end;
  206. until false;
  207. end
  208. else
  209. begin
  210. Message(parser_e_ill_property_access_sym);
  211. result:=false;
  212. end;
  213. end;
  214. function allow_default_property(p : tpropertysym) : boolean;
  215. begin
  216. allow_default_property:=
  217. (is_ordinal(p.propdef) or
  218. {$ifndef cpu64bitaddr}
  219. is_64bitint(p.propdef) or
  220. {$endif cpu64bitaddr}
  221. is_class(p.propdef) or
  222. is_single(p.propdef) or
  223. (p.propdef.typ in [classrefdef,pointerdef]) or
  224. is_smallset(p.propdef)
  225. ) and not
  226. (
  227. (p.propdef.typ=arraydef) and
  228. (ppo_indexed in p.propoptions)
  229. ) and not
  230. (ppo_hasparameters in p.propoptions);
  231. end;
  232. procedure create_accessor_procsym(p: tpropertysym; pd: tprocdef; const prefix: string;
  233. accesstype: tpropaccesslisttypes);
  234. var
  235. sym: tprocsym;
  236. begin
  237. handle_calling_convention(pd);
  238. sym:=cprocsym.create(prefix+lower(p.realname));
  239. symtablestack.top.insert(sym);
  240. pd.procsym:=sym;
  241. include(pd.procoptions,po_dispid);
  242. include(pd.procoptions,po_global);
  243. pd.visibility:=vis_private;
  244. proc_add_definition(pd);
  245. p.propaccesslist[accesstype].addsym(sl_call,sym);
  246. p.propaccesslist[accesstype].procdef:=pd;
  247. end;
  248. procedure parse_dispinterface(p : tpropertysym; readpd,writepd: tprocdef;
  249. var paranr: word);
  250. var
  251. hasread, haswrite: boolean;
  252. pt: tnode;
  253. hdispid: longint;
  254. hparavs: tparavarsym;
  255. begin
  256. p.propaccesslist[palt_read].clear;
  257. p.propaccesslist[palt_write].clear;
  258. hasread:=true;
  259. haswrite:=true;
  260. hdispid:=0;
  261. if try_to_consume(_READONLY) then
  262. haswrite:=false
  263. else if try_to_consume(_WRITEONLY) then
  264. hasread:=false;
  265. if try_to_consume(_DISPID) then
  266. begin
  267. pt:=comp_expr(true,false);
  268. if is_constintnode(pt) then
  269. if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
  270. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(longint)))
  271. else
  272. hdispid:=Tordconstnode(pt).value.svalue
  273. else
  274. Message(parser_e_dispid_must_be_ord_const);
  275. pt.free;
  276. end
  277. else
  278. hdispid:=tobjectdef(astruct).get_next_dispid;
  279. { COM property is simply a pair of methods, tagged with 'propertyget'
  280. and 'propertyset' flags (or a single method if access is restricted).
  281. Creating these implicit accessor methods also allows the rest of compiler
  282. to handle dispinterface properties the same way as regular ones. }
  283. if hasread then
  284. begin
  285. readpd.returndef:=p.propdef;
  286. readpd.dispid:=hdispid;
  287. readpd.proctypeoption:=potype_propgetter;
  288. create_accessor_procsym(p,readpd,'get$',palt_read);
  289. end;
  290. if haswrite then
  291. begin
  292. { add an extra parameter, a placeholder of the value to set }
  293. inc(paranr);
  294. hparavs:=cparavarsym.create('$value',10*paranr,vs_value,p.propdef,[]);
  295. writepd.parast.insert(hparavs);
  296. writepd.proctypeoption:=potype_propsetter;
  297. writepd.dispid:=hdispid;
  298. create_accessor_procsym(p,writepd,'put$',palt_write);
  299. end;
  300. end;
  301. var
  302. sym : tsym;
  303. srsymtable: tsymtable;
  304. p : tpropertysym;
  305. overridden : tsym;
  306. varspez : tvarspez;
  307. hdef : tdef;
  308. arraytype : tdef;
  309. def : tdef;
  310. pt : tnode;
  311. sc : TFPObjectList;
  312. paranr : word;
  313. i : longint;
  314. ImplIntf : TImplementedInterface;
  315. found : boolean;
  316. hreadparavs,
  317. hparavs : tparavarsym;
  318. storedprocdef: tprocvardef;
  319. readprocdef,
  320. writeprocdef : tprocdef;
  321. {$ifdef jvm}
  322. orgaccesspd : tprocdef;
  323. wrongvisibility : boolean;
  324. {$endif}
  325. begin
  326. result:=nil;
  327. { Generate temp procdefs to search for matching read/write
  328. procedures. the readprocdef will store all definitions }
  329. paranr:=0;
  330. readprocdef:=cprocdef.create(normal_function_level);
  331. writeprocdef:=cprocdef.create(normal_function_level);
  332. readprocdef.struct:=astruct;
  333. writeprocdef.struct:=astruct;
  334. if assigned(astruct) and is_classproperty then
  335. begin
  336. readprocdef.procoptions:=[po_staticmethod,po_classmethod];
  337. writeprocdef.procoptions:=[po_staticmethod,po_classmethod];
  338. end;
  339. if token<>_ID then
  340. begin
  341. consume(_ID);
  342. consume(_SEMICOLON);
  343. exit;
  344. end;
  345. { Generate propertysym and insert in symtablestack }
  346. p:=cpropertysym.create(orgpattern);
  347. p.visibility:=symtablestack.top.currentvisibility;
  348. p.default:=longint($80000000);
  349. if is_classproperty then
  350. include(p.symoptions, sp_static);
  351. symtablestack.top.insert(p);
  352. consume(_ID);
  353. { property parameters ? }
  354. if try_to_consume(_LECKKLAMMER) then
  355. begin
  356. if (p.visibility=vis_published) and
  357. not (m_delphi in current_settings.modeswitches) then
  358. Message(parser_e_cant_publish_that_property);
  359. { create a list of the parameters }
  360. p.parast:=tparasymtable.create(nil,0);
  361. symtablestack.push(p.parast);
  362. sc:=TFPObjectList.create(false);
  363. repeat
  364. if try_to_consume(_VAR) then
  365. varspez:=vs_var
  366. else if try_to_consume(_CONST) then
  367. varspez:=vs_const
  368. else if try_to_consume(_CONSTREF) then
  369. varspez:=vs_constref
  370. else if (m_out in current_settings.modeswitches) and try_to_consume(_OUT) then
  371. varspez:=vs_out
  372. else
  373. varspez:=vs_value;
  374. sc.clear;
  375. repeat
  376. inc(paranr);
  377. hreadparavs:=cparavarsym.create(orgpattern,10*paranr,varspez,generrordef,[]);
  378. p.parast.insert(hreadparavs);
  379. sc.add(hreadparavs);
  380. consume(_ID);
  381. until not try_to_consume(_COMMA);
  382. if try_to_consume(_COLON) then
  383. begin
  384. if try_to_consume(_ARRAY) then
  385. begin
  386. consume(_OF);
  387. { define range and type of range }
  388. hdef:=carraydef.create(0,-1,s32inttype);
  389. { define field type }
  390. single_type(arraytype,[]);
  391. tarraydef(hdef).elementdef:=arraytype;
  392. end
  393. else
  394. single_type(hdef,[]);
  395. end
  396. else
  397. hdef:=cformaltype;
  398. for i:=0 to sc.count-1 do
  399. tparavarsym(sc[i]).vardef:=hdef;
  400. until not try_to_consume(_SEMICOLON);
  401. sc.free;
  402. symtablestack.pop(p.parast);
  403. consume(_RECKKLAMMER);
  404. { the parser need to know if a property has parameters, the
  405. index parameter doesn't count (PFV) }
  406. if paranr>0 then
  407. begin
  408. p.add_accessor_parameters(readprocdef,writeprocdef);
  409. include(p.propoptions,ppo_hasparameters);
  410. end;
  411. end;
  412. { overridden property ? }
  413. { force property interface
  414. there is a property parameter
  415. a global property }
  416. if (token=_COLON) or (paranr>0) or (astruct=nil) then
  417. begin
  418. consume(_COLON);
  419. single_type(p.propdef,[stoAllowSpecialization]);
  420. if is_dispinterface(astruct) and not is_automatable(p.propdef) then
  421. Message1(type_e_not_automatable,p.propdef.typename);
  422. if (idtoken=_INDEX) then
  423. begin
  424. consume(_INDEX);
  425. pt:=comp_expr(true,false);
  426. { Only allow enum and integer indexes. Convert all integer
  427. values to objpas.integer (s32int on 32- and 64-bit targets,
  428. s16int on 16- and 8-bit) to be compatible with delphi,
  429. because the procedure matching requires equal parameters }
  430. if is_constnode(pt) and
  431. is_ordinal(pt.resultdef)
  432. and (not is_64bitint(pt.resultdef))
  433. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  434. and (not is_32bitint(pt.resultdef))
  435. {$endif}
  436. then
  437. begin
  438. if is_integer(pt.resultdef) then
  439. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  440. inserttypeconv_internal(pt,s16inttype);
  441. {$else}
  442. inserttypeconv_internal(pt,s32inttype);
  443. {$endif}
  444. p.index:=tordconstnode(pt).value.svalue;
  445. end
  446. else
  447. begin
  448. Message(parser_e_invalid_property_index_value);
  449. p.index:=0;
  450. end;
  451. p.indexdef:=pt.resultdef;
  452. include(p.propoptions,ppo_indexed);
  453. { concat a longint to the para templates }
  454. p.add_index_parameter(paranr,readprocdef,writeprocdef);
  455. pt.free;
  456. end;
  457. end
  458. else
  459. begin
  460. { do an property override }
  461. if (astruct.typ=objectdef) and assigned(tobjectdef(astruct).childof) then
  462. overridden:=search_struct_member(tobjectdef(astruct).childof,p.name)
  463. else
  464. overridden:=nil;
  465. if assigned(overridden) and
  466. (overridden.typ=propertysym) and
  467. not(is_dispinterface(astruct)) then
  468. begin
  469. tpropertysym(overridden).makeduplicate(p,readprocdef,writeprocdef,paranr);
  470. p.overriddenpropsym:=tpropertysym(overridden);
  471. include(p.propoptions,ppo_overrides);
  472. end
  473. else
  474. begin
  475. p.propdef:=generrordef;
  476. message(parser_e_no_property_found_to_override);
  477. end;
  478. end;
  479. if ((p.visibility=vis_published) or is_dispinterface(astruct)) and
  480. (not(p.propdef.is_publishable) or (sp_static in p.symoptions)) then
  481. begin
  482. Message(parser_e_cant_publish_that_property);
  483. p.visibility:=vis_public;
  484. end;
  485. if not(is_dispinterface(astruct)) then
  486. begin
  487. { parse accessors }
  488. if try_to_consume(_READ) then
  489. begin
  490. p.propaccesslist[palt_read].clear;
  491. if parse_symlist(p.propaccesslist[palt_read],def) then
  492. begin
  493. sym:=p.propaccesslist[palt_read].firstsym^.sym;
  494. { getter is a function returning the type of the property }
  495. if sym.typ=procsym then
  496. begin
  497. readprocdef.returndef:=p.propdef;
  498. { Insert hidden parameters }
  499. handle_calling_convention(readprocdef);
  500. end;
  501. p.add_getter_or_setter_for_sym(palt_read,sym,def,readprocdef);
  502. end;
  503. end;
  504. if try_to_consume(_WRITE) then
  505. begin
  506. p.propaccesslist[palt_write].clear;
  507. if parse_symlist(p.propaccesslist[palt_write],def) then
  508. begin
  509. sym:=p.propaccesslist[palt_write].firstsym^.sym;
  510. if sym.typ=procsym then
  511. begin
  512. { settter is a procedure with an extra value parameter
  513. of the of the property }
  514. writeprocdef.returndef:=voidtype;
  515. inc(paranr);
  516. hparavs:=cparavarsym.create('$value',10*paranr,vs_value,p.propdef,[]);
  517. writeprocdef.parast.insert(hparavs);
  518. { Insert hidden parameters }
  519. handle_calling_convention(writeprocdef);
  520. end;
  521. p.add_getter_or_setter_for_sym(palt_write,sym,def,writeprocdef);
  522. end;
  523. end;
  524. end
  525. else
  526. parse_dispinterface(p,readprocdef,writeprocdef,paranr);
  527. { stored is not allowed for dispinterfaces, records or class properties }
  528. if assigned(astruct) and not(is_dispinterface(astruct) or is_record(astruct)) and not is_classproperty then
  529. begin
  530. { ppo_stored is default on for not overridden properties }
  531. if not assigned(p.overriddenpropsym) then
  532. include(p.propoptions,ppo_stored);
  533. if try_to_consume(_STORED) then
  534. begin
  535. include(p.propoptions,ppo_stored);
  536. p.propaccesslist[palt_stored].clear;
  537. if token=_ID then
  538. begin
  539. { in the case that idtoken=_DEFAULT }
  540. { we have to do nothing except }
  541. { setting ppo_stored, it's the same }
  542. { as stored true }
  543. if idtoken<>_DEFAULT then
  544. begin
  545. { parse_symlist cannot deal with constsyms, and
  546. we also don't want to put constsyms in symlists
  547. since they have to be evaluated immediately rather
  548. than each time the property is accessed
  549. The proper fix would be to always create a parse tree
  550. and then convert that one, if appropriate, to a symlist.
  551. Currently, we e.g. don't support any constant expressions
  552. yet either here, while Delphi does.
  553. }
  554. { make sure we don't let constants mask class fields/
  555. methods
  556. }
  557. sym:=nil;
  558. if (not assigned(astruct) or
  559. (search_struct_member(astruct,pattern)=nil)) and
  560. searchsym(pattern,sym,srsymtable) and
  561. (sym.typ = constsym) then
  562. begin
  563. addsymref(sym);
  564. if not is_boolean(tconstsym(sym).constdef) then
  565. Message(parser_e_stored_property_must_be_boolean)
  566. else if (tconstsym(sym).value.valueord=0) then
  567. { same as for _FALSE }
  568. exclude(p.propoptions,ppo_stored)
  569. else
  570. { same as for _TRUE }
  571. p.default:=longint($80000000);
  572. consume(_ID);
  573. end
  574. else if parse_symlist(p.propaccesslist[palt_stored],def) then
  575. begin
  576. sym:=p.propaccesslist[palt_stored].firstsym^.sym;
  577. case sym.typ of
  578. procsym :
  579. begin
  580. { Create a temporary procvardef to handle parameters }
  581. storedprocdef:=cprocvardef.create(normal_function_level);
  582. include(storedprocdef.procoptions,po_methodpointer);
  583. { Return type must be boolean }
  584. storedprocdef.returndef:=pasbool8type;
  585. { Add index parameter if needed }
  586. if ppo_indexed in p.propoptions then
  587. begin
  588. hparavs:=cparavarsym.create('$index',10,vs_value,p.indexdef,[]);
  589. storedprocdef.parast.insert(hparavs);
  590. end;
  591. { Insert hidden parameters }
  592. handle_calling_convention(storedprocdef);
  593. p.propaccesslist[palt_stored].procdef:=Tprocsym(sym).Find_procdef_bypara(storedprocdef.paras,storedprocdef.returndef,[cpo_allowdefaults,cpo_ignorehidden]);
  594. if not assigned(p.propaccesslist[palt_stored].procdef) then
  595. message(parser_e_ill_property_storage_sym);
  596. { Not needed anymore }
  597. storedprocdef.owner.deletedef(storedprocdef);
  598. end;
  599. fieldvarsym :
  600. begin
  601. if not assigned(def) then
  602. internalerror(200310073);
  603. if (ppo_hasparameters in p.propoptions) or
  604. not(is_boolean(def)) then
  605. Message(parser_e_stored_property_must_be_boolean);
  606. end;
  607. else
  608. Message(parser_e_ill_property_access_sym);
  609. end;
  610. end;
  611. end;
  612. end;
  613. end;
  614. end;
  615. if not is_record(astruct) and try_to_consume(_DEFAULT) then
  616. begin
  617. if not allow_default_property(p) then
  618. begin
  619. Message(parser_e_property_cant_have_a_default_value);
  620. { Error recovery }
  621. pt:=comp_expr(true,false);
  622. pt.free;
  623. end
  624. else
  625. begin
  626. { Get the result of the default, the firstpass is
  627. needed to support values like -1 }
  628. pt:=comp_expr(true,false);
  629. if (p.propdef.typ=setdef) and
  630. (pt.nodetype=arrayconstructorn) then
  631. begin
  632. arrayconstructor_to_set(pt);
  633. do_typecheckpass(pt);
  634. end;
  635. inserttypeconv(pt,p.propdef);
  636. if not(is_constnode(pt)) then
  637. Message(parser_e_property_default_value_must_const);
  638. { Set default value }
  639. case pt.nodetype of
  640. setconstn :
  641. p.default:=plongint(tsetconstnode(pt).value_set)^;
  642. ordconstn :
  643. if (Tordconstnode(pt).value<int64(low(longint))) or
  644. (Tordconstnode(pt).value>int64(high(cardinal))) then
  645. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(cardinal)))
  646. else
  647. p.default:=longint(tordconstnode(pt).value.svalue);
  648. niln :
  649. p.default:=0;
  650. realconstn:
  651. p.default:=longint(single(trealconstnode(pt).value_real));
  652. end;
  653. pt.free;
  654. end;
  655. end
  656. else if not is_record(astruct) and try_to_consume(_NODEFAULT) then
  657. begin
  658. p.default:=longint($80000000);
  659. end;
  660. (*
  661. else {if allow_default_property(p) then
  662. begin
  663. p.default:=longint($80000000);
  664. end;
  665. *)
  666. { Parse possible "implements" keyword }
  667. if not is_record(astruct) and try_to_consume(_IMPLEMENTS) then
  668. repeat
  669. single_type(def,[]);
  670. if not(is_interface(def)) then
  671. message(parser_e_class_implements_must_be_interface);
  672. if is_interface(p.propdef) then
  673. begin
  674. { an interface type may delegate itself or one of its ancestors }
  675. if not def_is_related(p.propdef,def) then
  676. begin
  677. message2(parser_e_implements_must_have_correct_type,def.typename,p.propdef.typename);
  678. exit;
  679. end;
  680. end
  681. else if is_class(p.propdef) then
  682. begin
  683. ImplIntf:=find_implemented_interface(tobjectdef(p.propdef),tobjectdef(def));
  684. if assigned(ImplIntf) then
  685. begin
  686. if compare_defs(ImplIntf.IntfDef,def,nothingn)<te_equal then
  687. begin
  688. message2(parser_e_implements_must_have_correct_type,ImplIntf.IntfDef.typename,def.typename);
  689. exit;
  690. end;
  691. end
  692. else
  693. begin
  694. message2(parser_e_class_doesnt_implement_interface,p.propdef.typename,def.typename);
  695. exit;
  696. end;
  697. end
  698. else
  699. begin
  700. message(parser_e_implements_must_be_class_or_interface);
  701. exit;
  702. end;
  703. if not assigned(p.propaccesslist[palt_read].firstsym) then
  704. begin
  705. message(parser_e_implements_must_read_specifier);
  706. exit;
  707. end;
  708. if assigned(p.propaccesslist[palt_read].procdef) and
  709. (tprocdef(p.propaccesslist[palt_read].procdef).proccalloption<>pocall_default) then
  710. message(parser_e_implements_getter_not_default_cc);
  711. if assigned(p.propaccesslist[palt_write].firstsym) then
  712. begin
  713. message(parser_e_implements_must_not_have_write_specifier);
  714. exit;
  715. end;
  716. if assigned(p.propaccesslist[palt_stored].firstsym) then
  717. begin
  718. message(parser_e_implements_must_not_have_stored_specifier);
  719. exit;
  720. end;
  721. found:=false;
  722. ImplIntf:=nil;
  723. for i:=0 to tobjectdef(astruct).ImplementedInterfaces.Count-1 do
  724. begin
  725. ImplIntf:=TImplementedInterface(tobjectdef(astruct).ImplementedInterfaces[i]);
  726. if compare_defs(def,ImplIntf.IntfDef,nothingn)>=te_equal then
  727. begin
  728. found:=true;
  729. break;
  730. end;
  731. end;
  732. if found then
  733. begin
  734. { An interface may not be delegated by more than one property,
  735. it also may not have method mappings. }
  736. if Assigned(ImplIntf.ImplementsGetter) then
  737. message1(parser_e_duplicate_implements_clause,ImplIntf.IntfDef.typename);
  738. if Assigned(ImplIntf.NameMappings) then
  739. message2(parser_e_mapping_no_implements,ImplIntf.IntfDef.typename,astruct.objrealname^);
  740. ImplIntf.ImplementsGetter:=p;
  741. ImplIntf.VtblImplIntf:=ImplIntf;
  742. case p.propaccesslist[palt_read].firstsym^.sym.typ of
  743. procsym :
  744. begin
  745. if (po_virtualmethod in tprocdef(p.propaccesslist[palt_read].procdef).procoptions) and
  746. not is_objectpascal_helper(tprocdef(p.propaccesslist[palt_read].procdef).struct) then
  747. ImplIntf.IType:=etVirtualMethodResult
  748. else
  749. ImplIntf.IType:=etStaticMethodResult;
  750. end;
  751. fieldvarsym :
  752. begin
  753. ImplIntf.IType:=etFieldValue;
  754. { this must be done in a more robust way. Can't read the
  755. fieldvarsym's fieldoffset yet, because it may not yet
  756. be set }
  757. ImplIntf.ImplementsField:=p.propaccesslist[palt_read].firstsym^.sym;
  758. end
  759. else
  760. internalerror(200802161);
  761. end;
  762. if not is_interface(p.propdef) then
  763. case ImplIntf.IType of
  764. etVirtualMethodResult: ImplIntf.IType := etVirtualMethodClass;
  765. etStaticMethodResult: ImplIntf.IType := etStaticMethodClass;
  766. etFieldValue: ImplIntf.IType := etFieldValueClass;
  767. else
  768. internalerror(200912101);
  769. end;
  770. end
  771. else
  772. message1(parser_e_implements_uses_non_implemented_interface,def.typename);
  773. until not try_to_consume(_COMMA);
  774. { remove unneeded procdefs }
  775. if readprocdef.proctypeoption<>potype_propgetter then
  776. readprocdef.owner.deletedef(readprocdef);
  777. if writeprocdef.proctypeoption<>potype_propsetter then
  778. writeprocdef.owner.deletedef(writeprocdef);
  779. result:=p;
  780. end;
  781. function maybe_parse_proc_directives(def:tdef):boolean;
  782. var
  783. newtype : ttypesym;
  784. begin
  785. result:=false;
  786. { Process procvar directives before = and ; }
  787. if (def.typ=procvardef) and
  788. (def.typesym=nil) and
  789. check_proc_directive(true) then
  790. begin
  791. newtype:=ctypesym.create('unnamed',def);
  792. parse_var_proc_directives(tsym(newtype));
  793. newtype.typedef:=nil;
  794. def.typesym:=nil;
  795. newtype.free;
  796. result:=true;
  797. end;
  798. end;
  799. const
  800. variantrecordlevel : longint = 0;
  801. procedure read_public_and_external_sc(sc:TFPObjectList);
  802. var
  803. vs: tabstractvarsym;
  804. begin
  805. { only allowed for one var }
  806. vs:=tabstractvarsym(sc[0]);
  807. if sc.count>1 then
  808. Message1(parser_e_directive_only_one_var,arraytokeninfo[idtoken].str);
  809. read_public_and_external(vs);
  810. end;
  811. procedure read_public_and_external(vs: tabstractvarsym);
  812. var
  813. is_dll,
  814. is_cdecl,
  815. is_external_var,
  816. is_weak_external,
  817. is_public_var : boolean;
  818. dll_name,section_name,
  819. C_name,mangledname : string;
  820. begin
  821. { only allowed for one var }
  822. { only allow external and public on global symbols }
  823. if vs.typ<>staticvarsym then
  824. begin
  825. Message(parser_e_no_local_var_external);
  826. exit;
  827. end;
  828. { defaults }
  829. is_dll:=false;
  830. is_cdecl:=false;
  831. is_external_var:=false;
  832. is_public_var:=false;
  833. section_name := '';
  834. dll_name := '';
  835. C_name:=vs.realname;
  836. { macpas specific handling due to some switches}
  837. if (m_mac in current_settings.modeswitches) then
  838. begin
  839. if (cs_external_var in current_settings.localswitches) then
  840. begin {The effect of this is the same as if cvar; external; has been given as directives.}
  841. is_cdecl:=true;
  842. is_external_var:=true;
  843. end
  844. else if (cs_externally_visible in current_settings.localswitches) then
  845. begin {The effect of this is the same as if cvar has been given as directives and it's made public.}
  846. is_cdecl:=true;
  847. is_public_var:=true;
  848. end;
  849. end;
  850. { cdecl }
  851. if try_to_consume(_CVAR) then
  852. begin
  853. consume(_SEMICOLON);
  854. is_cdecl:=true;
  855. end;
  856. { external }
  857. is_weak_external:=try_to_consume(_WEAKEXTERNAL);
  858. if is_weak_external or
  859. try_to_consume(_EXTERNAL) then
  860. begin
  861. is_external_var:=true;
  862. if (idtoken<>_NAME) and (token<>_SEMICOLON) then
  863. begin
  864. is_dll:=true;
  865. dll_name:=get_stringconst;
  866. if ExtractFileExt(dll_name)='' then
  867. dll_name:=ChangeFileExt(dll_name,target_info.sharedlibext);
  868. end;
  869. if not(is_cdecl) and try_to_consume(_NAME) then
  870. C_name:=get_stringconst;
  871. consume(_SEMICOLON);
  872. end;
  873. { export or public }
  874. if idtoken in [_EXPORT,_PUBLIC] then
  875. begin
  876. consume(_ID);
  877. if is_external_var then
  878. Message(parser_e_not_external_and_export)
  879. else
  880. is_public_var:=true;
  881. if try_to_consume(_NAME) then
  882. C_name:=get_stringconst;
  883. if (target_info.system in systems_allow_section_no_semicolon) and
  884. (vs.typ=staticvarsym) and
  885. try_to_consume (_SECTION) then
  886. section_name:=get_stringconst;
  887. consume(_SEMICOLON);
  888. end;
  889. { Windows uses an indirect reference using import tables }
  890. if is_dll and
  891. (target_info.system in systems_all_windows) then
  892. include(vs.varoptions,vo_is_dll_var);
  893. { This can only happen if vs.typ=staticvarsym }
  894. if section_name<>'' then
  895. begin
  896. tstaticvarsym(vs).section:=section_name;
  897. include(vs.varoptions,vo_has_section);
  898. end;
  899. { Add C _ prefix }
  900. if is_cdecl or
  901. (
  902. is_dll and
  903. (target_info.system in systems_darwin)
  904. ) then
  905. C_Name := target_info.Cprefix+C_Name;
  906. if is_public_var then
  907. begin
  908. include(vs.varoptions,vo_is_public);
  909. vs.varregable := vr_none;
  910. { mark as referenced }
  911. inc(vs.refs);
  912. end;
  913. mangledname:=C_name;
  914. { now we can insert it in the import lib if its a dll, or
  915. add it to the externals }
  916. if is_external_var then
  917. begin
  918. if vo_is_typed_const in vs.varoptions then
  919. Message(parser_e_initialized_not_for_external);
  920. include(vs.varoptions,vo_is_external);
  921. if (is_weak_external) then
  922. begin
  923. if not(target_info.system in systems_weak_linking) then
  924. message(parser_e_weak_external_not_supported);
  925. include(vs.varoptions,vo_is_weak_external);
  926. end;
  927. vs.varregable := vr_none;
  928. if is_dll then
  929. begin
  930. if target_info.system in (systems_all_windows + systems_nativent +
  931. [system_i386_emx, system_i386_os2]) then
  932. mangledname:=make_dllmangledname(dll_name,C_name,0,pocall_none);
  933. current_module.AddExternalImport(dll_name,C_Name,mangledname,0,true,false);
  934. end
  935. else
  936. if tf_has_dllscanner in target_info.flags then
  937. current_module.dllscannerinputlist.Add(vs.mangledname,vs);
  938. end;
  939. { Set the assembler name }
  940. tstaticvarsym(vs).set_mangledbasename(mangledname);
  941. tstaticvarsym(vs).set_mangledname(mangledname);
  942. end;
  943. procedure try_consume_sectiondirective(var asection: ansistring);
  944. begin
  945. if idtoken=_SECTION then
  946. begin
  947. consume(_ID);
  948. asection:=get_stringconst;
  949. consume(_SEMICOLON);
  950. end;
  951. end;
  952. procedure try_read_field_external(vs: tabstractvarsym);
  953. var
  954. extname: string;
  955. begin
  956. if try_to_consume(_EXTERNAL) then
  957. begin
  958. consume(_NAME);
  959. extname:=get_stringconst;
  960. tfieldvarsym(vs).set_externalname(extname);
  961. consume(_SEMICOLON);
  962. end;
  963. end;
  964. procedure try_read_field_external_sc(sc:TFPObjectList);
  965. var
  966. vs: tabstractvarsym;
  967. begin
  968. { only allowed for one var }
  969. vs:=tabstractvarsym(sc[0]);
  970. if sc.count>1 then
  971. Message1(parser_e_directive_only_one_var,arraytokeninfo[idtoken].str);
  972. try_read_field_external(vs);
  973. end;
  974. procedure read_var_decls(options:Tvar_dec_options);
  975. procedure read_default_value(sc : TFPObjectList);
  976. var
  977. vs : tabstractnormalvarsym;
  978. tcsym : tstaticvarsym;
  979. begin
  980. vs:=tabstractnormalvarsym(sc[0]);
  981. if sc.count>1 then
  982. Message(parser_e_initialized_only_one_var);
  983. if vo_is_thread_var in vs.varoptions then
  984. Message(parser_e_initialized_not_for_threadvar);
  985. consume(_EQ);
  986. case vs.typ of
  987. localvarsym :
  988. begin
  989. tcsym:=cstaticvarsym.create('$default'+vs.realname,vs_const,vs.vardef,[]);
  990. include(tcsym.symoptions,sp_internal);
  991. vs.defaultconstsym:=tcsym;
  992. symtablestack.top.insert(tcsym);
  993. read_typed_const(current_asmdata.asmlists[al_typedconsts],tcsym,false);
  994. end;
  995. staticvarsym :
  996. begin
  997. read_typed_const(current_asmdata.asmlists[al_typedconsts],tstaticvarsym(vs),false);
  998. end;
  999. else
  1000. internalerror(200611051);
  1001. end;
  1002. vs.varstate:=vs_initialised;
  1003. end;
  1004. {$ifdef gpc_mode}
  1005. procedure read_gpc_name(sc : TFPObjectList);
  1006. var
  1007. vs : tabstractnormalvarsym;
  1008. C_Name : string;
  1009. begin
  1010. consume(_ID);
  1011. C_Name:=get_stringconst;
  1012. vs:=tabstractnormalvarsym(sc[0]);
  1013. if sc.count>1 then
  1014. Message(parser_e_directive_only_one_var,'ABSOLUTE');
  1015. if vs.typ=staticvarsym then
  1016. begin
  1017. tstaticvarsym(vs).set_mangledname(C_Name);
  1018. include(vs.varoptions,vo_is_external);
  1019. end
  1020. else
  1021. Message(parser_e_no_local_var_external);
  1022. end;
  1023. {$endif}
  1024. procedure read_absolute(sc : TFPObjectList);
  1025. var
  1026. vs : tabstractvarsym;
  1027. abssym : tabsolutevarsym;
  1028. pt,hp : tnode;
  1029. st : tsymtable;
  1030. {$if defined(i386) or defined(i8086)}
  1031. tmpaddr : int64;
  1032. {$endif defined(i386) or defined(i8086)}
  1033. begin
  1034. abssym:=nil;
  1035. { only allowed for one var }
  1036. vs:=tabstractvarsym(sc[0]);
  1037. if sc.count>1 then
  1038. Message1(parser_e_directive_only_one_var,'ABSOLUTE');
  1039. if vo_is_typed_const in vs.varoptions then
  1040. Message(parser_e_initialized_not_for_external);
  1041. { parse the rest }
  1042. pt:=expr(true);
  1043. { check allowed absolute types }
  1044. if (pt.nodetype=stringconstn) or
  1045. (is_constcharnode(pt)) then
  1046. begin
  1047. abssym:=cabsolutevarsym.create(vs.realname,vs.vardef);
  1048. abssym.fileinfo:=vs.fileinfo;
  1049. if pt.nodetype=stringconstn then
  1050. abssym.asmname:=stringdup(strpas(tstringconstnode(pt).value_str))
  1051. else
  1052. abssym.asmname:=stringdup(chr(tordconstnode(pt).value.svalue));
  1053. consume(token);
  1054. abssym.abstyp:=toasm;
  1055. end
  1056. { address }
  1057. else if is_constintnode(pt) then
  1058. begin
  1059. abssym:=cabsolutevarsym.create(vs.realname,vs.vardef);
  1060. abssym.fileinfo:=vs.fileinfo;
  1061. abssym.abstyp:=toaddr;
  1062. {$ifndef cpu64bitaddr}
  1063. { on 64 bit systems, abssym.addroffset is a qword and hence this
  1064. test is useless (value is a 64 bit entity) and will always fail
  1065. for positive values (since int64(high(abssym.addroffset))=-1
  1066. }
  1067. if (Tordconstnode(pt).value<int64(low(abssym.addroffset))) or
  1068. (Tordconstnode(pt).value>int64(high(abssym.addroffset))) then
  1069. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(abssym.addroffset)),tostr(high(abssym.addroffset)))
  1070. else
  1071. {$endif}
  1072. abssym.addroffset:=Tordconstnode(pt).value.svalue;
  1073. {$if defined(i386) or defined(i8086)}
  1074. tcpuabsolutevarsym(abssym).absseg:=false;
  1075. if (target_info.system in [system_i386_go32v2,system_i386_watcom,system_i8086_msdos]) and
  1076. try_to_consume(_COLON) then
  1077. begin
  1078. pt.free;
  1079. pt:=expr(true);
  1080. if is_constintnode(pt) then
  1081. begin
  1082. {$if defined(i8086)}
  1083. tcpuabsolutevarsym(abssym).addrsegment:=abssym.addroffset;
  1084. tmpaddr:=tordconstnode(pt).value.svalue;
  1085. if (tmpaddr<int64(low(abssym.addroffset))) or
  1086. (tmpaddr>int64(high(abssym.addroffset))) then
  1087. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(abssym.addroffset)),tostr(high(abssym.addroffset)))
  1088. else
  1089. abssym.addroffset:=tmpaddr;
  1090. {$elseif defined(i386)}
  1091. tmpaddr:=abssym.addroffset shl 4+tordconstnode(pt).value.svalue;
  1092. if (tmpaddr<int64(low(abssym.addroffset))) or
  1093. (tmpaddr>int64(high(abssym.addroffset))) then
  1094. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(abssym.addroffset)),tostr(high(abssym.addroffset)))
  1095. else
  1096. abssym.addroffset:=tmpaddr;
  1097. {$endif}
  1098. tcpuabsolutevarsym(abssym).absseg:=true;
  1099. end
  1100. else
  1101. Message(type_e_ordinal_expr_expected);
  1102. end;
  1103. {$endif i386 or i8086}
  1104. end
  1105. { variable }
  1106. else
  1107. begin
  1108. { we have to be able to take the address of the absolute
  1109. expression
  1110. }
  1111. valid_for_addr(pt,true);
  1112. { remove subscriptn before checking for loadn }
  1113. hp:=pt;
  1114. while (hp.nodetype in [subscriptn,typeconvn,vecn]) do
  1115. begin
  1116. { check for implicit dereferencing and reject it }
  1117. if (hp.nodetype in [subscriptn,vecn]) then
  1118. begin
  1119. if (tunarynode(hp).left.resultdef.typ in [pointerdef,classrefdef]) then
  1120. break;
  1121. { catch, e.g., 'var b: char absolute pchar_var[5];"
  1122. (pchar_var[5] is a pchar_2_string typeconv ->
  1123. the vecn only sees an array of char)
  1124. I don't know if all of these type conversions are
  1125. possible, but they're definitely all bad.
  1126. }
  1127. if (tunarynode(hp).left.nodetype=typeconvn) and
  1128. (ttypeconvnode(tunarynode(hp).left).convtype in
  1129. [tc_pchar_2_string,tc_pointer_2_array,
  1130. tc_intf_2_string,tc_intf_2_guid,
  1131. tc_dynarray_2_variant,tc_interface_2_variant,
  1132. tc_array_2_dynarray]) then
  1133. break;
  1134. if (tunarynode(hp).left.resultdef.typ=stringdef) and
  1135. not(tstringdef(tunarynode(hp).left.resultdef).stringtype in [st_shortstring,st_longstring]) then
  1136. break;
  1137. if (tunarynode(hp).left.resultdef.typ=objectdef) and
  1138. (tobjectdef(tunarynode(hp).left.resultdef).objecttype<>odt_object) then
  1139. break;
  1140. if is_dynamic_array(tunarynode(hp).left.resultdef) then
  1141. break;
  1142. end;
  1143. hp:=tunarynode(hp).left;
  1144. end;
  1145. if (hp.nodetype=loadn) then
  1146. begin
  1147. { we should check the result type of loadn }
  1148. if not (tloadnode(hp).symtableentry.typ in [fieldvarsym,staticvarsym,localvarsym,paravarsym]) then
  1149. Message(parser_e_absolute_only_to_var_or_const);
  1150. abssym:=cabsolutevarsym.create(vs.realname,vs.vardef);
  1151. abssym.fileinfo:=vs.fileinfo;
  1152. abssym.abstyp:=tovar;
  1153. abssym.ref:=node_to_propaccesslist(pt);
  1154. { if the sizes are different, can't be a regvar since you }
  1155. { can't be "absolute upper 8 bits of a register" (except }
  1156. { if its a record field of the same size of a record }
  1157. { regvar, but in that case pt.resultdef.size will have }
  1158. { the same size since it refers to the field and not to }
  1159. { the whole record -- which is why we use pt and not hp) }
  1160. { we can't take the size of an open array }
  1161. if is_open_array(pt.resultdef) or
  1162. (vs.vardef.size <> pt.resultdef.size) then
  1163. make_not_regable(pt,[ra_addr_regable]);
  1164. end
  1165. else
  1166. Message(parser_e_absolute_only_to_var_or_const);
  1167. end;
  1168. pt.free;
  1169. { replace old varsym with the new absolutevarsym }
  1170. if assigned(abssym) then
  1171. begin
  1172. st:=vs.owner;
  1173. vs.owner.Delete(vs);
  1174. st.insert(abssym);
  1175. sc[0]:=abssym;
  1176. end;
  1177. end;
  1178. var
  1179. sc : TFPObjectList;
  1180. vs : tabstractvarsym;
  1181. hdef : tdef;
  1182. i : longint;
  1183. semicoloneaten,
  1184. allowdefaultvalue,
  1185. hasdefaultvalue : boolean;
  1186. hintsymoptions : tsymoptions;
  1187. deprecatedmsg : pshortstring;
  1188. old_block_type : tblock_type;
  1189. sectionname : ansistring;
  1190. begin
  1191. old_block_type:=block_type;
  1192. block_type:=bt_var;
  1193. { Force an expected ID error message }
  1194. if not (token in [_ID,_CASE,_END]) then
  1195. consume(_ID);
  1196. { read vars }
  1197. sc:=TFPObjectList.create(false);
  1198. while (token=_ID) do
  1199. begin
  1200. semicoloneaten:=false;
  1201. hasdefaultvalue:=false;
  1202. allowdefaultvalue:=true;
  1203. sc.clear;
  1204. repeat
  1205. if (token = _ID) then
  1206. begin
  1207. case symtablestack.top.symtabletype of
  1208. localsymtable :
  1209. vs:=clocalvarsym.create(orgpattern,vs_value,generrordef,[]);
  1210. staticsymtable,
  1211. globalsymtable :
  1212. begin
  1213. vs:=cstaticvarsym.create(orgpattern,vs_value,generrordef,[]);
  1214. if vd_threadvar in options then
  1215. include(vs.varoptions,vo_is_thread_var);
  1216. end;
  1217. else
  1218. internalerror(200411064);
  1219. end;
  1220. sc.add(vs);
  1221. symtablestack.top.insert(vs);
  1222. end;
  1223. consume(_ID);
  1224. until not try_to_consume(_COMMA);
  1225. { read variable type def }
  1226. block_type:=bt_var_type;
  1227. consume(_COLON);
  1228. {$ifdef gpc_mode}
  1229. if (m_gpc in current_settings.modeswitches) and
  1230. (token=_ID) and
  1231. (orgpattern='__asmname__') then
  1232. read_gpc_name(sc);
  1233. {$endif}
  1234. read_anon_type(hdef,false);
  1235. maybe_guarantee_record_typesym(hdef,symtablestack.top);
  1236. for i:=0 to sc.count-1 do
  1237. begin
  1238. vs:=tabstractvarsym(sc[i]);
  1239. vs.vardef:=hdef;
  1240. end;
  1241. block_type:=bt_var;
  1242. { Process procvar directives }
  1243. if maybe_parse_proc_directives(hdef) then
  1244. semicoloneaten:=true;
  1245. { check for absolute }
  1246. if try_to_consume(_ABSOLUTE) then
  1247. begin
  1248. read_absolute(sc);
  1249. allowdefaultvalue:=false;
  1250. end;
  1251. { Check for EXTERNAL etc directives before a semicolon }
  1252. if (idtoken in [_EXPORT,_EXTERNAL,_WEAKEXTERNAL,_PUBLIC,_CVAR]) then
  1253. begin
  1254. read_public_and_external_sc(sc);
  1255. allowdefaultvalue:=false;
  1256. semicoloneaten:=true;
  1257. end;
  1258. { try to parse the hint directives }
  1259. hintsymoptions:=[];
  1260. deprecatedmsg:=nil;
  1261. try_consume_hintdirective(hintsymoptions,deprecatedmsg);
  1262. for i:=0 to sc.count-1 do
  1263. begin
  1264. vs:=tabstractvarsym(sc[i]);
  1265. vs.symoptions := vs.symoptions + hintsymoptions;
  1266. if deprecatedmsg<>nil then
  1267. vs.deprecatedmsg:=stringdup(deprecatedmsg^);
  1268. end;
  1269. stringdispose(deprecatedmsg);
  1270. { Handling of Delphi typed const = initialized vars }
  1271. if allowdefaultvalue and
  1272. (token=_EQ) and
  1273. not(m_tp7 in current_settings.modeswitches) and
  1274. (symtablestack.top.symtabletype<>parasymtable) then
  1275. begin
  1276. { Add calling convention for procvar }
  1277. if (hdef.typ=procvardef) and
  1278. (hdef.typesym=nil) then
  1279. handle_calling_convention(tprocvardef(hdef));
  1280. read_default_value(sc);
  1281. hasdefaultvalue:=true;
  1282. end
  1283. else
  1284. begin
  1285. if not(semicoloneaten) then
  1286. consume(_SEMICOLON);
  1287. end;
  1288. { Support calling convention for procvars after semicolon }
  1289. if not(hasdefaultvalue) and
  1290. (hdef.typ=procvardef) and
  1291. (hdef.typesym=nil) then
  1292. begin
  1293. { Parse procvar directives after ; }
  1294. maybe_parse_proc_directives(hdef);
  1295. { Add calling convention for procvar }
  1296. handle_calling_convention(tprocvardef(hdef));
  1297. { Handling of Delphi typed const = initialized vars }
  1298. if (token=_EQ) and
  1299. not(m_tp7 in current_settings.modeswitches) and
  1300. (symtablestack.top.symtabletype<>parasymtable) then
  1301. begin
  1302. read_default_value(sc);
  1303. hasdefaultvalue:=true;
  1304. end;
  1305. end;
  1306. { Check for EXTERNAL etc directives or, in macpas, if cs_external_var is set}
  1307. if (
  1308. (
  1309. (idtoken in [_EXPORT,_EXTERNAL,_WEAKEXTERNAL,_PUBLIC,_CVAR]) and
  1310. (m_cvar_support in current_settings.modeswitches)
  1311. ) or
  1312. (
  1313. (m_mac in current_settings.modeswitches) and
  1314. (
  1315. (cs_external_var in current_settings.localswitches) or
  1316. (cs_externally_visible in current_settings.localswitches)
  1317. )
  1318. )
  1319. ) then
  1320. read_public_and_external_sc(sc);
  1321. { try to parse a section directive }
  1322. if (target_info.system in systems_allow_section) and
  1323. (symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) and
  1324. (idtoken=_SECTION) then
  1325. begin
  1326. try_consume_sectiondirective(sectionname);
  1327. if sectionname<>'' then
  1328. begin
  1329. for i:=0 to sc.count-1 do
  1330. begin
  1331. vs:=tabstractvarsym(sc[i]);
  1332. if (vs.varoptions *[vo_is_external,vo_is_weak_external])<>[] then
  1333. Message(parser_e_externals_no_section);
  1334. if vs.typ<>staticvarsym then
  1335. Message(parser_e_section_no_locals);
  1336. tstaticvarsym(vs).section:=sectionname;
  1337. include(vs.varoptions, vo_has_section);
  1338. end;
  1339. end;
  1340. end;
  1341. { allocate normal variable (non-external and non-typed-const) staticvarsyms }
  1342. for i:=0 to sc.count-1 do
  1343. begin
  1344. vs:=tabstractvarsym(sc[i]);
  1345. if (vs.typ=staticvarsym) and
  1346. not(vo_is_typed_const in vs.varoptions) and
  1347. not(vo_is_external in vs.varoptions) then
  1348. cnodeutils.insertbssdata(tstaticvarsym(vs));
  1349. end;
  1350. end;
  1351. block_type:=old_block_type;
  1352. { free the list }
  1353. sc.free;
  1354. end;
  1355. procedure read_record_fields(options:Tvar_dec_options; reorderlist: TFPObjectList; variantdesc : ppvariantrecdesc);
  1356. var
  1357. sc : TFPObjectList;
  1358. i : longint;
  1359. hs,sorg : string;
  1360. hdef,casetype,tmpdef : tdef;
  1361. { maxsize contains the max. size of a variant }
  1362. { startvarrec contains the start of the variant part of a record }
  1363. maxsize, startvarrecsize : longint;
  1364. usedalign,
  1365. maxalignment,startvarrecalign,
  1366. maxpadalign, startpadalign: shortint;
  1367. stowner : tdef;
  1368. pt : tnode;
  1369. fieldvs : tfieldvarsym;
  1370. hstaticvs : tstaticvarsym;
  1371. vs : tabstractvarsym;
  1372. srsym : tsym;
  1373. srsymtable : TSymtable;
  1374. visibility : tvisibility;
  1375. recst : tabstractrecordsymtable;
  1376. unionsymtable : trecordsymtable;
  1377. offset : longint;
  1378. uniondef : trecorddef;
  1379. hintsymoptions : tsymoptions;
  1380. deprecatedmsg : pshortstring;
  1381. semicoloneaten,
  1382. removeclassoption: boolean;
  1383. {$if defined(powerpc) or defined(powerpc64)}
  1384. tempdef: tdef;
  1385. is_first_type: boolean;
  1386. {$endif powerpc or powerpc64}
  1387. old_block_type: tblock_type;
  1388. begin
  1389. old_block_type:=block_type;
  1390. block_type:=bt_var;
  1391. recst:=tabstractrecordsymtable(symtablestack.top);
  1392. {$if defined(powerpc) or defined(powerpc64)}
  1393. is_first_type:=true;
  1394. {$endif powerpc or powerpc64}
  1395. { Force an expected ID error message }
  1396. if not (token in [_ID,_CASE,_END]) then
  1397. consume(_ID);
  1398. { read vars }
  1399. sc:=TFPObjectList.create(false);
  1400. removeclassoption:=false;
  1401. while (token=_ID) and
  1402. not(((vd_object in options) or
  1403. ((vd_record in options) and (m_advanced_records in current_settings.modeswitches))) and
  1404. ((idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED,_STRICT]) or
  1405. ((m_final_fields in current_settings.modeswitches) and
  1406. (idtoken=_FINAL)))) do
  1407. begin
  1408. visibility:=symtablestack.top.currentvisibility;
  1409. semicoloneaten:=false;
  1410. sc.clear;
  1411. repeat
  1412. sorg:=orgpattern;
  1413. if token=_ID then
  1414. begin
  1415. vs:=cfieldvarsym.create(sorg,vs_value,generrordef,[]);
  1416. { normally the visibility is set via addfield, but sometimes
  1417. we collect symbols so we can add them in a batch of
  1418. potentially mixed visibility, and then the individual
  1419. symbols need to have their visibility already set }
  1420. vs.visibility:=visibility;
  1421. sc.add(vs);
  1422. recst.insert(vs);
  1423. end;
  1424. consume(_ID);
  1425. until not try_to_consume(_COMMA);
  1426. if m_delphi in current_settings.modeswitches then
  1427. block_type:=bt_var_type
  1428. else
  1429. block_type:=old_block_type;
  1430. consume(_COLON);
  1431. read_anon_type(hdef,false);
  1432. maybe_guarantee_record_typesym(hdef,symtablestack.top);
  1433. block_type:=bt_var;
  1434. { allow only static fields reference to struct where they are declared }
  1435. if not (vd_class in options) then
  1436. begin
  1437. stowner:=tdef(recst.defowner);
  1438. while assigned(stowner) and (stowner.typ in [objectdef,recorddef]) do
  1439. begin
  1440. if hdef.typ=arraydef then
  1441. begin
  1442. tmpdef:=hdef;
  1443. while (tmpdef.typ=arraydef) do
  1444. begin
  1445. { dynamic arrays are allowed }
  1446. if ado_IsDynamicArray in tarraydef(tmpdef).arrayoptions then
  1447. begin
  1448. tmpdef:=nil;
  1449. break;
  1450. end;
  1451. tmpdef:=tarraydef(tmpdef).elementdef;
  1452. end;
  1453. end
  1454. else
  1455. tmpdef:=hdef;
  1456. if assigned(tmpdef) and
  1457. (is_object(tmpdef) or is_record(tmpdef)) and
  1458. is_owned_by(tabstractrecorddef(stowner),tabstractrecorddef(tmpdef)) then
  1459. begin
  1460. Message1(type_e_type_is_not_completly_defined, tabstractrecorddef(tmpdef).RttiName);
  1461. { for error recovery or compiler will crash later }
  1462. hdef:=generrordef;
  1463. end;
  1464. stowner:=tdef(stowner.owner.defowner);
  1465. end;
  1466. end;
  1467. { Process procvar directives }
  1468. if maybe_parse_proc_directives(hdef) then
  1469. semicoloneaten:=true;
  1470. {$if defined(powerpc) or defined(powerpc64)}
  1471. { from gcc/gcc/config/rs6000/rs6000.h:
  1472. /* APPLE LOCAL begin Macintosh alignment 2002-1-22 ff */
  1473. /* Return the alignment of a struct based on the Macintosh PowerPC
  1474. alignment rules. In general the alignment of a struct is
  1475. determined by the greatest alignment of its elements. However, the
  1476. PowerPC rules cause the alignment of a struct to peg at word
  1477. alignment except when the first field has greater than word
  1478. (32-bit) alignment, in which case the alignment is determined by
  1479. the alignment of the first field. */
  1480. }
  1481. if (target_info.abi=abi_powerpc_aix) and
  1482. is_first_type and
  1483. (symtablestack.top.symtabletype=recordsymtable) and
  1484. (trecordsymtable(symtablestack.top).usefieldalignment=C_alignment) then
  1485. begin
  1486. tempdef:=hdef;
  1487. while tempdef.typ=arraydef do
  1488. tempdef:=tarraydef(tempdef).elementdef;
  1489. if tempdef.typ<>recorddef then
  1490. maxpadalign:=tempdef.alignment
  1491. else
  1492. maxpadalign:=trecorddef(tempdef).padalignment;
  1493. if (maxpadalign>4) and
  1494. (maxpadalign>trecordsymtable(symtablestack.top).padalignment) then
  1495. trecordsymtable(symtablestack.top).padalignment:=maxpadalign;
  1496. is_first_type:=false;
  1497. end;
  1498. {$endif powerpc or powerpc64}
  1499. { types that use init/final are not allowed in variant parts, but
  1500. classes are allowed }
  1501. if (variantrecordlevel>0) then
  1502. if is_managed_type(hdef) then
  1503. Message(parser_e_cant_use_inittable_here)
  1504. else
  1505. if hdef.typ=undefineddef then
  1506. Message(parser_e_cant_use_type_parameters_here);
  1507. { try to parse the hint directives }
  1508. hintsymoptions:=[];
  1509. deprecatedmsg:=nil;
  1510. try_consume_hintdirective(hintsymoptions,deprecatedmsg);
  1511. { update variable type and hints }
  1512. for i:=0 to sc.count-1 do
  1513. begin
  1514. fieldvs:=tfieldvarsym(sc[i]);
  1515. fieldvs.vardef:=hdef;
  1516. { insert any additional hint directives }
  1517. fieldvs.symoptions := fieldvs.symoptions + hintsymoptions;
  1518. if deprecatedmsg<>nil then
  1519. fieldvs.deprecatedmsg:=stringdup(deprecatedmsg^);
  1520. end;
  1521. stringdispose(deprecatedmsg);
  1522. { Records and objects can't have default values }
  1523. { for a record there doesn't need to be a ; before the END or ) }
  1524. if not(token in [_END,_RKLAMMER]) and
  1525. not(semicoloneaten) then
  1526. consume(_SEMICOLON);
  1527. { Parse procvar directives after ; }
  1528. maybe_parse_proc_directives(hdef);
  1529. { Add calling convention for procvar }
  1530. if (hdef.typ=procvardef) and
  1531. (hdef.typesym=nil) then
  1532. handle_calling_convention(tprocvardef(hdef));
  1533. if (vd_object in options) then
  1534. begin
  1535. { if it is not a class var section and token=STATIC then it is a class field too }
  1536. if not (vd_class in options) and try_to_consume(_STATIC) then
  1537. begin
  1538. consume(_SEMICOLON);
  1539. include(options,vd_class);
  1540. removeclassoption:=true;
  1541. end;
  1542. { Fields in Java classes/interfaces can have a separately
  1543. specified external name }
  1544. if is_java_class_or_interface(tdef(recst.defowner)) and
  1545. (oo_is_external in tobjectdef(recst.defowner).objectoptions) then
  1546. try_read_field_external_sc(sc);
  1547. end;
  1548. if (visibility=vis_published) and
  1549. not(is_class(hdef)) then
  1550. begin
  1551. MessagePos(tfieldvarsym(sc[0]).fileinfo,parser_e_cant_publish_that);
  1552. visibility:=vis_public;
  1553. end;
  1554. if (visibility=vis_published) and
  1555. not(oo_can_have_published in tobjectdef(hdef).objectoptions) and
  1556. not(m_delphi in current_settings.modeswitches) then
  1557. begin
  1558. MessagePos(tfieldvarsym(sc[0]).fileinfo,parser_e_only_publishable_classes_can_be_published);
  1559. visibility:=vis_public;
  1560. end;
  1561. if vd_class in options then
  1562. begin
  1563. { add static flag and staticvarsyms }
  1564. for i:=0 to sc.count-1 do
  1565. begin
  1566. fieldvs:=tfieldvarsym(sc[i]);
  1567. fieldvs.visibility:=visibility;
  1568. hstaticvs:=make_field_static(recst,fieldvs);
  1569. if not parse_generic then
  1570. cnodeutils.insertbssdata(hstaticvs);
  1571. if vd_final in options then
  1572. hstaticvs.varspez:=vs_final;
  1573. end;
  1574. if removeclassoption then
  1575. begin
  1576. exclude(options,vd_class);
  1577. removeclassoption:=false;
  1578. end;
  1579. end;
  1580. if vd_final in options then
  1581. begin
  1582. { add final flag }
  1583. for i:=0 to sc.count-1 do
  1584. begin
  1585. fieldvs:=tfieldvarsym(sc[i]);
  1586. fieldvs.varspez:=vs_final;
  1587. end;
  1588. end;
  1589. if not(vd_canreorder in options) then
  1590. { add field(s) to the recordsymtable }
  1591. recst.addfieldlist(sc,false)
  1592. else
  1593. { we may reorder the fields before adding them to the symbol
  1594. table }
  1595. reorderlist.concatlistcopy(sc)
  1596. end;
  1597. if m_delphi in current_settings.modeswitches then
  1598. block_type:=bt_var_type
  1599. else
  1600. block_type:=old_block_type;
  1601. { Check for Case }
  1602. if (vd_record in options) and
  1603. try_to_consume(_CASE) then
  1604. begin
  1605. maxsize:=0;
  1606. maxalignment:=0;
  1607. maxpadalign:=0;
  1608. { already inside a variant record? if not, setup a new variantdesc chain }
  1609. if not(assigned(variantdesc)) then
  1610. variantdesc:=@trecorddef(trecordsymtable(recst).defowner).variantrecdesc;
  1611. { else just concat the info to the given one }
  1612. new(variantdesc^);
  1613. fillchar(variantdesc^^,sizeof(tvariantrecdesc),0);
  1614. { including a field declaration? }
  1615. fieldvs:=nil;
  1616. sorg:=orgpattern;
  1617. hs:=pattern;
  1618. searchsym(hs,srsym,srsymtable);
  1619. if not(assigned(srsym) and (srsym.typ in [typesym,unitsym])) then
  1620. begin
  1621. consume(_ID);
  1622. consume(_COLON);
  1623. fieldvs:=cfieldvarsym.create(sorg,vs_value,generrordef,[]);
  1624. variantdesc^^.variantselector:=fieldvs;
  1625. symtablestack.top.insert(fieldvs);
  1626. end;
  1627. read_anon_type(casetype,true);
  1628. block_type:=bt_var;
  1629. if assigned(fieldvs) then
  1630. begin
  1631. fieldvs.vardef:=casetype;
  1632. recst.addfield(fieldvs,recst.currentvisibility);
  1633. end;
  1634. if not(is_ordinal(casetype))
  1635. {$ifndef cpu64bitaddr}
  1636. or is_64bitint(casetype)
  1637. {$endif cpu64bitaddr}
  1638. then
  1639. Message(type_e_ordinal_expr_expected);
  1640. consume(_OF);
  1641. UnionSymtable:=trecordsymtable.create('',current_settings.packrecords);
  1642. UnionDef:=crecorddef.create('',unionsymtable);
  1643. uniondef.isunion:=true;
  1644. startvarrecsize:=UnionSymtable.datasize;
  1645. { align the bitpacking to the next byte }
  1646. UnionSymtable.datasize:=startvarrecsize;
  1647. startvarrecalign:=UnionSymtable.fieldalignment;
  1648. startpadalign:=Unionsymtable.padalignment;
  1649. symtablestack.push(UnionSymtable);
  1650. repeat
  1651. SetLength(variantdesc^^.branches,length(variantdesc^^.branches)+1);
  1652. fillchar(variantdesc^^.branches[high(variantdesc^^.branches)],
  1653. sizeof(variantdesc^^.branches[high(variantdesc^^.branches)]),0);
  1654. repeat
  1655. pt:=comp_expr(true,false);
  1656. if not(pt.nodetype=ordconstn) then
  1657. Message(parser_e_illegal_expression);
  1658. { iso pascal does not support ranges in variant record definitions }
  1659. if not(m_iso in current_settings.modeswitches) and try_to_consume(_POINTPOINT) then
  1660. pt:=crangenode.create(pt,comp_expr(true,false))
  1661. else
  1662. begin
  1663. with variantdesc^^.branches[high(variantdesc^^.branches)] do
  1664. begin
  1665. SetLength(values,length(values)+1);
  1666. values[high(values)]:=tordconstnode(pt).value;
  1667. end;
  1668. end;
  1669. pt.free;
  1670. if token=_COMMA then
  1671. consume(_COMMA)
  1672. else
  1673. break;
  1674. until false;
  1675. if m_delphi in current_settings.modeswitches then
  1676. block_type:=bt_var_type
  1677. else
  1678. block_type:=old_block_type;
  1679. consume(_COLON);
  1680. { read the vars }
  1681. consume(_LKLAMMER);
  1682. inc(variantrecordlevel);
  1683. if token<>_RKLAMMER then
  1684. read_record_fields([vd_record],nil,@variantdesc^^.branches[high(variantdesc^^.branches)].nestedvariant);
  1685. dec(variantrecordlevel);
  1686. consume(_RKLAMMER);
  1687. { calculates maximal variant size }
  1688. maxsize:=max(maxsize,unionsymtable.datasize);
  1689. maxalignment:=max(maxalignment,unionsymtable.fieldalignment);
  1690. maxpadalign:=max(maxpadalign,unionsymtable.padalignment);
  1691. { the items of the next variant are overlayed }
  1692. unionsymtable.datasize:=startvarrecsize;
  1693. unionsymtable.fieldalignment:=startvarrecalign;
  1694. unionsymtable.padalignment:=startpadalign;
  1695. if (token<>_END) and (token<>_RKLAMMER) then
  1696. consume(_SEMICOLON)
  1697. else
  1698. break;
  1699. until (token=_END) or (token=_RKLAMMER);
  1700. symtablestack.pop(UnionSymtable);
  1701. { at last set the record size to that of the biggest variant }
  1702. unionsymtable.datasize:=maxsize;
  1703. unionsymtable.fieldalignment:=maxalignment;
  1704. unionsymtable.addalignmentpadding;
  1705. {$if defined(powerpc) or defined(powerpc64)}
  1706. { parent inherits the alignment padding if the variant is the first "field" of the parent record/variant }
  1707. if (target_info.system in [system_powerpc_darwin, system_powerpc_macos, system_powerpc64_darwin]) and
  1708. is_first_type and
  1709. (recst.usefieldalignment=C_alignment) and
  1710. (maxpadalign>recst.padalignment) then
  1711. recst.padalignment:=maxpadalign;
  1712. {$endif powerpc or powerpc64}
  1713. { Align the offset where the union symtable is added }
  1714. case recst.usefieldalignment of
  1715. { allow the unionsymtable to be aligned however it wants }
  1716. { (within the global min/max limits) }
  1717. 0, { default }
  1718. C_alignment:
  1719. usedalign:=used_align(unionsymtable.recordalignment,current_settings.alignment.recordalignmin,current_settings.alignment.maxCrecordalign);
  1720. { 1 byte alignment if we are bitpacked }
  1721. bit_alignment:
  1722. usedalign:=1;
  1723. mac68k_alignment:
  1724. usedalign:=2;
  1725. { otherwise alignment at the packrecords alignment of the }
  1726. { current record }
  1727. else
  1728. usedalign:=used_align(recst.fieldalignment,current_settings.alignment.recordalignmin,current_settings.alignment.recordalignmax);
  1729. end;
  1730. offset:=align(recst.datasize,usedalign);
  1731. recst.datasize:=offset+unionsymtable.datasize;
  1732. if unionsymtable.recordalignment>recst.fieldalignment then
  1733. recst.fieldalignment:=unionsymtable.recordalignment;
  1734. trecordsymtable(recst).insertunionst(Unionsymtable,offset);
  1735. uniondef.owner.deletedef(uniondef);
  1736. end;
  1737. { free the list }
  1738. sc.free;
  1739. {$ifdef powerpc}
  1740. is_first_type := false;
  1741. {$endif powerpc}
  1742. block_type:=old_block_type;
  1743. end;
  1744. end.