Merge from mainline (160224:163495).
[official-gcc/graphite-test-results.git] / gcc / c-family / c-semantics.c
blob0eccd5189e4b0c8ab17b5466bb50d4aaafcba89a
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 "toplev.h"
31 #include "flags.h"
32 #include "output.h"
33 #include "tree-iterator.h"
35 /* Create an empty statement tree rooted at T. */
37 tree
38 push_stmt_list (void)
40 tree t;
41 t = alloc_stmt_list ();
42 TREE_CHAIN (t) = cur_stmt_list;
43 cur_stmt_list = t;
44 return t;
47 /* Finish the statement tree rooted at T. */
49 tree
50 pop_stmt_list (tree t)
52 tree u = cur_stmt_list, chain;
54 /* Pop statement lists until we reach the target level. The extra
55 nestings will be due to outstanding cleanups. */
56 while (1)
58 chain = TREE_CHAIN (u);
59 TREE_CHAIN (u) = NULL_TREE;
60 if (chain)
61 STATEMENT_LIST_HAS_LABEL (chain) |= STATEMENT_LIST_HAS_LABEL (u);
62 if (t == u)
63 break;
64 u = chain;
66 cur_stmt_list = chain;
68 /* If the statement list is completely empty, just return it. This is
69 just as good small as build_empty_stmt, with the advantage that
70 statement lists are merged when they appended to one another. So
71 using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P
72 statements. */
73 if (TREE_SIDE_EFFECTS (t))
75 tree_stmt_iterator i = tsi_start (t);
77 /* If the statement list contained exactly one statement, then
78 extract it immediately. */
79 if (tsi_one_before_end_p (i))
81 u = tsi_stmt (i);
82 tsi_delink (&i);
83 free_stmt_list (t);
84 t = u;
88 return t;
91 /* Build a generic statement based on the given type of node and
92 arguments. Similar to `build_nt', except that we set
93 EXPR_LOCATION to LOC. */
94 /* ??? This should be obsolete with the lineno_stmt productions
95 in the grammar. */
97 tree
98 build_stmt (location_t loc, enum tree_code code, ...)
100 tree ret;
101 int length, i;
102 va_list p;
103 bool side_effects;
105 /* This function cannot be used to construct variably-sized nodes. */
106 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
108 va_start (p, code);
110 ret = make_node (code);
111 TREE_TYPE (ret) = void_type_node;
112 length = TREE_CODE_LENGTH (code);
113 SET_EXPR_LOCATION (ret, loc);
115 /* TREE_SIDE_EFFECTS will already be set for statements with
116 implicit side effects. Here we make sure it is set for other
117 expressions by checking whether the parameters have side
118 effects. */
120 side_effects = false;
121 for (i = 0; i < length; i++)
123 tree t = va_arg (p, tree);
124 if (t && !TYPE_P (t))
125 side_effects |= TREE_SIDE_EFFECTS (t);
126 TREE_OPERAND (ret, i) = t;
129 TREE_SIDE_EFFECTS (ret) |= side_effects;
131 va_end (p);
132 return ret;
135 /* Create a CASE_LABEL_EXPR tree node and return it. */
137 tree
138 build_case_label (location_t loc,
139 tree low_value, tree high_value, tree label_decl)
141 return build_stmt (loc, CASE_LABEL_EXPR, low_value, high_value, label_decl);