2015-06-23 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc.git] / gcc / cp / expr.c
blob4270fffe50970459170b90d2b83e040d1b8e2f10
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 "symtab.h"
28 #include "tree.h"
29 #include "flags.h"
30 #include "cp-tree.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 /* We can't lower this until the class is complete. */
49 if (!COMPLETE_TYPE_P (DECL_CONTEXT (member)))
50 return cst;
52 if (TREE_CODE (member) == FIELD_DECL)
54 /* Find the offset for the field. */
55 cst = byte_position (member);
56 while (!same_type_p (DECL_CONTEXT (member),
57 TYPE_PTRMEM_CLASS_TYPE (type)))
59 /* The MEMBER must have been nestled within an
60 anonymous aggregate contained in TYPE. Find the
61 anonymous aggregate. */
62 member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
63 DECL_CONTEXT (member));
64 cst = size_binop (PLUS_EXPR, cst, byte_position (member));
66 cst = fold (build_nop (type, cst));
68 else
70 tree delta;
71 tree pfn;
73 expand_ptrmemfunc_cst (cst, &delta, &pfn);
74 cst = build_ptrmemfunc1 (type, delta, pfn);
77 break;
79 case CONSTRUCTOR:
81 constructor_elt *elt;
82 unsigned HOST_WIDE_INT idx;
83 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (cst), idx, elt)
84 elt->value = cplus_expand_constant (elt->value);
87 default:
88 /* There's nothing to do. */
89 break;
92 return cst;
95 /* Called whenever an expression is used
96 in a rvalue context. */
98 tree
99 mark_rvalue_use (tree expr)
101 mark_exp_read (expr);
102 return expr;
105 /* Called whenever an expression is used
106 in a lvalue context. */
108 tree
109 mark_lvalue_use (tree expr)
111 mark_exp_read (expr);
112 return expr;
115 /* Called whenever an expression is used in a type use context. */
117 tree
118 mark_type_use (tree expr)
120 mark_exp_read (expr);
121 return expr;
124 /* Mark EXP as read, not just set, for set but not used -Wunused
125 warning purposes. */
127 void
128 mark_exp_read (tree exp)
130 if (exp == NULL)
131 return;
133 switch (TREE_CODE (exp))
135 case VAR_DECL:
136 case PARM_DECL:
137 DECL_READ_P (exp) = 1;
138 break;
139 case ARRAY_REF:
140 case COMPONENT_REF:
141 case MODIFY_EXPR:
142 case REALPART_EXPR:
143 case IMAGPART_EXPR:
144 CASE_CONVERT:
145 case ADDR_EXPR:
146 case INDIRECT_REF:
147 case FLOAT_EXPR:
148 mark_exp_read (TREE_OPERAND (exp, 0));
149 break;
150 case COMPOUND_EXPR:
151 mark_exp_read (TREE_OPERAND (exp, 1));
152 break;
153 case COND_EXPR:
154 if (TREE_OPERAND (exp, 1))
155 mark_exp_read (TREE_OPERAND (exp, 1));
156 if (TREE_OPERAND (exp, 2))
157 mark_exp_read (TREE_OPERAND (exp, 2));
158 break;
159 default:
160 break;