OSDN Git Service

2011-01-03 Martin Jambor <mjambor@suse.cz>
[pf3gnuchains/gcc-fork.git] / gcc / cp / cp-lang.c
1 /* Language-dependent hooks for C++.
2    Copyright 2001, 2002, 2004, 2007, 2008, 2009, 2010
3    Free Software Foundation, Inc.
4    Contributed by Alexandre Oliva  <aoliva@redhat.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
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-family/c-common.h"
29 #include "langhooks.h"
30 #include "langhooks-def.h"
31 #include "debug.h"
32 #include "cp-objcp-common.h"
33 #include "hashtab.h"
34 #include "target.h"
35
36 enum c_language_kind c_language = clk_cxx;
37 static void cp_init_ts (void);
38 static const char * cxx_dwarf_name (tree t, int verbosity);
39 static enum classify_record cp_classify_record (tree type);
40 static tree cp_eh_personality (void);
41
42 /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
43    consequently, there should be very few hooks below.  */
44
45 #undef LANG_HOOKS_NAME
46 #define LANG_HOOKS_NAME "GNU C++"
47 #undef LANG_HOOKS_INIT
48 #define LANG_HOOKS_INIT cxx_init
49 #undef LANG_HOOKS_CLASSIFY_RECORD
50 #define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
51 #undef LANG_HOOKS_GENERIC_TYPE_P
52 #define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
53
54 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
55 #define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \
56         get_primary_template_innermost_parameters
57 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
58 #define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \
59         get_template_innermost_arguments
60 #undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P
61 #define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \
62         function_parameter_pack_p
63 #undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS
64 #define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \
65         get_template_argument_pack_elems
66 #undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P
67 #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \
68         template_template_parameter_p
69 #undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P
70 #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \
71         function_parameter_expanded_from_pack_p
72 #undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL
73 #define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl
74 #undef LANG_HOOKS_DWARF_NAME
75 #define LANG_HOOKS_DWARF_NAME cxx_dwarf_name
76 #undef LANG_HOOKS_INIT_TS
77 #define LANG_HOOKS_INIT_TS cp_init_ts
78 #undef LANG_HOOKS_EH_PERSONALITY
79 #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
80 #undef LANG_HOOKS_EH_RUNTIME_TYPE
81 #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
82
83 /* Each front end provides its own lang hook initializer.  */
84 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
85
86 /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
87    there should be very few routines below.  */
88
89 /* The following function does something real, but only in Objective-C++.  */
90
91 tree
92 objcp_tsubst_copy_and_build (tree t ATTRIBUTE_UNUSED,
93                              tree args ATTRIBUTE_UNUSED,
94                              tsubst_flags_t complain ATTRIBUTE_UNUSED,
95                              tree in_decl ATTRIBUTE_UNUSED,
96                              bool function_p ATTRIBUTE_UNUSED)
97 {
98   return NULL_TREE;
99 }
100
101
102 static void
103 cp_init_ts (void)
104 {
105   tree_contains_struct[NAMESPACE_DECL][TS_DECL_NON_COMMON] = 1;
106   tree_contains_struct[USING_DECL][TS_DECL_NON_COMMON] = 1;
107   tree_contains_struct[TEMPLATE_DECL][TS_DECL_NON_COMMON] = 1;
108
109   tree_contains_struct[NAMESPACE_DECL][TS_DECL_WITH_VIS] = 1;
110   tree_contains_struct[USING_DECL][TS_DECL_WITH_VIS] = 1;
111   tree_contains_struct[TEMPLATE_DECL][TS_DECL_WITH_VIS] = 1;
112
113   tree_contains_struct[NAMESPACE_DECL][TS_DECL_WRTL] = 1;
114   tree_contains_struct[USING_DECL][TS_DECL_WRTL] = 1;
115   tree_contains_struct[TEMPLATE_DECL][TS_DECL_WRTL] = 1;
116
117   tree_contains_struct[NAMESPACE_DECL][TS_DECL_COMMON] = 1;
118   tree_contains_struct[USING_DECL][TS_DECL_COMMON] = 1;
119   tree_contains_struct[TEMPLATE_DECL][TS_DECL_COMMON] = 1;
120
121   tree_contains_struct[NAMESPACE_DECL][TS_DECL_MINIMAL] = 1;
122   tree_contains_struct[USING_DECL][TS_DECL_MINIMAL] = 1;
123   tree_contains_struct[TEMPLATE_DECL][TS_DECL_MINIMAL] = 1;
124
125   init_shadowed_var_for_decl ();
126
127 }
128
129 static const char *
130 cxx_dwarf_name (tree t, int verbosity)
131 {
132   gcc_assert (DECL_P (t));
133
134   if (DECL_NAME (t)
135       && (ANON_AGGRNAME_P (DECL_NAME (t)) || LAMBDANAME_P (DECL_NAME (t))))
136     return NULL;
137   if (verbosity >= 2)
138     return decl_as_string (t,
139                            TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
140                            | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
141
142   return cxx_printable_name (t, verbosity);
143 }
144
145 static enum classify_record
146 cp_classify_record (tree type)
147 {
148   if (CLASSTYPE_DECLARED_CLASS (type))
149     return RECORD_IS_CLASS;
150
151   return RECORD_IS_STRUCT;
152 }
153
154 static GTY(()) tree cp_eh_personality_decl;
155
156 static tree
157 cp_eh_personality (void)
158 {
159   if (!cp_eh_personality_decl)
160     {
161       const char *lang = (pragma_java_exceptions ? "gcj" : "gxx");
162       cp_eh_personality_decl = build_personality_function (lang);
163     }
164
165   return cp_eh_personality_decl;
166 }
167
168 #include "gt-cp-cp-lang.h"
169 #include "gtype-cp.h"