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