1*e4b17023SJohn Marino /* Some code common to C and ObjC front ends. 2*e4b17023SJohn Marino Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 3*e4b17023SJohn Marino 2009, 2010 Free Software Foundation, Inc. 4*e4b17023SJohn Marino 5*e4b17023SJohn Marino This file is part of GCC. 6*e4b17023SJohn Marino 7*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 8*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 9*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 10*e4b17023SJohn Marino version. 11*e4b17023SJohn Marino 12*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 14*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15*e4b17023SJohn Marino for more details. 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino You should have received a copy of the GNU General Public License 18*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see 19*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 20*e4b17023SJohn Marino 21*e4b17023SJohn Marino #include "config.h" 22*e4b17023SJohn Marino #include "system.h" 23*e4b17023SJohn Marino #include "coretypes.h" 24*e4b17023SJohn Marino #include "tree.h" 25*e4b17023SJohn Marino #include "c-tree.h" 26*e4b17023SJohn Marino #include "intl.h" 27*e4b17023SJohn Marino #include "c-family/c-pretty-print.h" 28*e4b17023SJohn Marino #include "flags.h" 29*e4b17023SJohn Marino #include "diagnostic.h" 30*e4b17023SJohn Marino #include "tree-pretty-print.h" 31*e4b17023SJohn Marino #include "langhooks.h" 32*e4b17023SJohn Marino #include "c-objc-common.h" 33*e4b17023SJohn Marino 34*e4b17023SJohn Marino static bool c_tree_printer (pretty_printer *, text_info *, const char *, 35*e4b17023SJohn Marino int, bool, bool, bool); 36*e4b17023SJohn Marino 37*e4b17023SJohn Marino bool 38*e4b17023SJohn Marino c_missing_noreturn_ok_p (tree decl) 39*e4b17023SJohn Marino { 40*e4b17023SJohn Marino /* A missing noreturn is not ok for freestanding implementations and 41*e4b17023SJohn Marino ok for the `main' function in hosted implementations. */ 42*e4b17023SJohn Marino return flag_hosted && MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl)); 43*e4b17023SJohn Marino } 44*e4b17023SJohn Marino 45*e4b17023SJohn Marino /* Called from check_global_declarations. */ 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino bool 48*e4b17023SJohn Marino c_warn_unused_global_decl (const_tree decl) 49*e4b17023SJohn Marino { 50*e4b17023SJohn Marino if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)) 51*e4b17023SJohn Marino return false; 52*e4b17023SJohn Marino if (DECL_IN_SYSTEM_HEADER (decl)) 53*e4b17023SJohn Marino return false; 54*e4b17023SJohn Marino 55*e4b17023SJohn Marino return true; 56*e4b17023SJohn Marino } 57*e4b17023SJohn Marino 58*e4b17023SJohn Marino /* Initialization common to C and Objective-C front ends. */ 59*e4b17023SJohn Marino bool 60*e4b17023SJohn Marino c_objc_common_init (void) 61*e4b17023SJohn Marino { 62*e4b17023SJohn Marino c_init_decl_processing (); 63*e4b17023SJohn Marino 64*e4b17023SJohn Marino if (c_common_init () == false) 65*e4b17023SJohn Marino return false; 66*e4b17023SJohn Marino 67*e4b17023SJohn Marino /* These were not defined in the Objective-C front end, but I'm 68*e4b17023SJohn Marino putting them here anyway. The diagnostic format decoder might 69*e4b17023SJohn Marino want an enhanced ObjC implementation. */ 70*e4b17023SJohn Marino diagnostic_format_decoder (global_dc) = &c_tree_printer; 71*e4b17023SJohn Marino 72*e4b17023SJohn Marino return true; 73*e4b17023SJohn Marino } 74*e4b17023SJohn Marino 75*e4b17023SJohn Marino /* Called during diagnostic message formatting process to print a 76*e4b17023SJohn Marino source-level entity onto BUFFER. The meaning of the format specifiers 77*e4b17023SJohn Marino is as follows: 78*e4b17023SJohn Marino %D: a general decl, 79*e4b17023SJohn Marino %E: an identifier or expression, 80*e4b17023SJohn Marino %F: a function declaration, 81*e4b17023SJohn Marino %T: a type. 82*e4b17023SJohn Marino %V: a list of type qualifiers from a tree. 83*e4b17023SJohn Marino %v: an explicit list of type qualifiers 84*e4b17023SJohn Marino %#v: an explicit list of type qualifiers of a function type. 85*e4b17023SJohn Marino 86*e4b17023SJohn Marino Please notice when called, the `%' part was already skipped by the 87*e4b17023SJohn Marino diagnostic machinery. */ 88*e4b17023SJohn Marino static bool 89*e4b17023SJohn Marino c_tree_printer (pretty_printer *pp, text_info *text, const char *spec, 90*e4b17023SJohn Marino int precision, bool wide, bool set_locus, bool hash) 91*e4b17023SJohn Marino { 92*e4b17023SJohn Marino tree t = NULL_TREE; 93*e4b17023SJohn Marino tree name; 94*e4b17023SJohn Marino c_pretty_printer *cpp = (c_pretty_printer *) pp; 95*e4b17023SJohn Marino pp->padding = pp_none; 96*e4b17023SJohn Marino 97*e4b17023SJohn Marino if (precision != 0 || wide) 98*e4b17023SJohn Marino return false; 99*e4b17023SJohn Marino 100*e4b17023SJohn Marino if (*spec == 'K') 101*e4b17023SJohn Marino { 102*e4b17023SJohn Marino percent_K_format (text); 103*e4b17023SJohn Marino return true; 104*e4b17023SJohn Marino } 105*e4b17023SJohn Marino 106*e4b17023SJohn Marino if (*spec != 'v') 107*e4b17023SJohn Marino { 108*e4b17023SJohn Marino t = va_arg (*text->args_ptr, tree); 109*e4b17023SJohn Marino if (set_locus && text->locus) 110*e4b17023SJohn Marino *text->locus = DECL_SOURCE_LOCATION (t); 111*e4b17023SJohn Marino } 112*e4b17023SJohn Marino 113*e4b17023SJohn Marino switch (*spec) 114*e4b17023SJohn Marino { 115*e4b17023SJohn Marino case 'D': 116*e4b17023SJohn Marino if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t)) 117*e4b17023SJohn Marino { 118*e4b17023SJohn Marino t = DECL_DEBUG_EXPR (t); 119*e4b17023SJohn Marino if (!DECL_P (t)) 120*e4b17023SJohn Marino { 121*e4b17023SJohn Marino pp_c_expression (cpp, t); 122*e4b17023SJohn Marino return true; 123*e4b17023SJohn Marino } 124*e4b17023SJohn Marino } 125*e4b17023SJohn Marino /* FALLTHRU */ 126*e4b17023SJohn Marino 127*e4b17023SJohn Marino case 'F': 128*e4b17023SJohn Marino if (DECL_NAME (t)) 129*e4b17023SJohn Marino { 130*e4b17023SJohn Marino pp_identifier (cpp, lang_hooks.decl_printable_name (t, 2)); 131*e4b17023SJohn Marino return true; 132*e4b17023SJohn Marino } 133*e4b17023SJohn Marino break; 134*e4b17023SJohn Marino 135*e4b17023SJohn Marino case 'T': 136*e4b17023SJohn Marino gcc_assert (TYPE_P (t)); 137*e4b17023SJohn Marino name = TYPE_NAME (t); 138*e4b17023SJohn Marino 139*e4b17023SJohn Marino if (name && TREE_CODE (name) == TYPE_DECL) 140*e4b17023SJohn Marino { 141*e4b17023SJohn Marino if (DECL_NAME (name)) 142*e4b17023SJohn Marino pp_identifier (cpp, lang_hooks.decl_printable_name (name, 2)); 143*e4b17023SJohn Marino else 144*e4b17023SJohn Marino pp_type_id (cpp, t); 145*e4b17023SJohn Marino return true; 146*e4b17023SJohn Marino } 147*e4b17023SJohn Marino else 148*e4b17023SJohn Marino { 149*e4b17023SJohn Marino pp_type_id (cpp, t); 150*e4b17023SJohn Marino return true; 151*e4b17023SJohn Marino } 152*e4b17023SJohn Marino break; 153*e4b17023SJohn Marino 154*e4b17023SJohn Marino case 'E': 155*e4b17023SJohn Marino if (TREE_CODE (t) == IDENTIFIER_NODE) 156*e4b17023SJohn Marino pp_identifier (cpp, IDENTIFIER_POINTER (t)); 157*e4b17023SJohn Marino else 158*e4b17023SJohn Marino pp_expression (cpp, t); 159*e4b17023SJohn Marino return true; 160*e4b17023SJohn Marino 161*e4b17023SJohn Marino case 'V': 162*e4b17023SJohn Marino pp_c_type_qualifier_list (cpp, t); 163*e4b17023SJohn Marino return true; 164*e4b17023SJohn Marino 165*e4b17023SJohn Marino case 'v': 166*e4b17023SJohn Marino pp_c_cv_qualifiers (cpp, va_arg (*text->args_ptr, int), hash); 167*e4b17023SJohn Marino return true; 168*e4b17023SJohn Marino 169*e4b17023SJohn Marino default: 170*e4b17023SJohn Marino return false; 171*e4b17023SJohn Marino } 172*e4b17023SJohn Marino 173*e4b17023SJohn Marino pp_string (cpp, _("({anonymous})")); 174*e4b17023SJohn Marino return true; 175*e4b17023SJohn Marino } 176*e4b17023SJohn Marino 177*e4b17023SJohn Marino /* In C and ObjC, all decls have "C" linkage. */ 178*e4b17023SJohn Marino bool 179*e4b17023SJohn Marino has_c_linkage (const_tree decl ATTRIBUTE_UNUSED) 180*e4b17023SJohn Marino { 181*e4b17023SJohn Marino return true; 182*e4b17023SJohn Marino } 183*e4b17023SJohn Marino 184*e4b17023SJohn Marino void 185*e4b17023SJohn Marino c_initialize_diagnostics (diagnostic_context *context) 186*e4b17023SJohn Marino { 187*e4b17023SJohn Marino pretty_printer *base; 188*e4b17023SJohn Marino c_pretty_printer *pp; 189*e4b17023SJohn Marino 190*e4b17023SJohn Marino c_common_initialize_diagnostics (context); 191*e4b17023SJohn Marino 192*e4b17023SJohn Marino base = context->printer; 193*e4b17023SJohn Marino pp = XNEW (c_pretty_printer); 194*e4b17023SJohn Marino memcpy (pp_base (pp), base, sizeof (pretty_printer)); 195*e4b17023SJohn Marino pp_c_pretty_printer_init (pp); 196*e4b17023SJohn Marino context->printer = (pretty_printer *) pp; 197*e4b17023SJohn Marino 198*e4b17023SJohn Marino /* It is safe to free this object because it was previously XNEW()'d. */ 199*e4b17023SJohn Marino XDELETE (base); 200*e4b17023SJohn Marino } 201*e4b17023SJohn Marino 202*e4b17023SJohn Marino int 203*e4b17023SJohn Marino c_types_compatible_p (tree x, tree y) 204*e4b17023SJohn Marino { 205*e4b17023SJohn Marino return comptypes (TYPE_MAIN_VARIANT (x), TYPE_MAIN_VARIANT (y)); 206*e4b17023SJohn Marino } 207*e4b17023SJohn Marino 208*e4b17023SJohn Marino /* Determine if the type is a vla type for the backend. */ 209*e4b17023SJohn Marino 210*e4b17023SJohn Marino bool 211*e4b17023SJohn Marino c_vla_unspec_p (tree x, tree fn ATTRIBUTE_UNUSED) 212*e4b17023SJohn Marino { 213*e4b17023SJohn Marino return c_vla_type_p (x); 214*e4b17023SJohn Marino } 215