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()
|
|
|
|
{
|
|
|
|
return static_cast<ASTExpression *>(children[1])->evaluate();
|
|
|
|
}
|
|
|
|
|
2012-12-09 20:17:13 +00:00
|
|
|
void Assignment::set_name(std::string name)
|
|
|
|
{
|
|
|
|
this->name = name;
|
|
|
|
}
|
|
|
|
|
2012-12-09 10:29:08 +00:00
|
|
|
void Assignment::execute()
|
|
|
|
{
|
|
|
|
auto left_value = static_cast<ASTExpression *>(children[0])->evaluate();
|
|
|
|
auto right_value = static_cast<ASTExpression *>(children[1])->evaluate();
|
2012-12-09 11:57:51 +00:00
|
|
|
static_cast<ASTExpression *>(children[1])->execute_quietly();
|
2012-12-09 20:17:13 +00:00
|
|
|
|
|
|
|
if(name != "")
|
2012-12-09 10:29:08 +00:00
|
|
|
{
|
2012-12-09 20:17:13 +00:00
|
|
|
context->set(name, right_value);
|
2012-12-09 10:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 11:57:51 +00:00
|
|
|
void Assignment::execute_quietly()
|
|
|
|
{
|
|
|
|
auto left_value = static_cast<ASTExpression *>(children[0])->evaluate();
|
|
|
|
auto right_value = static_cast<ASTExpression *>(children[1])->evaluate();
|
|
|
|
static_cast<ASTExpression *>(children[1])->execute_quietly();
|
|
|
|
if(left_value.name != "")
|
|
|
|
{
|
|
|
|
context->set(left_value.name, right_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-09 10:29:08 +00:00
|
|
|
void Assignment::add_lvalue(ASTExpression * left)
|
|
|
|
{
|
|
|
|
if(children.size()==0)
|
|
|
|
children.push_back(left);
|
|
|
|
else
|
|
|
|
children[0] = left;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Assignment::add_rvalue(ASTExpression * right)
|
|
|
|
{
|
|
|
|
if(children.size()==1)
|
|
|
|
children.push_back(right);
|
|
|
|
else if(children.size()>1)
|
|
|
|
children[1] = right;
|
2012-12-08 19:59:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-09 10:29:08 +00:00
|
|
|
std::string Assignment::debug()
|
|
|
|
{
|
|
|
|
std::string debug_note = static_cast<ASTExpression *>(children[0])->evaluate().repr();
|
|
|
|
debug_note += " = " + static_cast<ASTExpression *>(children[1])->evaluate().repr() + "\n";
|
|
|
|
return debug_note;
|
|
|
|
}
|
|
|
|
|
|
|
|
Assignment::Assignment(ASTNode * parent, Context * context)
|
|
|
|
{
|
|
|
|
this->parent = parent;
|
|
|
|
this->context = context;
|
2012-12-22 10:06:55 +00:00
|
|
|
this->type = "Assignment";
|
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
|
|
|
}
|
|
|
|
|