Commit c7ae29b0 authored by zygzagZ's avatar zygzagZ

POC

parent 5f84c1c3
......@@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include "Absyn.h"
#include "Info.h"
/******************** PIdent ********************/
PIdent::PIdent(String p1, Integer p2)
......@@ -1421,13 +1422,11 @@ Array *Array::clone() const
ClassT::ClassT(PIdent *p1)
{
pident_ = p1;
}
ClassT::ClassT(const ClassT & other)
{
pident_ = other.pident_->clone();
}
ClassT &ClassT::operator=(const ClassT & other)
......@@ -1440,7 +1439,7 @@ ClassT &ClassT::operator=(const ClassT & other)
void ClassT::swap(ClassT & other)
{
std::swap(pident_, other.pident_);
std::swap(binding, other.binding);
}
ClassT::~ClassT()
......@@ -2895,6 +2894,18 @@ bool Fun::isEqual(Type const *other) const {
if (*type_ != *casted->type_ || listtype_->size() != casted->listtype_->size()) {
return false;
}
// TODO: czy sprawdzać argumenty?
}
return false;
}
bool ClassT::isEqual(Type const *other) const {
if (const ClassT* casted = dynamic_cast<const ClassT*>(other)) {
BindingPtr ba = binding.lock(), bb = casted->binding.lock();
if (!ba || !bb) {
throw std::runtime_error("Binding nie znaleziony na typie klasy!");
}
return ba->classes[pident_] == bb->classes[pident_];
}
return false;
}
......@@ -223,6 +223,8 @@ public:
class Type : public Visitable
{
public:
// Type() {};
// Type(const &Type other) : binding(other.binding) {};
std::weak_ptr<Binding> binding;
virtual Type *clone() const = 0;
virtual std::string printName() const = 0;
......@@ -741,11 +743,8 @@ public:
virtual void accept(Visitor *v);
virtual ClassT *clone() const;
void swap(ClassT &);
std::string printName() const { return "class"; }
bool isEqual(Type const *other) const {
// TODO: implement ClassT comparison
return false;
}
std::string printName() const { return "class " + pident_->string_; }
bool isEqual(Type const *other) const;
};
class Fun : public Type
......
#include "Info.h"
FunctionInfo::FunctionInfo(FuncDef *expr, ClassInfoPtr klass)
: VarInfo(expr->pident_, expr->type_), block(expr->block_), klass(klass)
: VarInfo(expr->pident_, nullptr), block(expr->block_), klass(klass)
{
// TODO: tutaj leakujemy listtype
ListType *funArgs = new ListType();
type = make_shared<Fun>(expr->type_, funArgs);
arguments.reserve(expr->listarg_->size());
for (auto arg : *expr->listarg_) {
arguments.emplace_back(make_shared<VarInfo>((Ar*)arg));
funArgs->emplace_back(arg->type_);
}
}
......
......@@ -4,6 +4,7 @@
#include "Info.h"
#include "ParseError.h"
#include "TypeDefs.h"
#include <iostream>
template<typename T>
struct Compare
......
......@@ -27,6 +27,7 @@ ParseError::ParseError(string reason, Visitable *expr) : runtime_error("ParseErr
if (expr) {
ss << " Expression: " << PrintAbsyn().print(expr);
}
msg = ss.str();
}
RedefinedError::RedefinedError(PIdent *ident, VarInfoPtr orig) {
......
This diff is collapsed.
......@@ -21,7 +21,9 @@ class TypeCheck : public Visitor
void checkFunction(FunctionInfoPtr f);
void checkReturnStatement(shared_ptr<Type> type, Stmt *stmt);
void checkFunctionRet();
void setupEnv();
public:
BindingPtr getParentBinding() const { return scope->currentClass ? static_pointer_cast<Binding>(scope->currentClass) : static_pointer_cast<Binding>(scope); }
TypeCheck();
void check(Visitable *v);
protected:
......
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