Big refactoring (build still broken).
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__CONSTANT_H
|
||||
#define __PLASP__PDDL__CONSTANT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Type.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constant
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Constant
|
||||
{
|
||||
public:
|
||||
static Constant &parse(utils::Parser &parser, Context &context);
|
||||
static Constant &parseDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const PrimitiveType *type() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
Constant(std::string name);
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setDeclared();
|
||||
|
||||
void setType(const PrimitiveType *parentType);
|
||||
|
||||
bool m_isDirty;
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
const PrimitiveType *m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -6,9 +6,10 @@
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Action.h>
|
||||
#include <plasp/pddl/Constant.h>
|
||||
#include <plasp/pddl/Predicate.h>
|
||||
#include <plasp/pddl/Type.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/expressions/Constant.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -24,16 +25,14 @@ namespace pddl
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
std::vector<std::unique_ptr<PrimitiveType>> primitiveTypes;
|
||||
std::unordered_map<std::string, PrimitiveType *> primitiveTypesHashMap;
|
||||
expressions::PrimitiveTypes primitiveTypes;
|
||||
//std::unordered_map<std::string, expressions::PrimitiveType *> primitiveTypesHashMap;
|
||||
|
||||
std::vector<std::unique_ptr<EitherType>> eitherTypes;
|
||||
expressions::Constants constants;
|
||||
//std::unordered_map<std::string, expressions::Constant *> constantsHashMap;
|
||||
|
||||
std::vector<std::unique_ptr<Constant>> constants;
|
||||
std::unordered_map<std::string, Constant *> constantsHashMap;
|
||||
|
||||
std::vector<std::unique_ptr<Predicate>> predicates;
|
||||
std::unordered_map<PredicateHashMapKey, Predicate *> predicatesHashMap;
|
||||
expressions::PredicateDeclarations predicateDeclarations;
|
||||
//std::unordered_map<expressions::PredicateHashMapKey, expressions::Predicate *> predicatesHashMap;
|
||||
|
||||
std::vector<std::unique_ptr<Action>> actions;
|
||||
};
|
||||
|
@@ -4,9 +4,8 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Predicate.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/pddl/Type.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
@@ -28,9 +27,9 @@ class Domain
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Requirements &requirements() const;
|
||||
const std::vector<std::unique_ptr<PrimitiveType>> &types() const;
|
||||
const std::vector<std::unique_ptr<Constant>> &constants() const;
|
||||
const std::vector<std::unique_ptr<Predicate>> &predicates() const;
|
||||
const expressions::PrimitiveTypes &types() const;
|
||||
const expressions::Constants &constants() const;
|
||||
const expressions::PredicateDeclarations &predicates() const;
|
||||
const std::vector<std::unique_ptr<Action>> &actions() const;
|
||||
|
||||
private:
|
||||
|
@@ -1,43 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EITHER_TYPE_H
|
||||
#define __PLASP__PDDL__EITHER_TYPE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/PrimitiveType.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// EitherType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EitherType
|
||||
{
|
||||
public:
|
||||
static EitherType &parse(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::vector<const PrimitiveType *> &allowedTypes() const;
|
||||
|
||||
private:
|
||||
EitherType() = default;
|
||||
|
||||
std::vector<const PrimitiveType *> m_allowedTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -30,6 +30,13 @@ namespace expressions
|
||||
class And;
|
||||
using AndPointer = std::unique_ptr<And>;
|
||||
|
||||
class Constant;
|
||||
using ConstantPointer = std::unique_ptr<Constant>;
|
||||
using Constants = std::vector<ConstantPointer>;
|
||||
|
||||
class Either;
|
||||
using EitherPointer = std::unique_ptr<Either>;
|
||||
|
||||
class Not;
|
||||
using NotPointer = std::unique_ptr<Not>;
|
||||
|
||||
@@ -38,6 +45,20 @@ using OrPointer = std::unique_ptr<Or>;
|
||||
|
||||
class Predicate;
|
||||
using PredicatePointer = std::unique_ptr<Predicate>;
|
||||
using Predicates = std::vector<PredicatePointer>;
|
||||
|
||||
class PredicateDeclaration;
|
||||
using PredicateDeclarationPointer = std::unique_ptr<PredicateDeclaration>;
|
||||
using PredicateDeclarations = std::vector<PredicateDeclarationPointer>;
|
||||
|
||||
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>;
|
||||
|
@@ -1,81 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__PREDICATE_H
|
||||
#define __PLASP__PDDL__PREDICATE_H
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Predicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
struct PredicateHashMapKey
|
||||
{
|
||||
std::string name;
|
||||
size_t arity;
|
||||
|
||||
bool operator==(const PredicateHashMapKey &other) const
|
||||
{
|
||||
return arity == other.arity && name == other.name;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Predicate
|
||||
{
|
||||
public:
|
||||
static Predicate &parseDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const expressions::Variables &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
Predicate(std::string name);
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
expressions::Variables m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<plasp::pddl::PredicateHashMapKey>
|
||||
{
|
||||
std::size_t operator()(const plasp::pddl::PredicateHashMapKey &key) const
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
|
||||
boost::hash_combine(seed, key.name);
|
||||
boost::hash_combine(seed, key.arity);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,59 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__PRIMITIVE_TYPE_H
|
||||
#define __PLASP__PDDL__PRIMITIVE_TYPE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrimitiveType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PrimitiveType
|
||||
{
|
||||
public:
|
||||
static PrimitiveType &parse(utils::Parser &parser, Context &context);
|
||||
static PrimitiveType &parseDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const std::vector<const PrimitiveType *> &parentTypes() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
PrimitiveType(std::string name);
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setDeclared();
|
||||
|
||||
void addParentType(const PrimitiveType *parentType);
|
||||
|
||||
bool m_isDirty;
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
std::vector<const PrimitiveType *> m_parentTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
87
include/plasp/pddl/expressions/Constant.h
Normal file
87
include/plasp/pddl/expressions/Constant.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION__CONSTANT_H
|
||||
#define __PLASP__PDDL__EXPRESSION__CONSTANT_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Identifier.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constant
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Constant: public Expression
|
||||
{
|
||||
public:
|
||||
static ConstantPointer parseDeclaration(utils::Parser &parser, Context &context);
|
||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
template<class Container>
|
||||
static Constant *parseExisting(utils::Parser &parser, const Container &constants);
|
||||
|
||||
// TODO: method for lazy creation if not existing
|
||||
|
||||
public:
|
||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||
|
||||
const std::string &name() const;
|
||||
const PrimitiveType *type() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
Constant();
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setDeclared();
|
||||
|
||||
void setType(const PrimitiveType *parentType);
|
||||
|
||||
bool m_isDirty;
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
const PrimitiveType *m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Container>
|
||||
Constant *Constant::parseExisting(utils::Parser &parser, const Container &constants)
|
||||
{
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
const auto constantName = parser.parseIdentifier(isIdentifier);
|
||||
// TODO: use hash map
|
||||
const auto match = std::find_if(constants.cbegin(), constants.cend(),
|
||||
[&](const auto &constant)
|
||||
{
|
||||
return constant->name() == constantName;
|
||||
});
|
||||
const auto constantExists = (match != constants.cend());
|
||||
|
||||
if (!constantExists)
|
||||
throw utils::ParserException(parser.row(), parser.column(), "Constant \"" + constantName + "\" used but never declared");
|
||||
|
||||
return match->get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
55
include/plasp/pddl/expressions/Either.h
Normal file
55
include/plasp/pddl/expressions/Either.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION__EITHER_H
|
||||
#define __PLASP__PDDL__EXPRESSION__EITHER_H
|
||||
|
||||
#include <plasp/pddl/expressions/NAry.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Either
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Either: public NAry
|
||||
{
|
||||
public:
|
||||
template<typename ExpressionParser>
|
||||
static EitherPointer parse(utils::Parser &parser, Context &context,
|
||||
const Variables ¶meters, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||
|
||||
private:
|
||||
Either() = default;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ExpressionParser>
|
||||
EitherPointer Either::parse(utils::Parser &parser, Context &context,
|
||||
const Variables ¶meters, ExpressionParser parseExpression)
|
||||
{
|
||||
auto expression = std::make_unique<Either>(Either());
|
||||
|
||||
expression->NAry::parse(parser, context, parameters, parseExpression);
|
||||
|
||||
if (expression->arguments().empty())
|
||||
throw ConsistencyException("\"and\" expressions should not be empty");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,10 +1,6 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION__N_ARY_H
|
||||
#define __PLASP__PDDL__EXPRESSION__N_ARY_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/ConsistencyException.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#define __PLASP__PDDL__EXPRESSION__NOT_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Predicate.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
|
@@ -2,8 +2,6 @@
|
||||
#define __PLASP__PDDL__EXPRESSION__PREDICATE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Predicate.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -27,13 +25,20 @@ class Predicate: public Expression
|
||||
public:
|
||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||
|
||||
const std::vector<const Variable *> &arguments() const;
|
||||
const std::string &name() const;
|
||||
const Expressions &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
Predicate() = default;
|
||||
Predicate();
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
std::vector<const Variable *> m_arguments;
|
||||
Expressions m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
49
include/plasp/pddl/expressions/PredicateDeclaration.h
Normal file
49
include/plasp/pddl/expressions/PredicateDeclaration.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION__PREDICATE_DECLARATION_H
|
||||
#define __PLASP__PDDL__EXPRESSION__PREDICATE_DECLARATION_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PredicateDeclaration
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PredicateDeclaration: public Expression
|
||||
{
|
||||
public:
|
||||
static void parse(utils::Parser &parser, Context &context);
|
||||
|
||||
public:
|
||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||
|
||||
const std::string &name() const;
|
||||
const Variables &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
PredicateDeclaration();
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
Variables m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
92
include/plasp/pddl/expressions/PrimitiveType.h
Normal file
92
include/plasp/pddl/expressions/PrimitiveType.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION__PRIMITIVE_TYPE_H
|
||||
#define __PLASP__PDDL__EXPRESSION__PRIMITIVE_TYPE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Identifier.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrimitiveType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PrimitiveType: public Expression
|
||||
{
|
||||
public:
|
||||
static PrimitiveTypePointer parseDeclaration(utils::Parser &parser, Context &context);
|
||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context);
|
||||
|
||||
template<class Container>
|
||||
static PrimitiveType *parseExisting(utils::Parser &parser, const Container &primitiveTypes);
|
||||
|
||||
// TODO: method for lazy creation if not existing
|
||||
|
||||
public:
|
||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||
|
||||
const std::string &name() const;
|
||||
const std::vector<const PrimitiveType *> &parentTypes() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
PrimitiveType();
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setDeclared();
|
||||
|
||||
void addParentType(const PrimitiveType *parentType);
|
||||
|
||||
bool m_isDirty;
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
std::vector<const PrimitiveType *> m_parentTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Container>
|
||||
PrimitiveType *PrimitiveType::parseExisting(utils::Parser &parser,
|
||||
const Container &primitiveTypes)
|
||||
{
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
const auto typeName = parser.parseIdentifier(isIdentifier);
|
||||
// TODO: use hash map
|
||||
const auto match = std::find_if(primitiveTypes.cbegin(), primitiveTypes.cend(),
|
||||
[&](const auto &primitiveType)
|
||||
{
|
||||
return primitiveType->name() == typeName;
|
||||
});
|
||||
const auto typeExists = (match != primitiveTypes.cend());
|
||||
|
||||
// Return existing primitive types
|
||||
if (!typeExists)
|
||||
throw utils::ParserException(parser.row(), parser.column(), "Primitive type \"" + typeName + "\" used but never declared");
|
||||
|
||||
auto *type = match->get();
|
||||
type->setDirty();
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
76
include/plasp/pddl/expressions/Reference.h
Normal file
76
include/plasp/pddl/expressions/Reference.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION__REFERENCE_H
|
||||
#define __PLASP__PDDL__EXPRESSION__REFERENCE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/ExpressionVisitor.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Reference
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Type>
|
||||
class Reference: public Expression
|
||||
{
|
||||
public:
|
||||
Reference(const Type *value);
|
||||
|
||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||
|
||||
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>
|
||||
void Reference<Type>::accept(plasp::pddl::ExpressionVisitor &expressionVisitor) const
|
||||
{
|
||||
expressionVisitor.visit(*this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Type>
|
||||
const Type *Reference<Type>::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,16 +1,18 @@
|
||||
#ifndef __PLASP__PDDL__TYPE_H
|
||||
#define __PLASP__PDDL__TYPE_H
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__TYPE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__TYPE_H
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#include <plasp/pddl/EitherType.h>
|
||||
#include <plasp/pddl/PrimitiveType.h>
|
||||
#include <plasp/pddl/expressions/Either.h>
|
||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -18,16 +20,12 @@ namespace pddl
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using TypePtr = boost::variant<const PrimitiveType *, const EitherType *>;
|
||||
|
||||
TypePtr parseType(utils::Parser &parser, Context &context);
|
||||
ExpressionPointer parseExistingPrimitiveType(utils::Parser &parser, Context &context, const Variables ¶meters);
|
||||
//ExpressionPointer parseExistingType(utils::Parser &parser, Context &context, const Variables ¶meters);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#define __PLASP__PDDL__EXPRESSION__VARIABLE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Type.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -21,21 +20,22 @@ class Variable: public Expression
|
||||
{
|
||||
public:
|
||||
static VariablePointer parseDeclaration(utils::Parser &parser);
|
||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context,
|
||||
Variables &variables);
|
||||
|
||||
static const Variable *parse(utils::Parser &parser, const Variables &variables);
|
||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context,
|
||||
Variables ¶meters);
|
||||
|
||||
static const Variable *parseExisting(utils::Parser &parser, const Variables &variables);
|
||||
|
||||
public:
|
||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||
|
||||
const std::string &name() const;
|
||||
TypePtr type() const;
|
||||
const Expression *type() const;
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setType(TypePtr type);
|
||||
void setType(const Expression *type);
|
||||
|
||||
private:
|
||||
Variable();
|
||||
@@ -44,7 +44,10 @@ class Variable: public Expression
|
||||
|
||||
std::string m_name;
|
||||
|
||||
TypePtr m_type;
|
||||
const Expression *m_type;
|
||||
|
||||
// Stores "either" expression if necessary
|
||||
ExpressionPointer m_eitherExpression;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user