OSDN Git Service

Reorganize code.
[pf3gnuchains/gcc-fork.git] / gcc / c-semantics.c
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).
5
6 This file is part of GCC.
7
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
11 version.
12
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
16 for more details.
17
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/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "function.h"
28 #include "splay-tree.h"
29 #include "varray.h"
30 #include "c-common.h"
31 #include "except.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__
36 #include "toplev.h"
37 #include "flags.h"
38 #include "ggc.h"
39 #include "rtl.h"
40 #include "output.h"
41 #include "timevar.h"
42 #include "predict.h"
43 #include "tree-inline.h"
44 #include "gimple.h"
45 #include "tree-iterator.h"
46 #include "langhooks.h"
47
48 /* Create an empty statement tree rooted at T.  */
49
50 tree
51 push_stmt_list (void)
52 {
53   tree t;
54   t = alloc_stmt_list ();
55   TREE_CHAIN (t) = cur_stmt_list;
56   cur_stmt_list = t;
57   return t;
58 }
59
60 /* Finish the statement tree rooted at T.  */
61
62 tree
63 pop_stmt_list (tree t)
64 {
65   tree u = cur_stmt_list, chain;
66
67   /* Pop statement lists until we reach the target level.  The extra
68      nestings will be due to outstanding cleanups.  */
69   while (1)
70     {
71       chain = TREE_CHAIN (u);
72       TREE_CHAIN (u) = NULL_TREE;
73       if (t == u)
74         break;
75       u = chain;
76     }
77   cur_stmt_list = chain;
78
79   /* If the statement list is completely empty, just return it.  This is
80      just as good small as build_empty_stmt, with the advantage that
81      statement lists are merged when they appended to one another.  So
82      using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
83      statements.  */
84   if (TREE_SIDE_EFFECTS (t))
85     {
86       tree_stmt_iterator i = tsi_start (t);
87
88       /* If the statement list contained exactly one statement, then
89          extract it immediately.  */
90       if (tsi_one_before_end_p (i))
91         {
92           u = tsi_stmt (i);
93           tsi_delink (&i);
94           free_stmt_list (t);
95           t = u;
96         }
97     }
98
99   return t;
100 }
101
102 /* Build a generic statement based on the given type of node and
103    arguments. Similar to `build_nt', except that we set
104    EXPR_LOCATION to be the current source location.  */
105 /* ??? This should be obsolete with the lineno_stmt productions
106    in the grammar.  */
107
108 tree
109 build_stmt (enum tree_code code, ...)
110 {
111   tree ret;
112   int length, i;
113   va_list p;
114   bool side_effects;
115
116   /* This function cannot be used to construct variably-sized nodes.  */
117   gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
118
119   va_start (p, code);
120
121   ret = make_node (code);
122   TREE_TYPE (ret) = void_type_node;
123   length = TREE_CODE_LENGTH (code);
124   SET_EXPR_LOCATION (ret, input_location);
125
126   /* TREE_SIDE_EFFECTS will already be set for statements with
127      implicit side effects.  Here we make sure it is set for other
128      expressions by checking whether the parameters have side
129      effects.  */
130
131   side_effects = false;
132   for (i = 0; i < length; i++)
133     {
134       tree t = va_arg (p, tree);
135       if (t && !TYPE_P (t))
136         side_effects |= TREE_SIDE_EFFECTS (t);
137       TREE_OPERAND (ret, i) = t;
138     }
139
140   TREE_SIDE_EFFECTS (ret) |= side_effects;
141
142   va_end (p);
143   return ret;
144 }
145
146 /* Create a CASE_LABEL_EXPR tree node and return it.  */
147
148 tree
149 build_case_label (tree low_value, tree high_value, tree label_decl)
150 {
151   return build_stmt (CASE_LABEL_EXPR, low_value, high_value, label_decl);
152 }