pdecl.pas 51 KB

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