OSDN Git Service

gcc
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / symbian.c
index b729fea..abe685b 100644 (file)
@@ -1,5 +1,5 @@
 /* Routines for GCC for a Symbian OS targeted SH backend.
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
    Contributed by RedHat.
    Most of this code is stolen from i386/winnt.c.
 
@@ -7,7 +7,7 @@
 
    GCC is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published
-   by the Free Software Foundation; either version 2, or (at your
+   by the Free Software Foundation; either version 3, or (at your
    option) any later version.
 
    GCC is distributed in the hope that it will be useful, but WITHOUT
@@ -16,9 +16,8 @@
    License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GCC; see the file COPYING.  If not, write to
-   the Free Software Foundation, 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include "system.h"
@@ -38,8 +37,8 @@
    1 for informative messages about decisions to add attributes
    2 for verbose information about what is being done.  */
 #define SYMBIAN_DEBUG 0
-//#define SYMBIAN_DEBUG 1
-//#define SYMBIAN_DEBUG 2
+/* #define SYMBIAN_DEBUG 1 */
+/* #define SYMBIAN_DEBUG 2 */
 
 /* A unique character to encode declspec encoded objects.  */
 #define SH_SYMBIAN_FLAG_CHAR "$"
@@ -144,8 +143,9 @@ sh_symbian_dllimport_p (tree decl)
     {
       /* Don't warn about artificial methods.  */
       if (!DECL_ARTIFICIAL (decl))
-       warning ("%H function '%D' is defined after prior declaration as dllimport: attribute ignored",
-                & DECL_SOURCE_LOCATION (decl), decl);
+       warning (OPT_Wattributes, "function %q+D is defined after prior "
+                "declaration as dllimport: attribute ignored",
+                decl);
       return false;
     }
 
@@ -155,8 +155,9 @@ sh_symbian_dllimport_p (tree decl)
   else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
     {
       if (extra_warnings)
-       warning ("%Hinline function '%D' is declared as dllimport: attribute ignored.",
-                & DECL_SOURCE_LOCATION (decl), decl);
+       warning (OPT_Wattributes, "inline function %q+D is declared as "
+                "dllimport: attribute ignored",
+                decl);
       return false;
     }
 
@@ -168,8 +169,8 @@ sh_symbian_dllimport_p (tree decl)
           && !DECL_EXTERNAL (decl))
     {
       if (!DECL_VIRTUAL_P (decl))
-       error ("%Hdefinition of static data member '%D' of dllimport'd class.",
-              & DECL_SOURCE_LOCATION (decl), decl);
+       error ("definition of static data member %q+D of dllimport'd class",
+              decl);
       return false;
     }
 
@@ -205,7 +206,7 @@ sh_symbian_dllimport_name_p (const char *symbol)
 }
 
 /* Mark a DECL as being dllexport'd.
-   Note that we override the previous setting (eg: dllimport).  */
+   Note that we override the previous setting (e.g.: dllimport).  */
 
 static void
 sh_symbian_mark_dllexport (tree decl)
@@ -216,14 +217,10 @@ sh_symbian_mark_dllexport (tree decl)
   tree idp;
 
   rtlname = XEXP (DECL_RTL (decl), 0);
-
-  if (GET_CODE (rtlname) == SYMBOL_REF)
-    oldname = XSTR (rtlname, 0);
-  else if (GET_CODE (rtlname) == MEM
-          && GET_CODE (XEXP (rtlname, 0)) == SYMBOL_REF)
-    oldname = XSTR (XEXP (rtlname, 0), 0);
-  else
-    abort ();
+  if (GET_CODE (rtlname) == MEM)
+    rtlname = XEXP (rtlname, 0);
+  gcc_assert (GET_CODE (rtlname) == SYMBOL_REF);
+  oldname = XSTR (rtlname, 0);
 
   if (sh_symbian_dllimport_name_p (oldname))
     {
@@ -235,7 +232,7 @@ sh_symbian_mark_dllexport (tree decl)
        unit which has included the header in order to ensure argument
        correctness.  */
       oldname += strlen (DLL_IMPORT_PREFIX);
-      DECL_NON_ADDR_CONST_P (decl) = 0;
+      DECL_DLLIMPORT_P (decl) = 0;
     }
   else if (sh_symbian_dllexport_name_p (oldname))
     return; /* Already done.  */
@@ -265,26 +262,22 @@ sh_symbian_mark_dllimport (tree decl)
   rtx newrtl;
 
   rtlname = XEXP (DECL_RTL (decl), 0);
-
-  if (GET_CODE (rtlname) == SYMBOL_REF)
-    oldname = XSTR (rtlname, 0);
-  else if (GET_CODE (rtlname) == MEM
-          && GET_CODE (XEXP (rtlname, 0)) == SYMBOL_REF)
-    oldname = XSTR (XEXP (rtlname, 0), 0);
-  else
-    abort ();
+  if (GET_CODE (rtlname) == MEM)
+    rtlname = XEXP (rtlname, 0);
+  gcc_assert (GET_CODE (rtlname) == SYMBOL_REF);
+  oldname = XSTR (rtlname, 0);
 
   if (sh_symbian_dllexport_name_p (oldname))
     {
-      error ("`%s' declared as both exported to and imported from a DLL",
+      error ("%qs declared as both exported to and imported from a DLL",
              IDENTIFIER_POINTER (DECL_NAME (decl)));
     }
   else if (sh_symbian_dllimport_name_p (oldname))
     {
       /* Already done, but do a sanity check to prevent assembler errors.  */
       if (!DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
-       error ("%Hfailure in redeclaration of '%D': dllimport'd symbol lacks external linkage.",
-              &DECL_SOURCE_LOCATION (decl), decl);
+       error ("failure in redeclaration of %q+D: dllimport'd symbol lacks external linkage",
+              decl);
     }
   else
     {
@@ -315,7 +308,7 @@ sh_symbian_encode_section_info (tree decl, rtx rtl, int first)
   /* It might be that DECL has already been marked as dllimport, but a
      subsequent definition nullified that.  The attribute is gone but
      DECL_RTL still has (DLL_IMPORT_PREFIX) prefixed. We need to remove
-     that. Ditto for the DECL_NON_ADDR_CONST_P flag.  */
+     that. Ditto for the DECL_DLLIMPORT_P flag.  */
   else if (  (TREE_CODE (decl) == FUNCTION_DECL
           || TREE_CODE (decl) == VAR_DECL)
           && DECL_RTL (decl) != NULL_RTX
@@ -329,15 +322,14 @@ sh_symbian_encode_section_info (tree decl, rtx rtl, int first)
       tree idp = get_identifier (oldname + strlen (DLL_IMPORT_PREFIX));
       rtx newrtl = gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (idp));
 
-      warning ("%H%s '%D' %s after being referenced with dllimport linkage.",
-              & DECL_SOURCE_LOCATION (decl),
+      warning (0, "%s %q+D %s after being referenced with dllimport linkage",
               TREE_CODE (decl) == VAR_DECL ? "variable" : "function",
               decl, (DECL_INITIAL (decl) || !DECL_EXTERNAL (decl))
               ? "defined locally" : "redeclared without dllimport attribute");
 
       XEXP (DECL_RTL (decl), 0) = newrtl;
 
-      DECL_NON_ADDR_CONST_P (decl) = 0;
+      DECL_DLLIMPORT_P (decl) = 0;
     }
 }
 
@@ -382,11 +374,13 @@ symbian_add_attribute (tree node, const char *attr_name)
 
   attr = get_identifier (attr_name);
 
-  (DECL_P (node) ? DECL_ATTRIBUTES (node) : TYPE_ATTRIBUTES (node))
-    = tree_cons (attr, NULL_TREE, attrs);
+  if (DECL_P (node))
+    DECL_ATTRIBUTES (node) = tree_cons (attr, NULL_TREE, attrs);
+  else
+    TYPE_ATTRIBUTES (node) = tree_cons (attr, NULL_TREE, attrs);
 
 #if SYMBIAN_DEBUG
-  fprintf (stderr, "propogate %s attribute", attr_name);
+  fprintf (stderr, "propagate %s attribute", attr_name);
   print_node_brief (stderr, " to", node, 0);
   fprintf (stderr, "\n");
 #endif
@@ -411,14 +405,14 @@ sh_symbian_handle_dll_attribute (tree *pnode, tree name, tree args,
                   | (int) ATTR_FLAG_FUNCTION_NEXT
                   | (int) ATTR_FLAG_ARRAY_NEXT))
        {
-         warning ("`%s' attribute ignored", attr);
+         warning (OPT_Wattributes, "%qs attribute ignored", attr);
          *no_add_attrs = true;
          return tree_cons (name, args, NULL_TREE);
        }
 
       if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
        {
-         warning ("`%s' attribute ignored", attr);
+         warning (OPT_Wattributes, "%qs attribute ignored", attr);
          *no_add_attrs = true;
        }
 
@@ -433,8 +427,8 @@ sh_symbian_handle_dll_attribute (tree *pnode, tree name, tree args,
        {
          if (DECL_INITIAL (node))
            {
-             error ("%Hvariable `%D' definition is marked dllimport.",
-                    & DECL_SOURCE_LOCATION (node), node);
+             error ("variable %q+D definition is marked dllimport",
+                    node);
              *no_add_attrs = true;
            }
 
@@ -508,8 +502,8 @@ sh_symbian_handle_dll_attribute (tree *pnode, tree name, tree args,
       && (   TREE_CODE (node) == VAR_DECL
          || TREE_CODE (node) == FUNCTION_DECL))
     {
-      error ("%Hexternal linkage required for symbol '%D' because of '%s' attribute.",
-              & DECL_SOURCE_LOCATION (node), node, IDENTIFIER_POINTER (name));
+      error ("external linkage required for symbol %q+D because of %qs attribute",
+            node, IDENTIFIER_POINTER (name));
       *no_add_attrs = true;
     }
 
@@ -556,19 +550,18 @@ sh_symbian_handle_dll_attribute (tree *pnode, tree name, tree args,
 static void
 symbian_possibly_export_base_class (tree base_class)
 {
-  tree methods;
+  VEC(tree,gc) *method_vec;
   int len;
 
-  if (! (TYPE_POLYMORPHIC_P (base_class)
-        || TYPE_USES_VIRTUAL_BASECLASSES (base_class)))
+  if (! (TYPE_CONTAINS_VPTR_P (base_class)))
     return;
 
-  methods = CLASSTYPE_METHOD_VEC (base_class);
-  len = methods ? TREE_VEC_LENGTH (methods) : 0;
+  method_vec = CLASSTYPE_METHOD_VEC (base_class);
+  len = method_vec ? VEC_length (tree, method_vec) : 0;
 
   for (;len --;)
     {
-      tree member = TREE_VEC_ELT (methods, len);
+      tree member = VEC_index (tree, method_vec, len);
 
       if (! member)
        continue;
@@ -619,7 +612,7 @@ symbian_export_vtable_and_rtti_p (tree ctype)
   bool dllimport_ctor_dtor;
   bool dllimport_member;
   tree binfo, base_binfo;
-  tree methods;
+  VEC(tree,gc) *method_vec;
   tree key;
   int i;
   int len;
@@ -661,12 +654,12 @@ symbian_export_vtable_and_rtti_p (tree ctype)
   dllimport_ctor_dtor = false;
   dllimport_member = false;
 
-  methods = CLASSTYPE_METHOD_VEC (ctype);
-  len = methods ? TREE_VEC_LENGTH (methods) : 0;
+  method_vec = CLASSTYPE_METHOD_VEC (ctype);
+  len = method_vec ? VEC_length (tree, method_vec) : 0;
 
   for (;len --;)
     {
-      tree member = TREE_VEC_ELT (methods, len);
+      tree member = VEC_index (tree, method_vec, len);
 
       if (! member)
        continue;
@@ -762,22 +755,27 @@ symbian_add_attribute_to_class_vtable_and_rtti (tree ctype, const char *attr_nam
 static bool
 symbian_class_needs_attribute_p (tree ctype, const char *attribute_name)
 {
+  VEC(tree,gc) *method_vec;
+
+  method_vec = CLASSTYPE_METHOD_VEC (ctype);
+
   /* If the key function has the attribute then the class needs it too.  */
   if (TYPE_POLYMORPHIC_P (ctype)
-      && CLASSTYPE_KEY_METHOD (ctype)
+      && method_vec
       && lookup_attribute (attribute_name,
-                          DECL_ATTRIBUTES (CLASSTYPE_KEY_METHOD (ctype))))
+                          DECL_ATTRIBUTES (VEC_index (tree, method_vec, 0))))
     return true;
 
   /* Check the class's member functions.  */
   if (TREE_CODE (ctype) == RECORD_TYPE)
     {
-      tree methods = CLASSTYPE_METHOD_VEC (ctype);
-      unsigned int len = methods ? TREE_VEC_LENGTH (methods) : 0;
+      unsigned int len;
+
+      len = method_vec ? VEC_length (tree, method_vec) : 0;
 
       for (;len --;)
        {
-         tree member = TREE_VEC_ELT (methods, len);
+         tree member = VEC_index (tree, method_vec, len);
 
          if (! member)
            continue;