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 "double-int.h"
35 #include "stor-layout.h"
37 #include "c-family/c-common.h"
38 #include "langhooks.h"
39 #include "langhooks-def.h"
41 #include "cp-objcp-common.h"
46 enum c_language_kind c_language
= clk_cxx
;
47 static void cp_init_ts (void);
48 static const char * cxx_dwarf_name (tree t
, int verbosity
);
49 static enum classify_record
cp_classify_record (tree type
);
50 static tree
cp_eh_personality (void);
51 static tree
get_template_innermost_arguments_folded (const_tree
);
52 static tree
get_template_argument_pack_elems_folded (const_tree
);
53 static tree
cxx_enum_underlying_base_type (const_tree
);
55 /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
56 consequently, there should be very few hooks below. */
58 #undef LANG_HOOKS_NAME
59 #define LANG_HOOKS_NAME "GNU C++"
60 #undef LANG_HOOKS_INIT
61 #define LANG_HOOKS_INIT cxx_init
62 #undef LANG_HOOKS_CLASSIFY_RECORD
63 #define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
64 #undef LANG_HOOKS_GENERIC_TYPE_P
65 #define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
67 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
68 #define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \
69 get_primary_template_innermost_parameters
70 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
71 #define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \
72 get_template_innermost_arguments_folded
73 #undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P
74 #define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \
75 function_parameter_pack_p
76 #undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS
77 #define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \
78 get_template_argument_pack_elems_folded
79 #undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P
80 #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \
81 template_template_parameter_p
82 #undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P
83 #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \
84 function_parameter_expanded_from_pack_p
85 #undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL
86 #define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl
87 #undef LANG_HOOKS_DWARF_NAME
88 #define LANG_HOOKS_DWARF_NAME cxx_dwarf_name
89 #undef LANG_HOOKS_INIT_TS
90 #define LANG_HOOKS_INIT_TS cp_init_ts
91 #undef LANG_HOOKS_EH_PERSONALITY
92 #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
93 #undef LANG_HOOKS_EH_RUNTIME_TYPE
94 #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
95 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
96 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type
98 /* Each front end provides its own lang hook initializer. */
99 struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
101 /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
102 there should be very few routines below. */
104 /* The following function does something real, but only in Objective-C++. */
107 objcp_tsubst_copy_and_build (tree
/*t*/,
109 tsubst_flags_t
/*complain*/,
119 cp_common_init_ts ();
121 init_shadowed_var_for_decl ();
125 cxx_dwarf_name (tree t
, int verbosity
)
127 gcc_assert (DECL_P (t
));
130 && (ANON_AGGRNAME_P (DECL_NAME (t
)) || LAMBDA_TYPE_P (t
)))
133 return decl_as_dwarf_string (t
,
134 TFF_DECL_SPECIFIERS
| TFF_UNQUALIFIED_NAME
135 | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
137 return lang_decl_dwarf_name (t
, verbosity
, false);
140 static enum classify_record
141 cp_classify_record (tree type
)
143 if (TYPE_LANG_SPECIFIC (type
)
144 && CLASSTYPE_DECLARED_CLASS (type
))
145 return RECORD_IS_CLASS
;
147 return RECORD_IS_STRUCT
;
150 static GTY(()) tree cp_eh_personality_decl
;
153 cp_eh_personality (void)
155 if (!cp_eh_personality_decl
)
157 const char *lang
= (pragma_java_exceptions
? "gcj" : "gxx");
158 cp_eh_personality_decl
= build_personality_function (lang
);
161 return cp_eh_personality_decl
;
164 /* This is a subroutine of fold_cplus_constants. It returns TRUE if T
165 is a C++ specific constant that needs to be folded further before
166 being passed to the debug info emitter. */
169 template_arg_needs_folding (const_tree t
)
171 /* For now only PTRMEM_CST nodes are to be folded further. */
172 if (TREE_CODE (t
) == PTRMEM_CST
)
177 /* Fold the elements of the TREE_VEC C which are C++ specific nodes
178 that would need folding so that they can be processed by the debug
179 info emitter. This is a subroutine of
180 get_template_innermost_arguments_folded and
181 get_template_argument_pack_elems_folded. */
184 fold_cplus_constants (const_tree c
)
186 tree folded_elems
, elems
= CONST_CAST_TREE (c
);
189 if (elems
== NULL_TREE
|| elems
== error_mark_node
)
192 vec_len
= TREE_VEC_LENGTH (elems
);
194 /* First check if there is at least one element that needs
195 folding. If there is none, we just return ELEMS. Otherwise create
196 and return a new tree vector that contains the folded versions of
197 ELEMS. This is to avoid allocating memory if we don't need
199 for (i
= 0; i
< vec_len
; ++i
)
201 if (template_arg_needs_folding (TREE_VEC_ELT (elems
, i
)))
207 folded_elems
= make_tree_vec (vec_len
);
208 for (i
= 0; i
< vec_len
; ++i
)
210 tree elem
= TREE_VEC_ELT (elems
, i
);
211 TREE_VEC_ELT (folded_elems
, i
) =
212 (elem
&& !TYPE_P (elem
)) ? cplus_expand_constant (elem
) : elem
;
218 /* The C++ implementation of the LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
219 hook. It returns the innermost template arguments of type T, and
220 makes sure those arguments are folded enough for the debug info
224 get_template_innermost_arguments_folded (const_tree t
)
226 return fold_cplus_constants (get_template_innermost_arguments (t
));
230 get_template_argument_pack_elems_folded (const_tree t
)
232 return fold_cplus_constants (get_template_argument_pack_elems (t
));
235 /* The C++ version of the enum_underlying_base_type langhook.
236 See also cp/semantics.c (finish_underlying_type). */
239 tree
cxx_enum_underlying_base_type (const_tree type
)
241 tree underlying_type
= ENUM_UNDERLYING_TYPE (type
);
243 if (! ENUM_FIXED_UNDERLYING_TYPE_P (type
))
245 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
246 TYPE_UNSIGNED (underlying_type
));
248 return underlying_type
;
251 #include "gt-cp-cp-lang.h"
252 #include "gtype-cp.h"