From 1a6f1ea3b76c3ed4cad5aba5502af390ce50a2c0 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 28 May 2022 20:52:42 -0700 Subject: Changeset: 42 Change codegen input parsing to lookahead based; lookup table infra; input/output decl infra --- buildtools/codegen/CodegenInput.inl | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 buildtools/codegen/CodegenInput.inl (limited to 'buildtools/codegen/CodegenInput.inl') diff --git a/buildtools/codegen/CodegenInput.inl b/buildtools/codegen/CodegenInput.inl new file mode 100644 index 0000000..9fae43c --- /dev/null +++ b/buildtools/codegen/CodegenInput.inl @@ -0,0 +1,40 @@ +#pragma once + +#include "CodegenConfig.hpp" +#include "CodegenDecl.hpp" + +#include + +#include +#include +#include +#include + +class CodegenInput { +private: + std::vector mEnums; + robin_hood::unordered_map mDeclByName; + +public: + void AddEnum(DeclEnum decl) { +#if CODEGEN_DEBUG_PRINT + printf("Committed enum '%s'\n", decl.name.c_str()); + for (auto& elm : decl.elements) { + printf(" - element %s = %" PRId64 "\n", elm.name.c_str(), elm.value); + } +#endif + + mDeclByName.try_emplace(decl.name, mEnums.size()); + mEnums.push_back(std::move(decl)); + } + + const DeclEnum* FindEnumByName(std::string_view name) const { + // TODO handle multiple kinds of decl + auto iter = mDeclByName.find(name); + if (iter != mDeclByName.end()) { + return &mEnums[iter->second]; + } else { + return nullptr; + } + } +}; -- cgit v1.2.3-70-g09d2