pdecl.pas 51 KB

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