/*
 * ProgramNode.cpp
 *
 *  Created on: Nov 5, 2012
 *      Author: attero
 */

#include "ProgramNode.h"

ProgramNode::ProgramNode() {
	//Do nothing
	this->type = "ProgramNode";
}

ProgramNode::~ProgramNode() {
	for(auto it = children.begin(); it != children.end(); )
	{
		delete *it;
		it = children.erase(it);
	}
}

SenchaObject ProgramNode::execute() {
	for (std::vector<ASTNode *>::iterator it = children.begin(); it!= children.end()-1; ++it) {
		(*it)->execute();
	}
	return children[children.size() -1]->execute();
}

void ProgramNode::accept(Visitor * visitor)
{
	visitor->visit(this);
}

SenchaObject ProgramNode::execute_last()
{
	return children[children.size() - 1]->execute();
}

SenchaObject ProgramNode::evaluate_last()
{

	SenchaObject result = (children[children.size() - 1])->evaluate();
	return result;
}

void ProgramNode::add_statement(ASTStatement * statement)
{
	children.push_back(statement);
}

