Commit 062c55e3 authored by zygzagZ's avatar zygzagZ

WIP

parent 37c6faa0
...@@ -163,6 +163,8 @@ public: ...@@ -163,6 +163,8 @@ public:
class Arg : public Visitable class Arg : public Visitable
{ {
public: public:
Type *type_;
PIdent *pident_;
virtual Arg *clone() const = 0; virtual Arg *clone() const = 0;
}; };
...@@ -343,8 +345,6 @@ public: ...@@ -343,8 +345,6 @@ public:
class Ar : public Arg class Ar : public Arg
{ {
public: public:
Type *type_;
PIdent *pident_;
Ar(const Ar &); Ar(const Ar &);
Ar &operator=(const Ar &); Ar &operator=(const Ar &);
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
weak_ptr<ClassInfo> klass; weak_ptr<ClassInfo> klass;
weak_ptr<Binding> binding; weak_ptr<Binding> binding;
FunctionInfo(FuncDef *expr, ClassInfoPtr klass = nullptr); FunctionInfo(FuncDef *expr, ClassInfoPtr klass = nullptr);
FunctionInfo(PIdent *ident, ClassInfoPtr klass = nullptr) : VarInfo(ident), block(NULL), klass(klass) {}; // FunctionInfo(PIdent *ident, ClassInfoPtr klass = nullptr) : VarInfo(ident), block(NULL), klass(klass) {};
}; };
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
#include "ParseError.h" #include "ParseError.h"
#include <stdexcept> #include <stdexcept>
void TypeCheck::visitProgram(Program *t) {} //abstract class
void TypeCheck::visitTopDef(TopDef *t) {} //abstract class
void TypeCheck::visitFunDef(FunDef *t) {} //abstract class
void TypeCheck::visitArg(Arg *t) {} //abstract class
void TypeCheck::visitClassDef(ClassDef *t) { void TypeCheck::visitClassDef(ClassDef *t) {
const string name = t->getName()->string_; const string name = t->getName()->string_;
ClassInfoPtr parent = NULL; ClassInfoPtr parent = NULL;
...@@ -23,14 +19,6 @@ void TypeCheck::visitClassDef(ClassDef *t) { ...@@ -23,14 +19,6 @@ void TypeCheck::visitClassDef(ClassDef *t) {
scope.currentClass = NULL; scope.currentClass = NULL;
} }
void TypeCheck::visitStmt(Stmt *t) {} //abstract class
void TypeCheck::visitItem(Item *t) {} //abstract class
void TypeCheck::visitType(Type *t) {} //abstract class
void TypeCheck::visitExpr(Expr *t) {} //abstract class
void TypeCheck::visitAddOp(AddOp *t) {} //abstract class
void TypeCheck::visitMulOp(MulOp *t) {} //abstract class
void TypeCheck::visitRelOp(RelOp *t) {} //abstract class
void TypeCheck::visitPIdent(PIdent *p_ident) void TypeCheck::visitPIdent(PIdent *p_ident)
{ {
visitString(p_ident->string_); visitString(p_ident->string_);
...@@ -63,22 +51,14 @@ void TypeCheck::visitClDef(ClDef *cl_def) ...@@ -63,22 +51,14 @@ void TypeCheck::visitClDef(ClDef *cl_def)
void TypeCheck::visitFuncDef(FuncDef *def) void TypeCheck::visitFuncDef(FuncDef *def)
{ {
FunctionInfoPtr f = make_shared<FunctionInfo>(def->pident_, scope.currentClass); FunctionInfoPtr f = make_shared<FunctionInfo>(def, scope.currentClass);
// FunctionInfo tworzy argumenty
f->block = def->block_;
auto &targetVector = scope.currentClass ? scope.currentClass->functions : scope.functions; auto &targetVector = scope.currentClass ? scope.currentClass->functions : scope.functions;
targetVector << f; targetVector << f;
} }
void TypeCheck::visitAr(Ar *ar)
{
/* Code For Ar Goes Here */
ar->type_->accept(this);
ar->pident_->accept(this);
}
void TypeCheck::visitClassDefN(ClassDefN *class_def_n) void TypeCheck::visitClassDefN(ClassDefN *class_def_n)
{ {
visitClassDef(class_def_n); visitClassDef(class_def_n);
...@@ -136,19 +116,19 @@ void TypeCheck::visitBStmt(BStmt *b_stmt) ...@@ -136,19 +116,19 @@ void TypeCheck::visitBStmt(BStmt *b_stmt)
void TypeCheck::visitDecl(Decl *decl) void TypeCheck::visitDecl(Decl *decl)
{ {
/* Code For Decl Goes Here */ Type* type = decl->type_;
decl->type_->accept(this);
for (auto el : *decl->listitem_) { for (Item * el : *decl->listitem_) {
el->pident_->accept(this);
el->expr_->accept(this); el->expr_->accept(this);
VarInfoPtr var = make_shared<VarInfo>(el->pident_, type);
scope.currentBinding.variables << var;
} }
} }
void TypeCheck::visitAss(Ass *ass) void TypeCheck::visitAss(Ass *ass)
{ {
/* Code For Ass Goes Here */ auto var = scope.currentBinding.variables[]
ass->expr_1->accept(this); ass->expr_1->accept(this);
ass->expr_2->accept(this); ass->expr_2->accept(this);
......
...@@ -23,22 +23,11 @@ public: ...@@ -23,22 +23,11 @@ public:
TypeCheck(); TypeCheck();
void check(Visitable *v); void check(Visitable *v);
protected: protected:
void visitProgram(Program *p);
void visitTopDef(TopDef *p);
void visitFunDef(FunDef *p);
void visitArg(Arg *p);
void visitClassDef(ClassDef *p); void visitClassDef(ClassDef *p);
void visitStmt(Stmt *p);
void visitType(Type *p);
void visitExpr(Expr *p);
void visitAddOp(AddOp *p);
void visitMulOp(MulOp *p);
void visitRelOp(RelOp *p);
void visitProg(Prog *p); void visitProg(Prog *p);
void visitFnDef(FnDef *p); void visitFnDef(FnDef *p);
void visitClDef(ClDef *p); void visitClDef(ClDef *p);
void visitFuncDef(FuncDef *p); void visitFuncDef(FuncDef *p);
void visitAr(Ar *p);
void visitClassDefN(ClassDefN *p); void visitClassDefN(ClassDefN *p);
void visitClassDefE(ClassDefE *p); void visitClassDefE(ClassDefE *p);
void visitClassBl(ClassBl *p); void visitClassBl(ClassBl *p);
...@@ -103,15 +92,27 @@ protected: ...@@ -103,15 +92,27 @@ protected:
// abstract // abstract
// topdefs // topdefs
void visitProgram(Program *t) {} //abstract class
void visitTopDef(TopDef *t) {} //abstract class
void visitFunDef(FunDef *t) {} //abstract class
void visitBlock(Block *t) {}; void visitBlock(Block *t) {};
void visitClassBlock(ClassBlock *p) {}; void visitClassBlock(ClassBlock *p) {};
void visitClassBlockDef(ClassBlockDef *p) {}; void visitClassBlockDef(ClassBlockDef *p) {};
void visitItem(Item *p); void visitItem(Item *p) {};
void visitArg(Arg *p) {}
void visitStmt(Stmt *p) {};
void visitType(Type *p) {};
void visitExpr(Expr *p) {};
void visitAddOp(AddOp *p) {};
void visitMulOp(MulOp *p) {};
void visitRelOp(RelOp *p) {};
// stmts // stmts
void visitEmpty(Empty *p) {}; void visitEmpty(Empty *p) {};
void visitNoInit(NoInit *p) {}; void visitNoInit(NoInit *p) {};
void visitInit(Init *p) {}; void visitInit(Init *p) {};
void visitAr(Ar *p) {};
// exprs // exprs
void visitPlus(Plus *p) {}; void visitPlus(Plus *p) {};
......
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