190075Sobrien/* This file contains the definitions and documentation for the common 290075Sobrien tree codes used in the GNU C and C++ compilers (see c-common.def 3132718Skan for the standard codes). 4169689Skan Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 5169689Skan Free Software Foundation, Inc. 690075Sobrien Written by Benjamin Chelf (chelf@codesourcery.com). 790075Sobrien 890075SobrienThis file is part of GCC. 990075Sobrien 1090075SobrienGCC is free software; you can redistribute it and/or modify it under 1190075Sobrienthe terms of the GNU General Public License as published by the Free 1290075SobrienSoftware Foundation; either version 2, or (at your option) any later 1390075Sobrienversion. 1490075Sobrien 1590075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1690075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1790075SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1890075Sobrienfor more details. 1990075Sobrien 2090075SobrienYou should have received a copy of the GNU General Public License 2190075Sobrienalong with GCC; see the file COPYING. If not, write to the Free 22169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 23169689Skan02110-1301, USA. */ 2490075Sobrien 2590075Sobrien#include "config.h" 2690075Sobrien#include "system.h" 27132718Skan#include "coretypes.h" 28132718Skan#include "tm.h" 2990075Sobrien#include "tree.h" 3090075Sobrien#include "function.h" 3190075Sobrien#include "splay-tree.h" 3290075Sobrien#include "varray.h" 3390075Sobrien#include "c-common.h" 3490075Sobrien#include "except.h" 35132718Skan/* In order for the format checking to accept the C frontend 36132718Skan diagnostic framework extensions, you must define this token before 37132718Skan including toplev.h. */ 38132718Skan#define GCC_DIAG_STYLE __gcc_cdiag__ 3990075Sobrien#include "toplev.h" 4090075Sobrien#include "flags.h" 4190075Sobrien#include "ggc.h" 4290075Sobrien#include "rtl.h" 4390075Sobrien#include "output.h" 4490075Sobrien#include "timevar.h" 45117395Skan#include "predict.h" 46132718Skan#include "tree-inline.h" 47169689Skan#include "tree-gimple.h" 48169689Skan#include "langhooks.h" 4990075Sobrien 5090075Sobrien/* Create an empty statement tree rooted at T. */ 5190075Sobrien 5290075Sobrientree 53169689Skanpush_stmt_list (void) 5490075Sobrien{ 55169689Skan tree t; 56169689Skan t = alloc_stmt_list (); 57169689Skan TREE_CHAIN (t) = cur_stmt_list; 58169689Skan cur_stmt_list = t; 5990075Sobrien return t; 6090075Sobrien} 6190075Sobrien 62169689Skan/* Finish the statement tree rooted at T. */ 6390075Sobrien 6490075Sobrientree 65169689Skanpop_stmt_list (tree t) 6690075Sobrien{ 67169689Skan tree u = cur_stmt_list, chain; 6890075Sobrien 69169689Skan /* Pop statement lists until we reach the target level. The extra 70169689Skan nestings will be due to outstanding cleanups. */ 71169689Skan while (1) 7290075Sobrien { 73169689Skan chain = TREE_CHAIN (u); 74169689Skan TREE_CHAIN (u) = NULL_TREE; 75169689Skan if (t == u) 76169689Skan break; 77169689Skan u = chain; 7890075Sobrien } 79169689Skan cur_stmt_list = chain; 80169689Skan 81169689Skan /* If the statement list is completely empty, just return it. This is 82169689Skan just as good small as build_empty_stmt, with the advantage that 83169689Skan statement lists are merged when they appended to one another. So 84169689Skan using the STATEMENT_LIST avoids pathological buildup of EMPTY_STMT_P 85169689Skan statements. */ 86169689Skan if (TREE_SIDE_EFFECTS (t)) 8790075Sobrien { 88169689Skan tree_stmt_iterator i = tsi_start (t); 89169689Skan 90169689Skan /* If the statement list contained exactly one statement, then 91169689Skan extract it immediately. */ 92169689Skan if (tsi_one_before_end_p (i)) 93169689Skan { 94169689Skan u = tsi_stmt (i); 95169689Skan tsi_delink (&i); 96169689Skan free_stmt_list (t); 97169689Skan t = u; 98169689Skan } 9990075Sobrien } 10090075Sobrien 101169689Skan return t; 10290075Sobrien} 10390075Sobrien 10490075Sobrien/* Build a generic statement based on the given type of node and 10590075Sobrien arguments. Similar to `build_nt', except that we set 106169689Skan EXPR_LOCATION to be the current source location. */ 10790075Sobrien/* ??? This should be obsolete with the lineno_stmt productions 10890075Sobrien in the grammar. */ 10990075Sobrien 11090075Sobrientree 111132718Skanbuild_stmt (enum tree_code code, ...) 11290075Sobrien{ 113169689Skan tree ret; 114169689Skan int length, i; 115132718Skan va_list p; 116169689Skan bool side_effects; 11790075Sobrien 118132718Skan va_start (p, code); 11990075Sobrien 120169689Skan ret = make_node (code); 121169689Skan TREE_TYPE (ret) = void_type_node; 12290075Sobrien length = TREE_CODE_LENGTH (code); 123169689Skan SET_EXPR_LOCATION (ret, input_location); 12490075Sobrien 125169689Skan /* TREE_SIDE_EFFECTS will already be set for statements with 126169689Skan implicit side effects. Here we make sure it is set for other 127169689Skan expressions by checking whether the parameters have side 128169689Skan effects. */ 129169689Skan 130169689Skan side_effects = false; 13190075Sobrien for (i = 0; i < length; i++) 13290075Sobrien { 133169689Skan tree t = va_arg (p, tree); 134169689Skan if (t && !TYPE_P (t)) 135169689Skan side_effects |= TREE_SIDE_EFFECTS (t); 136169689Skan TREE_OPERAND (ret, i) = t; 13790075Sobrien } 13890075Sobrien 139169689Skan TREE_SIDE_EFFECTS (ret) |= side_effects; 14090075Sobrien 141169689Skan va_end (p); 142169689Skan return ret; 14390075Sobrien} 14490075Sobrien 14590075Sobrien/* Let the back-end know about DECL. */ 14690075Sobrien 14790075Sobrienvoid 148132718Skanemit_local_var (tree decl) 14990075Sobrien{ 15090075Sobrien /* Create RTL for this variable. */ 15190075Sobrien if (!DECL_RTL_SET_P (decl)) 15290075Sobrien { 153169689Skan if (DECL_HARD_REGISTER (decl)) 15490075Sobrien /* The user specified an assembler name for this variable. 15590075Sobrien Set that up now. */ 156169689Skan rest_of_decl_compilation (decl, 0, 0); 15790075Sobrien else 15890075Sobrien expand_decl (decl); 15990075Sobrien } 16090075Sobrien} 16190075Sobrien 162169689Skan/* Create a CASE_LABEL_EXPR tree node and return it. */ 16390075Sobrien 16490075Sobrientree 165132718Skanbuild_case_label (tree low_value, tree high_value, tree label_decl) 16690075Sobrien{ 167169689Skan return build_stmt (CASE_LABEL_EXPR, low_value, high_value, label_decl); 16890075Sobrien} 169