aboutsummaryrefslogtreecommitdiff
path: root/buildtools/codegen/CodegenInput.inl
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-05-30 15:52:19 -0700
committerrtk0c <[email protected]>2022-05-30 15:52:19 -0700
commit7d8bca09b3c4bf1418e758bd3bd0d6f85672153e (patch)
treef6e411e1ec949187889d268f2993e38cddb74d53 /buildtools/codegen/CodegenInput.inl
parentce9559e8c2b69d46cff064241bd9a04c014af44f (diff)
Changeset: 52 Add support for namespaced enums
Diffstat (limited to 'buildtools/codegen/CodegenInput.inl')
-rw-r--r--buildtools/codegen/CodegenInput.inl35
1 files changed, 32 insertions, 3 deletions
diff --git a/buildtools/codegen/CodegenInput.inl b/buildtools/codegen/CodegenInput.inl
index 80a39d0..0809e7f 100644
--- a/buildtools/codegen/CodegenInput.inl
+++ b/buildtools/codegen/CodegenInput.inl
@@ -3,20 +3,26 @@
#include "CodegenConfig.hpp"
#include "CodegenDecl.hpp"
+#include "CodegenUtils.inl"
+
#include <Utils.hpp>
#include <robin_hood.h>
#include <cinttypes>
#include <string>
+#include <string_view>
#include <vector>
+using namespace std::literals;
+
class CodegenInput {
private:
std::vector<DeclEnum> mEnums;
- robin_hood::unordered_map<std::string, size_t, StringHash, StringEqual> mDeclByName;
+ robin_hood::unordered_flat_map<std::string, size_t, StringHash, StringEqual> mDeclByName;
+ robin_hood::unordered_node_map<std::string, DeclNamespace, StringHash, StringEqual> mNamespaces;
public:
- void AddEnum(DeclEnum decl) {
+ void AddEnum(std::string fullname, DeclEnum decl) {
#if CODEGEN_DEBUG_PRINT
printf("Committed enum '%s'\n", decl.name.c_str());
for (auto& elm : decl.elements) {
@@ -24,10 +30,20 @@ public:
}
#endif
- mDeclByName.try_emplace(std::string(decl.name), mEnums.size());
+ mDeclByName.try_emplace(std::move(fullname), mEnums.size());
mEnums.push_back(std::move(decl));
}
+ DeclNamespace* AddNamespace(DeclNamespace ns) {
+ auto path = Utils::MakeFullName(""sv, &ns);
+ auto [iter, success] = mNamespaces.try_emplace(std::move(path), std::move(ns));
+ auto& nsRef = iter->second;
+ if (success) {
+ nsRef.fullname = iter->first;
+ }
+ return &nsRef;
+ }
+
const DeclEnum* FindEnumByName(std::string_view name) const {
// TODO handle multiple kinds of decl
auto iter = mDeclByName.find(name);
@@ -37,4 +53,17 @@ public:
return nullptr;
}
}
+
+ const DeclNamespace* FindNamespace(std::string_view fullname) const {
+ auto iter = mNamespaces.find(fullname);
+ if (iter != mNamespaces.end()) {
+ return &iter->second;
+ } else {
+ return nullptr;
+ }
+ }
+
+ DeclNamespace* FindNamespace(std::string_view name) {
+ return const_cast<DeclNamespace*>(const_cast<const CodegenInput*>(this)->FindNamespace(name));
+ }
};