OSDN Git Service

* gcc-interface/trans.c (can_equal_min_or_max_val_p): Be prepared for
[pf3gnuchains/gcc-fork.git] / gcc / cp / expr.c
index 34f779e..c521e7d 100644 (file)
@@ -1,46 +1,38 @@
 /* Convert language-specific tree expression to rtl instructions,
    for GNU compiler.
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   2000, 2001 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2007, 2010 Free Software Foundation, Inc.
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
+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 option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
-GNU CC is distributed in the hope that it will be useful,
+GCC is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU CC; 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"
-#include "rtl.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "tree.h"
 #include "flags.h"
-#include "expr.h"
 #include "cp-tree.h"
-#include "toplev.h"
-#include "except.h"
 #include "tm_p.h"
 
-static rtx cplus_expand_expr PARAMS ((tree, rtx, enum machine_mode,
-                                   enum expand_modifier));
-
-/* Hook used by output_constant to expand language-specific
-   constants.  */
+/* Expand C++-specific constants.  Currently, this means PTRMEM_CST.  */
 
 tree
-cplus_expand_constant (cst)
-     tree cst;
+cplus_expand_constant (tree cst)
 {
   switch (TREE_CODE (cst))
     {
@@ -48,15 +40,25 @@ cplus_expand_constant (cst)
       {
        tree type = TREE_TYPE (cst);
        tree member;
-      
+
        /* Find the member.  */
        member = PTRMEM_CST_MEMBER (cst);
 
-       if (TREE_CODE (member) == FIELD_DECL) 
+       if (TREE_CODE (member) == FIELD_DECL)
          {
            /* Find the offset for the field.  */
-           tree offset = byte_position (member);
-           cst = fold (build1 (NOP_EXPR, type, offset));
+           cst = byte_position (member);
+           while (!same_type_p (DECL_CONTEXT (member),
+                                TYPE_PTRMEM_CLASS_TYPE (type)))
+             {
+               /* The MEMBER must have been nestled within an
+                  anonymous aggregate contained in TYPE.  Find the
+                  anonymous aggregate.  */
+               member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
+                                           DECL_CONTEXT (member));
+               cst = size_binop (PLUS_EXPR, cst, byte_position (member));
+             }
+           cst = fold (build_nop (type, cst));
          }
        else
          {
@@ -77,70 +79,72 @@ cplus_expand_constant (cst)
   return cst;
 }
 
-/* Hook used by expand_expr to expand language-specific tree codes.  */
+/* Called whenever an expression is used
+   in a rvalue context.  */
 
-static rtx
-cplus_expand_expr (exp, target, tmode, modifier)
-     tree exp;
-     rtx target;
-     enum machine_mode tmode;
-     enum expand_modifier modifier;
+tree
+mark_rvalue_use (tree expr)
 {
-  tree type = TREE_TYPE (exp);
-  register enum machine_mode mode = TYPE_MODE (type);
-  register enum tree_code code = TREE_CODE (exp);
-  rtx ret;
+  mark_exp_read (expr);
+  return expr;
+}
 
-  /* No sense saving up arithmetic to be done
-     if it's all in the wrong mode to form part of an address.
-     And force_operand won't know whether to sign-extend or zero-extend.  */
+/* Called whenever an expression is used
+   in a lvalue context.  */
 
-  if (mode != Pmode && modifier == EXPAND_SUM)
-    modifier = EXPAND_NORMAL;
+tree
+mark_lvalue_use (tree expr)
+{
+  mark_exp_read (expr);
+  return expr;
+}
 
-  switch (code)
-    {
-    case PTRMEM_CST:
-      return expand_expr (cplus_expand_constant (exp),
-                         target, tmode, modifier);
-
-    case OFFSET_REF:
-      /* Offset refs should not make it through to here. */
-      abort ();
-      return const0_rtx;
-      
-    case THROW_EXPR:
-      expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
-      return NULL;
-
-    case MUST_NOT_THROW_EXPR:
-      expand_eh_region_start ();
-      ret = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
-      expand_eh_region_end_must_not_throw (build_call (terminate_node, 0));
-      return ret;
-
-    case EMPTY_CLASS_EXPR:
-      /* We don't need to generate any code for an empty class.  */
-      return const0_rtx;
+/* Called whenever an expression is used in a type use context.  */
 
-    default:
-      return c_expand_expr (exp, target, tmode, modifier);
-    }
-  abort ();
-  /* NOTREACHED */
-  return NULL;
+tree
+mark_type_use (tree expr)
+{
+  mark_exp_read (expr);
+  return expr;
 }
 
+/* Mark EXP as read, not just set, for set but not used -Wunused
+   warning purposes.  */
+
 void
-init_cplus_expand ()
+mark_exp_read (tree exp)
 {
-  lang_expand_expr = cplus_expand_expr;
-}
+  if (exp == NULL)
+    return;
 
-int
-extract_init (decl, init)
-     tree decl ATTRIBUTE_UNUSED, init ATTRIBUTE_UNUSED;
-{
-  return 0;
+  switch (TREE_CODE (exp))
+    {
+    case VAR_DECL:
+    case PARM_DECL:
+      DECL_READ_P (exp) = 1;
+      break;
+    case ARRAY_REF:
+    case COMPONENT_REF:
+    case MODIFY_EXPR:
+    case REALPART_EXPR:
+    case IMAGPART_EXPR:
+    CASE_CONVERT:
+    case ADDR_EXPR:
+    case INDIRECT_REF:
+    case FLOAT_EXPR:
+      mark_exp_read (TREE_OPERAND (exp, 0));
+      break;
+    case COMPOUND_EXPR:
+      mark_exp_read (TREE_OPERAND (exp, 1));
+      break;
+    case COND_EXPR:
+      if (TREE_OPERAND (exp, 1))
+       mark_exp_read (TREE_OPERAND (exp, 1));
+      if (TREE_OPERAND (exp, 2))
+       mark_exp_read (TREE_OPERAND (exp, 2));
+      break;
+    default:
+      break;
+    }
 }