sencha-lang/Sencha-lang/AST/Assignment.cpp

53 lines
1.0 KiB
C++
Raw Normal View History

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();
auto context = context_manager->get_top();
context->add(name, right_value);
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
}
SenchaObject Assignment::execute()
2012-12-09 11:57:51 +00:00
{
return evaluate();
2012-12-09 11:57:51 +00:00
}
Assignment::Assignment(ContextManager * context_manager, std::string name, ASTExpression * left, ASTExpression * right)
2012-12-09 10:29:08 +00:00
{
this->context_manager = context_manager;
this->name_of_context = "global";
this->type = "Assignment";
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() {
for(auto it = children.begin(); it != children.end(); )
{
delete *it;
it = children.erase(it);
}
2012-12-08 19:59:05 +00:00
}