OSDN Git Service

2006-02-20 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / objcp / objcp-lang.c
1 /* Language-dependent hooks for Objective-C++.
2    Copyright 2005 Free Software Foundation, Inc.
3    Contributed by Ziemowit Laski  <zlaski@apple.com>
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "cp-tree.h"
28 #include "c-common.h"
29 #include "toplev.h"
30 #include "objc-act.h"
31 #include "langhooks.h"
32 #include "langhooks-def.h"
33 #include "diagnostic.h"
34 #include "debug.h"
35 #include "cp-objcp-common.h"
36
37 enum c_language_kind c_language = clk_objcxx;
38 static void objcxx_init_ts (void);
39
40 /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
41    consequently, there should be very few hooks below.  */
42
43 #undef LANG_HOOKS_NAME
44 #define LANG_HOOKS_NAME "GNU Objective-C++"
45 #undef LANG_HOOKS_INIT
46 #define LANG_HOOKS_INIT objc_init
47 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
48 #define LANG_HOOKS_DECL_PRINTABLE_NAME  objc_printable_name
49 #undef LANG_HOOKS_GIMPLIFY_EXPR 
50 #define LANG_HOOKS_GIMPLIFY_EXPR objc_gimplify_expr
51 #undef LANG_HOOKS_GET_CALLEE_FNDECL
52 #define LANG_HOOKS_GET_CALLEE_FNDECL    objc_get_callee_fndecl
53 #undef LANG_HOOKS_INIT_TS
54 #define LANG_HOOKS_INIT_TS objcxx_init_ts
55
56 /* Each front end provides its own lang hook initializer.  */
57 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
58
59 /* Tree code classes.  */
60
61 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
62
63 const enum tree_code_class tree_code_type[] = {
64 #include "tree.def"
65   tcc_exceptional,
66 #include "c-common.def"
67   tcc_exceptional,
68 #include "cp-tree.def"
69   tcc_exceptional,
70 #include "objc-tree.def"
71 };
72 #undef DEFTREECODE
73
74 /* Table indexed by tree code giving number of expression
75    operands beyond the fixed part of the node structure.
76    Not used for types or decls.  */
77
78 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
79
80 const unsigned char tree_code_length[] = {
81 #include "tree.def"
82   0,
83 #include "c-common.def"
84   0,
85 #include "cp-tree.def"
86   0,
87 #include "objc-tree.def"
88 };
89 #undef DEFTREECODE
90
91 /* Names of tree components.
92    Used for printing out the tree and error messages.  */
93 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
94
95 const char *const tree_code_name[] = {
96 #include "tree.def"
97   "@@dummy",
98 #include "c-common.def"
99   "@@dummy",
100 #include "cp-tree.def"
101   "@@dummy",
102 #include "objc-tree.def"
103 };
104 #undef DEFTREECODE
105
106 /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
107    there should be very few (if any) routines below.  */
108
109 tree
110 objcp_tsubst_copy_and_build (tree t, tree args, tsubst_flags_t complain, 
111                              tree in_decl, bool function_p ATTRIBUTE_UNUSED)
112 {
113 #define RECURSE(NODE) \
114   tsubst_copy_and_build (NODE, args, complain, in_decl, /*function_p=*/false)
115
116   /* The following two can only occur in Objective-C++.  */
117
118   switch ((int) TREE_CODE (t))
119     {
120     case MESSAGE_SEND_EXPR:
121       return objc_finish_message_expr
122         (RECURSE (TREE_OPERAND (t, 0)),
123          TREE_OPERAND (t, 1),  /* No need to expand the selector.  */
124          RECURSE (TREE_OPERAND (t, 2)));
125
126     case CLASS_REFERENCE_EXPR:
127       return objc_get_class_reference
128         (RECURSE (TREE_OPERAND (t, 0)));
129
130     default:
131       break;
132     }
133
134   /* Fall back to C++ processing.  */
135   return NULL_TREE;
136
137 #undef RECURSE
138 }
139
140 static void
141 objcxx_init_ts (void)
142 {
143   /* objc decls */
144   tree_contains_struct[CLASS_METHOD_DECL][TS_DECL_NON_COMMON] = 1;
145   tree_contains_struct[INSTANCE_METHOD_DECL][TS_DECL_NON_COMMON] = 1;
146   tree_contains_struct[KEYWORD_DECL][TS_DECL_NON_COMMON] = 1;
147   
148   tree_contains_struct[CLASS_METHOD_DECL][TS_DECL_WITH_VIS] = 1;
149   tree_contains_struct[INSTANCE_METHOD_DECL][TS_DECL_WITH_VIS] = 1;
150   tree_contains_struct[KEYWORD_DECL][TS_DECL_WITH_VIS] = 1;
151
152   tree_contains_struct[CLASS_METHOD_DECL][TS_DECL_WRTL] = 1;
153   tree_contains_struct[INSTANCE_METHOD_DECL][TS_DECL_WRTL] = 1;
154   tree_contains_struct[KEYWORD_DECL][TS_DECL_WRTL] = 1;
155   
156   tree_contains_struct[CLASS_METHOD_DECL][TS_DECL_MINIMAL] = 1;
157   tree_contains_struct[INSTANCE_METHOD_DECL][TS_DECL_MINIMAL] = 1;
158   tree_contains_struct[KEYWORD_DECL][TS_DECL_MINIMAL] = 1;
159   
160   tree_contains_struct[CLASS_METHOD_DECL][TS_DECL_COMMON] = 1;
161   tree_contains_struct[INSTANCE_METHOD_DECL][TS_DECL_COMMON] = 1;
162   tree_contains_struct[KEYWORD_DECL][TS_DECL_COMMON] = 1;
163   
164   /* C++ decls */
165   tree_contains_struct[NAMESPACE_DECL][TS_DECL_NON_COMMON] = 1;
166   tree_contains_struct[USING_DECL][TS_DECL_NON_COMMON] = 1;
167   tree_contains_struct[TEMPLATE_DECL][TS_DECL_NON_COMMON] = 1;
168
169   tree_contains_struct[NAMESPACE_DECL][TS_DECL_WITH_VIS] = 1;
170   tree_contains_struct[USING_DECL][TS_DECL_WITH_VIS] = 1;
171   tree_contains_struct[TEMPLATE_DECL][TS_DECL_WITH_VIS] = 1;
172
173   tree_contains_struct[NAMESPACE_DECL][TS_DECL_WRTL] = 1;
174   tree_contains_struct[USING_DECL][TS_DECL_WRTL] = 1;
175   tree_contains_struct[TEMPLATE_DECL][TS_DECL_WRTL] = 1;
176   
177   tree_contains_struct[NAMESPACE_DECL][TS_DECL_COMMON] = 1;
178   tree_contains_struct[USING_DECL][TS_DECL_COMMON] = 1;
179   tree_contains_struct[TEMPLATE_DECL][TS_DECL_COMMON] = 1;
180  
181   tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
182   tree_contains_struct[USING_DECL][TS_DECL_MINIMAL] = 1;
183   tree_contains_struct[TEMPLATE_DECL][TS_DECL_MINIMAL] = 1;
184
185   init_shadowed_var_for_decl ();
186 }
187
188
189 void
190 finish_file (void)
191 {
192   objc_finish_file ();
193 }
194
195 #include "gtype-objcp.h"