pdecl.pas 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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. incompatibletypes(od,class_tcustomattribute);
  423. paran:=read_attr_paras;
  424. { Search the tprocdef of the constructor which has to be called. }
  425. constrsym:=find_create_constructor(od);
  426. if constrsym.typ<>procsym then
  427. internalerror(2018102301);
  428. pcalln:=ccallnode.create(paran,tprocsym(constrsym),od.symtable,cloadvmtaddrnode.create(p),[],nil);
  429. p:=nil;
  430. typecheckpass(pcalln);
  431. if (pcalln.nodetype=calln) and assigned(tcallnode(pcalln).procdefinition) and not codegenerror then
  432. begin
  433. { TODO: once extended RTTI for methods is supported, reject a
  434. constructor if it doesn't have extended RTTI enabled }
  435. { collect the parameters of the call node as there might be
  436. compile time type conversions (e.g. a Byte parameter being
  437. passed a value > 255) }
  438. paran:=tcallnode(pcalln).left;
  439. { only count visible parameters (thankfully open arrays are not
  440. supported, otherwise we'd need to handle those as well) }
  441. parasok:=true;
  442. paras:=nil;
  443. if assigned(paran) then
  444. begin
  445. ptmp:=paran;
  446. pcount:=0;
  447. while assigned(ptmp) do
  448. begin
  449. if not (vo_is_hidden_para in tcallparanode(ptmp).parasym.varoptions) then
  450. inc(pcount);
  451. ptmp:=tcallparanode(ptmp).right;
  452. end;
  453. setlength(paras,pcount);
  454. ptmp:=paran;
  455. pcount:=0;
  456. while assigned(ptmp) do
  457. begin
  458. if not (vo_is_hidden_para in tcallparanode(ptmp).parasym.varoptions) then
  459. begin
  460. if not is_constnode(tcallparanode(ptmp).left) then
  461. begin
  462. parasok:=false;
  463. messagepos(tcallparanode(ptmp).left.fileinfo,type_e_constant_expr_expected);
  464. end;
  465. paras[high(paras)-pcount]:=tcallparanode(ptmp).left.getcopy;
  466. inc(pcount);
  467. end;
  468. ptmp:=tcallparanode(ptmp).right;
  469. end;
  470. end;
  471. if parasok then
  472. begin
  473. { Add attribute to attribute list which will be added
  474. to the property which is defined next. }
  475. if not assigned(rtti_attrs_def) then
  476. rtti_attrs_def:=trtti_attribute_list.create;
  477. rtti_attrs_def.addattribute(typesym,tcallnode(pcalln).procdefinition,pcalln,paras);
  478. end
  479. else
  480. begin
  481. { cleanup }
  482. pcalln.free;
  483. for i:=0 to high(paras) do
  484. paras[i].free;
  485. end;
  486. end
  487. else
  488. pcalln.free;
  489. end
  490. else
  491. begin
  492. Message(type_e_type_id_expected);
  493. { try to recover by nevertheless reading the parameters (if any) }
  494. read_attr_paras.free;
  495. end;
  496. p.free;
  497. until not try_to_consume(_COMMA);
  498. consume(_RECKKLAMMER);
  499. end;
  500. procedure types_dec(in_structure: boolean;out had_generic:boolean;var rtti_attrs_def: trtti_attribute_list);
  501. function determine_generic_def(name:tidstring):tstoreddef;
  502. var
  503. hashedid : THashedIDString;
  504. pd : tprocdef;
  505. sym : tsym;
  506. begin
  507. result:=nil;
  508. { check whether this is a declaration of a type inside a
  509. specialization }
  510. if assigned(current_structdef) and
  511. (df_specialization in current_structdef.defoptions) then
  512. begin
  513. if not assigned(current_structdef.genericdef) or
  514. not (current_structdef.genericdef.typ in [recorddef,objectdef]) then
  515. internalerror(2011052301);
  516. hashedid.id:=name;
  517. { we could be inside a method of the specialization
  518. instead of its declaration, so check that first (as
  519. local nested types aren't allowed we don't need to
  520. walk the symtablestack to find the localsymtable) }
  521. if symtablestack.top.symtabletype=localsymtable then
  522. begin
  523. { we are in a method }
  524. if not assigned(symtablestack.top.defowner) or
  525. (symtablestack.top.defowner.typ<>procdef) then
  526. internalerror(2011120701);
  527. pd:=tprocdef(symtablestack.top.defowner);
  528. if not assigned(pd.genericdef) or (pd.genericdef.typ<>procdef) then
  529. internalerror(2011120702);
  530. sym:=tsym(tprocdef(pd.genericdef).localst.findwithhash(hashedid));
  531. end
  532. else
  533. sym:=nil;
  534. if not assigned(sym) or not (sym.typ=typesym) then
  535. begin
  536. { now search in the declaration of the generic }
  537. sym:=tsym(tabstractrecorddef(current_structdef.genericdef).symtable.findwithhash(hashedid));
  538. if not assigned(sym) or not (sym.typ=typesym) then
  539. internalerror(2011052302);
  540. end;
  541. { use the corresponding type in the generic's symtable as
  542. genericdef for the specialized type }
  543. result:=tstoreddef(ttypesym(sym).typedef);
  544. end;
  545. end;
  546. procedure finalize_class_external_status(od: tobjectdef);
  547. begin
  548. if [oo_is_external,oo_is_forward] <= od.objectoptions then
  549. begin
  550. { formal definition: x = objcclass external; }
  551. exclude(od.objectoptions,oo_is_forward);
  552. include(od.objectoptions,oo_is_formal);
  553. end;
  554. end;
  555. var
  556. typename,orgtypename,
  557. gentypename,genorgtypename : TIDString;
  558. newtype : ttypesym;
  559. sym : tsym;
  560. hdef : tdef;
  561. defpos,storetokenpos : tfileposinfo;
  562. old_block_type : tblock_type;
  563. old_checkforwarddefs: TFPObjectList;
  564. objecttype : tobjecttyp;
  565. first,
  566. isgeneric,
  567. isunique,
  568. istyperenaming : boolean;
  569. generictypelist : tfphashobjectlist;
  570. generictokenbuf : tdynamicarray;
  571. vmtbuilder : TVMTBuilder;
  572. p:tnode;
  573. gendef : tstoreddef;
  574. s : shortstring;
  575. i : longint;
  576. {$ifdef x86}
  577. segment_register: string;
  578. {$endif x86}
  579. begin
  580. old_block_type:=block_type;
  581. { save unit container of forward declarations -
  582. we can be inside nested class type block }
  583. old_checkforwarddefs:=current_module.checkforwarddefs;
  584. current_module.checkforwarddefs:=TFPObjectList.Create(false);
  585. block_type:=bt_type;
  586. hdef:=nil;
  587. first:=true;
  588. had_generic:=false;
  589. repeat
  590. defpos:=current_tokenpos;
  591. istyperenaming:=false;
  592. generictypelist:=nil;
  593. generictokenbuf:=nil;
  594. { class attribute definitions? }
  595. if m_prefixed_attributes in current_settings.modeswitches then
  596. while token=_LECKKLAMMER do
  597. parse_rttiattributes(rtti_attrs_def);
  598. { fpc generic declaration? }
  599. if first then
  600. had_generic:=not(m_delphi in current_settings.modeswitches) and try_to_consume(_GENERIC);
  601. isgeneric:=had_generic;
  602. typename:=pattern;
  603. orgtypename:=orgpattern;
  604. consume(_ID);
  605. { delphi generic declaration? }
  606. if (m_delphi in current_settings.modeswitches) then
  607. isgeneric:=token=_LSHARPBRACKET;
  608. { Generic type declaration? }
  609. if isgeneric then
  610. begin
  611. if assigned(current_genericdef) then
  612. Message(parser_f_no_generic_inside_generic);
  613. consume(_LSHARPBRACKET);
  614. generictypelist:=parse_generic_parameters(true);
  615. consume(_RSHARPBRACKET);
  616. { we are not freeing the type parameters, so register them }
  617. for i:=0 to generictypelist.count-1 do
  618. begin
  619. ttypesym(generictypelist[i]).register_sym;
  620. tstoreddef(ttypesym(generictypelist[i]).typedef).register_def;
  621. end;
  622. str(generictypelist.Count,s);
  623. gentypename:=typename+'$'+s;
  624. genorgtypename:=orgtypename+'$'+s;
  625. end
  626. else
  627. begin
  628. gentypename:=typename;
  629. genorgtypename:=orgtypename;
  630. end;
  631. consume(_EQ);
  632. { support 'ttype=type word' syntax }
  633. isunique:=try_to_consume(_TYPE);
  634. { MacPas object model is more like Delphi's than like TP's, but }
  635. { uses the object keyword instead of class }
  636. if (m_mac in current_settings.modeswitches) and
  637. (token = _OBJECT) then
  638. token := _CLASS;
  639. { Start recording a generic template }
  640. if assigned(generictypelist) then
  641. begin
  642. generictokenbuf:=tdynamicarray.create(256);
  643. current_scanner.startrecordtokens(generictokenbuf);
  644. end;
  645. { is the type already defined? -- must be in the current symtable,
  646. not in a nested symtable or one higher up the stack -> don't
  647. use searchsym & frinds! }
  648. sym:=tsym(symtablestack.top.find(gentypename));
  649. newtype:=nil;
  650. { found a symbol with this name? }
  651. if assigned(sym) then
  652. begin
  653. if (sym.typ=typesym) and
  654. { this should not be a symbol that was created by a generic
  655. that was declared earlier }
  656. not (
  657. (ttypesym(sym).typedef.typ=undefineddef) and
  658. (sp_generic_dummy in sym.symoptions)
  659. ) then
  660. begin
  661. if ((token=_CLASS) or
  662. (token=_INTERFACE) or
  663. (token=_DISPINTERFACE) or
  664. (token=_OBJCCLASS) or
  665. (token=_OBJCPROTOCOL) or
  666. (token=_OBJCCATEGORY)) and
  667. (assigned(ttypesym(sym).typedef)) and
  668. is_implicit_pointer_object_type(ttypesym(sym).typedef) and
  669. (oo_is_forward in tobjectdef(ttypesym(sym).typedef).objectoptions) then
  670. begin
  671. case token of
  672. _CLASS :
  673. objecttype:=default_class_type;
  674. _INTERFACE :
  675. case current_settings.interfacetype of
  676. it_interfacecom:
  677. objecttype:=odt_interfacecom;
  678. it_interfacecorba:
  679. objecttype:=odt_interfacecorba;
  680. it_interfacejava:
  681. objecttype:=odt_interfacejava;
  682. end;
  683. _DISPINTERFACE :
  684. objecttype:=odt_dispinterface;
  685. _OBJCCLASS,
  686. _OBJCCATEGORY :
  687. objecttype:=odt_objcclass;
  688. _OBJCPROTOCOL :
  689. objecttype:=odt_objcprotocol;
  690. else
  691. internalerror(200811072);
  692. end;
  693. consume(token);
  694. { determine the generic def in case we are in a nested type
  695. of a specialization }
  696. gendef:=determine_generic_def(gentypename);
  697. { we can ignore the result, the definition is modified }
  698. object_dec(objecttype,genorgtypename,newtype,gendef,generictypelist,tobjectdef(ttypesym(sym).typedef),ht_none);
  699. newtype:=ttypesym(sym);
  700. hdef:=newtype.typedef;
  701. end
  702. else
  703. message1(parser_h_type_redef,genorgtypename);
  704. end;
  705. end;
  706. { no old type reused ? Then insert this new type }
  707. if not assigned(newtype) then
  708. begin
  709. { insert the new type first with an errordef, so that
  710. referencing the type before it's really set it
  711. will give an error (PFV) }
  712. hdef:=generrordef;
  713. gendef:=nil;
  714. storetokenpos:=current_tokenpos;
  715. if isgeneric then
  716. begin
  717. { for generics we need to check whether a non-generic type
  718. already exists and if not we need to insert a symbol with
  719. the non-generic name (available in (org)typename) that is a
  720. undefineddef, so that inline specializations can be used }
  721. sym:=tsym(symtablestack.top.Find(typename));
  722. if not assigned(sym) then
  723. begin
  724. sym:=ctypesym.create(orgtypename,cundefineddef.create(true),true);
  725. Include(sym.symoptions,sp_generic_dummy);
  726. ttypesym(sym).typedef.typesym:=sym;
  727. sym.visibility:=symtablestack.top.currentvisibility;
  728. symtablestack.top.insert(sym);
  729. ttypesym(sym).typedef.owner:=sym.owner;
  730. end
  731. else
  732. { this is not allowed in non-Delphi modes }
  733. if not (m_delphi in current_settings.modeswitches) then
  734. Message1(sym_e_duplicate_id,genorgtypename)
  735. else
  736. begin
  737. { we need to find this symbol even if it's a variable or
  738. something else when doing an inline specialization }
  739. Include(sym.symoptions,sp_generic_dummy);
  740. add_generic_dummysym(sym);
  741. end;
  742. end
  743. else
  744. begin
  745. if assigned(sym) and (sym.typ=typesym) and
  746. (ttypesym(sym).typedef.typ=undefineddef) and
  747. (sp_generic_dummy in sym.symoptions) then
  748. begin
  749. { this is a symbol that was added by an earlier generic
  750. declaration, reuse it }
  751. newtype:=ttypesym(sym);
  752. newtype.typedef:=hdef;
  753. { use the correct casing }
  754. newtype.RealName:=genorgtypename;
  755. sym:=nil;
  756. end;
  757. { determine the generic def in case we are in a nested type
  758. of a specialization }
  759. gendef:=determine_generic_def(gentypename);
  760. end;
  761. { insert a new type if we don't reuse an existing symbol }
  762. if not assigned(newtype) then
  763. begin
  764. newtype:=ctypesym.create(genorgtypename,hdef,true);
  765. newtype.visibility:=symtablestack.top.currentvisibility;
  766. symtablestack.top.insert(newtype);
  767. end;
  768. current_tokenpos:=defpos;
  769. current_tokenpos:=storetokenpos;
  770. { read the type definition }
  771. read_named_type(hdef,newtype,gendef,generictypelist,false,isunique);
  772. { update the definition of the type }
  773. if assigned(hdef) then
  774. begin
  775. if df_generic in hdef.defoptions then
  776. { flag parent symtables that they now contain a generic }
  777. hdef.owner.includeoption(sto_has_generic);
  778. if assigned(hdef.typesym) then
  779. begin
  780. istyperenaming:=true;
  781. include(newtype.symoptions,sp_explicitrename);
  782. end;
  783. if isunique then
  784. begin
  785. if is_objc_class_or_protocol(hdef) or
  786. is_java_class_or_interface(hdef) then
  787. Message(parser_e_unique_unsupported);
  788. if is_object(hdef) or
  789. is_class_or_interface_or_dispinterface(hdef) then
  790. begin
  791. { just create a child class type; this is
  792. Delphi-compatible }
  793. hdef:=cobjectdef.create(tobjectdef(hdef).objecttype,genorgtypename,tobjectdef(hdef),true);
  794. end
  795. else
  796. begin
  797. hdef:=tstoreddef(hdef).getcopy;
  798. { check if it is an ansistirng(codepage) declaration }
  799. if is_ansistring(hdef) and try_to_consume(_LKLAMMER) then
  800. begin
  801. p:=comp_expr([ef_accept_equal]);
  802. consume(_RKLAMMER);
  803. if not is_constintnode(p) then
  804. begin
  805. Message(parser_e_illegal_expression);
  806. { error recovery }
  807. end
  808. else
  809. begin
  810. if (tordconstnode(p).value<0) or (tordconstnode(p).value>65535) then
  811. begin
  812. Message(parser_e_invalid_codepage);
  813. tordconstnode(p).value:=0;
  814. end;
  815. tstringdef(hdef).encoding:=int64(tordconstnode(p).value);
  816. end;
  817. p.free;
  818. end;
  819. if (hdef.typ in [pointerdef,classrefdef]) and
  820. (tabstractpointerdef(hdef).pointeddef.typ=forwarddef) then
  821. current_module.checkforwarddefs.add(hdef);
  822. end;
  823. include(hdef.defoptions,df_unique);
  824. end;
  825. if not assigned(hdef.typesym) then
  826. begin
  827. hdef.typesym:=newtype;
  828. if sp_generic_dummy in newtype.symoptions then
  829. add_generic_dummysym(newtype);
  830. end;
  831. end;
  832. { in non-Delphi modes we need a reference to the generic def
  833. without the generic suffix, so it can be found easily when
  834. parsing method implementations }
  835. if isgeneric and assigned(sym) and
  836. not (m_delphi in current_settings.modeswitches) and
  837. (ttypesym(sym).typedef.typ=undefineddef) then
  838. { don't free the undefineddef as the defids rely on the count
  839. of the defs in the def list of the module}
  840. ttypesym(sym).typedef:=hdef;
  841. newtype.typedef:=hdef;
  842. { ensure that the type is registered when no specialization is
  843. currently done }
  844. if current_scanner.replay_stack_depth=0 then
  845. hdef.register_def;
  846. { KAZ: handle TGUID declaration in system unit }
  847. if (cs_compilesystem in current_settings.moduleswitches) and
  848. assigned(hdef) and
  849. (hdef.typ=recorddef) then
  850. begin
  851. if not assigned(rec_tguid) and
  852. (gentypename='TGUID') and
  853. (hdef.size=16) then
  854. rec_tguid:=trecorddef(hdef)
  855. else if not assigned(rec_jmp_buf) and
  856. (gentypename='JMP_BUF') then
  857. rec_jmp_buf:=trecorddef(hdef)
  858. else if not assigned(rec_exceptaddr) and
  859. (gentypename='TEXCEPTADDR') then
  860. rec_exceptaddr:=trecorddef(hdef);
  861. end;
  862. end;
  863. if assigned(hdef) then
  864. begin
  865. case hdef.typ of
  866. pointerdef :
  867. begin
  868. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  869. consume(_SEMICOLON);
  870. {$ifdef x86}
  871. {$ifdef i8086}
  872. if try_to_consume(_HUGE) then
  873. begin
  874. tcpupointerdef(hdef).x86pointertyp:=x86pt_huge;
  875. consume(_SEMICOLON);
  876. end
  877. else
  878. {$endif i8086}
  879. if try_to_consume(_FAR) then
  880. begin
  881. {$if defined(i8086)}
  882. tcpupointerdef(hdef).x86pointertyp:=x86pt_far;
  883. {$elseif defined(i386)}
  884. tcpupointerdef(hdef).x86pointertyp:=x86pt_near_fs;
  885. {$elseif defined(x86_64)}
  886. { for compatibility with previous versions of fpc,
  887. far pointer = regular pointer on x86_64 }
  888. Message1(parser_w_ptr_type_ignored,'FAR');
  889. {$endif}
  890. consume(_SEMICOLON);
  891. end
  892. else
  893. if try_to_consume(_NEAR) then
  894. begin
  895. if token <> _SEMICOLON then
  896. begin
  897. segment_register:=get_stringconst;
  898. case UpCase(segment_register) of
  899. 'CS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_cs;
  900. 'DS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_ds;
  901. 'SS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_ss;
  902. 'ES': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_es;
  903. 'FS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_fs;
  904. 'GS': tcpupointerdef(hdef).x86pointertyp:=x86pt_near_gs;
  905. else
  906. Message(asmr_e_invalid_register);
  907. end;
  908. end
  909. else
  910. tcpupointerdef(hdef).x86pointertyp:=x86pt_near;
  911. consume(_SEMICOLON);
  912. end;
  913. {$else x86}
  914. { Previous versions of FPC support declaring a pointer as
  915. far even on non-x86 platforms. }
  916. if try_to_consume(_FAR) then
  917. begin
  918. Message1(parser_w_ptr_type_ignored,'FAR');
  919. consume(_SEMICOLON);
  920. end;
  921. {$endif x86}
  922. end;
  923. procvardef :
  924. begin
  925. { in case of type renaming, don't parse proc directives }
  926. if istyperenaming then
  927. begin
  928. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  929. consume(_SEMICOLON);
  930. end
  931. else
  932. begin
  933. if not check_proc_directive(true) then
  934. begin
  935. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  936. consume(_SEMICOLON);
  937. end;
  938. parse_var_proc_directives(tsym(newtype));
  939. if po_is_function_ref in tprocvardef(hdef).procoptions then
  940. begin
  941. { these always support everything, no "of object" or
  942. "is_nested" is allowed }
  943. if is_nested_pd(tprocvardef(hdef)) or
  944. is_methodpointer(hdef) then
  945. cgmessage(type_e_function_reference_kind)
  946. else
  947. begin
  948. if (po_hascallingconvention in tprocvardef(hdef).procoptions) and
  949. (tprocvardef(hdef).proccalloption in [pocall_cdecl,pocall_mwpascal]) then
  950. begin
  951. include(tprocvardef(hdef).procoptions,po_is_block);
  952. { can't check yet whether the parameter types
  953. are valid for a block, since some of them
  954. may still be forwarddefs }
  955. end
  956. else
  957. { a regular anonymous function type: not yet supported }
  958. { the }
  959. Comment(V_Error,'Function references are not yet supported, only C blocks (add "cdecl;" at the end)');
  960. end
  961. end;
  962. handle_calling_convention(tprocvardef(hdef),hcc_default_actions_intf);
  963. if try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg) then
  964. consume(_SEMICOLON);
  965. end;
  966. end;
  967. objectdef :
  968. begin
  969. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  970. consume(_SEMICOLON);
  971. { change a forward and external class declaration into
  972. formal external definition, so the compiler does not
  973. expect an real definition later }
  974. if is_objc_class_or_protocol(hdef) or
  975. is_java_class_or_interface(hdef) then
  976. finalize_class_external_status(tobjectdef(hdef));
  977. { Build VMT indexes, skip for type renaming and forward classes }
  978. if (hdef.typesym=newtype) and
  979. not(oo_is_forward in tobjectdef(hdef).objectoptions) then
  980. begin
  981. vmtbuilder:=TVMTBuilder.Create(tobjectdef(hdef));
  982. vmtbuilder.generate_vmt;
  983. vmtbuilder.free;
  984. end;
  985. { In case of an objcclass, verify that all methods have a message
  986. name set. We only check this now, because message names can be set
  987. during the protocol (interface) mapping. At the same time, set the
  988. mangled names (these depend on the "external" name of the class),
  989. and mark private fields of external classes as "used" (to avoid
  990. bogus notes about them being unused)
  991. }
  992. { watch out for crashes in case of errors }
  993. if is_objc_class_or_protocol(hdef) and
  994. (not is_objccategory(hdef) or
  995. assigned(tobjectdef(hdef).childof)) then
  996. tobjectdef(hdef).finish_objc_data;
  997. if is_cppclass(hdef) then
  998. tobjectdef(hdef).finish_cpp_data;
  999. end;
  1000. recorddef :
  1001. begin
  1002. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  1003. consume(_SEMICOLON);
  1004. end;
  1005. else
  1006. begin
  1007. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  1008. consume(_SEMICOLON);
  1009. end;
  1010. end;
  1011. { if we have a real type definition or a unique type we may bind
  1012. attributes to this def }
  1013. if not istyperenaming or isunique then
  1014. trtti_attribute_list.bind(rtti_attrs_def,tobjectdef(hdef).rtti_attribute_list);
  1015. end;
  1016. if isgeneric and (not(hdef.typ in [objectdef,recorddef,arraydef,procvardef])
  1017. or is_objectpascal_helper(hdef)) then
  1018. message(parser_e_cant_create_generics_of_this_type);
  1019. { Stop recording a generic template }
  1020. if assigned(generictypelist) then
  1021. begin
  1022. current_scanner.stoprecordtokens;
  1023. tstoreddef(hdef).generictokenbuf:=generictokenbuf;
  1024. { Generic is never a type renaming }
  1025. hdef.typesym:=newtype;
  1026. generictypelist.free;
  1027. end;
  1028. if not (m_delphi in current_settings.modeswitches) and
  1029. (token=_ID) and (idtoken=_GENERIC) then
  1030. begin
  1031. had_generic:=true;
  1032. consume(_ID);
  1033. if token in [_PROCEDURE,_FUNCTION,_CLASS] then
  1034. break;
  1035. end
  1036. else
  1037. had_generic:=false;
  1038. first:=false;
  1039. if assigned(rtti_attrs_def) and (rtti_attrs_def.get_attribute_count>0) then
  1040. Message1(parser_e_unbound_attribute,trtti_attribute(rtti_attrs_def.rtti_attributes[0]).typesym.prettyname);
  1041. until ((token<>_ID) and (token<>_LECKKLAMMER)) or
  1042. (in_structure and
  1043. ((idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]) or
  1044. ((m_final_fields in current_settings.modeswitches) and
  1045. (idtoken=_FINAL))));
  1046. { resolve type block forward declarations and restore a unit
  1047. container for them }
  1048. resolve_forward_types;
  1049. current_module.checkforwarddefs.free;
  1050. current_module.checkforwarddefs:=old_checkforwarddefs;
  1051. block_type:=old_block_type;
  1052. end;
  1053. { reads a type declaration to the symbol table }
  1054. procedure type_dec(out had_generic:boolean);
  1055. var
  1056. rtti_attrs_def: trtti_attribute_list;
  1057. begin
  1058. consume(_TYPE);
  1059. rtti_attrs_def := nil;
  1060. types_dec(false,had_generic,rtti_attrs_def);
  1061. rtti_attrs_def.free;
  1062. end;
  1063. procedure var_dec(out had_generic:boolean);
  1064. { parses variable declarations and inserts them in }
  1065. { the top symbol table of symtablestack }
  1066. begin
  1067. consume(_VAR);
  1068. read_var_decls([vd_check_generic],had_generic);
  1069. end;
  1070. procedure property_dec;
  1071. { parses a global property (fpc mode feature) }
  1072. var
  1073. old_block_type: tblock_type;
  1074. begin
  1075. consume(_PROPERTY);
  1076. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  1077. message(parser_e_property_only_sgr);
  1078. old_block_type:=block_type;
  1079. block_type:=bt_const;
  1080. repeat
  1081. read_property_dec(false, nil);
  1082. consume(_SEMICOLON);
  1083. until token<>_ID;
  1084. block_type:=old_block_type;
  1085. end;
  1086. procedure threadvar_dec(out had_generic:boolean);
  1087. { parses thread variable declarations and inserts them in }
  1088. { the top symbol table of symtablestack }
  1089. begin
  1090. consume(_THREADVAR);
  1091. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  1092. message(parser_e_threadvars_only_sg);
  1093. if f_threading in features then
  1094. read_var_decls([vd_threadvar,vd_check_generic],had_generic)
  1095. else
  1096. begin
  1097. Message1(parser_f_unsupported_feature,featurestr[f_threading]);
  1098. read_var_decls([vd_check_generic],had_generic);
  1099. end;
  1100. end;
  1101. procedure resourcestring_dec(out had_generic:boolean);
  1102. var
  1103. orgname : TIDString;
  1104. p : tnode;
  1105. dummysymoptions : tsymoptions;
  1106. deprecatedmsg : pshortstring;
  1107. storetokenpos,filepos : tfileposinfo;
  1108. old_block_type : tblock_type;
  1109. sp : pchar;
  1110. sym : tsym;
  1111. first,
  1112. isgeneric : boolean;
  1113. begin
  1114. if target_info.system in systems_managed_vm then
  1115. message(parser_e_feature_unsupported_for_vm);
  1116. consume(_RESOURCESTRING);
  1117. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  1118. message(parser_e_resourcestring_only_sg);
  1119. first:=true;
  1120. had_generic:=false;
  1121. old_block_type:=block_type;
  1122. block_type:=bt_const;
  1123. repeat
  1124. orgname:=orgpattern;
  1125. filepos:=current_tokenpos;
  1126. isgeneric:=not (m_delphi in current_settings.modeswitches) and (token=_ID) and (idtoken=_GENERIC);
  1127. consume(_ID);
  1128. case token of
  1129. _EQ:
  1130. begin
  1131. consume(_EQ);
  1132. p:=comp_expr([ef_accept_equal]);
  1133. storetokenpos:=current_tokenpos;
  1134. current_tokenpos:=filepos;
  1135. sym:=nil;
  1136. case p.nodetype of
  1137. ordconstn:
  1138. begin
  1139. if is_constcharnode(p) then
  1140. begin
  1141. getmem(sp,2);
  1142. sp[0]:=chr(tordconstnode(p).value.svalue);
  1143. sp[1]:=#0;
  1144. sym:=cconstsym.create_string(orgname,constresourcestring,sp,1,nil);
  1145. end
  1146. else
  1147. Message(parser_e_illegal_expression);
  1148. end;
  1149. stringconstn:
  1150. with Tstringconstnode(p) do
  1151. begin
  1152. { resourcestrings are currently always single byte }
  1153. if cst_type in [cst_widestring,cst_unicodestring] then
  1154. changestringtype(getansistringdef);
  1155. getmem(sp,len+1);
  1156. move(value_str^,sp^,len+1);
  1157. sym:=cconstsym.create_string(orgname,constresourcestring,sp,len,nil);
  1158. end;
  1159. else
  1160. Message(parser_e_illegal_expression);
  1161. end;
  1162. current_tokenpos:=storetokenpos;
  1163. { Support hint directives }
  1164. dummysymoptions:=[];
  1165. deprecatedmsg:=nil;
  1166. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  1167. if assigned(sym) then
  1168. begin
  1169. sym.symoptions:=sym.symoptions+dummysymoptions;
  1170. sym.deprecatedmsg:=deprecatedmsg;
  1171. symtablestack.top.insert(sym);
  1172. end
  1173. else
  1174. stringdispose(deprecatedmsg);
  1175. consume(_SEMICOLON);
  1176. p.free;
  1177. end;
  1178. else
  1179. if not first and isgeneric and
  1180. (token in [_PROCEDURE, _FUNCTION, _CLASS]) then
  1181. begin
  1182. had_generic:=true;
  1183. break;
  1184. end
  1185. else
  1186. consume(_EQ);
  1187. end;
  1188. first:=false;
  1189. until token<>_ID;
  1190. block_type:=old_block_type;
  1191. end;
  1192. end.