OSDN Git Service

Revert:
[pf3gnuchains/gcc-fork.git] / gcc / c-objc-common.c
1 /* Some code common to C and ObjC front ends.
2    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007,
3    2009 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "c-tree.h"
26 #include "intl.h"
27 #include "c-pretty-print.h"
28 #include "flags.h"
29 #include "diagnostic.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
82    These format specifiers form a subset of the format specifiers set used
83    by the C++ front-end.
84    Please notice when called, the `%' part was already skipped by the
85    diagnostic machinery.  */
86 static bool
87 c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
88                 int precision, bool wide, bool set_locus, bool hash)
89 {
90   tree t = va_arg (*text->args_ptr, tree);
91   tree name;
92   c_pretty_printer *cpp = (c_pretty_printer *) pp;
93   pp->padding = pp_none;
94
95   if (precision != 0 || wide || hash)
96     return false;
97
98   if (set_locus && text->locus)
99     *text->locus = DECL_SOURCE_LOCATION (t);
100
101   switch (*spec)
102     {
103     case 'D':
104       if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
105         {
106           t = DECL_DEBUG_EXPR (t);
107           if (!DECL_P (t))
108             {
109               pp_c_expression (cpp, t);
110               return true;
111             }
112         }
113       /* FALLTHRU */
114
115     case 'F':
116       if (DECL_NAME (t))
117         {
118           pp_identifier (cpp, lang_hooks.decl_printable_name (t, 2));
119           return true;
120         }
121       break;
122
123     case 'T':
124       gcc_assert (TYPE_P (t));
125       name = TYPE_NAME (t);
126
127       if (name && TREE_CODE (name) == TYPE_DECL)
128         {
129           if (DECL_NAME (name))
130             pp_identifier (cpp, lang_hooks.decl_printable_name (name, 2));
131           else
132             pp_type_id (cpp, t);
133           return true;
134         }
135       else
136         {
137           pp_type_id (cpp, t);
138           return true;
139         }
140       break;
141
142     case 'E':
143       if (TREE_CODE (t) == IDENTIFIER_NODE)
144         pp_identifier (cpp, IDENTIFIER_POINTER (t));
145       else
146         pp_expression (cpp, t);
147       return true;
148
149     default:
150       return false;
151     }
152
153   pp_string (cpp, _("({anonymous})"));
154   return true;
155 }
156
157 /* In C and ObjC, all decls have "C" linkage.  */
158 bool
159 has_c_linkage (const_tree decl ATTRIBUTE_UNUSED)
160 {
161   return true;
162 }
163
164 void
165 c_initialize_diagnostics (diagnostic_context *context)
166 {
167   pretty_printer *base = context->printer;
168   c_pretty_printer *pp = XNEW (c_pretty_printer);
169   memcpy (pp_base (pp), base, sizeof (pretty_printer));
170   pp_c_pretty_printer_init (pp);
171   context->printer = (pretty_printer *) pp;
172
173   /* It is safe to free this object because it was previously XNEW()'d.  */
174   XDELETE (base);
175 }
176
177 int
178 c_types_compatible_p (tree x, tree y)
179 {
180   return comptypes (TYPE_MAIN_VARIANT (x), TYPE_MAIN_VARIANT (y));
181 }
182
183 /* Determine if the type is a vla type for the backend.  */
184
185 bool
186 c_vla_unspec_p (tree x, tree fn ATTRIBUTE_UNUSED)
187 {
188   return c_vla_type_p (x);
189 }