pdecobj.pas 55 KB

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