summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/cp/expr.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/cp/expr.c')
-rw-r--r--contrib/gcc/cp/expr.c258
1 files changed, 149 insertions, 109 deletions
diff --git a/contrib/gcc/cp/expr.c b/contrib/gcc/cp/expr.c
index 99a611e..4c3d8b6 100644
--- a/contrib/gcc/cp/expr.c
+++ b/contrib/gcc/cp/expr.c
@@ -21,18 +21,24 @@ Boston, MA 02111-1307, USA. */
#include "config.h"
+#include "system.h"
#include "rtl.h"
#include "tree.h"
#include "flags.h"
#include "expr.h"
#include "cp-tree.h"
+#include "toplev.h"
-#undef NULL
-#define NULL 0
+#if 0
+static tree extract_aggr_init PROTO((tree, tree));
+static tree extract_scalar_init PROTO((tree, tree));
+#endif
+static rtx cplus_expand_expr PROTO((tree, rtx, enum machine_mode,
+ enum expand_modifier));
/* Hook used by expand_expr to expand language-specific tree codes. */
-rtx
+static rtx
cplus_expand_expr (exp, target, tmode, modifier)
tree exp;
rtx target;
@@ -42,11 +48,10 @@ cplus_expand_expr (exp, target, tmode, modifier)
tree type = TREE_TYPE (exp);
register enum machine_mode mode = TYPE_MODE (type);
register enum tree_code code = TREE_CODE (exp);
- rtx original_target = target;
int ignore = target == const0_rtx;
if (ignore)
- target = 0, original_target = 0;
+ target = 0;
/* No sense saving up arithmetic to be done
if it's all in the wrong mode to form part of an address.
@@ -57,7 +62,7 @@ cplus_expand_expr (exp, target, tmode, modifier)
switch (code)
{
- case NEW_EXPR:
+ case AGGR_INIT_EXPR:
{
/* Something needs to be initialized, but we didn't know
where that thing was when building the tree. For example,
@@ -74,8 +79,6 @@ cplus_expand_expr (exp, target, tmode, modifier)
tree func = TREE_OPERAND (exp, 0);
tree args = TREE_OPERAND (exp, 1);
tree type = TREE_TYPE (exp), slot;
- tree fn_type = TREE_TYPE (TREE_TYPE (func));
- tree return_type = TREE_TYPE (fn_type);
tree call_exp;
rtx call_target, return_target;
int pcc_struct_return = 0;
@@ -84,14 +87,8 @@ cplus_expand_expr (exp, target, tmode, modifier)
`target' represents. SLOT holds the slot for TARGET. */
slot = TREE_OPERAND (exp, 2);
- if (target == 0)
- {
- /* Should always be called with a target in BLKmode case. */
- my_friendly_assert (mode != BLKmode, 205);
- my_friendly_assert (DECL_RTL (slot) != 0, 206);
-
- target = gen_reg_rtx (mode);
- }
+ /* Should always be called with a target. */
+ my_friendly_assert (target != NULL_RTX, 205);
/* The target the initializer will initialize (CALL_TARGET)
must now be directed to initialize the target we are
@@ -110,97 +107,58 @@ cplus_expand_expr (exp, target, tmode, modifier)
parameter value. */
mark_addressable (slot);
if (TREE_PERMANENT (args))
- args = tree_cons (0, build1 (ADDR_EXPR, type, slot),
+ args = expr_tree_cons (0, build1 (ADDR_EXPR, type, slot),
TREE_CHAIN (args));
else
TREE_VALUE (args) = build1 (ADDR_EXPR, type, slot);
call_target = 0;
}
- else if (TREE_CODE (return_type) == REFERENCE_TYPE)
- {
- type = return_type;
- call_target = 0;
- }
else
{
-#ifdef PCC_STATIC_STRUCT_RETURN
- pcc_struct_return = 1;
- call_target = 0;
-#else
call_target = target;
+#ifdef PCC_STATIC_STRUCT_RETURN
+ if (aggregate_value_p (type))
+ {
+ pcc_struct_return = 1;
+ call_target = 0;
+ }
#endif
}
- if (call_target)
- {
- /* Make this a valid memory address now. The code below assumes
- that it can compare rtx and make assumptions based on the
- result. The assumptions are true only if the address was
- valid to begin with. */
- call_target = validize_mem (call_target);
- }
- call_exp = build (CALL_EXPR, type, func, args, 0);
+ call_exp = build (CALL_EXPR, type, func, args, NULL_TREE);
TREE_SIDE_EFFECTS (call_exp) = 1;
return_target = expand_call (call_exp, call_target, ignore);
- if (call_target == 0)
- {
- if (pcc_struct_return)
- {
- extern int flag_access_control;
- int old_ac = flag_access_control;
-
- tree init = build_decl (VAR_DECL, 0, type);
- TREE_ADDRESSABLE (init) = 1;
- DECL_RTL (init) = return_target;
-
- flag_access_control = 0;
- expand_aggr_init (slot, init, 0, LOOKUP_ONLYCONVERTING);
- flag_access_control = old_ac;
-
- if (TYPE_NEEDS_DESTRUCTOR (type))
- {
- init = build_decl (VAR_DECL, 0,
- build_reference_type (type));
- DECL_RTL (init) = XEXP (return_target, 0);
-
- init = maybe_build_cleanup (convert_from_reference (init));
- if (init != NULL_TREE)
- expand_expr (init, 0, 0, 0);
- }
- call_target = return_target = DECL_RTL (slot);
- }
- else
- call_target = return_target;
- }
-
- if (call_target != return_target)
- {
- my_friendly_assert (TYPE_HAS_TRIVIAL_INIT_REF (type), 317);
- if (GET_MODE (return_target) == BLKmode)
- emit_block_move (call_target, return_target, expr_size (exp),
- TYPE_ALIGN (type) / BITS_PER_UNIT);
- else
- emit_move_insn (call_target, return_target);
- }
- if (TREE_CODE (return_type) == REFERENCE_TYPE)
+ if (call_target)
+ /* Trust that the right thing has been done; it's too hard to
+ verify. */
+ return return_target;
+
+ /* If we're suffering under the ancient PCC_STATIC_STRUCT_RETURN
+ calling convention, we need to copy the return value out of
+ the static return buffer into slot. */
+ if (pcc_struct_return)
{
- tree init;
-
- if (GET_CODE (call_target) == REG
- && REGNO (call_target) < FIRST_PSEUDO_REGISTER)
- my_friendly_abort (39);
+ extern int flag_access_control;
+ int old_ac = flag_access_control;
- type = TREE_TYPE (exp);
+ tree init = build_decl (VAR_DECL, NULL_TREE,
+ build_reference_type (type));
+ DECL_RTL (init) = XEXP (return_target, 0);
+ init = convert_from_reference (init);
- init = build (RTL_EXPR, return_type, 0, call_target);
- /* We got back a reference to the type we want. Now initialize
- target with that. */
+ flag_access_control = 0;
expand_aggr_init (slot, init, 0, LOOKUP_ONLYCONVERTING);
+ flag_access_control = old_ac;
+
+ if (TYPE_NEEDS_DESTRUCTOR (type))
+ {
+ init = maybe_build_cleanup (init);
+ if (init != NULL_TREE)
+ expand_expr (init, const0_rtx, VOIDmode, 0);
+ }
}
- if (DECL_RTL (slot) != target)
- emit_move_insn (DECL_RTL (slot), target);
return DECL_RTL (slot);
}
@@ -226,13 +184,16 @@ cplus_expand_expr (exp, target, tmode, modifier)
expand_throw (TREE_OPERAND (exp, 0));
return NULL;
- case UNSAVE_EXPR:
- {
- rtx temp;
- temp = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
- TREE_OPERAND (exp, 0) = unsave_expr_now (TREE_OPERAND (exp, 0));
- return temp;
- }
+ case VEC_INIT_EXPR:
+ return expand_expr
+ (expand_vec_init
+ (NULL_TREE, TREE_OPERAND (exp, 0),
+ build_binary_op (MINUS_EXPR, TREE_OPERAND (exp, 2),
+ integer_one_node, 1),
+ TREE_OPERAND (exp, 1), 0), target, tmode, modifier);
+
+ case NEW_EXPR:
+ return expand_expr (build_new_1 (exp), target, tmode, modifier);
default:
break;
@@ -278,19 +239,7 @@ fixup_result_decl (decl, result)
}
}
-/* Return nonzero iff DECL is memory-based. The DECL_RTL of
- certain const variables might be a CONST_INT, or a REG
- in some cases. We cannot use `memory_operand' as a test
- here because on most RISC machines, a variable's address
- is not, by itself, a legitimate address. */
-
-int
-decl_in_memory_p (decl)
- tree decl;
-{
- return DECL_RTL (decl) != 0 && GET_CODE (DECL_RTL (decl)) == MEM;
-}
-
+#if 0
/* Expand this initialization inline and see if it's simple enough that
it can be done at compile-time. */
@@ -333,8 +282,8 @@ extract_scalar_init (decl, init)
to = XEXP (r, 0);
- if (! (to == value ||
- (GET_CODE (to) == SUBREG && XEXP (to, 0) == value)))
+ if (! (to == value
+ || (GET_CODE (to) == SUBREG && XEXP (to, 0) == value)))
return 0;
r = XEXP (r, 1);
@@ -351,6 +300,7 @@ extract_scalar_init (decl, init)
return t;
}
+#endif
int
extract_init (decl, init)
@@ -358,6 +308,7 @@ extract_init (decl, init)
{
return 0;
+#if 0
if (IS_AGGR_TYPE (TREE_TYPE (decl))
|| TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
init = extract_aggr_init (decl, init);
@@ -369,4 +320,93 @@ extract_init (decl, init)
DECL_INITIAL (decl) = init;
return 1;
+#endif
+}
+
+void
+do_case (start, end)
+ tree start, end;
+{
+ tree value1 = NULL_TREE, value2 = NULL_TREE, label;
+
+ if (start != NULL_TREE && TREE_TYPE (start) != NULL_TREE
+ && POINTER_TYPE_P (TREE_TYPE (start)))
+ error ("pointers are not permitted as case values");
+
+ if (end && pedantic)
+ pedwarn ("ANSI C++ forbids range expressions in switch statement");
+
+ if (processing_template_decl)
+ {
+ add_tree (build_min_nt (CASE_LABEL, start, end));
+ return;
+ }
+
+ if (start)
+ value1 = check_cp_case_value (start);
+ if (end)
+ value2 = check_cp_case_value (end);
+
+ label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
+
+ if (value1 != error_mark_node
+ && value2 != error_mark_node)
+ {
+ tree duplicate;
+ int success;
+
+ if (end)
+ success = pushcase_range (value1, value2, convert_and_check,
+ label, &duplicate);
+ else if (start)
+ success = pushcase (value1, convert_and_check, label, &duplicate);
+ else
+ success = pushcase (NULL_TREE, 0, label, &duplicate);
+
+ if (success == 1)
+ {
+ if (end)
+ error ("case label not within a switch statement");
+ else if (start)
+ cp_error ("case label `%E' not within a switch statement", start);
+ else
+ error ("default label not within a switch statement");
+ }
+ else if (success == 2)
+ {
+ if (end)
+ {
+ error ("duplicate (or overlapping) case value");
+ cp_error_at ("this is the first entry overlapping that value",
+ duplicate);
+ }
+ else if (start)
+ {
+ cp_error ("duplicate case value `%E'", start);
+ cp_error_at ("previously used here", duplicate);
+ }
+ else
+ {
+ error ("multiple default labels in one switch");
+ cp_error_at ("this is the first default label", duplicate);
+ }
+ }
+ else if (success == 3)
+ warning ("case value out of range");
+ else if (success == 4)
+ warning ("empty range specified");
+ else if (success == 5)
+ {
+ if (end)
+ error ("case label within scope of cleanup or variable array");
+ else if (! start)
+ error ("`default' label within scope of cleanup or variable array");
+ else
+ cp_error ("case label `%E' within scope of cleanup or variable array", start);
+ }
+ }
+ if (start)
+ define_case_label (label);
+ else
+ define_case_label (NULL_TREE);
}
OpenPOWER on IntegriCloud