diff --git a/include/ast/Node.h b/include/ast/Node.h index 0aace72cff5228c65217726ecebdb2e4bdf12a4f..b6e901aa134bc58ff3043b7e9953e466c444e986 100644 --- a/include/ast/Node.h +++ b/include/ast/Node.h @@ -48,8 +48,7 @@ public: SourceLocation get_location() const; protected: - SourceLocation location; ///< Source location where this node appears in the code - mutable Node* cached_eval{nullptr}; ///< Cached evaluation result + SourceLocation location; ///< Source location where this node appears in the code }; } // namespace funk diff --git a/source/ast/BlockNode.cc b/source/ast/BlockNode.cc index 8893c999e0fdfa49bcf76090875e9eba1d5bc689..c8cd698331cf1b5eb434281f7fcd9d601d708774 100644 --- a/source/ast/BlockNode.cc +++ b/source/ast/BlockNode.cc @@ -21,11 +21,9 @@ Vector<Node*> BlockNode::get_statements() const Node* BlockNode::evaluate() const { - if (cached_eval) { return cached_eval; } - Node* result{}; for (Node* statement : statements) { result = statement->evaluate(); } - return cached_eval = result; + return result; } String BlockNode::to_s() const diff --git a/source/ast/expression/BinaryOpNode.cc b/source/ast/expression/BinaryOpNode.cc index abe6cd1a9f5fa79cff142e612ba500c019f3bda8..a19bdc46ebc2b8dd58e38ccefab3e2bb516f683e 100644 --- a/source/ast/expression/BinaryOpNode.cc +++ b/source/ast/expression/BinaryOpNode.cc @@ -16,8 +16,6 @@ BinaryOpNode::~BinaryOpNode() Node* BinaryOpNode::evaluate() const { - if (cached_eval) { return cached_eval; } - NodeValue left_value{left->get_value()}; NodeValue right_value{right->get_value()}; @@ -53,7 +51,7 @@ Node* BinaryOpNode::evaluate() const throw RuntimeError(location, e.what()); } - return cached_eval = new LiteralNode(location, result); + return new LiteralNode(location, result); } String BinaryOpNode::to_s() const diff --git a/source/ast/expression/LiteralNode.cc b/source/ast/expression/LiteralNode.cc index f14a553e5700800fb99614943fc46afffb63f387..9a074def7f4285cbfe16d3add0ed7f1203064d44 100644 --- a/source/ast/expression/LiteralNode.cc +++ b/source/ast/expression/LiteralNode.cc @@ -7,8 +7,7 @@ LiteralNode::LiteralNode(const SourceLocation& loc, NodeValue value) : Expressio Node* LiteralNode::evaluate() const { - if (cached_eval) { return cached_eval; } - return cached_eval = const_cast<LiteralNode*>(this); + return const_cast<LiteralNode*>(this); } String LiteralNode::to_s() const diff --git a/source/ast/expression/UnaryOpNode.cc b/source/ast/expression/UnaryOpNode.cc index 60dcdb82825e29ad1301038e92885fb269872048..05d69dfc82ecde8fa7d246d8940f0f00b83b0732 100644 --- a/source/ast/expression/UnaryOpNode.cc +++ b/source/ast/expression/UnaryOpNode.cc @@ -15,8 +15,6 @@ UnaryOpNode::~UnaryOpNode() Node* UnaryOpNode::evaluate() const { - if (cached_eval) { return cached_eval; } - NodeValue expr_value{expr->get_value()}; NodeValue result{}; @@ -38,7 +36,7 @@ Node* UnaryOpNode::evaluate() const throw RuntimeError(location, e.what()); } - return cached_eval = new LiteralNode(location, result); + return new LiteralNode(location, result); } String UnaryOpNode::to_s() const