pdecobj.pas 32 KB

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