-
Notifications
You must be signed in to change notification settings - Fork 3
/
sema.h
59 lines (51 loc) · 3.06 KB
/
sema.h
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
#pragma once
#include "scope.h"
#include "ast.h"
#include "diag_engine.h"
#include <stack>
class Sema {
public:
enum class Mode {
Normal,
Skip
};
private:
DiagEngine &diagEngine;
public:
Sema(DiagEngine &diagEngine):diagEngine(diagEngine) {
modeStack.push(Mode::Normal);
}
std::shared_ptr<AstNode> SemaVariableDeclNode(Token tok, std::shared_ptr<CType> ty, bool isGlobal);
std::shared_ptr<AstNode> SemaVariableAccessNode(Token tok);
std::shared_ptr<AstNode> SemaNumberExprNode(Token tok, int val, std::shared_ptr<CType> ty);
std::shared_ptr<AstNode> SemaNumberExprNode(Token tok, std::shared_ptr<CType> ty);
std::shared_ptr<AstNode> SemaStringExprNode(Token tok, std::string val, std::shared_ptr<CType> ty);
std::shared_ptr<AstNode> SemaBinaryExprNode( std::shared_ptr<AstNode> left,std::shared_ptr<AstNode> right, BinaryOp op, Token tok);
std::shared_ptr<AstNode> SemaCastExprNode( std::shared_ptr<CType> targetType, std::shared_ptr<AstNode> node, Token tok);
std::shared_ptr<AstNode> SemaUnaryExprNode( std::shared_ptr<AstNode> unary, UnaryOp op, Token tok);
std::shared_ptr<AstNode> SemaThreeExprNode( std::shared_ptr<AstNode> cond,std::shared_ptr<AstNode> then, std::shared_ptr<AstNode> els, Token tok);
std::shared_ptr<AstNode> SemaSizeofExprNode( std::shared_ptr<AstNode> unary,std::shared_ptr<CType> ty);
std::shared_ptr<AstNode> SemaPostIncExprNode( std::shared_ptr<AstNode> left, Token tok);
std::shared_ptr<AstNode> SemaPostDecExprNode( std::shared_ptr<AstNode> left, Token tok);
std::shared_ptr<AstNode> SemaPostSubscriptNode(std::shared_ptr<AstNode> left, std::shared_ptr<AstNode> node, Token tok);
std::shared_ptr<AstNode> SemaPostMemberDotNode(std::shared_ptr<AstNode> left, Token iden, Token dotTok);
std::shared_ptr<AstNode> SemaPostMemberArrowNode(std::shared_ptr<AstNode> left, Token iden, Token arrowTok);
std::shared_ptr<VariableDecl::InitValue> SemaDeclInitValue(std::shared_ptr<CType> declType, std::shared_ptr<AstNode> value, std::vector<int> &offsetList, Token tok);
std::shared_ptr<AstNode> SemaIfStmtNode(std::shared_ptr<AstNode> condNode, std::shared_ptr<AstNode> thenNode, std::shared_ptr<AstNode> elseNode);
std::shared_ptr<CType> SemaTagAccess(Token tok);
std::shared_ptr<CType> SemaTagDecl(Token tok, const std::vector<Member> &members, TagKind tagKind);
std::shared_ptr<CType> SemaTagDecl(Token tok, std::shared_ptr<CType> type);
std::shared_ptr<CType> SemaAnonyTagDecl(const std::vector<Member> &members, TagKind tagKind);
std::shared_ptr<AstNode> SemaFuncDecl(Token tok, std::shared_ptr<CType> type, std::shared_ptr<AstNode> blockStmt);
std::shared_ptr<AstNode> SemaFuncCall(std::shared_ptr<AstNode> left, const std::vector<std::shared_ptr<AstNode>> &args);
void SemaTypedefDecl(std::shared_ptr<CType> type, Token tok);
std::shared_ptr<CType> SemaTypedefAccess(Token tok);
void EnterScope();
void ExitScope();
void SetMode(Mode mode);
void UnSetMode();
private:
Scope scope;
std::stack<Mode> modeStack;
Mode GetMode();
};