aboutsummaryrefslogtreecommitdiff
path: root/buildtools/codegen/CodegenInput.inl
blob: 80a39d0984ae0ad10db92d7b8b4d820456d5e8e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once

#include "CodegenConfig.hpp"
#include "CodegenDecl.hpp"

#include <Utils.hpp>

#include <robin_hood.h>
#include <cinttypes>
#include <string>
#include <vector>

class CodegenInput {
private:
	std::vector<DeclEnum> mEnums;
	robin_hood::unordered_map<std::string, size_t, StringHash, StringEqual> 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(std::string(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;
		}
	}
};