Added storing list of using namespace directives for each namespace

This commit is contained in:
Bartek Kryza
2022-03-14 23:23:48 +01:00
parent 1d0bef2085
commit c0a759c2c4
5 changed files with 52 additions and 1 deletions

View File

@@ -196,4 +196,17 @@ translation_unit_context::get_current_package() const
return current_package_;
}
void translation_unit_context::add_using_namespace_directive(
common::model::namespace_ ns)
{
using_ns_declarations_[ns_.to_string()].insert(std::move(ns));
}
const std::set<common::model::namespace_> &
translation_unit_context::using_namespace_directive(
const common::model::namespace_ &ns) const
{
return using_ns_declarations_.at(ns.to_string());
}
}

View File

@@ -78,10 +78,21 @@ public:
type_safe::optional_ref<common::model::package> get_current_package() const;
void add_using_namespace_directive(common::model::namespace_ ns);
const std::set<common::model::namespace_> &using_namespace_directive(
const common::model::namespace_ &ns) const;
private:
// Current visitor namespace
common::model::namespace_ ns_;
// A map of 'using namespace' declared within a given namespace scope
// This is necessary to properly establish the namespace of a given entity
// for instance in unexposed template parameters
std::map<std::string, std::set<common::model::namespace_>>
using_ns_declarations_;
// Reference to the cppast entity index
cppast::cpp_entity_index &entity_index_;

View File

@@ -187,6 +187,8 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
if (ns_ref.get(ctx.entity_index()).size() > 0) {
auto full_ns = cx::util::full_name(ctx.get_namespace(),
ns_ref.get(ctx.entity_index()).at(0).get());
ctx.add_using_namespace_directive(full_ns);
}
}
});