Added storing list of using namespace directives for each namespace
This commit is contained in:
@@ -196,4 +196,17 @@ translation_unit_context::get_current_package() const
|
|||||||
return current_package_;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,10 +78,21 @@ public:
|
|||||||
|
|
||||||
type_safe::optional_ref<common::model::package> get_current_package() const;
|
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:
|
private:
|
||||||
// Current visitor namespace
|
// Current visitor namespace
|
||||||
common::model::namespace_ ns_;
|
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
|
// Reference to the cppast entity index
|
||||||
cppast::cpp_entity_index &entity_index_;
|
cppast::cpp_entity_index &entity_index_;
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,8 @@ void translation_unit_visitor::operator()(const cppast::cpp_entity &file)
|
|||||||
if (ns_ref.get(ctx.entity_index()).size() > 0) {
|
if (ns_ref.get(ctx.entity_index()).size() > 0) {
|
||||||
auto full_ns = cx::util::full_name(ctx.get_namespace(),
|
auto full_ns = cx::util::full_name(ctx.get_namespace(),
|
||||||
ns_ref.get(ctx.entity_index()).at(0).get());
|
ns_ref.get(ctx.entity_index()).at(0).get());
|
||||||
|
|
||||||
|
ctx.add_using_namespace_directive(full_ns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -185,6 +185,11 @@ bool operator==(const namespace_ &left, const namespace_ &right)
|
|||||||
return left.namespace_path_ == right.namespace_path_;
|
return left.namespace_path_ == right.namespace_path_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator<(const namespace_ &left, const namespace_ &right)
|
||||||
|
{
|
||||||
|
return std::hash<namespace_>{}(left) < std::hash<namespace_>{}(right);
|
||||||
|
}
|
||||||
|
|
||||||
std::string namespace_::name() const
|
std::string namespace_::name() const
|
||||||
{
|
{
|
||||||
assert(size() > 0);
|
assert(size() > 0);
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
namespace clanguml::common::model {
|
namespace clanguml::common::model {
|
||||||
|
|
||||||
class namespace_ {
|
class namespace_ {
|
||||||
|
public:
|
||||||
using container_type = std::vector<std::string>;
|
using container_type = std::vector<std::string>;
|
||||||
|
|
||||||
public:
|
|
||||||
namespace_() = default;
|
namespace_() = default;
|
||||||
|
|
||||||
namespace_(const std::string &ns);
|
namespace_(const std::string &ns);
|
||||||
@@ -42,6 +42,7 @@ public:
|
|||||||
namespace_ &operator=(namespace_ &&right) noexcept = default;
|
namespace_ &operator=(namespace_ &&right) noexcept = default;
|
||||||
|
|
||||||
friend bool operator==(const namespace_ &left, const namespace_ &right);
|
friend bool operator==(const namespace_ &left, const namespace_ &right);
|
||||||
|
friend bool operator<(const namespace_ &left, const namespace_ &right);
|
||||||
|
|
||||||
namespace_(std::initializer_list<std::string> ns);
|
namespace_(std::initializer_list<std::string> ns);
|
||||||
|
|
||||||
@@ -85,4 +86,23 @@ private:
|
|||||||
container_type namespace_path_;
|
container_type namespace_path_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
|
||||||
|
template <> struct hash<clanguml::common::model::namespace_> {
|
||||||
|
std::size_t operator()(const clanguml::common::model::namespace_ &key) const
|
||||||
|
{
|
||||||
|
using clanguml::common::model::namespace_;
|
||||||
|
|
||||||
|
std::size_t seed = key.size();
|
||||||
|
for (const auto &ns : key) {
|
||||||
|
seed ^= std::hash<std::string>{}(ns) + 0x6a3712b5 + (seed << 6) +
|
||||||
|
(seed >> 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user