pdecobj.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. globtype,symtype,symdef;
  22. { parses a object declaration }
  23. function object_dec(const n : stringid;fd : tobjectdef) : tdef;
  24. implementation
  25. uses
  26. cutils,cclasses,
  27. globals,verbose,systems,tokens,
  28. symconst,symbase,symsym,
  29. node,nld,nmem,ncon,ncnv,ncal,
  30. scanner,
  31. pbase,pexpr,pdecsub,pdecvar,ptype
  32. ;
  33. const
  34. { Please leave this here, this module should NOT use
  35. these variables.
  36. Declaring it as string here results in an error when compiling (PFV) }
  37. current_procinfo = 'error';
  38. function object_dec(const n : stringid;fd : tobjectdef) : tdef;
  39. { this function parses an object or class declaration }
  40. var
  41. there_is_a_destructor : boolean;
  42. classtype : tobjectdeftype;
  43. // childof : tobjectdef;
  44. function constructor_head:tprocdef;
  45. var
  46. pd : tprocdef;
  47. begin
  48. consume(_CONSTRUCTOR);
  49. { must be at same level as in implementation }
  50. parse_proc_head(aktobjectdef,potype_constructor,pd);
  51. if not assigned(pd) then
  52. begin
  53. consume(_SEMICOLON);
  54. exit;
  55. end;
  56. if (cs_constructor_name in aktglobalswitches) and
  57. (pd.procsym.name<>'INIT') then
  58. Message(parser_e_constructorname_must_be_init);
  59. consume(_SEMICOLON);
  60. include(aktobjectdef.objectoptions,oo_has_constructor);
  61. { Set return type, class constructors return the
  62. created instance, object constructors return boolean }
  63. if is_class(pd._class) then
  64. pd.rettype.setdef(pd._class)
  65. else
  66. pd.rettype:=booltype;
  67. constructor_head:=pd;
  68. end;
  69. procedure property_dec;
  70. var
  71. p : tpropertysym;
  72. begin
  73. { check for a class }
  74. if not((is_class_or_interface(aktobjectdef)) or
  75. (not(m_tp7 in aktmodeswitches) and (is_object(aktobjectdef)))) then
  76. Message(parser_e_syntax_error);
  77. consume(_PROPERTY);
  78. p:=read_property_dec(aktobjectdef);
  79. consume(_SEMICOLON);
  80. if try_to_consume(_DEFAULT) then
  81. begin
  82. if oo_has_default_property in aktobjectdef.objectoptions then
  83. message(parser_e_only_one_default_property);
  84. include(aktobjectdef.objectoptions,oo_has_default_property);
  85. include(p.propoptions,ppo_defaultproperty);
  86. if not(ppo_hasparameters in p.propoptions) then
  87. message(parser_e_property_need_paras);
  88. consume(_SEMICOLON);
  89. end;
  90. { hint directives, these can be separated by semicolons here,
  91. that needs to be handled here with a loop (PFV) }
  92. while try_consume_hintdirective(p.symoptions) do
  93. Consume(_SEMICOLON);
  94. end;
  95. function destructor_head:tprocdef;
  96. var
  97. pd : tprocdef;
  98. begin
  99. consume(_DESTRUCTOR);
  100. parse_proc_head(aktobjectdef,potype_destructor,pd);
  101. if not assigned(pd) then
  102. begin
  103. consume(_SEMICOLON);
  104. exit;
  105. end;
  106. if (cs_constructor_name in aktglobalswitches) and
  107. (pd.procsym.name<>'DONE') then
  108. Message(parser_e_destructorname_must_be_done);
  109. if not(pd.maxparacount=0) and
  110. (m_fpc in aktmodeswitches) then
  111. Message(parser_e_no_paras_for_destructor);
  112. consume(_SEMICOLON);
  113. include(aktobjectdef.objectoptions,oo_has_destructor);
  114. { no return value }
  115. pd.rettype:=voidtype;
  116. destructor_head:=pd;
  117. end;
  118. var
  119. pcrd : tclassrefdef;
  120. tt : ttype;
  121. old_object_option : tsymoptions;
  122. oldparse_only : boolean;
  123. storetypecanbeforward : boolean;
  124. procedure setclassattributes;
  125. begin
  126. { publishable }
  127. if classtype in [odt_interfacecom,odt_class] then
  128. begin
  129. aktobjectdef.objecttype:=classtype;
  130. { set published flag in $M+ mode or it is inherited }
  131. if (cs_generate_rtti in aktlocalswitches) or
  132. (assigned(aktobjectdef.childof) and
  133. (oo_can_have_published in aktobjectdef.childof.objectoptions)) then
  134. include(aktobjectdef.objectoptions,oo_can_have_published);
  135. { in "publishable" classes the default access type is published, this is
  136. done separate from above if-statement because the option can be
  137. inherited from the forward class definition }
  138. if (oo_can_have_published in aktobjectdef.objectoptions) then
  139. current_object_option:=[sp_published];
  140. end;
  141. end;
  142. procedure setinterfacemethodoptions;
  143. var
  144. i: longint;
  145. defs: TIndexArray;
  146. pd: tdef;
  147. begin
  148. include(aktobjectdef.objectoptions,oo_has_virtual);
  149. defs:=aktobjectdef.symtable.defindex;
  150. for i:=1 to defs.count do
  151. begin
  152. pd:=tdef(defs.search(i));
  153. if pd.deftype=procdef then
  154. begin
  155. tprocdef(pd).extnumber:=aktobjectdef.lastvtableindex;
  156. inc(aktobjectdef.lastvtableindex);
  157. include(tprocdef(pd).procoptions,po_virtualmethod);
  158. tprocdef(pd).forwarddef:=false;
  159. end;
  160. end;
  161. end;
  162. function readobjecttype : boolean;
  163. begin
  164. readobjecttype:=true;
  165. { distinguish classes and objects }
  166. case token of
  167. _OBJECT:
  168. begin
  169. classtype:=odt_object;
  170. consume(_OBJECT)
  171. end;
  172. _CPPCLASS:
  173. begin
  174. classtype:=odt_cppclass;
  175. consume(_CPPCLASS);
  176. end;
  177. _INTERFACE:
  178. begin
  179. { need extra check here since interface is a keyword
  180. in all pascal modes }
  181. if not(m_class in aktmodeswitches) then
  182. Message(parser_f_need_objfpc_or_delphi_mode);
  183. if aktinterfacetype=it_interfacecom then
  184. classtype:=odt_interfacecom
  185. else {it_interfacecorba}
  186. classtype:=odt_interfacecorba;
  187. consume(_INTERFACE);
  188. { forward declaration }
  189. if not(assigned(fd)) and (token=_SEMICOLON) then
  190. begin
  191. { also anonym objects aren't allow (o : object a : longint; end;) }
  192. if n='' then
  193. Message(parser_f_no_anonym_objects);
  194. aktobjectdef:=tobjectdef.create(classtype,n,nil);
  195. if (cs_compilesystem in aktmoduleswitches) and
  196. (classtype=odt_interfacecom) and (upper(n)='IUNKNOWN') then
  197. interface_iunknown:=aktobjectdef;
  198. include(aktobjectdef.objectoptions,oo_is_forward);
  199. if (cs_generate_rtti in aktlocalswitches) and
  200. (classtype=odt_interfacecom) then
  201. include(aktobjectdef.objectoptions,oo_can_have_published);
  202. object_dec:=aktobjectdef;
  203. typecanbeforward:=storetypecanbeforward;
  204. readobjecttype:=false;
  205. exit;
  206. end;
  207. end;
  208. _CLASS:
  209. begin
  210. classtype:=odt_class;
  211. consume(_CLASS);
  212. if not(assigned(fd)) and
  213. (token=_OF) and
  214. { Delphi only allows class of in type blocks.
  215. Note that when parsing the type of a variable declaration
  216. the blocktype is bt_type so the check for typecanbeforward
  217. is also necessary (PFV) }
  218. (((block_type=bt_type) and typecanbeforward) or
  219. not(m_delphi in aktmodeswitches)) then
  220. begin
  221. { a hack, but it's easy to handle }
  222. { class reference type }
  223. consume(_OF);
  224. single_type(tt,typecanbeforward);
  225. { accept hp1, if is a forward def or a class }
  226. if (tt.def.deftype=forwarddef) or
  227. is_class(tt.def) then
  228. begin
  229. pcrd:=tclassrefdef.create(tt);
  230. object_dec:=pcrd;
  231. end
  232. else
  233. begin
  234. object_dec:=generrortype.def;
  235. Message1(type_e_class_type_expected,generrortype.def.typename);
  236. end;
  237. typecanbeforward:=storetypecanbeforward;
  238. readobjecttype:=false;
  239. exit;
  240. end
  241. { forward class }
  242. else if not(assigned(fd)) and (token=_SEMICOLON) then
  243. begin
  244. { also anonym objects aren't allow (o : object a : longint; end;) }
  245. if n='' then
  246. Message(parser_f_no_anonym_objects);
  247. aktobjectdef:=tobjectdef.create(odt_class,n,nil);
  248. if (cs_compilesystem in aktmoduleswitches) and (upper(n)='TOBJECT') then
  249. class_tobject:=aktobjectdef;
  250. aktobjectdef.objecttype:=odt_class;
  251. include(aktobjectdef.objectoptions,oo_is_forward);
  252. if (cs_generate_rtti in aktlocalswitches) then
  253. include(aktobjectdef.objectoptions,oo_can_have_published);
  254. { all classes must have a vmt !! at offset zero }
  255. if not(oo_has_vmt in aktobjectdef.objectoptions) then
  256. aktobjectdef.insertvmt;
  257. object_dec:=aktobjectdef;
  258. typecanbeforward:=storetypecanbeforward;
  259. readobjecttype:=false;
  260. exit;
  261. end;
  262. end;
  263. else
  264. begin
  265. classtype:=odt_class; { this is error but try to recover }
  266. consume(_OBJECT);
  267. end;
  268. end;
  269. end;
  270. procedure handleimplementedinterface(implintf : tobjectdef);
  271. begin
  272. if not is_interface(implintf) then
  273. begin
  274. Message1(type_e_interface_type_expected,implintf.typename);
  275. exit;
  276. end;
  277. if aktobjectdef.implementedinterfaces.searchintf(implintf)<>-1 then
  278. Message1(sym_e_duplicate_id,implintf.name)
  279. else
  280. begin
  281. { allocate and prepare the GUID only if the class
  282. implements some interfaces.
  283. }
  284. if aktobjectdef.implementedinterfaces.count = 0 then
  285. aktobjectdef.prepareguid;
  286. aktobjectdef.implementedinterfaces.addintf(implintf);
  287. end;
  288. end;
  289. procedure readimplementedinterfaces;
  290. var
  291. tt : ttype;
  292. begin
  293. while try_to_consume(_COMMA) do
  294. begin
  295. id_type(tt,false);
  296. if (tt.def.deftype<>objectdef) then
  297. begin
  298. Message1(type_e_interface_type_expected,tt.def.typename);
  299. continue;
  300. end;
  301. handleimplementedinterface(tobjectdef(tt.def));
  302. end;
  303. end;
  304. procedure readinterfaceiid;
  305. var
  306. p : tnode;
  307. valid : boolean;
  308. begin
  309. p:=comp_expr(true);
  310. if p.nodetype=stringconstn then
  311. begin
  312. stringdispose(aktobjectdef.iidstr);
  313. aktobjectdef.iidstr:=stringdup(strpas(tstringconstnode(p).value_str)); { or upper? }
  314. p.free;
  315. valid:=string2guid(aktobjectdef.iidstr^,aktobjectdef.iidguid^);
  316. if (classtype=odt_interfacecom) and not assigned(aktobjectdef.iidguid) and not valid then
  317. Message(parser_e_improper_guid_syntax);
  318. end
  319. else
  320. begin
  321. p.free;
  322. Message(parser_e_illegal_expression);
  323. end;
  324. end;
  325. procedure readparentclasses;
  326. var
  327. intfchildof,
  328. childof : tobjectdef;
  329. tt : ttype;
  330. hasparentdefined : boolean;
  331. begin
  332. childof:=nil;
  333. intfchildof:=nil;
  334. hasparentdefined:=false;
  335. { reads the parent class }
  336. if try_to_consume(_LKLAMMER) then
  337. begin
  338. id_type(tt,false);
  339. if (not assigned(tt.def)) or
  340. (tt.def.deftype<>objectdef) then
  341. begin
  342. if assigned(tt.def) then
  343. Message1(type_e_class_type_expected,tt.def.typename);
  344. end
  345. else
  346. begin
  347. childof:=tobjectdef(tt.def);
  348. { a mix of class, interfaces, objects and cppclasses
  349. isn't allowed }
  350. case classtype of
  351. odt_class:
  352. if not(is_class(childof)) then
  353. begin
  354. if is_interface(childof) then
  355. begin
  356. { we insert the interface after the child
  357. is set, see below
  358. }
  359. intfchildof:=childof;
  360. childof:=class_tobject;
  361. end
  362. else
  363. Message(parser_e_mix_of_classes_and_objects);
  364. end;
  365. odt_interfacecorba,
  366. odt_interfacecom:
  367. if not(is_interface(childof)) then
  368. Message(parser_e_mix_of_classes_and_objects);
  369. odt_cppclass:
  370. if not(is_cppclass(childof)) then
  371. Message(parser_e_mix_of_classes_and_objects);
  372. odt_object:
  373. if not(is_object(childof)) then
  374. Message(parser_e_mix_of_classes_and_objects);
  375. end;
  376. end;
  377. hasparentdefined:=true;
  378. end;
  379. { if no parent class, then a class get tobject as parent }
  380. if not assigned(childof) then
  381. begin
  382. case classtype of
  383. odt_class:
  384. if aktobjectdef<>class_tobject then
  385. childof:=class_tobject;
  386. odt_interfacecom:
  387. if aktobjectdef<>interface_iunknown then
  388. childof:=interface_iunknown;
  389. end;
  390. end;
  391. if assigned(childof) then
  392. begin
  393. { Forbid not completly defined objects to be used as parents. This will
  394. also prevent circular loops of classes, because we set the forward flag
  395. at the start of the new definition and will reset it below after the
  396. parent has been set }
  397. if not(oo_is_forward in childof.objectoptions) then
  398. aktobjectdef.set_parent(childof)
  399. else
  400. Message1(parser_e_forward_declaration_must_be_resolved,childof.objrealname^);
  401. end;
  402. { remove forward flag, is resolved }
  403. exclude(aktobjectdef.objectoptions,oo_is_forward);
  404. if hasparentdefined then
  405. begin
  406. if aktobjectdef.objecttype=odt_class then
  407. begin
  408. if assigned(intfchildof) then
  409. handleimplementedinterface(intfchildof);
  410. readimplementedinterfaces;
  411. end;
  412. consume(_RKLAMMER);
  413. end;
  414. { read GUID }
  415. if (classtype in [odt_interfacecom,odt_interfacecorba]) and
  416. try_to_consume(_LECKKLAMMER) then
  417. begin
  418. readinterfaceiid;
  419. consume(_RECKKLAMMER);
  420. end;
  421. end;
  422. procedure chkcpp(pd:tprocdef);
  423. begin
  424. if is_cppclass(pd._class) then
  425. begin
  426. pd.proccalloption:=pocall_cppdecl;
  427. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  428. end;
  429. end;
  430. var
  431. pd : tprocdef;
  432. dummysymoptions : tsymoptions;
  433. begin
  434. old_object_option:=current_object_option;
  435. { objects and class types can't be declared local }
  436. if not(symtablestack.symtabletype in [globalsymtable,staticsymtable]) then
  437. Message(parser_e_no_local_objects);
  438. storetypecanbeforward:=typecanbeforward;
  439. { for tp7 don't allow forward types }
  440. if (m_tp7 in aktmodeswitches) then
  441. typecanbeforward:=false;
  442. if not(readobjecttype) then
  443. exit;
  444. if assigned(fd) then
  445. aktobjectdef:=fd
  446. else
  447. begin
  448. { anonym objects aren't allow (o : object a : longint; end;) }
  449. if n='' then
  450. Message(parser_f_no_anonym_objects);
  451. aktobjectdef:=tobjectdef.create(classtype,n,nil);
  452. { include forward flag, it'll be removed after the parent class have been
  453. added. This is to prevent circular childof loops }
  454. include(aktobjectdef.objectoptions,oo_is_forward);
  455. end;
  456. { read list of parent classes }
  457. readparentclasses;
  458. { default access is public }
  459. there_is_a_destructor:=false;
  460. current_object_option:=[sp_public];
  461. { set class flags and inherits published }
  462. setclassattributes;
  463. aktobjectdef.symtable.next:=symtablestack;
  464. symtablestack:=aktobjectdef.symtable;
  465. testcurobject:=1;
  466. { short class declaration ? }
  467. if (classtype<>odt_class) or (token<>_SEMICOLON) then
  468. begin
  469. { Parse componenten }
  470. repeat
  471. case token of
  472. _ID :
  473. begin
  474. case idtoken of
  475. _PRIVATE :
  476. begin
  477. if is_interface(aktobjectdef) then
  478. Message(parser_e_no_access_specifier_in_interfaces);
  479. consume(_PRIVATE);
  480. current_object_option:=[sp_private];
  481. include(aktobjectdef.objectoptions,oo_has_private);
  482. end;
  483. _PROTECTED :
  484. begin
  485. if is_interface(aktobjectdef) then
  486. Message(parser_e_no_access_specifier_in_interfaces);
  487. consume(_PROTECTED);
  488. current_object_option:=[sp_protected];
  489. include(aktobjectdef.objectoptions,oo_has_protected);
  490. end;
  491. _PUBLIC :
  492. begin
  493. if is_interface(aktobjectdef) then
  494. Message(parser_e_no_access_specifier_in_interfaces);
  495. consume(_PUBLIC);
  496. current_object_option:=[sp_public];
  497. end;
  498. _PUBLISHED :
  499. begin
  500. { we've to check for a pushlished section in non- }
  501. { publishable classes later, if a real declaration }
  502. { this is the way, delphi does it }
  503. if is_interface(aktobjectdef) then
  504. Message(parser_e_no_access_specifier_in_interfaces);
  505. consume(_PUBLISHED);
  506. current_object_option:=[sp_published];
  507. end;
  508. _STRICT :
  509. begin
  510. if is_interface(aktobjectdef) then
  511. Message(parser_e_no_access_specifier_in_interfaces);
  512. consume(_STRICT);
  513. if token=_ID then
  514. begin
  515. case idtoken of
  516. _PRIVATE:
  517. begin
  518. consume(_PRIVATE);
  519. current_object_option:=[sp_strictprivate];
  520. include(aktobjectdef.objectoptions,oo_has_strictprivate);
  521. end;
  522. _PROTECTED:
  523. begin
  524. consume(_PROTECTED);
  525. current_object_option:=[sp_strictprotected];
  526. include(aktobjectdef.objectoptions,oo_has_strictprotected);
  527. end;
  528. else
  529. message(parser_e_protected_or_private_expected);
  530. end;
  531. end
  532. else
  533. message(parser_e_protected_or_private_expected);
  534. end;
  535. else
  536. begin
  537. if is_interface(aktobjectdef) then
  538. Message(parser_e_no_vars_in_interfaces);
  539. if (sp_published in current_object_option) and
  540. not(oo_can_have_published in aktobjectdef.objectoptions) then
  541. Message(parser_e_cant_have_published);
  542. read_var_decs(false,true,false);
  543. end;
  544. end;
  545. end;
  546. _PROPERTY :
  547. begin
  548. property_dec;
  549. end;
  550. _PROCEDURE,
  551. _FUNCTION,
  552. _CLASS :
  553. begin
  554. if (sp_published in current_object_option) and
  555. not(oo_can_have_published in aktobjectdef.objectoptions) then
  556. Message(parser_e_cant_have_published);
  557. oldparse_only:=parse_only;
  558. parse_only:=true;
  559. pd:=parse_proc_dec(aktobjectdef);
  560. { this is for error recovery as well as forward }
  561. { interface mappings, i.e. mapping to a method }
  562. { which isn't declared yet }
  563. if assigned(pd) then
  564. begin
  565. parse_object_proc_directives(pd);
  566. { all Macintosh Object Pascal methods are virtual. }
  567. { this can't be a class method, because macpas mode }
  568. { has no m_class }
  569. if (m_mac in aktmodeswitches) then
  570. include(pd.procoptions,po_virtualmethod);
  571. handle_calling_convention(pd);
  572. { add definition to procsym }
  573. proc_add_definition(pd);
  574. { add procdef options to objectdef options }
  575. if (po_msgint in pd.procoptions) then
  576. include(aktobjectdef.objectoptions,oo_has_msgint);
  577. if (po_msgstr in pd.procoptions) then
  578. include(aktobjectdef.objectoptions,oo_has_msgstr);
  579. if (po_virtualmethod in pd.procoptions) then
  580. include(aktobjectdef.objectoptions,oo_has_virtual);
  581. chkcpp(pd);
  582. end;
  583. { Support hint directives }
  584. dummysymoptions:=[];
  585. while try_consume_hintdirective(dummysymoptions) do
  586. Consume(_SEMICOLON);
  587. if assigned(pd) then
  588. pd.symoptions:=pd.symoptions+dummysymoptions;
  589. parse_only:=oldparse_only;
  590. end;
  591. _CONSTRUCTOR :
  592. begin
  593. if (sp_published in current_object_option) and
  594. not(oo_can_have_published in aktobjectdef.objectoptions) then
  595. Message(parser_e_cant_have_published);
  596. if not(sp_public in current_object_option) and
  597. not(sp_published in current_object_option) then
  598. Message(parser_w_constructor_should_be_public);
  599. if is_interface(aktobjectdef) then
  600. Message(parser_e_no_con_des_in_interfaces);
  601. oldparse_only:=parse_only;
  602. parse_only:=true;
  603. pd:=constructor_head;
  604. parse_object_proc_directives(pd);
  605. handle_calling_convention(pd);
  606. { add definition to procsym }
  607. proc_add_definition(pd);
  608. { add procdef options to objectdef options }
  609. if (po_virtualmethod in pd.procoptions) then
  610. include(aktobjectdef.objectoptions,oo_has_virtual);
  611. chkcpp(pd);
  612. { Support hint directives }
  613. dummysymoptions:=[];
  614. while try_consume_hintdirective(dummysymoptions) do
  615. Consume(_SEMICOLON);
  616. if assigned(pd) then
  617. pd.symoptions:=pd.symoptions+dummysymoptions;
  618. parse_only:=oldparse_only;
  619. end;
  620. _DESTRUCTOR :
  621. begin
  622. if (sp_published in current_object_option) and
  623. not(oo_can_have_published in aktobjectdef.objectoptions) then
  624. Message(parser_e_cant_have_published);
  625. if there_is_a_destructor then
  626. Message(parser_n_only_one_destructor);
  627. if is_interface(aktobjectdef) then
  628. Message(parser_e_no_con_des_in_interfaces);
  629. if not(sp_public in current_object_option) then
  630. Message(parser_w_destructor_should_be_public);
  631. there_is_a_destructor:=true;
  632. oldparse_only:=parse_only;
  633. parse_only:=true;
  634. pd:=destructor_head;
  635. parse_object_proc_directives(pd);
  636. handle_calling_convention(pd);
  637. { add definition to procsym }
  638. proc_add_definition(pd);
  639. { add procdef options to objectdef options }
  640. if (po_virtualmethod in pd.procoptions) then
  641. include(aktobjectdef.objectoptions,oo_has_virtual);
  642. chkcpp(pd);
  643. { Support hint directives }
  644. dummysymoptions:=[];
  645. while try_consume_hintdirective(dummysymoptions) do
  646. Consume(_SEMICOLON);
  647. if assigned(pd) then
  648. pd.symoptions:=pd.symoptions+dummysymoptions;
  649. parse_only:=oldparse_only;
  650. end;
  651. _END :
  652. begin
  653. consume(_END);
  654. break;
  655. end;
  656. else
  657. consume(_ID); { Give a ident expected message, like tp7 }
  658. end;
  659. until false;
  660. end;
  661. { generate vmt space if needed }
  662. if not(oo_has_vmt in aktobjectdef.objectoptions) and
  663. (([oo_has_virtual,oo_has_constructor,oo_has_destructor]*aktobjectdef.objectoptions<>[]) or
  664. (classtype in [odt_class])
  665. ) then
  666. aktobjectdef.insertvmt;
  667. if is_interface(aktobjectdef) then
  668. setinterfacemethodoptions;
  669. { return defined objectdef }
  670. result:=aktobjectdef;
  671. { restore old state }
  672. aktobjectdef:=nil;
  673. testcurobject:=0;
  674. typecanbeforward:=storetypecanbeforward;
  675. symtablestack:=symtablestack.next;
  676. current_object_option:=old_object_option;
  677. end;
  678. end.