/*
 * WhileNode.cpp
 *
 *  Created on: Dec 10, 2012
 *      Author: attero
 */

#include "WhileNode.h"

WhileNode::WhileNode(ASTExpression * condition, ASTStatement * body):
	body(body)
{
	type = "WhileNode";
	children.push_back(condition);
}

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


SenchaObject WhileNode::execute()
{
	while(evaluate_condition())
	{
		body->execute();
	}
	return SenchaObject();
}

bool WhileNode::evaluate_condition()
{
	auto condition = static_cast<ASTExpression * >(children[0])->evaluate();
		return condition.is_true();
}
