pdecobj.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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) : tobjectdef;
  25. implementation
  26. uses
  27. cutils,
  28. globals,verbose,systems,tokens,
  29. symbase,symsym,symtable,
  30. node,nld,nmem,ncon,ncnv,ncal,
  31. fmodule,scanner,
  32. pbase,pexpr,pdecsub,pdecvar,ptype,pdecl
  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 constructor_head:tprocdef;
  40. var
  41. pd : tprocdef;
  42. begin
  43. result:=nil;
  44. consume(_CONSTRUCTOR);
  45. { must be at same level as in implementation }
  46. parse_proc_head(current_objectdef,potype_constructor,pd);
  47. if not assigned(pd) then
  48. begin
  49. consume(_SEMICOLON);
  50. exit;
  51. end;
  52. if (cs_constructor_name in current_settings.globalswitches) and
  53. (pd.procsym.name<>'INIT') then
  54. Message(parser_e_constructorname_must_be_init);
  55. consume(_SEMICOLON);
  56. include(current_objectdef.objectoptions,oo_has_constructor);
  57. { Set return type, class constructors return the
  58. created instance, object constructors return boolean }
  59. if is_class(pd._class) then
  60. pd.returndef:=pd._class
  61. else
  62. {$ifdef CPU64bitaddr}
  63. pd.returndef:=bool64type;
  64. {$else CPU64bitaddr}
  65. pd.returndef:=bool32type;
  66. {$endif CPU64bitaddr}
  67. result:=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_or_dispinterface(current_objectdef)) or
  75. (not(m_tp7 in current_settings.modeswitches) and (is_object(current_objectdef)))) then
  76. Message(parser_e_syntax_error);
  77. consume(_PROPERTY);
  78. p:=read_property_dec(current_objectdef);
  79. consume(_SEMICOLON);
  80. if try_to_consume(_DEFAULT) then
  81. begin
  82. if oo_has_default_property in current_objectdef.objectoptions then
  83. message(parser_e_only_one_default_property);
  84. include(current_objectdef.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. result:=nil;
  100. consume(_DESTRUCTOR);
  101. parse_proc_head(current_objectdef,potype_destructor,pd);
  102. if not assigned(pd) then
  103. begin
  104. consume(_SEMICOLON);
  105. exit;
  106. end;
  107. if (cs_constructor_name in current_settings.globalswitches) and
  108. (pd.procsym.name<>'DONE') then
  109. Message(parser_e_destructorname_must_be_done);
  110. if not(pd.maxparacount=0) and
  111. (m_fpc in current_settings.modeswitches) then
  112. Message(parser_e_no_paras_for_destructor);
  113. consume(_SEMICOLON);
  114. include(current_objectdef.objectoptions,oo_has_destructor);
  115. { no return value }
  116. pd.returndef:=voidtype;
  117. result:=pd;
  118. end;
  119. procedure setinterfacemethodoptions;
  120. var
  121. i : longint;
  122. def : tdef;
  123. begin
  124. include(current_objectdef.objectoptions,oo_has_virtual);
  125. for i:=0 to current_objectdef.symtable.DefList.count-1 do
  126. begin
  127. def:=tdef(current_objectdef.symtable.DefList[i]);
  128. if assigned(def) and
  129. (def.typ=procdef) then
  130. begin
  131. include(tprocdef(def).procoptions,po_virtualmethod);
  132. tprocdef(def).forwarddef:=false;
  133. end;
  134. end;
  135. end;
  136. procedure handleImplementedInterface(intfdef : tobjectdef);
  137. begin
  138. if not is_interface(intfdef) then
  139. begin
  140. Message1(type_e_interface_type_expected,intfdef.typename);
  141. exit;
  142. end;
  143. if current_objectdef.find_implemented_interface(intfdef)<>nil then
  144. Message1(sym_e_duplicate_id,intfdef.objname^)
  145. else
  146. begin
  147. { allocate and prepare the GUID only if the class
  148. implements some interfaces. }
  149. if current_objectdef.ImplementedInterfaces.count = 0 then
  150. current_objectdef.prepareguid;
  151. current_objectdef.ImplementedInterfaces.Add(TImplementedInterface.Create(intfdef));
  152. end;
  153. end;
  154. procedure readImplementedInterfaces;
  155. var
  156. hdef : tdef;
  157. begin
  158. while try_to_consume(_COMMA) do
  159. begin
  160. id_type(hdef,false);
  161. if (hdef.typ<>objectdef) then
  162. begin
  163. Message1(type_e_interface_type_expected,hdef.typename);
  164. continue;
  165. end;
  166. handleImplementedInterface(tobjectdef(hdef));
  167. end;
  168. end;
  169. procedure readinterfaceiid;
  170. var
  171. p : tnode;
  172. valid : boolean;
  173. begin
  174. p:=comp_expr(true);
  175. if p.nodetype=stringconstn then
  176. begin
  177. stringdispose(current_objectdef.iidstr);
  178. current_objectdef.iidstr:=stringdup(strpas(tstringconstnode(p).value_str));
  179. valid:=string2guid(current_objectdef.iidstr^,current_objectdef.iidguid^);
  180. if (current_objectdef.objecttype in [odt_interfacecom,odt_dispinterface]) and
  181. not valid then
  182. Message(parser_e_improper_guid_syntax);
  183. include(current_objectdef.objectoptions,oo_has_valid_guid);
  184. end
  185. else
  186. Message(parser_e_illegal_expression);
  187. p.free;
  188. end;
  189. procedure parse_parent_classes;
  190. var
  191. intfchildof,
  192. childof : tobjectdef;
  193. hdef : tdef;
  194. hasparentdefined : boolean;
  195. begin
  196. childof:=nil;
  197. intfchildof:=nil;
  198. hasparentdefined:=false;
  199. { reads the parent class }
  200. if try_to_consume(_LKLAMMER) then
  201. begin
  202. { use single_type instead of id_type for specialize support }
  203. single_type(hdef,false);
  204. if (not assigned(hdef)) or
  205. (hdef.typ<>objectdef) then
  206. begin
  207. if assigned(hdef) then
  208. Message1(type_e_class_type_expected,hdef.typename);
  209. end
  210. else
  211. begin
  212. childof:=tobjectdef(hdef);
  213. { a mix of class, interfaces, objects and cppclasses
  214. isn't allowed }
  215. case current_objectdef.objecttype of
  216. odt_class:
  217. if not(is_class(childof)) then
  218. begin
  219. if is_interface(childof) then
  220. begin
  221. { we insert the interface after the child
  222. is set, see below
  223. }
  224. intfchildof:=childof;
  225. childof:=class_tobject;
  226. end
  227. else
  228. Message(parser_e_mix_of_classes_and_objects);
  229. end;
  230. odt_interfacecorba,
  231. odt_interfacecom:
  232. begin
  233. if not(is_interface(childof)) then
  234. Message(parser_e_mix_of_classes_and_objects);
  235. current_objectdef.objecttype:=childof.objecttype;
  236. current_objectdef.objecttype:=current_objectdef.objecttype;
  237. end;
  238. odt_cppclass:
  239. if not(is_cppclass(childof)) then
  240. Message(parser_e_mix_of_classes_and_objects);
  241. odt_objcclass:
  242. if not(is_objcclass(childof)) then
  243. Message(parser_e_mix_of_classes_and_objects);
  244. odt_object:
  245. if not(is_object(childof)) then
  246. Message(parser_e_mix_of_classes_and_objects);
  247. odt_dispinterface:
  248. Message(parser_e_dispinterface_cant_have_parent);
  249. end;
  250. end;
  251. hasparentdefined:=true;
  252. end;
  253. { no generic as parents }
  254. if assigned(childof) and
  255. (df_generic in childof.defoptions) then
  256. begin
  257. Message(parser_e_no_generics_as_types);
  258. childof:=nil;
  259. end;
  260. { if no parent class, then a class get tobject as parent }
  261. if not assigned(childof) then
  262. begin
  263. case current_objectdef.objecttype of
  264. odt_class:
  265. if current_objectdef<>class_tobject then
  266. childof:=class_tobject;
  267. odt_interfacecom:
  268. if current_objectdef<>interface_iunknown then
  269. childof:=interface_iunknown;
  270. odt_objcclass:
  271. if current_objectdef<>objcclass_nsobject then
  272. childof:=objcclass_nsobject;
  273. end;
  274. end;
  275. if assigned(childof) then
  276. begin
  277. { Forbid not completly defined objects to be used as parents. This will
  278. also prevent circular loops of classes, because we set the forward flag
  279. at the start of the new definition and will reset it below after the
  280. parent has been set }
  281. if not(oo_is_forward in childof.objectoptions) then
  282. current_objectdef.set_parent(childof)
  283. else
  284. Message1(parser_e_forward_declaration_must_be_resolved,childof.objrealname^);
  285. end;
  286. { remove forward flag, is resolved }
  287. exclude(current_objectdef.objectoptions,oo_is_forward);
  288. if hasparentdefined then
  289. begin
  290. if current_objectdef.objecttype=odt_class then
  291. begin
  292. if assigned(intfchildof) then
  293. handleImplementedInterface(intfchildof);
  294. readImplementedInterfaces;
  295. end;
  296. consume(_RKLAMMER);
  297. end;
  298. end;
  299. procedure parse_guid;
  300. begin
  301. { read GUID }
  302. if (current_objectdef.objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) and
  303. try_to_consume(_LECKKLAMMER) then
  304. begin
  305. readinterfaceiid;
  306. consume(_RECKKLAMMER);
  307. end
  308. else if (current_objectdef.objecttype=odt_dispinterface) then
  309. message(parser_e_dispinterface_needs_a_guid);
  310. end;
  311. procedure insert_generic_parameter_types(genericdef:tstoreddef;genericlist:TFPObjectList);
  312. var
  313. i : longint;
  314. generictype : ttypesym;
  315. begin
  316. current_objectdef.genericdef:=genericdef;
  317. if not assigned(genericlist) then
  318. exit;
  319. for i:=0 to genericlist.count-1 do
  320. begin
  321. generictype:=ttypesym(genericlist[i]);
  322. if generictype.typedef.typ=undefineddef then
  323. include(current_objectdef.defoptions,df_generic)
  324. else
  325. include(current_objectdef.defoptions,df_specialization);
  326. symtablestack.top.insert(generictype);
  327. end;
  328. end;
  329. procedure parse_object_members;
  330. procedure chkobjc(pd: tprocdef);
  331. begin
  332. if is_objcclass(pd._class) then
  333. begin
  334. { none of the explicit calling conventions should be allowed }
  335. if (po_hascallingconvention in pd.procoptions) then
  336. internalerror(2009032501);
  337. pd.proccalloption:=pocall_cdecl;
  338. if not(po_msgstr in pd.procoptions) then
  339. Message(parser_e_objc_requires_msgstr);
  340. include(pd.procoptions,po_objc);
  341. end;
  342. end;
  343. procedure chkcpp(pd:tprocdef);
  344. begin
  345. if is_cppclass(pd._class) then
  346. begin
  347. pd.proccalloption:=pocall_cppdecl;
  348. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  349. end;
  350. end;
  351. procedure maybe_parse_hint_directives(pd:tprocdef);
  352. var
  353. dummysymoptions : tsymoptions;
  354. begin
  355. dummysymoptions:=[];
  356. while try_consume_hintdirective(dummysymoptions) do
  357. Consume(_SEMICOLON);
  358. if assigned(pd) then
  359. pd.symoptions:=pd.symoptions+dummysymoptions;
  360. end;
  361. var
  362. pd : tprocdef;
  363. has_destructor,
  364. oldparse_only,
  365. old_parse_generic : boolean;
  366. object_member_blocktype : tblock_type;
  367. begin
  368. { empty class declaration ? }
  369. if (current_objectdef.objecttype in [odt_class,odt_objcclass]) and
  370. (token=_SEMICOLON) then
  371. exit;
  372. old_parse_generic:=parse_generic;
  373. parse_generic:=(df_generic in current_objectdef.defoptions);
  374. { in "publishable" classes the default access type is published }
  375. if (oo_can_have_published in current_objectdef.objectoptions) then
  376. current_objectdef.symtable.currentvisibility:=vis_published
  377. else
  378. current_objectdef.symtable.currentvisibility:=vis_public;
  379. testcurobject:=1;
  380. has_destructor:=false;
  381. object_member_blocktype:=bt_general;
  382. repeat
  383. case token of
  384. _TYPE :
  385. begin
  386. if ([df_generic,df_specialization]*current_objectdef.defoptions)=[] then
  387. Message(parser_e_type_and_var_only_in_generics);
  388. consume(_TYPE);
  389. object_member_blocktype:=bt_type;
  390. end;
  391. _VAR :
  392. begin
  393. if ([df_generic,df_specialization]*current_objectdef.defoptions)=[] then
  394. Message(parser_e_type_and_var_only_in_generics);
  395. consume(_VAR);
  396. object_member_blocktype:=bt_general;
  397. end;
  398. _ID :
  399. begin
  400. case idtoken of
  401. _PRIVATE :
  402. begin
  403. if is_interface(current_objectdef) then
  404. Message(parser_e_no_access_specifier_in_interfaces);
  405. consume(_PRIVATE);
  406. current_objectdef.symtable.currentvisibility:=vis_private;
  407. include(current_objectdef.objectoptions,oo_has_private);
  408. end;
  409. _PROTECTED :
  410. begin
  411. if is_interface(current_objectdef) then
  412. Message(parser_e_no_access_specifier_in_interfaces);
  413. consume(_PROTECTED);
  414. current_objectdef.symtable.currentvisibility:=vis_protected;
  415. include(current_objectdef.objectoptions,oo_has_protected);
  416. end;
  417. _PUBLIC :
  418. begin
  419. if is_interface(current_objectdef) then
  420. Message(parser_e_no_access_specifier_in_interfaces);
  421. consume(_PUBLIC);
  422. current_objectdef.symtable.currentvisibility:=vis_public;
  423. end;
  424. _PUBLISHED :
  425. begin
  426. { we've to check for a pushlished section in non- }
  427. { publishable classes later, if a real declaration }
  428. { this is the way, delphi does it }
  429. if is_interface(current_objectdef) then
  430. Message(parser_e_no_access_specifier_in_interfaces);
  431. consume(_PUBLISHED);
  432. current_objectdef.symtable.currentvisibility:=vis_published;
  433. end;
  434. _STRICT :
  435. begin
  436. if is_interface(current_objectdef) then
  437. Message(parser_e_no_access_specifier_in_interfaces);
  438. consume(_STRICT);
  439. if token=_ID then
  440. begin
  441. case idtoken of
  442. _PRIVATE:
  443. begin
  444. consume(_PRIVATE);
  445. current_objectdef.symtable.currentvisibility:=vis_strictprivate;
  446. include(current_objectdef.objectoptions,oo_has_strictprivate);
  447. end;
  448. _PROTECTED:
  449. begin
  450. consume(_PROTECTED);
  451. current_objectdef.symtable.currentvisibility:=vis_strictprotected;
  452. include(current_objectdef.objectoptions,oo_has_strictprotected);
  453. end;
  454. else
  455. message(parser_e_protected_or_private_expected);
  456. end;
  457. end
  458. else
  459. message(parser_e_protected_or_private_expected);
  460. end;
  461. else
  462. begin
  463. if object_member_blocktype=bt_general then
  464. begin
  465. if is_interface(current_objectdef) then
  466. Message(parser_e_no_vars_in_interfaces);
  467. if (current_objectdef.symtable.currentvisibility=vis_published) and
  468. not(oo_can_have_published in current_objectdef.objectoptions) then
  469. Message(parser_e_cant_have_published);
  470. read_record_fields([vd_object])
  471. end
  472. else
  473. types_dec;
  474. end;
  475. end;
  476. end;
  477. _PROPERTY :
  478. begin
  479. property_dec;
  480. end;
  481. _PROCEDURE,
  482. _FUNCTION,
  483. _CLASS :
  484. begin
  485. if (current_objectdef.symtable.currentvisibility=vis_published) and
  486. not(oo_can_have_published in current_objectdef.objectoptions) then
  487. Message(parser_e_cant_have_published);
  488. oldparse_only:=parse_only;
  489. parse_only:=true;
  490. pd:=parse_proc_dec(current_objectdef);
  491. { this is for error recovery as well as forward }
  492. { interface mappings, i.e. mapping to a method }
  493. { which isn't declared yet }
  494. if assigned(pd) then
  495. begin
  496. parse_object_proc_directives(pd);
  497. { all Macintosh Object Pascal methods are virtual. }
  498. { this can't be a class method, because macpas mode }
  499. { has no m_class }
  500. if (m_mac in current_settings.modeswitches) then
  501. include(pd.procoptions,po_virtualmethod);
  502. handle_calling_convention(pd);
  503. { add definition to procsym }
  504. proc_add_definition(pd);
  505. { add procdef options to objectdef options }
  506. if (po_msgint in pd.procoptions) then
  507. include(current_objectdef.objectoptions,oo_has_msgint);
  508. if (po_msgstr in pd.procoptions) then
  509. include(current_objectdef.objectoptions,oo_has_msgstr);
  510. if (po_virtualmethod in pd.procoptions) then
  511. include(current_objectdef.objectoptions,oo_has_virtual);
  512. chkcpp(pd);
  513. chkobjc(pd);
  514. end;
  515. maybe_parse_hint_directives(pd);
  516. parse_only:=oldparse_only;
  517. end;
  518. _CONSTRUCTOR :
  519. begin
  520. if (current_objectdef.symtable.currentvisibility=vis_published) and
  521. not(oo_can_have_published in current_objectdef.objectoptions) then
  522. Message(parser_e_cant_have_published);
  523. if not(current_objectdef.symtable.currentvisibility in [vis_public,vis_published]) then
  524. Message(parser_w_constructor_should_be_public);
  525. if is_interface(current_objectdef) then
  526. Message(parser_e_no_con_des_in_interfaces);
  527. oldparse_only:=parse_only;
  528. parse_only:=true;
  529. pd:=constructor_head;
  530. parse_object_proc_directives(pd);
  531. handle_calling_convention(pd);
  532. { add definition to procsym }
  533. proc_add_definition(pd);
  534. { add procdef options to objectdef options }
  535. if (po_virtualmethod in pd.procoptions) then
  536. include(current_objectdef.objectoptions,oo_has_virtual);
  537. chkcpp(pd);
  538. maybe_parse_hint_directives(pd);
  539. parse_only:=oldparse_only;
  540. end;
  541. _DESTRUCTOR :
  542. begin
  543. if (current_objectdef.symtable.currentvisibility=vis_published) and
  544. not(oo_can_have_published in current_objectdef.objectoptions) then
  545. Message(parser_e_cant_have_published);
  546. if has_destructor then
  547. Message(parser_n_only_one_destructor);
  548. has_destructor:=true;
  549. if is_interface(current_objectdef) then
  550. Message(parser_e_no_con_des_in_interfaces);
  551. if (current_objectdef.symtable.currentvisibility<>vis_public) then
  552. Message(parser_w_destructor_should_be_public);
  553. oldparse_only:=parse_only;
  554. parse_only:=true;
  555. pd:=destructor_head;
  556. parse_object_proc_directives(pd);
  557. handle_calling_convention(pd);
  558. { add definition to procsym }
  559. proc_add_definition(pd);
  560. { add procdef options to objectdef options }
  561. if (po_virtualmethod in pd.procoptions) then
  562. include(current_objectdef.objectoptions,oo_has_virtual);
  563. chkcpp(pd);
  564. maybe_parse_hint_directives(pd);
  565. parse_only:=oldparse_only;
  566. end;
  567. _END :
  568. begin
  569. consume(_END);
  570. break;
  571. end;
  572. else
  573. consume(_ID); { Give a ident expected message, like tp7 }
  574. end;
  575. until false;
  576. { restore }
  577. testcurobject:=0;
  578. parse_generic:=old_parse_generic;
  579. end;
  580. function object_dec(objecttype:tobjecttyp;const n:tidstring;genericdef:tstoreddef;genericlist:TFPObjectList;fd : tobjectdef) : tobjectdef;
  581. var
  582. old_current_objectdef : tobjectdef;
  583. begin
  584. old_current_objectdef:=current_objectdef;
  585. current_objectdef:=nil;
  586. { objects and class types can't be declared local }
  587. if not(symtablestack.top.symtabletype in [globalsymtable,staticsymtable]) and
  588. not assigned(genericlist) then
  589. Message(parser_e_no_local_objects);
  590. { reuse forward objectdef? }
  591. if assigned(fd) then
  592. begin
  593. if fd.objecttype<>objecttype then
  594. begin
  595. Message(parser_e_forward_mismatch);
  596. { recover }
  597. current_objectdef:=tobjectdef.create(current_objectdef.objecttype,n,nil);
  598. include(current_objectdef.objectoptions,oo_is_forward);
  599. end
  600. else
  601. current_objectdef:=fd
  602. end
  603. else
  604. begin
  605. { anonym objects aren't allow (o : object a : longint; end;) }
  606. if n='' then
  607. Message(parser_f_no_anonym_objects);
  608. { create new class }
  609. current_objectdef:=tobjectdef.create(objecttype,n,nil);
  610. { include always the forward flag, it'll be removed after the parent class have been
  611. added. This is to prevent circular childof loops }
  612. include(current_objectdef.objectoptions,oo_is_forward);
  613. if (cs_compilesystem in current_settings.moduleswitches) then
  614. begin
  615. case current_objectdef.objecttype of
  616. odt_interfacecom :
  617. if (current_objectdef.objname^='IUNKNOWN') then
  618. interface_iunknown:=current_objectdef;
  619. odt_class :
  620. if (current_objectdef.objname^='TOBJECT') then
  621. class_tobject:=current_objectdef;
  622. end;
  623. end;
  624. end;
  625. { set published flag in $M+ mode, it can also be inherited and will
  626. be added when the parent class set with tobjectdef.set_parent (PFV) }
  627. if (cs_generate_rtti in current_settings.localswitches) and
  628. (current_objectdef.objecttype in [odt_interfacecom,odt_class]) then
  629. include(current_objectdef.objectoptions,oo_can_have_published);
  630. { forward def? }
  631. if not assigned(fd) and
  632. (token=_SEMICOLON) then
  633. begin
  634. { add to the list of definitions to check that the forward
  635. is resolved. this is required for delphi mode }
  636. current_module.checkforwarddefs.add(current_objectdef);
  637. end
  638. else
  639. begin
  640. { parse list of parent classes }
  641. parse_parent_classes;
  642. { parse optional GUID for interfaces }
  643. parse_guid;
  644. { parse and insert object members }
  645. symtablestack.push(current_objectdef.symtable);
  646. insert_generic_parameter_types(genericdef,genericlist);
  647. parse_object_members;
  648. symtablestack.pop(current_objectdef.symtable);
  649. end;
  650. { generate vmt space if needed }
  651. if not(oo_has_vmt in current_objectdef.objectoptions) and
  652. (
  653. ([oo_has_virtual,oo_has_constructor,oo_has_destructor]*current_objectdef.objectoptions<>[]) or
  654. (current_objectdef.objecttype in [odt_class])
  655. ) then
  656. current_objectdef.insertvmt;
  657. { for implemented classes with a vmt check if there is a constructor }
  658. if (oo_has_vmt in current_objectdef.objectoptions) and
  659. not(oo_is_forward in current_objectdef.objectoptions) and
  660. not(oo_has_constructor in current_objectdef.objectoptions) then
  661. Message1(parser_w_virtual_without_constructor,current_objectdef.objrealname^);
  662. if is_interface(current_objectdef) then
  663. setinterfacemethodoptions;
  664. { return defined objectdef }
  665. result:=current_objectdef;
  666. { restore old state }
  667. current_objectdef:=old_current_objectdef;
  668. end;
  669. end.