Removed Reference expressions.
This commit is contained in:
@@ -59,11 +59,6 @@ class PrimitiveType;
|
||||
using PrimitiveTypePointer = std::unique_ptr<PrimitiveType>;
|
||||
using PrimitiveTypes = std::vector<PrimitiveTypePointer>;
|
||||
|
||||
template<class Type>
|
||||
class Reference;
|
||||
template<class Type>
|
||||
using ReferencePointer = std::unique_ptr<Reference<Type>>;
|
||||
|
||||
class Variable;
|
||||
using VariablePointer = std::unique_ptr<Variable>;
|
||||
using Variables = std::vector<VariablePointer>;
|
||||
@@ -86,7 +81,6 @@ class Expression
|
||||
PredicateDeclaration,
|
||||
Predicate,
|
||||
PrimitiveType,
|
||||
Reference,
|
||||
Variable
|
||||
};
|
||||
|
||||
|
@@ -29,12 +29,16 @@ class Binary: public ExpressionCRTP<Derived>
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
const Expression *leftArgument() const;
|
||||
const Expression *rightArgument() const;
|
||||
const std::array<const Expression *, 2> &arguments() const;
|
||||
|
||||
private:
|
||||
ExpressionPointer m_leftArgument;
|
||||
ExpressionPointer m_rightArgument;
|
||||
template<size_t i>
|
||||
void setArgument(const Expression *argument);
|
||||
template<size_t i>
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
|
||||
std::array<const Expression *, 2> m_arguments;
|
||||
std::array<ExpressionPointer, 2> m_argumentStorage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -59,8 +63,8 @@ std::unique_ptr<Derived> Binary<Derived>::parse(Context &context,
|
||||
|
||||
// Assume that expression identifier (imply, exists, etc.) is already parsed
|
||||
// Parse arguments of the expression
|
||||
expression->m_leftArgument = parseExpression(context, expressionContext);
|
||||
expression->m_rightArgument = parseExpression(context, expressionContext);
|
||||
expression->setArgument<0>(parseExpression(context, expressionContext));
|
||||
expression->setArgument<1>(parseExpression(context, expressionContext));
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
@@ -70,17 +74,33 @@ std::unique_ptr<Derived> Binary<Derived>::parse(Context &context,
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const Expression *Binary<Derived>::leftArgument() const
|
||||
template<size_t i>
|
||||
void Binary<Derived>::setArgument(const Expression *expression)
|
||||
{
|
||||
return m_leftArgument.get();
|
||||
static_assert(i <= 2, "Index out of range");
|
||||
|
||||
m_argumentStorage[i] = nullptr;
|
||||
m_arguments[i] = expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const Expression *Binary<Derived>::rightArgument() const
|
||||
template<size_t i>
|
||||
void Binary<Derived>::setArgument(ExpressionPointer &&expression)
|
||||
{
|
||||
return m_rightArgument.get();
|
||||
static_assert(i <= 2, "Index out of range");
|
||||
|
||||
m_argumentStorage[i] = std::move(expression);
|
||||
m_arguments[i] = m_argumentStorage[i].get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const std::array<const Expression *, 2> &Binary<Derived>::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -29,10 +29,14 @@ class NAry: public ExpressionCRTP<Derived>
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
const Expressions &arguments() const;
|
||||
const std::vector<const Expression *> &arguments() const;
|
||||
|
||||
private:
|
||||
Expressions m_arguments;
|
||||
void addArgument(const Expression *argument);
|
||||
void addArgument(ExpressionPointer &&argument);
|
||||
|
||||
std::vector<const Expression *> m_arguments;
|
||||
Expressions m_argumentStorage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -61,7 +65,7 @@ std::unique_ptr<Derived> NAry<Derived>::parse(Context &context,
|
||||
// Parse arguments of the expression
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
expression->m_arguments.emplace_back(parseExpression(context, expressionContext));
|
||||
expression->addArgument(parseExpression(context, expressionContext));
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
}
|
||||
@@ -77,7 +81,24 @@ std::unique_ptr<Derived> NAry<Derived>::parse(Context &context,
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const Expressions &NAry<Derived>::arguments() const
|
||||
void NAry<Derived>::addArgument(const Expression *argument)
|
||||
{
|
||||
m_arguments.emplace_back(argument);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
void NAry<Derived>::addArgument(ExpressionPointer &&argument)
|
||||
{
|
||||
m_argumentStorage.emplace_back(std::move(argument));
|
||||
m_arguments.emplace_back(m_argumentStorage.back().get());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const std::vector<const Expression *> &NAry<Derived>::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
@@ -28,10 +28,16 @@ class Not: public ExpressionCRTP<Not>
|
||||
ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
const Expression &argument() const;
|
||||
Not();
|
||||
|
||||
const Expression *argument() const;
|
||||
|
||||
private:
|
||||
ExpressionPointer m_argument;
|
||||
void setArgument(const Expression *argument);
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
|
||||
const Expression *m_argument;
|
||||
ExpressionPointer m_argumentStorage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -56,7 +62,7 @@ NotPointer Not::parse(Context &context, ExpressionContext &expressionContext,
|
||||
context.parser.skipWhiteSpace();
|
||||
|
||||
// Parse argument
|
||||
expression->m_argument = parseExpression(context, expressionContext);
|
||||
expression->setArgument(parseExpression(context, expressionContext));
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
|
@@ -26,7 +26,7 @@ class Predicate: public ExpressionCRTP<Predicate>
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Expressions &arguments() const;
|
||||
const std::vector<const Expression *> &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
@@ -38,7 +38,7 @@ class Predicate: public ExpressionCRTP<Predicate>
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
Expressions m_arguments;
|
||||
std::vector<const Expression *> m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -1,70 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__REFERENCE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__REFERENCE_H
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Reference
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: refactor without reference wrapper
|
||||
template<class Type>
|
||||
class Reference: public ExpressionCRTP<Reference<Type>>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Reference;
|
||||
|
||||
Reference(const Type *value);
|
||||
|
||||
const Type *value() const;
|
||||
|
||||
private:
|
||||
Reference();
|
||||
|
||||
const Type *m_value;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Type>
|
||||
Reference<Type>::Reference()
|
||||
: m_value{nullptr}
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Type>
|
||||
Reference<Type>::Reference(const Type *value)
|
||||
: m_value{value}
|
||||
{
|
||||
BOOST_ASSERT(m_value != nullptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Type>
|
||||
const Type *Reference<Type>::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -16,7 +16,7 @@ namespace expressions
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer parseExistingPrimitiveType(Context &context,
|
||||
const Expression *parseExistingPrimitiveType(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user