-
Notifications
You must be signed in to change notification settings - Fork 0
/
Resolver.h
74 lines (68 loc) · 1.8 KB
/
Resolver.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
#pragma once
#include <vector>
#include <unordered_map>
#include "Lox.h"
#include "Expr.h"
#include "Stmt.h"
#include "Interpreter.h"
enum FunctionType
{
FunctionType_None,
FunctionType_Function,
FunctionType_Initializer,
FunctionType_Method,
FunctionType_Lambda,
};
enum ClassType
{
ClassType_None,
ClassType_Class,
ClassType_Subclass
};
struct VariableFlags
{
bool initialized;
bool referenced;
};
class Resolver
{
std::vector<std::unordered_map<std::string, VariableFlags> *> scopes;
Interpreter *interpreter;
FunctionType currentFunction;
ClassType currentClass;
void beginScope();
void endScope();
void declare(Token *name);
void define(Token *name);
void resolveLocal(Expr *expr, Token *name);
void visitAssign(Assign *expr);
void visitTernary(Ternary *expr);
void visitBinary(Binary *expr);
void visitLogical(Logical *expr);
void visitSet(Set *expr);
void visitSuper(Super *expr);
void visitThis(This *expr);
void visitGrouping(Grouping *expr);
void visitLiteral(Literal *expr);
void visitUnary(Unary *expr);
void visitVariable(Variable *expr);
void visitCall(Call *stmt);
void visitGet(Get *stmt);
void visitLambda(Lambda *stmt);
void resolve(Expr *expr);
void visitPrint(Print *stmt);
void visitExpression(Expression *stmt);
void visitVar(Var *stmt);
void visitBlock(Block *stmt);
void visitIf(If *stmt);
void visitWhile(While *stmt);
void visitBreak(Break *stmt);
void visitFunction(Function *stmt);
void visitClass(Class *stmt);
void resolveFunction(void *stmt, FunctionType type);
void visitReturn(Return *stmt);
void resolve(Stmt *stmt);
public:
Resolver(Interpreter *interpreter);
void resolve(std::vector<Stmt *> statements);
};