pdecl.pas 51 KB

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