Commit 519005ca authored by zygzagZ's avatar zygzagZ

Eager class names fetching

parent 067f6adb
...@@ -21,10 +21,7 @@ void TypeCheck::visitClassDef(ClassDef *t) { ...@@ -21,10 +21,7 @@ void TypeCheck::visitClassDef(ClassDef *t) {
t->getName()->var = c; t->getName()->var = c;
scope->classes << c; scope->classes << c;
scope->currentBinding = scope->currentClass = c; classDefs.emplace_back(c, t);
t->getBlock()->accept(this);
scope->currentClass = nullptr;
scope->currentBinding = scope;
} }
void TypeCheck::visitPIdent(PIdent *p_ident) void TypeCheck::visitPIdent(PIdent *p_ident)
...@@ -564,8 +561,20 @@ void TypeCheck::check(Visitable *v) ...@@ -564,8 +561,20 @@ void TypeCheck::check(Visitable *v)
scope->currentBinding = scope; scope->currentBinding = scope;
// najpierw zebranie nazw klas
v->accept(this); v->accept(this);
// teraz bloki klas jak juz znamy wszystkie istniejace klasy
for (auto p : classDefs) {
scope->currentBinding = scope->currentClass = p.first;
p.second->getBlock()->accept(this);
scope->currentClass = nullptr;
scope->currentBinding = scope;
}
classDefs.clear();
// a teraz mozna funkcje w klasach
for (auto c : scope->classes) { for (auto c : scope->classes) {
scope->currentClass = c; scope->currentClass = c;
try { try {
......
...@@ -20,6 +20,8 @@ class TypeCheck : public Visitor ...@@ -20,6 +20,8 @@ class TypeCheck : public Visitor
shared_ptr<Type> lastType, returnType; shared_ptr<Type> lastType, returnType;
set<int> posv; set<int> posv;
vector<pair<ClassInfoPtr, ClassDef*>> classDefs;
void checkFunction(FunctionInfoPtr f); void checkFunction(FunctionInfoPtr f);
void checkReturnStatement(shared_ptr<Type> type, Stmt *stmt); void checkReturnStatement(shared_ptr<Type> type, Stmt *stmt);
void checkFunctionRet(); void checkFunctionRet();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment