OSDN Git Service

Set TARGET_ASM_FILE_END to file_end_indicate_exec_stack.
[pf3gnuchains/gcc-fork.git] / gcc / c-semantics.c
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).
6
7 This file is part of GCC.
8
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
12 version.
13
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
17 for more details.
18
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
22 02111-1307, USA.  */
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "tree.h"
29 #include "function.h"
30 #include "splay-tree.h"
31 #include "varray.h"
32 #include "c-common.h"
33 #include "except.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__
38 #include "toplev.h"
39 #include "flags.h"
40 #include "ggc.h"
41 #include "rtl.h"
42 #include "output.h"
43 #include "timevar.h"
44 #include "predict.h"
45 #include "tree-inline.h"
46 #include "tree-gimple.h"
47 #include "langhooks.h"
48
49 /* Create an empty statement tree rooted at T.  */
50
51 tree
52 push_stmt_list (void)
53 {
54   tree t;
55   t = alloc_stmt_list ();
56   TREE_CHAIN (t) = cur_stmt_list;
57   cur_stmt_list = t;
58   return t;
59 }
60
61 /* Finish the statement tree rooted at T.  */
62
63 tree
64 pop_stmt_list (tree t)
65 {
66   tree u = cur_stmt_list, chain;
67
68   /* Pop statement lists until we reach the target level.  The extra
69      nestings will be due to outstanding cleanups.  */
70   while (1)
71     {
72       chain = TREE_CHAIN (u);
73       TREE_CHAIN (u) = NULL_TREE;
74       if (t == u)
75         break;
76       u = chain;
77     }
78   cur_stmt_list = chain;
79
80   /* If the statement list is completely empty, just return it.  This is
81      just as good small as build_empty_stmt, with the advantage that 
82      statement lists are merged when they appended to one another.  So
83      using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
84      statements.  */
85   if (TREE_SIDE_EFFECTS (t))
86     {
87       tree_stmt_iterator i = tsi_start (t);
88
89       /* If the statement list contained exactly one statement, then
90          extract it immediately.  */
91       if (tsi_one_before_end_p (i))
92         {
93           u = tsi_stmt (i);
94           tsi_delink (&i);
95           free_stmt_list (t);
96           t = u;
97         }
98     }
99
100   return t;
101 }
102
103 /* T is a statement.  Add it to the statement-tree.  */
104
105 tree
106 add_stmt (tree t)
107 {
108   enum tree_code code = TREE_CODE (t);
109
110   if ((EXPR_P (t) || STATEMENT_CODE_P (code)) && code != LABEL_EXPR)
111     {
112       if (!EXPR_HAS_LOCATION (t))
113         SET_EXPR_LOCATION (t, input_location);
114
115       /* When we expand a statement-tree, we must know whether or not the
116          statements are full-expressions.  We record that fact here.  */
117       STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
118     }
119
120   if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
121     STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
122
123   /* Add T to the statement-tree.  Non-side-effect statements need to be
124      recorded during statement expressions.  */
125   append_to_statement_list_force (t, &cur_stmt_list);
126
127   return t;
128 }
129
130 /* Build a generic statement based on the given type of node and
131    arguments. Similar to `build_nt', except that we set
132    EXPR_LOCATION to be the current source location.  */
133 /* ??? This should be obsolete with the lineno_stmt productions
134    in the grammar.  */
135
136 tree
137 build_stmt (enum tree_code code, ...)
138 {
139   tree ret;
140   int length, i;
141   va_list p;
142   bool side_effects;
143
144   va_start (p, code);
145
146   ret = make_node (code);
147   TREE_TYPE (ret) = void_type_node;
148   length = TREE_CODE_LENGTH (code);
149   SET_EXPR_LOCATION (ret, input_location);
150
151   /* Most statements have implicit side effects all on their own, 
152      such as control transfer.  For those that do, we'll compute
153      the real value of TREE_SIDE_EFFECTS from its arguments.  */
154   switch (code)
155     {
156     case EXPR_STMT:
157       side_effects = false;
158       break;
159     default:
160       side_effects = true;
161       break;
162     }
163
164   for (i = 0; i < length; i++)
165     {
166       tree t = va_arg (p, tree);
167       if (t && IS_NON_TYPE_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (t))))
168         side_effects |= TREE_SIDE_EFFECTS (t);
169       TREE_OPERAND (ret, i) = t;
170     }
171
172   TREE_SIDE_EFFECTS (ret) = side_effects;
173
174   va_end (p);
175   return ret;
176 }
177
178 /* Let the back-end know about DECL.  */
179
180 void
181 emit_local_var (tree decl)
182 {
183   /* Create RTL for this variable.  */
184   if (!DECL_RTL_SET_P (decl))
185     {
186       if (DECL_HARD_REGISTER (decl))
187         /* The user specified an assembler name for this variable.
188            Set that up now.  */
189         rest_of_decl_compilation (decl, 0, 0);
190       else
191         expand_decl (decl);
192     }
193 }
194
195 /* Build a break statement node and return it.  */
196
197 tree
198 build_break_stmt (void)
199 {
200   return (build_stmt (BREAK_STMT));
201 }
202
203 /* Build a continue statement node and return it.  */
204
205 tree
206 build_continue_stmt (void)
207 {
208   return (build_stmt (CONTINUE_STMT));
209 }
210
211 /* Create a CASE_LABEL_EXPR tree node and return it.  */
212
213 tree
214 build_case_label (tree low_value, tree high_value, tree label_decl)
215 {
216   return build_stmt (CASE_LABEL_EXPR, low_value, high_value, label_decl);
217 }