1 /* This file contains the definitions and documentation for the common
2 tree codes used in the GNU C and C++ compilers (see c-common.def
3 for the standard codes).
4 Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 Written by Benjamin Chelf (chelf@codesourcery.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "coretypes.h"
30 #include "splay-tree.h"
34 /* In order for the format checking to accept the C frontend
35 diagnostic framework extensions, you must define this token before
36 including toplev.h. */
37 #define GCC_DIAG_STYLE __gcc_cdiag__
45 #include "tree-inline.h"
46 #include "tree-gimple.h"
47 #include "langhooks.h"
49 /* Create an empty statement tree rooted at T. */
55 t
= alloc_stmt_list ();
56 TREE_CHAIN (t
) = cur_stmt_list
;
61 /* Similarly, except that T may have already been pushed/popped, and
62 thus may already contain statement(s). Arrage for new statements
66 re_push_stmt_list (tree t
)
70 if (TREE_CODE (t
) != STATEMENT_LIST
)
72 tree u
= alloc_stmt_list ();
73 append_to_statement_list_force (t
, &u
);
78 t
= alloc_stmt_list ();
79 TREE_CHAIN (t
) = cur_stmt_list
;
84 /* Finish the statement tree rooted at T. */
87 pop_stmt_list (tree t
)
89 tree u
= cur_stmt_list
, chain
;
91 /* Pop statement lists until we reach the target level. The extra
92 nestings will be due to outstanding cleanups. */
95 chain
= TREE_CHAIN (u
);
96 TREE_CHAIN (u
) = NULL_TREE
;
101 cur_stmt_list
= chain
;
103 /* If the statement list is completely empty, just return it. This is
104 just as good small as build_empty_stmt, with the advantage that
105 statement lists are merged when they appended to one another. So
106 using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
108 if (TREE_SIDE_EFFECTS (t
))
110 tree_stmt_iterator i
= tsi_start (t
);
112 /* If the statement list contained exactly one statement, then
113 extract it immediately. */
114 if (tsi_one_before_end_p (i
))
126 /* T is a statement. Add it to the statement-tree. */
131 enum tree_code code
= TREE_CODE (t
);
133 if ((EXPR_P (t
) || STATEMENT_CODE_P (code
)) && code
!= LABEL_EXPR
)
135 if (!EXPR_HAS_LOCATION (t
))
136 SET_EXPR_LOCATION (t
, input_location
);
138 /* When we expand a statement-tree, we must know whether or not the
139 statements are full-expressions. We record that fact here. */
140 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
143 /* Add T to the statement-tree. Non-side-effect statements need to be
144 recorded during statement expressions. */
145 append_to_statement_list_force (t
, &cur_stmt_list
);
150 /* Build a generic statement based on the given type of node and
151 arguments. Similar to `build_nt', except that we set
152 EXPR_LOCATION to be the current source location. */
153 /* ??? This should be obsolete with the lineno_stmt productions
157 build_stmt (enum tree_code code
, ...)
166 ret
= make_node (code
);
167 TREE_TYPE (ret
) = void_type_node
;
168 length
= TREE_CODE_LENGTH (code
);
169 SET_EXPR_LOCATION (ret
, input_location
);
171 /* Most statements have implicit side effects all on their own,
172 such as control transfer. For those that do, we'll compute
173 the real value of TREE_SIDE_EFFECTS from its arguments. */
177 side_effects
= false;
184 for (i
= 0; i
< length
; i
++)
186 tree t
= va_arg (p
, tree
);
187 if (t
&& IS_NON_TYPE_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (t
))))
188 side_effects
|= TREE_SIDE_EFFECTS (t
);
189 TREE_OPERAND (ret
, i
) = t
;
192 TREE_SIDE_EFFECTS (ret
) = side_effects
;
198 /* Create RTL for the local static variable DECL. */
201 make_rtl_for_local_static (tree decl
)
203 const char *asmspec
= NULL
;
205 /* If we inlined this variable, we could see it's declaration
207 if (TREE_ASM_WRITTEN (decl
))
210 /* If the DECL_ASSEMBLER_NAME is not the same as the DECL_NAME, then
211 either we already created RTL for this DECL (and since it was a
212 local variable, its DECL_ASSEMBLER_NAME got hacked up to prevent
213 clashes with other local statics with the same name by a previous
214 call to make_decl_rtl), or the user explicitly requested a
215 particular assembly name for this variable, using the GNU
216 extension for this purpose:
220 There's no way to know which case we're in, here. But, it turns
221 out we're safe. If there's already RTL, then
222 rest_of_decl_compilation ignores the ASMSPEC parameter, so we
223 may as well not pass it in. If there isn't RTL, then we didn't
224 already create RTL, which means that the modification to
225 DECL_ASSEMBLER_NAME came only via the explicit extension. */
226 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
227 && !DECL_RTL_SET_P (decl
))
228 asmspec
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
230 rest_of_decl_compilation (decl
, asmspec
, /*top_level=*/0, /*at_end=*/0);
233 /* Let the back-end know about DECL. */
236 emit_local_var (tree decl
)
238 /* Create RTL for this variable. */
239 if (!DECL_RTL_SET_P (decl
))
241 if (DECL_HARD_REGISTER (decl
))
242 /* The user specified an assembler name for this variable.
244 rest_of_decl_compilation
245 (decl
, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
246 /*top_level=*/0, /*at_end=*/0);
252 /* Build a break statement node and return it. */
255 build_break_stmt (void)
257 return (build_stmt (BREAK_STMT
));
260 /* Build a continue statement node and return it. */
263 build_continue_stmt (void)
265 return (build_stmt (CONTINUE_STMT
));
268 /* Create a CASE_LABEL_EXPR tree node and return it. */
271 build_case_label (tree low_value
, tree high_value
, tree label_decl
)
273 return build_stmt (CASE_LABEL_EXPR
, low_value
, high_value
, label_decl
);