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