Add C++11 header <cuchar>.
[official-gcc.git] / gcc / cp / expr.c
blob71dec3da0335df86bc28034d6b0f820dc43658c4
1 /* Convert language-specific tree expression to rtl instructions,
2 for GNU compiler.
3 Copyright (C) 1988-2015 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "alias.h"
27 #include "tree.h"
28 #include "flags.h"
29 #include "cp-tree.h"
30 #include "tm_p.h"
32 /* Expand C++-specific constants. Currently, this means PTRMEM_CST. */
34 tree
35 cplus_expand_constant (tree cst)
37 switch (TREE_CODE (cst))
39 case PTRMEM_CST:
41 tree type = TREE_TYPE (cst);
42 tree member;
44 /* Find the member. */
45 member = PTRMEM_CST_MEMBER (cst);
47 /* We can't lower this until the class is complete. */
48 if (!COMPLETE_TYPE_P (DECL_CONTEXT (member)))
49 return 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 case CONSTRUCTOR:
80 constructor_elt *elt;
81 unsigned HOST_WIDE_INT idx;
82 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (cst), idx, elt)
83 elt->value = cplus_expand_constant (elt->value);
86 default:
87 /* There's nothing to do. */
88 break;
91 return cst;
94 /* Called whenever the expression EXPR is used in an rvalue context.
95 When REJECT_BUILTIN is true the expression is checked to make sure
96 it doesn't make it possible to obtain the address of a GCC built-in
97 function with no library fallback (or any of its bits, such as in
98 a conversion to bool). */
99 tree
100 mark_rvalue_use (tree expr,
101 location_t loc /* = UNKNOWN_LOCATION */,
102 bool reject_builtin /* = true */)
104 if (reject_builtin && reject_gcc_builtin (expr, loc))
105 return error_mark_node;
107 mark_exp_read (expr);
108 return expr;
111 /* Called whenever an expression is used in an lvalue context. */
113 tree
114 mark_lvalue_use (tree expr)
116 mark_exp_read (expr);
117 return expr;
120 /* Called whenever an expression is used in a type use context. */
122 tree
123 mark_type_use (tree expr)
125 mark_exp_read (expr);
126 return expr;
129 /* Mark EXP as read, not just set, for set but not used -Wunused
130 warning purposes. */
132 void
133 mark_exp_read (tree exp)
135 if (exp == NULL)
136 return;
138 switch (TREE_CODE (exp))
140 case VAR_DECL:
141 case PARM_DECL:
142 DECL_READ_P (exp) = 1;
143 break;
144 case ARRAY_REF:
145 case COMPONENT_REF:
146 case MODIFY_EXPR:
147 case REALPART_EXPR:
148 case IMAGPART_EXPR:
149 CASE_CONVERT:
150 case ADDR_EXPR:
151 case INDIRECT_REF:
152 case FLOAT_EXPR:
153 mark_exp_read (TREE_OPERAND (exp, 0));
154 break;
155 case COMPOUND_EXPR:
156 mark_exp_read (TREE_OPERAND (exp, 1));
157 break;
158 case COND_EXPR:
159 if (TREE_OPERAND (exp, 1))
160 mark_exp_read (TREE_OPERAND (exp, 1));
161 if (TREE_OPERAND (exp, 2))
162 mark_exp_read (TREE_OPERAND (exp, 2));
163 break;
164 default:
165 break;