aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/expr.c
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>1999-05-20 10:44:47 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1999-05-20 10:44:47 +0000
commit87533b37c7f8d54d0dad71d1a44a541d5ff36587 (patch)
tree3cf5566ec06f2dc7cde61acc0794f3a26018176d /gcc/cp/expr.c
parente697e20a892668e5a9189980193e23412a0cc221 (diff)
downloadgcc-87533b37c7f8d54d0dad71d1a44a541d5ff36587.zip
gcc-87533b37c7f8d54d0dad71d1a44a541d5ff36587.tar.gz
gcc-87533b37c7f8d54d0dad71d1a44a541d5ff36587.tar.bz2
cp-tree.h (make_ptrmem_cst): New function.
* cp-tree.h (make_ptrmem_cst): New function. * expr.c (cplus_expand_constant): Split out from ... (cplus_expand_expr): Here. Use cplus_expand_constant. (init_cplus_expand): Set lang_expand_constant. * pt.c (convert_nontype_argument): Use make_ptrmem_cst. * tree.c (make_ptrmem_cst): Define. * typeck.c (unary_complex_lvalue): Use make_ptrmem_cst. * typeck2.c (initializer_constant_valid_p): Use make_ptrmem_cst. From-SVN: r27060
Diffstat (limited to 'gcc/cp/expr.c')
-rw-r--r--gcc/cp/expr.c96
1 files changed, 59 insertions, 37 deletions
diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c
index bc745ff..83bdff9 100644
--- a/gcc/cp/expr.c
+++ b/gcc/cp/expr.c
@@ -36,6 +36,62 @@ static tree extract_scalar_init PROTO((tree, tree));
static rtx cplus_expand_expr PROTO((tree, rtx, enum machine_mode,
enum expand_modifier));
+/* Hook used by output_constant to expand language-specific
+ constants. */
+
+static tree
+cplus_expand_constant (cst)
+ tree cst;
+{
+ switch (TREE_CODE (cst))
+ {
+ case PTRMEM_CST:
+ {
+ tree type = TREE_TYPE (cst);
+ tree member;
+ tree offset;
+
+ /* Find the member. */
+ member = PTRMEM_CST_MEMBER (cst);
+
+ if (TREE_CODE (member) == FIELD_DECL)
+ {
+ /* Find the offset for the field. */
+ offset = convert (sizetype,
+ size_binop (EASY_DIV_EXPR,
+ DECL_FIELD_BITPOS (member),
+ size_int (BITS_PER_UNIT)));
+
+ /* We offset all pointer to data members by 1 so that we
+ can distinguish between a null pointer to data member
+ and the first data member of a structure. */
+ offset = size_binop (PLUS_EXPR, offset, size_int (1));
+
+ cst = cp_convert (type, offset);
+ }
+ else
+ {
+ tree delta;
+ tree idx;
+ tree pfn;
+ tree delta2;
+
+ expand_ptrmemfunc_cst (cst, &delta, &idx, &pfn, &delta2);
+
+ cst = build_ptrmemfunc1 (type, delta, idx,
+ pfn, delta2);
+ }
+ }
+ break;
+
+ default:
+ /* There's nothing to do. */
+ break;
+ }
+
+ return cst;
+}
+
/* Hook used by expand_expr to expand language-specific tree codes. */
static rtx
@@ -163,43 +219,8 @@ cplus_expand_expr (exp, target, tmode, modifier)
}
case PTRMEM_CST:
- {
- tree member;
- tree offset;
-
- /* Find the member. */
- member = PTRMEM_CST_MEMBER (exp);
-
- if (TREE_CODE (member) == FIELD_DECL)
- {
- /* Find the offset for the field. */
- offset = convert (sizetype,
- size_binop (EASY_DIV_EXPR,
- DECL_FIELD_BITPOS (member),
- size_int (BITS_PER_UNIT)));
-
- /* We offset all pointer to data members by 1 so that we
- can distinguish between a null pointer to data member
- and the first data member of a structure. */
- offset = size_binop (PLUS_EXPR, offset, size_int (1));
-
- return expand_expr (cp_convert (type, offset), target, tmode,
- modifier);
- }
- else
- {
- tree delta;
- tree idx;
- tree pfn;
- tree delta2;
-
- expand_ptrmemfunc_cst (exp, &delta, &idx, &pfn, &delta2);
-
- return expand_expr (build_ptrmemfunc1 (type, delta, idx,
- pfn, delta2),
- target, tmode, modifier);
- }
- }
+ return expand_expr (cplus_expand_constant (exp),
+ target, tmode, modifier);
case OFFSET_REF:
{
@@ -237,6 +258,7 @@ void
init_cplus_expand ()
{
lang_expand_expr = cplus_expand_expr;
+ lang_expand_constant = cplus_expand_constant;
}
/* If DECL had its rtl moved from where callers expect it