-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDecl.cpp
More file actions
69 lines (62 loc) · 1.24 KB
/
Copy pathDecl.cpp
File metadata and controls
69 lines (62 loc) · 1.24 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
/**
* @file Decl.cpp
* 描述Decl及其子类转换为Json格式的方式
**/
#include "Decl.h"
#include <iostream>
using namespace AST;
json TranslationUnitDecl::toJson() const
{
json res = {
{"kind","TranslationUnitDecl"}
};
if (!decls.empty())
{
res["inner"] = json::array();
for (const auto& u : decls)
{
res["inner"].emplace_back(u->toJson());
}
}
return res;
}
Value* AST::TranslationUnitDecl::genCode(CodeGeneratorBase& generator) const
{
for (const auto& decl : decls)
{
decl->genCode(generator);
}
return nullptr;
}
json VarDecl::toJson() const
{
json res={
{"kind", "VarDecl"},
{"name", name},
{"type", type},
{"hasInit", hasInit}
};
if (hasInit)
{
res["inner"] = json::array({ initValue->toJson() });
}
return res;
}
Value* AST::VarDecl::genCode(CodeGeneratorBase& generator) const
{
return generator.gen(*this);
}
json ParmVarDecl::toJson() const
{
json res = {
{"kind", "ParmVarDecl"},
{"name", name},
{"type", type},
{"hasDefault", hasInit}
};
if (hasInit)
{
res["inner"] = json::array({ initValue->toJson() });
}
return res;
}