diff options
author | Dodji Seketeli <dodji@redhat.com> | 2009-08-31 21:48:04 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@gcc.gnu.org> | 2009-08-31 23:48:04 +0200 |
commit | f9329c35d72509053c31a8cf6938aa665f1352c1 (patch) | |
tree | e200e788bb350c1d9043fd4bea07ad60134978d6 /gcc/cp | |
parent | e756464b1f73a6d9ecc9477e45ce28589f7ef041 (diff) | |
download | gcc-f9329c35d72509053c31a8cf6938aa665f1352c1.zip gcc-f9329c35d72509053c31a8cf6938aa665f1352c1.tar.gz gcc-f9329c35d72509053c31a8cf6938aa665f1352c1.tar.bz2 |
Emit DWARF for template parameters (PR debug/30161)
ChangeLog:
PR debug/30161
* include/dwarf2.h (enum dwarf_tag): Added
DW_TAG_GNU_template_template_param
(enum dwarf_attribute): Added DW_AT_GNU_template_name.
gcc/ChangeLog:
PR debug/30161
* cgraph.h (cgraph_get_node): Declare ...
* cgraph.c (cgraph_get_node): ... new function.
* dwarf2out.c (gen_generic_params_dies,
generic_parameter_die, tree_add_const_value_attribute_for_decl,
make_ith_pack_parameter_name,
append_entry_to_tmpl_value_parm_die_table,
gen_remaining_tmpl_value_param_die_attribute): New functions.
(gen_subprogram_die): Generate debug info for template parameters
if debug info level is higher than DINFO_LEVEL_TERSE.
Use tree_add_const_value_attribute_for_decl instead of
tree_add_const_value_attribute.
(gen_const_die): Use tree_add_const_value_attribute_for_decl
instead of tree_add_const_value_attribute.
(gen_struct_or_union_type_die): Generate debug
info for template parameters if debug info level is higher than
DINFO_LEVEL_TERSE.
(tree_add_const_value_attribute): Handle integral and pointer
constants. Update comment.
(dwarf_tag_name): Support DW_TAG_GNU_template_template_param.
(dwarf_attr_name): Support DW_AT_GNU_template_name.
(reference_to_unused): Fix thinko. Remove redundant predicates from
tests.
(tree_add_const_value_attribute): Make this work for constant
expressions only.
tree_add_const_value_attribute_for_decl is to be used for variable
DECLs now.
(add_location_or_const_value_attribute): Use
tree_add_const_value_attribute_for_decl now.
(dwarf2out_finish): Emit the DW_AT_const_value attribute of
DW_TAG_template_value_param DIEs after function DIEs have been
emitted.
* langhooks.h (lang_hooks_for_types): Add
get_argument_pack_elems.
(lang_hooks_for_decls): Add generic_generic_parameter_decl_p.
(lang_hooks): Added get_innermost_generic_parms,
get_innermost_generic_args.
* langhooks-def.h (LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS,
LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS,
LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS,
LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P): New language hooks.
gcc/cp/ChangeLog:
PR debug/30161
* cp-tree.h (get_template_info): Parameter should be const.
(CLASSTYPE_SPECIALIZATION_OF_PRIMARY_TEMPLATE_P): Fix typo.
(get_template_argument_pack_elems,
get_primary_template_innermost_parameters,
get_template_innermost_arguments, template_template_parameter_p):
Declare ...
* pt.c (get_template_argument_pack_elems,
get_template_innermost_parameters, get_template_innermost_arguments,
template_template_parameter_p):
... New C++ front end implementation of new language hooks.
(primary_template_instantiation_p): New private helper.
(make_ith_pack_parameter_name): Use snprintf and strnlen instead of
printf and strlen.
(get_template_info): Const-ify parameter.
* cp-lang.c (LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS,
LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS,
LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS,
LANG_HOOKS_GENERIC_TYPE_PARAMETER_DECL_P): Initialize these
interfaces for the C++ front-end.
gcc/testsuite/ChangeLog:
PR debug/30161
* g++.dg/debug/dwarf2/template-params-1.C: New test.
* g++.dg/debug/dwarf2/template-params-2.C: Likewise.
* g++.dg/debug/dwarf2/template-params-3.C: Likewise.
* g++.dg/debug/dwarf2/template-params-4.C: Likewise.
* g++.dg/debug/dwarf2/template-params-5.C: Likewise.
* g++.dg/debug/dwarf2/template-params-6.C: Likewise.
* g++.dg/debug/dwarf2/template-func-params-1.C: Likewise.
* g++.dg/debug/dwarf2/template-func-params-2.C: Likewise.
* g++.dg/debug/dwarf2/template-func-params-3.C: Likewise.
* g++.dg/debug/dwarf2/template-func-params-4.C: Likewise.
* g++.dg/debug/dwarf2/template-func-params-5.C: Likewise.
* g++.dg/debug/dwarf2/template-func-params-6.C: Likewise.
* g++.dg/debug/dwarf2/template-func-params-7.C: Likewise.
From-SVN: r151249
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 23 | ||||
-rw-r--r-- | gcc/cp/cp-lang.c | 14 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 8 | ||||
-rw-r--r-- | gcc/cp/pt.c | 88 |
4 files changed, 125 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 78d075e..fa5bc97 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,26 @@ +2009-08-31 Dodji Seketeli <dodji@redhat.com> + + PR debug/30161 + * cp-tree.h (get_template_info): Parameter should be const. + (CLASSTYPE_SPECIALIZATION_OF_PRIMARY_TEMPLATE_P): Fix typo. + (get_template_argument_pack_elems, + get_primary_template_innermost_parameters, + get_template_innermost_arguments, template_template_parameter_p): + Declare ... + * pt.c (get_template_argument_pack_elems, + get_template_innermost_parameters, get_template_innermost_arguments, + template_template_parameter_p): + ... New C++ front end implementation of new language hooks. + (primary_template_instantiation_p): New private helper. + (make_ith_pack_parameter_name): Use snprintf and strnlen instead of + printf and strlen. + (get_template_info): Const-ify parameter. + * cp-lang.c (LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS, + LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS, + LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS, + LANG_HOOKS_GENERIC_TYPE_PARAMETER_DECL_P): Initialize these + interfaces for the C++ front-end. + 2009-08-31 Jason Merrill <jason@redhat.com> PR c++/41127 diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c index c8fa77c..bd35a65 100644 --- a/gcc/cp/cp-lang.c +++ b/gcc/cp/cp-lang.c @@ -49,6 +49,20 @@ static enum classify_record cp_classify_record (tree type); #define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record #undef LANG_HOOKS_GENERIC_TYPE_P #define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p + +#undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS +#define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \ + get_primary_template_innermost_parameters +#undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS +#define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \ + get_template_innermost_arguments +#undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS +#define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \ + get_template_argument_pack_elems +#undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P +#define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \ + template_template_parameter_p + #undef LANG_HOOKS_DECL_PRINTABLE_NAME #define LANG_HOOKS_DECL_PRINTABLE_NAME cxx_printable_name #undef LANG_HOOKS_DWARF_NAME diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ff9ca7b4..4480103 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3283,7 +3283,7 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) #define CLASSTYPE_SPECIALIZATION_OF_PRIMARY_TEMPLATE_P(NODE) \ (CLASS_TYPE_P (NODE) \ && CLASSTYPE_USE_TEMPLATE (NODE) \ - && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (arg))) + && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (NODE))) #define DECL_TEMPLATE_INSTANTIATION(NODE) (DECL_USE_TEMPLATE (NODE) & 1) #define CLASSTYPE_TEMPLATE_INSTANTIATION(NODE) \ @@ -4638,7 +4638,7 @@ extern bool uses_parameter_packs (tree); extern bool template_parameter_pack_p (const_tree); extern tree make_pack_expansion (tree); extern bool check_for_bare_parameter_packs (tree); -extern tree get_template_info (tree); +extern tree get_template_info (const_tree); extern tree get_types_needing_access_check (tree); extern int template_class_depth (tree); extern int is_specialization_of (tree, tree); @@ -4680,6 +4680,10 @@ extern bool explicit_class_specialization_p (tree); extern struct tinst_level *outermost_tinst_level(void); extern bool parameter_of_template_p (tree, tree); extern void init_template_processing (void); +bool template_template_parameter_p (const_tree); +extern tree get_primary_template_innermost_parameters (const_tree); +extern tree get_template_innermost_arguments (const_tree); +extern tree get_template_argument_pack_elems (const_tree); /* in repo.c */ extern void init_repo (void); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b856140..03b89fa 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -191,6 +191,7 @@ static tree tsubst_decl (tree, tree, tsubst_flags_t); static void perform_typedefs_access_check (tree tmpl, tree targs); static void append_type_to_template_for_access_check_1 (tree, tree, tree); static hashval_t iterative_hash_template_arg (tree arg, hashval_t val); +static bool primary_template_instantiation_p (const_tree); /* Make the current scope suitable for access checking when we are processing T. T can be FUNCTION_DECL for instantiated function @@ -287,7 +288,7 @@ finish_member_template_decl (tree decl) /* Return the template info node corresponding to T, whatever T is. */ tree -get_template_info (tree t) +get_template_info (const_tree t) { tree tinfo = NULL_TREE; @@ -2660,15 +2661,90 @@ static tree make_ith_pack_parameter_name (tree name, int i) { /* Munge the name to include the parameter index. */ - char numbuf[128]; +#define NUMBUF_LEN 128 + char numbuf[NUMBUF_LEN]; char* newname; - - sprintf(numbuf, "%i", i); - newname = (char*)alloca (IDENTIFIER_LENGTH (name) + strlen(numbuf) + 2); - sprintf(newname, "%s#%i", IDENTIFIER_POINTER (name), i); + int newname_len; + + snprintf (numbuf, NUMBUF_LEN, "%i", i); + newname_len = IDENTIFIER_LENGTH (name) + + strnlen (numbuf, NUMBUF_LEN) + 2; + newname = (char*)alloca (newname_len); + snprintf (newname, newname_len, + "%s#%i", IDENTIFIER_POINTER (name), i); return get_identifier (newname); } +/* Return true if T is a primary function + or class template instantiation. */ + +static bool +primary_template_instantiation_p (const_tree t) +{ + if (!t) + return false; + + if (TREE_CODE (t) == FUNCTION_DECL) + return DECL_LANG_SPECIFIC (t) + && DECL_TEMPLATE_INSTANTIATION (t) + && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t)); + else if (CLASS_TYPE_P (t)) + return CLASSTYPE_TEMPLATE_INSTANTIATION (t) + && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)); + return false; +} + +/* Return true if PARM is a template template parameter. */ + +bool +template_template_parameter_p (const_tree parm) +{ + return DECL_TEMPLATE_TEMPLATE_PARM_P (parm); +} + +/* Return the template parameters of T if T is a + primary template instantiation, NULL otherwise. */ + +tree +get_primary_template_innermost_parameters (const_tree t) +{ + tree parms = NULL, template_info = NULL; + + if ((template_info = get_template_info (t)) + && primary_template_instantiation_p (t)) + parms = INNERMOST_TEMPLATE_PARMS + (DECL_TEMPLATE_PARMS (TI_TEMPLATE (template_info))); + + return parms; +} + +/* Returns the template arguments of T if T is a template instantiation, + NULL otherwise. */ + +tree +get_template_innermost_arguments (const_tree t) +{ + tree args = NULL, template_info = NULL; + + if ((template_info = get_template_info (t)) + && TI_ARGS (template_info)) + args = INNERMOST_TEMPLATE_ARGS (TI_ARGS (template_info)); + + return args; +} + +/* Return the arguments pack of T if T is a template, NULL otherwise. */ + +tree +get_template_argument_pack_elems (const_tree t) +{ + if (TREE_CODE (t) != TYPE_ARGUMENT_PACK + && TREE_CODE (t) != NONTYPE_ARGUMENT_PACK) + return NULL; + + return ARGUMENT_PACK_ARGS (t); +} + /* Structure used to track the progress of find_parameter_packs_r. */ struct find_parameter_pack_data { |