aboutsummaryrefslogtreecommitdiff
path: root/source/20-codegen-compiler/CodegenModel.hpp
blob: 99c345d487c4990db951253f7718b1e6f246ffff (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include "CodegenConfig.hpp"
#include "CodegenDecl.hpp"
#include "CodegenModel.hpp"
#include "CodegenUtils.hpp"

#include <sqlite3.h>
#include <cinttypes>
#include <cstdint>
#include <string>
#include <string_view>

using namespace std::literals;

class CodegenRuntimeModel {
private:
	class Private;
	Private* m;

public:
	CodegenRuntimeModel();
	~CodegenRuntimeModel();

	// Implementation detail helper, don't use outside
	Private& GetPimpl() const { return *m; }

	DeclEnum* AddEnum(std::string fullname, DeclEnum decl);
	DeclStruct* AddStruct(std::string fullname, DeclStruct decl);

	const DeclEnum* FindEnum(std::string_view name) const;
	const DeclStruct* FindStruct(std::string_view name) const;

	DeclNamespace* AddNamespace(DeclNamespace ns);

	const DeclNamespace* FindNamespace(std::string_view fullname) const;
	DeclNamespace* FindNamespace(std::string_view name);
};

class CodegenArchiveModel {
private:
	class Private;
	Private* m;

public:
	CodegenArchiveModel(std::string_view dbPath);
	~CodegenArchiveModel();

	// Implementation detail helper, don't use outside
	Private& GetPimpl() const { return *m; }

	void DeleteDeclsRelatedToFile(std::string_view filename);

	void Store(const CodegenRuntimeModel& model);
	void LoadInto(CodegenRuntimeModel& model) const;
	CodegenRuntimeModel Load() const;

	void StoreStruct(const DeclStruct& decl);
	void StoreFunction(const DeclFunction& decl);
	void StoreEnum(const DeclEnum& decl);
};