annotate gcc/fortran/convert.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 /* Data type conversion
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 /* This file contains the functions for converting expressions to
kono
parents:
diff changeset
22 different data types for the translation of the gfortran internal
kono
parents:
diff changeset
23 representation to GIMPLE. The only entry point is `convert'. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "config.h"
kono
parents:
diff changeset
26 #include "system.h"
kono
parents:
diff changeset
27 #include "coretypes.h"
kono
parents:
diff changeset
28 #include "tree.h"
kono
parents:
diff changeset
29 #include "fold-const.h"
kono
parents:
diff changeset
30 #include "convert.h"
kono
parents:
diff changeset
31
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
32 #include "gfortran.h"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
33 #include "trans.h"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
34 #include "trans-types.h"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
35
111
kono
parents:
diff changeset
36 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
kono
parents:
diff changeset
37 or validate its data type for a GIMPLE `if' or `while' statement.
kono
parents:
diff changeset
38
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
39 The resulting type should always be `logical_type_node'. */
111
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 static tree
kono
parents:
diff changeset
42 truthvalue_conversion (tree expr)
kono
parents:
diff changeset
43 {
kono
parents:
diff changeset
44 switch (TREE_CODE (TREE_TYPE (expr)))
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 case BOOLEAN_TYPE:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
47 if (TREE_TYPE (expr) == logical_type_node)
111
kono
parents:
diff changeset
48 return expr;
kono
parents:
diff changeset
49 else if (COMPARISON_CLASS_P (expr))
kono
parents:
diff changeset
50 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 TREE_TYPE (expr) = logical_type_node;
111
kono
parents:
diff changeset
52 return expr;
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54 else if (TREE_CODE (expr) == NOP_EXPR)
kono
parents:
diff changeset
55 return fold_build1_loc (input_location, NOP_EXPR,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 logical_type_node,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 TREE_OPERAND (expr, 0));
111
kono
parents:
diff changeset
58 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 return fold_build1_loc (input_location, NOP_EXPR,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60 logical_type_node,
111
kono
parents:
diff changeset
61 expr);
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 case INTEGER_TYPE:
kono
parents:
diff changeset
64 if (TREE_CODE (expr) == INTEGER_CST)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 return integer_zerop (expr) ? logical_false_node
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
66 : logical_true_node;
111
kono
parents:
diff changeset
67 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 return fold_build2_loc (input_location, NE_EXPR,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69 logical_type_node,
111
kono
parents:
diff changeset
70 expr, build_int_cst (TREE_TYPE (expr), 0));
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 default:
kono
parents:
diff changeset
73 gcc_unreachable ();
kono
parents:
diff changeset
74 }
kono
parents:
diff changeset
75 }
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 /* Create an expression whose value is that of EXPR,
kono
parents:
diff changeset
78 converted to type TYPE. The TREE_TYPE of the value
kono
parents:
diff changeset
79 is always TYPE. This function implements all reasonable
kono
parents:
diff changeset
80 conversions; callers should filter out those that are
kono
parents:
diff changeset
81 not permitted by the language being compiled. */
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 tree
kono
parents:
diff changeset
84 convert (tree type, tree expr)
kono
parents:
diff changeset
85 {
kono
parents:
diff changeset
86 tree e = expr;
kono
parents:
diff changeset
87 enum tree_code code;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 if (type == TREE_TYPE (expr))
kono
parents:
diff changeset
90 return expr;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 if (TREE_CODE (type) == ERROR_MARK
kono
parents:
diff changeset
93 || TREE_CODE (expr) == ERROR_MARK
kono
parents:
diff changeset
94 || TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
kono
parents:
diff changeset
95 return expr;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 gcc_checking_assert (TREE_CODE (TREE_TYPE (expr)) != VOID_TYPE);
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
kono
parents:
diff changeset
100 return fold_build1_loc (input_location, NOP_EXPR, type, expr);
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 code = TREE_CODE (type);
kono
parents:
diff changeset
103 if (code == VOID_TYPE)
kono
parents:
diff changeset
104 return fold_build1_loc (input_location, CONVERT_EXPR, type, e);
kono
parents:
diff changeset
105 if (code == BOOLEAN_TYPE)
kono
parents:
diff changeset
106 return fold_build1_loc (input_location, NOP_EXPR, type,
kono
parents:
diff changeset
107 truthvalue_conversion (e));
kono
parents:
diff changeset
108 if (code == INTEGER_TYPE)
kono
parents:
diff changeset
109 return fold (convert_to_integer (type, e));
kono
parents:
diff changeset
110 if (code == POINTER_TYPE || code == REFERENCE_TYPE)
kono
parents:
diff changeset
111 return fold (convert_to_pointer (type, e));
kono
parents:
diff changeset
112 if (code == REAL_TYPE)
kono
parents:
diff changeset
113 return fold (convert_to_real (type, e));
kono
parents:
diff changeset
114 if (code == COMPLEX_TYPE)
kono
parents:
diff changeset
115 return fold (convert_to_complex (type, e));
kono
parents:
diff changeset
116 if (code == VECTOR_TYPE)
kono
parents:
diff changeset
117 return fold (convert_to_vector (type, e));
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 gcc_unreachable ();
kono
parents:
diff changeset
120 }
kono
parents:
diff changeset
121