diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 352d97fd..d0768c38 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -392,18 +392,103 @@ is_global_scope(const scope_decl* scope) return !!dynamic_cast(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) +is_at_global_scope(const shared_ptr 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) +{ + return (decl && dynamic_cast(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) +{ + return (decl && dynamic_cast(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) +{ + return (decl && (dynamic_pointer_cast(decl) + || dynamic_pointer_cast(decl) + || dynamic_pointer_cast(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) +{ + return decl && dynamic_pointer_cast(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) +{ + 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) +{ + return (decl + && dynamic_pointer_cast(decl) + && dynamic_cast(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) +{ + return decl && dynamic_pointer_cast(decl); } // diff --git a/src/abg-ir.h b/src/abg-ir.h index 52e2f8fb..dedb31b9 100644 --- a/src/abg-ir.h +++ b/src/abg-ir.h @@ -64,7 +64,21 @@ bool is_global_scope(const scope_decl*); bool is_global_scope(const shared_ptr); -bool is_decl_at_global_scope(const shared_ptr); +bool is_at_global_scope(const shared_ptr); + +bool is_at_class_scope(const shared_ptr); + +bool is_at_template_scope(const shared_ptr); + +bool is_template_parameter(const shared_ptr); + +bool is_type(const shared_ptr); + +bool is_template_parm_composition_type(const shared_ptr); + +bool is_template_decl(const shared_ptr); + +bool is_function_template_pattern(const shared_ptr); /// \brief The source location of a token. /// diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 9eda22d6..ced42a3e 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -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(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