Yet more Objective-C++...
authorZiemowit Laski <zlaski@apple.com>
Tue, 17 May 2005 20:11:44 +0000 (20:11 +0000)
committerMike Stump <mrs@gcc.gnu.org>
Tue, 17 May 2005 20:11:44 +0000 (20:11 +0000)
        * c-common.h (objc_finish_try_stmt): Add.
        (objc_build_synchronized): Add.
        (objc_generate_write_barrier): Add.
        * stub-objc.c (objc_build_synchronized): Add return value.
        (objc_finish_try_stmt): Likewise.
        (objc_generate_write_barrier): Add.

        * c-common.h (objc_rewrite_function_call): Add.
        * c-typeck.c (build_function_call): Allow objc to rewrite
        FUNCTION_DECLs.
        (build_modify_expr): Allow objc to generate write barriers.
        * c.opt (Wassign-intercept): Add.
        (Wstrict-selector-match): Add.
        (fobjc-call-cxx-cdtors): Add.
        (fobjc-direct-dispatch): Add.
        (fobjc-gc): Add.
        * dbxout.c (get_lang_number): Add Objective-C++ support.
        * doc/invoke.texi (-fobjc-call-cxx-cdtors): Likewise.
        (-Wstrict-selector-match): Likewise.
        (-fobjc-direct-dispatch): Likewise.
        (-Wassign-intercept): Likewise.
        (Overall Options): Likewise.
        * gengtype.c (get_output_file_with_visibility): Likewise.
        * stub-objc.c (objc_rewrite_function_call): Add.
        * config/darwin.h (ASM_OUTPUT_LABELREF): Improved quoting support.

        * c-common.c (flag_objc_exceptions): Remove.
        (flag_objc_sjlj_exceptions): Remove.
        * c-decl.c (objc_mark_locals_volatile): Don't change decls
        that are already ok.
        * c-opts.c (c_common_handle_option, case
        OPT_fobjc_exceptions): Remove.
        (case OPT_fobjc_sjlj_exceptions): Remove
        * c.opt (fobjc-call-cxx-cdtors): Have opt create the flag.
        (fobjc-exceptions): Likewise.
        (fobjc-sjlj-exceptions): Likewise.
        * config/rs6000/darwin.h (OFFS_MSGSEND_FAST): Add.
        (OFFS_ASSIGNIVAR_FAST): Add.

From-SVN: r99858

13 files changed:
gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-decl.c
gcc/c-opts.c
gcc/c-typeck.c
gcc/c.opt
gcc/config/darwin.h
gcc/config/rs6000/darwin.h
gcc/dbxout.c
gcc/doc/invoke.texi
gcc/gengtype.c
gcc/stub-objc.c

index 761c6d0c1f35c36e4f4b5186e4bafaf456fa540e..127f1049574f04a06b1fab364f4d4f9762828446 100644 (file)
@@ -1,3 +1,46 @@
+2005-05-17  Mike Stump  <mrs@apple.com>
+
+       Yet more Objective-C++...
+
+       * c-common.h (objc_finish_try_stmt): Add.
+       (objc_build_synchronized): Add.
+       (objc_generate_write_barrier): Add.
+       * stub-objc.c (objc_build_synchronized): Add return value.
+       (objc_finish_try_stmt): Likewise.
+       (objc_generate_write_barrier): Add.
+
+       * c-common.h (objc_rewrite_function_call): Add.
+       * c-typeck.c (build_function_call): Allow objc to rewrite
+       FUNCTION_DECLs.
+       (build_modify_expr): Allow objc to generate write barriers.
+       * c.opt (Wassign-intercept): Add.
+       (Wstrict-selector-match): Add.
+       (fobjc-call-cxx-cdtors): Add.
+       (fobjc-direct-dispatch): Add.
+       (fobjc-gc): Add.
+       * dbxout.c (get_lang_number): Add Objective-C++ support.
+       * doc/invoke.texi (-fobjc-call-cxx-cdtors): Likewise.
+       (-Wstrict-selector-match): Likewise.
+       (-fobjc-direct-dispatch): Likewise.
+       (-Wassign-intercept): Likewise.
+       (Overall Options): Likewise.
+       * gengtype.c (get_output_file_with_visibility): Likewise.
+       * stub-objc.c (objc_rewrite_function_call): Add.
+       * config/darwin.h (ASM_OUTPUT_LABELREF): Improved quoting support.
+
+       * c-common.c (flag_objc_exceptions): Remove.
+       (flag_objc_sjlj_exceptions): Remove.
+       * c-decl.c (objc_mark_locals_volatile): Don't change decls
+       that are already ok.
+       * c-opts.c (c_common_handle_option, case
+       OPT_fobjc_exceptions): Remove.
+       (case OPT_fobjc_sjlj_exceptions): Remove
+       * c.opt (fobjc-call-cxx-cdtors): Have opt create the flag.
+       (fobjc-exceptions): Likewise.
+       (fobjc-sjlj-exceptions): Likewise.
+       * config/rs6000/darwin.h (OFFS_MSGSEND_FAST): Add.
+       (OFFS_ASSIGNIVAR_FAST): Add.
+       
 2005-05-17  Eric Botcazou  <ebotcazou@libertysurf.fr>
 
        * config/sparc/sparc.md (movhi): Do not test constness
@@ -38,6 +81,7 @@
        * cfgloopanal.c (just_once_each_iteration_p): Make the loop argument
        const.
 
+>>>>>>> 2.8834
 2005-05-17  Zdenek Dvorak  <dvorakz@suse.cz>
 
        * ggc-page.c (ggc_alloc_stat): Record amount of memory allocated.
index ecbe4024956d12056b32183b0fc7db88f55c8f2f..c9027463795546d8820414901a404eac0ac437e7 100644 (file)
@@ -290,13 +290,6 @@ int warn_strict_null_sentinel;
    will most likely result in crashes.  */
 int flag_nil_receivers = 1;
 
-/* Nonzero means that we will allow new ObjC exception syntax (@throw,
-   @try, etc.) in source code.  */
-int flag_objc_exceptions = 0;
-
-/* Nonzero means that we generate NeXT setjmp based exceptions.  */
-int flag_objc_sjlj_exceptions = -1;
-
 /* Nonzero means that code generation will be altered to support
    "zero-link" execution.  This currently affects ObjC only, but may
    affect other languages in the future.  */
index 94532cc1e6e80c4c37c3b687b1d9849ee79a91c5..e4c899dbc8eb9207cd4738846f49f514a96aee7a 100644 (file)
@@ -874,6 +874,7 @@ extern tree objc_is_object_ptr (tree);
 extern void objc_check_decl (tree);
 extern int objc_is_reserved_word (tree);
 extern int objc_comptypes (tree, tree, int);
+extern tree objc_rewrite_function_call (tree, tree);
 extern tree objc_message_selector (void);
 extern tree objc_lookup_ivar (tree, tree);
 extern void objc_clear_super_receiver (void);
@@ -910,13 +911,14 @@ extern void objc_add_instance_variable (tree);
 extern tree objc_build_keyword_decl (tree, tree, tree);
 extern tree objc_build_throw_stmt (tree);
 extern void objc_begin_try_stmt (location_t, tree);
-extern void objc_finish_try_stmt (void);
+extern tree objc_finish_try_stmt (void);
 extern void objc_begin_catch_clause (tree);
 extern void objc_finish_catch_clause (void);
 extern void objc_build_finally_clause (location_t, tree);
-extern void objc_build_synchronized (location_t, tree, tree);
+extern tree objc_build_synchronized (location_t, tree, tree);
 extern int objc_static_init_needed_p (void);
 extern tree objc_generate_static_init_call (tree);
+extern tree objc_generate_write_barrier (tree, enum tree_code, tree);
 
 /* The following are provided by the C and C++ front-ends, and called by
    ObjC/ObjC++.  */
index e189d3629dd363d29338dea15bbacaac66cda8ae..b71838755f8f2dadb737c1582b876eb57785cc5d 100644 (file)
@@ -567,12 +567,22 @@ objc_mark_locals_volatile (void *enclosing_blk)
     {
       for (b = scope->bindings; b; b = b->prev)
        {
-         if (TREE_CODE (b->decl) == VAR_DECL
-             || TREE_CODE (b->decl) == PARM_DECL)
+         tree decl = b->decl;
+
+         /* Do not mess with variables that are 'static' or (already)
+            'volatile'.  */
+         if (!TREE_THIS_VOLATILE (decl) && !TREE_STATIC (decl)
+             && (TREE_CODE (decl) == VAR_DECL
+                 || TREE_CODE (decl) == PARM_DECL))
            {
-             C_DECL_REGISTER (b->decl) = 0;
-             DECL_REGISTER (b->decl) = 0;
-             TREE_THIS_VOLATILE (b->decl) = 1;
+             TREE_TYPE (decl)
+               = build_qualified_type (TREE_TYPE (decl),
+                                       (TYPE_QUALS (TREE_TYPE (decl))
+                                        | TYPE_QUAL_VOLATILE));
+             TREE_THIS_VOLATILE (decl) = 1;
+             TREE_SIDE_EFFECTS (decl) = 1;
+             DECL_REGISTER (decl) = 0;
+             C_DECL_REGISTER (decl) = 0;
            }
        }
 
index ebf23e571d79fb5a94d7930ffb1e6040f5f25e65..fd0765cf71fbdcf0843a040069886be96f295e96 100644 (file)
@@ -699,14 +699,6 @@ c_common_handle_option (size_t scode, const char *arg, int value)
       flag_no_nonansi_builtin = !value;
       break;
 
-    case OPT_fobjc_exceptions:
-      flag_objc_exceptions = value;
-      break;
-
-    case OPT_fobjc_sjlj_exceptions:
-      flag_objc_sjlj_exceptions = value;
-      break;
-
     case OPT_foperator_names:
       cpp_opts->operator_names = value;
       break;
index 04fa74540238c145aa19718f57777b4261ff3864..e8b2b372e1d3c1be83cd2b5f925957735ca86d87 100644 (file)
@@ -2023,6 +2023,10 @@ build_function_call (tree function, tree params)
   else
     function = default_conversion (function);
 
+  /* For Objective-C, convert any calls via a cast to OBJC_TYPE_REF
+     expressions, like those used for ObjC messenger dispatches.  */
+  function = objc_rewrite_function_call (function, params);
+
   fntype = TREE_TYPE (function);
 
   if (TREE_CODE (fntype) == ERROR_MARK)
@@ -3485,6 +3489,14 @@ build_modify_expr (tree lhs, enum tree_code modifycode, tree rhs)
   if (TREE_CODE (newrhs) == ERROR_MARK)
     return error_mark_node;
 
+  /* Emit ObjC write barrier, if necessary.  */
+  if (c_dialect_objc () && flag_objc_gc)
+    {
+      result = objc_generate_write_barrier (lhs, modifycode, newrhs);
+      if (result)
+       return result;
+    }
+
   /* Scan operands.  */
 
   result = build2 (MODIFY_EXPR, lhstype, lhs, newrhs);
index 4467df3eb80765bd8bd4018481a18821d975cb68..976f6e9c3556e8a0258617834c32227bcf1373de 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -120,6 +120,10 @@ Wall
 C ObjC C++ ObjC++
 Enable most warning messages
 
+Wassign-intercept
+ObjC ObjC++ Var(warn_assign_intercept)
+Warn whenever an Objective-C assignment is being intercepted by the garbage collector
+
 Wbad-function-cast
 C ObjC Var(warn_bad_function_cast)
 Warn about casting functions to incompatible types
@@ -362,6 +366,10 @@ Wstrict-prototypes
 C ObjC Var(warn_strict_prototypes)
 Warn about unprototyped function declarations
 
+Wstrict-selector-match
+ObjC ObjC++ Var(warn_strict_selector_match)
+Warn if type signatures of candidate methods do not match exactly
+
 Wsynth
 C++ ObjC++ Var(warn_synth)
 Warn when synthesis behavior differs from Cfront
@@ -564,12 +572,29 @@ C++ ObjC++
 fnonnull-objects
 C++ ObjC++
 
+; Generate special '- .cxx_construct' and '- .cxx_destruct' methods
+; to initialize any non-POD ivars in Objective-C++ classes.
+fobjc-call-cxx-cdtors
+ObjC++ Var(flag_objc_call_cxx_cdtors)
+Generate special Objective-C methods to initialize/destroy non-POD C++ ivars, if needed
+
+fobjc-direct-dispatch
+ObjC ObjC++ Var(flag_objc_direct_dispatch)
+Allow fast jumps to the message dispatcher
+
+; Nonzero means that we will allow new ObjC exception syntax (@throw,
+; @try, etc.) in source code.
 fobjc-exceptions
-ObjC ObjC++
+ObjC ObjC++ Var(flag_objc_exceptions)
 Enable Objective-C exception and synchronization syntax
 
+fobjc-gc
+ObjC ObjC++ Var(flag_objc_gc)
+Enable garbage collection (GC) in Objective-C/Objective-C++ programs
+
+; Nonzero means that we generate NeXT setjmp based exceptions.
 fobjc-sjlj-exceptions
-ObjC ObjC++
+ObjC ObjC++ Var(flag_objc_sjlj_exceptions) Init(-1)
 Enable Objective-C setjmp exception handling runtime
 
 foperator-names
index 3ccfea6a5f52467afc3660ff34c59aa33a1c4bf5..c2a53d0b45e7883b20c2128044225f087302928b 100644 (file)
@@ -533,7 +533,10 @@ Boston, MA 02111-1307, USA.  */
             machopic_validate_stub_or_non_lazy_ptr (xname);                 \
           else if (len > 14 && !strcmp ("$non_lazy_ptr", xname + len - 13)) \
             machopic_validate_stub_or_non_lazy_ptr (xname);                 \
-          fputs (&xname[1], FILE);                                          \
+          if (xname[1] != '"' && name_needs_quotes (&xname[1]))             \
+            fprintf (FILE, "\"%s\"", &xname[1]);                            \
+          else                                                              \
+            fputs (&xname[1], FILE);                                        \
         }                                                                   \
        else if (xname[0] == '+' || xname[0] == '-')                         \
          fprintf (FILE, "\"%s\"", xname);                                   \
@@ -541,6 +544,8 @@ Boston, MA 02111-1307, USA.  */
          fprintf (FILE, "L%s", xname);                                      \
        else if (!strncmp (xname, ".objc_class_name_", 17))                  \
         fprintf (FILE, "%s", xname);                                        \
+       else if (xname[0] != '"' && name_needs_quotes (xname))               \
+        fprintf (FILE, "\"%s\"", xname);                                    \
        else                                                                 \
          asm_fprintf (FILE, "%U%s", xname);                                 \
   } while (0)
index 58ef8db958276ce8cc4d10b12ef7cbd5b0aaf6ae..3890dea12d8eae2f48bbd2b6d1a8d77ff81042ca 100644 (file)
@@ -407,3 +407,9 @@ do {                                                                        \
    references for data to the original instance of that data.  */
 
 #define TARGET_FIX_AND_CONTINUE (darwin_fix_and_continue)
+
+/* This is the reserved direct dispatch address for Objective-C.  */
+#define OFFS_MSGSEND_FAST              0xFFFEFF00
+
+/* This is the reserved ivar address Objective-C.  */
+#define OFFS_ASSIGNIVAR_FAST           0xFFFEFEC0
index c4cae3fc7fa57751be3a9e0cb77e0c78280ee868..a4a036bb51f8aa31351a37d02b956fbb83ce8c45 100644 (file)
@@ -971,6 +971,8 @@ get_lang_number (void)
     return N_SO_PASCAL;
   else if (strcmp (language_string, "GNU Objective-C") == 0)
     return N_SO_OBJC;
+  else if (strcmp (language_string, "GNU Objective-C++") == 0)
+    return N_SO_OBJCPLUS;
   else
     return 0;
 
index 77c94e53c1ede1f95377547cc654b710f8254d27..96e3823b81548c5b2aec1b91c113dfeb7ba47dc7 100644 (file)
@@ -197,11 +197,17 @@ Objective-C and Objective-C++ Dialects}.
 -fconstant-string-class=@var{class-name} @gol
 -fgnu-runtime  -fnext-runtime @gol
 -fno-nil-receivers @gol
+-fobjc-call-cxx-cdtors @gol
+-fobjc-direct-dispatch @gol
 -fobjc-exceptions @gol
+-fobjc-gc @gol
 -freplace-objc-classes @gol
 -fzero-link @gol
 -gen-decls @gol
--Wno-protocol  -Wselector -Wundeclared-selector}
+-Wassign-intercept @gol
+-Wno-protocol  -Wselector @gol
+-Wstrict-selector-match @gol
+-Wundeclared-selector}
 
 @item Language Independent Options
 @xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}.
@@ -816,6 +822,13 @@ C++ source code which must be preprocessed.  Note that in @samp{.cxx},
 the last two letters must both be literally @samp{x}.  Likewise,
 @samp{.C} refers to a literal capital C@.
 
+@item @var{file}.mm
+@itemx @var{file}.M
+Objective-C++ source code which must be preprocessed.
+
+@item @var{file}.mii
+Objective-C++ source code which should not be preprocessed.
+
 @item @var{file}.hh
 @itemx @var{file}.H
 C++ header file to be turned into a precompiled header.
@@ -1897,6 +1910,35 @@ is not @code{nil}.  This allows for more efficient entry points in the runtime
 to be used.  Currently, this option is only available in conjunction with
 the NeXT runtime on Mac OS X 10.3 and later.
 
+@item -fobjc-call-cxx-cdtors
+@opindex fobjc-call-cxx-cdtors
+For each Objective-C class, check if any of its instance variables is a
+C++ object with a non-trivial default constructor.  If so, synthesize a
+special @code{- (id) .cxx_construct} instance method that will run
+non-trivial default constructors on any such instance variables, in order,
+and then return @code{self}.  Similarly, check if any instance variable
+is a C++ object with a non-trivial destructor, and if so, synthesize a
+special @code{- (void) .cxx_destruct} method that will run
+all such default destructors, in reverse order.
+
+The @code{- (id) .cxx_construct} and/or @code{- (void) .cxx_destruct} methods
+thusly generated will only operate on instance variables declared in the
+current Objective-C class, and not those inherited from superclasses.  It
+is the responsibility of the Objective-C runtime to invoke all such methods
+in an object's inheritance hierarchy.  The @code{- (id) .cxx_construct} methods
+will be invoked by the runtime immediately after a new object
+instance is allocated; the @code{- (void) .cxx_destruct} methods will
+be invoked immediately before the runtime deallocates an object instance.
+
+As of this writing, only the NeXT runtime on Mac OS X 10.4 and later has
+support for invoking the @code{- (id) .cxx_construct} and
+@code{- (void) .cxx_destruct} methods.
+
+@item -fobjc-direct-dispatch
+@opindex fobjc-direct-dispatch
+Allow fast jumps to the message dispatcher.  On Darwin this is
+accompilished via the comm page.
+
 @item -fobjc-exceptions
 @opindex fobjc-exceptions
 Enable syntactic support for structured exception handling in Objective-C,
@@ -1989,6 +2031,10 @@ Unlike Java, Objective-C does not allow for entire methods to be marked
 @code{@@synchronized} blocks is allowed, and will cause the guarding object
 to be unlocked properly.
 
+@item -fobjc-gc
+@opindex fobjc-gc
+Enable garbage collection (GC) in Objective-C and Objective-C++ programs.
+
 @item -freplace-objc-classes
 @opindex freplace-objc-classes
 Emit a special marker instructing @command{ld(1)} not to statically link in
@@ -2015,6 +2061,11 @@ for individual class implementations to be modified during program execution.
 Dump interface declarations for all classes seen in the source file to a
 file named @file{@var{sourcename}.decl}.
 
+@item -Wassign-intercept
+@opindex Wassign-intercept
+Warn whenever an Objective-C assignment is being intercepted by the
+garbage collector.
+
 @item -Wno-protocol
 @opindex Wno-protocol
 If a class is declared to implement a protocol, a warning is issued for
@@ -2038,6 +2089,15 @@ stage of compilation is not reached, for example because an error is
 found during compilation, or because the @option{-fsyntax-only} option is
 being used.
 
+@item -Wstrict-selector-match
+@opindex Wstrict-selector-match
+Warn if multiple methods with differing argument and/or return types are
+found for a given selector when attempting to send a message using this
+selector to a receiver of type @code{id} or @code{Class}.  When this flag
+is off (which is the default behavior), the compiler will omit such warnings
+if any differences found are confined to types which share the same size
+and alignment.
+
 @item -Wundeclared-selector
 @opindex Wundeclared-selector
 Warn if a @code{@@selector(@dots{})} expression referring to an
index 2b6cc0fef05d8ba10cdd9f79a41a0bb6f778342b..519ff7258d2cfd1f9d232bd8f89712c3f144e865 100644 (file)
@@ -1238,6 +1238,15 @@ get_output_file_with_visibility (const char *input_file)
     output_name = "gt-c-common.h", for_name = "c-common.c";
   else if (strcmp (basename, "c-tree.h") == 0)
     output_name = "gt-c-decl.h", for_name = "c-decl.c";
+  else if (strncmp (basename, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename[2])
+          && strcmp (basename + 3, "cp-tree.h") == 0)
+    output_name = "gt-cp-tree.h", for_name = "cp/tree.c";
+  else if (strncmp (basename, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename[2])
+          && strcmp (basename + 3, "decl.h") == 0)
+    output_name = "gt-cp-decl.h", for_name = "cp/decl.c";
+  else if (strncmp (basename, "cp", 2) == 0 && IS_DIR_SEPARATOR (basename[2])
+          && strcmp (basename + 3, "name-lookup.h") == 0)
+    output_name = "gt-cp-name-lookup.h", for_name = "cp/name-lookup.c";
   else if (strncmp (basename, "objc", 4) == 0 && IS_DIR_SEPARATOR (basename[4])
           && strcmp (basename + 5, "objc-act.h") == 0)
     output_name = "gt-objc-objc-act.h", for_name = "objc/objc-act.c";
index 481183fd9423c1ac7c70b39ab8a4e9291123e1d3..ed9ac97258f4416eff28e4781eee20f8ee9409f0 100644 (file)
@@ -70,6 +70,12 @@ objc_comptypes (tree ARG_UNUSED (lhs), tree ARG_UNUSED (rhs),
   return -1;
 }
 
+tree
+objc_rewrite_function_call (tree function, tree ARG_UNUSED (params))
+{
+  return function;
+}
+
 tree
 objc_message_selector (void)
 { 
@@ -257,21 +263,22 @@ objc_is_public (tree ARG_UNUSED (expr), tree ARG_UNUSED (identifier))
 }
 
 tree
-objc_get_class_ivars (tree ARG_UNUSED (class_name))
+objc_get_class_ivars (tree ARG_UNUSED (name))
 {
   return 0;
 }
 
 tree
-objc_build_throw_stmt (tree ARG_UNUSED (throw_expr))
+objc_build_throw_stmt (tree ARG_UNUSED (expr))
 {
   return 0;
 }
 
-void
+tree
 objc_build_synchronized (location_t ARG_UNUSED (start_locus),
                         tree ARG_UNUSED (mutex), tree ARG_UNUSED (body))
 {
+  return 0;
 }
 
 void
@@ -295,7 +302,16 @@ objc_build_finally_clause (location_t ARG_UNUSED (finally_locus),
 {
 }
 
-void
+tree
 objc_finish_try_stmt (void)
 {
+  return 0;
 }
+
+tree
+objc_generate_write_barrier (tree ARG_UNUSED (lhs),
+                            enum tree_code ARG_UNUSED (modifycode),
+                            tree ARG_UNUSED (rhs))
+{
+  return 0;
+}