Switched to intrusive pointers for much easier maintenance.
This commit is contained in:
		@@ -38,8 +38,8 @@ class Action
 | 
			
		||||
		std::string m_name;
 | 
			
		||||
 | 
			
		||||
		expressions::Variables m_parameters;
 | 
			
		||||
		std::unique_ptr<Expression> m_precondition;
 | 
			
		||||
		std::unique_ptr<Expression> m_effect;
 | 
			
		||||
		ExpressionPointer m_precondition;
 | 
			
		||||
		ExpressionPointer m_effect;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
#ifndef __PLASP__PDDL__EXPRESSION_H
 | 
			
		||||
#define __PLASP__PDDL__EXPRESSION_H
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <boost/intrusive_ptr.hpp>
 | 
			
		||||
 | 
			
		||||
#include <plasp/utils/Parser.h>
 | 
			
		||||
 | 
			
		||||
@@ -23,55 +23,58 @@ class ExpressionVisitor;
 | 
			
		||||
class Problem;
 | 
			
		||||
 | 
			
		||||
class Expression;
 | 
			
		||||
using ExpressionPointer = std::unique_ptr<Expression>;
 | 
			
		||||
using ExpressionPointer = boost::intrusive_ptr<Expression>;
 | 
			
		||||
using Expressions = std::vector<ExpressionPointer>;
 | 
			
		||||
 | 
			
		||||
namespace expressions
 | 
			
		||||
{
 | 
			
		||||
class And;
 | 
			
		||||
using AndPointer = std::unique_ptr<And>;
 | 
			
		||||
using AndPointer = boost::intrusive_ptr<And>;
 | 
			
		||||
 | 
			
		||||
class At;
 | 
			
		||||
using AtPointer = std::unique_ptr<At>;
 | 
			
		||||
using AtPointer = boost::intrusive_ptr<At>;
 | 
			
		||||
 | 
			
		||||
class Constant;
 | 
			
		||||
using ConstantPointer = std::unique_ptr<Constant>;
 | 
			
		||||
using ConstantPointer = boost::intrusive_ptr<Constant>;
 | 
			
		||||
using Constants = std::vector<ConstantPointer>;
 | 
			
		||||
 | 
			
		||||
class Dummy;
 | 
			
		||||
using DummyPointer = boost::intrusive_ptr<Dummy>;
 | 
			
		||||
 | 
			
		||||
class Either;
 | 
			
		||||
using EitherPointer = std::unique_ptr<Either>;
 | 
			
		||||
using EitherPointer = boost::intrusive_ptr<Either>;
 | 
			
		||||
 | 
			
		||||
class Imply;
 | 
			
		||||
using ImplyPointer = std::unique_ptr<Imply>;
 | 
			
		||||
using ImplyPointer = boost::intrusive_ptr<Imply>;
 | 
			
		||||
 | 
			
		||||
class Not;
 | 
			
		||||
using NotPointer = std::unique_ptr<Not>;
 | 
			
		||||
using NotPointer = boost::intrusive_ptr<Not>;
 | 
			
		||||
 | 
			
		||||
class Or;
 | 
			
		||||
using OrPointer = std::unique_ptr<Or>;
 | 
			
		||||
using OrPointer = boost::intrusive_ptr<Or>;
 | 
			
		||||
 | 
			
		||||
class Predicate;
 | 
			
		||||
using PredicatePointer = std::unique_ptr<Predicate>;
 | 
			
		||||
using PredicatePointer = boost::intrusive_ptr<Predicate>;
 | 
			
		||||
using Predicates = std::vector<PredicatePointer>;
 | 
			
		||||
 | 
			
		||||
class PredicateDeclaration;
 | 
			
		||||
using PredicateDeclarationPointer = std::unique_ptr<PredicateDeclaration>;
 | 
			
		||||
using PredicateDeclarationPointer = boost::intrusive_ptr<PredicateDeclaration>;
 | 
			
		||||
using PredicateDeclarations = std::vector<PredicateDeclarationPointer>;
 | 
			
		||||
 | 
			
		||||
class PrimitiveType;
 | 
			
		||||
using PrimitiveTypePointer = std::unique_ptr<PrimitiveType>;
 | 
			
		||||
using PrimitiveTypePointer = boost::intrusive_ptr<PrimitiveType>;
 | 
			
		||||
using PrimitiveTypes = std::vector<PrimitiveTypePointer>;
 | 
			
		||||
 | 
			
		||||
template<class Type>
 | 
			
		||||
class Reference;
 | 
			
		||||
template<class Type>
 | 
			
		||||
using ReferencePointer = std::unique_ptr<Reference<Type>>;
 | 
			
		||||
using ReferencePointer = boost::intrusive_ptr<Reference<Type>>;
 | 
			
		||||
 | 
			
		||||
class Unsupported;
 | 
			
		||||
using UnsupportedPointer = std::unique_ptr<Unsupported>;
 | 
			
		||||
using UnsupportedPointer = boost::intrusive_ptr<Unsupported>;
 | 
			
		||||
 | 
			
		||||
class Variable;
 | 
			
		||||
using VariablePointer = std::unique_ptr<Variable>;
 | 
			
		||||
using VariablePointer = boost::intrusive_ptr<Variable>;
 | 
			
		||||
using Variables = std::vector<VariablePointer>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -110,10 +113,31 @@ class Expression
 | 
			
		||||
		//     * a new expression pointer to replace this one if required; this object is then empty
 | 
			
		||||
		//     * nullptr otherwise; the object may or may not have changed
 | 
			
		||||
		virtual ExpressionPointer normalize() = 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 Derived>
 | 
			
		||||
class ExpressionCRTP: public Expression
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,7 @@ AtPointer At::parse(Context &context, ExpressionContext &expressionContext,
 | 
			
		||||
		return nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto expression = std::make_unique<At>(At());
 | 
			
		||||
	auto expression = AtPointer(new At);
 | 
			
		||||
 | 
			
		||||
	expression->m_timePoint = timePoint;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ class Binary: public ExpressionCRTP<Derived>
 | 
			
		||||
{
 | 
			
		||||
	public:
 | 
			
		||||
		template<typename ExpressionParser>
 | 
			
		||||
		static std::unique_ptr<Derived> parse(Context &context,
 | 
			
		||||
		static boost::intrusive_ptr<Derived> parse(Context &context,
 | 
			
		||||
			ExpressionContext &expressionContext, ExpressionParser parseExpression);
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
@@ -45,7 +45,7 @@ class Binary: public ExpressionCRTP<Derived>
 | 
			
		||||
 | 
			
		||||
template<class Derived>
 | 
			
		||||
template<typename ExpressionParser>
 | 
			
		||||
std::unique_ptr<Derived> Binary<Derived>::parse(Context &context,
 | 
			
		||||
boost::intrusive_ptr<Derived> Binary<Derived>::parse(Context &context,
 | 
			
		||||
	ExpressionContext &expressionContext, ExpressionParser parseExpression)
 | 
			
		||||
{
 | 
			
		||||
	auto &parser = context.parser;
 | 
			
		||||
@@ -59,7 +59,7 @@ std::unique_ptr<Derived> Binary<Derived>::parse(Context &context,
 | 
			
		||||
		return nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto expression = std::make_unique<Derived>();
 | 
			
		||||
	auto expression = boost::intrusive_ptr<Derived>(new Derived);
 | 
			
		||||
 | 
			
		||||
	// Assume that expression identifier (imply, exists, etc.) is already parsed
 | 
			
		||||
	// Parse arguments of the expression
 | 
			
		||||
 
 | 
			
		||||
@@ -28,12 +28,12 @@ class Constant: public ExpressionCRTP<Constant>
 | 
			
		||||
		static void parseTypedDeclaration(Context &context, Problem &problem);
 | 
			
		||||
		static void parseTypedDeclarations(Context &context, Problem &problem);
 | 
			
		||||
 | 
			
		||||
		static Constant *parseAndFind(Context &context, const Domain &domain);
 | 
			
		||||
		static Constant *parseAndFind(Context &context, const Problem &problem);
 | 
			
		||||
		static ConstantPointer parseAndFind(Context &context, const Domain &domain);
 | 
			
		||||
		static ConstantPointer parseAndFind(Context &context, const Problem &problem);
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		const std::string &name() const;
 | 
			
		||||
		const PrimitiveType *type() const;
 | 
			
		||||
		PrimitiveTypePointer type() const;
 | 
			
		||||
 | 
			
		||||
		ExpressionPointer normalize() override;
 | 
			
		||||
 | 
			
		||||
@@ -41,20 +41,20 @@ class Constant: public ExpressionCRTP<Constant>
 | 
			
		||||
		static ConstantPointer parseDeclaration(Context &context);
 | 
			
		||||
		static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);
 | 
			
		||||
 | 
			
		||||
		static Constant *parseAndFind(const std::string &constantName, const Constants &constants);
 | 
			
		||||
		static ConstantPointer parseAndFind(const std::string &constantName, const Constants &constants);
 | 
			
		||||
 | 
			
		||||
		Constant();
 | 
			
		||||
 | 
			
		||||
		void setDirty(bool isDirty = true);
 | 
			
		||||
		bool isDirty() const;
 | 
			
		||||
 | 
			
		||||
		void setType(const PrimitiveType *parentType);
 | 
			
		||||
		void setType(PrimitiveTypePointer parentType);
 | 
			
		||||
 | 
			
		||||
		bool m_isDirty;
 | 
			
		||||
 | 
			
		||||
		std::string m_name;
 | 
			
		||||
 | 
			
		||||
		const PrimitiveType *m_type;
 | 
			
		||||
		PrimitiveTypePointer m_type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ class NAry: public ExpressionCRTP<Derived>
 | 
			
		||||
{
 | 
			
		||||
	public:
 | 
			
		||||
		template<typename ExpressionParser>
 | 
			
		||||
		static std::unique_ptr<Derived> parse(Context &context,
 | 
			
		||||
		static boost::intrusive_ptr<Derived> parse(Context &context,
 | 
			
		||||
			ExpressionContext &expressionContext, ExpressionParser parseExpression);
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
@@ -43,7 +43,7 @@ class NAry: public ExpressionCRTP<Derived>
 | 
			
		||||
 | 
			
		||||
template<class Derived>
 | 
			
		||||
template<typename ExpressionParser>
 | 
			
		||||
std::unique_ptr<Derived> NAry<Derived>::parse(Context &context,
 | 
			
		||||
boost::intrusive_ptr<Derived> NAry<Derived>::parse(Context &context,
 | 
			
		||||
	ExpressionContext &expressionContext, ExpressionParser parseExpression)
 | 
			
		||||
{
 | 
			
		||||
	auto &parser = context.parser;
 | 
			
		||||
@@ -57,7 +57,7 @@ std::unique_ptr<Derived> NAry<Derived>::parse(Context &context,
 | 
			
		||||
		return nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto expression = std::make_unique<Derived>();
 | 
			
		||||
	auto expression = boost::intrusive_ptr<Derived>(new Derived);
 | 
			
		||||
 | 
			
		||||
	parser.skipWhiteSpace();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -57,7 +57,7 @@ NotPointer Not::parse(Context &context, ExpressionContext &expressionContext,
 | 
			
		||||
		return nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto expression = std::make_unique<Not>(Not());
 | 
			
		||||
	auto expression = NotPointer(new Not);
 | 
			
		||||
 | 
			
		||||
	context.parser.skipWhiteSpace();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ class Predicate: public ExpressionCRTP<Predicate>
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		const std::string &name() const;
 | 
			
		||||
		const std::vector<const Expression *> &arguments() const;
 | 
			
		||||
		const std::vector<ExpressionPointer> &arguments() const;
 | 
			
		||||
 | 
			
		||||
		bool isDeclared() const;
 | 
			
		||||
 | 
			
		||||
@@ -40,7 +40,7 @@ class Predicate: public ExpressionCRTP<Predicate>
 | 
			
		||||
		bool m_isDeclared;
 | 
			
		||||
 | 
			
		||||
		std::string m_name;
 | 
			
		||||
		std::vector<const Expression *> m_arguments;
 | 
			
		||||
		std::vector<ExpressionPointer> m_arguments;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 
 | 
			
		||||
@@ -26,14 +26,14 @@ class PrimitiveType: public ExpressionCRTP<PrimitiveType>
 | 
			
		||||
		static void parseDeclaration(Context &context, Domain &domain);
 | 
			
		||||
		static void parseTypedDeclaration(Context &context, Domain &domain);
 | 
			
		||||
 | 
			
		||||
		static PrimitiveType *parseAndFind(Context &context, Domain &domain);
 | 
			
		||||
		static PrimitiveTypePointer parseAndFind(Context &context, Domain &domain);
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		PrimitiveType();
 | 
			
		||||
		PrimitiveType(std::string name);
 | 
			
		||||
 | 
			
		||||
		const std::string &name() const;
 | 
			
		||||
		const std::vector<const PrimitiveType *> &parentTypes() const;
 | 
			
		||||
		const std::vector<PrimitiveTypePointer> &parentTypes() const;
 | 
			
		||||
 | 
			
		||||
		ExpressionPointer normalize() override;
 | 
			
		||||
 | 
			
		||||
@@ -45,7 +45,7 @@ class PrimitiveType: public ExpressionCRTP<PrimitiveType>
 | 
			
		||||
 | 
			
		||||
		std::string m_name;
 | 
			
		||||
 | 
			
		||||
		std::vector<const PrimitiveType *> m_parentTypes;
 | 
			
		||||
		std::vector<PrimitiveTypePointer> m_parentTypes;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 
 | 
			
		||||
@@ -1,75 +0,0 @@
 | 
			
		||||
#ifndef __PLASP__PDDL__EXPRESSIONS__REFERENCE_H
 | 
			
		||||
#define __PLASP__PDDL__EXPRESSIONS__REFERENCE_H
 | 
			
		||||
 | 
			
		||||
#include <plasp/pddl/Expression.h>
 | 
			
		||||
 | 
			
		||||
namespace plasp
 | 
			
		||||
{
 | 
			
		||||
namespace pddl
 | 
			
		||||
{
 | 
			
		||||
namespace expressions
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Reference
 | 
			
		||||
//
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
template<class Type>
 | 
			
		||||
class Reference: public ExpressionCRTP<Reference<Type>>
 | 
			
		||||
{
 | 
			
		||||
	public:
 | 
			
		||||
		static const Expression::Type ExpressionType = Expression::Type::Reference;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		Reference(Type *value);
 | 
			
		||||
 | 
			
		||||
		Type *get();
 | 
			
		||||
		const Type *get() const;
 | 
			
		||||
 | 
			
		||||
		ExpressionPointer normalize();
 | 
			
		||||
 | 
			
		||||
	protected:
 | 
			
		||||
		Type *m_value = nullptr;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
template<class Type>
 | 
			
		||||
Reference<Type>::Reference(Type *value)
 | 
			
		||||
:	m_value{value}
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
template<class Type>
 | 
			
		||||
Type *Reference<Type>::get()
 | 
			
		||||
{
 | 
			
		||||
	return m_value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
template<class Type>
 | 
			
		||||
const Type *Reference<Type>::get() const
 | 
			
		||||
{
 | 
			
		||||
	return m_value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
template<class Type>
 | 
			
		||||
ExpressionPointer Reference<Type>::normalize()
 | 
			
		||||
{
 | 
			
		||||
	return nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -16,7 +16,7 @@ namespace expressions
 | 
			
		||||
//
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const Expression *parseExistingPrimitiveType(Context &context,
 | 
			
		||||
ExpressionPointer parseExistingPrimitiveType(Context &context,
 | 
			
		||||
	ExpressionContext &expressionContext);
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 
 | 
			
		||||
@@ -24,20 +24,19 @@ class Variable: public ExpressionCRTP<Variable>
 | 
			
		||||
		static void parseTypedDeclaration(Context &context, ExpressionContext &expressionContext);
 | 
			
		||||
		static void parseTypedDeclarations(Context &context, ExpressionContext &expressionContext);
 | 
			
		||||
 | 
			
		||||
		static const Variable *parseAndFind(Context &context,
 | 
			
		||||
		static VariablePointer parseAndFind(Context &context,
 | 
			
		||||
			const ExpressionContext &expressionContext);
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		void setName(std::string name);
 | 
			
		||||
		const std::string &name() const;
 | 
			
		||||
 | 
			
		||||
		const Expression *type() const;
 | 
			
		||||
		void setType(ExpressionPointer type);
 | 
			
		||||
		ExpressionPointer type() const;
 | 
			
		||||
 | 
			
		||||
		void setDirty(bool isDirty = true);
 | 
			
		||||
		bool isDirty() const;
 | 
			
		||||
 | 
			
		||||
		void setType(const Expression *type);
 | 
			
		||||
 | 
			
		||||
		ExpressionPointer normalize() override;
 | 
			
		||||
 | 
			
		||||
	private:
 | 
			
		||||
@@ -50,10 +49,7 @@ class Variable: public ExpressionCRTP<Variable>
 | 
			
		||||
 | 
			
		||||
		std::string m_name;
 | 
			
		||||
 | 
			
		||||
		const Expression *m_type;
 | 
			
		||||
 | 
			
		||||
		// Stores "either" expression if necessary
 | 
			
		||||
		ExpressionPointer m_eitherExpression;
 | 
			
		||||
		ExpressionPointer m_type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 
 | 
			
		||||
@@ -313,7 +313,7 @@ void TranslatorASP::translateConstants(const std::string &heading, const express
 | 
			
		||||
				<< utils::String(constant->name())
 | 
			
		||||
				<< "))." << std::endl;
 | 
			
		||||
 | 
			
		||||
			const auto *type = constant->type();
 | 
			
		||||
			const auto type = constant->type();
 | 
			
		||||
 | 
			
		||||
			if (type != nullptr)
 | 
			
		||||
			{
 | 
			
		||||
@@ -366,7 +366,7 @@ void TranslatorASP::translateVariablesBody(const expressions::Variables &variabl
 | 
			
		||||
			if (variable.type()->expressionType() != Expression::Type::PrimitiveType)
 | 
			
		||||
				throw utils::TranslatorException("only primitive types supported currently");
 | 
			
		||||
 | 
			
		||||
			const auto &type = *dynamic_cast<const expressions::PrimitiveType *>(variable.type());
 | 
			
		||||
			const auto &type = dynamic_cast<const expressions::PrimitiveType &>(*variable.type());
 | 
			
		||||
 | 
			
		||||
			m_outputStream << utils::RuleName("has") << "("
 | 
			
		||||
				<< utils::Variable(variable.name()) << ", "
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@ ConstantPointer Constant::parseDeclaration(Context &context)
 | 
			
		||||
{
 | 
			
		||||
	context.parser.skipWhiteSpace();
 | 
			
		||||
 | 
			
		||||
	auto constant = std::make_unique<Constant>(Constant());
 | 
			
		||||
	auto constant = ConstantPointer(new Constant);
 | 
			
		||||
 | 
			
		||||
	constant->m_name = context.parser.parseIdentifier();
 | 
			
		||||
 | 
			
		||||
@@ -75,7 +75,7 @@ void Constant::parseTypedDeclaration(Context &context, Domain &domain, Constants
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	// If existing, parse and store parent type
 | 
			
		||||
	auto *type = PrimitiveType::parseAndFind(context, domain);
 | 
			
		||||
	auto type = PrimitiveType::parseAndFind(context, domain);
 | 
			
		||||
 | 
			
		||||
	// Assign parent type to all types that were previously flagged
 | 
			
		||||
	std::for_each(constants.begin(), constants.end(),
 | 
			
		||||
@@ -145,7 +145,7 @@ void Constant::parseTypedDeclarations(Context &context, Problem &problem)
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
Constant *Constant::parseAndFind(Context &context, const Domain &domain)
 | 
			
		||||
ConstantPointer Constant::parseAndFind(Context &context, const Domain &domain)
 | 
			
		||||
{
 | 
			
		||||
	auto &parser = context.parser;
 | 
			
		||||
 | 
			
		||||
@@ -153,7 +153,7 @@ Constant *Constant::parseAndFind(Context &context, const Domain &domain)
 | 
			
		||||
 | 
			
		||||
	const auto constantName = parser.parseIdentifier();
 | 
			
		||||
 | 
			
		||||
	auto *constant = parseAndFind(constantName, domain.constants());
 | 
			
		||||
	auto constant = parseAndFind(constantName, domain.constants());
 | 
			
		||||
 | 
			
		||||
	if (constant != nullptr)
 | 
			
		||||
		return constant;
 | 
			
		||||
@@ -163,7 +163,7 @@ Constant *Constant::parseAndFind(Context &context, const Domain &domain)
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
Constant *Constant::parseAndFind(Context &context, const Problem &problem)
 | 
			
		||||
ConstantPointer Constant::parseAndFind(Context &context, const Problem &problem)
 | 
			
		||||
{
 | 
			
		||||
	auto &parser = context.parser;
 | 
			
		||||
 | 
			
		||||
@@ -171,7 +171,7 @@ Constant *Constant::parseAndFind(Context &context, const Problem &problem)
 | 
			
		||||
 | 
			
		||||
	const auto constantName = parser.parseIdentifier();
 | 
			
		||||
 | 
			
		||||
	auto *constant = parseAndFind(constantName, problem.domain().constants());
 | 
			
		||||
	auto constant = parseAndFind(constantName, problem.domain().constants());
 | 
			
		||||
 | 
			
		||||
	if (constant)
 | 
			
		||||
		return constant;
 | 
			
		||||
@@ -186,7 +186,7 @@ Constant *Constant::parseAndFind(Context &context, const Problem &problem)
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
Constant *Constant::parseAndFind(const std::string &constantName, const Constants &constants)
 | 
			
		||||
ConstantPointer Constant::parseAndFind(const std::string &constantName, const Constants &constants)
 | 
			
		||||
{
 | 
			
		||||
	const auto match = std::find_if(constants.cbegin(), constants.cend(),
 | 
			
		||||
		[&](const auto &constant)
 | 
			
		||||
@@ -225,14 +225,14 @@ const std::string &Constant::name() const
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
void Constant::setType(const PrimitiveType *type)
 | 
			
		||||
void Constant::setType(PrimitiveTypePointer type)
 | 
			
		||||
{
 | 
			
		||||
	m_type = type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const PrimitiveType *Constant::type() const
 | 
			
		||||
PrimitiveTypePointer Constant::type() const
 | 
			
		||||
{
 | 
			
		||||
	return m_type;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,10 +26,10 @@ ExpressionPointer Imply::normalize()
 | 
			
		||||
	BOOST_ASSERT(m_argumentStorage[0]);
 | 
			
		||||
	BOOST_ASSERT(m_argumentStorage[1]);
 | 
			
		||||
 | 
			
		||||
	auto notArgument0 = std::make_unique<Not>();
 | 
			
		||||
	auto notArgument0 = NotPointer(new Not);
 | 
			
		||||
	notArgument0->setArgument(std::move(m_argumentStorage[0]));
 | 
			
		||||
 | 
			
		||||
	auto orExpression = std::make_unique<Or>();
 | 
			
		||||
	auto orExpression = OrPointer(new Or);
 | 
			
		||||
	orExpression->addArgument(std::move(notArgument0));
 | 
			
		||||
	orExpression->addArgument(std::move(m_argumentStorage[1]));
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,7 @@ PredicatePointer Predicate::parse(Context &context, ExpressionContext &expressio
 | 
			
		||||
		return nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto predicate = std::make_unique<Predicate>(Predicate());
 | 
			
		||||
	auto predicate = PredicatePointer(new Predicate);
 | 
			
		||||
 | 
			
		||||
	predicate->m_name = predicateName;
 | 
			
		||||
 | 
			
		||||
@@ -66,13 +66,13 @@ PredicatePointer Predicate::parse(Context &context, ExpressionContext &expressio
 | 
			
		||||
		// Parse variables
 | 
			
		||||
		if (context.parser.currentCharacter() == '?')
 | 
			
		||||
		{
 | 
			
		||||
			const auto *variable = Variable::parseAndFind(context, expressionContext);
 | 
			
		||||
			const auto variable = Variable::parseAndFind(context, expressionContext);
 | 
			
		||||
			predicate->m_arguments.emplace_back(variable);
 | 
			
		||||
		}
 | 
			
		||||
		// Parse constants
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			const auto *constant = (expressionContext.problem == nullptr)
 | 
			
		||||
			const auto constant = (expressionContext.problem == nullptr)
 | 
			
		||||
				? Constant::parseAndFind(context, expressionContext.domain)
 | 
			
		||||
				: Constant::parseAndFind(context, *expressionContext.problem);
 | 
			
		||||
			predicate->m_arguments.emplace_back(constant);
 | 
			
		||||
@@ -117,7 +117,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
 | 
			
		||||
		return nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	auto predicate = std::make_unique<Predicate>(Predicate());
 | 
			
		||||
	auto predicate = PredicatePointer(new Predicate);
 | 
			
		||||
 | 
			
		||||
	predicate->m_name = predicateName;
 | 
			
		||||
 | 
			
		||||
@@ -129,7 +129,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
 | 
			
		||||
			throw utils::ParserException(parser.coordinate(), "variables not allowed in this context");
 | 
			
		||||
 | 
			
		||||
		// Parse objects and constants
 | 
			
		||||
		const auto *constant = Constant::parseAndFind(context, problem);
 | 
			
		||||
		const auto constant = Constant::parseAndFind(context, problem);
 | 
			
		||||
		predicate->m_arguments.emplace_back(constant);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -163,7 +163,7 @@ const std::string &Predicate::name() const
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const std::vector<const Expression *> &Predicate::arguments() const
 | 
			
		||||
const std::vector<ExpressionPointer> &Predicate::arguments() const
 | 
			
		||||
{
 | 
			
		||||
	return m_arguments;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ void PredicateDeclaration::parse(Context &context, Domain &domain)
 | 
			
		||||
{
 | 
			
		||||
	context.parser.expect<std::string>("(");
 | 
			
		||||
 | 
			
		||||
	auto predicate = std::make_unique<PredicateDeclaration>(PredicateDeclaration());
 | 
			
		||||
	auto predicate = PredicateDeclarationPointer(new PredicateDeclaration);
 | 
			
		||||
 | 
			
		||||
	predicate->m_name = context.parser.parseIdentifier();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ void PrimitiveType::parseDeclaration(Context &context, Domain &domain)
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	types.emplace_back(std::make_unique<PrimitiveType>(typeName));
 | 
			
		||||
	types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
@@ -82,7 +82,7 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain)
 | 
			
		||||
	domain.checkRequirement(Requirement::Type::Typing);
 | 
			
		||||
 | 
			
		||||
	// If existing, parse and store parent type
 | 
			
		||||
	auto *parentType = parseAndFind(context, domain);
 | 
			
		||||
	auto parentType = parseAndFind(context, domain);
 | 
			
		||||
 | 
			
		||||
	parentType->setDirty(false);
 | 
			
		||||
 | 
			
		||||
@@ -100,7 +100,7 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain)
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
PrimitiveType *PrimitiveType::parseAndFind(Context &context, Domain &domain)
 | 
			
		||||
PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domain)
 | 
			
		||||
{
 | 
			
		||||
	auto &parser = context.parser;
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +125,7 @@ PrimitiveType *PrimitiveType::parseAndFind(Context &context, Domain &domain)
 | 
			
		||||
		if (typeName == "object" || typeName == "objects")
 | 
			
		||||
		{
 | 
			
		||||
			context.logger.logWarning(parser.coordinate(), "primitive type “" + typeName + "” should be declared");
 | 
			
		||||
			types.emplace_back(std::make_unique<expressions::PrimitiveType>(typeName));
 | 
			
		||||
			types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
			throw utils::ParserException(parser.coordinate(), "type “" + typeName + "” used but never declared");
 | 
			
		||||
@@ -162,7 +162,7 @@ const std::string &PrimitiveType::name() const
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const std::vector<const PrimitiveType *> &PrimitiveType::parentTypes() const
 | 
			
		||||
const std::vector<PrimitiveTypePointer> &PrimitiveType::parentTypes() const
 | 
			
		||||
{
 | 
			
		||||
	return m_parentTypes;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ namespace expressions
 | 
			
		||||
//
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const Expression *parseExistingPrimitiveType(Context &context, ExpressionContext &expressionContext)
 | 
			
		||||
ExpressionPointer parseExistingPrimitiveType(Context &context, ExpressionContext &expressionContext)
 | 
			
		||||
{
 | 
			
		||||
	return PrimitiveType::parseAndFind(context, expressionContext.domain);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ UnsupportedPointer Unsupported::parse(Context &context)
 | 
			
		||||
{
 | 
			
		||||
	auto &parser = context.parser;
 | 
			
		||||
 | 
			
		||||
	auto expression = std::make_unique<Unsupported>(Unsupported());
 | 
			
		||||
	auto expression = UnsupportedPointer(new Unsupported);
 | 
			
		||||
 | 
			
		||||
	parser.expect<std::string>("(");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
 | 
			
		||||
 | 
			
		||||
	parser.expect<std::string>("?");
 | 
			
		||||
 | 
			
		||||
	auto variable = std::make_unique<Variable>(Variable());
 | 
			
		||||
	auto variable = VariablePointer(new Variable);
 | 
			
		||||
 | 
			
		||||
	variable->m_name = parser.parseIdentifier();
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +58,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
 | 
			
		||||
	// Flag variable for potentially upcoming type declaration
 | 
			
		||||
	variable->setDirty();
 | 
			
		||||
 | 
			
		||||
	parameters.emplace_back(std::move(variable));
 | 
			
		||||
	parameters.emplace_back(variable);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
@@ -80,7 +80,7 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	const auto setType =
 | 
			
		||||
		[&](const auto *type)
 | 
			
		||||
		[&](ExpressionPointer type)
 | 
			
		||||
		{
 | 
			
		||||
			// Set the argument type for all previously flagged arguments
 | 
			
		||||
			std::for_each(variables.begin(), variables.end(),
 | 
			
		||||
@@ -96,17 +96,14 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
 | 
			
		||||
 | 
			
		||||
	parser.skipWhiteSpace();
 | 
			
		||||
 | 
			
		||||
	// Parse argument of "either" type (always begins with opening parenthesis)
 | 
			
		||||
	if ((variable->m_eitherExpression = Either::parse(context, expressionContext, parseExistingPrimitiveType)))
 | 
			
		||||
	{
 | 
			
		||||
		setType(variable->m_eitherExpression.get());
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	// Parse argument if it has "either" type (always begins with opening parenthesis)
 | 
			
		||||
	variable->m_type = Either::parse(context, expressionContext, parseExistingPrimitiveType);
 | 
			
		||||
 | 
			
		||||
	// Parse primitive type
 | 
			
		||||
	const auto *type = PrimitiveType::parseAndFind(context, expressionContext.domain);
 | 
			
		||||
	// Else, try parsing it as a primitive type
 | 
			
		||||
	if (!variable->m_type)
 | 
			
		||||
		variable->m_type = PrimitiveType::parseAndFind(context, expressionContext.domain);
 | 
			
		||||
 | 
			
		||||
	setType(type);
 | 
			
		||||
	setType(variable->m_type);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
@@ -138,7 +135,7 @@ void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expre
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const Variable *Variable::parseAndFind(Context &context, const ExpressionContext &expressionContext)
 | 
			
		||||
VariablePointer Variable::parseAndFind(Context &context, const ExpressionContext &expressionContext)
 | 
			
		||||
{
 | 
			
		||||
	auto &parser = context.parser;
 | 
			
		||||
 | 
			
		||||
@@ -178,7 +175,14 @@ const std::string &Variable::name() const
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const Expression *Variable::type() const
 | 
			
		||||
void Variable::setType(ExpressionPointer type)
 | 
			
		||||
{
 | 
			
		||||
	m_type = type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
ExpressionPointer Variable::type() const
 | 
			
		||||
{
 | 
			
		||||
	return m_type;
 | 
			
		||||
}
 | 
			
		||||
@@ -199,13 +203,6 @@ bool Variable::isDirty() const
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
void Variable::setType(const Expression *type)
 | 
			
		||||
{
 | 
			
		||||
	m_type = type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
ExpressionPointer Variable::normalize()
 | 
			
		||||
{
 | 
			
		||||
	return nullptr;
 | 
			
		||||
 
 | 
			
		||||
@@ -11,14 +11,14 @@ using namespace plasp::pddl;
 | 
			
		||||
 | 
			
		||||
TEST(PDDLNormalizationTests, Implication)
 | 
			
		||||
{
 | 
			
		||||
	auto i = std::make_unique<expressions::Imply>();
 | 
			
		||||
	auto d1 = std::make_unique<expressions::Dummy>();
 | 
			
		||||
	auto i = expressions::ImplyPointer(new expressions::Imply);
 | 
			
		||||
	auto d1 = expressions::DummyPointer(new expressions::Dummy);
 | 
			
		||||
	const auto d1p = d1.get();
 | 
			
		||||
	auto d2 = std::make_unique<expressions::Dummy>();
 | 
			
		||||
	auto d2 = expressions::DummyPointer(new expressions::Dummy);
 | 
			
		||||
	const auto d2p = d2.get();
 | 
			
		||||
 | 
			
		||||
	i->setArgument<0>(std::move(d1));
 | 
			
		||||
	i->setArgument<1>(std::move(d2));
 | 
			
		||||
	i->setArgument<0>(d1);
 | 
			
		||||
	i->setArgument<1>(d2);
 | 
			
		||||
 | 
			
		||||
	auto normalized = i->normalize();
 | 
			
		||||
 | 
			
		||||
@@ -40,9 +40,9 @@ TEST(PDDLNormalizationTests, Implication)
 | 
			
		||||
 | 
			
		||||
TEST(PDDLNormalizationTests, DoubleNegation)
 | 
			
		||||
{
 | 
			
		||||
	auto n1 = std::make_unique<expressions::Not>();
 | 
			
		||||
	auto n2 = std::make_unique<expressions::Not>();
 | 
			
		||||
	auto d = std::make_unique<expressions::Dummy>();
 | 
			
		||||
	auto n1 = expressions::NotPointer(new expressions::Not);
 | 
			
		||||
	auto n2 = expressions::NotPointer(new expressions::Not);
 | 
			
		||||
	auto d = expressions::DummyPointer(new expressions::Dummy);
 | 
			
		||||
	const auto dp = d.get();
 | 
			
		||||
 | 
			
		||||
	n2->setArgument(std::move(d));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user