2013-10-20 15:06:05 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
2013-10-20 15:06:05 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-10-16 17:44:06 +02:00
|
|
|
#ifndef EXPRESSION_H
|
|
|
|
#define EXPRESSION_H
|
2013-10-20 15:06:05 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "config/i2-config.hpp"
|
2014-09-09 14:49:21 +02:00
|
|
|
#include "base/debuginfo.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/array.hpp"
|
|
|
|
#include "base/dictionary.hpp"
|
2013-10-20 15:06:05 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2014-08-12 15:31:47 +02:00
|
|
|
struct DebugHint
|
|
|
|
{
|
|
|
|
std::vector<std::pair<String, DebugInfo> > Messages;
|
|
|
|
std::map<String, DebugHint> Children;
|
|
|
|
|
|
|
|
inline void AddMessage(const String& message, const DebugInfo& di)
|
|
|
|
{
|
|
|
|
Messages.push_back(std::make_pair(message, di));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline DebugHint *GetChild(const String& name)
|
|
|
|
{
|
|
|
|
return &Children[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary::Ptr ToDictionary(void) const;
|
|
|
|
};
|
|
|
|
|
2014-11-04 15:19:33 +01:00
|
|
|
enum CombinedSetOp
|
|
|
|
{
|
|
|
|
OpSetLiteral,
|
|
|
|
OpSetAdd,
|
|
|
|
OpSetSubtract,
|
|
|
|
OpSetMultiply,
|
|
|
|
OpSetDivide
|
|
|
|
};
|
|
|
|
|
2013-10-20 15:06:05 +02:00
|
|
|
/**
|
|
|
|
* @ingroup config
|
|
|
|
*/
|
2014-10-16 17:44:06 +02:00
|
|
|
class I2_CONFIG_API Expression : public Object
|
2013-10-20 15:06:05 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-11-07 12:32:25 +01:00
|
|
|
DECLARE_PTR_TYPEDEFS(Expression);
|
2014-03-22 10:29:45 +01:00
|
|
|
|
2014-11-06 19:35:47 +01:00
|
|
|
typedef Value (*OpCallback)(const Expression *, const Object::Ptr&, DebugHint *dhint);
|
2013-10-20 15:06:05 +02:00
|
|
|
|
2014-10-16 17:44:06 +02:00
|
|
|
Expression(OpCallback op, const Value& operand1, const DebugInfo& di);
|
|
|
|
Expression(OpCallback op, const Value& operand1, const Value& operand2, const DebugInfo& di);
|
2013-10-20 15:06:05 +02:00
|
|
|
|
2014-11-06 19:35:47 +01:00
|
|
|
Value Evaluate(const Object::Ptr& context, DebugHint *dhint = NULL) const;
|
2013-10-20 15:06:05 +02:00
|
|
|
|
2014-03-23 11:27:40 +01:00
|
|
|
void MakeInline(void);
|
|
|
|
|
2014-03-24 09:27:46 +01:00
|
|
|
void Dump(std::ostream& stream, int indent = 0) const;
|
2014-03-24 12:54:23 +01:00
|
|
|
|
2014-11-06 19:35:47 +01:00
|
|
|
static Value OpLiteral(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpVariable(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpNegate(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpLogicalNegate(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpAdd(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpSubtract(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpMultiply(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpDivide(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpBinaryAnd(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpBinaryOr(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpShiftLeft(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpShiftRight(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpEqual(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpNotEqual(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpLessThan(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpGreaterThan(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpLessThanOrEqual(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpGreaterThanOrEqual(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpIn(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpNotIn(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpLogicalAnd(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpLogicalOr(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpFunctionCall(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpArray(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpDict(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpSet(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpIndexer(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpImport(const Expression *expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpFunction(const Expression* expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpApply(const Expression* expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpObject(const Expression* expr, const Object::Ptr& context, DebugHint *dhint);
|
|
|
|
static Value OpFor(const Expression* expr, const Object::Ptr& context, DebugHint *dhint);
|
2014-03-22 10:29:45 +01:00
|
|
|
|
2013-10-20 15:06:05 +02:00
|
|
|
private:
|
2014-03-22 10:29:45 +01:00
|
|
|
OpCallback m_Operator;
|
|
|
|
Value m_Operand1;
|
|
|
|
Value m_Operand2;
|
2014-03-18 15:29:04 +01:00
|
|
|
DebugInfo m_DebugInfo;
|
2014-03-22 10:29:45 +01:00
|
|
|
|
2014-11-06 19:35:47 +01:00
|
|
|
Value EvaluateOperand1(const Object::Ptr& context, DebugHint *dhint = NULL) const;
|
|
|
|
Value EvaluateOperand2(const Object::Ptr& context, DebugHint *dhint = NULL) const;
|
2014-03-23 19:58:24 +01:00
|
|
|
|
|
|
|
static void DumpOperand(std::ostream& stream, const Value& operand, int indent);
|
2014-03-30 15:04:53 +02:00
|
|
|
|
|
|
|
static Value FunctionWrapper(const std::vector<Value>& arguments, const Array::Ptr& funcargs,
|
2014-11-06 19:35:47 +01:00
|
|
|
const Expression::Ptr& expr, const Object::Ptr& scope);
|
|
|
|
|
|
|
|
static bool HasField(const Object::Ptr& context, const String& field);
|
|
|
|
static Value GetField(const Object::Ptr& context, const String& field);
|
|
|
|
static void SetField(const Object::Ptr& context, const String& field, const Value& value);
|
2013-10-20 15:06:05 +02:00
|
|
|
};
|
|
|
|
|
2014-11-04 15:19:33 +01:00
|
|
|
I2_CONFIG_API Expression::Ptr MakeLiteral(const Value& lit = Value());
|
|
|
|
|
2013-10-20 15:06:05 +02:00
|
|
|
}
|
|
|
|
|
2014-10-16 17:44:06 +02:00
|
|
|
#endif /* EXPRESSION_H */
|