Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / cp / expr.c
blob681834d9a377cfa77d6ee803c3ccebd6afa0744e
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, 2010 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 "tree.h"
28 #include "flags.h"
29 #include "cp-tree.h"
30 #include "toplev.h"
31 #include "tm_p.h"
33 /* Expand C++-specific constants. Currently, this means PTRMEM_CST. */
35 tree
36 cplus_expand_constant (tree cst)
38 switch (TREE_CODE (cst))
40 case PTRMEM_CST:
42 tree type = TREE_TYPE (cst);
43 tree member;
45 /* Find the member. */
46 member = PTRMEM_CST_MEMBER (cst);
48 if (TREE_CODE (member) == FIELD_DECL)
50 /* Find the offset for the field. */
51 cst = byte_position (member);
52 while (!same_type_p (DECL_CONTEXT (member),
53 TYPE_PTRMEM_CLASS_TYPE (type)))
55 /* The MEMBER must have been nestled within an
56 anonymous aggregate contained in TYPE. Find the
57 anonymous aggregate. */
58 member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
59 DECL_CONTEXT (member));
60 cst = size_binop (PLUS_EXPR, cst, byte_position (member));
62 cst = fold (build_nop (type, cst));
64 else
66 tree delta;
67 tree pfn;
69 expand_ptrmemfunc_cst (cst, &delta, &pfn);
70 cst = build_ptrmemfunc1 (type, delta, pfn);
73 break;
75 default:
76 /* There's nothing to do. */
77 break;
80 return cst;
83 /* Called whenever an expression is used
84 in a rvalue context. */
86 tree
87 mark_rvalue_use (tree expr)
89 mark_exp_read (expr);
90 return expr;
93 /* Called whenever an expression is used
94 in a lvalue context. */
96 tree
97 mark_lvalue_use (tree expr)
99 mark_exp_read (expr);
100 return expr;
103 /* Called whenever an expression is used in a type use context. */
105 tree
106 mark_type_use (tree expr)
108 mark_exp_read (expr);
109 return expr;
112 /* Mark EXP as read, not just set, for set but not used -Wunused
113 warning purposes. */
115 void
116 mark_exp_read (tree exp)
118 if (exp == NULL)
119 return;
121 switch (TREE_CODE (exp))
123 case VAR_DECL:
124 case PARM_DECL:
125 DECL_READ_P (exp) = 1;
126 break;
127 case ARRAY_REF:
128 case COMPONENT_REF:
129 case MODIFY_EXPR:
130 case REALPART_EXPR:
131 case IMAGPART_EXPR:
132 CASE_CONVERT:
133 case ADDR_EXPR:
134 case INDIRECT_REF:
135 mark_exp_read (TREE_OPERAND (exp, 0));
136 break;
137 case COMPOUND_EXPR:
138 mark_exp_read (TREE_OPERAND (exp, 1));
139 break;
140 case COND_EXPR:
141 if (TREE_OPERAND (exp, 1))
142 mark_exp_read (TREE_OPERAND (exp, 1));
143 if (TREE_OPERAND (exp, 2))
144 mark_exp_read (TREE_OPERAND (exp, 2));
145 break;
146 default:
147 break;