pdecobj.pas 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does object types 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 pdecobj;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,symconst,symtype,symdef;
  23. { parses a object declaration }
  24. function object_dec(objecttype:tobjecttyp;const n:tidstring;genericdef:tstoreddef;genericlist:TFPObjectList;fd : tobjectdef;helpertype:thelpertype) : tobjectdef;
  25. function class_constructor_head:tprocdef;
  26. function class_destructor_head:tprocdef;
  27. function constructor_head:tprocdef;
  28. function destructor_head:tprocdef;
  29. procedure struct_property_dec(is_classproperty:boolean);
  30. implementation
  31. uses
  32. sysutils,cutils,
  33. globals,verbose,systems,tokens,
  34. symbase,symsym,symtable,
  35. node,nld,nmem,ncon,ncnv,ncal,
  36. fmodule,scanner,
  37. pbase,pexpr,pdecsub,pdecvar,ptype,pdecl,ppu
  38. ;
  39. const
  40. { Please leave this here, this module should NOT use
  41. these variables.
  42. Declaring it as string here results in an error when compiling (PFV) }
  43. current_procinfo = 'error';
  44. var
  45. current_objectdef : tobjectdef absolute current_structdef;
  46. function class_constructor_head:tprocdef;
  47. var
  48. pd : tprocdef;
  49. begin
  50. result:=nil;
  51. consume(_CONSTRUCTOR);
  52. { must be at same level as in implementation }
  53. parse_proc_head(current_structdef,potype_class_constructor,pd);
  54. if not assigned(pd) then
  55. begin
  56. consume(_SEMICOLON);
  57. exit;
  58. end;
  59. pd.calcparas;
  60. if (pd.maxparacount>0) then
  61. Message(parser_e_no_paras_for_class_constructor);
  62. consume(_SEMICOLON);
  63. include(current_structdef.objectoptions,oo_has_class_constructor);
  64. current_module.flags:=current_module.flags or uf_classinits;
  65. { no return value }
  66. pd.returndef:=voidtype;
  67. result:=pd;
  68. end;
  69. function constructor_head:tprocdef;
  70. var
  71. pd : tprocdef;
  72. begin
  73. result:=nil;
  74. consume(_CONSTRUCTOR);
  75. { must be at same level as in implementation }
  76. parse_proc_head(current_structdef,potype_constructor,pd);
  77. if not assigned(pd) then
  78. begin
  79. consume(_SEMICOLON);
  80. exit;
  81. end;
  82. if (cs_constructor_name in current_settings.globalswitches) and
  83. (pd.procsym.name<>'INIT') then
  84. Message(parser_e_constructorname_must_be_init);
  85. consume(_SEMICOLON);
  86. include(current_structdef.objectoptions,oo_has_constructor);
  87. { Set return type, class and record constructors return the
  88. created instance, helper types return the extended type,
  89. object constructors return boolean }
  90. if is_class(pd.struct) or is_record(pd.struct) then
  91. pd.returndef:=pd.struct
  92. else
  93. if is_objectpascal_helper(pd.struct) then
  94. pd.returndef:=tobjectdef(pd.struct).extendeddef
  95. else
  96. {$ifdef CPU64bitaddr}
  97. pd.returndef:=bool64type;
  98. {$else CPU64bitaddr}
  99. pd.returndef:=bool32type;
  100. {$endif CPU64bitaddr}
  101. result:=pd;
  102. end;
  103. procedure struct_property_dec(is_classproperty:boolean);
  104. var
  105. p : tpropertysym;
  106. begin
  107. { check for a class, record or helper }
  108. if not((is_class_or_interface_or_dispinterface(current_structdef) or is_record(current_structdef) or is_objectpascal_helper(current_structdef)) or
  109. (not(m_tp7 in current_settings.modeswitches) and (is_object(current_structdef)))) then
  110. Message(parser_e_syntax_error);
  111. consume(_PROPERTY);
  112. p:=read_property_dec(is_classproperty,current_structdef);
  113. consume(_SEMICOLON);
  114. if try_to_consume(_DEFAULT) then
  115. begin
  116. if oo_has_default_property in current_structdef.objectoptions then
  117. message(parser_e_only_one_default_property);
  118. include(current_structdef.objectoptions,oo_has_default_property);
  119. include(p.propoptions,ppo_defaultproperty);
  120. if not(ppo_hasparameters in p.propoptions) then
  121. message(parser_e_property_need_paras);
  122. if (token=_COLON) then
  123. begin
  124. Message(parser_e_field_not_allowed_here);
  125. consume_all_until(_SEMICOLON);
  126. end;
  127. consume(_SEMICOLON);
  128. end;
  129. { parse possible enumerator modifier }
  130. if try_to_consume(_ENUMERATOR) then
  131. begin
  132. if (token = _ID) then
  133. begin
  134. if pattern='CURRENT' then
  135. begin
  136. if oo_has_enumerator_current in current_structdef.objectoptions then
  137. message(parser_e_only_one_enumerator_current);
  138. if not p.propaccesslist[palt_read].empty then
  139. begin
  140. include(current_structdef.objectoptions,oo_has_enumerator_current);
  141. include(p.propoptions,ppo_enumerator_current);
  142. end
  143. else
  144. Message(parser_e_enumerator_current_is_not_valid) // property has no reader
  145. end
  146. else
  147. Message1(parser_e_invalid_enumerator_identifier, pattern);
  148. consume(token);
  149. end
  150. else
  151. Message(parser_e_enumerator_identifier_required);
  152. consume(_SEMICOLON);
  153. end;
  154. { hint directives, these can be separated by semicolons here,
  155. that needs to be handled here with a loop (PFV) }
  156. while try_consume_hintdirective(p.symoptions,p.deprecatedmsg) do
  157. Consume(_SEMICOLON);
  158. end;
  159. function class_destructor_head:tprocdef;
  160. var
  161. pd : tprocdef;
  162. begin
  163. result:=nil;
  164. consume(_DESTRUCTOR);
  165. parse_proc_head(current_structdef,potype_class_destructor,pd);
  166. if not assigned(pd) then
  167. begin
  168. consume(_SEMICOLON);
  169. exit;
  170. end;
  171. pd.calcparas;
  172. if (pd.maxparacount>0) then
  173. Message(parser_e_no_paras_for_class_destructor);
  174. consume(_SEMICOLON);
  175. include(current_structdef.objectoptions,oo_has_class_destructor);
  176. current_module.flags:=current_module.flags or uf_classinits;
  177. { no return value }
  178. pd.returndef:=voidtype;
  179. result:=pd;
  180. end;
  181. function destructor_head:tprocdef;
  182. var
  183. pd : tprocdef;
  184. begin
  185. result:=nil;
  186. consume(_DESTRUCTOR);
  187. parse_proc_head(current_structdef,potype_destructor,pd);
  188. if not assigned(pd) then
  189. begin
  190. consume(_SEMICOLON);
  191. exit;
  192. end;
  193. if (cs_constructor_name in current_settings.globalswitches) and
  194. (pd.procsym.name<>'DONE') then
  195. Message(parser_e_destructorname_must_be_done);
  196. pd.calcparas;
  197. if not(pd.maxparacount=0) and
  198. (m_fpc in current_settings.modeswitches) then
  199. Message(parser_e_no_paras_for_destructor);
  200. consume(_SEMICOLON);
  201. include(current_structdef.objectoptions,oo_has_destructor);
  202. { no return value }
  203. pd.returndef:=voidtype;
  204. result:=pd;
  205. end;
  206. procedure setinterfacemethodoptions;
  207. var
  208. i : longint;
  209. def : tdef;
  210. begin
  211. include(current_structdef.objectoptions,oo_has_virtual);
  212. for i:=0 to current_structdef.symtable.DefList.count-1 do
  213. begin
  214. def:=tdef(current_structdef.symtable.DefList[i]);
  215. if assigned(def) and
  216. (def.typ=procdef) then
  217. begin
  218. include(tprocdef(def).procoptions,po_virtualmethod);
  219. tprocdef(def).forwarddef:=false;
  220. end;
  221. end;
  222. end;
  223. procedure setobjcclassmethodoptions;
  224. var
  225. i : longint;
  226. def : tdef;
  227. begin
  228. for i:=0 to current_structdef.symtable.DefList.count-1 do
  229. begin
  230. def:=tdef(current_structdef.symtable.DefList[i]);
  231. if assigned(def) and
  232. (def.typ=procdef) then
  233. begin
  234. include(tprocdef(def).procoptions,po_virtualmethod);
  235. end;
  236. end;
  237. end;
  238. procedure handleImplementedInterface(intfdef : tobjectdef);
  239. begin
  240. if not is_interface(intfdef) then
  241. begin
  242. Message1(type_e_interface_type_expected,intfdef.typename);
  243. exit;
  244. end;
  245. if current_objectdef.find_implemented_interface(intfdef)<>nil then
  246. Message1(sym_e_duplicate_id,intfdef.objname^)
  247. else
  248. begin
  249. { allocate and prepare the GUID only if the class
  250. implements some interfaces. }
  251. if current_objectdef.ImplementedInterfaces.count = 0 then
  252. current_objectdef.prepareguid;
  253. current_objectdef.ImplementedInterfaces.Add(TImplementedInterface.Create(intfdef));
  254. end;
  255. end;
  256. procedure handleImplementedProtocol(intfdef : tobjectdef);
  257. begin
  258. intfdef:=find_real_objcclass_definition(intfdef,false);
  259. if not is_objcprotocol(intfdef) then
  260. begin
  261. Message1(type_e_protocol_type_expected,intfdef.typename);
  262. exit;
  263. end;
  264. if ([oo_is_forward,oo_is_formal] * intfdef.objectoptions <> []) then
  265. begin
  266. Message1(parser_e_forward_protocol_declaration_must_be_resolved,intfdef.objrealname^);
  267. exit;
  268. end;
  269. if current_objectdef.find_implemented_interface(intfdef)<>nil then
  270. Message1(sym_e_duplicate_id,intfdef.objname^)
  271. else
  272. begin
  273. current_objectdef.ImplementedInterfaces.Add(TImplementedInterface.Create(intfdef));
  274. end;
  275. end;
  276. procedure readImplementedInterfacesAndProtocols(intf: boolean);
  277. var
  278. hdef : tdef;
  279. begin
  280. while try_to_consume(_COMMA) do
  281. begin
  282. { use single_type instead of id_type for specialize support }
  283. single_type(hdef,[stoAllowSpecialization,stoParseClassParent]);
  284. if (hdef.typ<>objectdef) then
  285. begin
  286. if intf then
  287. Message1(type_e_interface_type_expected,hdef.typename)
  288. else
  289. Message1(type_e_protocol_type_expected,hdef.typename);
  290. continue;
  291. end;
  292. if intf then
  293. handleImplementedInterface(tobjectdef(hdef))
  294. else
  295. handleImplementedProtocol(tobjectdef(hdef));
  296. end;
  297. end;
  298. procedure readinterfaceiid;
  299. var
  300. p : tnode;
  301. valid : boolean;
  302. begin
  303. p:=comp_expr(true,false);
  304. if p.nodetype=stringconstn then
  305. begin
  306. stringdispose(current_objectdef.iidstr);
  307. current_objectdef.iidstr:=stringdup(strpas(tstringconstnode(p).value_str));
  308. valid:=string2guid(current_objectdef.iidstr^,current_objectdef.iidguid^);
  309. if (current_objectdef.objecttype in [odt_interfacecom,odt_dispinterface]) and
  310. not valid then
  311. Message(parser_e_improper_guid_syntax);
  312. include(current_structdef.objectoptions,oo_has_valid_guid);
  313. end
  314. else
  315. Message(parser_e_illegal_expression);
  316. p.free;
  317. end;
  318. procedure get_cpp_class_external_status(od: tobjectdef);
  319. var
  320. hs: string;
  321. begin
  322. { C++ classes can be external -> all methods inside are external
  323. (defined at the class level instead of per method, so that you cannot
  324. define some methods as external and some not)
  325. }
  326. if try_to_consume(_EXTERNAL) then
  327. begin
  328. if token in [_CSTRING,_CWSTRING,_CCHAR,_CWCHAR] then
  329. begin
  330. { Always add library prefix and suffix to create an uniform name }
  331. hs:=get_stringconst;
  332. if ExtractFileExt(hs)='' then
  333. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  334. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  335. hs:=target_info.sharedlibprefix+hs;
  336. od.import_lib:=stringdup(hs);
  337. end;
  338. include(od.objectoptions, oo_is_external);
  339. { check if we shall use another name for the class }
  340. if try_to_consume(_NAME) then
  341. od.objextname:=stringdup(get_stringconst)
  342. else
  343. od.objextname:=stringdup(od.objrealname^);
  344. include(od.objectoptions,oo_is_external);
  345. end
  346. else
  347. od.objextname:=stringdup(od.objrealname^);
  348. { ToDo: read the namespace of the class (influences the mangled name)}
  349. end;
  350. procedure get_objc_class_or_protocol_external_status(od: tobjectdef);
  351. begin
  352. { Objective-C classes can be external -> all messages inside are
  353. external (defined at the class level instead of per method, so
  354. that you cannot define some methods as external and some not)
  355. }
  356. if try_to_consume(_EXTERNAL) then
  357. begin
  358. if try_to_consume(_NAME) then
  359. od.objextname:=stringdup(get_stringconst)
  360. else
  361. { the external name doesn't matter for formally declared
  362. classes, and allowing to specify one would mean that we would
  363. have to check it for consistency with the actual definition
  364. later on }
  365. od.objextname:=stringdup(od.objrealname^);
  366. include(od.objectoptions,oo_is_external);
  367. end
  368. else
  369. od.objextname:=stringdup(od.objrealname^);
  370. end;
  371. procedure parse_object_options;
  372. begin
  373. case current_objectdef.objecttype of
  374. odt_object,odt_class:
  375. begin
  376. while true do
  377. begin
  378. if try_to_consume(_ABSTRACT) then
  379. include(current_structdef.objectoptions,oo_is_abstract)
  380. else
  381. if try_to_consume(_SEALED) then
  382. include(current_structdef.objectoptions,oo_is_sealed)
  383. else
  384. break;
  385. end;
  386. if [oo_is_abstract, oo_is_sealed] * current_structdef.objectoptions = [oo_is_abstract, oo_is_sealed] then
  387. Message(parser_e_abstract_and_sealed_conflict);
  388. end;
  389. odt_cppclass:
  390. get_cpp_class_external_status(current_objectdef);
  391. odt_objcclass,odt_objcprotocol,odt_objccategory:
  392. get_objc_class_or_protocol_external_status(current_objectdef);
  393. odt_helper: ; // nothing
  394. end;
  395. end;
  396. procedure parse_parent_classes;
  397. var
  398. intfchildof,
  399. childof : tobjectdef;
  400. hdef : tdef;
  401. hasparentdefined : boolean;
  402. begin
  403. childof:=nil;
  404. intfchildof:=nil;
  405. hasparentdefined:=false;
  406. { reads the parent class }
  407. if (token=_LKLAMMER) or
  408. is_objccategory(current_structdef) then
  409. begin
  410. consume(_LKLAMMER);
  411. { use single_type instead of id_type for specialize support }
  412. single_type(hdef,[stoAllowSpecialization, stoParseClassParent]);
  413. if (not assigned(hdef)) or
  414. (hdef.typ<>objectdef) then
  415. begin
  416. if assigned(hdef) then
  417. Message1(type_e_class_type_expected,hdef.typename)
  418. else if is_objccategory(current_structdef) then
  419. { a category must specify the class to extend }
  420. Message(type_e_objcclass_type_expected);
  421. end
  422. else
  423. begin
  424. childof:=tobjectdef(hdef);
  425. { a mix of class, interfaces, objects and cppclasses
  426. isn't allowed }
  427. case current_objectdef.objecttype of
  428. odt_class:
  429. if not(is_class(childof)) then
  430. begin
  431. if is_interface(childof) then
  432. begin
  433. { we insert the interface after the child
  434. is set, see below
  435. }
  436. intfchildof:=childof;
  437. childof:=class_tobject;
  438. end
  439. else
  440. Message(parser_e_mix_of_classes_and_objects);
  441. end
  442. else
  443. if oo_is_sealed in childof.objectoptions then
  444. Message1(parser_e_sealed_descendant,childof.typename);
  445. odt_interfacecorba,
  446. odt_interfacecom:
  447. begin
  448. if not(is_interface(childof)) then
  449. Message(parser_e_mix_of_classes_and_objects);
  450. current_objectdef.objecttype:=childof.objecttype;
  451. end;
  452. odt_cppclass:
  453. if not(is_cppclass(childof)) then
  454. Message(parser_e_mix_of_classes_and_objects);
  455. odt_objcclass:
  456. if not(is_objcclass(childof) or
  457. is_objccategory(childof)) then
  458. begin
  459. if is_objcprotocol(childof) then
  460. begin
  461. if not(oo_is_classhelper in current_structdef.objectoptions) then
  462. begin
  463. intfchildof:=childof;
  464. childof:=nil;
  465. CGMessage(parser_h_no_objc_parent);
  466. end
  467. else
  468. { a category must specify the class to extend }
  469. CGMessage(type_e_objcclass_type_expected);
  470. end
  471. else
  472. Message(parser_e_mix_of_classes_and_objects);
  473. end
  474. else
  475. childof:=find_real_objcclass_definition(childof,true);
  476. odt_objcprotocol:
  477. begin
  478. if not(is_objcprotocol(childof)) then
  479. Message(parser_e_mix_of_classes_and_objects);
  480. intfchildof:=childof;
  481. childof:=nil;
  482. end;
  483. odt_object:
  484. if not(is_object(childof)) then
  485. Message(parser_e_mix_of_classes_and_objects)
  486. else
  487. if oo_is_sealed in childof.objectoptions then
  488. Message1(parser_e_sealed_descendant,childof.typename);
  489. odt_dispinterface:
  490. Message(parser_e_dispinterface_cant_have_parent);
  491. odt_helper:
  492. if not is_objectpascal_helper(childof) then
  493. begin
  494. Message(type_e_helper_type_expected);
  495. childof:=nil;
  496. end;
  497. end;
  498. end;
  499. hasparentdefined:=true;
  500. end;
  501. { if no parent class, then a class get tobject as parent }
  502. if not assigned(childof) then
  503. begin
  504. case current_objectdef.objecttype of
  505. odt_class:
  506. if current_objectdef<>class_tobject then
  507. childof:=class_tobject;
  508. odt_interfacecom:
  509. if current_objectdef<>interface_iunknown then
  510. childof:=interface_iunknown;
  511. odt_dispinterface:
  512. childof:=interface_idispatch;
  513. odt_objcclass:
  514. CGMessage(parser_h_no_objc_parent);
  515. end;
  516. end;
  517. if assigned(childof) then
  518. begin
  519. { Forbid not completly defined objects to be used as parents. This will
  520. also prevent circular loops of classes, because we set the forward flag
  521. at the start of the new definition and will reset it below after the
  522. parent has been set }
  523. if (oo_is_forward in childof.objectoptions) then
  524. Message1(parser_e_forward_declaration_must_be_resolved,childof.objrealname^)
  525. else if not(oo_is_formal in childof.objectoptions) then
  526. current_objectdef.set_parent(childof)
  527. else
  528. Message1(sym_e_objc_formal_class_not_resolved,childof.objrealname^);
  529. end;
  530. { remove forward flag, is resolved }
  531. exclude(current_structdef.objectoptions,oo_is_forward);
  532. if hasparentdefined then
  533. begin
  534. if current_objectdef.objecttype in [odt_class,odt_objcclass,odt_objcprotocol] then
  535. begin
  536. if assigned(intfchildof) then
  537. if current_objectdef.objecttype=odt_class then
  538. handleImplementedInterface(intfchildof)
  539. else
  540. handleImplementedProtocol(intfchildof);
  541. readImplementedInterfacesAndProtocols(current_objectdef.objecttype=odt_class);
  542. end;
  543. consume(_RKLAMMER);
  544. end;
  545. end;
  546. procedure parse_extended_type(helpertype:thelpertype);
  547. var
  548. hdef: tdef;
  549. begin
  550. if not is_objectpascal_helper(current_structdef) then
  551. Internalerror(2011021103);
  552. if helpertype=ht_none then
  553. Internalerror(2011021001);
  554. consume(_FOR);
  555. single_type(hdef,[stoParseClassParent]);
  556. if (not assigned(hdef)) or
  557. not (hdef.typ in [objectdef,recorddef]) then
  558. begin
  559. if helpertype=ht_class then
  560. Message1(type_e_class_type_expected,hdef.typename)
  561. else
  562. if helpertype=ht_record then
  563. Message1(type_e_record_type_expected,hdef.typename);
  564. end
  565. else
  566. begin
  567. case helpertype of
  568. ht_class:
  569. begin
  570. if not is_class(hdef) then
  571. Message1(type_e_class_type_expected,hdef.typename);
  572. { a class helper must extend the same class or a subclass
  573. of the class extended by the parent class helper }
  574. if assigned(current_objectdef.childof) then
  575. begin
  576. if not is_class(current_objectdef.childof.extendeddef) then
  577. Internalerror(2011021101);
  578. if not hdef.is_related(current_objectdef.childof.extendeddef) then
  579. Message1(type_e_class_helper_must_extend_subclass,current_objectdef.childof.extendeddef.typename);
  580. end;
  581. end;
  582. ht_record:
  583. begin
  584. if not is_record(hdef) then
  585. Message1(type_e_record_type_expected,hdef.typename);
  586. { a record helper must extend the same record as the
  587. parent helper }
  588. if assigned(current_objectdef.childof) then
  589. begin
  590. if not is_record(current_objectdef.childof.extendeddef) then
  591. Internalerror(2011021102);
  592. if hdef<>current_objectdef.childof.extendeddef then
  593. Message1(type_e_record_helper_must_extend_same_record,current_objectdef.childof.extendeddef.typename);
  594. end;
  595. end;
  596. else
  597. hdef:=nil;
  598. end;
  599. end;
  600. if assigned(hdef) then
  601. current_objectdef.extendeddef:=hdef
  602. else
  603. current_objectdef.extendeddef:=generrordef;
  604. end;
  605. procedure parse_guid;
  606. begin
  607. { read GUID }
  608. if (current_objectdef.objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) and
  609. try_to_consume(_LECKKLAMMER) then
  610. begin
  611. readinterfaceiid;
  612. consume(_RECKKLAMMER);
  613. end
  614. else if (current_objectdef.objecttype=odt_dispinterface) then
  615. message(parser_e_dispinterface_needs_a_guid);
  616. end;
  617. procedure parse_object_members;
  618. procedure chkobjc(pd: tprocdef);
  619. begin
  620. if is_objc_class_or_protocol(pd.struct) then
  621. begin
  622. include(pd.procoptions,po_objc);
  623. end;
  624. end;
  625. procedure chkcpp(pd:tprocdef);
  626. begin
  627. { nothing currently }
  628. end;
  629. procedure maybe_parse_hint_directives(pd:tprocdef);
  630. var
  631. dummysymoptions : tsymoptions;
  632. deprecatedmsg : pshortstring;
  633. begin
  634. dummysymoptions:=[];
  635. deprecatedmsg:=nil;
  636. while try_consume_hintdirective(dummysymoptions,deprecatedmsg) do
  637. Consume(_SEMICOLON);
  638. if assigned(pd) then
  639. begin
  640. pd.symoptions:=pd.symoptions+dummysymoptions;
  641. pd.deprecatedmsg:=deprecatedmsg;
  642. end
  643. else
  644. stringdispose(deprecatedmsg);
  645. end;
  646. var
  647. pd : tprocdef;
  648. has_destructor,
  649. oldparse_only: boolean;
  650. object_member_blocktype : tblock_type;
  651. fields_allowed, is_classdef, classfields: boolean;
  652. vdoptions: tvar_dec_options;
  653. begin
  654. { empty class declaration ? }
  655. if (current_objectdef.objecttype in [odt_class,odt_objcclass]) and
  656. (token=_SEMICOLON) then
  657. exit;
  658. { in "publishable" classes the default access type is published }
  659. if (oo_can_have_published in current_structdef.objectoptions) then
  660. current_structdef.symtable.currentvisibility:=vis_published
  661. else
  662. current_structdef.symtable.currentvisibility:=vis_public;
  663. has_destructor:=false;
  664. fields_allowed:=true;
  665. is_classdef:=false;
  666. classfields:=false;
  667. object_member_blocktype:=bt_general;
  668. repeat
  669. case token of
  670. _TYPE :
  671. begin
  672. if not(current_objectdef.objecttype in [odt_class,odt_object,odt_helper]) then
  673. Message(parser_e_type_var_const_only_in_records_and_classes);
  674. consume(_TYPE);
  675. object_member_blocktype:=bt_type;
  676. end;
  677. _VAR :
  678. begin
  679. if not(current_objectdef.objecttype in [odt_class,odt_object,odt_helper]) then
  680. Message(parser_e_type_var_const_only_in_records_and_classes);
  681. consume(_VAR);
  682. fields_allowed:=true;
  683. object_member_blocktype:=bt_general;
  684. classfields:=is_classdef;
  685. is_classdef:=false;
  686. end;
  687. _CONST:
  688. begin
  689. if not(current_objectdef.objecttype in [odt_class,odt_object,odt_helper]) then
  690. Message(parser_e_type_var_const_only_in_records_and_classes);
  691. consume(_CONST);
  692. object_member_blocktype:=bt_const;
  693. end;
  694. _ID :
  695. begin
  696. if is_objcprotocol(current_structdef) and
  697. ((idtoken=_REQUIRED) or
  698. (idtoken=_OPTIONAL)) then
  699. begin
  700. current_structdef.symtable.currentlyoptional:=(idtoken=_OPTIONAL);
  701. consume(idtoken)
  702. end
  703. else case idtoken of
  704. _PRIVATE :
  705. begin
  706. if is_interface(current_structdef) or
  707. is_objc_protocol_or_category(current_structdef) then
  708. Message(parser_e_no_access_specifier_in_interfaces);
  709. consume(_PRIVATE);
  710. current_structdef.symtable.currentvisibility:=vis_private;
  711. include(current_structdef.objectoptions,oo_has_private);
  712. fields_allowed:=true;
  713. is_classdef:=false;
  714. classfields:=false;
  715. object_member_blocktype:=bt_general;
  716. end;
  717. _PROTECTED :
  718. begin
  719. if is_interface(current_structdef) or
  720. is_objc_protocol_or_category(current_structdef) then
  721. Message(parser_e_no_access_specifier_in_interfaces);
  722. consume(_PROTECTED);
  723. current_structdef.symtable.currentvisibility:=vis_protected;
  724. include(current_structdef.objectoptions,oo_has_protected);
  725. fields_allowed:=true;
  726. is_classdef:=false;
  727. classfields:=false;
  728. object_member_blocktype:=bt_general;
  729. end;
  730. _PUBLIC :
  731. begin
  732. if is_interface(current_structdef) or
  733. is_objc_protocol_or_category(current_structdef) then
  734. Message(parser_e_no_access_specifier_in_interfaces);
  735. consume(_PUBLIC);
  736. current_structdef.symtable.currentvisibility:=vis_public;
  737. fields_allowed:=true;
  738. is_classdef:=false;
  739. classfields:=false;
  740. object_member_blocktype:=bt_general;
  741. end;
  742. _PUBLISHED :
  743. begin
  744. { we've to check for a pushlished section in non- }
  745. { publishable classes later, if a real declaration }
  746. { this is the way, delphi does it }
  747. if is_interface(current_structdef) then
  748. Message(parser_e_no_access_specifier_in_interfaces);
  749. { Objective-C classes do not support "published",
  750. as basically everything is published. }
  751. if is_objc_class_or_protocol(current_structdef) then
  752. Message(parser_e_no_objc_published);
  753. consume(_PUBLISHED);
  754. current_structdef.symtable.currentvisibility:=vis_published;
  755. fields_allowed:=true;
  756. is_classdef:=false;
  757. classfields:=false;
  758. object_member_blocktype:=bt_general;
  759. end;
  760. _STRICT :
  761. begin
  762. if is_interface(current_structdef) or
  763. is_objc_protocol_or_category(current_structdef) then
  764. Message(parser_e_no_access_specifier_in_interfaces);
  765. consume(_STRICT);
  766. if token=_ID then
  767. begin
  768. case idtoken of
  769. _PRIVATE:
  770. begin
  771. consume(_PRIVATE);
  772. current_structdef.symtable.currentvisibility:=vis_strictprivate;
  773. include(current_structdef.objectoptions,oo_has_strictprivate);
  774. end;
  775. _PROTECTED:
  776. begin
  777. consume(_PROTECTED);
  778. current_structdef.symtable.currentvisibility:=vis_strictprotected;
  779. include(current_structdef.objectoptions,oo_has_strictprotected);
  780. end;
  781. else
  782. message(parser_e_protected_or_private_expected);
  783. end;
  784. end
  785. else
  786. message(parser_e_protected_or_private_expected);
  787. fields_allowed:=true;
  788. is_classdef:=false;
  789. classfields:=false;
  790. object_member_blocktype:=bt_general;
  791. end
  792. else
  793. begin
  794. if object_member_blocktype=bt_general then
  795. begin
  796. if is_interface(current_structdef) or
  797. is_objc_protocol_or_category(current_structdef) or
  798. is_objectpascal_helper(current_structdef) then
  799. Message(parser_e_no_vars_in_interfaces);
  800. if (current_structdef.symtable.currentvisibility=vis_published) and
  801. not(oo_can_have_published in current_structdef.objectoptions) then
  802. Message(parser_e_cant_have_published);
  803. if (not fields_allowed) then
  804. Message(parser_e_field_not_allowed_here);
  805. vdoptions:=[vd_object];
  806. if classfields then
  807. include(vdoptions,vd_class);
  808. read_record_fields(vdoptions);
  809. end
  810. else if object_member_blocktype=bt_type then
  811. types_dec(true)
  812. else if object_member_blocktype=bt_const then
  813. consts_dec(true)
  814. else
  815. internalerror(201001110);
  816. end;
  817. end;
  818. end;
  819. _PROPERTY :
  820. begin
  821. struct_property_dec(is_classdef);
  822. fields_allowed:=false;
  823. is_classdef:=false;
  824. end;
  825. _CLASS:
  826. begin
  827. is_classdef:=false;
  828. { read class method/field/property }
  829. consume(_CLASS);
  830. { class modifier is only allowed for procedures, functions, }
  831. { constructors, destructors, fields and properties }
  832. if not(token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_CONSTRUCTOR,_DESTRUCTOR]) then
  833. Message(parser_e_procedure_or_function_expected);
  834. if is_interface(current_structdef) then
  835. Message(parser_e_no_static_method_in_interfaces)
  836. else
  837. { class methods are also allowed for Objective-C protocols }
  838. is_classdef:=true;
  839. end;
  840. _PROCEDURE,
  841. _FUNCTION:
  842. begin
  843. if (current_structdef.symtable.currentvisibility=vis_published) and
  844. not(oo_can_have_published in current_structdef.objectoptions) then
  845. Message(parser_e_cant_have_published);
  846. oldparse_only:=parse_only;
  847. parse_only:=true;
  848. pd:=parse_proc_dec(is_classdef,current_structdef);
  849. { this is for error recovery as well as forward }
  850. { interface mappings, i.e. mapping to a method }
  851. { which isn't declared yet }
  852. if assigned(pd) then
  853. begin
  854. parse_object_proc_directives(pd);
  855. { check if dispid is set }
  856. if is_dispinterface(pd.struct) and not (po_dispid in pd.procoptions) then
  857. begin
  858. pd.dispid:=tobjectdef(pd.struct).get_next_dispid;
  859. include(pd.procoptions, po_dispid);
  860. end;
  861. { all Macintosh Object Pascal methods are virtual. }
  862. { this can't be a class method, because macpas mode }
  863. { has no m_class }
  864. if (m_mac in current_settings.modeswitches) then
  865. include(pd.procoptions,po_virtualmethod);
  866. { for record helpers only static class methods are allowed }
  867. if is_objectpascal_helper(current_structdef) and
  868. is_record(current_objectdef.extendeddef) and
  869. is_classdef and not (po_staticmethod in pd.procoptions) then
  870. MessagePos(pd.fileinfo, parser_e_class_methods_only_static_in_records);
  871. handle_calling_convention(pd);
  872. { add definition to procsym }
  873. proc_add_definition(pd);
  874. { add procdef options to objectdef options }
  875. if (po_msgint in pd.procoptions) then
  876. include(current_structdef.objectoptions,oo_has_msgint);
  877. if (po_msgstr in pd.procoptions) then
  878. include(current_structdef.objectoptions,oo_has_msgstr);
  879. if (po_virtualmethod in pd.procoptions) then
  880. include(current_structdef.objectoptions,oo_has_virtual);
  881. chkcpp(pd);
  882. chkobjc(pd);
  883. end;
  884. maybe_parse_hint_directives(pd);
  885. parse_only:=oldparse_only;
  886. fields_allowed:=false;
  887. is_classdef:=false;
  888. end;
  889. _CONSTRUCTOR :
  890. begin
  891. if (current_structdef.symtable.currentvisibility=vis_published) and
  892. not(oo_can_have_published in current_structdef.objectoptions) then
  893. Message(parser_e_cant_have_published);
  894. if not is_classdef and not(current_structdef.symtable.currentvisibility in [vis_public,vis_published]) then
  895. Message(parser_w_constructor_should_be_public);
  896. if is_interface(current_structdef) then
  897. Message(parser_e_no_con_des_in_interfaces);
  898. { Objective-C does not know the concept of a constructor }
  899. if is_objc_class_or_protocol(current_structdef) then
  900. Message(parser_e_objc_no_constructor_destructor);
  901. if is_objectpascal_helper(current_structdef) then
  902. if is_classdef then
  903. { class constructors are not allowed in class helpers }
  904. Message(parser_e_no_class_constructor_in_helpers)
  905. else
  906. if is_record(current_objectdef.extendeddef) then
  907. { as long as constructors aren't allowed in records they
  908. aren't allowed in helpers either }
  909. Message(parser_e_no_constructor_in_records);
  910. { only 1 class constructor is allowed }
  911. if is_classdef and (oo_has_class_constructor in current_structdef.objectoptions) then
  912. Message1(parser_e_only_one_class_constructor_allowed, current_structdef.objrealname^);
  913. oldparse_only:=parse_only;
  914. parse_only:=true;
  915. if is_classdef then
  916. pd:=class_constructor_head
  917. else
  918. pd:=constructor_head;
  919. parse_object_proc_directives(pd);
  920. handle_calling_convention(pd);
  921. { add definition to procsym }
  922. proc_add_definition(pd);
  923. { add procdef options to objectdef options }
  924. if (po_virtualmethod in pd.procoptions) then
  925. include(current_structdef.objectoptions,oo_has_virtual);
  926. chkcpp(pd);
  927. maybe_parse_hint_directives(pd);
  928. parse_only:=oldparse_only;
  929. fields_allowed:=false;
  930. is_classdef:=false;
  931. end;
  932. _DESTRUCTOR :
  933. begin
  934. if (current_structdef.symtable.currentvisibility=vis_published) and
  935. not(oo_can_have_published in current_structdef.objectoptions) then
  936. Message(parser_e_cant_have_published);
  937. if not is_classdef then
  938. if has_destructor then
  939. Message(parser_n_only_one_destructor)
  940. else
  941. has_destructor:=true;
  942. if is_interface(current_structdef) then
  943. Message(parser_e_no_con_des_in_interfaces);
  944. { (class) destructors are not allowed in class helpers }
  945. if is_objectpascal_helper(current_structdef) then
  946. Message(parser_e_no_destructor_in_records);
  947. if not is_classdef and (current_structdef.symtable.currentvisibility<>vis_public) then
  948. Message(parser_w_destructor_should_be_public);
  949. { Objective-C does not know the concept of a destructor }
  950. if is_objc_class_or_protocol(current_structdef) then
  951. Message(parser_e_objc_no_constructor_destructor);
  952. { only 1 class destructor is allowed }
  953. if is_classdef and (oo_has_class_destructor in current_structdef.objectoptions) then
  954. Message1(parser_e_only_one_class_destructor_allowed, current_structdef.objrealname^);
  955. oldparse_only:=parse_only;
  956. parse_only:=true;
  957. if is_classdef then
  958. pd:=class_destructor_head
  959. else
  960. pd:=destructor_head;
  961. parse_object_proc_directives(pd);
  962. handle_calling_convention(pd);
  963. { add definition to procsym }
  964. proc_add_definition(pd);
  965. { add procdef options to objectdef options }
  966. if (po_virtualmethod in pd.procoptions) then
  967. include(current_structdef.objectoptions,oo_has_virtual);
  968. chkcpp(pd);
  969. maybe_parse_hint_directives(pd);
  970. parse_only:=oldparse_only;
  971. fields_allowed:=false;
  972. is_classdef:=false;
  973. end;
  974. _END :
  975. begin
  976. consume(_END);
  977. break;
  978. end;
  979. else
  980. consume(_ID); { Give a ident expected message, like tp7 }
  981. end;
  982. until false;
  983. end;
  984. function object_dec(objecttype:tobjecttyp;const n:tidstring;genericdef:tstoreddef;genericlist:TFPObjectList;fd : tobjectdef;helpertype:thelpertype) : tobjectdef;
  985. var
  986. old_current_structdef: tabstractrecorddef;
  987. old_current_genericdef,
  988. old_current_specializedef: tstoreddef;
  989. old_parse_generic: boolean;
  990. list: TFPObjectList;
  991. s: String;
  992. st: TSymtable;
  993. begin
  994. old_current_structdef:=current_structdef;
  995. old_current_genericdef:=current_genericdef;
  996. old_current_specializedef:=current_specializedef;
  997. old_parse_generic:=parse_generic;
  998. current_structdef:=nil;
  999. current_genericdef:=nil;
  1000. current_specializedef:=nil;
  1001. { objects and class types can't be declared local }
  1002. if not(symtablestack.top.symtabletype in [globalsymtable,staticsymtable,objectsymtable,recordsymtable]) and
  1003. not assigned(genericlist) then
  1004. Message(parser_e_no_local_objects);
  1005. { reuse forward objectdef? }
  1006. if assigned(fd) then
  1007. begin
  1008. if fd.objecttype<>objecttype then
  1009. begin
  1010. Message(parser_e_forward_mismatch);
  1011. { recover }
  1012. current_structdef:=tobjectdef.create(current_objectdef.objecttype,n,nil);
  1013. include(current_structdef.objectoptions,oo_is_forward);
  1014. end
  1015. else
  1016. current_structdef:=fd
  1017. end
  1018. else
  1019. begin
  1020. { anonym objects aren't allow (o : object a : longint; end;) }
  1021. if n='' then
  1022. Message(parser_f_no_anonym_objects);
  1023. { create new class }
  1024. current_structdef:=tobjectdef.create(objecttype,n,nil);
  1025. { include always the forward flag, it'll be removed after the parent class have been
  1026. added. This is to prevent circular childof loops }
  1027. include(current_structdef.objectoptions,oo_is_forward);
  1028. if (cs_compilesystem in current_settings.moduleswitches) then
  1029. begin
  1030. case current_objectdef.objecttype of
  1031. odt_interfacecom :
  1032. if (current_structdef.objname^='IUNKNOWN') then
  1033. interface_iunknown:=current_objectdef
  1034. else
  1035. if (current_structdef.objname^='IDISPATCH') then
  1036. interface_idispatch:=current_objectdef;
  1037. odt_class :
  1038. if (current_structdef.objname^='TOBJECT') then
  1039. class_tobject:=current_objectdef;
  1040. end;
  1041. end;
  1042. if (current_module.modulename^='OBJCBASE') then
  1043. begin
  1044. case current_objectdef.objecttype of
  1045. odt_objcclass:
  1046. if (current_objectdef.objname^='Protocol') then
  1047. objc_protocoltype:=current_objectdef;
  1048. end;
  1049. end;
  1050. end;
  1051. { usage of specialized type inside its generic template }
  1052. if assigned(genericdef) then
  1053. current_specializedef:=current_structdef
  1054. { reject declaration of generic class inside generic class }
  1055. else if assigned(genericlist) then
  1056. current_genericdef:=current_structdef;
  1057. { set published flag in $M+ mode, it can also be inherited and will
  1058. be added when the parent class set with tobjectdef.set_parent (PFV) }
  1059. if (cs_generate_rtti in current_settings.localswitches) and
  1060. (current_objectdef.objecttype in [odt_interfacecom,odt_class,odt_helper]) then
  1061. include(current_structdef.objectoptions,oo_can_have_published);
  1062. { Objective-C objectdefs can be "formal definitions", in which case
  1063. the syntax is "type tc = objcclass external;" -> we have to parse
  1064. its object options (external) already here, to make sure that such
  1065. definitions are recognised as formal defs }
  1066. if objecttype in [odt_objcclass,odt_objcprotocol,odt_objccategory] then
  1067. parse_object_options;
  1068. { forward def? }
  1069. if not assigned(fd) and
  1070. (token=_SEMICOLON) then
  1071. begin
  1072. { add to the list of definitions to check that the forward
  1073. is resolved. this is required for delphi mode }
  1074. current_module.checkforwarddefs.add(current_structdef);
  1075. end
  1076. else
  1077. begin
  1078. { change objccategories into objcclass helpers }
  1079. if (objecttype=odt_objccategory) then
  1080. begin
  1081. current_objectdef.objecttype:=odt_objcclass;
  1082. include(current_structdef.objectoptions,oo_is_classhelper);
  1083. end;
  1084. { include the class helper flag for Object Pascal helpers }
  1085. if (objecttype=odt_helper) then
  1086. include(current_objectdef.objectoptions,oo_is_classhelper);
  1087. { parse list of options (abstract / sealed) }
  1088. if not(objecttype in [odt_objcclass,odt_objcprotocol,odt_objccategory]) then
  1089. parse_object_options;
  1090. symtablestack.push(current_structdef.symtable);
  1091. insert_generic_parameter_types(current_structdef,genericdef,genericlist);
  1092. parse_generic:=(df_generic in current_structdef.defoptions);
  1093. { parse list of parent classes }
  1094. { for record helpers in mode Delphi this is not allowed }
  1095. if not (is_objectpascal_helper(current_objectdef) and
  1096. (m_delphi in current_settings.modeswitches) and
  1097. (helpertype=ht_record)) then
  1098. parse_parent_classes
  1099. else
  1100. { remove forward flag, is resolved (this is normally done inside
  1101. parse_parent_classes) }
  1102. exclude(current_structdef.objectoptions,oo_is_forward);
  1103. { parse extended type for helpers }
  1104. if is_objectpascal_helper(current_structdef) then
  1105. parse_extended_type(helpertype);
  1106. { parse optional GUID for interfaces }
  1107. parse_guid;
  1108. { parse and insert object members }
  1109. parse_object_members;
  1110. symtablestack.pop(current_structdef.symtable);
  1111. end;
  1112. { generate vmt space if needed }
  1113. if not(oo_has_vmt in current_structdef.objectoptions) and
  1114. not(oo_is_forward in current_structdef.objectoptions) and
  1115. (
  1116. ([oo_has_virtual,oo_has_constructor,oo_has_destructor]*current_structdef.objectoptions<>[]) or
  1117. (current_objectdef.objecttype in [odt_class])
  1118. ) then
  1119. current_objectdef.insertvmt;
  1120. { for implemented classes with a vmt check if there is a constructor }
  1121. if (oo_has_vmt in current_structdef.objectoptions) and
  1122. not(oo_is_forward in current_structdef.objectoptions) and
  1123. not(oo_has_constructor in current_structdef.objectoptions) and
  1124. not is_objc_class_or_protocol(current_structdef) then
  1125. Message1(parser_w_virtual_without_constructor,current_structdef.objrealname^);
  1126. if is_interface(current_structdef) or
  1127. is_objcprotocol(current_structdef) then
  1128. setinterfacemethodoptions
  1129. else if is_objcclass(current_structdef) then
  1130. setobjcclassmethodoptions;
  1131. { if this helper is defined in the implementation section of the unit
  1132. or inside the main project file, the extendeddefs list of the current
  1133. module must be updated (it will be removed when poping the symtable) }
  1134. if is_objectpascal_helper(current_structdef) and
  1135. (current_objectdef.extendeddef.typ in [recorddef,objectdef]) then
  1136. begin
  1137. { the topmost symtable must be a static symtable }
  1138. st:=current_structdef.owner;
  1139. while st.symtabletype in [objectsymtable,recordsymtable] do
  1140. st:=st.defowner.owner;
  1141. if st.symtabletype=staticsymtable then
  1142. begin
  1143. s:=make_mangledname('',tabstractrecorddef(current_objectdef.extendeddef).symtable,'');
  1144. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1145. if not assigned(list) then
  1146. begin
  1147. list:=TFPObjectList.Create(false);
  1148. current_module.extendeddefs.Add(s, list);
  1149. end;
  1150. list.add(current_structdef);
  1151. end;
  1152. end;
  1153. tabstractrecordsymtable(current_objectdef.symtable).addalignmentpadding;
  1154. { return defined objectdef }
  1155. result:=current_objectdef;
  1156. { restore old state }
  1157. current_structdef:=old_current_structdef;
  1158. current_genericdef:=old_current_genericdef;
  1159. current_specializedef:=old_current_specializedef;
  1160. parse_generic:=old_parse_generic;
  1161. end;
  1162. end.