2012-12-10 08:43:16 +00:00
|
|
|
/*
|
|
|
|
* WhileNode.cpp
|
|
|
|
*
|
|
|
|
* Created on: Dec 10, 2012
|
|
|
|
* Author: attero
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "WhileNode.h"
|
|
|
|
|
2012-12-28 16:39:43 +00:00
|
|
|
WhileNode::WhileNode(ASTExpression * condition, ASTStatement * body):
|
|
|
|
body(body)
|
|
|
|
{
|
|
|
|
type = "WhileNode";
|
|
|
|
children.push_back(condition);
|
2012-12-10 08:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WhileNode::~WhileNode() {
|
2012-12-17 08:25:58 +00:00
|
|
|
delete body;
|
|
|
|
for(auto it = children.begin(); it != children.end(); )
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
it = children.erase(it);
|
|
|
|
}
|
2012-12-10 08:43:16 +00:00
|
|
|
}
|
|
|
|
|
2012-12-10 11:37:29 +00:00
|
|
|
|
2012-12-31 16:10:37 +00:00
|
|
|
SenchaObject WhileNode::execute()
|
2012-12-10 11:37:29 +00:00
|
|
|
{
|
|
|
|
while(evaluate_condition())
|
|
|
|
{
|
|
|
|
body->execute();
|
|
|
|
}
|
2012-12-31 16:10:37 +00:00
|
|
|
return SenchaObject();
|
2012-12-10 11:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WhileNode::evaluate_condition()
|
|
|
|
{
|
|
|
|
auto condition = static_cast<ASTExpression * >(children[0])->evaluate();
|
|
|
|
return condition.is_true();
|
|
|
|
}
|