1 /* This file contains subroutine used by the C front-end to construct GENERIC.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
3 Written by Benjamin Chelf (chelf@codesourcery.com).
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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/>. */
23 #include "coretypes.h"
25 #include "tree-iterator.h"
27 /* Create an empty statement tree rooted at T. */
33 t
= alloc_stmt_list ();
34 vec_safe_push (stmt_list_stack
, t
);
38 /* Return TRUE if, after I, there are any nondebug stmts. */
41 only_debug_stmts_after_p (tree_stmt_iterator i
)
43 for (tsi_next (&i
); !tsi_end_p (i
); tsi_next (&i
))
44 if (TREE_CODE (tsi_stmt (i
)) != DEBUG_BEGIN_STMT
)
49 /* Finish the statement tree rooted at T. */
52 pop_stmt_list (tree t
)
56 /* Pop statement lists until we reach the target level. The extra
57 nestings will be due to outstanding cleanups. */
60 u
= stmt_list_stack
->pop ();
61 if (!stmt_list_stack
->is_empty ())
63 tree x
= stmt_list_stack
->last ();
64 STATEMENT_LIST_HAS_LABEL (x
) |= STATEMENT_LIST_HAS_LABEL (u
);
70 gcc_assert (u
!= NULL_TREE
);
72 /* If the statement list is completely empty, just return it. This is
73 just as good small as build_empty_stmt, with the advantage that
74 statement lists are merged when they appended to one another. So
75 using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
77 if (TREE_SIDE_EFFECTS (t
))
79 tree_stmt_iterator i
= tsi_start (t
);
81 /* If the statement list contained exactly one statement, then
82 extract it immediately. */
83 if (tsi_one_before_end_p (i
))
90 /* If the statement list contained a debug begin stmt and a
91 statement list, move the debug begin stmt into the statement
92 list and return it. */
93 else if (!tsi_end_p (i
)
94 && TREE_CODE (tsi_stmt (i
)) == DEBUG_BEGIN_STMT
)
98 if (tsi_one_before_end_p (i
)
99 && TREE_CODE (tsi_stmt (i
)) == STATEMENT_LIST
)
101 tree l
= tsi_stmt (i
);
108 tsi_link_before (&i
, u
, TSI_SAME_STMT
);
110 while (!tsi_end_p (i
)
111 && TREE_CODE (tsi_stmt (i
)) == DEBUG_BEGIN_STMT
)
113 /* If there are only debug stmts in the list, without them
114 we'd have an empty stmt without side effects. If there's
115 only one nondebug stmt, we'd have extracted the stmt and
116 dropped the list, and we'd take TREE_SIDE_EFFECTS from
117 that statement. In either case, keep the list's
118 TREE_SIDE_EFFECTS in sync. */
120 TREE_SIDE_EFFECTS (t
) = 0;
121 else if (only_debug_stmts_after_p (i
))
122 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (tsi_stmt (i
));
129 /* Build a generic statement based on the given type of node and
130 arguments. Similar to `build_nt', except that we set
131 EXPR_LOCATION to LOC. */
132 /* ??? This should be obsolete with the lineno_stmt productions
136 build_stmt (location_t loc
, enum tree_code code
, ...)
143 /* This function cannot be used to construct variably-sized nodes. */
144 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
148 ret
= make_node (code
);
149 TREE_TYPE (ret
) = void_type_node
;
150 length
= TREE_CODE_LENGTH (code
);
151 SET_EXPR_LOCATION (ret
, loc
);
153 /* TREE_SIDE_EFFECTS will already be set for statements with
154 implicit side effects. Here we make sure it is set for other
155 expressions by checking whether the parameters have side
158 side_effects
= false;
159 for (i
= 0; i
< length
; i
++)
161 tree t
= va_arg (p
, tree
);
162 if (t
&& !TYPE_P (t
))
163 side_effects
|= TREE_SIDE_EFFECTS (t
);
164 TREE_OPERAND (ret
, i
) = t
;
167 TREE_SIDE_EFFECTS (ret
) |= side_effects
;
173 /* Build a REALPART_EXPR or IMAGPART_EXPR, according to CODE, from ARG. */
176 build_real_imag_expr (location_t location
, enum tree_code code
, tree arg
)
179 tree arg_type
= TREE_TYPE (arg
);
181 gcc_assert (code
== REALPART_EXPR
|| code
== IMAGPART_EXPR
);
183 if (TREE_CODE (arg_type
) == COMPLEX_TYPE
)
185 ret
= build1 (code
, TREE_TYPE (TREE_TYPE (arg
)), arg
);
186 SET_EXPR_LOCATION (ret
, location
);
188 else if (INTEGRAL_TYPE_P (arg_type
) || SCALAR_FLOAT_TYPE_P (arg_type
))
190 ret
= (code
== REALPART_EXPR
192 : omit_one_operand_loc (location
, arg_type
,
193 integer_zero_node
, arg
));
197 error_at (location
, "wrong type argument to %s",
198 code
== REALPART_EXPR
? "__real" : "__imag");
199 ret
= error_mark_node
;