-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathASTnode.h
More file actions
107 lines (82 loc) · 2.14 KB
/
ASTnode.h
File metadata and controls
107 lines (82 loc) · 2.14 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef ASTNODE_H
#define ASTNODE_H
#include<llvm/IR/Value.h>
#include<vector>
#include<string>
#define EXCEPT_MSG_RET(except, msg, ret) if(!(except)) {errmsg = msg; return ret;}
#define EXCEPT_RET(except, ret) if(!(except)) {return ret;}
class ASTnode;
struct CodegenContext;
extern ASTnode* rootNode;
extern std::string errmsg;
#define __C_NEW_ASTNODE(name) class name : public ASTnode { \
public: \
name(std::string kind = "", std::string spelling = "", std::string type = "") \
: ASTnode(kind, spelling, type){} \
~name() {} \
llvm::Value* CodeGen(CodegenContext &context) override;
#define __C_ASTNODE_END };
class ASTnode
{
public:
std::vector<ASTnode*> sons;
std::string spelling;
std::string kind;
std::string type;
int line, column;
public:
ASTnode(std::string kind = "", std::string spelling = "", std::string type = "");
~ASTnode() {};
void AddSon(ASTnode* son);
void SetKind(std::string s);
void SetSpelling(std::string s);
void SetType(std::string s);
void SetPos(int l, int c);
std::string DumpPos();
void Traverse(int intend);
void MaintainType() {
for(auto son : sons) {
son->SetType(type);
}
}
virtual llvm::Value* CodeGen(CodegenContext &context) {
EXCEPT_MSG_RET(0, "Abstract node codegen, wtf?", nullptr);
};
};
__C_NEW_ASTNODE(BinaryNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(StmtsNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(VardeclNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(VardefNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(LiteralNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(DeclrefNode)
public:
bool isL;
__C_ASTNODE_END
__C_NEW_ASTNODE(UnaryNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(CompstmtNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(FunctionDeclNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(CallNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(ReturnNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(IfStmtNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(WhileNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(ArrayDefNode);
__C_ASTNODE_END
__C_NEW_ASTNODE(ArrayDimNode)
public:
std::vector<llvm::Value*> dims;
__C_ASTNODE_END
__C_NEW_ASTNODE(ForNode);
__C_ASTNODE_END
#endif