Add some decl predicates

* src/abg-ir.h (is_at_global_scope): Rename
	is_decl_at_global_scope into this.
	(is_at_class_scope, is_at_template_scope)
	(is_template_parameter, is_type)
	(is_template_parm_composition_type)
	(is_function_template_pattern, is_template_decl): New
	declarations.
	* src/abg-ir.cc (is_at_global_scope): Rename
	is_decl_at_global_scope into this.
	(is_at_class_scope, is_at_template_scope, is_template_parameter)
	(is_type, is_template_parm_composition_type)
	(is_function_template_pattern, is_template_decl): New definitions.
	* src/abg-reader.cc (update_depth_info_of_read_context): Use the
	new is_at_class_scope decl.
This commit is contained in:
Dodji Seketeli 2013-04-25 16:06:21 +02:00 committed by Dodji Seketeli
parent 6831ba7c21
commit 59ff969f2e
3 changed files with 106 additions and 9 deletions

View File

@ -392,18 +392,103 @@ is_global_scope(const scope_decl* scope)
return !!dynamic_cast<const global_scope*>(scope);
}
/// Tests wether if a given decl is at global scope.
/// Tests whether a given decl is at global scope.
///
/// \param decl the decl to consider.
///
/// \return true iff #decl is at global scope.
bool
is_decl_at_global_scope(const shared_ptr<decl_base> decl)
is_at_global_scope(const shared_ptr<decl_base> decl)
{
if (!decl)
return false;
return (decl && is_global_scope(decl->get_scope()));
}
return is_global_scope(decl->get_scope());
/// Tests whether a given decl is at class scope.
///
/// \param the decl to consider.
///
/// \return true iff #decl is at class scope.
bool
is_at_class_scope(const shared_ptr<decl_base> decl)
{
return (decl && dynamic_cast<class_decl*>(decl->get_scope()));
}
/// Tests whether a given decl is at template scope.
///
/// Note that only template parameters , types that are compositions,
/// and template patterns (function or class) can be at template scope.
///
/// \param the decl to consider.
///
/// \return true iff the decl is at template scope.
bool
is_at_template_scope(const shared_ptr<decl_base> decl)
{
return (decl && dynamic_cast<template_decl*>(decl->get_scope()));
}
/// Tests whether a decl is a template parameter.
///
/// \param the decl to consider.
///
/// \return true iff #decl is a template parameter.
bool
is_template_parameter(const shared_ptr<decl_base> decl)
{
return (decl && (dynamic_pointer_cast<template_type_parameter>(decl)
|| dynamic_pointer_cast<template_non_type_parameter>(decl)
|| dynamic_pointer_cast<template_template_parameter>(decl)));
}
/// Tests whether a declaration is a type.
///
/// \param decl the decl to consider.
///
/// \return true iff #decl is a type.
bool
is_type(const shared_ptr<decl_base> decl)
{
return decl && dynamic_pointer_cast<type_base>(decl);
}
/// Tests whether a decl is a template parameter composition type.
///
/// \param decl the declaration to consider.
///
/// \return true iff #decl is a template parameter composition type.
bool
is_template_parm_composition_type(const shared_ptr<decl_base> decl)
{
return (decl
&& is_at_template_scope(decl)
&& is_type(decl)
&& !is_template_parameter(decl));
}
/// Test whether a decl is the pattern of a function template.
///
/// \param decl the decl to consider.
///
/// \return true iff #decl is the pattern of a function template.
bool
is_function_template_pattern(const shared_ptr<decl_base> decl)
{
return (decl
&& dynamic_pointer_cast<function_decl>(decl)
&& dynamic_cast<template_decl*>(decl->get_scope()));
}
/// Tests whether a decl is a template.
///
/// \param decl the decl to consider.
///
/// \return true iff #decl is a function template, class template, or
/// template template parameter.
bool
is_template_decl(const shared_ptr<decl_base> decl)
{
return decl && dynamic_pointer_cast<template_decl>(decl);
}
// </scope_decl definition>

View File

@ -64,7 +64,21 @@ bool is_global_scope(const scope_decl*);
bool is_global_scope(const shared_ptr<scope_decl>);
bool is_decl_at_global_scope(const shared_ptr<decl_base>);
bool is_at_global_scope(const shared_ptr<decl_base>);
bool is_at_class_scope(const shared_ptr<decl_base>);
bool is_at_template_scope(const shared_ptr<decl_base>);
bool is_template_parameter(const shared_ptr<decl_base>);
bool is_type(const shared_ptr<decl_base>);
bool is_template_parm_composition_type(const shared_ptr<decl_base>);
bool is_template_decl(const shared_ptr<decl_base>);
bool is_function_template_pattern(const shared_ptr<decl_base>);
/// \brief The source location of a token.
///

View File

@ -486,9 +486,7 @@ update_depth_info_of_read_context(read_context& ctxt, int new_depth)
/// OK, this is a hack needed because the libxml reader
/// interface doesn't provide us with a reliable way to know
/// when we read the end of an XML element.
if (d
&& dynamic_cast<class_decl*>(d->get_scope())
&& nb > 2)
if (is_at_class_scope(d) && nb > 2)
// This means we logically poped out at least a member of
// a class (i.e, during the xml parsing, we went up so
// that we got out of an e.g, member-type, data-member or