#define EXPRESSIONS_H
#include "common.h"
+#include "token.h"
#include "visitor.h"
#include <cstdint>
};
struct ThisExpr : public Expr {
- ThisExpr(int line, int column, const std::string &file)
- : Expr(line, column, file) {}
+public:
+ std::shared_ptr<const Token> keyword;
+
+ ThisExpr(int line, int column, const std::string &file, std::shared_ptr<const Token>& keyword)
+ : keyword(keyword), Expr(line, column, file) {}
+
LBPLType accept(Expression::Visitor *visitor) {
return visitor->visitThisExpr(this);
}
}
LBPLType Interpreter::visitSuperExpr(SuperExpr *) { return nullptr; }
-LBPLType Interpreter::visitThisExpr(ThisExpr *) { return nullptr; }
+LBPLType Interpreter::visitThisExpr(ThisExpr *expr) { return lookupVariable(expr->keyword, expr); }
LBPLType Interpreter::visitCallExpr(FnCallExpr *expr) {
LBPLType callee = expr->callee->accept(this);
return std::make_unique<SuperExpr>(line, col, lexer->getFilename(), field);
} else if (match(TokenType::This)) {
- return std::make_unique<ThisExpr>(line, col, lexer->getFilename());
+ return std::make_unique<ThisExpr>(line, col, lexer->getFilename(), previous);
} else if (match(TokenType::Identifier)) {
return std::make_unique<VariableExpr>(line, col, lexer->getFilename(),
previous);