pdecl.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does declaration (but not type) parsing for Free Pascal
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit pdecl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { global }
  24. globtype,
  25. { symtable }
  26. symsym,symdef,
  27. { pass_1 }
  28. node;
  29. function readconstant(const orgname:string;const filepos:tfileposinfo; out nodetype: tnodetype):tconstsym;
  30. procedure const_dec(out had_generic:boolean);
  31. procedure consts_dec(in_structure, allow_typed_const: boolean;out had_generic:boolean);
  32. procedure label_dec;
  33. procedure type_dec(out had_generic:boolean);
  34. procedure types_dec(in_structure: boolean;out had_generic:boolean;var rtti_attrs_def: trtti_attribute_list);
  35. procedure var_dec(out had_generic:boolean);
  36. procedure threadvar_dec(out had_generic:boolean);
  37. procedure property_dec;
  38. procedure resourcestring_dec(out had_generic:boolean);
  39. procedure parse_rttiattributes(var rtti_attrs_def:trtti_attribute_list);
  40. implementation
  41. uses
  42. SysUtils,
  43. { common }
  44. cutils,
  45. { global }
  46. globals,tokens,verbose,widestr,constexp,
  47. systems,aasmdata,fmodule,compinnr,
  48. { symtable }
  49. symconst,symbase,symtype,symcpu,symcreat,defutil,defcmp,symtable,
  50. { pass 1 }
  51. ninl,ncon,nobj,ngenutil,nld,nmem,ncal,pass_1,
  52. { parser }
  53. scanner,
  54. pbase,pexpr,ptype,ptconst,pdecsub,pdecvar,pdecobj,pgenutil,pparautl,
  55. {$ifdef jvm}
  56. pjvm,
  57. {$endif}
  58. { cpu-information }
  59. cpuinfo
  60. ;
  61. function is_system_custom_attribute_descendant(def:tdef):boolean;
  62. begin
  63. if not assigned(class_tcustomattribute) then
  64. class_tcustomattribute:=tobjectdef(search_system_type('TCUSTOMATTRIBUTE').typedef);
  65. Result:=def_is_related(def,class_tcustomattribute);
  66. end;
  67. function readconstant(const orgname:string;const filepos:tfileposinfo; out nodetype: tnodetype):tconstsym;
  68. var
  69. hp : tconstsym;
  70. p : tnode;
  71. ps : pconstset;
  72. pd : pbestreal;
  73. pg : pguid;
  74. sp : pchar;
  75. pw : pcompilerwidestring;
  76. storetokenpos : tfileposinfo;
  77. begin
  78. readconstant:=nil;
  79. if orgname='' then
  80. internalerror(9584582);
  81. hp:=nil;
  82. p:=comp_expr([ef_accept_equal]);
  83. nodetype:=p.nodetype;
  84. storetokenpos:=current_tokenpos;
  85. current_tokenpos:=filepos;
  86. case p.nodetype of
  87. ordconstn:
  88. begin
  89. if p.resultdef.typ=pointerdef then
  90. hp:=cconstsym.create_ordptr(orgname,constpointer,tordconstnode(p).value.uvalue,p.resultdef)
  91. else
  92. hp:=cconstsym.create_ord(orgname,constord,tordconstnode(p).value,p.resultdef);
  93. end;
  94. stringconstn:
  95. begin
  96. if is_wide_or_unicode_string(p.resultdef) then
  97. begin
  98. initwidestring(pw);
  99. copywidestring(pcompilerwidestring(tstringconstnode(p).value_str),pw);
  100. hp:=cconstsym.create_wstring(orgname,constwstring,pw);
  101. end
  102. else
  103. begin
  104. getmem(sp,tstringconstnode(p).len+1);
  105. move(tstringconstnode(p).value_str^,sp^,tstringconstnode(p).len+1);
  106. { if a non-default ansistring code page has been specified,
  107. keep it }
  108. if is_ansistring(p.resultdef) and
  109. (tstringdef(p.resultdef).encoding<>0) then
  110. hp:=cconstsym.create_string(orgname,conststring,sp,tstringconstnode(p).len,p.resultdef)
  111. else
  112. hp:=cconstsym.create_string(orgname,conststring,sp,tstringconstnode(p).len,nil);
  113. end;
  114. end;
  115. realconstn :
  116. begin
  117. new(pd);
  118. pd^:=trealconstnode(p).value_real;
  119. hp:=cconstsym.create_ptr(orgname,constreal,pd,p.resultdef);
  120. end;
  121. setconstn :
  122. begin
  123. new(ps);
  124. ps^:=tsetconstnode(p).value_set^;
  125. hp:=cconstsym.create_ptr(orgname,constset,ps,p.resultdef);
  126. end;
  127. pointerconstn :
  128. begin
  129. hp:=cconstsym.create_ordptr(orgname,constpointer,tpointerconstnode(p).value,p.resultdef);
  130. end;
  131. niln :
  132. begin
  133. hp:=cconstsym.create_ord(orgname,constnil,0,p.resultdef);
  134. end;
  135. typen :
  136. begin
  137. if is_interface(p.resultdef) then
  138. begin
  139. if assigned(tobjectdef(p.resultdef).iidguid) then
  140. begin
  141. new(pg);
  142. pg^:=tobjectdef(p.resultdef).iidguid^;
  143. hp:=cconstsym.create_ptr(orgname,constguid,pg,p.resultdef);
  144. end
  145. else
  146. Message1(parser_e_interface_has_no_guid,tobjectdef(p.resultdef).objrealname^);
  147. end
  148. else
  149. Message(parser_e_illegal_expression);
  150. end;
  151. inlinen:
  152. begin
  153. { this situation only happens if a intrinsic is parsed that has a
  154. generic type as its argument. As we don't know certain
  155. information about the final type yet, we need to use safe
  156. values (mostly 0, except for (Bit)SizeOf()) }
  157. if not parse_generic then
  158. Message(parser_e_illegal_expression);
  159. case tinlinenode(p).inlinenumber of
  160. in_sizeof_x:
  161. begin
  162. hp:=cconstsym.create_ord(orgname,constord,1,p.resultdef);
  163. end;
  164. in_bitsizeof_x:
  165. begin
  166. hp:=cconstsym.create_ord(orgname,constord,8,p.resultdef);
  167. end;
  168. { add other cases here if necessary }
  169. else
  170. Message(parser_e_illegal_expression);
  171. end;
  172. end;
  173. else
  174. Message(parser_e_illegal_expression);
  175. end;
  176. current_tokenpos:=storetokenpos;
  177. p.free;
  178. readconstant:=hp;
  179. end;
  180. procedure const_dec(out had_generic:boolean);
  181. begin
  182. consume(_CONST);
  183. consts_dec(false,true,had_generic);
  184. end;
  185. procedure consts_dec(in_structure, allow_typed_const: boolean;out had_generic:boolean);
  186. var
  187. orgname : TIDString;
  188. hdef : tdef;
  189. sym : tsym;
  190. dummysymoptions : tsymoptions;
  191. deprecatedmsg : pshortstring;
  192. storetokenpos,filepos : tfileposinfo;
  193. nodetype : tnodetype;
  194. old_block_type : tblock_type;
  195. first,
  196. isgeneric,
  197. skipequal : boolean;
  198. tclist : tasmlist;
  199. varspez : tvarspez;
  200. begin
  201. old_block_type:=block_type;
  202. block_type:=bt_const;
  203. had_generic:=false;
  204. first:=true;
  205. repeat
  206. orgname:=orgpattern;
  207. filepos:=current_tokenpos;
  208. isgeneric:=not (m_delphi in current_settings.modeswitches) and (token=_ID) and (idtoken=_GENERIC);
  209. consume(_ID);
  210. case token of
  211. _EQ:
  212. begin
  213. consume(_EQ);
  214. sym:=readconstant(orgname,filepos,nodetype);
  215. { Support hint directives }
  216. dummysymoptions:=[];
  217. deprecatedmsg:=nil;
  218. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  219. if assigned(sym) then
  220. begin
  221. sym.symoptions:=sym.symoptions+dummysymoptions;
  222. sym.deprecatedmsg:=deprecatedmsg;
  223. sym.visibility:=symtablestack.top.currentvisibility;
  224. symtablestack.top.insert(sym);
  225. {$ifdef jvm}
  226. { for the JVM target, some constants need to be
  227. initialized at run time (enums, sets) -> create fake
  228. typed const to do so (at least if they are visible
  229. outside this routine, since we won't directly access
  230. these symbols in the generated code) }
  231. if (symtablestack.top.symtablelevel<normal_function_level) and
  232. assigned(tconstsym(sym).constdef) and
  233. (tconstsym(sym).constdef.typ in [enumdef,setdef]) then
  234. jvm_add_typed_const_initializer(tconstsym(sym));
  235. {$endif}
  236. end
  237. else
  238. stringdispose(deprecatedmsg);
  239. consume(_SEMICOLON);
  240. end;
  241. _COLON:
  242. begin
  243. if not allow_typed_const then
  244. begin
  245. Message(parser_e_no_typed_const);
  246. consume_all_until(_SEMICOLON);
  247. end;
  248. { set the blocktype first so a consume also supports a
  249. caret, to support const s : ^string = nil }
  250. block_type:=bt_const_type;
  251. consume(_COLON);
  252. read_anon_type(hdef,false);
  253. block_type:=bt_const;
  254. skipequal:=false;
  255. { create symbol }
  256. storetokenpos:=current_tokenpos;
  257. current_tokenpos:=filepos;
  258. if not (cs_typed_const_writable in current_settings.localswitches) then
  259. varspez:=vs_const
  260. else
  261. varspez:=vs_value;
  262. { if we are dealing with structure const then we need to handle it as a
  263. structure static variable: create a symbol in unit symtable and a reference
  264. to it from the structure or linking will fail }
  265. if symtablestack.top.symtabletype in [recordsymtable,ObjectSymtable] then
  266. begin
  267. { note: we keep hdef so that we might at least read the
  268. constant data correctly for error recovery }
  269. check_allowed_for_var_or_const(hdef,false);
  270. sym:=cfieldvarsym.create(orgname,varspez,hdef,[],true);
  271. symtablestack.top.insert(sym);
  272. sym:=make_field_static(symtablestack.top,tfieldvarsym(sym));
  273. end
  274. else
  275. begin
  276. sym:=cstaticvarsym.create(orgname,varspez,hdef,[],true);
  277. sym.visibility:=symtablestack.top.currentvisibility;
  278. symtablestack.top.insert(sym);
  279. end;
  280. current_tokenpos:=storetokenpos;
  281. { procvar can have proc directives, but not type references }
  282. if (hdef.typ=procvardef) and
  283. (hdef.typesym=nil) then
  284. begin
  285. { support p : procedure;stdcall=nil; }
  286. if try_to_consume(_SEMICOLON) then
  287. begin
  288. if check_proc_directive(true) then
  289. parse_var_proc_directives(sym)
  290. else
  291. begin
  292. Message(parser_e_proc_directive_expected);
  293. skipequal:=true;
  294. end;
  295. end
  296. else
  297. { support p : procedure stdcall=nil; }
  298. begin
  299. if check_proc_directive(true) then
  300. parse_var_proc_directives(sym);
  301. end;
  302. { add default calling convention }
  303. handle_calling_convention(tabstractprocdef(hdef),hcc_default_actions_intf);
  304. end;
  305. if not skipequal then
  306. begin
  307. { get init value }
  308. consume(_EQ);
  309. if (cs_typed_const_writable in current_settings.localswitches) then
  310. tclist:=current_asmdata.asmlists[al_typedconsts]
  311. else
  312. tclist:=current_asmdata.asmlists[al_rotypedconsts];
  313. read_typed_const(tclist,tstaticvarsym(sym),in_structure);
  314. end;
  315. end;
  316. else
  317. if not first and isgeneric and (token in [_PROCEDURE,_FUNCTION,_CLASS]) then
  318. begin
  319. had_generic:=true;
  320. break;
  321. end
  322. else
  323. { generate an error }
  324. consume(_EQ);
  325. end;
  326. first:=false;
  327. until (token<>_ID) or
  328. (in_structure and
  329. ((idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]) or
  330. ((m_final_fields in current_settings.modeswitches) and
  331. (idtoken=_FINAL))));
  332. block_type:=old_block_type;
  333. end;
  334. procedure label_dec;
  335. var
  336. labelsym : tlabelsym;
  337. begin
  338. consume(_LABEL);
  339. if not(cs_support_goto in current_settings.moduleswitches) then
  340. Message(sym_e_goto_and_label_not_supported);
  341. repeat
  342. if not(token in [_ID,_INTCONST]) then
  343. consume(_ID)
  344. else
  345. begin
  346. if token=_ID then
  347. labelsym:=clabelsym.create(orgpattern)
  348. else
  349. labelsym:=clabelsym.create(pattern);
  350. symtablestack.top.insert(labelsym);
  351. if m_non_local_goto in current_settings.modeswitches then
  352. begin
  353. if symtablestack.top.symtabletype=localsymtable then
  354. begin
  355. labelsym.jumpbuf:=clocalvarsym.create('LABEL$_'+labelsym.name,vs_value,rec_jmp_buf,[],true);
  356. symtablestack.top.insert(labelsym.jumpbuf);
  357. end
  358. else
  359. begin
  360. labelsym.jumpbuf:=cstaticvarsym.create('LABEL$_'+labelsym.name,vs_value,rec_jmp_buf,[],true);
  361. symtablestack.top.insert(labelsym.jumpbuf);
  362. cnodeutils.insertbssdata(tstaticvarsym(labelsym.jumpbuf));
  363. end;
  364. include(labelsym.jumpbuf.symoptions,sp_internal);
  365. { the buffer will be setup later, but avoid a hint }
  366. tabstractvarsym(labelsym.jumpbuf).varstate:=vs_written;
  367. end;
  368. consume(token);
  369. end;
  370. if token<>_SEMICOLON then consume(_COMMA);
  371. until not(token in [_ID,_INTCONST]);
  372. consume(_SEMICOLON);
  373. end;
  374. function find_create_constructor(objdef:tobjectdef):tsymentry;
  375. begin
  376. while assigned(objdef) do
  377. begin
  378. result:=objdef.symtable.Find('CREATE');
  379. if assigned(result) then
  380. exit;
  381. objdef:=objdef.childof;
  382. end;
  383. // A class without a constructor called 'create'?!?
  384. internalerror(2012111101);
  385. end;
  386. procedure parse_rttiattributes(var rtti_attrs_def:trtti_attribute_list);
  387. function read_attr_paras:tnode;
  388. var
  389. old_block_type : tblock_type;
  390. begin
  391. if try_to_consume(_LKLAMMER) then
  392. begin
  393. { we only want constants here }
  394. old_block_type:=block_type;
  395. block_type:=bt_const;
  396. result:=parse_paras(false,false,_RKLAMMER);
  397. block_type:=old_block_type;
  398. consume(_RKLAMMER);
  399. end
  400. else
  401. result:=nil;
  402. end;
  403. var
  404. p,paran,pcalln,ptmp : tnode;
  405. i,pcount : sizeint;
  406. paras : array of tnode;
  407. od : tobjectdef;
  408. constrsym : tsymentry;
  409. typesym : ttypesym;
  410. parasok : boolean;
  411. begin
  412. consume(_LECKKLAMMER);
  413. repeat
  414. { Parse attribute type }
  415. p:=factor(false,[ef_type_only,ef_check_attr_suffix]);
  416. if p.nodetype=typen then
  417. begin
  418. typesym:=ttypesym(ttypenode(p).typesym);
  419. od:=tobjectdef(ttypenode(p).typedef);
  420. { Check if the attribute class is related to TCustomAttribute }
  421. if not is_system_custom_attribute_descendant(od) then
  422. begin
  423. incompatibletypes(od,class_tcustomattribute);
  424. read_attr_paras.free;
  425. continue;
  426. end;
  427. paran:=read_attr_paras;
  428. { Search the tprocdef of the constructor which has to be called. }
  429. constrsym:=find_create_constructor(od);
  430. if constrsym.typ<>procsym then
  431. internalerror(2018102301);
  432. pcalln:=ccallnode.create(paran,tprocsym(constrsym),od.symtable,cloadvmtaddrnode.create(p),[],nil);
  433. p:=nil;
  434. typecheckpass(pcalln);
  435. if (pcalln.nodetype=calln) and assigned(tcallnode(pcalln).procdefinition) and not codegenerror then
  436. begin
  437. { TODO: once extended RTTI for methods is supported, reject a
  438. constructor if it doesn't have extended RTTI enabled }
  439. { collect the parameters of the call node as there might be
  440. compile time type conversions (e.g. a Byte parameter being
  441. passed a value > 255) }
  442. paran:=tcallnode(pcalln).left;
  443. { only count visible parameters (thankfully open arrays are not
  444. supported, otherwise we'd need to handle those as well) }
  445. parasok:=true;
  446. paras:=nil;
  447. if assigned(paran) then
  448. begin
  449. ptmp:=paran;
  450. pcount:=0;
  451. while assigned(ptmp) do
  452. begin
  453. if not (vo_is_hidden_para in tcallparanode(ptmp).parasym.varoptions) then
  454. inc(pcount);
  455. ptmp:=tcallparanode(ptmp).right;
  456. end;
  457. setlength(paras,pcount);
  458. ptmp:=paran;
  459. pcount:=0;
  460. while assigned(ptmp) do
  461. begin
  462. if not (vo_is_hidden_para in tcallparanode(ptmp).parasym.varoptions) then
  463. begin
  464. if not is_constnode(tcallparanode(ptmp).left) then
  465. begin
  466. parasok:=false;
  467. messagepos(tcallparanode(ptmp).left.fileinfo,type_e_constant_expr_expected);
  468. end;
  469. paras[high(paras)-pcount]:=tcallparanode(ptmp).left.getcopy;
  470. inc(pcount);
  471. end;
  472. ptmp:=tcallparanode(ptmp).right;
  473. end;
  474. end;
  475. if parasok then
  476. begin
  477. { Add attribute to attribute list which will be added
  478. to the property which is defined next. }
  479. if not assigned(rtti_attrs_def) then
  480. rtti_attrs_def:=trtti_attribute_list.create;
  481. rtti_attrs_def.addattribute(typesym,tcallnode(pcalln).procdefinition,pcalln,paras);
  482. end
  483. else
  484. begin
  485. { cleanup }
  486. pcalln.free;
  487. for i:=0 to high(paras) do
  488. paras[i].free;
  489. end;
  490. end
  491. else
  492. pcalln.free;
  493. end
  494. else
  495. begin
  496. Message(type_e_type_id_expected);
  497. { try to recover by nevertheless reading the parameters (if any) }
  498. read_attr_paras.free;
  499. end;
  500. p.free;
  501. until not try_to_consume(_COMMA);
  502. consume(_RECKKLAMMER);
  503. end;
  504. procedure types_dec(in_structure: boolean;out had_generic:boolean;var rtti_attrs_def: trtti_attribute_list);
  505. function determine_generic_def(name:tidstring):tstoreddef;
  506. var
  507. hashedid : THashedIDString;
  508. pd : tprocdef;
  509. sym : tsym;
  510. begin
  511. result:=nil;
  512. { check whether this is a declaration of a type inside a
  513. specialization }
  514. if assigned(current_structdef) and
  515. (df_specialization in current_structdef.defoptions) then
  516. begin
  517. if not assigned(current_structdef.genericdef) or
  518. not (current_structdef.genericdef.typ in [recorddef,objectdef]) then
  519. internalerror(2011052301);
  520. hashedid.id:=name;
  521. { we could be inside a method of the specialization
  522. instead of its declaration, so check that first (as
  523. local nested types aren't allowed we don't need to
  524. walk the symtablestack to find the localsymtable) }
  525. if symtablestack.top.symtabletype=localsymtable then
  526. begin
  527. { we are in a method }
  528. if not assigned(symtablestack.top.defowner) or
  529. (symtablestack.top.defowner.typ<>procdef) then
  530. internalerror(2011120701);
  531. pd:=tprocdef(symtablestack.top.defowner);
  532. if not assigned(pd.genericdef) or (pd.genericdef.typ<>procdef) then
  533. internalerror(2011120702);
  534. sym:=tsym(tprocdef(pd.genericdef).localst.findwithhash(hashedid));
  535. end
  536. else
  537. sym:=nil;
  538. if not assigned(sym) or not (sym.typ=typesym) then
  539. begin
  540. { now search in the declaration of the generic }
  541. sym:=tsym(tabstractrecorddef(current_structdef.genericdef).symtable.findwithhash(hashedid));
  542. if not assigned(sym) or not (sym.typ=typesym) then
  543. internalerror(2011052302);
  544. end;
  545. { use the corresponding type in the generic's symtable as
  546. genericdef for the specialized type }
  547. result:=tstoreddef(ttypesym(sym).typedef);
  548. end;
  549. end;
  550. procedure finalize_class_external_status(od: tobjectdef);
  551. begin
  552. if [oo_is_external,oo_is_forward] <= od.objectoptions then
  553. begin
  554. { formal definition: x = objcclass external; }
  555. exclude(od.objectoptions,oo_is_forward);
  556. include(od.objectoptions,oo_is_formal);
  557. end;
  558. end;
  559. var
  560. typename,orgtypename,
  561. gentypename,genorgtypename : TIDString;
  562. newtype : ttypesym;
  563. sym : tsym;
  564. hdef : tdef;
  565. defpos,storetokenpos : tfileposinfo;
  566. old_block_type : tblock_type;
  567. old_checkforwarddefs: TFPObjectList;
  568. objecttype : tobjecttyp;
  569. first,
  570. isgeneric,
  571. isunique,
  572. istyperenaming : boolean;
  573. generictypelist : tfphashobjectlist;
  574. generictokenbuf : tdynamicarray;
  575. vmtbuilder : TVMTBuilder;
  576. p:tnode;
  577. gendef : tstoreddef;
  578. s : shortstring;
  579. i : longint;
  580. {$ifdef x86}
  581. segment_register: string;
  582. {$endif x86}
  583. begin
  584. old_block_type:=block_type;
  585. { save unit container of forward declarations -
  586. we can be inside nested class type block }
  587. old_checkforwarddefs:=current_module.checkforwarddefs;
  588. current_module.checkforwarddefs:=TFPObjectList.Create(false);
  589. block_type:=bt_type;
  590. hdef:=nil;
  591. first:=true;
  592. had_generic:=false;
  593. repeat
  594. defpos:=current_tokenpos;
  595. istyperenaming:=false;
  596. generictypelist:=nil;
  597. generictokenbuf:=nil;
  598. { class attribute definitions? }
  599. if m_prefixed_attributes in current_settings.modeswitches then
  600. while token=_LECKKLAMMER do
  601. parse_rttiattributes(rtti_attrs_def);
  602. { fpc generic declaration? }
  603. if first then
  604. had_generic:=not(m_delphi in current_settings.modeswitches) and try_to_consume(_GENERIC);
  605. isgeneric:=had_generic;
  606. typename:=pattern;
  607. orgtypename:=orgpattern;
  608. consume(_ID);
  609. { delphi generic declaration? }
  610. if (m_delphi in current_settings.modeswitches) then
  611. isgeneric:=token=_LSHARPBRACKET;
  612. { Generic type declaration? }
  613. if isgeneric then
  614. begin
  615. if assigned(current_genericdef) then
  616. Message(parser_f_no_generic_inside_generic);
  617. consume(_LSHARPBRACKET);
  618. generictypelist:=parse_generic_parameters(true);
  619. consume(_RSHARPBRACKET);
  620. { we are not freeing the type parameters, so register them }
  621. for i:=0 to generictypelist.count-1 do
  622. begin
  623. ttypesym(generictypelist[i]).register_sym;
  624. tstoreddef(ttypesym(generictypelist[i]).typedef).register_def;
  625. end;
  626. str(generictypelist.Count,s);
  627. gentypename:=typename+'$'+s;
  628. genorgtypename:=orgtypename+'$'+s;
  629. end
  630. else
  631. begin
  632. gentypename:=typename;
  633. genorgtypename:=orgtypename;
  634. end;
  635. consume(_EQ);
  636. { support 'ttype=type word' syntax }
  637. isunique:=try_to_consume(_TYPE);
  638. { MacPas object model is more like Delphi's than like TP's, but }
  639. { uses the object keyword instead of class }
  640. if (m_mac in current_settings.modeswitches) and
  641. (token = _OBJECT) then
  642. token := _CLASS;
  643. { Start recording a generic template }
  644. if assigned(generictypelist) then
  645. begin
  646. generictokenbuf:=tdynamicarray.create(256);
  647. current_scanner.startrecordtokens(generictokenbuf);
  648. end;
  649. { is the type already defined? -- must be in the current symtable,
  650. not in a nested symtable or one higher up the stack -> don't
  651. use searchsym & frinds! }
  652. sym:=tsym(symtablestack.top.find(gentypename));
  653. newtype:=nil;
  654. { found a symbol with this name? }
  655. if assigned(sym) then
  656. begin
  657. if (sym.typ=typesym) and
  658. { this should not be a symbol that was created by a generic
  659. that was declared earlier }
  660. not (
  661. (ttypesym(sym).typedef.typ=undefineddef) and
  662. (sp_generic_dummy in sym.symoptions)
  663. ) then
  664. begin
  665. if ((token=_CLASS) or
  666. (token=_INTERFACE) or
  667. (token=_DISPINTERFACE) or
  668. (token=_OBJCCLASS) or
  669. (token=_OBJCPROTOCOL) or
  670. (token=_OBJCCATEGORY)) and
  671. (assigned(ttypesym(sym).typedef)) and
  672. is_implicit_pointer_object_type(ttypesym(sym).typedef) and
  673. (oo_is_forward in tobjectdef(ttypesym(sym).typedef).objectoptions) then
  674. begin
  675. case token of
  676. _CLASS :
  677. objecttype:=default_class_type;
  678. _INTERFACE :
  679. case current_settings.interfacetype of
  680. it_interfacecom:
  681. objecttype:=odt_interfacecom;
  682. it_interfacecorba:
  683. objecttype:=odt_interfacecorba;
  684. it_interfacejava:
  685. objecttype:=odt_interfacejava;
  686. end;
  687. _DISPINTERFACE :
  688. objecttype:=odt_dispinterface;
  689. _OBJCCLASS,
  690. _OBJCCATEGORY :
  691. objecttype:=odt_objcclass;
  692. _OBJCPROTOCOL :
  693. objecttype:=odt_objcprotocol;
  694. else
  695. internalerror(200811072);
  696. end;
  697. consume(token);
  698. { determine the generic def in case we are in a nested type
  699. of a specialization }
  700. gendef:=determine_generic_def(gentypename);
  701. { we can ignore the result, the definition is modified }
  702. object_dec(objecttype,genorgtypename,newtype,gendef,generictypelist,tobjectdef(ttypesym(sym).typedef),ht_none);
  703. newtype:=ttypesym(sym);
  704. hdef:=newtype.typedef;
  705. end
  706. else
  707. message1(parser_h_type_redef,genorgtypename);
  708. end;
  709. end;
  710. { no old type reused ? Then insert this new type }
  711. if not assigned(newtype) then
  712. begin
  713. { insert the new type first with an errordef, so that
  714. referencing the type before it's really set it
  715. will give an error (PFV) }
  716. hdef:=generrordef;
  717. gendef:=nil;
  718. storetokenpos:=current_tokenpos;
  719. if isgeneric then
  720. begin
  721. { for generics we need to check whether a non-generic type
  722. already exists and if not we need to insert a symbol with
  723. the non-generic name (available in (org)typename) that is a
  724. undefineddef, so that inline specializations can be used }
  725. sym:=tsym(symtablestack.top.Find(typename));
  726. if not assigned(sym) then
  727. begin
  728. sym:=ctypesym.create(orgtypename,cundefineddef.create(true),true);
  729. Include(sym.symoptions,sp_generic_dummy);
  730. ttypesym(sym).typedef.typesym:=sym;
  731. sym.visibility:=symtablestack.top.currentvisibility;
  732. symtablestack.top.insert(sym);
  733. ttypesym(sym).typedef.owner:=sym.owner;
  734. end
  735. else
  736. { this is not allowed in non-Delphi modes }
  737. if not (m_delphi in current_settings.modeswitches) then
  738. Message1(sym_e_duplicate_id,genorgtypename)
  739. else
  740. begin
  741. { we need to find this symbol even if it's a variable or
  742. something else when doing an inline specialization }
  743. Include(sym.symoptions,sp_generic_dummy);
  744. add_generic_dummysym(sym);
  745. end;
  746. end
  747. else
  748. begin
  749. if assigned(sym) and (sym.typ=typesym) and
  750. (ttypesym(sym).typedef.typ=undefineddef) and
  751. (sp_generic_dummy in sym.symoptions) then
  752. begin
  753. { this is a symbol that was added by an earlier generic
  754. declaration, reuse it }
  755. newtype:=ttypesym(sym);
  756. newtype.typedef:=hdef;
  757. { use the correct casing }
  758. newtype.RealName:=genorgtypename;
  759. sym:=nil;
  760. end;
  761. { determine the generic def in case we are in a nested type
  762. of a specialization }
  763. gendef:=determine_generic_def(gentypename);
  764. end;
  765. { insert a new type if we don't reuse an existing symbol }
  766. if not assigned(newtype) then
  767. begin
  768. newtype:=ctypesym.create(genorgtypename,hdef,true);
  769. newtype.visibility:=symtablestack.top.currentvisibility;
  770. symtablestack.top.insert(newtype);
  771. end;
  772. current_tokenpos:=defpos;
  773. current_tokenpos:=storetokenpos;
  774. { read the type definition }
  775. read_named_type(hdef,newtype,gendef,generictypelist,false,isunique);
  776. { update the definition of the type }
  777. if assigned(hdef) then
  778. begin
  779. if df_generic in hdef.defoptions then
  780. { flag parent symtables that they now contain a generic }
  781. hdef.owner.includeoption(sto_has_generic);
  782. if assigned(hdef.typesym) then
  783. begin
  784. istyperenaming:=true;
  785. include(newtype.symoptions,sp_explicitrename);
  786. end;
  787. if isunique then
  788. begin
  789. if is_objc_class_or_protocol(hdef) or
  790. is_java_class_or_interface(hdef) then
  791. Message(parser_e_unique_unsupported);
  792. if is_object(hdef) or
  793. is_class_or_interface_or_dispinterface(hdef) then
  794. begin
  795. { just create a child class type; this is
  796. Delphi-compatible }
  797. hdef:=cobjectdef.create(tobjectdef(hdef).objecttype,genorgtypename,tobjectdef(hdef),true);
  798. end
  799. else
  800. begin
  801. hdef:=tstoreddef(hdef).getcopy;
  802. { check if it is an ansistirng(codepage) declaration }
  803. if is_ansistring(hdef) and try_to_consume(_LKLAMMER) then
  804. begin
  805. p:=comp_expr([ef_accept_equal]);
  806. consume(_RKLAMMER);
  807. if not is_constintnode(p) then
  808. begin
  809. Message(parser_e_illegal_expression);
  810. { error recovery }
  811. end
  812. else
  813. begin
  814. if (tordconstnode(p).value<0) or (tordconstnode(p).value>65535) then
  815. begin
  816. Message(parser_e_invalid_codepage);
  817. tordconstnode(p).value:=0;
  818. end;
  819. tstringdef(hdef).encoding:=int64(tordconstnode(p).value);
  820. end;
  821. p.free;
  822. end;
  823. if (hdef.typ in [pointerdef,classrefdef]) and
  824. (tabstractpointerdef(hdef).pointeddef.typ=forwarddef) then
  825. current_module.checkforwarddefs.add(hdef);
  826. end;
  827. include(hdef.defoptions,df_unique);
  828. end;
  829. if not assigned(hdef.typesym) then
  830. begin
  831. hdef.typesym:=newtype;
  832. if sp_generic_dummy in newtype.symoptions then
  833. add_generic_dummysym(newtype);
  834. end;
  835. end;
  836. { in non-Delphi modes we need a reference to the generic def
  837. without the generic suffix, so it can be found easily when
  838. parsing method implementations }
  839. if isgeneric and assigned(sym) and
  840. not (m_delphi in current_settings.modeswitches) and
  841. (ttypesym(sym).typedef.typ=undefineddef) then
  842. { don't free the undefineddef as the defids rely on the count
  843. of the defs in the def list of the module}
  844. ttypesym(sym).typedef:=hdef;
  845. newtype.typedef:=hdef;
  846. { ensure that the type is registered when no specialization is
  847. currently done }
  848. if current_scanner.replay_stack_depth=0 then
  849. hdef.register_def;
  850. { KAZ: handle TGUID declaration in system unit }
  851. if (cs_compilesystem in current_settings.moduleswitches) and
  852. assigned(hdef) and
  853. (hdef.typ=recorddef) then
  854. begin
  855. if not assigned(rec_tguid) and
  856. (gentypename='TGUID') and
  857. (hdef.size=16) then
  858. rec_tguid:=trecorddef(hdef)
  859. else if not assigned(rec_jmp_buf) and
  860. (gentypename='JMP_BUF') then
  861. rec_jmp_buf:=trecorddef(hdef)
  862. else if not assigned(rec_exceptaddr) and
  863. (gentypename='TEXCEPTADDR') then
  864. rec_exceptaddr:=trecorddef(hdef);
  865. end;
  866. end;
  867. if assigned(hdef) then
  868. begin
  869. case hdef.typ of
  870. pointerdef :
  871. begin
  872. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  873. consume(_SEMICOLON);
  874. {$ifdef x86}
  875. {$ifdef i8086}
  876. if try_to_consume(_HUGE) then
  877. begin
  878. tcpupointerdef(hdef).x86pointertyp:=x86pt_huge;
  879. consume(_SEMICOLON);
  880. end
  881. else
  882. {$endif i8086}
  883. if try_to_consume(_FAR) then
  884. begin
  885. {$if defined(i8086)}
  886. tcpupointerdef(hdef).x86pointertyp:=x86pt_far;
  887. {$elseif defined(i386)}
  888. tcpupointerdef(hdef).x86pointertyp:=x86pt_near_fs;
  889. {$elseif defined(x86_64)}
  890. { for compatibility with previous versions of fpc,
  891. far pointer = regular pointer on x86_64 }
  892. Message1(parser_w_ptr_type_ignored,'FAR');
  893. {$endif}
  894. consume(_SEMICOLON);
  895. end
  896. else
  897. if try_to_consume(_NEAR) then
  898. begin
  899. if token <> _SEMICOLON then
  900. begin
  901. segment_register:=get_stringconst;
  902. case UpCase(segment_register) of
  903. 'CS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_cs;
  904. 'DS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_ds;
  905. 'SS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_ss;
  906. 'ES': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_es;
  907. 'FS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_fs;
  908. 'GS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_gs;
  909. else
  910. Message(asmr_e_invalid_register);
  911. end;
  912. end
  913. else
  914. tcpupointerdef(hdef).x86pointertyp:=x86pt_near;
  915. consume(_SEMICOLON);
  916. end;
  917. {$else x86}
  918. { Previous versions of FPC support declaring a pointer as
  919. far even on non-x86 platforms. }
  920. if try_to_consume(_FAR) then
  921. begin
  922. Message1(parser_w_ptr_type_ignored,'FAR');
  923. consume(_SEMICOLON);
  924. end;
  925. {$endif x86}
  926. end;
  927. procvardef :
  928. begin
  929. { in case of type renaming, don't parse proc directives }
  930. if istyperenaming then
  931. begin
  932. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  933. consume(_SEMICOLON);
  934. end
  935. else
  936. begin
  937. if not check_proc_directive(true) then
  938. begin
  939. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  940. consume(_SEMICOLON);
  941. end;
  942. parse_var_proc_directives(tsym(newtype));
  943. if po_is_function_ref in tprocvardef(hdef).procoptions then
  944. begin
  945. { these always support everything, no "of object" or
  946. "is_nested" is allowed }
  947. if is_nested_pd(tprocvardef(hdef)) or
  948. is_methodpointer(hdef) then
  949. cgmessage(type_e_function_reference_kind)
  950. else
  951. begin
  952. if (po_hascallingconvention in tprocvardef(hdef).procoptions) and
  953. (tprocvardef(hdef).proccalloption in [pocall_cdecl,pocall_mwpascal]) then
  954. begin
  955. include(tprocvardef(hdef).procoptions,po_is_block);
  956. { can't check yet whether the parameter types
  957. are valid for a block, since some of them
  958. may still be forwarddefs }
  959. end
  960. else
  961. { a regular anonymous function type: not yet supported }
  962. { the }
  963. Comment(V_Error,'Function references are not yet supported, only C blocks (add "cdecl;" at the end)');
  964. end
  965. end;
  966. handle_calling_convention(tprocvardef(hdef),hcc_default_actions_intf);
  967. if try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg) then
  968. consume(_SEMICOLON);
  969. end;
  970. end;
  971. objectdef :
  972. begin
  973. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  974. consume(_SEMICOLON);
  975. { change a forward and external class declaration into
  976. formal external definition, so the compiler does not
  977. expect an real definition later }
  978. if is_objc_class_or_protocol(hdef) or
  979. is_java_class_or_interface(hdef) then
  980. finalize_class_external_status(tobjectdef(hdef));
  981. { Build VMT indexes, skip for type renaming and forward classes }
  982. if (hdef.typesym=newtype) and
  983. not(oo_is_forward in tobjectdef(hdef).objectoptions) then
  984. begin
  985. vmtbuilder:=TVMTBuilder.Create(tobjectdef(hdef));
  986. vmtbuilder.generate_vmt;
  987. vmtbuilder.free;
  988. end;
  989. { In case of an objcclass, verify that all methods have a message
  990. name set. We only check this now, because message names can be set
  991. during the protocol (interface) mapping. At the same time, set the
  992. mangled names (these depend on the "external" name of the class),
  993. and mark private fields of external classes as "used" (to avoid
  994. bogus notes about them being unused)
  995. }
  996. { watch out for crashes in case of errors }
  997. if is_objc_class_or_protocol(hdef) and
  998. (not is_objccategory(hdef) or
  999. assigned(tobjectdef(hdef).childof)) then
  1000. tobjectdef(hdef).finish_objc_data;
  1001. if is_cppclass(hdef) then
  1002. tobjectdef(hdef).finish_cpp_data;
  1003. end;
  1004. recorddef :
  1005. begin
  1006. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  1007. consume(_SEMICOLON);
  1008. end;
  1009. else
  1010. begin
  1011. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  1012. consume(_SEMICOLON);
  1013. end;
  1014. end;
  1015. { if we have a real type definition or a unique type we may bind
  1016. attributes to this def }
  1017. if not istyperenaming or isunique then
  1018. trtti_attribute_list.bind(rtti_attrs_def,tstoreddef(hdef).rtti_attribute_list);
  1019. end;
  1020. if isgeneric and (not(hdef.typ in [objectdef,recorddef,arraydef,procvardef])
  1021. or is_objectpascal_helper(hdef)) then
  1022. message(parser_e_cant_create_generics_of_this_type);
  1023. { Stop recording a generic template }
  1024. if assigned(generictypelist) then
  1025. begin
  1026. current_scanner.stoprecordtokens;
  1027. tstoreddef(hdef).generictokenbuf:=generictokenbuf;
  1028. { Generic is never a type renaming }
  1029. hdef.typesym:=newtype;
  1030. generictypelist.free;
  1031. end;
  1032. if not (m_delphi in current_settings.modeswitches) and
  1033. (token=_ID) and (idtoken=_GENERIC) then
  1034. begin
  1035. had_generic:=true;
  1036. consume(_ID);
  1037. if token in [_PROCEDURE,_FUNCTION,_CLASS] then
  1038. break;
  1039. end
  1040. else
  1041. had_generic:=false;
  1042. first:=false;
  1043. if assigned(rtti_attrs_def) and (rtti_attrs_def.get_attribute_count>0) then
  1044. Message1(parser_e_unbound_attribute,trtti_attribute(rtti_attrs_def.rtti_attributes[0]).typesym.prettyname);
  1045. until ((token<>_ID) and (token<>_LECKKLAMMER)) or
  1046. (in_structure and
  1047. ((idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]) or
  1048. ((m_final_fields in current_settings.modeswitches) and
  1049. (idtoken=_FINAL))));
  1050. { resolve type block forward declarations and restore a unit
  1051. container for them }
  1052. resolve_forward_types;
  1053. current_module.checkforwarddefs.free;
  1054. current_module.checkforwarddefs:=old_checkforwarddefs;
  1055. block_type:=old_block_type;
  1056. end;
  1057. { reads a type declaration to the symbol table }
  1058. procedure type_dec(out had_generic:boolean);
  1059. var
  1060. rtti_attrs_def: trtti_attribute_list;
  1061. begin
  1062. consume(_TYPE);
  1063. rtti_attrs_def := nil;
  1064. types_dec(false,had_generic,rtti_attrs_def);
  1065. rtti_attrs_def.free;
  1066. end;
  1067. procedure var_dec(out had_generic:boolean);
  1068. { parses variable declarations and inserts them in }
  1069. { the top symbol table of symtablestack }
  1070. begin
  1071. consume(_VAR);
  1072. read_var_decls([vd_check_generic],had_generic);
  1073. end;
  1074. procedure property_dec;
  1075. { parses a global property (fpc mode feature) }
  1076. var
  1077. old_block_type: tblock_type;
  1078. begin
  1079. consume(_PROPERTY);
  1080. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  1081. message(parser_e_property_only_sgr);
  1082. old_block_type:=block_type;
  1083. block_type:=bt_const;
  1084. repeat
  1085. read_property_dec(false, nil);
  1086. consume(_SEMICOLON);
  1087. until token<>_ID;
  1088. block_type:=old_block_type;
  1089. end;
  1090. procedure threadvar_dec(out had_generic:boolean);
  1091. { parses thread variable declarations and inserts them in }
  1092. { the top symbol table of symtablestack }
  1093. begin
  1094. consume(_THREADVAR);
  1095. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  1096. message(parser_e_threadvars_only_sg);
  1097. if f_threading in features then
  1098. read_var_decls([vd_threadvar,vd_check_generic],had_generic)
  1099. else
  1100. begin
  1101. Message1(parser_f_unsupported_feature,featurestr[f_threading]);
  1102. read_var_decls([vd_check_generic],had_generic);
  1103. end;
  1104. end;
  1105. procedure resourcestring_dec(out had_generic:boolean);
  1106. var
  1107. orgname : TIDString;
  1108. p : tnode;
  1109. dummysymoptions : tsymoptions;
  1110. deprecatedmsg : pshortstring;
  1111. storetokenpos,filepos : tfileposinfo;
  1112. old_block_type : tblock_type;
  1113. sp : pchar;
  1114. sym : tsym;
  1115. first,
  1116. isgeneric : boolean;
  1117. begin
  1118. if target_info.system in systems_managed_vm then
  1119. message(parser_e_feature_unsupported_for_vm);
  1120. consume(_RESOURCESTRING);
  1121. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  1122. message(parser_e_resourcestring_only_sg);
  1123. first:=true;
  1124. had_generic:=false;
  1125. old_block_type:=block_type;
  1126. block_type:=bt_const;
  1127. repeat
  1128. orgname:=orgpattern;
  1129. filepos:=current_tokenpos;
  1130. isgeneric:=not (m_delphi in current_settings.modeswitches) and (token=_ID) and (idtoken=_GENERIC);
  1131. consume(_ID);
  1132. case token of
  1133. _EQ:
  1134. begin
  1135. consume(_EQ);
  1136. p:=comp_expr([ef_accept_equal]);
  1137. storetokenpos:=current_tokenpos;
  1138. current_tokenpos:=filepos;
  1139. sym:=nil;
  1140. case p.nodetype of
  1141. ordconstn:
  1142. begin
  1143. if is_constcharnode(p) then
  1144. begin
  1145. getmem(sp,2);
  1146. sp[0]:=chr(tordconstnode(p).value.svalue);
  1147. sp[1]:=#0;
  1148. sym:=cconstsym.create_string(orgname,constresourcestring,sp,1,nil);
  1149. end
  1150. else
  1151. Message(parser_e_illegal_expression);
  1152. end;
  1153. stringconstn:
  1154. with Tstringconstnode(p) do
  1155. begin
  1156. { resourcestrings are currently always single byte }
  1157. if cst_type in [cst_widestring,cst_unicodestring] then
  1158. changestringtype(getansistringdef);
  1159. getmem(sp,len+1);
  1160. move(value_str^,sp^,len+1);
  1161. sym:=cconstsym.create_string(orgname,constresourcestring,sp,len,nil);
  1162. end;
  1163. else
  1164. Message(parser_e_illegal_expression);
  1165. end;
  1166. current_tokenpos:=storetokenpos;
  1167. { Support hint directives }
  1168. dummysymoptions:=[];
  1169. deprecatedmsg:=nil;
  1170. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  1171. if assigned(sym) then
  1172. begin
  1173. sym.symoptions:=sym.symoptions+dummysymoptions;
  1174. sym.deprecatedmsg:=deprecatedmsg;
  1175. symtablestack.top.insert(sym);
  1176. end
  1177. else
  1178. stringdispose(deprecatedmsg);
  1179. consume(_SEMICOLON);
  1180. p.free;
  1181. end;
  1182. else
  1183. if not first and isgeneric and
  1184. (token in [_PROCEDURE, _FUNCTION, _CLASS]) then
  1185. begin
  1186. had_generic:=true;
  1187. break;
  1188. end
  1189. else
  1190. consume(_EQ);
  1191. end;
  1192. first:=false;
  1193. until token<>_ID;
  1194. block_type:=old_block_type;
  1195. end;
  1196. end.