ソースを参照

* fixed check for forbidding constructors/destructors in objcclasses + tests

git-svn-id: branches/objc@13179 -
Jonas Maebe 16 年 前
コミット
27afdbf94a

+ 2 - 0
.gitattributes

@@ -7918,6 +7918,8 @@ tests/test/tmt1.pp svneol=native#text/plain
 tests/test/tobjc1.pp svneol=native#text/plain
 tests/test/tobjc2.pp svneol=native#text/plain
 tests/test/tobjc3.pp svneol=native#text/plain
+tests/test/tobjc4.pp svneol=native#text/plain
+tests/test/tobjc4a.pp svneol=native#text/plain
 tests/test/tobject1.pp svneol=native#text/plain
 tests/test/tobject2.pp svneol=native#text/plain
 tests/test/tobject3.pp svneol=native#text/plain

+ 1 - 1
compiler/msg/errore.msg

@@ -1181,7 +1181,7 @@ parser_e_objc_requires_msgstr=03251_E_Objective-C messages require their Objecti
 % While bindings to other languages automatically generate such names based on the identifier you use (by replacing
 % all underscores with colons), this is unsafe since nothing prevents an Objective-C method name to contain actual
 % colons.
-parser_e_objc_no_constructor_destructor=03252_E_Objective-C does not have formal constructors or destructors. Use initXXX and the dealloc instance methods.
+parser_e_objc_no_constructor_destructor=03252_E_Objective-C does not have formal constructors nor destructors. Use the alloc, initXXX and dealloc messages.
 % The Objective-C language does not have any constructors or destructors. While there are some messages with a similar
 % purpose (such as \var{init} and \var{dealloc}), these cannot be identified using automatic parsers and do not
 % guarantee anything like Pascal constructors/destructors (e.g., you have to take care of only calling ``designated''

+ 2 - 2
compiler/msgtxt.inc

@@ -390,8 +390,8 @@ const msgtxt : array[0..000215,1..240] of char=(
   'ass $3 ($4)'#000+
   '03251_E_Objective-C messages require their Objec','tive-C selector name'+
   ' to be specified using the "message" directive.'#000+
-  '03252_E_Objective-C does not have formal constructors or destructors. '+
-  'Use initXXX and the dealloc instance methods.'#000+
+  '03252_E_Objective-C does not have formal constructors nor destructors.'+
+  ' Use the alloc, initXXX and dealloc messages.'#000+
   '03253_E_Message name is too long (max. 255 characters)'#000+
   '0','3254_E_Objective-C message symbol name for "$1" is too long'#000+
   '03255_H_Defining a new Objective-C root class. To derive from another '+

+ 8 - 0
compiler/pdecobj.pas

@@ -584,6 +584,10 @@ implementation
                 if is_interface(current_objectdef) then
                   Message(parser_e_no_con_des_in_interfaces);
 
+                { Objective-C does not know the concept of a constructor }
+                if is_objcclass(current_objectdef) then
+                  Message(parser_e_objc_no_constructor_destructor);
+
                 oldparse_only:=parse_only;
                 parse_only:=true;
                 pd:=constructor_head;
@@ -617,6 +621,10 @@ implementation
                 if (current_objectdef.symtable.currentvisibility<>vis_public) then
                   Message(parser_w_destructor_should_be_public);
 
+                { Objective-C does not know the concept of a destructor }
+                if is_objcclass(current_objectdef) then
+                  Message(parser_e_objc_no_constructor_destructor);
+
                 oldparse_only:=parse_only;
                 parse_only:=true;
                 pd:=destructor_head;

+ 0 - 6
compiler/pdecsub.pas

@@ -1028,9 +1028,6 @@ implementation
 
           _CONSTRUCTOR :
             begin
-              { Objective-C does not know the concept of a constructor }
-              if is_objcclass(aclass) then
-                Message(parser_e_objc_no_constructor_destructor);
               consume(_CONSTRUCTOR);
               parse_proc_head(aclass,potype_constructor,pd);
               if assigned(pd) and
@@ -1051,9 +1048,6 @@ implementation
 
           _DESTRUCTOR :
             begin
-              { Objective-C does not know the concept of a destructor }
-              if is_objcclass(aclass) then
-                Message(parser_e_objc_no_constructor_destructor);
               consume(_DESTRUCTOR);
               parse_proc_head(aclass,potype_destructor,pd);
               if assigned(pd) then

+ 14 - 0
tests/test/tobjc4.pp

@@ -0,0 +1,14 @@
+{ %fail }
+{ %target=darwin }
+{ %cpu=powerpc,i386 }
+
+{$modeswitch objectivec1}
+
+type
+  ta = objcclass
+    { no constructors in Objective-C }
+    constructor create;
+  end; external;
+
+begin
+end.

+ 14 - 0
tests/test/tobjc4a.pp

@@ -0,0 +1,14 @@
+{ %fail }
+{ %target=darwin }
+{ %cpu=powerpc,i386 }
+
+{$modeswitch objectivec1}
+
+type
+  ta = objcclass
+    { no destructors in Objective-C }
+    destructor done;
+  end; external;
+
+begin
+end.