2012-12-08 19:59:05 +00:00
|
|
|
/*
|
|
|
|
* Assignment.cpp
|
|
|
|
*
|
|
|
|
* Created on: Dec 7, 2012
|
|
|
|
* Author: attero
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Assignment.h"
|
|
|
|
|
2012-12-09 10:29:08 +00:00
|
|
|
SenchaObject Assignment::evaluate()
|
|
|
|
{
|
2013-01-10 15:15:43 +00:00
|
|
|
//TODO do something different with name evaluation
|
|
|
|
auto left_value = static_cast<ASTExpression *>(children[0])->evaluate();
|
|
|
|
if(left_value.name != "")
|
|
|
|
{
|
|
|
|
name = left_value.name;
|
|
|
|
}
|
2012-12-09 10:29:08 +00:00
|
|
|
auto right_value = static_cast<ASTExpression *>(children[1])->evaluate();
|
2012-12-31 16:10:37 +00:00
|
|
|
auto context = context_manager->get_top();
|
|
|
|
context->add(name, right_value);
|
2012-12-09 20:17:13 +00:00
|
|
|
|
2013-01-10 15:15:43 +00:00
|
|
|
left_value = right_value;
|
|
|
|
left_value.name = name;
|
|
|
|
return left_value;
|
2012-12-09 10:29:08 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 16:10:37 +00:00
|
|
|
|
|
|
|
SenchaObject Assignment::execute()
|
2012-12-09 11:57:51 +00:00
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
return evaluate();
|
2012-12-09 11:57:51 +00:00
|
|
|
}
|
|
|
|
|
2012-12-31 16:10:37 +00:00
|
|
|
|
|
|
|
Assignment::Assignment(ContextManager * context_manager, std::string name, ASTExpression * left, ASTExpression * right)
|
2012-12-09 10:29:08 +00:00
|
|
|
{
|
2012-12-31 16:10:37 +00:00
|
|
|
this->context_manager = context_manager;
|
|
|
|
this->name_of_context = "global";
|
2012-12-22 10:06:55 +00:00
|
|
|
this->type = "Assignment";
|
2012-12-28 15:19:47 +00:00
|
|
|
this->children.push_back(left);
|
|
|
|
this->children.push_back(right);
|
|
|
|
this->name = name;
|
2012-12-09 10:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-08 19:59:05 +00:00
|
|
|
Assignment::~Assignment() {
|
2012-12-17 08:25:58 +00:00
|
|
|
for(auto it = children.begin(); it != children.end(); )
|
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
it = children.erase(it);
|
|
|
|
}
|
2012-12-08 19:59:05 +00:00
|
|
|
}
|
|
|
|
|