]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/cp-lang.c
extend.texi (Java Exceptions): Remove.
[thirdparty/gcc.git] / gcc / cp / cp-lang.c
CommitLineData
19551f29 1/* Language-dependent hooks for C++.
818ab71a 2 Copyright (C) 2001-2016 Free Software Foundation, Inc.
19551f29
AO
3 Contributed by Alexandre Oliva <aoliva@redhat.com>
4
f5adbb8d 5This file is part of GCC.
19551f29 6
f5adbb8d 7GCC is free software; you can redistribute it and/or modify
19551f29 8it under the terms of the GNU General Public License as published by
e77f031d 9the Free Software Foundation; either version 3, or (at your option)
19551f29
AO
10any later version.
11
f5adbb8d 12GCC is distributed in the hope that it will be useful,
19551f29
AO
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
e77f031d
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
19551f29
AO
20
21#include "config.h"
22#include "system.h"
4977bab6 23#include "coretypes.h"
19551f29 24#include "cp-tree.h"
2adfab87 25#include "stor-layout.h"
19551f29 26#include "langhooks.h"
d23c55c2 27#include "langhooks-def.h"
11bb4b27 28#include "cp-objcp-common.h"
19551f29 29
37fa72e9 30enum c_language_kind c_language = clk_cxx;
820cc88f 31static void cp_init_ts (void);
a0ad3539 32static const char * cxx_dwarf_name (tree t, int verbosity);
394d9fe7 33static enum classify_record cp_classify_record (tree type);
f9417da1 34static tree cp_eh_personality (void);
f8fb7295
DS
35static tree get_template_innermost_arguments_folded (const_tree);
36static tree get_template_argument_pack_elems_folded (const_tree);
7315daa6 37static tree cxx_enum_underlying_base_type (const_tree);
37fa72e9 38
11bb4b27
ZL
39/* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
40 consequently, there should be very few hooks below. */
41
3ac88239
NB
42#undef LANG_HOOKS_NAME
43#define LANG_HOOKS_NAME "GNU C++"
19551f29
AO
44#undef LANG_HOOKS_INIT
45#define LANG_HOOKS_INIT cxx_init
394d9fe7
AO
46#undef LANG_HOOKS_CLASSIFY_RECORD
47#define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
39ef6592
LC
48#undef LANG_HOOKS_GENERIC_TYPE_P
49#define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
f9329c35
DS
50
51#undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
52#define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \
53 get_primary_template_innermost_parameters
54#undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
55#define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \
f8fb7295 56 get_template_innermost_arguments_folded
d40a19da
DS
57#undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P
58#define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \
59 function_parameter_pack_p
f9329c35
DS
60#undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS
61#define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \
f8fb7295 62 get_template_argument_pack_elems_folded
f9329c35
DS
63#undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P
64#define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \
65 template_template_parameter_p
d40a19da
DS
66#undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P
67#define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \
68 function_parameter_expanded_from_pack_p
69#undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL
70#define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl
a0ad3539
MM
71#undef LANG_HOOKS_DWARF_NAME
72#define LANG_HOOKS_DWARF_NAME cxx_dwarf_name
820cc88f
DB
73#undef LANG_HOOKS_INIT_TS
74#define LANG_HOOKS_INIT_TS cp_init_ts
f9417da1
RG
75#undef LANG_HOOKS_EH_PERSONALITY
76#define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
77#undef LANG_HOOKS_EH_RUNTIME_TYPE
78#define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
7315daa6
MW
79#undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
80#define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type
f1e639b1 81
11bb4b27 82/* Each front end provides its own lang hook initializer. */
4537ec0c 83struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
8ac61af7 84
11bb4b27
ZL
85/* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
86 there should be very few routines below. */
8bcefb43 87
11bb4b27 88/* The following function does something real, but only in Objective-C++. */
e1a4dd13 89
11bb4b27 90tree
12308bc6
PC
91objcp_tsubst_copy_and_build (tree /*t*/,
92 tree /*args*/,
93 tsubst_flags_t /*complain*/,
94 tree /*in_decl*/,
95 bool /*function_p*/)
f75fbaf7 96{
11bb4b27 97 return NULL_TREE;
f75fbaf7
ZW
98}
99
820cc88f
DB
100static void
101cp_init_ts (void)
102{
81f653d6 103 cp_common_init_ts ();
820cc88f 104
3ed8593d 105 init_shadowed_var_for_decl ();
820cc88f
DB
106}
107
a0ad3539
MM
108static const char *
109cxx_dwarf_name (tree t, int verbosity)
110{
111 gcc_assert (DECL_P (t));
112
bde2d108 113 if (DECL_NAME (t)
ee47f74e 114 && (anon_aggrname_p (DECL_NAME (t)) || LAMBDA_TYPE_P (t)))
bde2d108 115 return NULL;
a0ad3539 116 if (verbosity >= 2)
7496cd5b
SA
117 return decl_as_dwarf_string (t,
118 TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
119 | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
a0ad3539 120
7496cd5b 121 return lang_decl_dwarf_name (t, verbosity, false);
a0ad3539
MM
122}
123
394d9fe7
AO
124static enum classify_record
125cp_classify_record (tree type)
126{
cc059bdd
JM
127 if (TYPE_LANG_SPECIFIC (type)
128 && CLASSTYPE_DECLARED_CLASS (type))
394d9fe7
AO
129 return RECORD_IS_CLASS;
130
131 return RECORD_IS_STRUCT;
132}
133
f9417da1
RG
134static GTY(()) tree cp_eh_personality_decl;
135
136static tree
137cp_eh_personality (void)
138{
139 if (!cp_eh_personality_decl)
bfecd57c 140 cp_eh_personality_decl = build_personality_function ("gxx");
f9417da1
RG
141
142 return cp_eh_personality_decl;
143}
144
f8fb7295
DS
145/* This is a subroutine of fold_cplus_constants. It returns TRUE if T
146 is a C++ specific constant that needs to be folded further before
147 being passed to the debug info emitter. */
148
149static bool
150template_arg_needs_folding (const_tree t)
151{
152 /* For now only PTRMEM_CST nodes are to be folded further. */
153 if (TREE_CODE (t) == PTRMEM_CST)
154 return true;
155 return false;
156}
157
158/* Fold the elements of the TREE_VEC C which are C++ specific nodes
159 that would need folding so that they can be processed by the debug
160 info emitter. This is a subroutine of
161 get_template_innermost_arguments_folded and
162 get_template_argument_pack_elems_folded. */
163
164static tree
165fold_cplus_constants (const_tree c)
166{
167 tree folded_elems, elems = CONST_CAST_TREE (c);
168 int vec_len, i;
169
170 if (elems == NULL_TREE || elems == error_mark_node)
171 return elems;
172
173 vec_len = TREE_VEC_LENGTH (elems);
174
175 /* First check if there is at least one element that needs
176 folding. If there is none, we just return ELEMS. Otherwise create
177 and return a new tree vector that contains the folded versions of
178 ELEMS. This is to avoid allocating memory if we don't need
179 to. */
180 for (i = 0; i < vec_len; ++i)
181 {
182 if (template_arg_needs_folding (TREE_VEC_ELT (elems, i)))
183 break;
184 }
185 if (i == vec_len)
186 return elems;
187
188 folded_elems = make_tree_vec (vec_len);
189 for (i = 0; i < vec_len; ++i)
190 {
191 tree elem = TREE_VEC_ELT (elems, i);
192 TREE_VEC_ELT (folded_elems, i) =
193 (elem && !TYPE_P (elem)) ? cplus_expand_constant (elem) : elem;
194
195 }
196 return folded_elems;
197}
198
199/* The C++ implementation of the LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
200 hook. It returns the innermost template arguments of type T, and
201 makes sure those arguments are folded enough for the debug info
202 emitter. */
203
204static tree
205get_template_innermost_arguments_folded (const_tree t)
206{
207 return fold_cplus_constants (get_template_innermost_arguments (t));
208}
209
210static tree
211get_template_argument_pack_elems_folded (const_tree t)
212{
213 return fold_cplus_constants (get_template_argument_pack_elems (t));
214}
215
7315daa6
MW
216/* The C++ version of the enum_underlying_base_type langhook.
217 See also cp/semantics.c (finish_underlying_type). */
218
219static
220tree cxx_enum_underlying_base_type (const_tree type)
221{
222 tree underlying_type = ENUM_UNDERLYING_TYPE (type);
223
224 if (! ENUM_FIXED_UNDERLYING_TYPE_P (type))
225 underlying_type
226 = c_common_type_for_mode (TYPE_MODE (underlying_type),
227 TYPE_UNSIGNED (underlying_type));
228
229 return underlying_type;
230}
231
6561cdf6 232#include "gt-cp-cp-lang.h"
11bb4b27 233#include "gtype-cp.h"