annotate gcc/fortran/trans-const.c @ 145:1830386684a0

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