pdecvar.pas 75 KB

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