annotate gcc/fortran/trans-const.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Translation of constants
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2002-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Paul Brook
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* trans-const.c -- convert constant values */
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #include "config.h"
kono
parents:
diff changeset
24 #include "system.h"
kono
parents:
diff changeset
25 #include "coretypes.h"
kono
parents:
diff changeset
26 #include "tree.h"
kono
parents:
diff changeset
27 #include "gfortran.h"
kono
parents:
diff changeset
28 #include "trans.h"
kono
parents:
diff changeset
29 #include "fold-const.h"
kono
parents:
diff changeset
30 #include "stor-layout.h"
kono
parents:
diff changeset
31 #include "realmpfr.h"
kono
parents:
diff changeset
32 #include "trans-const.h"
kono
parents:
diff changeset
33 #include "trans-types.h"
kono
parents:
diff changeset
34 #include "target-memory.h"
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 tree gfc_rank_cst[GFC_MAX_DIMENSIONS + 1];
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 /* Build a constant with given type from an int_cst. */
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 tree
kono
parents:
diff changeset
41 gfc_build_const (tree type, tree intval)
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 tree val;
kono
parents:
diff changeset
44 tree zero;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 switch (TREE_CODE (type))
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 case INTEGER_TYPE:
kono
parents:
diff changeset
49 val = convert (type, intval);
kono
parents:
diff changeset
50 break;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 case REAL_TYPE:
kono
parents:
diff changeset
53 val = build_real_from_int_cst (type, intval);
kono
parents:
diff changeset
54 break;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 case COMPLEX_TYPE:
kono
parents:
diff changeset
57 val = build_real_from_int_cst (TREE_TYPE (type), intval);
kono
parents:
diff changeset
58 zero = build_real_from_int_cst (TREE_TYPE (type), integer_zero_node);
kono
parents:
diff changeset
59 val = build_complex (type, val, zero);
kono
parents:
diff changeset
60 break;
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 default:
kono
parents:
diff changeset
63 gcc_unreachable ();
kono
parents:
diff changeset
64 }
kono
parents:
diff changeset
65 return val;
kono
parents:
diff changeset
66 }
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Build a string constant with C char type. */
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 tree
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 gfc_build_string_const (size_t length, const char *s)
111
kono
parents:
diff changeset
72 {
kono
parents:
diff changeset
73 tree str;
kono
parents:
diff changeset
74 tree len;
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 str = build_string (length, s);
kono
parents:
diff changeset
77 len = size_int (length);
kono
parents:
diff changeset
78 TREE_TYPE (str) =
kono
parents:
diff changeset
79 build_array_type (gfc_character1_type_node,
kono
parents:
diff changeset
80 build_range_type (gfc_charlen_type_node,
kono
parents:
diff changeset
81 size_one_node, len));
kono
parents:
diff changeset
82 TYPE_STRING_FLAG (TREE_TYPE (str)) = 1;
kono
parents:
diff changeset
83 return str;
kono
parents:
diff changeset
84 }
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /* Build a string constant with a type given by its kind; take care of
kono
parents:
diff changeset
88 non-default character kinds. */
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 tree
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 gfc_build_wide_string_const (int kind, size_t length, const gfc_char_t *string)
111
kono
parents:
diff changeset
92 {
kono
parents:
diff changeset
93 int i;
kono
parents:
diff changeset
94 tree str, len;
kono
parents:
diff changeset
95 size_t size;
kono
parents:
diff changeset
96 char *s;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 i = gfc_validate_kind (BT_CHARACTER, kind, false);
kono
parents:
diff changeset
99 size = length * gfc_character_kinds[i].bit_size / 8;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 s = XCNEWVAR (char, size);
kono
parents:
diff changeset
102 gfc_encode_character (kind, length, string, (unsigned char *) s, size);
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 str = build_string (size, s);
kono
parents:
diff changeset
105 free (s);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 len = size_int (length);
kono
parents:
diff changeset
108 TREE_TYPE (str) =
kono
parents:
diff changeset
109 build_array_type (gfc_get_char_type (kind),
kono
parents:
diff changeset
110 build_range_type (gfc_charlen_type_node,
kono
parents:
diff changeset
111 size_one_node, len));
kono
parents:
diff changeset
112 TYPE_STRING_FLAG (TREE_TYPE (str)) = 1;
kono
parents:
diff changeset
113 return str;
kono
parents:
diff changeset
114 }
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* Build a Fortran character constant from a zero-terminated string.
kono
parents:
diff changeset
118 There a two version of this function, one that translates the string
kono
parents:
diff changeset
119 and one that doesn't. */
kono
parents:
diff changeset
120 tree
kono
parents:
diff changeset
121 gfc_build_cstring_const (const char *string)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 return gfc_build_string_const (strlen (string) + 1, string);
kono
parents:
diff changeset
124 }
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 tree
kono
parents:
diff changeset
127 gfc_build_localized_cstring_const (const char *msgid)
kono
parents:
diff changeset
128 {
kono
parents:
diff changeset
129 const char *localized = _(msgid);
kono
parents:
diff changeset
130 return gfc_build_string_const (strlen (localized) + 1, localized);
kono
parents:
diff changeset
131 }
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 /* Return a string constant with the given length. Used for static
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 initializers. The constant will be padded or truncated to match
111
kono
parents:
diff changeset
136 length. */
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 tree
kono
parents:
diff changeset
139 gfc_conv_string_init (tree length, gfc_expr * expr)
kono
parents:
diff changeset
140 {
kono
parents:
diff changeset
141 gfc_char_t *s;
kono
parents:
diff changeset
142 HOST_WIDE_INT len;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 gfc_charlen_t slen;
111
kono
parents:
diff changeset
144 tree str;
kono
parents:
diff changeset
145 bool free_s = false;
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 gcc_assert (expr->expr_type == EXPR_CONSTANT);
kono
parents:
diff changeset
148 gcc_assert (expr->ts.type == BT_CHARACTER);
kono
parents:
diff changeset
149 gcc_assert (tree_fits_uhwi_p (length));
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 len = TREE_INT_CST_LOW (length);
kono
parents:
diff changeset
152 slen = expr->value.character.length;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 if (len > slen)
kono
parents:
diff changeset
155 {
kono
parents:
diff changeset
156 s = gfc_get_wide_string (len);
kono
parents:
diff changeset
157 memcpy (s, expr->value.character.string, slen * sizeof (gfc_char_t));
kono
parents:
diff changeset
158 gfc_wide_memset (&s[slen], ' ', len - slen);
kono
parents:
diff changeset
159 free_s = true;
kono
parents:
diff changeset
160 }
kono
parents:
diff changeset
161 else
kono
parents:
diff changeset
162 s = expr->value.character.string;
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 str = gfc_build_wide_string_const (expr->ts.kind, len, s);
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 if (free_s)
kono
parents:
diff changeset
167 free (s);
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 return str;
kono
parents:
diff changeset
170 }
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 /* Create a tree node for the string length if it is constant. */
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 void
kono
parents:
diff changeset
176 gfc_conv_const_charlen (gfc_charlen * cl)
kono
parents:
diff changeset
177 {
kono
parents:
diff changeset
178 if (!cl || cl->backend_decl)
kono
parents:
diff changeset
179 return;
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 if (cl->length && cl->length->expr_type == EXPR_CONSTANT)
kono
parents:
diff changeset
182 {
kono
parents:
diff changeset
183 cl->backend_decl = gfc_conv_mpz_to_tree (cl->length->value.integer,
kono
parents:
diff changeset
184 cl->length->ts.kind);
kono
parents:
diff changeset
185 cl->backend_decl = fold_convert (gfc_charlen_type_node,
kono
parents:
diff changeset
186 cl->backend_decl);
kono
parents:
diff changeset
187 }
kono
parents:
diff changeset
188 }
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 void
kono
parents:
diff changeset
191 gfc_init_constants (void)
kono
parents:
diff changeset
192 {
kono
parents:
diff changeset
193 int n;
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 for (n = 0; n <= GFC_MAX_DIMENSIONS; n++)
kono
parents:
diff changeset
196 gfc_rank_cst[n] = build_int_cst (gfc_array_index_type, n);
kono
parents:
diff changeset
197 }
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 /* Converts a GMP integer into a backend tree node. */
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 tree
kono
parents:
diff changeset
202 gfc_conv_mpz_to_tree (mpz_t i, int kind)
kono
parents:
diff changeset
203 {
kono
parents:
diff changeset
204 wide_int val = wi::from_mpz (gfc_get_int_type (kind), i, true);
kono
parents:
diff changeset
205 return wide_int_to_tree (gfc_get_int_type (kind), val);
kono
parents:
diff changeset
206 }
kono
parents:
diff changeset
207
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
208
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
209 /* Convert a GMP integer into a tree node of type given by the type
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
210 argument. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
211
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
212 tree
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
213 gfc_conv_mpz_to_tree_type (mpz_t i, const tree type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
214 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
215 const wide_int val = wi::from_mpz (type, i, true);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
216 return wide_int_to_tree (type, val);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
217 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
218
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
219
111
kono
parents:
diff changeset
220 /* Converts a backend tree into a GMP integer. */
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 void
kono
parents:
diff changeset
223 gfc_conv_tree_to_mpz (mpz_t i, tree source)
kono
parents:
diff changeset
224 {
kono
parents:
diff changeset
225 wi::to_mpz (wi::to_wide (source), i, TYPE_SIGN (TREE_TYPE (source)));
kono
parents:
diff changeset
226 }
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 /* Converts a real constant into backend form. */
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 tree
kono
parents:
diff changeset
231 gfc_conv_mpfr_to_tree (mpfr_t f, int kind, int is_snan)
kono
parents:
diff changeset
232 {
kono
parents:
diff changeset
233 tree type;
kono
parents:
diff changeset
234 int n;
kono
parents:
diff changeset
235 REAL_VALUE_TYPE real;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 n = gfc_validate_kind (BT_REAL, kind, false);
kono
parents:
diff changeset
238 gcc_assert (gfc_real_kinds[n].radix == 2);
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 type = gfc_get_real_type (kind);
kono
parents:
diff changeset
241 if (mpfr_nan_p (f) && is_snan)
kono
parents:
diff changeset
242 real_from_string (&real, "SNaN");
kono
parents:
diff changeset
243 else
kono
parents:
diff changeset
244 real_from_mpfr (&real, f, type, GFC_RND_MODE);
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 return build_real (type, real);
kono
parents:
diff changeset
247 }
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 /* Returns a real constant that is +Infinity if the target
kono
parents:
diff changeset
250 supports infinities for this floating-point mode, and
kono
parents:
diff changeset
251 +HUGE_VAL otherwise (the largest representable number). */
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 tree
kono
parents:
diff changeset
254 gfc_build_inf_or_huge (tree type, int kind)
kono
parents:
diff changeset
255 {
kono
parents:
diff changeset
256 if (HONOR_INFINITIES (TYPE_MODE (type)))
kono
parents:
diff changeset
257 {
kono
parents:
diff changeset
258 REAL_VALUE_TYPE real;
kono
parents:
diff changeset
259 real_inf (&real);
kono
parents:
diff changeset
260 return build_real (type, real);
kono
parents:
diff changeset
261 }
kono
parents:
diff changeset
262 else
kono
parents:
diff changeset
263 {
kono
parents:
diff changeset
264 int k = gfc_validate_kind (BT_REAL, kind, false);
kono
parents:
diff changeset
265 return gfc_conv_mpfr_to_tree (gfc_real_kinds[k].huge, kind, 0);
kono
parents:
diff changeset
266 }
kono
parents:
diff changeset
267 }
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 /* Returns a floating-point NaN of a given type. */
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 tree
kono
parents:
diff changeset
272 gfc_build_nan (tree type, const char *str)
kono
parents:
diff changeset
273 {
kono
parents:
diff changeset
274 REAL_VALUE_TYPE real;
kono
parents:
diff changeset
275 real_nan (&real, str, 1, TYPE_MODE (type));
kono
parents:
diff changeset
276 return build_real (type, real);
kono
parents:
diff changeset
277 }
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 /* Converts a backend tree into a real constant. */
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 void
kono
parents:
diff changeset
282 gfc_conv_tree_to_mpfr (mpfr_ptr f, tree source)
kono
parents:
diff changeset
283 {
kono
parents:
diff changeset
284 mpfr_from_real (f, TREE_REAL_CST_PTR (source), GFC_RND_MODE);
kono
parents:
diff changeset
285 }
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 /* Translate any literal constant to a tree. Constants never have
kono
parents:
diff changeset
288 pre or post chains. Character literal constants are special
kono
parents:
diff changeset
289 special because they have a value and a length, so they cannot be
kono
parents:
diff changeset
290 returned as a single tree. It is up to the caller to set the
kono
parents:
diff changeset
291 length somewhere if necessary.
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 Returns the translated constant, or aborts if it gets a type it
kono
parents:
diff changeset
294 can't handle. */
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 tree
kono
parents:
diff changeset
297 gfc_conv_constant_to_tree (gfc_expr * expr)
kono
parents:
diff changeset
298 {
kono
parents:
diff changeset
299 tree res;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 gcc_assert (expr->expr_type == EXPR_CONSTANT);
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 /* If it is has a prescribed memory representation, we build a string
kono
parents:
diff changeset
304 constant and VIEW_CONVERT to its type. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
305
111
kono
parents:
diff changeset
306 switch (expr->ts.type)
kono
parents:
diff changeset
307 {
kono
parents:
diff changeset
308 case BT_INTEGER:
kono
parents:
diff changeset
309 if (expr->representation.string)
kono
parents:
diff changeset
310 return fold_build1_loc (input_location, VIEW_CONVERT_EXPR,
kono
parents:
diff changeset
311 gfc_get_int_type (expr->ts.kind),
kono
parents:
diff changeset
312 gfc_build_string_const (expr->representation.length,
kono
parents:
diff changeset
313 expr->representation.string));
kono
parents:
diff changeset
314 else
kono
parents:
diff changeset
315 return gfc_conv_mpz_to_tree (expr->value.integer, expr->ts.kind);
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 case BT_REAL:
kono
parents:
diff changeset
318 if (expr->representation.string)
kono
parents:
diff changeset
319 return fold_build1_loc (input_location, VIEW_CONVERT_EXPR,
kono
parents:
diff changeset
320 gfc_get_real_type (expr->ts.kind),
kono
parents:
diff changeset
321 gfc_build_string_const (expr->representation.length,
kono
parents:
diff changeset
322 expr->representation.string));
kono
parents:
diff changeset
323 else
kono
parents:
diff changeset
324 return gfc_conv_mpfr_to_tree (expr->value.real, expr->ts.kind, expr->is_snan);
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 case BT_LOGICAL:
kono
parents:
diff changeset
327 if (expr->representation.string)
kono
parents:
diff changeset
328 {
kono
parents:
diff changeset
329 tree tmp = fold_build1_loc (input_location, VIEW_CONVERT_EXPR,
kono
parents:
diff changeset
330 gfc_get_int_type (expr->ts.kind),
kono
parents:
diff changeset
331 gfc_build_string_const (expr->representation.length,
kono
parents:
diff changeset
332 expr->representation.string));
kono
parents:
diff changeset
333 if (!integer_zerop (tmp) && !integer_onep (tmp))
kono
parents:
diff changeset
334 gfc_warning (0, "Assigning value other than 0 or 1 to LOGICAL"
kono
parents:
diff changeset
335 " has undefined result at %L", &expr->where);
kono
parents:
diff changeset
336 return fold_convert (gfc_get_logical_type (expr->ts.kind), tmp);
kono
parents:
diff changeset
337 }
kono
parents:
diff changeset
338 else
kono
parents:
diff changeset
339 return build_int_cst (gfc_get_logical_type (expr->ts.kind),
kono
parents:
diff changeset
340 expr->value.logical);
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 case BT_COMPLEX:
kono
parents:
diff changeset
343 if (expr->representation.string)
kono
parents:
diff changeset
344 return fold_build1_loc (input_location, VIEW_CONVERT_EXPR,
kono
parents:
diff changeset
345 gfc_get_complex_type (expr->ts.kind),
kono
parents:
diff changeset
346 gfc_build_string_const (expr->representation.length,
kono
parents:
diff changeset
347 expr->representation.string));
kono
parents:
diff changeset
348 else
kono
parents:
diff changeset
349 {
kono
parents:
diff changeset
350 tree real = gfc_conv_mpfr_to_tree (mpc_realref (expr->value.complex),
kono
parents:
diff changeset
351 expr->ts.kind, expr->is_snan);
kono
parents:
diff changeset
352 tree imag = gfc_conv_mpfr_to_tree (mpc_imagref (expr->value.complex),
kono
parents:
diff changeset
353 expr->ts.kind, expr->is_snan);
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 return build_complex (gfc_typenode_for_spec (&expr->ts),
kono
parents:
diff changeset
356 real, imag);
kono
parents:
diff changeset
357 }
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 case BT_CHARACTER:
kono
parents:
diff changeset
360 res = gfc_build_wide_string_const (expr->ts.kind,
kono
parents:
diff changeset
361 expr->value.character.length,
kono
parents:
diff changeset
362 expr->value.character.string);
kono
parents:
diff changeset
363 return res;
kono
parents:
diff changeset
364
kono
parents:
diff changeset
365 case BT_HOLLERITH:
kono
parents:
diff changeset
366 return gfc_build_string_const (expr->representation.length,
kono
parents:
diff changeset
367 expr->representation.string);
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 default:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
370 gcc_unreachable ();
111
kono
parents:
diff changeset
371 }
kono
parents:
diff changeset
372 }
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 /* Like gfc_conv_constant_to_tree, but for a simplified expression.
kono
parents:
diff changeset
376 We can handle character literal constants here as well. */
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 void
kono
parents:
diff changeset
379 gfc_conv_constant (gfc_se * se, gfc_expr * expr)
kono
parents:
diff changeset
380 {
kono
parents:
diff changeset
381 gfc_ss *ss;
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 /* We may be receiving an expression for C_NULL_PTR or C_NULL_FUNPTR. If
kono
parents:
diff changeset
384 so, the expr_type will not yet be an EXPR_CONSTANT. We need to make
kono
parents:
diff changeset
385 it so here. */
kono
parents:
diff changeset
386 if (expr->ts.type == BT_DERIVED && expr->ts.u.derived
kono
parents:
diff changeset
387 && expr->ts.u.derived->attr.is_iso_c)
kono
parents:
diff changeset
388 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
389 if (expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_PTR
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
390 || expr->symtree->n.sym->intmod_sym_id == ISOCBINDING_NULL_FUNPTR)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
391 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
392 /* Create a new EXPR_CONSTANT expression for our local uses. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
393 expr = gfc_get_int_expr (gfc_default_integer_kind, NULL, 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
394 }
111
kono
parents:
diff changeset
395 }
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 if (expr->expr_type != EXPR_CONSTANT)
kono
parents:
diff changeset
398 {
kono
parents:
diff changeset
399 gfc_expr *e = gfc_get_int_expr (gfc_default_integer_kind, NULL, 0);
kono
parents:
diff changeset
400 gfc_error ("non-constant initialization expression at %L", &expr->where);
kono
parents:
diff changeset
401 se->expr = gfc_conv_constant_to_tree (e);
kono
parents:
diff changeset
402 return;
kono
parents:
diff changeset
403 }
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 ss = se->ss;
kono
parents:
diff changeset
406 if (ss != NULL)
kono
parents:
diff changeset
407 {
kono
parents:
diff changeset
408 gfc_ss_info *ss_info;
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 ss_info = ss->info;
kono
parents:
diff changeset
411 gcc_assert (ss != gfc_ss_terminator);
kono
parents:
diff changeset
412 gcc_assert (ss_info->type == GFC_SS_SCALAR);
kono
parents:
diff changeset
413 gcc_assert (ss_info->expr == expr);
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 se->expr = ss_info->data.scalar.value;
kono
parents:
diff changeset
416 se->string_length = ss_info->string_length;
kono
parents:
diff changeset
417 gfc_advance_se_ss_chain (se);
kono
parents:
diff changeset
418 return;
kono
parents:
diff changeset
419 }
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 /* Translate the constant and put it in the simplifier structure. */
kono
parents:
diff changeset
422 se->expr = gfc_conv_constant_to_tree (expr);
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 /* If this is a CHARACTER string, set its length in the simplifier
kono
parents:
diff changeset
425 structure, too. */
kono
parents:
diff changeset
426 if (expr->ts.type == BT_CHARACTER)
kono
parents:
diff changeset
427 se->string_length = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (se->expr)));
kono
parents:
diff changeset
428 }