mirror of https://github.com/Icinga/icinga2.git
parent
04b8724cb8
commit
3587dbbd13
|
@ -34,12 +34,12 @@ AExpression::AExpression(AOperator op, const AValue& operand1, const AValue& ope
|
||||||
op == AEBinaryAnd || op == AEBinaryOr || op == AEShiftLeft || op == AEShiftRight);
|
op == AEBinaryAnd || op == AEBinaryOr || op == AEShiftLeft || op == AEShiftRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value AExpression::Evaluate(const Object::Ptr& thisRef) const
|
Value AExpression::Evaluate(const Dictionary::Ptr& locals) const
|
||||||
{
|
{
|
||||||
Value left, right;
|
Value left, right;
|
||||||
|
|
||||||
left = m_Operand1.Evaluate(thisRef);
|
left = m_Operand1.Evaluate(locals);
|
||||||
right = m_Operand2.Evaluate(thisRef);
|
right = m_Operand2.Evaluate(locals);
|
||||||
|
|
||||||
switch (m_Operator) {
|
switch (m_Operator) {
|
||||||
case AEReturn:
|
case AEReturn:
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "config/i2-config.h"
|
#include "config/i2-config.h"
|
||||||
#include "config/avalue.h"
|
#include "config/avalue.h"
|
||||||
#include "base/object.h"
|
#include "base/dictionary.h"
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
AExpression(AOperator op, const AValue& operand1);
|
AExpression(AOperator op, const AValue& operand1);
|
||||||
AExpression(AOperator op, const AValue& operand1, const AValue& operand2);
|
AExpression(AOperator op, const AValue& operand1, const AValue& operand2);
|
||||||
|
|
||||||
Value Evaluate(const Object::Ptr& thisRef) const;
|
Value Evaluate(const Dictionary::Ptr& locals) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AOperator m_Operator;
|
AOperator m_Operator;
|
||||||
|
|
|
@ -35,17 +35,20 @@ AValue::AValue(AValueType type, const Value& value)
|
||||||
: m_Type(type), m_Value(value)
|
: m_Type(type), m_Value(value)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Value AValue::Evaluate(const Object::Ptr& thisRef) const
|
Value AValue::Evaluate(const Dictionary::Ptr& locals) const
|
||||||
{
|
{
|
||||||
switch (m_Type) {
|
switch (m_Type) {
|
||||||
case ATSimple:
|
case ATSimple:
|
||||||
return m_Value;
|
return m_Value;
|
||||||
case ATVariable:
|
case ATVariable:
|
||||||
return ScriptVariable::Get(m_Value);
|
if (locals && locals->Contains(m_Value))
|
||||||
|
return locals->Get(m_Value);
|
||||||
|
else
|
||||||
|
return ScriptVariable::Get(m_Value);
|
||||||
case ATThisRef:
|
case ATThisRef:
|
||||||
VERIFY(!"Not implemented.");
|
VERIFY(!"Not implemented.");
|
||||||
case ATExpression:
|
case ATExpression:
|
||||||
return m_Expression->Evaluate(thisRef);
|
return m_Expression->Evaluate(locals);
|
||||||
default:
|
default:
|
||||||
ASSERT(!"Invalid type.");
|
ASSERT(!"Invalid type.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include "config/i2-config.h"
|
#include "config/i2-config.h"
|
||||||
#include "base/value.h"
|
#include "base/value.h"
|
||||||
#include "base/object.h"
|
#include "base/dictionary.h"
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ public:
|
||||||
AValue(const shared_ptr<AExpression>& expr);
|
AValue(const shared_ptr<AExpression>& expr);
|
||||||
AValue(AValueType type, const Value& value);
|
AValue(AValueType type, const Value& value);
|
||||||
|
|
||||||
Value Evaluate(const Object::Ptr& thisRef) const;
|
Value Evaluate(const Dictionary::Ptr& locals) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AValueType m_Type;
|
AValueType m_Type;
|
||||||
|
|
|
@ -668,7 +668,7 @@ value: simplevalue
|
||||||
| aterm
|
| aterm
|
||||||
{
|
{
|
||||||
AExpression::Ptr aexpr = *$1;
|
AExpression::Ptr aexpr = *$1;
|
||||||
$$ = new Value(aexpr->Evaluate(Object::Ptr()));
|
$$ = new Value(aexpr->Evaluate(Dictionary::Ptr()));
|
||||||
delete $1;
|
delete $1;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in New Issue