Skip to content
Snippets Groups Projects
Commit 5917f2f5 authored by Mattias Ajander's avatar Mattias Ajander
Browse files

Changed include path, moved ProgramNode to BlockNode to be used later.

parent d64e4143
No related branches found
No related tags found
No related merge requests found
#pragma once #pragma once
#include "ast/Node.h" #include "ast/Node.h"
namespace funk namespace funk
{ {
class ProgramNode : public Node
class BlockNode : public Node
{ {
public: public:
ProgramNode(const SourceLocation& loc); BlockNode(const SourceLocation& loc);
~ProgramNode(); ~BlockNode();
void add(Node* statement); void add(Node* statement);
Vector<Node*> get_statements() const;
Node* evaluate() const override; Node* evaluate() const override;
String to_s() const override; String to_s() const override;
...@@ -17,4 +20,5 @@ public: ...@@ -17,4 +20,5 @@ public:
private: private:
Vector<Node*> statements; Vector<Node*> statements;
}; };
} // namespace funk } // namespace funk
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "token/Token.h" #include "token/Token.h"
#include "utils/Common.h" #include "utils/Common.h"
#include "ast/BinaryOpNode.h" #include "ast/BlockNode.h"
#include "ast/LiteralNode.h"
#include "ast/Node.h" #include "ast/Node.h"
#include "ast/ProgramNode.h" #include "ast/expression/BinaryOpNode.h"
#include "ast/UnaryOpNode.h" #include "ast/expression/LiteralNode.h"
#include "ast/expression/UnaryOpNode.h"
namespace funk namespace funk
{ {
......
#include "ast/ProgramNode.h" #include "ast/BlockNode.h"
namespace funk namespace funk
{ {
ProgramNode::ProgramNode(const SourceLocation& loc) : Node(loc), statements{} {} BlockNode::BlockNode(const SourceLocation& loc) : Node(loc), statements{} {}
ProgramNode::~ProgramNode() BlockNode::~BlockNode()
{ {
for (Node* statement : statements) { delete statement; } for (Node* statement : statements) { delete statement; }
} }
void ProgramNode::add(Node* statement) void BlockNode::add(Node* statement)
{ {
statements.push_back(statement); statements.push_back(statement);
} }
Node* ProgramNode::evaluate() const Vector<Node*> BlockNode::get_statements() const
{
return statements;
}
Node* BlockNode::evaluate() const
{ {
if (cached_eval) { return cached_eval; } if (cached_eval) { return cached_eval; }
...@@ -23,7 +28,7 @@ Node* ProgramNode::evaluate() const ...@@ -23,7 +28,7 @@ Node* ProgramNode::evaluate() const
return cached_eval = result; return cached_eval = result;
} }
String ProgramNode::to_s() const String BlockNode::to_s() const
{ {
String repr{}; String repr{};
......
...@@ -11,9 +11,9 @@ Node* Parser::parse() ...@@ -11,9 +11,9 @@ Node* Parser::parse()
{ {
LOG_DEBUG("Parse program"); LOG_DEBUG("Parse program");
ProgramNode* program = new ProgramNode(SourceLocation(filename, 0, 0)); BlockNode* block = new BlockNode(SourceLocation(filename, 0, 0));
while (!done()) { program->add(parse_statement()); } while (!done()) { block->add(parse_statement()); }
return program; return block;
} }
Parser Parser::load(String filename) Parser Parser::load(String filename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment