pdecobj.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. _DISPINTERFACE:
  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. classtype:=odt_dispinterface;
  184. consume(_DISPINTERFACE);
  185. { no forward declaration }
  186. if not(assigned(fd)) and (token=_SEMICOLON) then
  187. begin
  188. { also anonym objects aren't allow (o : object a : longint; end;) }
  189. if n='' then
  190. Message(parser_f_no_anonym_objects);
  191. aktobjectdef:=tobjectdef.create(classtype,n,nil);
  192. include(aktobjectdef.objectoptions,oo_is_forward);
  193. object_dec:=aktobjectdef;
  194. typecanbeforward:=storetypecanbeforward;
  195. readobjecttype:=false;
  196. exit;
  197. end;
  198. end;
  199. _INTERFACE:
  200. begin
  201. { need extra check here since interface is a keyword
  202. in all pascal modes }
  203. if not(m_class in aktmodeswitches) then
  204. Message(parser_f_need_objfpc_or_delphi_mode);
  205. if aktinterfacetype=it_interfacecom then
  206. classtype:=odt_interfacecom
  207. else {it_interfacecorba}
  208. classtype:=odt_interfacecorba;
  209. consume(_INTERFACE);
  210. { forward declaration }
  211. if not(assigned(fd)) and (token=_SEMICOLON) then
  212. begin
  213. { also anonym objects aren't allow (o : object a : longint; end;) }
  214. if n='' then
  215. Message(parser_f_no_anonym_objects);
  216. aktobjectdef:=tobjectdef.create(classtype,n,nil);
  217. if (cs_compilesystem in aktmoduleswitches) and
  218. (classtype=odt_interfacecom) and (upper(n)='IUNKNOWN') then
  219. interface_iunknown:=aktobjectdef;
  220. include(aktobjectdef.objectoptions,oo_is_forward);
  221. if (cs_generate_rtti in aktlocalswitches) and
  222. (classtype=odt_interfacecom) then
  223. include(aktobjectdef.objectoptions,oo_can_have_published);
  224. object_dec:=aktobjectdef;
  225. typecanbeforward:=storetypecanbeforward;
  226. readobjecttype:=false;
  227. exit;
  228. end;
  229. end;
  230. _CLASS:
  231. begin
  232. classtype:=odt_class;
  233. consume(_CLASS);
  234. if not(assigned(fd)) and
  235. (token=_OF) and
  236. { Delphi only allows class of in type blocks.
  237. Note that when parsing the type of a variable declaration
  238. the blocktype is bt_type so the check for typecanbeforward
  239. is also necessary (PFV) }
  240. (((block_type=bt_type) and typecanbeforward) or
  241. not(m_delphi in aktmodeswitches)) then
  242. begin
  243. { a hack, but it's easy to handle }
  244. { class reference type }
  245. consume(_OF);
  246. single_type(tt,typecanbeforward);
  247. { accept hp1, if is a forward def or a class }
  248. if (tt.def.deftype=forwarddef) or
  249. is_class(tt.def) then
  250. begin
  251. pcrd:=tclassrefdef.create(tt);
  252. object_dec:=pcrd;
  253. end
  254. else
  255. begin
  256. object_dec:=generrortype.def;
  257. Message1(type_e_class_type_expected,generrortype.def.typename);
  258. end;
  259. typecanbeforward:=storetypecanbeforward;
  260. readobjecttype:=false;
  261. exit;
  262. end
  263. { forward class }
  264. else if not(assigned(fd)) and (token=_SEMICOLON) then
  265. begin
  266. { also anonym objects aren't allow (o : object a : longint; end;) }
  267. if n='' then
  268. Message(parser_f_no_anonym_objects);
  269. aktobjectdef:=tobjectdef.create(odt_class,n,nil);
  270. if (cs_compilesystem in aktmoduleswitches) and (upper(n)='TOBJECT') then
  271. class_tobject:=aktobjectdef;
  272. aktobjectdef.objecttype:=odt_class;
  273. include(aktobjectdef.objectoptions,oo_is_forward);
  274. if (cs_generate_rtti in aktlocalswitches) then
  275. include(aktobjectdef.objectoptions,oo_can_have_published);
  276. { all classes must have a vmt !! at offset zero }
  277. if not(oo_has_vmt in aktobjectdef.objectoptions) then
  278. aktobjectdef.insertvmt;
  279. object_dec:=aktobjectdef;
  280. typecanbeforward:=storetypecanbeforward;
  281. readobjecttype:=false;
  282. exit;
  283. end;
  284. end;
  285. else
  286. begin
  287. classtype:=odt_class; { this is error but try to recover }
  288. consume(_OBJECT);
  289. end;
  290. end;
  291. end;
  292. procedure handleimplementedinterface(implintf : tobjectdef);
  293. begin
  294. if not is_interface(implintf) then
  295. begin
  296. Message1(type_e_interface_type_expected,implintf.typename);
  297. exit;
  298. end;
  299. if aktobjectdef.implementedinterfaces.searchintf(implintf)<>-1 then
  300. Message1(sym_e_duplicate_id,implintf.name)
  301. else
  302. begin
  303. { allocate and prepare the GUID only if the class
  304. implements some interfaces.
  305. }
  306. if aktobjectdef.implementedinterfaces.count = 0 then
  307. aktobjectdef.prepareguid;
  308. aktobjectdef.implementedinterfaces.addintf(implintf);
  309. end;
  310. end;
  311. procedure readimplementedinterfaces;
  312. var
  313. tt : ttype;
  314. begin
  315. while try_to_consume(_COMMA) do
  316. begin
  317. id_type(tt,false);
  318. if (tt.def.deftype<>objectdef) then
  319. begin
  320. Message1(type_e_interface_type_expected,tt.def.typename);
  321. continue;
  322. end;
  323. handleimplementedinterface(tobjectdef(tt.def));
  324. end;
  325. end;
  326. procedure readinterfaceiid;
  327. var
  328. p : tnode;
  329. valid : boolean;
  330. begin
  331. p:=comp_expr(true);
  332. if p.nodetype=stringconstn then
  333. begin
  334. stringdispose(aktobjectdef.iidstr);
  335. aktobjectdef.iidstr:=stringdup(strpas(tstringconstnode(p).value_str)); { or upper? }
  336. p.free;
  337. valid:=string2guid(aktobjectdef.iidstr^,aktobjectdef.iidguid^);
  338. if (classtype=odt_interfacecom) and not assigned(aktobjectdef.iidguid) and not valid then
  339. Message(parser_e_improper_guid_syntax);
  340. end
  341. else
  342. begin
  343. p.free;
  344. Message(parser_e_illegal_expression);
  345. end;
  346. end;
  347. procedure readparentclasses;
  348. var
  349. intfchildof,
  350. childof : tobjectdef;
  351. tt : ttype;
  352. hasparentdefined : boolean;
  353. begin
  354. childof:=nil;
  355. intfchildof:=nil;
  356. hasparentdefined:=false;
  357. { reads the parent class }
  358. if try_to_consume(_LKLAMMER) then
  359. begin
  360. id_type(tt,false);
  361. if (not assigned(tt.def)) or
  362. (tt.def.deftype<>objectdef) then
  363. begin
  364. if assigned(tt.def) then
  365. Message1(type_e_class_type_expected,childof.typename);
  366. end
  367. else
  368. begin
  369. childof:=tobjectdef(tt.def);
  370. { a mix of class, interfaces, objects and cppclasses
  371. isn't allowed }
  372. case classtype of
  373. odt_class:
  374. if not(is_class(childof)) then
  375. begin
  376. if is_interface(childof) then
  377. begin
  378. { we insert the interface after the child
  379. is set, see below
  380. }
  381. intfchildof:=childof;
  382. childof:=class_tobject;
  383. end
  384. else
  385. Message(parser_e_mix_of_classes_and_objects);
  386. end;
  387. odt_interfacecorba,
  388. odt_interfacecom:
  389. if not(is_interface(childof)) then
  390. Message(parser_e_mix_of_classes_and_objects);
  391. odt_cppclass:
  392. if not(is_cppclass(childof)) then
  393. Message(parser_e_mix_of_classes_and_objects);
  394. odt_object:
  395. if not(is_object(childof)) then
  396. Message(parser_e_mix_of_classes_and_objects);
  397. odt_dispinterface:
  398. Message(parser_e_dispinterface_cant_have_parent);
  399. end;
  400. end;
  401. hasparentdefined:=true;
  402. end;
  403. { if no parent class, then a class get tobject as parent }
  404. if not assigned(childof) then
  405. begin
  406. case classtype of
  407. odt_class:
  408. if aktobjectdef<>class_tobject then
  409. childof:=class_tobject;
  410. odt_interfacecom:
  411. if aktobjectdef<>interface_iunknown then
  412. childof:=interface_iunknown;
  413. end;
  414. end;
  415. if assigned(childof) then
  416. begin
  417. { Forbid not completly defined objects to be used as parents. This will
  418. also prevent circular loops of classes, because we set the forward flag
  419. at the start of the new definition and will reset it below after the
  420. parent has been set }
  421. if not(oo_is_forward in childof.objectoptions) then
  422. aktobjectdef.set_parent(childof)
  423. else
  424. Message1(parser_e_forward_declaration_must_be_resolved,childof.objrealname^);
  425. end;
  426. { remove forward flag, is resolved }
  427. exclude(aktobjectdef.objectoptions,oo_is_forward);
  428. if hasparentdefined then
  429. begin
  430. if aktobjectdef.objecttype=odt_class then
  431. begin
  432. if assigned(intfchildof) then
  433. handleimplementedinterface(intfchildof);
  434. readimplementedinterfaces;
  435. end;
  436. consume(_RKLAMMER);
  437. end;
  438. { read GUID }
  439. if (classtype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) and
  440. try_to_consume(_LECKKLAMMER) then
  441. begin
  442. readinterfaceiid;
  443. consume(_RECKKLAMMER);
  444. end
  445. else if (classtype=odt_dispinterface) then
  446. message(parser_e_dispinterface_needs_a_guid);
  447. end;
  448. procedure chkcpp(pd:tprocdef);
  449. begin
  450. if is_cppclass(pd._class) then
  451. begin
  452. pd.proccalloption:=pocall_cppdecl;
  453. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  454. end;
  455. end;
  456. var
  457. pd : tprocdef;
  458. dummysymoptions : tsymoptions;
  459. begin
  460. old_object_option:=current_object_option;
  461. { objects and class types can't be declared local }
  462. if not(symtablestack.symtabletype in [globalsymtable,staticsymtable]) then
  463. Message(parser_e_no_local_objects);
  464. storetypecanbeforward:=typecanbeforward;
  465. { for tp7 don't allow forward types }
  466. if (m_tp7 in aktmodeswitches) then
  467. typecanbeforward:=false;
  468. if not(readobjecttype) then
  469. exit;
  470. if assigned(fd) then
  471. aktobjectdef:=fd
  472. else
  473. begin
  474. { anonym objects aren't allow (o : object a : longint; end;) }
  475. if n='' then
  476. Message(parser_f_no_anonym_objects);
  477. aktobjectdef:=tobjectdef.create(classtype,n,nil);
  478. { include forward flag, it'll be removed after the parent class have been
  479. added. This is to prevent circular childof loops }
  480. include(aktobjectdef.objectoptions,oo_is_forward);
  481. end;
  482. { read list of parent classes }
  483. readparentclasses;
  484. { default access is public }
  485. there_is_a_destructor:=false;
  486. current_object_option:=[sp_public];
  487. { set class flags and inherits published }
  488. setclassattributes;
  489. aktobjectdef.symtable.next:=symtablestack;
  490. symtablestack:=aktobjectdef.symtable;
  491. testcurobject:=1;
  492. { short class declaration ? }
  493. if (classtype<>odt_class) or (token<>_SEMICOLON) then
  494. begin
  495. { Parse componenten }
  496. repeat
  497. case token of
  498. _ID :
  499. begin
  500. case idtoken of
  501. _PRIVATE :
  502. begin
  503. if is_interface(aktobjectdef) then
  504. Message(parser_e_no_access_specifier_in_interfaces);
  505. consume(_PRIVATE);
  506. current_object_option:=[sp_private];
  507. include(aktobjectdef.objectoptions,oo_has_private);
  508. end;
  509. _PROTECTED :
  510. begin
  511. if is_interface(aktobjectdef) then
  512. Message(parser_e_no_access_specifier_in_interfaces);
  513. consume(_PROTECTED);
  514. current_object_option:=[sp_protected];
  515. include(aktobjectdef.objectoptions,oo_has_protected);
  516. end;
  517. _PUBLIC :
  518. begin
  519. if is_interface(aktobjectdef) then
  520. Message(parser_e_no_access_specifier_in_interfaces);
  521. consume(_PUBLIC);
  522. current_object_option:=[sp_public];
  523. end;
  524. _PUBLISHED :
  525. begin
  526. { we've to check for a pushlished section in non- }
  527. { publishable classes later, if a real declaration }
  528. { this is the way, delphi does it }
  529. if is_interface(aktobjectdef) then
  530. Message(parser_e_no_access_specifier_in_interfaces);
  531. consume(_PUBLISHED);
  532. current_object_option:=[sp_published];
  533. end;
  534. _STRICT :
  535. begin
  536. if is_interface(aktobjectdef) then
  537. Message(parser_e_no_access_specifier_in_interfaces);
  538. consume(_STRICT);
  539. if token=_ID then
  540. begin
  541. case idtoken of
  542. _PRIVATE:
  543. begin
  544. consume(_PRIVATE);
  545. current_object_option:=[sp_strictprivate];
  546. include(aktobjectdef.objectoptions,oo_has_strictprivate);
  547. end;
  548. _PROTECTED:
  549. begin
  550. consume(_PROTECTED);
  551. current_object_option:=[sp_strictprotected];
  552. include(aktobjectdef.objectoptions,oo_has_strictprotected);
  553. end;
  554. else
  555. message(parser_e_protected_or_private_expected);
  556. end;
  557. end
  558. else
  559. message(parser_e_protected_or_private_expected);
  560. end;
  561. else
  562. begin
  563. if is_interface(aktobjectdef) then
  564. Message(parser_e_no_vars_in_interfaces);
  565. if (sp_published in current_object_option) and
  566. not(oo_can_have_published in aktobjectdef.objectoptions) then
  567. Message(parser_e_cant_have_published);
  568. read_var_decs([vd_object]);
  569. end;
  570. end;
  571. end;
  572. _PROPERTY :
  573. begin
  574. property_dec;
  575. end;
  576. _PROCEDURE,
  577. _FUNCTION,
  578. _CLASS :
  579. begin
  580. if (sp_published in current_object_option) and
  581. not(oo_can_have_published in aktobjectdef.objectoptions) then
  582. Message(parser_e_cant_have_published);
  583. oldparse_only:=parse_only;
  584. parse_only:=true;
  585. pd:=parse_proc_dec(aktobjectdef);
  586. { this is for error recovery as well as forward }
  587. { interface mappings, i.e. mapping to a method }
  588. { which isn't declared yet }
  589. if assigned(pd) then
  590. begin
  591. parse_object_proc_directives(pd);
  592. { all Macintosh Object Pascal methods are virtual. }
  593. { this can't be a class method, because macpas mode }
  594. { has no m_class }
  595. if (m_mac in aktmodeswitches) then
  596. include(pd.procoptions,po_virtualmethod);
  597. handle_calling_convention(pd);
  598. { add definition to procsym }
  599. proc_add_definition(pd);
  600. { add procdef options to objectdef options }
  601. if (po_msgint in pd.procoptions) then
  602. include(aktobjectdef.objectoptions,oo_has_msgint);
  603. if (po_msgstr in pd.procoptions) then
  604. include(aktobjectdef.objectoptions,oo_has_msgstr);
  605. if (po_virtualmethod in pd.procoptions) then
  606. include(aktobjectdef.objectoptions,oo_has_virtual);
  607. chkcpp(pd);
  608. end;
  609. { Support hint directives }
  610. dummysymoptions:=[];
  611. while try_consume_hintdirective(dummysymoptions) do
  612. Consume(_SEMICOLON);
  613. if assigned(pd) then
  614. pd.symoptions:=pd.symoptions+dummysymoptions;
  615. parse_only:=oldparse_only;
  616. end;
  617. _CONSTRUCTOR :
  618. begin
  619. if (sp_published in current_object_option) and
  620. not(oo_can_have_published in aktobjectdef.objectoptions) then
  621. Message(parser_e_cant_have_published);
  622. if not(sp_public in current_object_option) and
  623. not(sp_published in current_object_option) then
  624. Message(parser_w_constructor_should_be_public);
  625. if is_interface(aktobjectdef) then
  626. Message(parser_e_no_con_des_in_interfaces);
  627. oldparse_only:=parse_only;
  628. parse_only:=true;
  629. pd:=constructor_head;
  630. parse_object_proc_directives(pd);
  631. handle_calling_convention(pd);
  632. { add definition to procsym }
  633. proc_add_definition(pd);
  634. { add procdef options to objectdef options }
  635. if (po_virtualmethod in pd.procoptions) then
  636. include(aktobjectdef.objectoptions,oo_has_virtual);
  637. chkcpp(pd);
  638. { Support hint directives }
  639. dummysymoptions:=[];
  640. while try_consume_hintdirective(dummysymoptions) do
  641. Consume(_SEMICOLON);
  642. if assigned(pd) then
  643. pd.symoptions:=pd.symoptions+dummysymoptions;
  644. parse_only:=oldparse_only;
  645. end;
  646. _DESTRUCTOR :
  647. begin
  648. if (sp_published in current_object_option) and
  649. not(oo_can_have_published in aktobjectdef.objectoptions) then
  650. Message(parser_e_cant_have_published);
  651. if there_is_a_destructor then
  652. Message(parser_n_only_one_destructor);
  653. if is_interface(aktobjectdef) then
  654. Message(parser_e_no_con_des_in_interfaces);
  655. if not(sp_public in current_object_option) then
  656. Message(parser_w_destructor_should_be_public);
  657. there_is_a_destructor:=true;
  658. oldparse_only:=parse_only;
  659. parse_only:=true;
  660. pd:=destructor_head;
  661. parse_object_proc_directives(pd);
  662. handle_calling_convention(pd);
  663. { add definition to procsym }
  664. proc_add_definition(pd);
  665. { add procdef options to objectdef options }
  666. if (po_virtualmethod in pd.procoptions) then
  667. include(aktobjectdef.objectoptions,oo_has_virtual);
  668. chkcpp(pd);
  669. { Support hint directives }
  670. dummysymoptions:=[];
  671. while try_consume_hintdirective(dummysymoptions) do
  672. Consume(_SEMICOLON);
  673. if assigned(pd) then
  674. pd.symoptions:=pd.symoptions+dummysymoptions;
  675. parse_only:=oldparse_only;
  676. end;
  677. _END :
  678. begin
  679. consume(_END);
  680. break;
  681. end;
  682. else
  683. consume(_ID); { Give a ident expected message, like tp7 }
  684. end;
  685. until false;
  686. end;
  687. { generate vmt space if needed }
  688. if not(oo_has_vmt in aktobjectdef.objectoptions) and
  689. (([oo_has_virtual,oo_has_constructor,oo_has_destructor]*aktobjectdef.objectoptions<>[]) or
  690. (classtype in [odt_class])
  691. ) then
  692. aktobjectdef.insertvmt;
  693. if is_interface(aktobjectdef) then
  694. setinterfacemethodoptions;
  695. { return defined objectdef }
  696. result:=aktobjectdef;
  697. { restore old state }
  698. aktobjectdef:=nil;
  699. testcurobject:=0;
  700. typecanbeforward:=storetypecanbeforward;
  701. symtablestack:=symtablestack.next;
  702. current_object_option:=old_object_option;
  703. end;
  704. end.