icinga2/lib/config/expression.hpp

972 lines
28 KiB
C++
Raw Normal View History

/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2014-10-16 17:44:06 +02:00
#ifndef EXPRESSION_H
#define EXPRESSION_H
2014-05-25 16:23:35 +02:00
#include "config/i2-config.hpp"
#include "base/debuginfo.hpp"
2014-05-25 16:23:35 +02:00
#include "base/array.hpp"
#include "base/dictionary.hpp"
#include "base/function.hpp"
#include "base/exception.hpp"
#include "base/scriptframe.hpp"
#include "base/shared-object.hpp"
#include "base/convert.hpp"
#include <map>
namespace icinga
{
struct DebugHint
{
2014-11-17 10:34:11 +01:00
public:
DebugHint(Dictionary::Ptr hints = nullptr)
: m_Hints(std::move(hints))
2014-11-17 10:34:11 +01:00
{ }
DebugHint(Dictionary::Ptr&& hints)
: m_Hints(std::move(hints))
{ }
void AddMessage(const String& message, const DebugInfo& di)
{
GetMessages()->Add(new Array({ message, di.Path, di.FirstLine, di.FirstColumn, di.LastLine, di.LastColumn }));
2014-11-17 10:34:11 +01:00
}
DebugHint GetChild(const String& name)
2014-11-17 10:34:11 +01:00
{
const Dictionary::Ptr& children = GetChildren();
2014-11-17 10:34:11 +01:00
Value vchild;
Dictionary::Ptr child;
2014-11-17 10:34:11 +01:00
if (!children->Get(name, &vchild)) {
child = new Dictionary();
children->Set(name, child);
} else
child = vchild;
2014-11-17 10:34:11 +01:00
return DebugHint(child);
}
Dictionary::Ptr ToDictionary() const
{
2014-11-17 10:34:11 +01:00
return m_Hints;
}
2014-11-17 10:34:11 +01:00
private:
Dictionary::Ptr m_Hints;
Array::Ptr m_Messages;
Dictionary::Ptr m_Children;
const Array::Ptr& GetMessages()
{
if (m_Messages)
return m_Messages;
if (!m_Hints)
m_Hints = new Dictionary();
Value vmessages;
if (!m_Hints->Get("messages", &vmessages)) {
m_Messages = new Array();
m_Hints->Set("messages", m_Messages);
} else
m_Messages = vmessages;
return m_Messages;
}
const Dictionary::Ptr& GetChildren()
{
if (m_Children)
return m_Children;
if (!m_Hints)
m_Hints = new Dictionary();
Value vchildren;
if (!m_Hints->Get("properties", &vchildren)) {
m_Children = new Dictionary();
m_Hints->Set("properties", m_Children);
} else
m_Children = vchildren;
return m_Children;
}
};
enum CombinedSetOp
{
OpSetLiteral,
OpSetAdd,
OpSetSubtract,
OpSetMultiply,
OpSetDivide,
OpSetModulo,
OpSetXor,
OpSetBinaryAnd,
OpSetBinaryOr
};
enum ScopeSpecifier
{
ScopeLocal,
ScopeThis,
ScopeGlobal
};
typedef std::map<String, String> DefinitionMap;
/**
* @ingroup config
*/
enum ExpressionResultCode
{
ResultOK,
ResultReturn,
ResultContinue,
ResultBreak
};
/**
* @ingroup config
*/
struct ExpressionResult
2014-11-24 00:04:26 +01:00
{
public:
template<typename T>
ExpressionResult(T value, ExpressionResultCode code = ResultOK)
: m_Value(std::move(value)), m_Code(code)
2014-11-24 00:04:26 +01:00
{ }
operator const Value&() const
{
return m_Value;
}
const Value& GetValue() const
{
return m_Value;
}
2014-11-24 00:04:26 +01:00
ExpressionResultCode GetCode() const
2014-11-24 00:04:26 +01:00
{
return m_Code;
2014-11-24 00:04:26 +01:00
}
private:
Value m_Value;
ExpressionResultCode m_Code;
2014-11-24 00:04:26 +01:00
};
#define CHECK_RESULT(res) \
do { \
if (res.GetCode() != ResultOK) \
return res; \
} while (0);
#define CHECK_RESULT_LOOP(res) \
if (res.GetCode() == ResultReturn) \
return res; \
if (res.GetCode() == ResultContinue) \
continue; \
if (res.GetCode() == ResultBreak) \
break; \
/**
* @ingroup config
*/
class Expression : public SharedObject
{
public:
DECLARE_PTR_TYPEDEFS(Expression);
Expression() = default;
2017-12-19 15:00:09 +01:00
Expression(const Expression&) = delete;
virtual ~Expression();
2014-11-09 19:48:28 +01:00
2017-12-19 15:00:09 +01:00
Expression& operator=(const Expression&) = delete;
2017-12-14 15:37:20 +01:00
ExpressionResult Evaluate(ScriptFrame& frame, DebugHint *dhint = nullptr) const;
virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint = nullptr) const;
virtual const DebugInfo& GetDebugInfo() const;
2014-11-09 19:48:28 +01:00
virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const = 0;
static boost::signals2::signal<void (ScriptFrame& frame, ScriptError *ex, const DebugInfo& di)> OnBreakpoint;
static void ScriptBreakpoint(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di);
2014-11-09 19:48:28 +01:00
};
2017-12-31 07:22:16 +01:00
std::unique_ptr<Expression> MakeIndexer(ScopeSpecifier scopeSpec, const String& index);
2014-11-09 19:48:28 +01:00
2018-01-04 06:11:04 +01:00
class OwnedExpression final : public Expression
2014-11-09 19:48:28 +01:00
{
public:
OwnedExpression(Expression::Ptr expression)
: m_Expression(std::move(expression))
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override
2014-11-09 19:48:28 +01:00
{
return m_Expression->DoEvaluate(frame, dhint);
2014-11-09 19:48:28 +01:00
}
const DebugInfo& GetDebugInfo() const override
2014-11-09 19:48:28 +01:00
{
return m_Expression->GetDebugInfo();
}
private:
Expression::Ptr m_Expression;
2014-11-09 19:48:28 +01:00
};
2018-01-04 06:11:04 +01:00
class LiteralExpression final : public Expression
2014-11-09 19:48:28 +01:00
{
public:
LiteralExpression(Value value = Value());
2014-11-09 19:48:28 +01:00
const Value& GetValue() const
{
return m_Value;
}
2014-11-09 19:48:28 +01:00
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
private:
Value m_Value;
};
inline LiteralExpression *MakeLiteralRaw(const Value& literal = Value())
2014-11-09 19:48:28 +01:00
{
return new LiteralExpression(literal);
}
inline std::unique_ptr<LiteralExpression> MakeLiteral(const Value& literal = Value())
{
return std::unique_ptr<LiteralExpression>(MakeLiteralRaw(literal));
}
2017-12-31 07:22:16 +01:00
class DebuggableExpression : public Expression
2014-11-09 19:48:28 +01:00
{
public:
DebuggableExpression(DebugInfo debugInfo = DebugInfo())
: m_DebugInfo(std::move(debugInfo))
2014-11-09 19:48:28 +01:00
{ }
protected:
const DebugInfo& GetDebugInfo() const final;
2014-11-09 19:48:28 +01:00
DebugInfo m_DebugInfo;
};
2017-12-31 07:22:16 +01:00
class UnaryExpression : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
UnaryExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Operand(std::move(operand))
2014-11-09 19:48:28 +01:00
{ }
protected:
std::unique_ptr<Expression> m_Operand;
2014-11-09 19:48:28 +01:00
};
2017-12-31 07:22:16 +01:00
class BinaryExpression : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
BinaryExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Operand1(std::move(operand1)), m_Operand2(std::move(operand2))
2014-11-09 19:48:28 +01:00
{ }
2017-12-13 12:54:14 +01:00
2014-11-09 19:48:28 +01:00
protected:
std::unique_ptr<Expression> m_Operand1;
std::unique_ptr<Expression> m_Operand2;
2014-11-09 19:48:28 +01:00
};
2018-01-04 06:11:04 +01:00
class VariableExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
VariableExpression(String variable, std::vector<Expression::Ptr> imports, const DebugInfo& debugInfo = DebugInfo());
2014-11-09 19:48:28 +01:00
String GetVariable() const
{
return m_Variable;
}
2014-11-09 19:48:28 +01:00
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const override;
2014-11-09 19:48:28 +01:00
private:
String m_Variable;
std::vector<Expression::Ptr> m_Imports;
2017-12-31 07:22:16 +01:00
friend void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-08-02 10:17:04 +02:00
class DerefExpression final : public UnaryExpression
{
public:
DerefExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(std::move(operand), debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const override;
};
class RefExpression final : public UnaryExpression
{
public:
RefExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(std::move(operand), debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class NegateExpression final : public UnaryExpression
2014-11-09 19:48:28 +01:00
{
public:
NegateExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(std::move(operand), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class LogicalNegateExpression final : public UnaryExpression
2014-11-09 19:48:28 +01:00
{
public:
LogicalNegateExpression(std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(std::move(operand), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2018-01-04 06:11:04 +01:00
class AddExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
AddExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class SubtractExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
SubtractExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class MultiplyExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
MultiplyExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class DivideExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
DivideExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2018-01-04 06:11:04 +01:00
class ModuloExpression final : public BinaryExpression
{
public:
ModuloExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class XorExpression final : public BinaryExpression
{
public:
XorExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class BinaryAndExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
BinaryAndExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class BinaryOrExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
BinaryOrExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class ShiftLeftExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
ShiftLeftExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class ShiftRightExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
ShiftRightExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class EqualExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
EqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class NotEqualExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
NotEqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class LessThanExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
LessThanExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class GreaterThanExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
GreaterThanExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class LessThanOrEqualExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
LessThanOrEqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class GreaterThanOrEqualExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
GreaterThanOrEqualExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class InExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
InExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class NotInExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
NotInExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class LogicalAndExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
LogicalAndExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class LogicalOrExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
LogicalOrExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class FunctionCallExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
FunctionCallExpression(std::unique_ptr<Expression> fname, std::vector<std::unique_ptr<Expression> >&& args, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_FName(std::move(fname)), m_Args(std::move(args))
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
public:
std::unique_ptr<Expression> m_FName;
std::vector<std::unique_ptr<Expression> > m_Args;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class ArrayExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
ArrayExpression(std::vector<std::unique_ptr<Expression > >&& expressions, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Expressions(std::move(expressions))
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
private:
std::vector<std::unique_ptr<Expression> > m_Expressions;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class DictExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
DictExpression(std::vector<std::unique_ptr<Expression> >&& expressions = {}, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Expressions(std::move(expressions))
2014-11-09 19:48:28 +01:00
{ }
void MakeInline();
2014-11-09 19:48:28 +01:00
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
private:
std::vector<std::unique_ptr<Expression> > m_Expressions;
bool m_Inline{false};
2017-12-31 07:22:16 +01:00
friend void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-08-07 13:55:41 +02:00
class SetConstExpression final : public UnaryExpression
{
public:
SetConstExpression(const String& name, std::unique_ptr<Expression> operand, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(std::move(operand), debugInfo), m_Name(name)
{ }
protected:
String m_Name;
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class SetExpression final : public BinaryExpression
2014-11-09 19:48:28 +01:00
{
public:
SetExpression(std::unique_ptr<Expression> operand1, CombinedSetOp op, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo), m_Op(op)
2014-11-09 19:48:28 +01:00
{ }
void SetOverrideFrozen();
2014-11-09 19:48:28 +01:00
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
2014-11-09 19:48:28 +01:00
CombinedSetOp m_Op;
bool m_OverrideFrozen{false};
2017-12-31 07:22:16 +01:00
friend void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
2014-11-09 19:48:28 +01:00
};
2018-01-04 06:11:04 +01:00
class ConditionalExpression final : public DebuggableExpression
{
public:
ConditionalExpression(std::unique_ptr<Expression> condition, std::unique_ptr<Expression> true_branch, std::unique_ptr<Expression> false_branch, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Condition(std::move(condition)), m_TrueBranch(std::move(true_branch)), m_FalseBranch(std::move(false_branch))
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
std::unique_ptr<Expression> m_Condition;
std::unique_ptr<Expression> m_TrueBranch;
std::unique_ptr<Expression> m_FalseBranch;
};
2018-01-04 06:11:04 +01:00
class WhileExpression final : public DebuggableExpression
{
public:
WhileExpression(std::unique_ptr<Expression> condition, std::unique_ptr<Expression> loop_body, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Condition(std::move(condition)), m_LoopBody(std::move(loop_body))
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
std::unique_ptr<Expression> m_Condition;
std::unique_ptr<Expression> m_LoopBody;
};
2018-01-04 06:11:04 +01:00
class ReturnExpression final : public UnaryExpression
2014-11-24 00:04:26 +01:00
{
public:
ReturnExpression(std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(std::move(expression), debugInfo)
2014-11-24 00:04:26 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class BreakExpression final : public DebuggableExpression
{
public:
BreakExpression(const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class ContinueExpression final : public DebuggableExpression
{
public:
ContinueExpression(const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-24 00:04:26 +01:00
};
2018-01-04 06:11:04 +01:00
class GetScopeExpression final : public Expression
2014-11-09 19:48:28 +01:00
{
public:
GetScopeExpression(ScopeSpecifier scopeSpec)
: m_ScopeSpec(scopeSpec)
2014-11-09 19:48:28 +01:00
{ }
2014-11-09 19:48:28 +01:00
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
ScopeSpecifier m_ScopeSpec;
};
2018-01-04 06:11:04 +01:00
class IndexerExpression final : public BinaryExpression
{
public:
IndexerExpression(std::unique_ptr<Expression> operand1, std::unique_ptr<Expression> operand2, const DebugInfo& debugInfo = DebugInfo())
: BinaryExpression(std::move(operand1), std::move(operand2), debugInfo)
{ }
void SetOverrideFrozen();
protected:
bool m_OverrideFrozen{false};
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint) const override;
2017-12-31 07:22:16 +01:00
friend void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
2014-11-09 19:48:28 +01:00
};
2017-12-31 07:22:16 +01:00
void BindToScope(std::unique_ptr<Expression>& expr, ScopeSpecifier scopeSpec);
2018-01-04 06:11:04 +01:00
class ThrowExpression final : public DebuggableExpression
{
public:
ThrowExpression(std::unique_ptr<Expression> message, bool incompleteExpr, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Message(std::move(message)), m_IncompleteExpr(incompleteExpr)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
std::unique_ptr<Expression> m_Message;
bool m_IncompleteExpr;
};
2018-01-04 06:11:04 +01:00
class ImportExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
ImportExpression(std::unique_ptr<Expression> name, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Name(std::move(name))
2014-11-09 19:48:28 +01:00
{ }
2014-11-09 19:48:28 +01:00
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-06 19:35:47 +01:00
2014-11-09 19:48:28 +01:00
private:
std::unique_ptr<Expression> m_Name;
};
2018-01-04 06:11:04 +01:00
class ImportDefaultTemplatesExpression final : public DebuggableExpression
{
public:
ImportDefaultTemplatesExpression(const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class FunctionExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
FunctionExpression(String name, std::vector<String> args,
std::map<String, std::unique_ptr<Expression> >&& closedVars, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Name(std::move(name)), m_Args(std::move(args)), m_ClosedVars(std::move(closedVars)), m_Expression(expression.release())
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
private:
String m_Name;
2014-11-09 19:48:28 +01:00
std::vector<String> m_Args;
std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
Expression::Ptr m_Expression;
2014-11-09 19:48:28 +01:00
};
2018-01-04 06:11:04 +01:00
class ApplyExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
ApplyExpression(String type, String target, std::unique_ptr<Expression> name,
std::unique_ptr<Expression> filter, String package, String fkvar, String fvvar,
std::unique_ptr<Expression> fterm, std::map<String, std::unique_ptr<Expression> >&& closedVars, bool ignoreOnError,
std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Type(std::move(type)), m_Target(std::move(target)),
m_Name(std::move(name)), m_Filter(filter.release()), m_Package(std::move(package)), m_FKVar(std::move(fkvar)), m_FVVar(std::move(fvvar)),
m_FTerm(fterm.release()), m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)),
m_Expression(expression.release())
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
private:
String m_Type;
String m_Target;
std::unique_ptr<Expression> m_Name;
Expression::Ptr m_Filter;
String m_Package;
2014-11-09 19:48:28 +01:00
String m_FKVar;
String m_FVVar;
Expression::Ptr m_FTerm;
bool m_IgnoreOnError;
std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
Expression::Ptr m_Expression;
2014-11-09 19:48:28 +01:00
};
class NamespaceExpression final : public DebuggableExpression
{
public:
NamespaceExpression(std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Expression(expression.release())
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
Expression::Ptr m_Expression;
};
2018-01-04 06:11:04 +01:00
class ObjectExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
ObjectExpression(bool abstract, std::unique_ptr<Expression> type, std::unique_ptr<Expression> name, std::unique_ptr<Expression> filter,
String zone, String package, std::map<String, std::unique_ptr<Expression> >&& closedVars,
bool defaultTmpl, bool ignoreOnError, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_Abstract(abstract), m_Type(std::move(type)),
m_Name(std::move(name)), m_Filter(filter.release()), m_Zone(std::move(zone)), m_Package(std::move(package)), m_DefaultTmpl(defaultTmpl),
m_IgnoreOnError(ignoreOnError), m_ClosedVars(std::move(closedVars)), m_Expression(expression.release())
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
private:
bool m_Abstract;
std::unique_ptr<Expression> m_Type;
std::unique_ptr<Expression> m_Name;
Expression::Ptr m_Filter;
2014-11-09 19:48:28 +01:00
String m_Zone;
String m_Package;
bool m_DefaultTmpl;
bool m_IgnoreOnError;
std::map<String, std::unique_ptr<Expression> > m_ClosedVars;
Expression::Ptr m_Expression;
2014-11-09 19:48:28 +01:00
};
2017-12-13 12:54:14 +01:00
2018-01-04 06:11:04 +01:00
class ForExpression final : public DebuggableExpression
2014-11-09 19:48:28 +01:00
{
public:
ForExpression(String fkvar, String fvvar, std::unique_ptr<Expression> value, std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_FKVar(std::move(fkvar)), m_FVVar(std::move(fvvar)), m_Value(std::move(value)), m_Expression(std::move(expression))
2014-11-09 19:48:28 +01:00
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
2014-11-09 19:48:28 +01:00
private:
String m_FKVar;
String m_FVVar;
std::unique_ptr<Expression> m_Value;
std::unique_ptr<Expression> m_Expression;
2014-11-09 19:48:28 +01:00
};
2018-01-04 06:11:04 +01:00
class LibraryExpression final : public UnaryExpression
{
public:
LibraryExpression(std::unique_ptr<Expression> expression, const DebugInfo& debugInfo = DebugInfo())
: UnaryExpression(std::move(expression), debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
enum IncludeType
{
IncludeRegular,
IncludeRecursive,
IncludeZones
};
2018-01-04 06:11:04 +01:00
class IncludeExpression final : public DebuggableExpression
{
public:
IncludeExpression(String relativeBase, std::unique_ptr<Expression> path, std::unique_ptr<Expression> pattern, std::unique_ptr<Expression> name,
IncludeType type, bool searchIncludes, String zone, String package, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_RelativeBase(std::move(relativeBase)), m_Path(std::move(path)), m_Pattern(std::move(pattern)),
m_Name(std::move(name)), m_Type(type), m_SearchIncludes(searchIncludes), m_Zone(std::move(zone)), m_Package(std::move(package))
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
String m_RelativeBase;
std::unique_ptr<Expression> m_Path;
std::unique_ptr<Expression> m_Pattern;
std::unique_ptr<Expression> m_Name;
IncludeType m_Type;
bool m_SearchIncludes;
String m_Zone;
String m_Package;
};
2018-01-04 06:11:04 +01:00
class BreakpointExpression final : public DebuggableExpression
{
public:
BreakpointExpression(const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo)
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
};
2018-01-04 06:11:04 +01:00
class TryExceptExpression final : public DebuggableExpression
{
public:
TryExceptExpression(std::unique_ptr<Expression> tryBody, std::unique_ptr<Expression> exceptBody, const DebugInfo& debugInfo = DebugInfo())
: DebuggableExpression(debugInfo), m_TryBody(std::move(tryBody)), m_ExceptBody(std::move(exceptBody))
{ }
protected:
ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const override;
private:
std::unique_ptr<Expression> m_TryBody;
std::unique_ptr<Expression> m_ExceptBody;
};
}
2014-10-16 17:44:06 +02:00
#endif /* EXPRESSION_H */