summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/AST/Assignment.cpp
blob: fe4c79a24d5f7f7fb8ed90d5c38cb99d28a1231f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Assignment.cpp
 *
 *  Created on: Dec 7, 2012
 *      Author: attero
 */

#include "Assignment.h"

SenchaObject Assignment::evaluate()
{
	auto right_value = static_cast<ASTExpression *>(children[1])->evaluate();
	auto context = context_manager->get_top();
	context->add(name, right_value);

	return children[0]->execute();
}


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


Assignment::Assignment(ContextManager * context_manager, std::string name, ASTExpression * left, ASTExpression * right)
{
	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;
}


Assignment::~Assignment() {
	for(auto it = children.begin(); it != children.end(); )
	{
		delete *it;
		it = children.erase(it);
	}
}