mirror of
git://sourceware.org/git/libabigail.git
synced 2025-01-29 12:42:50 +00:00
Add dumping routines for declaration location
* include/abg-fwd.h (get_global_scope()): New overload for const decl_base&. Move the other overloads up in the file. (get_translation_unit): Add an overload for decl_base&. Constify the others. (dump_decl_location): Declare new functions. * src/abg-ir.cc (get_global_scope): Define the overload for const decl_base&. Write the other overloads in terms of this one. (get_translation_unit): Likewise, define the overload for const decl_base&. Write the other overloads in terms of this one. (dump_decl_location): Define these new overloads. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
parent
2dd9d92e34
commit
c545e58b52
@ -113,14 +113,23 @@ add_decl_to_scope(shared_ptr<decl_base>, scope_decl*);
|
||||
shared_ptr<decl_base>
|
||||
add_decl_to_scope (shared_ptr<decl_base>, shared_ptr<scope_decl>);
|
||||
|
||||
const global_scope*
|
||||
get_global_scope(const decl_base&);
|
||||
|
||||
const global_scope*
|
||||
get_global_scope(const decl_base*);
|
||||
|
||||
const global_scope*
|
||||
get_global_scope(const shared_ptr<decl_base>);
|
||||
|
||||
translation_unit*
|
||||
get_translation_unit(const shared_ptr<decl_base>);
|
||||
get_translation_unit(const decl_base&);
|
||||
|
||||
translation_unit*
|
||||
get_translation_unit(decl_base*);
|
||||
get_translation_unit(const decl_base*);
|
||||
|
||||
translation_unit*
|
||||
get_translation_unit(const shared_ptr<decl_base>);
|
||||
|
||||
bool
|
||||
is_global_scope(const scope_decl*);
|
||||
@ -314,15 +323,6 @@ set_member_function_is_virtual(const shared_ptr<function_decl>&, bool);
|
||||
shared_ptr<type_base>
|
||||
strip_typedef(const shared_ptr<type_base>);
|
||||
|
||||
const global_scope*
|
||||
get_global_scope(const decl_base* decl);
|
||||
|
||||
translation_unit*
|
||||
get_translation_unit(decl_base* decl);
|
||||
|
||||
translation_unit*
|
||||
get_translation_unit(const shared_ptr<decl_base>);
|
||||
|
||||
string
|
||||
get_type_name(const shared_ptr<type_base>);
|
||||
|
||||
@ -428,5 +428,14 @@ dump(const shared_ptr<translation_unit>, std::ostream&);
|
||||
void
|
||||
dump(const shared_ptr<translation_unit>);
|
||||
|
||||
void
|
||||
dump_decl_location(const decl_base&);
|
||||
|
||||
void
|
||||
dump_decl_location(const decl_base*);
|
||||
|
||||
void
|
||||
dump_decl_location(const shared_ptr<decl_base>&);
|
||||
|
||||
} // end namespace abigail
|
||||
#endif // __ABG_IRFWD_H__
|
||||
|
@ -1421,18 +1421,28 @@ insert_decl_into_scope(decl_base_sptr decl,
|
||||
/// @return the global scope of the decl, or a null pointer if the
|
||||
/// decl is not yet added to a translation_unit.
|
||||
const global_scope*
|
||||
get_global_scope(const decl_base* decl)
|
||||
get_global_scope(const decl_base& decl)
|
||||
{
|
||||
if (const global_scope* s = dynamic_cast<const global_scope*>(decl))
|
||||
if (const global_scope* s = dynamic_cast<const global_scope*>(&decl))
|
||||
return s;
|
||||
|
||||
scope_decl* scope = decl ? decl->get_scope() : 0;
|
||||
scope_decl* scope = decl.get_scope();
|
||||
while (scope && !dynamic_cast<global_scope*>(scope))
|
||||
scope = scope->get_scope();
|
||||
|
||||
return scope ? dynamic_cast<global_scope*> (scope) : 0;
|
||||
}
|
||||
|
||||
/// return the global scope as seen by a given declaration.
|
||||
///
|
||||
/// @param decl the declaration to consider.
|
||||
///
|
||||
/// @return the global scope of the decl, or a null pointer if the
|
||||
/// decl is not yet added to a translation_unit.
|
||||
const global_scope*
|
||||
get_global_scope(const decl_base* decl)
|
||||
{return get_global_scope(*decl);}
|
||||
|
||||
/// Return the global scope as seen by a given declaration.
|
||||
///
|
||||
/// @param decl the declaration to consider.
|
||||
@ -1642,7 +1652,7 @@ types_are_compatible(const decl_base_sptr d1,
|
||||
/// @return the resulting translation unit, or null if the decl is not
|
||||
/// yet added to a translation unit.
|
||||
translation_unit*
|
||||
get_translation_unit(decl_base* decl)
|
||||
get_translation_unit(const decl_base& decl)
|
||||
{
|
||||
const global_scope* global = get_global_scope(decl);
|
||||
|
||||
@ -1651,6 +1661,16 @@ get_translation_unit(decl_base* decl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Return the translation unit a declaration belongs to.
|
||||
///
|
||||
/// @param decl the declaration to consider.
|
||||
///
|
||||
/// @return the resulting translation unit, or null if the decl is not
|
||||
/// yet added to a translation unit.
|
||||
translation_unit*
|
||||
get_translation_unit(const decl_base* decl)
|
||||
{return decl ? get_translation_unit(*decl) : 0;}
|
||||
|
||||
/// Return the translation unit a declaration belongs to.
|
||||
///
|
||||
/// @param decl the declaration to consider.
|
||||
|
@ -2218,5 +2218,50 @@ dump(const translation_unit_sptr t)
|
||||
if (t)
|
||||
dump(*t);
|
||||
}
|
||||
|
||||
/// Serialize the source location of a decl to an output stream for
|
||||
/// debugging purposes.
|
||||
///
|
||||
/// @param d the declaration to consider.
|
||||
///
|
||||
/// @param o the output stream to serizalize the location to.
|
||||
void
|
||||
dump_decl_location(const decl_base& d, ostream& o)
|
||||
{
|
||||
string path;
|
||||
unsigned line = 0, col = 0;
|
||||
translation_unit* tu = get_translation_unit(d);
|
||||
|
||||
tu->get_loc_mgr().expand_location(d.get_location(), path, line, col);
|
||||
o << path << ":" << line << "," << col << "\n";
|
||||
}
|
||||
|
||||
/// Serialize the source location of a decl to stderr for debugging
|
||||
/// purposes.
|
||||
///
|
||||
/// @param d the declaration to consider.
|
||||
void
|
||||
dump_decl_location(const decl_base& d)
|
||||
{dump_decl_location(d, cerr);}
|
||||
|
||||
/// Serialize the source location of a dcl to stderr for debugging
|
||||
/// purposes.
|
||||
///
|
||||
/// @param d the declaration to consider.
|
||||
void
|
||||
dump_decl_location(const decl_base* d)
|
||||
{
|
||||
if (d)
|
||||
dump_decl_location(*d);
|
||||
}
|
||||
|
||||
/// Serialize the source location of a dcl to stderr for debugging
|
||||
/// purposes.
|
||||
///
|
||||
/// @param d the declaration to consider.
|
||||
void
|
||||
dump_decl_location(const decl_base_sptr d)
|
||||
{dump_decl_location(d.get());}
|
||||
|
||||
// </Debugging routines>
|
||||
} //end namespace abigail
|
||||
|
Loading…
Reference in New Issue
Block a user