Daily bump.
[official-gcc.git] / gcc / c-semantics.c
blob1acf6e899560c54ee1c06b19dc36166f978e381d
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, 2005
5 Free Software Foundation, Inc.
6 Written by Benjamin Chelf (chelf@codesourcery.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 02111-1307, USA. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "tree.h"
30 #include "function.h"
31 #include "splay-tree.h"
32 #include "varray.h"
33 #include "c-common.h"
34 #include "except.h"
35 /* In order for the format checking to accept the C frontend
36 diagnostic framework extensions, you must define this token before
37 including toplev.h. */
38 #define GCC_DIAG_STYLE __gcc_cdiag__
39 #include "toplev.h"
40 #include "flags.h"
41 #include "ggc.h"
42 #include "rtl.h"
43 #include "output.h"
44 #include "timevar.h"
45 #include "predict.h"
46 #include "tree-inline.h"
47 #include "tree-gimple.h"
48 #include "langhooks.h"
50 /* Create an empty statement tree rooted at T. */
52 tree
53 push_stmt_list (void)
55 tree t;
56 t = alloc_stmt_list ();
57 TREE_CHAIN (t) = cur_stmt_list;
58 cur_stmt_list = t;
59 return t;
62 /* Finish the statement tree rooted at T. */
64 tree
65 pop_stmt_list (tree t)
67 tree u = cur_stmt_list, chain;
69 /* Pop statement lists until we reach the target level. The extra
70 nestings will be due to outstanding cleanups. */
71 while (1)
73 chain = TREE_CHAIN (u);
74 TREE_CHAIN (u) = NULL_TREE;
75 if (t == u)
76 break;
77 u = chain;
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
85 statements. */
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))
94 u = tsi_stmt (i);
95 tsi_delink (&i);
96 free_stmt_list (t);
97 t = u;
101 return t;
104 /* T is a statement. Add it to the statement-tree. */
106 tree
107 add_stmt (tree t)
109 enum tree_code code = TREE_CODE (t);
111 if ((EXPR_P (t) || STATEMENT_CODE_P (code)) && code != LABEL_EXPR)
113 if (!EXPR_HAS_LOCATION (t))
114 SET_EXPR_LOCATION (t, input_location);
116 /* When we expand a statement-tree, we must know whether or not the
117 statements are full-expressions. We record that fact here. */
118 STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
121 if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
122 STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
124 /* Add T to the statement-tree. Non-side-effect statements need to be
125 recorded during statement expressions. */
126 append_to_statement_list_force (t, &cur_stmt_list);
128 return t;
131 /* Build a generic statement based on the given type of node and
132 arguments. Similar to `build_nt', except that we set
133 EXPR_LOCATION to be the current source location. */
134 /* ??? This should be obsolete with the lineno_stmt productions
135 in the grammar. */
137 tree
138 build_stmt (enum tree_code code, ...)
140 tree ret;
141 int length, i;
142 va_list p;
143 bool side_effects;
145 va_start (p, code);
147 ret = make_node (code);
148 TREE_TYPE (ret) = void_type_node;
149 length = TREE_CODE_LENGTH (code);
150 SET_EXPR_LOCATION (ret, input_location);
152 /* Most statements have implicit side effects all on their own,
153 such as control transfer. For those that do, we'll compute
154 the real value of TREE_SIDE_EFFECTS from its arguments. */
155 switch (code)
157 case EXPR_STMT:
158 side_effects = false;
159 break;
160 default:
161 side_effects = true;
162 break;
165 for (i = 0; i < length; i++)
167 tree t = va_arg (p, tree);
168 if (t && !TYPE_P (t))
169 side_effects |= TREE_SIDE_EFFECTS (t);
170 TREE_OPERAND (ret, i) = t;
173 TREE_SIDE_EFFECTS (ret) = side_effects;
175 va_end (p);
176 return ret;
179 /* Let the back-end know about DECL. */
181 void
182 emit_local_var (tree decl)
184 /* Create RTL for this variable. */
185 if (!DECL_RTL_SET_P (decl))
187 if (DECL_HARD_REGISTER (decl))
188 /* The user specified an assembler name for this variable.
189 Set that up now. */
190 rest_of_decl_compilation (decl, 0, 0);
191 else
192 expand_decl (decl);
196 /* Build a break statement node and return it. */
198 tree
199 build_break_stmt (void)
201 return (build_stmt (BREAK_STMT));
204 /* Build a continue statement node and return it. */
206 tree
207 build_continue_stmt (void)
209 return (build_stmt (CONTINUE_STMT));
212 /* Create a CASE_LABEL_EXPR tree node and return it. */
214 tree
215 build_case_label (tree low_value, tree high_value, tree label_decl)
217 return build_stmt (CASE_LABEL_EXPR, low_value, high_value, label_decl);