-
Notifications
You must be signed in to change notification settings - Fork 1
/
type_check.h
81 lines (76 loc) · 2.14 KB
/
type_check.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef LATTE_TYPE_CHECK_H
#define LATTE_TYPE_CHECK_H
#include "functions_types.h"
#include <iostream>
/*
* Class performing type check on given program. Requires functions'
* signatures to be known before.
* */
namespace latte_type_check
{
class TypeCheck : public Visitor
{
public:
TypeCheck(FunTypesEnv const& _funEnv) : funEnv(_funEnv) {}
void visitPProg(PProg* p);
void visitTFnDef(TFnDef* p);
void visitAArg(AArg* p);
void visitBBlock(BBlock* p);
void visitSEmpty(SEmpty* p);
void visitSBStmt(SBStmt* p);
void visitSDecl(SDecl* p);
void visitINoInit(INoInit* p);
void visitIInit(IInit* p);
void visitSAss(SAss* p);
void visitSIncr(SIncr* p);
void visitSDecr(SDecr* p);
void visitSRet(SRet* p);
void visitSVRet(SVRet* p);
void visitSCond(SCond* p);
void visitSCondElse(SCondElse* p);
void visitSWhile(SWhile* p);
void visitSSExp(SSExp* p);
void visitTInt(TInt* p);
void visitTStr(TStr* p);
void visitTBool(TBool* p);
void visitTVoid(TVoid* p);
void visitEVar(EVar* p);
void visitELitInt(ELitInt* p);
void visitELitTrue(ELitTrue* p);
void visitELitFalse(ELitFalse* p);
void visitEApp(EApp* p);
void visitEString(EString* p);
void visitENeg(ENeg* p);
void visitENot(ENot* p);
void visitEMul(EMul* p);
void visitEAdd(EAdd* p);
void visitERel(ERel* p);
void visitEAnd(EAnd* p);
void visitEOr(EOr* p);
void visitOPlus(OPlus* p);
void visitOMinus(OMinus* p);
void visitListTopDef(ListTopDef* p);
void visitListArg(ListArg* p);
void visitListStmt(ListStmt* p);
void visitListItem(ListItem* p);
void visitListExpr(ListExpr* p);
void visitIdent(Ident x);
Errors const& getErrors();
private:
void expectType(LatteType const& t);
void compareTypes(LatteType const& t1, LatteType const& t2);
private:
FunTypesEnv funEnv;
Environment<std::shared_ptr<LatteType>> typeEnv;
Errors err;
int lastLineNumber;
std::shared_ptr<Ident> lastIdent;
std::shared_ptr<LatteType> declType;
std::shared_ptr<LatteType> lastType;
std::shared_ptr<Ident> funcName;
std::shared_ptr<LatteType> returnType;
AddOp* lastAddOp;
std::vector<std::shared_ptr<LatteType>> expectedArgsType;
};
}
#endif