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

82 lines
1.7 KiB
C++

/*
* ConstantExpression.cpp
*
* Created on: Dec 5, 2012
* Author: attero
*/
#include "ConstantExpression.h"
ConstantExpression::ConstantExpression(ASTNode * parent) {
this->parent = parent;
value = SenchaObject();
this->context = NULL;
}
ConstantExpression::~ConstantExpression() {
// TODO Auto-generated destructor stub
}
ConstantExpression::ConstantExpression(ASTNode * parent, SenchaObject value, std::string name)
{
this->parent = parent;
this->value = value;
this->value.name = name;
this->context = NULL;
}
ConstantExpression::ConstantExpression(ASTNode * parent, SenchaObject value, Context * context)
{
this->context = context;
this->parent = parent;
this->value = value;
}
ConstantExpression::ConstantExpression(ASTNode * parent, SenchaObject value)
{
this->parent = parent;
this->value = value;
this->context = NULL;
}
SenchaObject ConstantExpression::evaluate()
{
if(value.name != "" && context != NULL)
{
return context->get(value.name);
}
return value;
}
void ConstantExpression::execute()
{
std::cout << evaluate().repr() << std::endl;//Do nothing
}
void ConstantExpression::execute_quietly()
{
evaluate();
}
ConstantExpression::ConstantExpression(ASTNode * parent, int number)
{
this->parent = parent; value = SenchaObject(number);
this->context = NULL;
}
ConstantExpression::ConstantExpression(ASTNode * parent, double number)
{
this->parent = parent;
value = SenchaObject(number);
this->context = NULL;
}
ConstantExpression::ConstantExpression(ASTNode * parent, std::string text)
{
this->parent = parent; value = SenchaObject(text);
this->context = NULL;
}
std::string ConstantExpression::debug() { return "Constant expression:\n" + value.repr() + "\n"; }