pdecvar.pas 74 KB

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