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