Commit fc611ce0 by Mark Mitchell Committed by Mark Mitchell

cp-tree.h (TREE_READONLY_DECL_P): Use DECL_P.

	* cp-tree.h (TREE_READONLY_DECL_P): Use DECL_P.
	* init.c (decl_constant_value): Check TREE_READONLY_DECL_P.
	* call.c (convert_like_real): Don't test TREE_READONLY_DECL_P
	before calling decl_constant_value.
	* class.c (check_bitfield_decl): Likewise.
	* cvt.c (ocp_convert): Likewise.
	(convert): Likewise.
	* decl.c (compute_array_index_type): Likewise.
	(build_enumerator): Likewise.
	* decl2.c (check_cp_case_value): Likewise.
	* pt.c (convert_nontype_argument): Likewise.
	(tsubst): Likewise.
	* typeck.c (decay_conversion): Likewise.
	(build_compound_expr): Likewise.
	(build_reinterpret_cast): Likewise.
	(build_c_cast): Likewise.
	(convert_for_assignment): Likewise.

From-SVN: r33446
parent d4047e24
2000-04-26 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (TREE_READONLY_DECL_P): Use DECL_P.
* init.c (decl_constant_value): Check TREE_READONLY_DECL_P.
* call.c (convert_like_real): Don't test TREE_READONLY_DECL_P
before calling decl_constant_value.
* class.c (check_bitfield_decl): Likewise.
* cvt.c (ocp_convert): Likewise.
(convert): Likewise.
* decl.c (compute_array_index_type): Likewise.
(build_enumerator): Likewise.
* decl2.c (check_cp_case_value): Likewise.
* pt.c (convert_nontype_argument): Likewise.
(tsubst): Likewise.
* typeck.c (decay_conversion): Likewise.
(build_compound_expr): Likewise.
(build_reinterpret_cast): Likewise.
(build_c_cast): Likewise.
(convert_for_assignment): Likewise.
2000-04-26 Jason Merrill <jason@casey.cygnus.com> 2000-04-26 Jason Merrill <jason@casey.cygnus.com>
* decl.c (finish_function): Don't play games with DECL_INLINE. * decl.c (finish_function): Don't play games with DECL_INLINE.
......
...@@ -3720,7 +3720,7 @@ convert_like_real (convs, expr, fn, argnum, inner) ...@@ -3720,7 +3720,7 @@ convert_like_real (convs, expr, fn, argnum, inner)
/* Convert a non-array constant variable to its underlying value, unless we /* Convert a non-array constant variable to its underlying value, unless we
are about to bind it to a reference, in which case we need to are about to bind it to a reference, in which case we need to
leave it as an lvalue. */ leave it as an lvalue. */
if (TREE_READONLY_DECL_P (expr) && TREE_CODE (convs) != REF_BIND if (TREE_CODE (convs) != REF_BIND
&& TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE) && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
expr = decl_constant_value (expr); expr = decl_constant_value (expr);
......
...@@ -3061,7 +3061,7 @@ check_bitfield_decl (field) ...@@ -3061,7 +3061,7 @@ check_bitfield_decl (field)
/* detect invalid field size. */ /* detect invalid field size. */
if (TREE_CODE (w) == CONST_DECL) if (TREE_CODE (w) == CONST_DECL)
w = DECL_INITIAL (w); w = DECL_INITIAL (w);
else if (TREE_READONLY_DECL_P (w)) else
w = decl_constant_value (w); w = decl_constant_value (w);
if (TREE_CODE (w) != INTEGER_CST) if (TREE_CODE (w) != INTEGER_CST)
......
...@@ -1922,7 +1922,7 @@ struct lang_decl ...@@ -1922,7 +1922,7 @@ struct lang_decl
/* Non-zero if NODE is a _DECL with TREE_READONLY set. */ /* Non-zero if NODE is a _DECL with TREE_READONLY set. */
#define TREE_READONLY_DECL_P(NODE) \ #define TREE_READONLY_DECL_P(NODE) \
(TREE_READONLY (NODE) && TREE_CODE_CLASS (TREE_CODE (NODE)) == 'd') (TREE_READONLY (NODE) && DECL_P (NODE))
/* Non-zero iff DECL is memory-based. The DECL_RTL of /* Non-zero iff DECL is memory-based. The DECL_RTL of
certain const variables might be a CONST_INT, or a REG certain const variables might be a CONST_INT, or a REG
......
...@@ -673,8 +673,7 @@ ocp_convert (type, expr, convtype, flags) ...@@ -673,8 +673,7 @@ ocp_convert (type, expr, convtype, flags)
complete_type (type); complete_type (type);
complete_type (TREE_TYPE (expr)); complete_type (TREE_TYPE (expr));
if (TREE_READONLY_DECL_P (e)) e = decl_constant_value (e);
e = decl_constant_value (e);
if (IS_AGGR_TYPE (type) && (convtype & CONV_FORCE_TEMP) if (IS_AGGR_TYPE (type) && (convtype & CONV_FORCE_TEMP)
/* Some internal structures (vtable_entry_type, sigtbl_ptr_type) /* Some internal structures (vtable_entry_type, sigtbl_ptr_type)
...@@ -1003,8 +1002,7 @@ convert (type, expr) ...@@ -1003,8 +1002,7 @@ convert (type, expr)
if (POINTER_TYPE_P (type) && POINTER_TYPE_P (intype)) if (POINTER_TYPE_P (type) && POINTER_TYPE_P (intype))
{ {
if (TREE_READONLY_DECL_P (expr)) expr = decl_constant_value (expr);
expr = decl_constant_value (expr);
return fold (build1 (NOP_EXPR, type, expr)); return fold (build1 (NOP_EXPR, type, expr));
} }
......
...@@ -9124,8 +9124,7 @@ compute_array_index_type (name, size) ...@@ -9124,8 +9124,7 @@ compute_array_index_type (name, size)
STRIP_TYPE_NOPS (size); STRIP_TYPE_NOPS (size);
/* It might be a const variable or enumeration constant. */ /* It might be a const variable or enumeration constant. */
if (TREE_READONLY_DECL_P (size)) size = decl_constant_value (size);
size = decl_constant_value (size);
/* If this involves a template parameter, it will be a constant at /* If this involves a template parameter, it will be a constant at
instantiation time, but we don't know what the value is yet. instantiation time, but we don't know what the value is yet.
...@@ -13019,8 +13018,7 @@ build_enumerator (name, value, enumtype) ...@@ -13019,8 +13018,7 @@ build_enumerator (name, value, enumtype)
/* Validate and default VALUE. */ /* Validate and default VALUE. */
if (value != NULL_TREE) if (value != NULL_TREE)
{ {
if (TREE_READONLY_DECL_P (value)) value = decl_constant_value (value);
value = decl_constant_value (value);
if (TREE_CODE (value) == INTEGER_CST) if (TREE_CODE (value) == INTEGER_CST)
{ {
......
...@@ -4143,12 +4143,8 @@ check_cp_case_value (value) ...@@ -4143,12 +4143,8 @@ check_cp_case_value (value)
/* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
STRIP_TYPE_NOPS (value); STRIP_TYPE_NOPS (value);
value = decl_constant_value (value);
if (TREE_READONLY_DECL_P (value)) STRIP_TYPE_NOPS (value);
{
value = decl_constant_value (value);
STRIP_TYPE_NOPS (value);
}
value = fold (value); value = fold (value);
if (TREE_CODE (value) != INTEGER_CST if (TREE_CODE (value) != INTEGER_CST
......
...@@ -1779,13 +1779,15 @@ resolve_offset_ref (exp) ...@@ -1779,13 +1779,15 @@ resolve_offset_ref (exp)
return NULL_TREE; return NULL_TREE;
} }
/* Return either DECL or its known constant value (if it has one). */ /* If DECL is a `const' declaration, and its value is a known
constant, then return that value. */
tree tree
decl_constant_value (decl) decl_constant_value (decl)
tree decl; tree decl;
{ {
if (! TREE_THIS_VOLATILE (decl) if (TREE_READONLY_DECL_P (decl)
&& ! TREE_THIS_VOLATILE (decl)
&& DECL_INITIAL (decl) && DECL_INITIAL (decl)
&& DECL_INITIAL (decl) != error_mark_node && DECL_INITIAL (decl) != error_mark_node
/* This is invalid if initial value is not constant. /* This is invalid if initial value is not constant.
......
...@@ -2701,7 +2701,7 @@ convert_nontype_argument (type, expr) ...@@ -2701,7 +2701,7 @@ convert_nontype_argument (type, expr)
enumerators. Simplify things by folding them to their values, enumerators. Simplify things by folding them to their values,
unless we're about to bind the declaration to a reference unless we're about to bind the declaration to a reference
parameter. */ parameter. */
if (INTEGRAL_TYPE_P (expr_type) && TREE_READONLY_DECL_P (expr) if (INTEGRAL_TYPE_P (expr_type)
&& TREE_CODE (type) != REFERENCE_TYPE) && TREE_CODE (type) != REFERENCE_TYPE)
expr = decl_constant_value (expr); expr = decl_constant_value (expr);
...@@ -6200,7 +6200,7 @@ tsubst (t, args, complain, in_decl) ...@@ -6200,7 +6200,7 @@ tsubst (t, args, complain, in_decl)
/* See if we can reduce this expression to something simpler. */ /* See if we can reduce this expression to something simpler. */
max = maybe_fold_nontype_arg (max); max = maybe_fold_nontype_arg (max);
if (!processing_template_decl && TREE_READONLY_DECL_P (max)) if (!processing_template_decl)
max = decl_constant_value (max); max = decl_constant_value (max);
if (processing_template_decl if (processing_template_decl
......
...@@ -1710,7 +1710,7 @@ decay_conversion (exp) ...@@ -1710,7 +1710,7 @@ decay_conversion (exp)
don't do this for arrays, though; we want the address of the don't do this for arrays, though; we want the address of the
first element of the array, not the address of the first element first element of the array, not the address of the first element
of its initializing constant. */ of its initializing constant. */
else if (TREE_READONLY_DECL_P (exp) && code != ARRAY_TYPE) else if (code != ARRAY_TYPE)
{ {
exp = decl_constant_value (exp); exp = decl_constant_value (exp);
type = TREE_TYPE (exp); type = TREE_TYPE (exp);
...@@ -5084,8 +5084,7 @@ build_compound_expr (list) ...@@ -5084,8 +5084,7 @@ build_compound_expr (list)
register tree rest; register tree rest;
tree first; tree first;
if (TREE_READONLY_DECL_P (TREE_VALUE (list))) TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
if (TREE_CHAIN (list) == 0) if (TREE_CHAIN (list) == 0)
{ {
...@@ -5272,8 +5271,7 @@ build_reinterpret_cast (type, expr) ...@@ -5272,8 +5271,7 @@ build_reinterpret_cast (type, expr)
else if ((TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype)) else if ((TYPE_PTRFN_P (type) && TYPE_PTRFN_P (intype))
|| (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype))) || (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)))
{ {
if (TREE_READONLY_DECL_P (expr)) expr = decl_constant_value (expr);
expr = decl_constant_value (expr);
return fold (build1 (NOP_EXPR, type, expr)); return fold (build1 (NOP_EXPR, type, expr));
} }
else if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype)) else if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
...@@ -5283,16 +5281,14 @@ build_reinterpret_cast (type, expr) ...@@ -5283,16 +5281,14 @@ build_reinterpret_cast (type, expr)
cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)", cp_pedwarn ("reinterpret_cast from `%T' to `%T' casts away const (or volatile)",
intype, type); intype, type);
if (TREE_READONLY_DECL_P (expr)) expr = decl_constant_value (expr);
expr = decl_constant_value (expr);
return fold (build1 (NOP_EXPR, type, expr)); return fold (build1 (NOP_EXPR, type, expr));
} }
else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype)) else if ((TYPE_PTRFN_P (type) && TYPE_PTROBV_P (intype))
|| (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type))) || (TYPE_PTRFN_P (intype) && TYPE_PTROBV_P (type)))
{ {
pedwarn ("ISO C++ forbids casting between pointer-to-function and pointer-to-object"); pedwarn ("ISO C++ forbids casting between pointer-to-function and pointer-to-object");
if (TREE_READONLY_DECL_P (expr)) expr = decl_constant_value (expr);
expr = decl_constant_value (expr);
return fold (build1 (NOP_EXPR, type, expr)); return fold (build1 (NOP_EXPR, type, expr));
} }
else else
...@@ -5498,8 +5494,7 @@ build_c_cast (type, expr) ...@@ -5498,8 +5494,7 @@ build_c_cast (type, expr)
{ {
tree ovalue; tree ovalue;
if (TREE_READONLY_DECL_P (value)) value = decl_constant_value (value);
value = decl_constant_value (value);
ovalue = value; ovalue = value;
value = convert_force (type, value, CONV_C_CAST); value = convert_force (type, value, CONV_C_CAST);
...@@ -6493,7 +6488,7 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum) ...@@ -6493,7 +6488,7 @@ convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
/* Simplify the RHS if possible. */ /* Simplify the RHS if possible. */
if (TREE_CODE (rhs) == CONST_DECL) if (TREE_CODE (rhs) == CONST_DECL)
rhs = DECL_INITIAL (rhs); rhs = DECL_INITIAL (rhs);
else if (TREE_READONLY_DECL_P (rhs) && coder != ARRAY_TYPE) else if (coder != ARRAY_TYPE)
rhs = decl_constant_value (rhs); rhs = decl_constant_value (rhs);
/* [expr.ass] /* [expr.ass]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment