Add ChangeLog entries.
[official-gcc/constexpr.git] / gcc / c-semantics.c
blob5111f819c72dc13a67da9c18f33658e06dbe915a
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
11 version.
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.
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/>. */
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 "c-common.h"
30 #include "except.h"
31 /* In order for the format checking to accept the C frontend
32 diagnostic framework extensions, you must define this token before
33 including toplev.h. */
34 #define GCC_DIAG_STYLE __gcc_cdiag__
35 #include "toplev.h"
36 #include "flags.h"
37 #include "ggc.h"
38 #include "rtl.h"
39 #include "output.h"
40 #include "timevar.h"
41 #include "predict.h"
42 #include "tree-inline.h"
43 #include "gimple.h"
44 #include "tree-iterator.h"
45 #include "langhooks.h"
47 /* Create an empty statement tree rooted at T. */
49 tree
50 push_stmt_list (void)
52 tree t;
53 t = alloc_stmt_list ();
54 TREE_CHAIN (t) = cur_stmt_list;
55 cur_stmt_list = t;
56 return t;
59 /* Finish the statement tree rooted at T. */
61 tree
62 pop_stmt_list (tree t)
64 tree u = cur_stmt_list, chain;
66 /* Pop statement lists until we reach the target level. The extra
67 nestings will be due to outstanding cleanups. */
68 while (1)
70 chain = TREE_CHAIN (u);
71 TREE_CHAIN (u) = NULL_TREE;
72 if (chain)
73 STATEMENT_LIST_HAS_LABEL (chain) |= STATEMENT_LIST_HAS_LABEL (u);
74 if (t == u)
75 break;
76 u = chain;
78 cur_stmt_list = chain;
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))
87 tree_stmt_iterator i = tsi_start (t);
89 /* If the statement list contained exactly one statement, then
90 extract it immediately. */
91 if (tsi_one_before_end_p (i))
93 u = tsi_stmt (i);
94 tsi_delink (&i);
95 free_stmt_list (t);
96 t = u;
100 return t;
103 /* Build a generic statement based on the given type of node and
104 arguments. Similar to `build_nt', except that we set
105 EXPR_LOCATION to LOC. */
106 /* ??? This should be obsolete with the lineno_stmt productions
107 in the grammar. */
109 tree
110 build_stmt (location_t loc, enum tree_code code, ...)
112 tree ret;
113 int length, i;
114 va_list p;
115 bool side_effects;
117 /* This function cannot be used to construct variably-sized nodes. */
118 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
120 va_start (p, code);
122 ret = make_node (code);
123 TREE_TYPE (ret) = void_type_node;
124 length = TREE_CODE_LENGTH (code);
125 SET_EXPR_LOCATION (ret, loc);
127 /* TREE_SIDE_EFFECTS will already be set for statements with
128 implicit side effects. Here we make sure it is set for other
129 expressions by checking whether the parameters have side
130 effects. */
132 side_effects = false;
133 for (i = 0; i < length; i++)
135 tree t = va_arg (p, tree);
136 if (t && !TYPE_P (t))
137 side_effects |= TREE_SIDE_EFFECTS (t);
138 TREE_OPERAND (ret, i) = t;
141 TREE_SIDE_EFFECTS (ret) |= side_effects;
143 va_end (p);
144 return ret;
147 /* Create a CASE_LABEL_EXPR tree node and return it. */
149 tree
150 build_case_label (location_t loc,
151 tree low_value, tree high_value, tree label_decl)
153 return build_stmt (loc, CASE_LABEL_EXPR, low_value, high_value, label_decl);