-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTSEmitter.h
More file actions
85 lines (65 loc) · 1.9 KB
/
Copy pathTSEmitter.h
File metadata and controls
85 lines (65 loc) · 1.9 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
79
80
81
82
83
84
85
#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(const 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(const 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(const 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:
struct Options {
Options() : indexMode("all") {}
std::string indexMode; // all | frameworks-list
std::vector<std::string> indexFrameworks;
};
TSEmitter(MetadataFactory &factory, std::string outDir, Options options = {})
: outDir(outDir), factory(factory), options(options) {}
void resolveImports(TSFile &file);
TSFile& ensureFile(const std::string& framework);
void write();
std::string outDir;
std::unordered_map<std::string, TSFile> files;
MetadataFactory &factory;
Options options;
};
} // namespace metagen