Repository navigation
Expand file tree
/
Copy pathTSEmitter.h
More file actions
78 lines (59 loc) · 1.66 KB
/
Copy pathTSEmitter.h
File metadata and controls
78 lines (59 loc) · 1.66 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include "IR.h"
#include "MetadataWriter.h"
#include "Util.h"
#include <algorithm>
#include <assert.h>
#include <clang-c/Index.h>
#include <filesystem>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace metagen {
class TSLines {
public:
TSLines() {}
void write(std::string value);
void newline();
void enter();
void exit();
std::vector<std::string> lines;
int indentLevel = 0;
};
class TSFile {
public:
TSFile() {}
TSFile(std::string name, MetadataFactory *factory)
: factory(factory), name(name) {}
std::string typeToString(TypeSpec &type, bool isStatic, bool isReturn);
void write(VariableDecl &decl);
void write(EnumDecl &decl);
void write(StructDecl &decl);
void write(UnionDecl &decl);
void write(FunctionDecl &decl);
void write(MemberDecl &decl, bool isInterface = false,
std::vector<std::string> *classTypeParameters = nullptr);
void write(ProtocolDecl &decl);
void write(ClassDecl &decl);
std::string toString();
inline void import(std::string module) { imports.insert(module); }
MetadataFactory *factory = nullptr;
std::string name;
std::unordered_set<std::string> imports;
TSLines code;
std::unordered_set<std::string> classReferences;
std::unordered_set<std::string> protocolReferences;
};
class TSEmitter {
public:
TSEmitter(MetadataFactory &factory, std::string outDir)
: outDir(outDir), factory(factory) {}
void resolveImports(TSFile &file);
void ensureFile(std::string framework);
void write();
std::string outDir;
std::unordered_map<std::string, TSFile> files;
MetadataFactory &factory;
};
} // namespace metagen