mips-protos.h (mips_regno_mode_ok_for_base_p): Give the STRICT_P argument type "bool...
[official-gcc.git] / gcc / cp / expr.c
blobb5186462e5ec3efe0da76e1350dc423d1aafbdae
1 /* Convert language-specific tree expression to rtl instructions,
2 for GNU compiler.
3 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "rtl.h"
28 #include "tree.h"
29 #include "flags.h"
30 #include "expr.h"
31 #include "cp-tree.h"
32 #include "toplev.h"
33 #include "except.h"
34 #include "tm_p.h"
36 /* Expand C++-specific constants. Currently, this means PTRMEM_CST. */
38 tree
39 cplus_expand_constant (tree cst)
41 switch (TREE_CODE (cst))
43 case PTRMEM_CST:
45 tree type = TREE_TYPE (cst);
46 tree member;
48 /* Find the member. */
49 member = PTRMEM_CST_MEMBER (cst);
51 if (TREE_CODE (member) == FIELD_DECL)
53 /* Find the offset for the field. */
54 cst = byte_position (member);
55 while (!same_type_p (DECL_CONTEXT (member),
56 TYPE_PTRMEM_CLASS_TYPE (type)))
58 /* The MEMBER must have been nestled within an
59 anonymous aggregate contained in TYPE. Find the
60 anonymous aggregate. */
61 member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
62 DECL_CONTEXT (member));
63 cst = size_binop (PLUS_EXPR, cst, byte_position (member));
65 cst = fold (build_nop (type, cst));
67 else
69 tree delta;
70 tree pfn;
72 expand_ptrmemfunc_cst (cst, &delta, &pfn);
73 cst = build_ptrmemfunc1 (type, delta, pfn);
76 break;
78 default:
79 /* There's nothing to do. */
80 break;
83 return cst;
86 /* Hook used by expand_expr to expand language-specific tree codes. */
87 /* ??? The only thing that should be here are things needed to expand
88 constant initializers; everything else should be handled by the
89 gimplification routines. Are EMPTY_CLASS_EXPR or BASELINK needed? */
91 rtx
92 cxx_expand_expr (tree exp, rtx target, enum machine_mode tmode, int modifier,
93 rtx *alt_rtl)
95 tree type = TREE_TYPE (exp);
96 enum machine_mode mode = TYPE_MODE (type);
97 enum tree_code code = TREE_CODE (exp);
99 /* No sense saving up arithmetic to be done
100 if it's all in the wrong mode to form part of an address.
101 And force_operand won't know whether to sign-extend or zero-extend. */
103 if (mode != Pmode && modifier == EXPAND_SUM)
104 modifier = EXPAND_NORMAL;
106 switch (code)
108 case PTRMEM_CST:
109 return expand_expr (cplus_expand_constant (exp),
110 target, tmode, modifier);
112 case OFFSET_REF:
113 /* Offset refs should not make it through to here. */
114 gcc_unreachable ();
116 case EMPTY_CLASS_EXPR:
117 /* We don't need to generate any code for an empty class. */
118 return const0_rtx;
120 case BASELINK:
121 return expand_expr (BASELINK_FUNCTIONS (exp), target, tmode,
122 modifier);
124 default:
125 return c_expand_expr (exp, target, tmode, modifier, alt_rtl);