Fix mistake in my previous commit (n_of_executions_at_least should be
[official-gcc.git] / gcc / cp / expr.c
blob40390028dff248aa8c2187f5361279a58baa80eb
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 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 2, 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 COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "flags.h"
31 #include "expr.h"
32 #include "cp-tree.h"
33 #include "toplev.h"
34 #include "except.h"
35 #include "tm_p.h"
37 /* Hook used by output_constant to expand language-specific
38 constants. */
40 tree
41 cplus_expand_constant (tree cst)
43 switch (TREE_CODE (cst))
45 case PTRMEM_CST:
47 tree type = TREE_TYPE (cst);
48 tree member;
50 /* Find the member. */
51 member = PTRMEM_CST_MEMBER (cst);
53 if (TREE_CODE (member) == FIELD_DECL)
55 /* Find the offset for the field. */
56 cst = byte_position (member);
57 while (!same_type_p (DECL_CONTEXT (member),
58 TYPE_PTRMEM_CLASS_TYPE (type)))
60 /* The MEMBER must have been nestled within an
61 anonymous aggregate contained in TYPE. Find the
62 anonymous aggregate. */
63 member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
64 DECL_CONTEXT (member));
65 cst = size_binop (PLUS_EXPR, cst, byte_position (member));
67 cst = fold (build_nop (type, cst));
69 else
71 tree delta;
72 tree pfn;
74 expand_ptrmemfunc_cst (cst, &delta, &pfn);
75 cst = build_ptrmemfunc1 (type, delta, pfn);
78 break;
80 default:
81 /* There's nothing to do. */
82 break;
85 return cst;
88 /* Hook used by expand_expr to expand language-specific tree codes. */
89 /* ??? The only thing that should be here are things needed to expand
90 constant initializers; everything else should be handled by the
91 gimplification routines. Are EMPTY_CLASS_EXPR or BASELINK needed? */
93 rtx
94 cxx_expand_expr (tree exp, rtx target, enum machine_mode tmode, int modifier,
95 rtx *alt_rtl)
97 tree type = TREE_TYPE (exp);
98 enum machine_mode mode = TYPE_MODE (type);
99 enum tree_code code = TREE_CODE (exp);
101 /* No sense saving up arithmetic to be done
102 if it's all in the wrong mode to form part of an address.
103 And force_operand won't know whether to sign-extend or zero-extend. */
105 if (mode != Pmode && modifier == EXPAND_SUM)
106 modifier = EXPAND_NORMAL;
108 switch (code)
110 case PTRMEM_CST:
111 return expand_expr (cplus_expand_constant (exp),
112 target, tmode, modifier);
114 case OFFSET_REF:
115 /* Offset refs should not make it through to here. */
116 gcc_unreachable ();
118 case EMPTY_CLASS_EXPR:
119 /* We don't need to generate any code for an empty class. */
120 return const0_rtx;
122 case BASELINK:
123 return expand_expr (BASELINK_FUNCTIONS (exp), target, tmode,
124 modifier);
126 default:
127 return c_expand_expr (exp, target, tmode, modifier, alt_rtl);