1 /* Language-dependent hooks for C++.
2 Copyright (C) 2001-2015 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)
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/>. */
23 #include "coretypes.h"
28 #include "stor-layout.h"
30 #include "c-family/c-common.h"
31 #include "langhooks.h"
32 #include "langhooks-def.h"
34 #include "cp-objcp-common.h"
38 enum c_language_kind c_language
= clk_cxx
;
39 static void cp_init_ts (void);
40 static const char * cxx_dwarf_name (tree t
, int verbosity
);
41 static enum classify_record
cp_classify_record (tree type
);
42 static tree
cp_eh_personality (void);
43 static tree
get_template_innermost_arguments_folded (const_tree
);
44 static tree
get_template_argument_pack_elems_folded (const_tree
);
45 static tree
cxx_enum_underlying_base_type (const_tree
);
47 /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
48 consequently, there should be very few hooks below. */
50 #undef LANG_HOOKS_NAME
51 #define LANG_HOOKS_NAME "GNU C++"
52 #undef LANG_HOOKS_INIT
53 #define LANG_HOOKS_INIT cxx_init
54 #undef LANG_HOOKS_CLASSIFY_RECORD
55 #define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
56 #undef LANG_HOOKS_GENERIC_TYPE_P
57 #define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
59 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
60 #define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \
61 get_primary_template_innermost_parameters
62 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
63 #define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \
64 get_template_innermost_arguments_folded
65 #undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P
66 #define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \
67 function_parameter_pack_p
68 #undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS
69 #define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \
70 get_template_argument_pack_elems_folded
71 #undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P
72 #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \
73 template_template_parameter_p
74 #undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P
75 #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \
76 function_parameter_expanded_from_pack_p
77 #undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL
78 #define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl
79 #undef LANG_HOOKS_DWARF_NAME
80 #define LANG_HOOKS_DWARF_NAME cxx_dwarf_name
81 #undef LANG_HOOKS_INIT_TS
82 #define LANG_HOOKS_INIT_TS cp_init_ts
83 #undef LANG_HOOKS_EH_PERSONALITY
84 #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
85 #undef LANG_HOOKS_EH_RUNTIME_TYPE
86 #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
87 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
88 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type
90 /* Each front end provides its own lang hook initializer. */
91 struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
93 /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
94 there should be very few routines below. */
96 /* The following function does something real, but only in Objective-C++. */
99 objcp_tsubst_copy_and_build (tree
/*t*/,
101 tsubst_flags_t
/*complain*/,
111 cp_common_init_ts ();
113 init_shadowed_var_for_decl ();
117 cxx_dwarf_name (tree t
, int verbosity
)
119 gcc_assert (DECL_P (t
));
122 && (anon_aggrname_p (DECL_NAME (t
)) || LAMBDA_TYPE_P (t
)))
125 return decl_as_dwarf_string (t
,
126 TFF_DECL_SPECIFIERS
| TFF_UNQUALIFIED_NAME
127 | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
129 return lang_decl_dwarf_name (t
, verbosity
, false);
132 static enum classify_record
133 cp_classify_record (tree type
)
135 if (TYPE_LANG_SPECIFIC (type
)
136 && CLASSTYPE_DECLARED_CLASS (type
))
137 return RECORD_IS_CLASS
;
139 return RECORD_IS_STRUCT
;
142 static GTY(()) tree cp_eh_personality_decl
;
145 cp_eh_personality (void)
147 if (!cp_eh_personality_decl
)
149 const char *lang
= (pragma_java_exceptions
? "gcj" : "gxx");
150 cp_eh_personality_decl
= build_personality_function (lang
);
153 return cp_eh_personality_decl
;
156 /* This is a subroutine of fold_cplus_constants. It returns TRUE if T
157 is a C++ specific constant that needs to be folded further before
158 being passed to the debug info emitter. */
161 template_arg_needs_folding (const_tree t
)
163 /* For now only PTRMEM_CST nodes are to be folded further. */
164 if (TREE_CODE (t
) == PTRMEM_CST
)
169 /* Fold the elements of the TREE_VEC C which are C++ specific nodes
170 that would need folding so that they can be processed by the debug
171 info emitter. This is a subroutine of
172 get_template_innermost_arguments_folded and
173 get_template_argument_pack_elems_folded. */
176 fold_cplus_constants (const_tree c
)
178 tree folded_elems
, elems
= CONST_CAST_TREE (c
);
181 if (elems
== NULL_TREE
|| elems
== error_mark_node
)
184 vec_len
= TREE_VEC_LENGTH (elems
);
186 /* First check if there is at least one element that needs
187 folding. If there is none, we just return ELEMS. Otherwise create
188 and return a new tree vector that contains the folded versions of
189 ELEMS. This is to avoid allocating memory if we don't need
191 for (i
= 0; i
< vec_len
; ++i
)
193 if (template_arg_needs_folding (TREE_VEC_ELT (elems
, i
)))
199 folded_elems
= make_tree_vec (vec_len
);
200 for (i
= 0; i
< vec_len
; ++i
)
202 tree elem
= TREE_VEC_ELT (elems
, i
);
203 TREE_VEC_ELT (folded_elems
, i
) =
204 (elem
&& !TYPE_P (elem
)) ? cplus_expand_constant (elem
) : elem
;
210 /* The C++ implementation of the LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
211 hook. It returns the innermost template arguments of type T, and
212 makes sure those arguments are folded enough for the debug info
216 get_template_innermost_arguments_folded (const_tree t
)
218 return fold_cplus_constants (get_template_innermost_arguments (t
));
222 get_template_argument_pack_elems_folded (const_tree t
)
224 return fold_cplus_constants (get_template_argument_pack_elems (t
));
227 /* The C++ version of the enum_underlying_base_type langhook.
228 See also cp/semantics.c (finish_underlying_type). */
231 tree
cxx_enum_underlying_base_type (const_tree type
)
233 tree underlying_type
= ENUM_UNDERLYING_TYPE (type
);
235 if (! ENUM_FIXED_UNDERLYING_TYPE_P (type
))
237 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
238 TYPE_UNSIGNED (underlying_type
));
240 return underlying_type
;
243 #include "gt-cp-cp-lang.h"
244 #include "gtype-cp.h"