Daily bump.
[official-gcc.git] / gcc / cp / cp-lang.c
blob014f393ecfa71ffa62a84ee3807e49bb3007afd6
1 /* Language-dependent hooks for C++.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 Contributed by Alexandre Oliva <aoliva@redhat.com>
5 This file is part of GCC.
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 3, or (at your option)
10 any later version.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "stor-layout.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 #include "parser.h"
37 enum c_language_kind c_language = clk_cxx;
38 static void cp_init_ts (void);
39 static const char * cxx_dwarf_name (tree t, int verbosity);
40 static enum classify_record cp_classify_record (tree type);
41 static tree cp_eh_personality (void);
42 static tree get_template_innermost_arguments_folded (const_tree);
43 static tree get_template_argument_pack_elems_folded (const_tree);
44 static tree cxx_enum_underlying_base_type (const_tree);
46 /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
47 consequently, there should be very few hooks below. */
49 #undef LANG_HOOKS_NAME
50 #define LANG_HOOKS_NAME "GNU C++"
51 #undef LANG_HOOKS_INIT
52 #define LANG_HOOKS_INIT cxx_init
53 #undef LANG_HOOKS_CLASSIFY_RECORD
54 #define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
55 #undef LANG_HOOKS_GENERIC_TYPE_P
56 #define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
58 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
59 #define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \
60 get_primary_template_innermost_parameters
61 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
62 #define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \
63 get_template_innermost_arguments_folded
64 #undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P
65 #define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \
66 function_parameter_pack_p
67 #undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS
68 #define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \
69 get_template_argument_pack_elems_folded
70 #undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P
71 #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \
72 template_template_parameter_p
73 #undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P
74 #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \
75 function_parameter_expanded_from_pack_p
76 #undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL
77 #define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl
78 #undef LANG_HOOKS_DWARF_NAME
79 #define LANG_HOOKS_DWARF_NAME cxx_dwarf_name
80 #undef LANG_HOOKS_INIT_TS
81 #define LANG_HOOKS_INIT_TS cp_init_ts
82 #undef LANG_HOOKS_EH_PERSONALITY
83 #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
84 #undef LANG_HOOKS_EH_RUNTIME_TYPE
85 #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
86 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
87 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type
89 /* Each front end provides its own lang hook initializer. */
90 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
92 /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
93 there should be very few routines below. */
95 /* The following function does something real, but only in Objective-C++. */
97 tree
98 objcp_tsubst_copy_and_build (tree /*t*/,
99 tree /*args*/,
100 tsubst_flags_t /*complain*/,
101 tree /*in_decl*/,
102 bool /*function_p*/)
104 return NULL_TREE;
107 static void
108 cp_init_ts (void)
110 cp_common_init_ts ();
112 init_shadowed_var_for_decl ();
115 static const char *
116 cxx_dwarf_name (tree t, int verbosity)
118 gcc_assert (DECL_P (t));
120 if (DECL_NAME (t)
121 && (ANON_AGGRNAME_P (DECL_NAME (t)) || LAMBDA_TYPE_P (t)))
122 return NULL;
123 if (verbosity >= 2)
124 return decl_as_dwarf_string (t,
125 TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
126 | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
128 return lang_decl_dwarf_name (t, verbosity, false);
131 static enum classify_record
132 cp_classify_record (tree type)
134 if (TYPE_LANG_SPECIFIC (type)
135 && CLASSTYPE_DECLARED_CLASS (type))
136 return RECORD_IS_CLASS;
138 return RECORD_IS_STRUCT;
141 static GTY(()) tree cp_eh_personality_decl;
143 static tree
144 cp_eh_personality (void)
146 if (!cp_eh_personality_decl)
148 const char *lang = (pragma_java_exceptions ? "gcj" : "gxx");
149 cp_eh_personality_decl = build_personality_function (lang);
152 return cp_eh_personality_decl;
155 /* This is a subroutine of fold_cplus_constants. It returns TRUE if T
156 is a C++ specific constant that needs to be folded further before
157 being passed to the debug info emitter. */
159 static bool
160 template_arg_needs_folding (const_tree t)
162 /* For now only PTRMEM_CST nodes are to be folded further. */
163 if (TREE_CODE (t) == PTRMEM_CST)
164 return true;
165 return false;
168 /* Fold the elements of the TREE_VEC C which are C++ specific nodes
169 that would need folding so that they can be processed by the debug
170 info emitter. This is a subroutine of
171 get_template_innermost_arguments_folded and
172 get_template_argument_pack_elems_folded. */
174 static tree
175 fold_cplus_constants (const_tree c)
177 tree folded_elems, elems = CONST_CAST_TREE (c);
178 int vec_len, i;
180 if (elems == NULL_TREE || elems == error_mark_node)
181 return elems;
183 vec_len = TREE_VEC_LENGTH (elems);
185 /* First check if there is at least one element that needs
186 folding. If there is none, we just return ELEMS. Otherwise create
187 and return a new tree vector that contains the folded versions of
188 ELEMS. This is to avoid allocating memory if we don't need
189 to. */
190 for (i = 0; i < vec_len; ++i)
192 if (template_arg_needs_folding (TREE_VEC_ELT (elems, i)))
193 break;
195 if (i == vec_len)
196 return elems;
198 folded_elems = make_tree_vec (vec_len);
199 for (i = 0; i < vec_len; ++i)
201 tree elem = TREE_VEC_ELT (elems, i);
202 TREE_VEC_ELT (folded_elems, i) =
203 (elem && !TYPE_P (elem)) ? cplus_expand_constant (elem) : elem;
206 return folded_elems;
209 /* The C++ implementation of the LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
210 hook. It returns the innermost template arguments of type T, and
211 makes sure those arguments are folded enough for the debug info
212 emitter. */
214 static tree
215 get_template_innermost_arguments_folded (const_tree t)
217 return fold_cplus_constants (get_template_innermost_arguments (t));
220 static tree
221 get_template_argument_pack_elems_folded (const_tree t)
223 return fold_cplus_constants (get_template_argument_pack_elems (t));
226 /* The C++ version of the enum_underlying_base_type langhook.
227 See also cp/semantics.c (finish_underlying_type). */
229 static
230 tree cxx_enum_underlying_base_type (const_tree type)
232 tree underlying_type = ENUM_UNDERLYING_TYPE (type);
234 if (! ENUM_FIXED_UNDERLYING_TYPE_P (type))
235 underlying_type
236 = c_common_type_for_mode (TYPE_MODE (underlying_type),
237 TYPE_UNSIGNED (underlying_type));
239 return underlying_type;
242 #include "gt-cp-cp-lang.h"
243 #include "gtype-cp.h"