#ifndef __PLASP__PDDL__EXPRESSION_H #define __PLASP__PDDL__EXPRESSION_H #include #include #include namespace plasp { namespace pddl { //////////////////////////////////////////////////////////////////////////////////////////////////// // // Expression // //////////////////////////////////////////////////////////////////////////////////////////////////// class Context; class Domain; class ExpressionContext; class ExpressionVisitor; class Problem; class Expression; using ExpressionPointer = boost::intrusive_ptr; using Expressions = std::vector; namespace expressions { class And; using AndPointer = boost::intrusive_ptr; class At; using AtPointer = boost::intrusive_ptr; class Constant; using ConstantPointer = boost::intrusive_ptr; using Constants = std::vector; class Dummy; using DummyPointer = boost::intrusive_ptr; class Either; using EitherPointer = boost::intrusive_ptr; class Imply; using ImplyPointer = boost::intrusive_ptr; class Not; using NotPointer = boost::intrusive_ptr; class Or; using OrPointer = boost::intrusive_ptr; class Predicate; using PredicatePointer = boost::intrusive_ptr; using Predicates = std::vector; class PredicateDeclaration; using PredicateDeclarationPointer = boost::intrusive_ptr; using PredicateDeclarations = std::vector; class PrimitiveType; using PrimitiveTypePointer = boost::intrusive_ptr; using PrimitiveTypes = std::vector; template class Reference; template using ReferencePointer = boost::intrusive_ptr>; class Unsupported; using UnsupportedPointer = boost::intrusive_ptr; class Variable; using VariablePointer = boost::intrusive_ptr; using Variables = std::vector; } //////////////////////////////////////////////////////////////////////////////////////////////////// class Expression { public: enum class Type { And, At, Binary, Constant, Dummy, Either, Imply, Not, Or, PredicateDeclaration, Predicate, PrimitiveType, Reference, Unsupported, Variable, }; public: virtual ~Expression() = default; virtual Type expressionType() const = 0; virtual ExpressionPointer normalized(); ExpressionPointer negated(); virtual void print(std::ostream &ostream) const = 0; private: friend void intrusive_ptr_add_ref(Expression *expression); friend void intrusive_ptr_release(Expression *expression); size_t m_referenceCount = 0; }; //////////////////////////////////////////////////////////////////////////////////////////////////// inline void intrusive_ptr_add_ref(Expression *expression) { expression->m_referenceCount++; } //////////////////////////////////////////////////////////////////////////////////////////////////// inline void intrusive_ptr_release(Expression *expression) { if (--expression->m_referenceCount == 0) delete expression; } //////////////////////////////////////////////////////////////////////////////////////////////////// template class ExpressionCRTP: public Expression { public: Type expressionType() const override final { return Derived::ExpressionType; } }; //////////////////////////////////////////////////////////////////////////////////////////////////// ExpressionPointer parseLiteral(Context &context, ExpressionContext &expressionContext); ExpressionPointer parseAtomicFormula(Context &context, ExpressionContext &expressionContext); ExpressionPointer parsePreconditionExpression(Context &context, ExpressionContext &expressionContext); ExpressionPointer parseExpression(Context &context, ExpressionContext &expressionContext); ExpressionPointer parseEffectExpression(Context &context, ExpressionContext &expressionContext); //////////////////////////////////////////////////////////////////////////////////////////////////// } } #endif