]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/cp/decl2.c
cp-tree.h (build_scoped_method_call): Remove.
[thirdparty/gcc.git] / gcc / cp / decl2.c
index 39f6ca5536917e0fba46e94b63a729862feac36d..7158f1021471f192a64f5bce96457b4d06c1f637 100644 (file)
@@ -409,8 +409,7 @@ grok_array_decl (tree array_expr, tree index_exp)
 
   my_friendly_assert (type, 20030626);
 
-  if (TREE_CODE (type) == REFERENCE_TYPE)
-    type = TREE_TYPE (type);
+  type = non_reference (type);
 
   /* If they have an `operator[]', use that.  */
   if (IS_AGGR_TYPE (type) || IS_AGGR_TYPE (TREE_TYPE (index_exp)))
@@ -2938,415 +2937,6 @@ finish_file ()
   input_location = locus;
 }
 
-/* T is the parse tree for an expression.  Return the expression after
-   performing semantic analysis.  */
-
-tree
-build_expr_from_tree (tree t)
-{
-  if (t == NULL_TREE || t == error_mark_node)
-    return t;
-
-  switch (TREE_CODE (t))
-    {
-    case IDENTIFIER_NODE:
-      return do_identifier (t, NULL_TREE);
-
-    case LOOKUP_EXPR:
-      if (LOOKUP_EXPR_GLOBAL (t))
-       {
-         tree token = TREE_OPERAND (t, 0);
-         return do_scoped_id (token, IDENTIFIER_GLOBAL_VALUE (token));
-       }
-      else
-       {
-         t = do_identifier (TREE_OPERAND (t, 0), NULL_TREE);
-         if (TREE_CODE (t) == ALIAS_DECL)
-           t = DECL_INITIAL (t);
-         return t;
-       }
-
-    case TEMPLATE_ID_EXPR:
-      {
-       tree template;
-       tree args;
-       tree object;
-
-       template = build_expr_from_tree (TREE_OPERAND (t, 0));
-       args = build_expr_from_tree (TREE_OPERAND (t, 1));
-       
-       if (TREE_CODE (template) == COMPONENT_REF)
-         {
-           object = TREE_OPERAND (template, 0);
-           template = TREE_OPERAND (template, 1);
-         }
-       else
-         object = NULL_TREE;
-
-       template = lookup_template_function (template, args);
-       if (object)
-         return build (COMPONENT_REF, TREE_TYPE (template), 
-                       object, template);
-       else
-         return template;
-      }
-
-    case INDIRECT_REF:
-      return build_x_indirect_ref
-       (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
-
-    case CAST_EXPR:
-      return build_functional_cast
-       (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case REINTERPRET_CAST_EXPR:
-      return build_reinterpret_cast
-       (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case CONST_CAST_EXPR:
-      return build_const_cast
-       (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case DYNAMIC_CAST_EXPR:
-      return build_dynamic_cast
-       (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case STATIC_CAST_EXPR:
-      return build_static_cast
-       (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case PREDECREMENT_EXPR:
-    case PREINCREMENT_EXPR:
-    case POSTDECREMENT_EXPR:
-    case POSTINCREMENT_EXPR:
-    case NEGATE_EXPR:
-    case BIT_NOT_EXPR:
-    case ABS_EXPR:
-    case TRUTH_NOT_EXPR:
-    case ADDR_EXPR:
-    case CONVERT_EXPR:      /* Unary + */
-    case REALPART_EXPR:
-    case IMAGPART_EXPR:
-      if (TREE_TYPE (t))
-       return t;
-      return build_x_unary_op (TREE_CODE (t),
-                              build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case PLUS_EXPR:
-    case MINUS_EXPR:
-    case MULT_EXPR:
-    case TRUNC_DIV_EXPR:
-    case CEIL_DIV_EXPR:
-    case FLOOR_DIV_EXPR:
-    case ROUND_DIV_EXPR:
-    case EXACT_DIV_EXPR:
-    case BIT_AND_EXPR:
-    case BIT_ANDTC_EXPR:
-    case BIT_IOR_EXPR:
-    case BIT_XOR_EXPR:
-    case TRUNC_MOD_EXPR:
-    case FLOOR_MOD_EXPR:
-    case TRUTH_ANDIF_EXPR:
-    case TRUTH_ORIF_EXPR:
-    case TRUTH_AND_EXPR:
-    case TRUTH_OR_EXPR:
-    case RSHIFT_EXPR:
-    case LSHIFT_EXPR:
-    case RROTATE_EXPR:
-    case LROTATE_EXPR:
-    case EQ_EXPR:
-    case NE_EXPR:
-    case MAX_EXPR:
-    case MIN_EXPR:
-    case LE_EXPR:
-    case GE_EXPR:
-    case LT_EXPR:
-    case GT_EXPR:
-    case MEMBER_REF:
-      return build_x_binary_op
-       (TREE_CODE (t), 
-        build_expr_from_tree (TREE_OPERAND (t, 0)),
-        build_expr_from_tree (TREE_OPERAND (t, 1)));
-
-    case DOTSTAR_EXPR:
-      return build_m_component_ref
-       (build_expr_from_tree (TREE_OPERAND (t, 0)),
-        build_expr_from_tree (TREE_OPERAND (t, 1)));
-
-    case SCOPE_REF:
-      return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
-
-    case ARRAY_REF:
-      if (TREE_OPERAND (t, 0) == NULL_TREE)
-       /* new-type-id */
-       return build_nt (ARRAY_REF, NULL_TREE,
-                        build_expr_from_tree (TREE_OPERAND (t, 1)));
-      return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
-                             build_expr_from_tree (TREE_OPERAND (t, 1)));
-
-    case SIZEOF_EXPR:
-    case ALIGNOF_EXPR:
-      {
-       tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
-       if (!TYPE_P (r))
-         return TREE_CODE (t) == SIZEOF_EXPR ? expr_sizeof (r) : c_alignof_expr (r);
-       else
-         return cxx_sizeof_or_alignof_type (r, TREE_CODE (t), true);
-      }
-
-    case MODOP_EXPR:
-      return build_x_modify_expr
-       (build_expr_from_tree (TREE_OPERAND (t, 0)),
-        TREE_CODE (TREE_OPERAND (t, 1)),
-        build_expr_from_tree (TREE_OPERAND (t, 2)));
-
-    case ARROW_EXPR:
-      return build_x_arrow
-       (build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case NEW_EXPR:
-      return build_new
-       (build_expr_from_tree (TREE_OPERAND (t, 0)),
-        build_expr_from_tree (TREE_OPERAND (t, 1)),
-        build_expr_from_tree (TREE_OPERAND (t, 2)),
-        NEW_EXPR_USE_GLOBAL (t));
-
-    case DELETE_EXPR:
-      return delete_sanity
-       (build_expr_from_tree (TREE_OPERAND (t, 0)),
-        build_expr_from_tree (TREE_OPERAND (t, 1)),
-        DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
-
-    case COMPOUND_EXPR:
-      if (TREE_OPERAND (t, 1) == NULL_TREE)
-       return build_x_compound_expr
-         (build_expr_from_tree (TREE_OPERAND (t, 0)));
-      else
-       abort ();
-
-    case METHOD_CALL_EXPR:
-      if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
-       {
-         tree ref = TREE_OPERAND (t, 0);
-         tree name = TREE_OPERAND (ref, 1);
-         
-         if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
-           name = build_nt (TEMPLATE_ID_EXPR,
-                            TREE_OPERAND (name, 0),
-                            build_expr_from_tree (TREE_OPERAND (name, 1)));
-           
-         return build_scoped_method_call
-           (build_expr_from_tree (TREE_OPERAND (t, 1)),
-            build_expr_from_tree (TREE_OPERAND (ref, 0)),
-            name,
-            build_expr_from_tree (TREE_OPERAND (t, 2)));
-       }
-      else 
-       {
-         tree fn = TREE_OPERAND (t, 0);
-
-         /* We can get a TEMPLATE_ID_EXPR here on code like:
-
-              x->f<2>();
-             
-            so we must resolve that.  However, we can also get things
-            like a BIT_NOT_EXPR here, when referring to a destructor,
-            and things like that are not correctly resolved by
-            build_expr_from_tree.  So, just use build_expr_from_tree
-            when we really need it.  */
-         if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
-           fn = lookup_template_function
-             (TREE_OPERAND (fn, 0),
-              build_expr_from_tree (TREE_OPERAND (fn, 1)));
-
-         return build_method_call
-           (build_expr_from_tree (TREE_OPERAND (t, 1)),
-            fn,
-            build_expr_from_tree (TREE_OPERAND (t, 2)),
-            NULL_TREE, LOOKUP_NORMAL);
-       }
-
-    case CALL_EXPR:
-      if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
-       {
-         tree ref = TREE_OPERAND (t, 0);
-         tree name = TREE_OPERAND (ref, 1);
-         tree fn, scope, args;
-         
-         if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
-           name = build_nt (TEMPLATE_ID_EXPR,
-                            TREE_OPERAND (name, 0),
-                            build_expr_from_tree (TREE_OPERAND (name, 1)));
-
-         scope = build_expr_from_tree (TREE_OPERAND (ref, 0));
-         args = build_expr_from_tree (TREE_OPERAND (t, 1));
-         fn = resolve_scoped_fn_name (scope, name);
-         
-         return build_call_from_tree (fn, args, 1);
-       }
-      else
-       {
-         tree name = TREE_OPERAND (t, 0);
-          tree id;
-          tree args = build_expr_from_tree (TREE_OPERAND (t, 1));
-          if (args != NULL_TREE && TREE_CODE (name) == LOOKUP_EXPR
-              && !LOOKUP_EXPR_GLOBAL (name)
-              && TREE_CODE ((id = TREE_OPERAND (name, 0))) == IDENTIFIER_NODE
-              && (!current_class_type
-                  || !lookup_member (current_class_type, id, 0, false)))
-            {
-              /* Do Koenig lookup if there are no class members.  */
-              name = do_identifier (id, args);
-            }
-          else if (TREE_CODE (name) == TEMPLATE_ID_EXPR
-                  || ! really_overloaded_fn (name))
-           name = build_expr_from_tree (name);
-
-         if (TREE_CODE (name) == OFFSET_REF)
-           return build_offset_ref_call_from_tree (name, args);
-         if (TREE_CODE (name) == COMPONENT_REF)
-           return finish_object_call_expr (TREE_OPERAND (name, 1),
-                                           TREE_OPERAND (name, 0),
-                                           args);
-         name = convert_from_reference (name);
-         return build_call_from_tree (name, args, 
-                                      /*disallow_virtual=*/false);
-       }
-
-    case COND_EXPR:
-      return build_x_conditional_expr
-       (build_expr_from_tree (TREE_OPERAND (t, 0)),
-        build_expr_from_tree (TREE_OPERAND (t, 1)),
-        build_expr_from_tree (TREE_OPERAND (t, 2)));
-
-    case PSEUDO_DTOR_EXPR:
-      return (finish_pseudo_destructor_expr 
-             (build_expr_from_tree (TREE_OPERAND (t, 0)),
-              build_expr_from_tree (TREE_OPERAND (t, 1)),
-              build_expr_from_tree (TREE_OPERAND (t, 2))));
-
-    case TREE_LIST:
-      {
-       tree purpose, value, chain;
-
-       if (t == void_list_node)
-         return t;
-
-       purpose = TREE_PURPOSE (t);
-       if (purpose)
-         purpose = build_expr_from_tree (purpose);
-       value = TREE_VALUE (t);
-       if (value)
-         value = build_expr_from_tree (value);
-       chain = TREE_CHAIN (t);
-       if (chain && chain != void_type_node)
-         chain = build_expr_from_tree (chain);
-       return tree_cons (purpose, value, chain);
-      }
-
-    case COMPONENT_REF:
-      {
-       tree object = build_expr_from_tree (TREE_OPERAND (t, 0));
-       tree member = TREE_OPERAND (t, 1);
-
-       if (!CLASS_TYPE_P (TREE_TYPE (object)))
-         {
-           if (TREE_CODE (member) == BIT_NOT_EXPR)
-             return finish_pseudo_destructor_expr (object, 
-                                                   NULL_TREE,
-                                                   TREE_TYPE (object));
-           else if (TREE_CODE (member) == SCOPE_REF
-                    && (TREE_CODE (TREE_OPERAND (member, 1)) == BIT_NOT_EXPR))
-             return finish_pseudo_destructor_expr (object, 
-                                                   TREE_OPERAND (t, 0),
-                                                   TREE_TYPE (object));
-         }
-       else if (TREE_CODE (member) == SCOPE_REF
-                && TREE_CODE (TREE_OPERAND (member, 1)) == TEMPLATE_ID_EXPR)
-         {
-           tree tmpl;
-           tree args;
-       
-           /* Lookup the template functions now that we know what the
-              scope is.  */
-           tmpl = TREE_OPERAND (TREE_OPERAND (member, 1), 0);
-           args = TREE_OPERAND (TREE_OPERAND (member, 1), 1);
-           member = lookup_qualified_name (TREE_OPERAND (member, 0),
-                                           tmpl, 
-                                           /*is_type=*/0,
-                                           /*flags=*/0);
-           if (BASELINK_P (member))
-             BASELINK_FUNCTIONS (member) 
-               = build_nt (TEMPLATE_ID_EXPR, BASELINK_FUNCTIONS (member),
-                           args);
-           else
-             {
-               error ("`%D' is not a member of `%T'",
-                      tmpl, TREE_TYPE (object));
-               return error_mark_node;
-             }
-         }
-
-
-       return finish_class_member_access_expr (object, member);
-      }
-
-    case THROW_EXPR:
-      return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case CONSTRUCTOR:
-      {
-       tree r;
-       tree elts;
-       tree type = TREE_TYPE (t);
-       bool purpose_p;
-
-       /* digest_init will do the wrong thing if we let it.  */
-       if (type && TYPE_PTRMEMFUNC_P (type))
-         return t;
-
-       r = NULL_TREE;
-       /* We do not want to process the purpose of aggregate
-          initializers as they are identifier nodes which will be
-          looked up by digest_init.  */
-       purpose_p = !(type && IS_AGGR_TYPE (type));
-       for (elts = CONSTRUCTOR_ELTS (t); elts; elts = TREE_CHAIN (elts))
-         {
-           tree purpose = TREE_PURPOSE (elts);
-           tree value = TREE_VALUE (elts);
-           
-           if (purpose && purpose_p)
-             purpose = build_expr_from_tree (purpose);
-           value = build_expr_from_tree (value);
-           r = tree_cons (purpose, value, r);
-         }
-       
-       r = build_constructor (NULL_TREE, nreverse (r));
-       TREE_HAS_CONSTRUCTOR (r) = TREE_HAS_CONSTRUCTOR (t);
-
-       if (type)
-         return digest_init (type, r, 0);
-       return r;
-      }
-
-    case TYPEID_EXPR:
-      if (TYPE_P (TREE_OPERAND (t, 0)))
-       return get_typeid (TREE_OPERAND (t, 0));
-      return build_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
-
-    case PARM_DECL:
-    case VAR_DECL:
-      return convert_from_reference (t);
-
-    case VA_ARG_EXPR:
-      return build_va_arg (build_expr_from_tree (TREE_OPERAND (t, 0)),
-                          TREE_TYPE (t));
-
-    default:
-      return t;
-    }
-}
-
 /* FN is an OFFSET_REF indicating the function to call in parse-tree
    form; it has not yet been semantically analyzed.  ARGS are the
    arguments to the function.  They have already been semantically
@@ -3359,22 +2949,12 @@ build_offset_ref_call_from_tree (tree fn, tree args)
 
   my_friendly_assert (TREE_CODE (fn) == OFFSET_REF, 20020725);
 
-  /* A qualified name corresponding to a non-static member
-     function or a pointer-to-member is represented as an 
-     OFFSET_REF.  
-
-     For both of these function calls, FN will be an OFFSET_REF.
-
-       struct A { void f(); };
-       void A::f() { (A::f) (); } 
+  /* A qualified name corresponding to a bound pointer-to-member is
+     represented as an OFFSET_REF:
 
        struct B { void g(); };
        void (B::*p)();
        void B::g() { (this->*p)(); }  */
-
-  /* This code is not really correct (for example, it does not
-     handle the case that `A::f' is overloaded), but it is
-     historically how we have handled this situation.  */
   if (TREE_CODE (TREE_OPERAND (fn, 1)) == FIELD_DECL)
     /* This case should now be handled elsewhere.  */
     abort ();