/*
 * VariableExpression.cpp
 *
 *  Created on: Dec 17, 2012
 *      Author: att
 */

#include "VariableExpression.h"

VariableExpression::VariableExpression(std::string name, ContextManager * context_manager) {
	this->name = name;
	this->name_of_context = "global";
	this->context_manager = context_manager;
	this->type = "VariableExpression";
}

VariableExpression::~VariableExpression() {
	// Do nothing
}

SenchaObject VariableExpression::evaluate()
{

	auto context = context_manager->get_top();
	//std::cout << "I'm retrieving variable " + name + " from " + context->name << std::endl;
	SenchaObject result = context->get(name);
	if(result.type == SenchaObject::string_literal)
	{
		result = context->get_updated_string(name);
	}
	//std::cout << "And it's: " + result.repr() << std::endl;
	result.name = name;
	return result;
}

SenchaObject  VariableExpression::execute()
{
	return evaluate();
}

