PR target/54640
[official-gcc.git] / gcc / c / c-objc-common.c
blob6020c028da40de02dc7752a1b37ab3e2ef70c53d
1 /* Some code common to C and ObjC front ends.
2 Copyright (C) 2001-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
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"
33 static bool c_tree_printer (pretty_printer *, text_info *, const char *,
34 int, bool, bool, bool);
36 bool
37 c_missing_noreturn_ok_p (tree decl)
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));
44 /* Called from check_global_declarations. */
46 bool
47 c_warn_unused_global_decl (const_tree decl)
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;
54 return true;
57 /* Initialization common to C and Objective-C front ends. */
58 bool
59 c_objc_common_init (void)
61 c_init_decl_processing ();
63 if (c_common_init () == false)
64 return false;
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;
71 return true;
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.
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)
91 tree t = NULL_TREE;
92 tree name;
93 c_pretty_printer *cpp = (c_pretty_printer *) pp;
94 pp->padding = pp_none;
96 if (precision != 0 || wide)
97 return false;
99 if (*spec == 'K')
101 percent_K_format (text);
102 return true;
105 if (*spec != 'v')
107 t = va_arg (*text->args_ptr, tree);
108 if (set_locus && text->locus)
109 *text->locus = DECL_SOURCE_LOCATION (t);
112 switch (*spec)
114 case 'D':
115 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
117 t = DECL_DEBUG_EXPR (t);
118 if (!DECL_P (t))
120 pp_c_expression (cpp, t);
121 return true;
124 /* FALLTHRU */
126 case 'F':
127 if (DECL_NAME (t))
129 pp_identifier (cpp, lang_hooks.decl_printable_name (t, 2));
130 return true;
132 break;
134 case 'T':
135 gcc_assert (TYPE_P (t));
136 name = TYPE_NAME (t);
138 if (name && TREE_CODE (name) == TYPE_DECL)
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;
146 else
148 pp_type_id (cpp, t);
149 return true;
151 break;
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;
160 case 'V':
161 pp_c_type_qualifier_list (cpp, t);
162 return true;
164 case 'v':
165 pp_c_cv_qualifiers (cpp, va_arg (*text->args_ptr, int), hash);
166 return true;
168 default:
169 return false;
172 pp_string (cpp, _("({anonymous})"));
173 return true;
176 /* In C and ObjC, all decls have "C" linkage. */
177 bool
178 has_c_linkage (const_tree decl ATTRIBUTE_UNUSED)
180 return true;
183 void
184 c_initialize_diagnostics (diagnostic_context *context)
186 pretty_printer *base;
187 c_pretty_printer *pp;
189 c_common_initialize_diagnostics (context);
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;
197 /* It is safe to free this object because it was previously XNEW()'d. */
198 XDELETE (base);
202 c_types_compatible_p (tree x, tree y)
204 return comptypes (TYPE_MAIN_VARIANT (x), TYPE_MAIN_VARIANT (y));
207 /* Determine if the type is a vla type for the backend. */
209 bool
210 c_vla_unspec_p (tree x, tree fn ATTRIBUTE_UNUSED)
212 return c_vla_type_p (x);