2012-12-03 22:40:47 +00:00
|
|
|
/*
|
|
|
|
* IfNode.cpp
|
|
|
|
*
|
|
|
|
* Created on: Nov 18, 2012
|
|
|
|
* Author: attero
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IfNode.h"
|
|
|
|
|
|
|
|
|
2012-12-28 10:01:48 +00:00
|
|
|
IfNode::IfNode() {
|
2012-12-09 16:42:13 +00:00
|
|
|
is_else = false;
|
2012-12-22 10:06:55 +00:00
|
|
|
this->type = "IfNode";
|
2012-12-09 16:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IfNode::evaluate_condition()
|
|
|
|
{
|
|
|
|
auto condition = static_cast<ASTExpression * >(children[0])->evaluate();
|
|
|
|
return condition.is_true();
|
2012-12-03 22:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IfNode::~IfNode() {
|
2012-12-17 08:25:58 +00:00
|
|
|
for(auto it = children.begin(); it != children.end(); )
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
it = children.erase(it);
|
|
|
|
}
|
2012-12-03 22:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IfNode::add_condition(ASTExpression * expression)
|
|
|
|
{
|
|
|
|
children.push_back(expression);
|
|
|
|
}
|
|
|
|
|
2012-12-31 16:10:37 +00:00
|
|
|
SenchaObject IfNode::execute()
|
2012-12-09 16:42:13 +00:00
|
|
|
{
|
|
|
|
if(evaluate_condition())
|
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
return children[1]->execute();
|
2012-12-09 16:42:13 +00:00
|
|
|
}
|
|
|
|
else if(is_else)
|
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
return children[2]->execute();
|
2012-12-09 16:42:13 +00:00
|
|
|
}
|
2012-12-31 16:10:37 +00:00
|
|
|
return SenchaObject();
|
2012-12-09 16:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-03 22:40:47 +00:00
|
|
|
void IfNode::add_body(ASTStatement * statement)
|
|
|
|
{
|
|
|
|
children.push_back(statement);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IfNode::add_else_block(ASTStatement * statement)
|
|
|
|
{
|
2012-12-09 16:42:13 +00:00
|
|
|
is_else = true;
|
2012-12-03 22:40:47 +00:00
|
|
|
children.push_back(statement);
|
|
|
|
}
|