1 /* This file contains subroutine used by the C front-end to construct GENERIC.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
3 Free Software Foundation, Inc.
4 Written by Benjamin Chelf (chelf@codesourcery.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
28 #include "splay-tree.h"
32 /* In order for the format checking to accept the C frontend
33 diagnostic framework extensions, you must define this token before
34 including toplev.h. */
35 #define GCC_DIAG_STYLE __gcc_cdiag__
43 #include "tree-inline.h"
45 #include "tree-iterator.h"
46 #include "langhooks.h"
48 /* Create an empty statement tree rooted at T. */
54 t
= alloc_stmt_list ();
55 TREE_CHAIN (t
) = cur_stmt_list
;
60 /* Finish the statement tree rooted at T. */
63 pop_stmt_list (tree t
)
65 tree u
= cur_stmt_list
, chain
;
67 /* Pop statement lists until we reach the target level. The extra
68 nestings will be due to outstanding cleanups. */
71 chain
= TREE_CHAIN (u
);
72 TREE_CHAIN (u
) = NULL_TREE
;
74 STATEMENT_LIST_HAS_LABEL (chain
) |= STATEMENT_LIST_HAS_LABEL (u
);
79 cur_stmt_list
= chain
;
81 /* If the statement list is completely empty, just return it. This is
82 just as good small as build_empty_stmt, with the advantage that
83 statement lists are merged when they appended to one another. So
84 using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
86 if (TREE_SIDE_EFFECTS (t
))
88 tree_stmt_iterator i
= tsi_start (t
);
90 /* If the statement list contained exactly one statement, then
91 extract it immediately. */
92 if (tsi_one_before_end_p (i
))
104 /* Build a generic statement based on the given type of node and
105 arguments. Similar to `build_nt', except that we set
106 EXPR_LOCATION to LOC. */
107 /* ??? This should be obsolete with the lineno_stmt productions
111 build_stmt (location_t loc
, enum tree_code code
, ...)
118 /* This function cannot be used to construct variably-sized nodes. */
119 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
123 ret
= make_node (code
);
124 TREE_TYPE (ret
) = void_type_node
;
125 length
= TREE_CODE_LENGTH (code
);
126 SET_EXPR_LOCATION (ret
, loc
);
128 /* TREE_SIDE_EFFECTS will already be set for statements with
129 implicit side effects. Here we make sure it is set for other
130 expressions by checking whether the parameters have side
133 side_effects
= false;
134 for (i
= 0; i
< length
; i
++)
136 tree t
= va_arg (p
, tree
);
137 if (t
&& !TYPE_P (t
))
138 side_effects
|= TREE_SIDE_EFFECTS (t
);
139 TREE_OPERAND (ret
, i
) = t
;
142 TREE_SIDE_EFFECTS (ret
) |= side_effects
;
148 /* Create a CASE_LABEL_EXPR tree node and return it. */
151 build_case_label (location_t loc
,
152 tree low_value
, tree high_value
, tree label_decl
)
154 return build_stmt (loc
, CASE_LABEL_EXPR
, low_value
, high_value
, label_decl
);