Commit 062c55e3 authored by zygzagZ's avatar zygzagZ

WIP

parent 37c6faa0
......@@ -163,6 +163,8 @@ public:
class Arg : public Visitable
{
public:
Type *type_;
PIdent *pident_;
virtual Arg *clone() const = 0;
};
......@@ -343,8 +345,6 @@ public:
class Ar : public Arg
{
public:
Type *type_;
PIdent *pident_;
Ar(const Ar &);
Ar &operator=(const Ar &);
......
......@@ -31,7 +31,7 @@ public:
weak_ptr<ClassInfo> klass;
weak_ptr<Binding> binding;
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 @@
#include "ParseError.h"
#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) {
const string name = t->getName()->string_;
ClassInfoPtr parent = NULL;
......@@ -23,14 +19,6 @@ void TypeCheck::visitClassDef(ClassDef *t) {
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)
{
visitString(p_ident->string_);
......@@ -63,22 +51,14 @@ void TypeCheck::visitClDef(ClDef *cl_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;
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)
{
visitClassDef(class_def_n);
......@@ -136,19 +116,19 @@ void TypeCheck::visitBStmt(BStmt *b_stmt)
void TypeCheck::visitDecl(Decl *decl)
{
/* Code For Decl Goes Here */
decl->type_->accept(this);
Type* type = decl->type_;
for (auto el : *decl->listitem_) {
el->pident_->accept(this);
for (Item * el : *decl->listitem_) {
el->expr_->accept(this);
VarInfoPtr var = make_shared<VarInfo>(el->pident_, type);
scope.currentBinding.variables << var;
}
}
void TypeCheck::visitAss(Ass *ass)
{
/* Code For Ass Goes Here */
auto var = scope.currentBinding.variables[]
ass->expr_1->accept(this);
ass->expr_2->accept(this);
......
......@@ -23,22 +23,11 @@ public:
TypeCheck();
void check(Visitable *v);
protected:
void visitProgram(Program *p);
void visitTopDef(TopDef *p);
void visitFunDef(FunDef *p);
void visitArg(Arg *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 visitFnDef(FnDef *p);
void visitClDef(ClDef *p);
void visitFuncDef(FuncDef *p);
void visitAr(Ar *p);
void visitClassDefN(ClassDefN *p);
void visitClassDefE(ClassDefE *p);
void visitClassBl(ClassBl *p);
......@@ -103,15 +92,27 @@ protected:
// abstract
// topdefs
void visitProgram(Program *t) {} //abstract class
void visitTopDef(TopDef *t) {} //abstract class
void visitFunDef(FunDef *t) {} //abstract class
void visitBlock(Block *t) {};
void visitClassBlock(ClassBlock *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
void visitEmpty(Empty *p) {};
void visitNoInit(NoInit *p) {};
void visitInit(Init *p) {};
void visitAr(Ar *p) {};
// exprs
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