summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/AST/WhileNode.cpp
blob: 6cabda08ce8d2b03604d43603971df45e07d3a15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * 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();
}