From 696697fdc41f56392ace4559a503fb06392d2894 Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Sat, 13 Apr 2024 11:52:48 +0200 Subject: [PATCH] refactor namespaces --- benchmarks/iterate_atoms.cpp | 14 +- benchmarks/utils.cpp | 55 ++-- benchmarks/utils.hpp | 2 +- examples/position_cache.cpp | 8 +- examples/undefined_behavior.cpp | 2 +- include/loki/parser.hpp | 8 +- include/loki/pddl/action.hpp | 4 +- include/loki/pddl/atom.hpp | 4 +- include/loki/pddl/axiom.hpp | 8 +- include/loki/pddl/conditions.hpp | 20 +- include/loki/pddl/context.hpp | 4 +- include/loki/pddl/declarations.hpp | 4 - include/loki/pddl/domain.hpp | 8 +- include/loki/pddl/effects.hpp | 10 +- include/loki/pddl/exceptions.hpp | 16 +- include/loki/pddl/factories.hpp | 276 +++++++++++++++++---- include/loki/pddl/function.hpp | 8 +- include/loki/pddl/function_expressions.hpp | 20 +- include/loki/pddl/function_skeleton.hpp | 8 +- include/loki/pddl/ground_atom.hpp | 8 +- include/loki/pddl/ground_literal.hpp | 8 +- include/loki/pddl/literal.hpp | 8 +- include/loki/pddl/metric.hpp | 10 +- include/loki/pddl/numeric_fluent.hpp | 8 +- include/loki/pddl/object.hpp | 8 +- include/loki/pddl/parameter.hpp | 8 +- include/loki/pddl/parser.hpp | 4 +- include/loki/pddl/predicate.hpp | 8 +- include/loki/pddl/problem.hpp | 8 +- include/loki/pddl/reference.hpp | 2 +- include/loki/pddl/requirements.hpp | 10 +- include/loki/pddl/scope.hpp | 2 +- include/loki/pddl/term.hpp | 10 +- include/loki/pddl/type.hpp | 8 +- include/loki/pddl/variable.hpp | 8 +- include/loki/pddl/visitors.hpp | 2 +- src/parser.cpp | 22 +- src/pddl/action.cpp | 2 +- src/pddl/atom.cpp | 2 +- src/pddl/axiom.cpp | 2 +- src/pddl/conditions.cpp | 2 +- src/pddl/domain.cpp | 6 +- src/pddl/effects.cpp | 4 +- src/pddl/exceptions.cpp | 20 +- src/pddl/function.cpp | 2 +- src/pddl/function_expressions.cpp | 6 +- src/pddl/function_skeleton.cpp | 2 +- src/pddl/ground_atom.cpp | 2 +- src/pddl/ground_literal.cpp | 2 +- src/pddl/literal.cpp | 2 +- src/pddl/metric.cpp | 4 +- src/pddl/numeric_fluent.cpp | 2 +- src/pddl/object.cpp | 2 +- src/pddl/parameter.cpp | 7 +- src/pddl/parser.cpp | 82 +++--- src/pddl/parser/common.cpp | 28 +-- src/pddl/parser/common.hpp | 14 +- src/pddl/parser/conditions.cpp | 142 +++++------ src/pddl/parser/conditions.hpp | 60 ++--- src/pddl/parser/constants.cpp | 32 +-- src/pddl/parser/constants.hpp | 8 +- src/pddl/parser/effects.cpp | 66 ++--- src/pddl/parser/effects.hpp | 38 +-- src/pddl/parser/functions.cpp | 135 +++++----- src/pddl/parser/functions.hpp | 80 +++--- src/pddl/parser/goal.cpp | 2 +- src/pddl/parser/goal.hpp | 2 +- src/pddl/parser/ground_literal.cpp | 35 ++- src/pddl/parser/ground_literal.hpp | 20 +- src/pddl/parser/initial.cpp | 32 +-- src/pddl/parser/initial.hpp | 14 +- src/pddl/parser/literal.cpp | 34 +-- src/pddl/parser/literal.hpp | 20 +- src/pddl/parser/metric.cpp | 25 +- src/pddl/parser/metric.hpp | 20 +- src/pddl/parser/objects.cpp | 32 +-- src/pddl/parser/objects.hpp | 10 +- src/pddl/parser/parameters.cpp | 28 +-- src/pddl/parser/parameters.hpp | 6 +- src/pddl/parser/predicates.cpp | 20 +- src/pddl/parser/predicates.hpp | 4 +- src/pddl/parser/reference_utils.cpp | 24 +- src/pddl/parser/reference_utils.hpp | 16 +- src/pddl/parser/requirements.cpp | 170 +++++++------ src/pddl/parser/requirements.hpp | 46 ++-- src/pddl/parser/structure.cpp | 22 +- src/pddl/parser/structure.hpp | 12 +- src/pddl/parser/types.cpp | 66 ++--- src/pddl/parser/types.hpp | 28 +-- src/pddl/predicate.cpp | 2 +- src/pddl/problem.cpp | 4 +- src/pddl/requirements.cpp | 4 +- src/pddl/term.cpp | 2 +- src/pddl/type.cpp | 2 +- src/pddl/variable.cpp | 2 +- tests/unit/pddl/reference.cpp | 6 +- tests/unit/utils/persistent_factory.cpp | 8 +- 97 files changed, 1062 insertions(+), 1031 deletions(-) diff --git a/benchmarks/iterate_atoms.cpp b/benchmarks/iterate_atoms.cpp index 450f9860..b7a8411f 100644 --- a/benchmarks/iterate_atoms.cpp +++ b/benchmarks/iterate_atoms.cpp @@ -29,15 +29,15 @@ namespace loki::benchmarks struct AtomAccessResult { int atom_identifier; - loki::pddl::Predicate atom_predicate; - loki::pddl::TermList atom_terms; + loki::Predicate atom_predicate; + loki::TermList atom_terms; }; -static AtomAccessResult access_atom_data(const loki::pddl::Atom& atom) +static AtomAccessResult access_atom_data(const loki::Atom& atom) { const auto atom_identifier = atom->get_identifier(); const auto atom_predicate = atom->get_predicate(); - auto atom_terms = loki::pddl::TermList(); + auto atom_terms = loki::TermList(); for (const auto& term : atom->get_terms()) { atom_terms.push_back(term); @@ -70,7 +70,7 @@ static void BM_IterateAtoms(benchmark::State& state) } } - state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::pddl::ActionImpl)); + state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::ActionImpl)); } static void BM_RandomlyIterateAtoms(benchmark::State& state) @@ -98,13 +98,13 @@ static void BM_RandomlyIterateAtoms(benchmark::State& state) } } - state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::pddl::ActionImpl)); + state.SetBytesProcessed(state.iterations() * atoms.size() * sizeof(loki::ActionImpl)); } } // Tetralith has Intel Xeon Gold 6130 with L1=512KB, L2=8192KB, L3=22528KB -// sizeof(loki::pddl::AtomImpl)=56 => 9142 fit into L1, 146285 fit into L2, 402285 fit into L3 +// sizeof(loki::AtomImpl)=56 => 9142 fit into L1, 146285 fit into L2, 402285 fit into L3 // we just choose some reasonable numbers that can be observed in planning tasks BENCHMARK(loki::benchmarks::BM_IterateAtoms)->Arg(100); // small tasks diff --git a/benchmarks/utils.cpp b/benchmarks/utils.cpp index 8d5e993b..71c95bf9 100644 --- a/benchmarks/utils.cpp +++ b/benchmarks/utils.cpp @@ -1,47 +1,38 @@ #include "utils.hpp" -namespace loki::benchmarks { +namespace loki::benchmarks +{ -loki::pddl::AtomList create_atoms( - size_t num_objects, - size_t num_predicates, - loki::PDDLFactories& factories) { +loki::AtomList create_atoms(size_t num_objects, size_t num_predicates, loki::PDDLFactories& factories) +{ // Create num_objects-many objects with name object_1,...,object_ - auto objects = loki::pddl::ObjectList(); - for (size_t i = 1; i <= num_objects; ++i) { - objects.push_back(factories.objects.get_or_create( - ("object_" + std::to_string(i)), pddl::TypeList()) - ); + auto objects = loki::ObjectList(); + for (size_t i = 1; i <= num_objects; ++i) + { + objects.push_back(factories.get_or_create_object(("object_" + std::to_string(i)), TypeList())); } // Create num_predicates-many binary predicates with name predicate_1,...,predicate_ - auto parameters = loki::pddl::ParameterList{ - factories.parameters.get_or_create( - factories.variables.get_or_create("?variable_left"), - loki::pddl::TypeList{}), - factories.parameters.get_or_create( - factories.variables.get_or_create("?variable_right"), - loki::pddl::TypeList{}) - }; + auto parameters = loki::ParameterList { factories.get_or_create_parameter(factories.get_or_create_variable("?variable_left"), loki::TypeList {}), + factories.get_or_create_parameter(factories.get_or_create_variable("?variable_right"), loki::TypeList {}) }; - auto predicates = loki::pddl::PredicateList(); - for (size_t i = 1; i <= num_predicates; ++i) { - predicates.push_back(factories.predicates.get_or_create( - ("predicate_" + std::to_string(i)), - parameters)); + auto predicates = loki::PredicateList(); + for (size_t i = 1; i <= num_predicates; ++i) + { + predicates.push_back(factories.get_or_create_predicate(("predicate_" + std::to_string(i)), parameters)); } - auto atoms = loki::pddl::AtomList(); + auto atoms = loki::AtomList(); // Construct num_objects^2 * num_predicates many atoms - for (const auto& predicate : predicates) { - for (const auto& object_left : objects) { - for (const auto& object_right : objects) { - atoms.push_back(factories.atoms.get_or_create( + for (const auto& predicate : predicates) + { + for (const auto& object_left : objects) + { + for (const auto& object_right : objects) + { + atoms.push_back(factories.get_or_create_atom( predicate, - loki::pddl::TermList{ - factories.terms.get_or_create(object_left), - factories.terms.get_or_create(object_right) - })); + loki::TermList { factories.get_or_create_term_object(object_left), factories.get_or_create_term_object(object_right) })); } } } diff --git a/benchmarks/utils.hpp b/benchmarks/utils.hpp index c6d695e9..c24d1874 100644 --- a/benchmarks/utils.hpp +++ b/benchmarks/utils.hpp @@ -24,7 +24,7 @@ namespace loki::benchmarks { -extern loki::pddl::AtomList create_atoms(size_t num_objects, size_t num_predicates, PDDLFactories& factories); +extern loki::AtomList create_atoms(size_t num_objects, size_t num_predicates, PDDLFactories& factories); } #endif \ No newline at end of file diff --git a/examples/position_cache.cpp b/examples/position_cache.cpp index 4ae28d6e..2fe6d298 100644 --- a/examples/position_cache.cpp +++ b/examples/position_cache.cpp @@ -42,19 +42,19 @@ struct TestUnsupportedAndConditionVisitor } /// @brief For inner nodes we need to recursively call the visitor - void operator()(const loki::pddl::ConditionOrImpl& node) + void operator()(const loki::ConditionOrImpl& node) { for (const auto& child_node : node.get_conditions()) { // We call front() to obtain the first occurence. - const auto child_position = position_cache.get(child_node).front(); + const auto child_position = position_cache.get(child_node).front(); std::visit(TestUnsupportedAndConditionVisitor(child_position, position_cache, error_handler), *child_node); } } /// @brief For the unsupported And-Condition, /// we print an clang-style error message and throw an exception. - void operator()(const loki::pddl::ConditionAndImpl&) + void operator()(const loki::ConditionAndImpl&) { std::cout << error_handler(position, "Your awesome error message.") << std::endl; throw std::runtime_error("Unexpected And-Condition."); @@ -80,7 +80,7 @@ int main() continue; } // We call front() to obtain the first occurence. - auto condition_position = position_cache.get(condition.value()).front(); + auto condition_position = position_cache.get(condition.value()).front(); std::visit(TestUnsupportedAndConditionVisitor(condition_position, position_cache, error_handler), *condition.value()); } diff --git a/examples/undefined_behavior.cpp b/examples/undefined_behavior.cpp index d95656a1..43790d3f 100644 --- a/examples/undefined_behavior.cpp +++ b/examples/undefined_behavior.cpp @@ -21,7 +21,7 @@ /// @brief This example illustrates incorrect ownership handling int main() { - auto domain = loki::pddl::Domain { nullptr }; + auto domain = loki::Domain { nullptr }; { // Parse the domain auto domain_parser = loki::DomainParser("data/gripper/domain.pddl"); diff --git a/include/loki/parser.hpp b/include/loki/parser.hpp index 29f4f7d7..5d3d6e6b 100644 --- a/include/loki/parser.hpp +++ b/include/loki/parser.hpp @@ -40,7 +40,7 @@ class DomainParser std::unique_ptr m_scopes; // Parsed result - pddl::Domain m_domain; + Domain m_domain; friend class ProblemParser; @@ -54,7 +54,7 @@ class DomainParser const PDDLPositionCache& get_position_cache() const; /// @brief Get the parsed domain. - const pddl::Domain& get_domain() const; + const Domain& get_domain() const; }; class ProblemParser @@ -70,7 +70,7 @@ class ProblemParser std::unique_ptr m_scopes; // Parsed result - pddl::Problem m_problem; + Problem m_problem; public: explicit ProblemParser(const fs::path& file_path, DomainParser& domain_parser); @@ -79,7 +79,7 @@ class ProblemParser const PDDLPositionCache& get_position_cache() const; /// @brief Get the parsed problem. - const pddl::Problem& get_problem() const; + const Problem& get_problem() const; }; } diff --git a/include/loki/pddl/action.hpp b/include/loki/pddl/action.hpp index 5efaf763..328c2765 100644 --- a/include/loki/pddl/action.hpp +++ b/include/loki/pddl/action.hpp @@ -25,7 +25,7 @@ #include #include -namespace loki::pddl +namespace loki { class ActionImpl : public Base { @@ -38,7 +38,7 @@ class ActionImpl : public Base ActionImpl(int identifier, std::string name, ParameterList parameters, std::optional condition, std::optional effect); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for structural equivalence bool is_structurally_equivalent_to_impl(const ActionImpl& other) const; diff --git a/include/loki/pddl/atom.hpp b/include/loki/pddl/atom.hpp index 25420d64..a03781d3 100644 --- a/include/loki/pddl/atom.hpp +++ b/include/loki/pddl/atom.hpp @@ -24,7 +24,7 @@ #include -namespace loki::pddl +namespace loki { class AtomImpl : public Base { @@ -35,7 +35,7 @@ class AtomImpl : public Base AtomImpl(int identifier, Predicate predicate, TermList terms); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const AtomImpl& other) const; diff --git a/include/loki/pddl/axiom.hpp b/include/loki/pddl/axiom.hpp index a37a92d8..4b53a5e0 100644 --- a/include/loki/pddl/axiom.hpp +++ b/include/loki/pddl/axiom.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class AxiomImpl : public Base { private: @@ -41,7 +35,7 @@ class AxiomImpl : public Base AxiomImpl(int identifier, Literal literal, Condition condition); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for structural equivalence bool is_structurally_equivalent_to_impl(const AxiomImpl& other) const; diff --git a/include/loki/pddl/conditions.hpp b/include/loki/pddl/conditions.hpp index 4c588f7d..e14e5c5b 100644 --- a/include/loki/pddl/conditions.hpp +++ b/include/loki/pddl/conditions.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ /* Literal */ class ConditionLiteralImpl : public Base @@ -42,7 +36,7 @@ class ConditionLiteralImpl : public Base ConditionLiteralImpl(int identifier, Literal literal); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const ConditionLiteralImpl& other) const; size_t hash_impl() const; @@ -64,7 +58,7 @@ class ConditionAndImpl : public Base ConditionAndImpl(int identifier, ConditionList conditions); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const ConditionAndImpl& other) const; size_t hash_impl() const; @@ -86,7 +80,7 @@ class ConditionOrImpl : public Base ConditionOrImpl(int identifier, ConditionList conditions); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const ConditionOrImpl& other) const; size_t hash_impl() const; @@ -108,7 +102,7 @@ class ConditionNotImpl : public Base ConditionNotImpl(int identifier, Condition condition); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const ConditionNotImpl& other) const; size_t hash_impl() const; @@ -131,7 +125,7 @@ class ConditionImplyImpl : public Base ConditionImplyImpl(int identifier, Condition condition_left, Condition condition_right); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const ConditionImplyImpl& other) const; size_t hash_impl() const; @@ -155,7 +149,7 @@ class ConditionExistsImpl : public Base ConditionExistsImpl(int identifier, ParameterList parameters, Condition condition); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const ConditionExistsImpl& other) const; size_t hash_impl() const; @@ -179,7 +173,7 @@ class ConditionForallImpl : public Base ConditionForallImpl(int identifier, ParameterList parameters, Condition condition); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const ConditionForallImpl& other) const; size_t hash_impl() const; diff --git a/include/loki/pddl/context.hpp b/include/loki/pddl/context.hpp index 9ac3e62e..3f37ca01 100644 --- a/include/loki/pddl/context.hpp +++ b/include/loki/pddl/context.hpp @@ -37,8 +37,8 @@ struct Context // For checking that certain PDDL objects were referenced at least once ReferencedPDDLObjects references; // For convenience, to avoid an additional parameter during semantic parsing - pddl::Requirements requirements; - std::unordered_set derived_predicates; + Requirements requirements; + std::unordered_set derived_predicates; Context(PDDLFactories& factories_, PDDLPositionCache& positions_, ScopeStack& scopes_) : factories(factories_), diff --git a/include/loki/pddl/declarations.hpp b/include/loki/pddl/declarations.hpp index 52ea218e..3c962c19 100644 --- a/include/loki/pddl/declarations.hpp +++ b/include/loki/pddl/declarations.hpp @@ -32,10 +32,6 @@ namespace loki */ template using PDDLElement = const T*; -} - -namespace loki::pddl -{ /** * Domain diff --git a/include/loki/pddl/domain.hpp b/include/loki/pddl/domain.hpp index 62cbdf8d..e93e749a 100644 --- a/include/loki/pddl/domain.hpp +++ b/include/loki/pddl/domain.hpp @@ -27,12 +27,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class DomainImpl : public Base { @@ -59,7 +53,7 @@ class DomainImpl : public Base AxiomList axioms); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for structural equivalence bool is_structurally_equivalent_to_impl(const DomainImpl& other) const; diff --git a/include/loki/pddl/effects.hpp b/include/loki/pddl/effects.hpp index dd5cc4c9..b00ffd0d 100644 --- a/include/loki/pddl/effects.hpp +++ b/include/loki/pddl/effects.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ enum class AssignOperatorEnum { ASSIGN, @@ -42,7 +36,7 @@ enum class AssignOperatorEnum }; extern std::unordered_map assign_operator_enum_to_string; -extern const std::string& to_string(pddl::AssignOperatorEnum assign_operator); +extern const std::string& to_string(AssignOperatorEnum assign_operator); /* Literal */ class EffectLiteralImpl : public Base @@ -53,7 +47,7 @@ class EffectLiteralImpl : public Base EffectLiteralImpl(int identifier, Literal literal); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; // Give access to the private interface implementations. friend class Base; diff --git a/include/loki/pddl/exceptions.hpp b/include/loki/pddl/exceptions.hpp index 122d2666..827b85a4 100644 --- a/include/loki/pddl/exceptions.hpp +++ b/include/loki/pddl/exceptions.hpp @@ -127,34 +127,32 @@ class MultiDefinitionFunctionSkeletonError : public SemanticParserError class UnusedRequirementError : public SemanticParserError { public: - UnusedRequirementError(pddl::RequirementEnum requirement, const std::string& error_handler_output); + UnusedRequirementError(RequirementEnum requirement, const std::string& error_handler_output); }; class UndefinedRequirementError : public SemanticParserError { public: - UndefinedRequirementError(pddl::RequirementEnum requirement, const std::string& error_handler_output); + UndefinedRequirementError(RequirementEnum requirement, const std::string& error_handler_output); }; class UnsupportedRequirementError : public std::runtime_error { public: - explicit UnsupportedRequirementError(pddl::RequirementEnum requirement, const std::string& error_handler_output); + explicit UnsupportedRequirementError(RequirementEnum requirement, const std::string& error_handler_output); }; /* Compatibility errors */ class MismatchedPredicateTermListError : public SemanticParserError { public: - MismatchedPredicateTermListError(const pddl::Predicate& predicate, const pddl::TermList& term_list, const std::string& error_handler_output); + MismatchedPredicateTermListError(const Predicate& predicate, const TermList& term_list, const std::string& error_handler_output); }; class MismatchedFunctionSkeletonTermListError : public SemanticParserError { public: - MismatchedFunctionSkeletonTermListError(const pddl::FunctionSkeleton& function_skeleton, - const pddl::TermList& term_list, - const std::string& error_handler_output); + MismatchedFunctionSkeletonTermListError(const FunctionSkeleton& function_skeleton, const TermList& term_list, const std::string& error_handler_output); }; class UnexpectedDerivedPredicateInEffect : public SemanticParserError @@ -192,13 +190,13 @@ class MultiDefinitionObjectError : public SemanticParserError class MismatchedDomainError : public SemanticParserError { public: - MismatchedDomainError(const pddl::Domain& domain, const std::string& domain_name, const std::string& error_handler_output); + MismatchedDomainError(const Domain& domain, const std::string& domain_name, const std::string& error_handler_output); }; class MismatchedPredicateObjectListError : public SemanticParserError { public: - MismatchedPredicateObjectListError(const pddl::Predicate& predicate, const pddl::ObjectList& object_list, const std::string& error_handler_output); + MismatchedPredicateObjectListError(const Predicate& predicate, const ObjectList& object_list, const std::string& error_handler_output); }; class NegativeCostError : public SemanticParserError diff --git a/include/loki/pddl/factories.hpp b/include/loki/pddl/factories.hpp index 4dab9e95..664f4533 100644 --- a/include/loki/pddl/factories.hpp +++ b/include/loki/pddl/factories.hpp @@ -22,6 +22,7 @@ #include "loki/pddl/atom.hpp" #include "loki/pddl/axiom.hpp" #include "loki/pddl/conditions.hpp" +#include "loki/pddl/declarations.hpp" #include "loki/pddl/domain.hpp" #include "loki/pddl/effects.hpp" #include "loki/pddl/factory.hpp" @@ -49,55 +50,56 @@ namespace loki // to avoid allocations and for continuous storage. // The values are just educated guesses based on the knowledge // that cache line size is 64 Bytes. -using RequirementFactory = PDDLFactory; -using TypeFactory = PDDLFactory; -using VariableFactory = PDDLFactory; -using TermFactory = PDDLFactory; -using ObjectFactory = PDDLFactory; -using AtomFactory = PDDLFactory; -using GroundAtomFactory = PDDLFactory; -using LiteralFactory = PDDLFactory; -using GroundLiteralFactory = PDDLFactory; -using ParameterFactory = PDDLFactory; -using PredicateFactory = PDDLFactory; -using FunctionExpressionFactory = PDDLFactory; -using FunctionFactory = PDDLFactory; -using FunctionSkeletonFactory = PDDLFactory; -using ConditionFactory = PDDLFactory; -using EffectFactory = PDDLFactory; -using ActionFactory = PDDLFactory; -using AxiomFactory = PDDLFactory; -using OptimizationMetricFactory = PDDLFactory; -using NumericFluentFactory = PDDLFactory; -using DomainFactory = PDDLFactory; -using ProblemFactory = PDDLFactory; - -using PDDLPositionCache = PositionCache; +using RequirementFactory = PDDLFactory; +using TypeFactory = PDDLFactory; +using VariableFactory = PDDLFactory; +using TermFactory = PDDLFactory; +using ObjectFactory = PDDLFactory; +using AtomFactory = PDDLFactory; +using GroundAtomFactory = PDDLFactory; +using LiteralFactory = PDDLFactory; +using GroundLiteralFactory = PDDLFactory; +using ParameterFactory = PDDLFactory; +using PredicateFactory = PDDLFactory; +using FunctionExpressionFactory = PDDLFactory; +using FunctionFactory = PDDLFactory; +using FunctionSkeletonFactory = PDDLFactory; +using ConditionFactory = PDDLFactory; +using EffectFactory = PDDLFactory; +using ActionFactory = PDDLFactory; +using AxiomFactory = PDDLFactory; +using OptimizationMetricFactory = PDDLFactory; +using NumericFluentFactory = PDDLFactory; +using DomainFactory = PDDLFactory; +using ProblemFactory = PDDLFactory; + +using PDDLPositionCache = PositionCache; /// @brief Collection of factories for the unique creation of PDDL objects. -struct PDDLFactories +class PDDLFactories { +private: RequirementFactory requirements; TypeFactory types; VariableFactory variables; @@ -122,6 +124,7 @@ struct PDDLFactories DomainFactory domains; ProblemFactory problems; +public: PDDLFactories() : requirements(RequirementFactory(100)), types(TypeFactory(1000)), @@ -154,6 +157,187 @@ struct PDDLFactories PDDLFactories& operator=(const PDDLFactories& other) = delete; PDDLFactories(PDDLFactories&& other) = delete; PDDLFactories& operator=(PDDLFactories&& other) = delete; + + Requirements get_or_create_requirements(RequirementEnumSet requirement_set) + { + return requirements.get_or_create(std::move(requirement_set)); + } + + Type get_or_create_type(std::string name, TypeList bases) { return types.get_or_create(std::move(name), std::move(bases)); } + + Variable get_or_create_variable(std::string name) { return variables.get_or_create(std::move(name)); } + + Term get_or_create_term_variable(Variable variable) { return terms.get_or_create(std::move(variable)); } + + Term get_or_create_term_object(Object object) { return terms.get_or_create(std::move(object)); } + + Object get_or_create_object(std::string name, TypeList types) { return objects.get_or_create(std::move(name), std::move(types)); } + + Atom get_or_create_atom(Predicate predicate, TermList terms) { return atoms.get_or_create(std::move(predicate), std::move(terms)); } + + GroundAtom get_or_create_ground_atom(Predicate predicate, ObjectList objects) + { + return ground_atoms.get_or_create(std::move(predicate), std::move(objects)); + } + + Literal get_or_create_literal(bool is_negated, Atom atom) { return literals.get_or_create(std::move(is_negated), std::move(atom)); } + + GroundLiteral get_or_create_ground_literal(bool is_negated, GroundAtom atom) + { + return ground_literals.get_or_create(std::move(is_negated), std::move(atom)); + } + + Parameter get_or_create_parameter(Variable variable, TypeList types) + { + return parameters.get_or_create(std::move(variable), std::move(types)); + } + + Predicate get_or_create_predicate(std::string name, ParameterList parameters) + { + return predicates.get_or_create(std::move(name), std::move(parameters)); + } + + FunctionExpression get_or_create_function_expression_number(double number) + { + return function_expressions.get_or_create(number); + } + + FunctionExpression get_or_create_function_expression_binary_operator(BinaryOperatorEnum binary_operator, + FunctionExpression left_function_expression, + FunctionExpression right_function_expression) + { + return function_expressions.get_or_create(binary_operator, + std::move(left_function_expression), + std::move(right_function_expression)); + } + + FunctionExpression get_or_create_function_expression_multi_operator(MultiOperatorEnum multi_operator, FunctionExpressionList function_expressions_) + { + return function_expressions.get_or_create(multi_operator, std::move(function_expressions_)); + } + + FunctionExpression get_or_create_function_expression_minus(FunctionExpression function_expression) + { + return function_expressions.get_or_create(std::move(function_expression)); + } + + FunctionExpression get_or_create_function_expression_function(Function function) + { + return function_expressions.get_or_create(std::move(function)); + } + + Function get_or_create_function(FunctionSkeleton function_skeleton, TermList terms) + { + return functions.get_or_create(std::move(function_skeleton), std::move(terms)); + } + + FunctionSkeleton get_or_create_function_skeleton(std::string name, ParameterList parameters, Type type) + { + return function_skeletons.get_or_create(std::move(name), std::move(parameters), std::move(type)); + } + + Condition get_or_create_condition_literal(Literal literal) { return conditions.get_or_create(std::move(literal)); } + + Condition get_or_create_condition_and(ConditionList conditions_) { return conditions.get_or_create(std::move(conditions_)); } + + Condition get_or_create_condition_or(ConditionList conditions_) { return conditions.get_or_create(std::move(conditions_)); } + + Condition get_or_create_condition_not(Condition condition) { return conditions.get_or_create(std::move(condition)); } + + Condition get_or_create_condition_imply(Condition condition_left, Condition condition_right) + { + return conditions.get_or_create(std::move(condition_left), std::move(condition_right)); + } + + Condition get_or_create_condition_exists(ParameterList parameters, Condition condition) + { + return conditions.get_or_create(std::move(parameters), std::move(condition)); + } + + Condition get_or_create_condition_forall(ParameterList parameters, Condition condition) + { + return conditions.get_or_create(std::move(parameters), std::move(condition)); + } + + Effect get_or_create_effect_literal(Literal literal) { return effects.get_or_create(std::move(literal)); } + + Effect get_or_create_effect_and(EffectList effects_) { return effects.get_or_create(std::move(effects_)); } + + Effect get_or_create_effect_numeric(AssignOperatorEnum assign_operator, Function function, FunctionExpression function_expression) + { + return effects.get_or_create(std::move(assign_operator), std::move(function), std::move(function_expression)); + } + + Effect get_or_create_effect_conditional_forall(ParameterList parameters, Effect effect) + { + return effects.get_or_create(std::move(parameters), std::move(effect)); + } + + Effect get_or_create_effect_conditional_when(Condition condition, Effect effect) + { + return effects.get_or_create(std::move(condition), std::move(effect)); + } + + Action get_or_create_action(std::string name, ParameterList parameters, std::optional condition, std::optional effect) + { + return actions.get_or_create(std::move(name), std::move(parameters), std::move(condition), std::move(effect)); + } + + Axiom get_or_create_axiom(Literal literal, Condition condition) { return axioms.get_or_create(std::move(literal), std::move(condition)); } + + OptimizationMetric get_or_create_optimization_metric(OptimizationMetricEnum metric, FunctionExpression function_expression) + { + return optimization_metrics.get_or_create(std::move(metric), std::move(function_expression)); + } + + NumericFluent get_or_create_numeric_fluent(Function function, double number) + { + return numeric_fluents.get_or_create(std::move(function), std::move(number)); + } + + Domain get_or_create_domain(std::string name, + Requirements requirements, + TypeList types, + ObjectList constants, + PredicateList predicates, + PredicateList derived_predicates, + FunctionSkeletonList functions, + ActionList actions, + AxiomList axioms) + { + return domains.get_or_create(std::move(name), + std::move(requirements), + std::move(types), + std::move(constants), + std::move(predicates), + std::move(derived_predicates), + std::move(functions), + std::move(actions), + std::move(axioms)); + } + + Problem get_or_create_problem(Domain domain, + std::string name, + Requirements requirements, + ObjectList objects, + PredicateList derived_predicates, + GroundLiteralList initial_literals, + NumericFluentList numeric_fluents, + std::optional goal_condition, + std::optional optimization_metric, + AxiomList axioms) + { + return problems.get_or_create(std::move(domain), + std::move(name), + std::move(requirements), + std::move(objects), + std::move(derived_predicates), + std::move(initial_literals), + std::move(numeric_fluents), + std::move(goal_condition), + std::move(optimization_metric), + std::move(axioms)); + } }; } diff --git a/include/loki/pddl/function.hpp b/include/loki/pddl/function.hpp index 5cb87652..e6775318 100644 --- a/include/loki/pddl/function.hpp +++ b/include/loki/pddl/function.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class FunctionImpl : public Base { private: @@ -41,7 +35,7 @@ class FunctionImpl : public Base FunctionImpl(int identifier, FunctionSkeleton function_skeleton, TermList terms); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const FunctionImpl& other) const; diff --git a/include/loki/pddl/function_expressions.hpp b/include/loki/pddl/function_expressions.hpp index 24cda084..01ae178c 100644 --- a/include/loki/pddl/function_expressions.hpp +++ b/include/loki/pddl/function_expressions.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ enum class BinaryOperatorEnum { MUL, @@ -41,7 +35,7 @@ enum class BinaryOperatorEnum }; extern std::unordered_map binary_operator_enum_to_string; -extern const std::string& to_string(pddl::BinaryOperatorEnum binary_operator); +extern const std::string& to_string(BinaryOperatorEnum binary_operator); enum class MultiOperatorEnum { @@ -50,7 +44,7 @@ enum class MultiOperatorEnum }; extern std::unordered_map multi_operator_enum_to_string; -extern const std::string& to_string(pddl::MultiOperatorEnum multi_operator); +extern const std::string& to_string(MultiOperatorEnum multi_operator); /* FunctionExpressionNumber */ class FunctionExpressionNumberImpl : public Base @@ -61,7 +55,7 @@ class FunctionExpressionNumberImpl : public Base FunctionExpressionNumberImpl(int identifier, double number); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const FunctionExpressionNumberImpl& other) const; size_t hash_impl() const; @@ -88,7 +82,7 @@ class FunctionExpressionBinaryOperatorImpl : public Base, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const FunctionExpressionBinaryOperatorImpl& other) const; size_t hash_impl() const; @@ -113,7 +107,7 @@ class FunctionExpressionMultiOperatorImpl : public Base, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const FunctionExpressionMultiOperatorImpl& other) const; size_t hash_impl() const; @@ -136,7 +130,7 @@ class FunctionExpressionMinusImpl : public Base FunctionExpressionMinusImpl(int identifier, FunctionExpression function_expression); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const FunctionExpressionMinusImpl& other) const; size_t hash_impl() const; @@ -158,7 +152,7 @@ class FunctionExpressionFunctionImpl : public Base, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const FunctionExpressionFunctionImpl& other) const; size_t hash_impl() const; diff --git a/include/loki/pddl/function_skeleton.hpp b/include/loki/pddl/function_skeleton.hpp index b99ad053..4a8735e7 100644 --- a/include/loki/pddl/function_skeleton.hpp +++ b/include/loki/pddl/function_skeleton.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class FunctionSkeletonImpl : public Base { private: @@ -42,7 +36,7 @@ class FunctionSkeletonImpl : public Base FunctionSkeletonImpl(int identifier, std::string name, ParameterList parameters, Type type); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const FunctionSkeletonImpl& other) const; diff --git a/include/loki/pddl/ground_atom.hpp b/include/loki/pddl/ground_atom.hpp index 96341f34..4d948330 100644 --- a/include/loki/pddl/ground_atom.hpp +++ b/include/loki/pddl/ground_atom.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class GroundAtomImpl : public Base { private: @@ -41,7 +35,7 @@ class GroundAtomImpl : public Base GroundAtomImpl(int identifier, Predicate predicate, ObjectList objects); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const GroundAtomImpl& other) const; diff --git a/include/loki/pddl/ground_literal.hpp b/include/loki/pddl/ground_literal.hpp index 5e4ca06d..070346ff 100644 --- a/include/loki/pddl/ground_literal.hpp +++ b/include/loki/pddl/ground_literal.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class GroundLiteralImpl : public Base { private: @@ -41,7 +35,7 @@ class GroundLiteralImpl : public Base GroundLiteralImpl(int identifier, bool is_negated, GroundAtom atom); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const GroundLiteralImpl& other) const; diff --git a/include/loki/pddl/literal.hpp b/include/loki/pddl/literal.hpp index 3b208131..2e526bb0 100644 --- a/include/loki/pddl/literal.hpp +++ b/include/loki/pddl/literal.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class LiteralImpl : public Base { private: @@ -41,7 +35,7 @@ class LiteralImpl : public Base LiteralImpl(int identifier, bool is_negated, Atom atom); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const LiteralImpl& other) const; diff --git a/include/loki/pddl/metric.hpp b/include/loki/pddl/metric.hpp index 79d94958..6ea18719 100644 --- a/include/loki/pddl/metric.hpp +++ b/include/loki/pddl/metric.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ enum class OptimizationMetricEnum { MINIMIZE, @@ -39,7 +33,7 @@ enum class OptimizationMetricEnum }; extern std::unordered_map optimization_metric_enum_to_string; -extern const std::string& to_string(pddl::OptimizationMetricEnum optimization_metric); +extern const std::string& to_string(OptimizationMetricEnum optimization_metric); class OptimizationMetricImpl : public Base { @@ -50,7 +44,7 @@ class OptimizationMetricImpl : public Base OptimizationMetricImpl(int identifier, OptimizationMetricEnum optimization_metric, FunctionExpression function_expression); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const OptimizationMetricImpl& other) const; diff --git a/include/loki/pddl/numeric_fluent.hpp b/include/loki/pddl/numeric_fluent.hpp index b36f8a96..0aa0ff7f 100644 --- a/include/loki/pddl/numeric_fluent.hpp +++ b/include/loki/pddl/numeric_fluent.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class NumericFluentImpl : public Base { private: @@ -39,7 +33,7 @@ class NumericFluentImpl : public Base double m_number; // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; NumericFluentImpl(int identifier, Function function, double number); diff --git a/include/loki/pddl/object.hpp b/include/loki/pddl/object.hpp index ea8214d7..4a1fda46 100644 --- a/include/loki/pddl/object.hpp +++ b/include/loki/pddl/object.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class ObjectImpl : public Base { private: @@ -41,7 +35,7 @@ class ObjectImpl : public Base ObjectImpl(int identifier, std::string name, TypeList types = {}); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const ObjectImpl& other) const; diff --git a/include/loki/pddl/parameter.hpp b/include/loki/pddl/parameter.hpp index a2243808..1d9a5acf 100644 --- a/include/loki/pddl/parameter.hpp +++ b/include/loki/pddl/parameter.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class ParameterImpl : public Base { @@ -42,7 +36,7 @@ class ParameterImpl : public Base ParameterImpl(int identifier, Variable variable, TypeList types); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const ParameterImpl& other) const; diff --git a/include/loki/pddl/parser.hpp b/include/loki/pddl/parser.hpp index 8a0b4975..5444e053 100644 --- a/include/loki/pddl/parser.hpp +++ b/include/loki/pddl/parser.hpp @@ -25,8 +25,8 @@ namespace loki { -extern pddl::Domain parse(const ast::Domain& domain_node, Context& context); -extern pddl::Problem parse(const ast::Problem& problem_node, Context& context, const pddl::Domain& domain); +extern Domain parse(const ast::Domain& domain_node, Context& context); +extern Problem parse(const ast::Problem& problem_node, Context& context, const Domain& domain); } diff --git a/include/loki/pddl/predicate.hpp b/include/loki/pddl/predicate.hpp index acdcf2ce..b3804860 100644 --- a/include/loki/pddl/predicate.hpp +++ b/include/loki/pddl/predicate.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ // An alternative name is AtomSkeleton class PredicateImpl : public Base @@ -43,7 +37,7 @@ class PredicateImpl : public Base PredicateImpl(int identifier, std::string name, ParameterList parameters); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const PredicateImpl& other) const; diff --git a/include/loki/pddl/problem.hpp b/include/loki/pddl/problem.hpp index 95e34707..6b3327e6 100644 --- a/include/loki/pddl/problem.hpp +++ b/include/loki/pddl/problem.hpp @@ -27,12 +27,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class ProblemImpl : public Base { private: @@ -60,7 +54,7 @@ class ProblemImpl : public Base AxiomList axioms); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const ProblemImpl& other) const; diff --git a/include/loki/pddl/reference.hpp b/include/loki/pddl/reference.hpp index 77c5d814..02051901 100644 --- a/include/loki/pddl/reference.hpp +++ b/include/loki/pddl/reference.hpp @@ -64,7 +64,7 @@ class References void untrack(T reference); }; -using ReferencedPDDLObjects = References; +using ReferencedPDDLObjects = References; } diff --git a/include/loki/pddl/requirements.hpp b/include/loki/pddl/requirements.hpp index 7670a0f2..41c6525a 100644 --- a/include/loki/pddl/requirements.hpp +++ b/include/loki/pddl/requirements.hpp @@ -28,12 +28,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ enum class RequirementEnum { STRIPS, @@ -61,7 +55,7 @@ using RequirementEnumSet = std::set; using RequirementEnumList = std::vector; extern std::unordered_map requirement_enum_to_string; -extern const std::string& to_string(pddl::RequirementEnum requirement); +extern const std::string& to_string(RequirementEnum requirement); class RequirementsImpl : public Base { @@ -71,7 +65,7 @@ class RequirementsImpl : public Base RequirementsImpl(int identifier, RequirementEnumSet requirements); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const RequirementsImpl& other) const; diff --git a/include/loki/pddl/scope.hpp b/include/loki/pddl/scope.hpp index 6d800920..04d2eecd 100644 --- a/include/loki/pddl/scope.hpp +++ b/include/loki/pddl/scope.hpp @@ -72,7 +72,7 @@ class Scope private: const Scope* m_parent_scope; - Bindings bindings; + Bindings bindings; public: explicit Scope(const Scope* parent_scope = nullptr); diff --git a/include/loki/pddl/term.hpp b/include/loki/pddl/term.hpp index fa028197..57457ab8 100644 --- a/include/loki/pddl/term.hpp +++ b/include/loki/pddl/term.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class TermObjectImpl : public Base { @@ -41,7 +35,7 @@ class TermObjectImpl : public Base TermObjectImpl(int identifier, Object object); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const TermObjectImpl& other) const; size_t hash_impl() const; @@ -62,7 +56,7 @@ class TermVariableImpl : public Base TermVariableImpl(int identifier, Variable variable); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; bool is_structurally_equivalent_to_impl(const TermVariableImpl& other) const; size_t hash_impl() const; diff --git a/include/loki/pddl/type.hpp b/include/loki/pddl/type.hpp index 6ec0987c..9d8ccf50 100644 --- a/include/loki/pddl/type.hpp +++ b/include/loki/pddl/type.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class TypeImpl : public Base { private: @@ -41,7 +35,7 @@ class TypeImpl : public Base TypeImpl(int identifier, std::string name, TypeList bases = {}); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const TypeImpl& other) const; diff --git a/include/loki/pddl/variable.hpp b/include/loki/pddl/variable.hpp index 788a4dba..1510a927 100644 --- a/include/loki/pddl/variable.hpp +++ b/include/loki/pddl/variable.hpp @@ -26,12 +26,6 @@ namespace loki { -template -class PDDLFactory; -} - -namespace loki::pddl -{ class VariableImpl : public Base { private: @@ -40,7 +34,7 @@ class VariableImpl : public Base VariableImpl(int identifier, std::string name); // Give access to the constructor. - friend class loki::PDDLFactory, loki::EqualTo>; + friend class PDDLFactory, EqualTo>; /// @brief Test for semantic equivalence bool is_structurally_equivalent_to_impl(const VariableImpl& other) const; diff --git a/include/loki/pddl/visitors.hpp b/include/loki/pddl/visitors.hpp index 4ff7a951..8aadae92 100644 --- a/include/loki/pddl/visitors.hpp +++ b/include/loki/pddl/visitors.hpp @@ -22,7 +22,7 @@ #include -namespace loki::pddl +namespace loki { struct LessComparatorVisitor { diff --git a/src/parser.cpp b/src/parser.cpp index e0c173e2..338c0290 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -61,20 +61,18 @@ DomainParser::DomainParser(const fs::path& file_path) : context.scopes.open_scope(); // Create base types. - const auto base_type_object = context.factories.types.get_or_create("object", pddl::TypeList()); - const auto base_type_number = context.factories.types.get_or_create("number", pddl::TypeList()); + const auto base_type_object = context.factories.get_or_create_type("object", TypeList()); + const auto base_type_number = context.factories.get_or_create_type("number", TypeList()); context.scopes.insert("object", base_type_object, {}); context.scopes.insert("number", base_type_number, {}); // Create equal predicate with name "=" and two parameters "?left_arg" and "?right_arg" - const auto binary_parameterlist = pddl::ParameterList { - context.factories.parameters.get_or_create(context.factories.variables.get_or_create("?left_arg"), - pddl::TypeList { base_type_object }), - context.factories.parameters.get_or_create(context.factories.variables.get_or_create("?right_arg"), - pddl::TypeList { base_type_object }) - - }; - const auto equal_predicate = context.factories.predicates.get_or_create("=", binary_parameterlist); + const auto binary_parameterlist = + ParameterList { context.factories.get_or_create_parameter(context.factories.get_or_create_variable("?left_arg"), TypeList { base_type_object }), + context.factories.get_or_create_parameter(context.factories.get_or_create_variable("?right_arg"), TypeList { base_type_object }) + + }; + const auto equal_predicate = context.factories.get_or_create_predicate("=", binary_parameterlist); context.scopes.insert("=", equal_predicate, {}); m_domain = parse(node, context); @@ -94,7 +92,7 @@ PDDLFactories& DomainParser::get_factories() { return m_factories; } const PDDLPositionCache& DomainParser::get_position_cache() const { return *m_position_cache; } -const pddl::Domain& DomainParser::get_domain() const { return m_domain; } +const Domain& DomainParser::get_domain() const { return m_domain; } ProblemParser::ProblemParser(const fs::path& file_path, DomainParser& domain_parser) : m_file_path(file_path), @@ -137,6 +135,6 @@ ProblemParser::ProblemParser(const fs::path& file_path, DomainParser& domain_par const PDDLPositionCache& ProblemParser::get_position_cache() const { return *m_position_cache; } -const pddl::Problem& ProblemParser::get_problem() const { return m_problem; } +const Problem& ProblemParser::get_problem() const { return m_problem; } } \ No newline at end of file diff --git a/src/pddl/action.cpp b/src/pddl/action.cpp index f998ead8..a37198eb 100644 --- a/src/pddl/action.cpp +++ b/src/pddl/action.cpp @@ -24,7 +24,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { ActionImpl::ActionImpl(int identifier, std::string name, ParameterList parameters, std::optional condition, std::optional effect) : Base(identifier), diff --git a/src/pddl/atom.cpp b/src/pddl/atom.cpp index 2c0fa07e..0c744b8e 100644 --- a/src/pddl/atom.cpp +++ b/src/pddl/atom.cpp @@ -23,7 +23,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { AtomImpl::AtomImpl(int identifier, Predicate predicate, TermList terms) : Base(identifier), m_predicate(std::move(predicate)), m_terms(std::move(terms)) {} diff --git a/src/pddl/axiom.cpp b/src/pddl/axiom.cpp index df81c6cd..366654aa 100644 --- a/src/pddl/axiom.cpp +++ b/src/pddl/axiom.cpp @@ -26,7 +26,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { AxiomImpl::AxiomImpl(int identifier, Literal literal, Condition condition) : Base(identifier), m_literal(std::move(literal)), m_condition(std::move(condition)) { diff --git a/src/pddl/conditions.cpp b/src/pddl/conditions.cpp index 4ef2022d..56c713b7 100644 --- a/src/pddl/conditions.cpp +++ b/src/pddl/conditions.cpp @@ -23,7 +23,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { /* Literal */ diff --git a/src/pddl/domain.cpp b/src/pddl/domain.cpp index 839288be..90b9813b 100644 --- a/src/pddl/domain.cpp +++ b/src/pddl/domain.cpp @@ -30,7 +30,7 @@ using namespace std; -namespace loki::pddl +namespace loki { DomainImpl::DomainImpl(int identifier, std::string name, @@ -91,7 +91,7 @@ void DomainImpl::str_impl(std::ostream& out, const FormattingOptions& options) c if (!m_types.empty()) { out << string(nested_options.indent, ' ') << "(:types "; - std::unordered_map> subtypes_by_parent_types; + std::unordered_map> subtypes_by_parent_types; for (const auto& type : m_types) { subtypes_by_parent_types[type->get_bases()].push_back(type); @@ -130,7 +130,7 @@ void DomainImpl::str_impl(std::ostream& out, const FormattingOptions& options) c if (!m_constants.empty()) { out << string(nested_options.indent, ' ') << "(:constants "; - std::unordered_map> constants_by_types; + std::unordered_map> constants_by_types; for (const auto& constant : m_constants) { constants_by_types[constant->get_bases()].push_back(constant); diff --git a/src/pddl/effects.cpp b/src/pddl/effects.cpp index 75056a01..ad13defe 100644 --- a/src/pddl/effects.cpp +++ b/src/pddl/effects.cpp @@ -28,7 +28,7 @@ #include -namespace loki::pddl +namespace loki { std::unordered_map assign_operator_enum_to_string = { @@ -36,7 +36,7 @@ std::unordered_map assign_operator_enum_to_stri { AssignOperatorEnum::INCREASE, "increase" }, { AssignOperatorEnum::DECREASE, "decrease" }, }; -const std::string& to_string(pddl::AssignOperatorEnum assign_operator) +const std::string& to_string(AssignOperatorEnum assign_operator) { assert(assign_operator_enum_to_string.count(assign_operator)); return assign_operator_enum_to_string.at(assign_operator); diff --git a/src/pddl/exceptions.cpp b/src/pddl/exceptions.cpp index de8e73d5..06f73e63 100644 --- a/src/pddl/exceptions.cpp +++ b/src/pddl/exceptions.cpp @@ -111,24 +111,24 @@ MultiDefinitionFunctionSkeletonError::MultiDefinitionFunctionSkeletonError(const } /* Requirement */ -UnusedRequirementError::UnusedRequirementError(pddl::RequirementEnum requirement, const std::string& error_handler_output) : +UnusedRequirementError::UnusedRequirementError(RequirementEnum requirement, const std::string& error_handler_output) : SemanticParserError("The requirement with name \""s + to_string(requirement) + "\" was never used."s, error_handler_output) { } -UndefinedRequirementError::UndefinedRequirementError(pddl::RequirementEnum requirement, const std::string& error_handler_output) : +UndefinedRequirementError::UndefinedRequirementError(RequirementEnum requirement, const std::string& error_handler_output) : SemanticParserError("Undefined requirement: "s + to_string(requirement), error_handler_output) { } -UnsupportedRequirementError::UnsupportedRequirementError(pddl::RequirementEnum requirement, const std::string& error_handler_output) : +UnsupportedRequirementError::UnsupportedRequirementError(RequirementEnum requirement, const std::string& error_handler_output) : std::runtime_error("Unsupported requirement: "s + to_string(requirement) + "\n"s + error_handler_output) { } /* Compatibility errors */ -MismatchedPredicateTermListError::MismatchedPredicateTermListError(const pddl::Predicate& predicate, - const pddl::TermList& term_list, +MismatchedPredicateTermListError::MismatchedPredicateTermListError(const Predicate& predicate, + const TermList& term_list, const std::string& error_handler_output) : SemanticParserError("Mismatched number of terms for predicate \""s + predicate->get_name() + "\" with sizes "s + std::to_string(predicate->get_parameters().size()) + "!="s + std::to_string(term_list.size()) + "."s, @@ -136,8 +136,8 @@ MismatchedPredicateTermListError::MismatchedPredicateTermListError(const pddl::P { } -MismatchedFunctionSkeletonTermListError::MismatchedFunctionSkeletonTermListError(const pddl::FunctionSkeleton& function_skeleton, - const pddl::TermList& term_list, +MismatchedFunctionSkeletonTermListError::MismatchedFunctionSkeletonTermListError(const FunctionSkeleton& function_skeleton, + const TermList& term_list, const std::string& error_handler_output) : SemanticParserError("Mismatched number of terms for function skeleton \""s + function_skeleton->get_name() + "\" with sizes "s + std::to_string(function_skeleton->get_parameters().size()) + "!="s + std::to_string(term_list.size()) + ".", @@ -175,13 +175,13 @@ MultiDefinitionObjectError::MultiDefinitionObjectError(const std::string& name, } /* Compatibility errors */ -MismatchedDomainError::MismatchedDomainError(const pddl::Domain& domain, const std::string& domain_name, const std::string& error_handler_output) : +MismatchedDomainError::MismatchedDomainError(const Domain& domain, const std::string& domain_name, const std::string& error_handler_output) : SemanticParserError("Mismatched domain names \"" + domain->get_name() + "!=" + domain_name + ".", error_handler_output) { } -MismatchedPredicateObjectListError::MismatchedPredicateObjectListError(const pddl::Predicate& predicate, - const pddl::ObjectList& object_list, +MismatchedPredicateObjectListError::MismatchedPredicateObjectListError(const Predicate& predicate, + const ObjectList& object_list, const std::string& error_handler_output) : SemanticParserError("Mismatched number of terms for predicate \"" + predicate->get_name() + "\" with sizes " + std::to_string(predicate->get_parameters().size()) + "!=" + std::to_string(object_list.size()) + ".", diff --git a/src/pddl/function.cpp b/src/pddl/function.cpp index 554e4177..b828cafd 100644 --- a/src/pddl/function.cpp +++ b/src/pddl/function.cpp @@ -22,7 +22,7 @@ #include "loki/pddl/visitors.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { FunctionImpl::FunctionImpl(int identifier, FunctionSkeleton function_skeleton, TermList terms) : Base(identifier), diff --git a/src/pddl/function_expressions.cpp b/src/pddl/function_expressions.cpp index 2c390848..912c709e 100644 --- a/src/pddl/function_expressions.cpp +++ b/src/pddl/function_expressions.cpp @@ -24,7 +24,7 @@ #include -namespace loki::pddl +namespace loki { std::unordered_map binary_operator_enum_to_string = { @@ -34,7 +34,7 @@ std::unordered_map binary_operator_enum_to_stri { BinaryOperatorEnum::DIV, "/" }, }; -const std::string& to_string(pddl::BinaryOperatorEnum binary_operator) +const std::string& to_string(BinaryOperatorEnum binary_operator) { assert(binary_operator_enum_to_string.count(binary_operator)); return binary_operator_enum_to_string.at(binary_operator); @@ -45,7 +45,7 @@ std::unordered_map multi_operator_enum_to_string { MultiOperatorEnum::PLUS, "+" }, }; -const std::string& to_string(pddl::MultiOperatorEnum multi_operator) +const std::string& to_string(MultiOperatorEnum multi_operator) { assert(multi_operator_enum_to_string.count(multi_operator)); return multi_operator_enum_to_string.at(multi_operator); diff --git a/src/pddl/function_skeleton.cpp b/src/pddl/function_skeleton.cpp index 48f62a21..b2ee838c 100644 --- a/src/pddl/function_skeleton.cpp +++ b/src/pddl/function_skeleton.cpp @@ -20,7 +20,7 @@ #include "loki/pddl/parameter.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { FunctionSkeletonImpl::FunctionSkeletonImpl(int identifier, std::string name, ParameterList parameters, Type type) : Base(identifier), diff --git a/src/pddl/ground_atom.cpp b/src/pddl/ground_atom.cpp index bf3eed8a..3cd12014 100644 --- a/src/pddl/ground_atom.cpp +++ b/src/pddl/ground_atom.cpp @@ -23,7 +23,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { GroundAtomImpl::GroundAtomImpl(int identifier, Predicate predicate, ObjectList objects) : Base(identifier), diff --git a/src/pddl/ground_literal.cpp b/src/pddl/ground_literal.cpp index 3fd02431..c2f8201a 100644 --- a/src/pddl/ground_literal.cpp +++ b/src/pddl/ground_literal.cpp @@ -21,7 +21,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { GroundLiteralImpl::GroundLiteralImpl(int identifier, bool is_negated, GroundAtom atom) : Base(identifier), m_is_negated(is_negated), m_atom(std::move(atom)) {} diff --git a/src/pddl/literal.cpp b/src/pddl/literal.cpp index 48c10622..e5496400 100644 --- a/src/pddl/literal.cpp +++ b/src/pddl/literal.cpp @@ -21,7 +21,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { LiteralImpl::LiteralImpl(int identifier, bool is_negated, Atom atom) : Base(identifier), m_is_negated(is_negated), m_atom(std::move(atom)) {} diff --git a/src/pddl/metric.cpp b/src/pddl/metric.cpp index af573199..2b2e0b6b 100644 --- a/src/pddl/metric.cpp +++ b/src/pddl/metric.cpp @@ -26,14 +26,14 @@ using namespace std; -namespace loki::pddl +namespace loki { std::unordered_map optimization_metric_enum_to_string = { { OptimizationMetricEnum::MINIMIZE, "minimize" }, { OptimizationMetricEnum::MAXIMIZE, "maximize" }, }; -const std::string& to_string(pddl::OptimizationMetricEnum optimization_metric) +const std::string& to_string(OptimizationMetricEnum optimization_metric) { assert(optimization_metric_enum_to_string.count(optimization_metric)); return optimization_metric_enum_to_string.at(optimization_metric); diff --git a/src/pddl/numeric_fluent.cpp b/src/pddl/numeric_fluent.cpp index 3d870650..4b9a38e1 100644 --- a/src/pddl/numeric_fluent.cpp +++ b/src/pddl/numeric_fluent.cpp @@ -20,7 +20,7 @@ #include "loki/pddl/function.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { NumericFluentImpl::NumericFluentImpl(int identifier, Function function, double number) : Base(identifier), m_function(std::move(function)), m_number(number) {} diff --git a/src/pddl/object.cpp b/src/pddl/object.cpp index 86998e62..1a00fe06 100644 --- a/src/pddl/object.cpp +++ b/src/pddl/object.cpp @@ -21,7 +21,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { ObjectImpl::ObjectImpl(int identifier, std::string name, TypeList types) : Base(identifier), m_name(std::move(name)), m_types(std::move(types)) {} diff --git a/src/pddl/parameter.cpp b/src/pddl/parameter.cpp index 5a8d663f..5c822dc3 100644 --- a/src/pddl/parameter.cpp +++ b/src/pddl/parameter.cpp @@ -24,12 +24,9 @@ #include -namespace loki::pddl +namespace loki { -ParameterImpl::ParameterImpl(int identifier, pddl::Variable variable, TypeList types) : - Base(identifier), - m_variable(std::move(variable)), - m_types(std::move(types)) +ParameterImpl::ParameterImpl(int identifier, Variable variable, TypeList types) : Base(identifier), m_variable(std::move(variable)), m_types(std::move(types)) { } diff --git a/src/pddl/parser.cpp b/src/pddl/parser.cpp index 3ff9c491..f2ba86b5 100644 --- a/src/pddl/parser.cpp +++ b/src/pddl/parser.cpp @@ -44,60 +44,60 @@ using namespace std; namespace loki { -pddl::Domain parse(const ast::Domain& domain_node, Context& context) +Domain parse(const ast::Domain& domain_node, Context& context) { const auto domain_name = parse(domain_node.domain_name.name); /* Requirements section */ if (domain_node.requirements.has_value()) { - context.requirements = context.factories.requirements.get_or_create(parse(domain_node.requirements.value(), context)); + context.requirements = context.factories.get_or_create_requirements(parse(domain_node.requirements.value(), context)); context.positions.push_back(context.requirements, domain_node.requirements.value()); } else { // Default requirements - context.requirements = context.factories.requirements.get_or_create(pddl::RequirementEnumSet { pddl::RequirementEnum::STRIPS }); + context.requirements = context.factories.get_or_create_requirements(RequirementEnumSet { RequirementEnum::STRIPS }); } /* Types section */ - auto types = pddl::TypeList(); + auto types = TypeList(); if (domain_node.types.has_value()) { - if (!context.requirements->test(pddl::RequirementEnum::TYPING)) + if (!context.requirements->test(RequirementEnum::TYPING)) { - throw UndefinedRequirementError(pddl::RequirementEnum::TYPING, context.scopes.get_error_handler()(domain_node.types.value(), "")); + throw UndefinedRequirementError(RequirementEnum::TYPING, context.scopes.get_error_handler()(domain_node.types.value(), "")); } types = parse(domain_node.types.value(), context); } /* Constants section */ - auto constants = pddl::ObjectList(); + auto constants = ObjectList(); if (domain_node.constants.has_value()) { constants = parse(domain_node.constants.value(), context); } /* Predicates section */ - auto predicates = pddl::PredicateList(); + auto predicates = PredicateList(); if (domain_node.predicates.has_value()) { predicates = parse(domain_node.predicates.value(), context); } track_predicate_references(predicates, context); /* DerivedPredicates section */ - auto derived_predicates = pddl::PredicateList(); + auto derived_predicates = PredicateList(); if (domain_node.derived_predicates.has_value()) { derived_predicates = parse(domain_node.derived_predicates.value(), context); } track_predicate_references(derived_predicates, context); /* Functions section */ - auto function_skeletons = pddl::FunctionSkeletonList(); + auto function_skeletons = FunctionSkeletonList(); if (domain_node.functions.has_value()) { function_skeletons = parse(domain_node.functions.value(), context); } track_function_skeleton_references(function_skeletons, context); /* Structure section */ - auto axiom_list = pddl::AxiomList(); - auto action_list = pddl::ActionList(); + auto axiom_list = AxiomList(); + auto action_list = ActionList(); for (const auto& structure_node : domain_node.structures) { auto variant = boost::apply_visitor(StructureVisitor(context), structure_node); @@ -108,20 +108,20 @@ pddl::Domain parse(const ast::Domain& domain_node, Context& context) test_predicate_references(derived_predicates, context); test_function_skeleton_references(function_skeletons, context); - const auto domain = context.factories.domains.get_or_create(domain_name, - context.requirements, - types, - constants, - predicates, - derived_predicates, - function_skeletons, - action_list, - axiom_list); + const auto domain = context.factories.get_or_create_domain(domain_name, + context.requirements, + types, + constants, + predicates, + derived_predicates, + function_skeletons, + action_list, + axiom_list); context.positions.push_back(domain, domain_node); return domain; } -pddl::Problem parse(const ast::Problem& problem_node, Context& context, const pddl::Domain& domain) +Problem parse(const ast::Problem& problem_node, Context& context, const Domain& domain) { /* Domain name section */ const auto domain_name = parse(problem_node.domain_name.name); @@ -134,31 +134,31 @@ pddl::Problem parse(const ast::Problem& problem_node, Context& context, const pd /* Requirements section */ if (problem_node.requirements.has_value()) { - context.requirements = context.factories.requirements.get_or_create(parse(problem_node.requirements.value(), context)); + context.requirements = context.factories.get_or_create_requirements(parse(problem_node.requirements.value(), context)); context.positions.push_back(context.requirements, problem_node.requirements.value()); } else { // Default requirements - context.requirements = context.factories.requirements.get_or_create(pddl::RequirementEnumSet { pddl::RequirementEnum::STRIPS }); + context.requirements = context.factories.get_or_create_requirements(RequirementEnumSet { RequirementEnum::STRIPS }); } /* Objects section */ - auto objects = pddl::ObjectList(); + auto objects = ObjectList(); if (problem_node.objects.has_value()) { objects = parse(problem_node.objects.value(), context); } track_object_references(objects, context); /* DerivedPredicates section */ - auto derived_predicates = pddl::PredicateList(); + auto derived_predicates = PredicateList(); if (problem_node.derived_predicates.has_value()) { derived_predicates = parse(problem_node.derived_predicates.value(), context); } track_predicate_references(derived_predicates, context); /* Initial section */ - auto initial_literals = pddl::GroundLiteralList(); - auto numeric_fluents = pddl::NumericFluentList(); + auto initial_literals = GroundLiteralList(); + auto numeric_fluents = NumericFluentList(); if (problem_node.initial.has_value()) { const auto initial_elements = parse(problem_node.initial.value(), context); @@ -168,13 +168,13 @@ pddl::Problem parse(const ast::Problem& problem_node, Context& context, const pd } } /* Goal section */ - auto goal_condition = std::optional(); + auto goal_condition = std::optional(); if (problem_node.goal.has_value()) { goal_condition = parse(problem_node.goal.value(), context); } /* Metric section */ - auto optimization_metric = std::optional(); + auto optimization_metric = std::optional(); if (problem_node.metric_specification.has_value()) { optimization_metric = parse(problem_node.metric_specification.value(), context); @@ -185,7 +185,7 @@ pddl::Problem parse(const ast::Problem& problem_node, Context& context, const pd test_predicate_references(derived_predicates, context); /* Structure section */ - auto axioms = pddl::AxiomList(); + auto axioms = AxiomList(); if (problem_node.axioms.has_value()) { for (const auto& axiom_node : problem_node.axioms.value()) @@ -194,16 +194,16 @@ pddl::Problem parse(const ast::Problem& problem_node, Context& context, const pd } } - const auto problem = context.factories.problems.get_or_create(domain, - problem_name, - context.requirements, - objects, - derived_predicates, - initial_literals, - numeric_fluents, - goal_condition, - optimization_metric, - axioms); + const auto problem = context.factories.get_or_create_problem(domain, + problem_name, + context.requirements, + objects, + derived_predicates, + initial_literals, + numeric_fluents, + goal_condition, + optimization_metric, + axioms); context.positions.push_back(problem, problem_node); return problem; } diff --git a/src/pddl/parser/common.cpp b/src/pddl/parser/common.cpp index 7a57b93f..ffcb73ab 100644 --- a/src/pddl/parser/common.cpp +++ b/src/pddl/parser/common.cpp @@ -28,9 +28,9 @@ namespace loki string parse(const ast::Name& node) { return node.characters; } /* Variable */ -pddl::Variable parse(const ast::Variable& node, Context& context) +Variable parse(const ast::Variable& node, Context& context) { - const auto variable = context.factories.variables.get_or_create(node.characters); + const auto variable = context.factories.get_or_create_variable(node.characters); // Declare variable as being referenced. context.references.untrack(variable); // Add position of PDDL object @@ -41,11 +41,11 @@ pddl::Variable parse(const ast::Variable& node, Context& context) /* Term */ TermDeclarationTermVisitor::TermDeclarationTermVisitor(Context& context_) : context(context_) {} -pddl::Term TermDeclarationTermVisitor::operator()(const ast::Name& node) const +Term TermDeclarationTermVisitor::operator()(const ast::Name& node) const { const auto constant_name = parse(node); // Test for undefined constant. - const auto binding = context.scopes.get(constant_name); + const auto binding = context.scopes.get(constant_name); if (!binding.has_value()) { throw UndefinedConstantError(constant_name, context.scopes.get_error_handler()(node, "")); @@ -53,17 +53,17 @@ pddl::Term TermDeclarationTermVisitor::operator()(const ast::Name& node) const // Constant are not tracked and hence must not be untracked. // Construct Term and return it const auto [constant, _position, _error_handler] = binding.value(); - const auto term = context.factories.terms.get_or_create(constant); + const auto term = context.factories.get_or_create_term_object(constant); // Add position of PDDL object context.positions.push_back(term, node); return term; } -pddl::Term TermDeclarationTermVisitor::operator()(const ast::Variable& node) const +Term TermDeclarationTermVisitor::operator()(const ast::Variable& node) const { const auto variable = parse(node, context); // Test for multiple definition - const auto binding = context.scopes.get(variable->get_name()); + const auto binding = context.scopes.get(variable->get_name()); if (binding.has_value()) { const auto message_1 = context.scopes.get_error_handler()(node, "Defined here:"); @@ -75,7 +75,7 @@ pddl::Term TermDeclarationTermVisitor::operator()(const ast::Variable& node) con // Add binding to scope context.scopes.insert(variable->get_name(), variable, node); // Construct Term and return it - const auto term = context.factories.terms.get_or_create(variable); + const auto term = context.factories.get_or_create_term_variable(variable); // Add position of PDDL object context.positions.push_back(term, node); return term; @@ -83,11 +83,11 @@ pddl::Term TermDeclarationTermVisitor::operator()(const ast::Variable& node) con TermReferenceTermVisitor::TermReferenceTermVisitor(Context& context_) : context(context_) {} -pddl::Term TermReferenceTermVisitor::operator()(const ast::Name& node) const +Term TermReferenceTermVisitor::operator()(const ast::Name& node) const { const auto object_name = parse(node); // Test for undefined constant. - const auto binding = context.scopes.get(object_name); + const auto binding = context.scopes.get(object_name); if (!binding.has_value()) { throw UndefinedConstantError(object_name, context.scopes.get_error_handler()(node, "")); @@ -95,23 +95,23 @@ pddl::Term TermReferenceTermVisitor::operator()(const ast::Name& node) const // Construct Term and return it const auto [object, _position, _error_handler] = binding.value(); context.references.untrack(object); - const auto term = context.factories.terms.get_or_create(object); + const auto term = context.factories.get_or_create_term_object(object); // Add position of PDDL object context.positions.push_back(term, node); return term; } -pddl::Term TermReferenceTermVisitor::operator()(const ast::Variable& node) const +Term TermReferenceTermVisitor::operator()(const ast::Variable& node) const { const auto variable = parse(node, context); // Test for undefined variable - const auto binding = context.scopes.get(variable->get_name()); + const auto binding = context.scopes.get(variable->get_name()); if (!binding.has_value()) { throw UndefinedVariableError(variable->get_name(), context.scopes.get_error_handler()(node, "")); } // Construct Term and return it - const auto term = context.factories.terms.get_or_create(variable); + const auto term = context.factories.get_or_create_term_variable(variable); // Add position of PDDL object context.positions.push_back(term, node); return term; diff --git a/src/pddl/parser/common.hpp b/src/pddl/parser/common.hpp index 44ba27be..a35a1a86 100644 --- a/src/pddl/parser/common.hpp +++ b/src/pddl/parser/common.hpp @@ -28,27 +28,27 @@ namespace loki extern std::string parse(const ast::Name& node); /* Variable */ -extern pddl::Variable parse(const ast::Variable& node, Context& context); +extern Variable parse(const ast::Variable& node, Context& context); /* Term */ -struct TermDeclarationTermVisitor : boost::static_visitor +struct TermDeclarationTermVisitor : boost::static_visitor { Context& context; TermDeclarationTermVisitor(Context& context_); - pddl::Term operator()(const ast::Name& node) const; - pddl::Term operator()(const ast::Variable& node) const; + Term operator()(const ast::Name& node) const; + Term operator()(const ast::Variable& node) const; }; -struct TermReferenceTermVisitor : boost::static_visitor +struct TermReferenceTermVisitor : boost::static_visitor { Context& context; TermReferenceTermVisitor(Context& context_); - pddl::Term operator()(const ast::Name& node) const; - pddl::Term operator()(const ast::Variable& node) const; + Term operator()(const ast::Name& node) const; + Term operator()(const ast::Variable& node) const; }; /* Number */ diff --git a/src/pddl/parser/conditions.cpp b/src/pddl/parser/conditions.cpp index dda414ce..dbdfd8aa 100644 --- a/src/pddl/parser/conditions.cpp +++ b/src/pddl/parser/conditions.cpp @@ -26,9 +26,9 @@ namespace loki { // parse a vector of goal descriptors template -static pddl::ConditionList parse(const std::vector& nodes, Context& context) +static ConditionList parse(const std::vector& nodes, Context& context) { - auto condition_list = pddl::ConditionList(); + auto condition_list = ConditionList(); for (const auto& node : nodes) { condition_list.push_back(parse(node, context)); @@ -36,98 +36,98 @@ static pddl::ConditionList parse(const std::vector& nodes, Context& context) return condition_list; } -pddl::Condition parse(const ast::GoalDescriptor& node, Context& context) { return boost::apply_visitor(ConditionVisitor(context), node); } +Condition parse(const ast::GoalDescriptor& node, Context& context) { return boost::apply_visitor(ConditionVisitor(context), node); } -pddl::Condition parse(const ast::GoalDescriptorAtom& node, Context& context) +Condition parse(const ast::GoalDescriptorAtom& node, Context& context) { - const auto condition = context.factories.conditions.get_or_create(parse(node.atom, context)); + const auto condition = context.factories.get_or_create_condition_literal(parse(node.atom, context)); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::GoalDescriptorLiteral& node, Context& context) +Condition parse(const ast::GoalDescriptorLiteral& node, Context& context) { // requires :negative-preconditions - if (!context.requirements->test(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::NEGATIVE_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::NEGATIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS); - const auto condition = context.factories.conditions.get_or_create(parse(node.literal, context)); + context.references.untrack(RequirementEnum::NEGATIVE_PRECONDITIONS); + const auto condition = context.factories.get_or_create_condition_literal(parse(node.literal, context)); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::GoalDescriptorAnd& node, Context& context) +Condition parse(const ast::GoalDescriptorAnd& node, Context& context) { auto condition_list = parse(node.goal_descriptors, context); - const auto condition = context.factories.conditions.get_or_create(condition_list); + const auto condition = context.factories.get_or_create_condition_and(condition_list); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::GoalDescriptorOr& node, Context& context) +Condition parse(const ast::GoalDescriptorOr& node, Context& context) { // requires :disjunctive-preconditions - if (!context.requirements->test(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::DISJUNCTIVE_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::DISJUNCTIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS); + context.references.untrack(RequirementEnum::DISJUNCTIVE_PRECONDITIONS); auto condition_list = parse(node.goal_descriptors, context); - const auto condition = context.factories.conditions.get_or_create(condition_list); + const auto condition = context.factories.get_or_create_condition_or(condition_list); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::GoalDescriptorNot& node, Context& context) +Condition parse(const ast::GoalDescriptorNot& node, Context& context) { // requires :disjunctive-preconditions - if (!context.requirements->test(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::NEGATIVE_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::NEGATIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS); + context.references.untrack(RequirementEnum::NEGATIVE_PRECONDITIONS); auto child_condition = parse(node.goal_descriptor, context); - const auto condition = context.factories.conditions.get_or_create(child_condition); + const auto condition = context.factories.get_or_create_condition_not(child_condition); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::GoalDescriptorImply& node, Context& context) +Condition parse(const ast::GoalDescriptorImply& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::DISJUNCTIVE_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::DISJUNCTIVE_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS); + context.references.untrack(RequirementEnum::DISJUNCTIVE_PRECONDITIONS); auto condition_left = parse(node.goal_descriptor_left, context); auto condition_right = parse(node.goal_descriptor_right, context); - const auto condition = context.factories.conditions.get_or_create(condition_left, condition_right); + const auto condition = context.factories.get_or_create_condition_imply(condition_left, condition_right); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::GoalDescriptorExists& node, Context& context) +Condition parse(const ast::GoalDescriptorExists& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::EXISTENTIAL_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::EXISTENTIAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS); + context.references.untrack(RequirementEnum::EXISTENTIAL_PRECONDITIONS); context.scopes.open_scope(); auto parameter_list = boost::apply_visitor(ParameterListVisitor(context), node.typed_list_of_variables); track_variable_references(parameter_list, context); auto child_condition = parse(node.goal_descriptor, context); test_variable_references(parameter_list, context); context.scopes.close_scope(); - auto condition = context.factories.conditions.get_or_create(parameter_list, child_condition); + auto condition = context.factories.get_or_create_condition_exists(parameter_list, child_condition); context.positions.push_back(condition, node); return condition; } template -pddl::Condition parse_condition_forall(const ast::TypedListOfVariables& parameters_node, const ConditionNode& condition_node, Context& context) +Condition parse_condition_forall(const ast::TypedListOfVariables& parameters_node, const ConditionNode& condition_node, Context& context) { context.scopes.open_scope(); auto parameter_list = boost::apply_visitor(ParameterListVisitor(context), parameters_node); @@ -135,136 +135,136 @@ pddl::Condition parse_condition_forall(const ast::TypedListOfVariables& paramete auto child_condition = parse(condition_node, context); test_variable_references(parameter_list, context); context.scopes.close_scope(); - auto condition = context.factories.conditions.get_or_create(parameter_list, child_condition); + auto condition = context.factories.get_or_create_condition_forall(parameter_list, child_condition); context.positions.push_back(condition, condition_node); return condition; } -pddl::Condition parse(const ast::GoalDescriptorForall& node, Context& context) +Condition parse(const ast::GoalDescriptorForall& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::UNIVERSAL_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::UNIVERSAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS); + context.references.untrack(RequirementEnum::UNIVERSAL_PRECONDITIONS); return parse_condition_forall(node.typed_list_of_variables, node.goal_descriptor, context); } -pddl::Condition parse(const ast::GoalDescriptorFunctionComparison& node, Context& context) +Condition parse(const ast::GoalDescriptorFunctionComparison& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::NUMERIC_FLUENTS)) + if (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::NUMERIC_FLUENTS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.scopes.get_error_handler()(node, "")); } throw NotImplementedError("parse(const ast::GoalDescriptorFunctionComparison& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptor& node, Context& context) { return boost::apply_visitor(ConditionVisitor(context), node); } +Condition parse(const ast::ConstraintGoalDescriptor& node, Context& context) { return boost::apply_visitor(ConditionVisitor(context), node); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorAnd& node, Context& context) +Condition parse(const ast::ConstraintGoalDescriptorAnd& node, Context& context) { - auto condition_list = pddl::ConditionList(); + auto condition_list = ConditionList(); for (const auto& child_node : node.constraint_goal_descriptors) { condition_list.push_back(parse(child_node, context)); } - const auto condition = context.factories.conditions.get_or_create(condition_list); + const auto condition = context.factories.get_or_create_condition_and(condition_list); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::ConstraintGoalDescriptorForall& node, Context& context) +Condition parse(const ast::ConstraintGoalDescriptorForall& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::UNIVERSAL_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::UNIVERSAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS); + context.references.untrack(RequirementEnum::UNIVERSAL_PRECONDITIONS); return parse_condition_forall(node.typed_list_of_variables, node.constraint_goal_descriptor, context); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorAtEnd& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorAtEnd& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorAtEnd& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorAlways& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorAlways& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorAlways& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorSometime& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorSometime& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorSometime& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorWithin& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorWithin& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorWithin& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorAtMostOnce& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorAtMostOnce& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorAtMostOnce& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorSometimeAfter& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorSometimeAfter& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorSometimeAfter& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorSometimeBefore& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorSometimeBefore& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorSometimeBefore& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorAlwaysWithin& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorAlwaysWithin& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorAlwaysWithin& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorHoldDuring& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorHoldDuring& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorHoldDuring& node, Context& context)"); } -pddl::Condition parse(const ast::ConstraintGoalDescriptorHoldAfter& /*node*/, Context& /*context*/) +Condition parse(const ast::ConstraintGoalDescriptorHoldAfter& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::ConstraintGoalDescriptorHoldAfter& node, Context& context)"); } -pddl::Condition parse(const ast::PreconditionGoalDescriptor& node, Context& context) { return boost::apply_visitor(ConditionVisitor(context), node); } +Condition parse(const ast::PreconditionGoalDescriptor& node, Context& context) { return boost::apply_visitor(ConditionVisitor(context), node); } -pddl::Condition parse(const ast::PreconditionGoalDescriptorSimple& node, Context& context) { return parse(node.goal_descriptor, context); } +Condition parse(const ast::PreconditionGoalDescriptorSimple& node, Context& context) { return parse(node.goal_descriptor, context); } -pddl::Condition parse(const ast::PreconditionGoalDescriptorAnd& node, Context& context) +Condition parse(const ast::PreconditionGoalDescriptorAnd& node, Context& context) { - auto condition_list = pddl::ConditionList(); + auto condition_list = ConditionList(); for (const auto& child_node : node.precondition_goal_descriptors) { condition_list.push_back(parse(child_node, context)); } - const auto condition = context.factories.conditions.get_or_create(condition_list); + const auto condition = context.factories.get_or_create_condition_and(condition_list); context.positions.push_back(condition, node); return condition; } -pddl::Condition parse(const ast::PreconditionGoalDescriptorPreference& node, Context& context) +Condition parse(const ast::PreconditionGoalDescriptorPreference& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::PREFERENCES)) + if (!context.requirements->test(RequirementEnum::PREFERENCES)) { - throw UndefinedRequirementError(pddl::RequirementEnum::PREFERENCES, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::PREFERENCES, context.scopes.get_error_handler()(node, "")); } throw NotImplementedError("parse(const ast::PreconditionGoalDescriptorPreference& node, Context& context)"); } -pddl::Condition parse(const ast::PreconditionGoalDescriptorForall& node, Context& context) +Condition parse(const ast::PreconditionGoalDescriptorForall& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS)) + if (!context.requirements->test(RequirementEnum::UNIVERSAL_PRECONDITIONS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::UNIVERSAL_PRECONDITIONS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS); + context.references.untrack(RequirementEnum::UNIVERSAL_PRECONDITIONS); return parse_condition_forall(node.typed_list_of_variables, node.precondition_goal_descriptor, context); } diff --git a/src/pddl/parser/conditions.hpp b/src/pddl/parser/conditions.hpp index 50b8cb81..2b204558 100644 --- a/src/pddl/parser/conditions.hpp +++ b/src/pddl/parser/conditions.hpp @@ -28,45 +28,45 @@ namespace loki { -extern pddl::Condition parse(const ast::GoalDescriptor& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorAtom& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorLiteral& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorAnd& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorOr& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorNot& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorImply& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorExists& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorForall& node, Context& context); -extern pddl::Condition parse(const ast::GoalDescriptorFunctionComparison& node, Context& context); +extern Condition parse(const ast::GoalDescriptor& node, Context& context); +extern Condition parse(const ast::GoalDescriptorAtom& node, Context& context); +extern Condition parse(const ast::GoalDescriptorLiteral& node, Context& context); +extern Condition parse(const ast::GoalDescriptorAnd& node, Context& context); +extern Condition parse(const ast::GoalDescriptorOr& node, Context& context); +extern Condition parse(const ast::GoalDescriptorNot& node, Context& context); +extern Condition parse(const ast::GoalDescriptorImply& node, Context& context); +extern Condition parse(const ast::GoalDescriptorExists& node, Context& context); +extern Condition parse(const ast::GoalDescriptorForall& node, Context& context); +extern Condition parse(const ast::GoalDescriptorFunctionComparison& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptor& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorAnd& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorForall& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorAtEnd& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorAlways& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorSometime& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorWithin& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorAtMostOnce& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorSometimeAfter& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorSometimeBefore& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorAlwaysWithin& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorHoldDuring& node, Context& context); -extern pddl::Condition parse(const ast::ConstraintGoalDescriptorHoldAfter& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptor& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorAnd& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorForall& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorAtEnd& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorAlways& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorSometime& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorWithin& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorAtMostOnce& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorSometimeAfter& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorSometimeBefore& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorAlwaysWithin& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorHoldDuring& node, Context& context); +extern Condition parse(const ast::ConstraintGoalDescriptorHoldAfter& node, Context& context); -extern pddl::Condition parse(const ast::PreconditionGoalDescriptor& node, Context& context); -extern pddl::Condition parse(const ast::PreconditionGoalDescriptorSimple& node, Context& context); -extern pddl::Condition parse(const ast::PreconditionGoalDescriptorAnd& node, Context& context); -extern pddl::Condition parse(const ast::PreconditionGoalDescriptorPreference& node, Context& context); -extern pddl::Condition parse(const ast::PreconditionGoalDescriptorForall& node, Context& context); +extern Condition parse(const ast::PreconditionGoalDescriptor& node, Context& context); +extern Condition parse(const ast::PreconditionGoalDescriptorSimple& node, Context& context); +extern Condition parse(const ast::PreconditionGoalDescriptorAnd& node, Context& context); +extern Condition parse(const ast::PreconditionGoalDescriptorPreference& node, Context& context); +extern Condition parse(const ast::PreconditionGoalDescriptorForall& node, Context& context); -struct ConditionVisitor : boost::static_visitor +struct ConditionVisitor : boost::static_visitor { Context& context; ConditionVisitor(Context& context_); template - pddl::Condition operator()(const Node& node) const + Condition operator()(const Node& node) const { return parse(node, context); } diff --git a/src/pddl/parser/constants.cpp b/src/pddl/parser/constants.cpp index da98136b..1b538506 100644 --- a/src/pddl/parser/constants.cpp +++ b/src/pddl/parser/constants.cpp @@ -25,10 +25,10 @@ using namespace std; namespace loki { -static void test_multiple_definition(const pddl::Object& constant, const ast::Name& node, const Context& context) +static void test_multiple_definition(const Object& constant, const ast::Name& node, const Context& context) { const auto constant_name = constant->get_name(); - const auto binding = context.scopes.get(constant_name); + const auto binding = context.scopes.get(constant_name); if (binding.has_value()) { const auto message_1 = context.scopes.get_error_handler()(node, "Defined here:"); @@ -42,23 +42,23 @@ static void test_multiple_definition(const pddl::Object& constant, const ast::Na } } -static void insert_context_information(const pddl::Object& constant, const ast::Name& node, Context& context) +static void insert_context_information(const Object& constant, const ast::Name& node, Context& context) { context.positions.push_back(constant, node); context.scopes.insert(constant->get_name(), constant, node); } -static pddl::Object parse_constant_definition(const ast::Name& node, const pddl::TypeList& type_list, Context& context) +static Object parse_constant_definition(const ast::Name& node, const TypeList& type_list, Context& context) { - const auto constant = context.factories.objects.get_or_create(parse(node), type_list); + const auto constant = context.factories.get_or_create_object(parse(node), type_list); test_multiple_definition(constant, node, context); insert_context_information(constant, node, context); return constant; } -static pddl::ObjectList parse_constant_definitions(const std::vector& nodes, const pddl::TypeList& type_list, Context& context) +static ObjectList parse_constant_definitions(const std::vector& nodes, const TypeList& type_list, Context& context) { - auto constant_list = pddl::ObjectList(); + auto constant_list = ObjectList(); for (const auto& node : nodes) { constant_list.push_back(parse_constant_definition(node, type_list, context)); @@ -66,28 +66,28 @@ static pddl::ObjectList parse_constant_definitions(const std::vector& return constant_list; } -pddl::ObjectList parse(const ast::Constants& constants_node, Context& context) +ObjectList parse(const ast::Constants& constants_node, Context& context) { return boost::apply_visitor(ConstantListVisitor(context), constants_node.typed_list_of_names.get()); } ConstantListVisitor::ConstantListVisitor(Context& context_) : context(context_) {} -pddl::ObjectList ConstantListVisitor::operator()(const std::vector& name_nodes) +ObjectList ConstantListVisitor::operator()(const std::vector& name_nodes) { // std::vector has single base type "object" - assert(context.scopes.get("object").has_value()); - const auto [type, _position, _error_handler] = context.scopes.get("object").value(); - return parse_constant_definitions(name_nodes, pddl::TypeList { type }, context); + assert(context.scopes.get("object").has_value()); + const auto [type, _position, _error_handler] = context.scopes.get("object").value(); + return parse_constant_definitions(name_nodes, TypeList { type }, context); } -pddl::ObjectList ConstantListVisitor::operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node) +ObjectList ConstantListVisitor::operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node) { - if (!context.requirements->test(pddl::RequirementEnum::TYPING)) + if (!context.requirements->test(RequirementEnum::TYPING)) { - throw UndefinedRequirementError(pddl::RequirementEnum::TYPING, context.scopes.get_error_handler()(typed_list_of_names_recursively_node, "")); + throw UndefinedRequirementError(RequirementEnum::TYPING, context.scopes.get_error_handler()(typed_list_of_names_recursively_node, "")); } - context.references.untrack(pddl::RequirementEnum::TYPING); + context.references.untrack(RequirementEnum::TYPING); const auto type_list = boost::apply_visitor(TypeReferenceTypeVisitor(context), typed_list_of_names_recursively_node.type); // TypedListOfNamesRecursively has user defined base types auto constant_list = parse_constant_definitions(typed_list_of_names_recursively_node.names, type_list, context); diff --git a/src/pddl/parser/constants.hpp b/src/pddl/parser/constants.hpp index dbb5ee4d..cbad25ea 100644 --- a/src/pddl/parser/constants.hpp +++ b/src/pddl/parser/constants.hpp @@ -26,9 +26,9 @@ namespace loki { /* Constants */ -extern pddl::ObjectList parse(const ast::Constants& constants_node, Context& context); +extern ObjectList parse(const ast::Constants& constants_node, Context& context); -class ConstantListVisitor : boost::static_visitor +class ConstantListVisitor : boost::static_visitor { private: Context& context; @@ -36,9 +36,9 @@ class ConstantListVisitor : boost::static_visitor public: ConstantListVisitor(Context& context_); - pddl::ObjectList operator()(const std::vector& name_nodes); + ObjectList operator()(const std::vector& name_nodes); - pddl::ObjectList operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node); + ObjectList operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node); }; } diff --git a/src/pddl/parser/effects.cpp b/src/pddl/parser/effects.cpp index d32e1a93..cb8c3ea9 100644 --- a/src/pddl/parser/effects.cpp +++ b/src/pddl/parser/effects.cpp @@ -28,34 +28,34 @@ namespace loki { -pddl::AssignOperatorEnum parse(const ast::AssignOperatorAssign&) { return pddl::AssignOperatorEnum::ASSIGN; } +AssignOperatorEnum parse(const ast::AssignOperatorAssign&) { return AssignOperatorEnum::ASSIGN; } -pddl::AssignOperatorEnum parse(const ast::AssignOperatorScaleUp&) { return pddl::AssignOperatorEnum::SCALE_UP; } +AssignOperatorEnum parse(const ast::AssignOperatorScaleUp&) { return AssignOperatorEnum::SCALE_UP; } -pddl::AssignOperatorEnum parse(const ast::AssignOperatorScaleDown&) { return pddl::AssignOperatorEnum::SCALE_DOWN; } +AssignOperatorEnum parse(const ast::AssignOperatorScaleDown&) { return AssignOperatorEnum::SCALE_DOWN; } -pddl::AssignOperatorEnum parse(const ast::AssignOperatorIncrease&) { return pddl::AssignOperatorEnum::INCREASE; } +AssignOperatorEnum parse(const ast::AssignOperatorIncrease&) { return AssignOperatorEnum::INCREASE; } -pddl::AssignOperatorEnum parse(const ast::AssignOperatorDecrease&) { return pddl::AssignOperatorEnum::DECREASE; } +AssignOperatorEnum parse(const ast::AssignOperatorDecrease&) { return AssignOperatorEnum::DECREASE; } -pddl::AssignOperatorEnum parse(const ast::AssignOperator& node) { return boost::apply_visitor(AssignOperatorVisitor(), node); } +AssignOperatorEnum parse(const ast::AssignOperator& node) { return boost::apply_visitor(AssignOperatorVisitor(), node); } -pddl::Effect parse(const std::vector& effect_nodes, Context& context) +Effect parse(const std::vector& effect_nodes, Context& context) { - auto effect_list = pddl::EffectList(); + auto effect_list = EffectList(); for (const auto& effect_node : effect_nodes) { effect_list.push_back(parse(effect_node, context)); } - return context.factories.effects.get_or_create(effect_list); + return context.factories.get_or_create_effect_and(effect_list); } -pddl::Effect parse(const ast::Effect& node, Context& context) { return boost::apply_visitor(EffectVisitor(context), node); } +Effect parse(const ast::Effect& node, Context& context) { return boost::apply_visitor(EffectVisitor(context), node); } -pddl::Effect parse(const ast::EffectProductionLiteral& node, Context& context) +Effect parse(const ast::EffectProductionLiteral& node, Context& context) { auto literal = parse(node.literal, context); - const auto effect = context.factories.effects.get_or_create(literal); + const auto effect = context.factories.get_or_create_effect_literal(literal); if (context.derived_predicates.count(literal->get_atom()->get_predicate())) { @@ -66,49 +66,49 @@ pddl::Effect parse(const ast::EffectProductionLiteral& node, Context& context) return effect; } -pddl::Effect parse(const ast::EffectProductionNumericFluentTotalCost& node, Context& context) +Effect parse(const ast::EffectProductionNumericFluentTotalCost& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::ACTION_COSTS)) + if (!context.requirements->test(RequirementEnum::ACTION_COSTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::ACTION_COSTS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::ACTION_COSTS); + context.references.untrack(RequirementEnum::ACTION_COSTS); const auto assign_operator_increase = parse(node.assign_operator_increase); auto function_name = parse(node.function_symbol_total_cost.name); assert(function_name == "total-cost"); - auto binding = context.scopes.get(function_name); + auto binding = context.scopes.get(function_name); if (!binding.has_value()) { throw UndefinedFunctionSkeletonError(function_name, context.scopes.get_error_handler()(node.function_symbol_total_cost, "")); } const auto [function_skeleton, _position, _error_handler] = binding.value(); - const auto function = context.factories.functions.get_or_create(function_skeleton, pddl::TermList {}); + const auto function = context.factories.get_or_create_function(function_skeleton, TermList {}); context.references.untrack(function->get_function_skeleton()); const auto function_expression = boost::apply_visitor(FunctionExpressionVisitor(context), node.numeric_term); - const auto effect = context.factories.effects.get_or_create(assign_operator_increase, function, function_expression); + const auto effect = context.factories.get_or_create_effect_numeric(assign_operator_increase, function, function_expression); context.positions.push_back(effect, node); return effect; } -pddl::Effect parse(const ast::EffectProductionNumericFluentGeneral& node, Context& context) +Effect parse(const ast::EffectProductionNumericFluentGeneral& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::NUMERIC_FLUENTS)) + if (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::NUMERIC_FLUENTS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::NUMERIC_FLUENTS); + context.references.untrack(RequirementEnum::NUMERIC_FLUENTS); const auto assign_operator = parse(node.assign_operator); const auto function = parse(node.function_head, context); context.references.untrack(function->get_function_skeleton()); const auto function_expression = parse(node.function_expression, context); - const auto effect = context.factories.effects.get_or_create(assign_operator, function, function_expression); + const auto effect = context.factories.get_or_create_effect_numeric(assign_operator, function, function_expression); context.positions.push_back(effect, node); return effect; } -pddl::Effect parse(const ast::EffectProduction& node, Context& context) { return boost::apply_visitor(EffectVisitor(context), node); } +Effect parse(const ast::EffectProduction& node, Context& context) { return boost::apply_visitor(EffectVisitor(context), node); } -pddl::Effect parse(const ast::EffectConditionalForall& node, Context& context) +Effect parse(const ast::EffectConditionalForall& node, Context& context) { context.scopes.open_scope(); const auto parameter_list = boost::apply_visitor(ParameterListVisitor(context), node.typed_list_of_variables); @@ -116,30 +116,30 @@ pddl::Effect parse(const ast::EffectConditionalForall& node, Context& context) const auto child_effect = parse(node.effect, context); test_variable_references(parameter_list, context); context.scopes.close_scope(); - const auto effect = context.factories.effects.get_or_create(parameter_list, child_effect); + const auto effect = context.factories.get_or_create_effect_conditional_forall(parameter_list, child_effect); context.positions.push_back(effect, node); return effect; } -pddl::Effect parse(const ast::EffectConditionalWhen& node, Context& context) +Effect parse(const ast::EffectConditionalWhen& node, Context& context) { context.scopes.open_scope(); const auto condition = parse(node.goal_descriptor, context); const auto child_effect = parse(node.effect, context); context.scopes.close_scope(); - const auto effect = context.factories.effects.get_or_create(condition, child_effect); + const auto effect = context.factories.get_or_create_effect_conditional_when(condition, child_effect); context.positions.push_back(effect, node); return effect; } -pddl::Effect parse(const ast::EffectConditional& node, Context& context) +Effect parse(const ast::EffectConditional& node, Context& context) { // requires :conditional-effects - if (!context.requirements->test(pddl::RequirementEnum::CONDITIONAL_EFFECTS)) + if (!context.requirements->test(RequirementEnum::CONDITIONAL_EFFECTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::CONDITIONAL_EFFECTS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::CONDITIONAL_EFFECTS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::CONDITIONAL_EFFECTS); + context.references.untrack(RequirementEnum::CONDITIONAL_EFFECTS); const auto effect = boost::apply_visitor(EffectVisitor(context), node); context.positions.push_back(effect, node); return effect; diff --git a/src/pddl/parser/effects.hpp b/src/pddl/parser/effects.hpp index f48cfea1..55ddce02 100644 --- a/src/pddl/parser/effects.hpp +++ b/src/pddl/parser/effects.hpp @@ -29,41 +29,41 @@ namespace loki { /* AssignOperator */ -extern pddl::AssignOperatorEnum parse(const ast::AssignOperatorAssign& node); -extern pddl::AssignOperatorEnum parse(const ast::AssignOperatorScaleUp& node); -extern pddl::AssignOperatorEnum parse(const ast::AssignOperatorScaleDown& node); -extern pddl::AssignOperatorEnum parse(const ast::AssignOperatorIncrease& node); -extern pddl::AssignOperatorEnum parse(const ast::AssignOperatorDecrease& node); -extern pddl::AssignOperatorEnum parse(const ast::AssignOperator& node); +extern AssignOperatorEnum parse(const ast::AssignOperatorAssign& node); +extern AssignOperatorEnum parse(const ast::AssignOperatorScaleUp& node); +extern AssignOperatorEnum parse(const ast::AssignOperatorScaleDown& node); +extern AssignOperatorEnum parse(const ast::AssignOperatorIncrease& node); +extern AssignOperatorEnum parse(const ast::AssignOperatorDecrease& node); +extern AssignOperatorEnum parse(const ast::AssignOperator& node); -struct AssignOperatorVisitor : boost::static_visitor +struct AssignOperatorVisitor : boost::static_visitor { template - pddl::AssignOperatorEnum operator()(const Node& node) const + AssignOperatorEnum operator()(const Node& node) const { return parse(node); } }; /* Effects */ -extern pddl::Effect parse(const std::vector& effect_nodes, Context& context); -extern pddl::Effect parse(const ast::Effect& node, Context& context); -extern pddl::Effect parse(const ast::EffectProductionLiteral& node, Context& context); -extern pddl::Effect parse(const ast::EffectProductionNumericFluentTotalCost& node, Context& context); -extern pddl::Effect parse(const ast::EffectProductionNumericFluentGeneral& node, Context& context); -extern pddl::Effect parse(const ast::EffectProduction& node, Context& context); -extern pddl::Effect parse(const ast::EffectConditionalForall& node, Context& context); -extern pddl::Effect parse(const ast::EffectConditionalWhen& node, Context& context); -extern pddl::Effect parse(const ast::EffectConditional& node, Context& context); +extern Effect parse(const std::vector& effect_nodes, Context& context); +extern Effect parse(const ast::Effect& node, Context& context); +extern Effect parse(const ast::EffectProductionLiteral& node, Context& context); +extern Effect parse(const ast::EffectProductionNumericFluentTotalCost& node, Context& context); +extern Effect parse(const ast::EffectProductionNumericFluentGeneral& node, Context& context); +extern Effect parse(const ast::EffectProduction& node, Context& context); +extern Effect parse(const ast::EffectConditionalForall& node, Context& context); +extern Effect parse(const ast::EffectConditionalWhen& node, Context& context); +extern Effect parse(const ast::EffectConditional& node, Context& context); -struct EffectVisitor : boost::static_visitor +struct EffectVisitor : boost::static_visitor { Context& context; EffectVisitor(Context& context_); template - pddl::Effect operator()(const Node& node) const + Effect operator()(const Node& node) const { return parse(node, context); } diff --git a/src/pddl/parser/functions.cpp b/src/pddl/parser/functions.cpp index 350298c9..b6c7536b 100644 --- a/src/pddl/parser/functions.cpp +++ b/src/pddl/parser/functions.cpp @@ -26,60 +26,58 @@ namespace loki { /* MultiOperator */ -pddl::MultiOperatorEnum MultiOperatorVisitor::operator()(const ast::MultiOperatorMul&) const { return pddl::MultiOperatorEnum::MUL; } +MultiOperatorEnum MultiOperatorVisitor::operator()(const ast::MultiOperatorMul&) const { return MultiOperatorEnum::MUL; } -pddl::MultiOperatorEnum MultiOperatorVisitor::operator()(const ast::MultiOperatorPlus&) const { return pddl::MultiOperatorEnum::PLUS; } +MultiOperatorEnum MultiOperatorVisitor::operator()(const ast::MultiOperatorPlus&) const { return MultiOperatorEnum::PLUS; } /* BinaryOperator */ -pddl::BinaryOperatorEnum MultiToBinaryOperatorVisitor::operator()(const ast::MultiOperatorMul&) const { return pddl::BinaryOperatorEnum::MUL; } +BinaryOperatorEnum MultiToBinaryOperatorVisitor::operator()(const ast::MultiOperatorMul&) const { return BinaryOperatorEnum::MUL; } -pddl::BinaryOperatorEnum MultiToBinaryOperatorVisitor::operator()(const ast::MultiOperatorPlus&) const { return pddl::BinaryOperatorEnum::PLUS; } +BinaryOperatorEnum MultiToBinaryOperatorVisitor::operator()(const ast::MultiOperatorPlus&) const { return BinaryOperatorEnum::PLUS; } -pddl::BinaryOperatorEnum BinaryOperatorVisitor::operator()(const ast::BinaryOperatorDiv&) const { return pddl::BinaryOperatorEnum::DIV; } +BinaryOperatorEnum BinaryOperatorVisitor::operator()(const ast::BinaryOperatorDiv&) const { return BinaryOperatorEnum::DIV; } -pddl::BinaryOperatorEnum BinaryOperatorVisitor::operator()(const ast::BinaryOperatorMinus&) const { return pddl::BinaryOperatorEnum::MINUS; } +BinaryOperatorEnum BinaryOperatorVisitor::operator()(const ast::BinaryOperatorMinus&) const { return BinaryOperatorEnum::MINUS; } -pddl::BinaryOperatorEnum BinaryOperatorVisitor::operator()(const ast::MultiOperator& node) const +BinaryOperatorEnum BinaryOperatorVisitor::operator()(const ast::MultiOperator& node) const { return boost::apply_visitor(MultiToBinaryOperatorVisitor(), node); } /* FunctionExpression */ -pddl::FunctionExpression parse(const ast::FunctionExpression& node, Context& context) { return boost::apply_visitor(FunctionExpressionVisitor(context), node); } +FunctionExpression parse(const ast::FunctionExpression& node, Context& context) { return boost::apply_visitor(FunctionExpressionVisitor(context), node); } -pddl::FunctionExpression parse(const ast::FunctionExpressionNumber& node, Context& context) +FunctionExpression parse(const ast::FunctionExpressionNumber& node, Context& context) { const auto number = parse(node.number); - const auto function_expression = context.factories.function_expressions.get_or_create(number); + const auto function_expression = context.factories.get_or_create_function_expression_number(number); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::FunctionExpressionBinaryOp& node, Context& context) +FunctionExpression parse(const ast::FunctionExpressionBinaryOp& node, Context& context) { const auto binary_operator = boost::apply_visitor(BinaryOperatorVisitor(), node.binary_operator); const auto left_function_expression = parse(node.function_expression_left, context); const auto right_function_expression = parse(node.function_expression_right, context); const auto function_expression = - context.factories.function_expressions.get_or_create(binary_operator, - left_function_expression, - right_function_expression); + context.factories.get_or_create_function_expression_binary_operator(binary_operator, left_function_expression, right_function_expression); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::FunctionExpressionMinus& node, Context& context) +FunctionExpression parse(const ast::FunctionExpressionMinus& node, Context& context) { const auto child_function_expression = parse(node.function_expression, context); - const auto function_expression = context.factories.function_expressions.get_or_create(child_function_expression); + const auto function_expression = context.factories.get_or_create_function_expression_minus(child_function_expression); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::FunctionExpressionHead node, Context& context) +FunctionExpression parse(const ast::FunctionExpressionHead node, Context& context) { const auto function = parse(node.function_head, context); - const auto function_expression = context.factories.function_expressions.get_or_create(function); + const auto function_expression = context.factories.get_or_create_function_expression_function(function); context.positions.push_back(function_expression, node); return function_expression; } @@ -87,10 +85,10 @@ pddl::FunctionExpression parse(const ast::FunctionExpressionHead node, Context& FunctionExpressionVisitor::FunctionExpressionVisitor(Context& context_) : context(context_) {} /* Function */ -pddl::Function parse(const ast::FunctionHead& node, Context& context) +Function parse(const ast::FunctionHead& node, Context& context) { const auto function_skeleton = parse_function_skeleton_reference(node.function_symbol, context); - auto term_list = pddl::TermList(); + auto term_list = TermList(); for (const auto& term_node : node.terms) { term_list.push_back(boost::apply_visitor(TermReferenceTermVisitor(context), term_node)); @@ -99,17 +97,17 @@ pddl::Function parse(const ast::FunctionHead& node, Context& context) { throw MismatchedFunctionSkeletonTermListError(function_skeleton, term_list, context.scopes.get_error_handler()(node, "")); } - const auto function = context.factories.functions.get_or_create(function_skeleton, term_list); + const auto function = context.factories.get_or_create_function(function_skeleton, term_list); context.positions.push_back(function, node); context.references.untrack(function->get_function_skeleton()); return function; } /* FunctionSkeleton */ -pddl::FunctionSkeleton parse_function_skeleton_reference(const ast::FunctionSymbol& node, Context& context) +FunctionSkeleton parse_function_skeleton_reference(const ast::FunctionSymbol& node, Context& context) { auto function_name = parse(node.name); - auto binding = context.scopes.get(function_name); + auto binding = context.scopes.get(function_name); if (!binding.has_value()) { throw UndefinedFunctionSkeletonError(function_name, context.scopes.get_error_handler()(node, "")); @@ -119,10 +117,10 @@ pddl::FunctionSkeleton parse_function_skeleton_reference(const ast::FunctionSymb return function_skeleton; } -static void test_multiple_definition(const pddl::FunctionSkeleton& function_skeleton, const ast::Name& node, const Context& context) +static void test_multiple_definition(const FunctionSkeleton& function_skeleton, const ast::Name& node, const Context& context) { const auto function_name = function_skeleton->get_name(); - const auto binding = context.scopes.get(function_name); + const auto binding = context.scopes.get(function_name); if (binding.has_value()) { const auto message_1 = context.scopes.get_error_handler()(node, "Defined here:"); @@ -136,36 +134,36 @@ static void test_multiple_definition(const pddl::FunctionSkeleton& function_skel } } -static void insert_context_information(const pddl::FunctionSkeleton& function_skeleton, const ast::Name& node, Context& context) +static void insert_context_information(const FunctionSkeleton& function_skeleton, const ast::Name& node, Context& context) { context.positions.push_back(function_skeleton, node); context.scopes.insert(function_skeleton->get_name(), function_skeleton, node); } -pddl::FunctionSkeleton parse(const ast::AtomicFunctionSkeletonTotalCost& node, Context& context) +FunctionSkeleton parse(const ast::AtomicFunctionSkeletonTotalCost& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::ACTION_COSTS)) + if (!context.requirements->test(RequirementEnum::ACTION_COSTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::ACTION_COSTS, context.positions.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.positions.get_error_handler()(node, "")); } else { - context.references.untrack(pddl::RequirementEnum::ACTION_COSTS); + context.references.untrack(RequirementEnum::ACTION_COSTS); } - if ((!context.requirements->test(pddl::RequirementEnum::ACTION_COSTS)) && (!context.requirements->test(pddl::RequirementEnum::NUMERIC_FLUENTS))) + if ((!context.requirements->test(RequirementEnum::ACTION_COSTS)) && (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS))) { - throw UndefinedRequirementError(pddl::RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, "")); } else { - context.references.untrack(pddl::RequirementEnum::ACTION_COSTS); - context.references.untrack(pddl::RequirementEnum::NUMERIC_FLUENTS); + context.references.untrack(RequirementEnum::ACTION_COSTS); + context.references.untrack(RequirementEnum::NUMERIC_FLUENTS); } - assert(context.scopes.get("number").has_value()); - const auto [type, _position, _error_handler] = context.scopes.get("number").value(); + assert(context.scopes.get("number").has_value()); + const auto [type, _position, _error_handler] = context.scopes.get("number").value(); auto function_name = parse(node.function_symbol.name); - auto function_skeleton = context.factories.function_skeletons.get_or_create(function_name, pddl::ParameterList {}, type); + auto function_skeleton = context.factories.get_or_create_function_skeleton(function_name, ParameterList {}, type); test_multiple_definition(function_skeleton, node.function_symbol.name, context); insert_context_information(function_skeleton, node.function_symbol.name, context); @@ -173,22 +171,22 @@ pddl::FunctionSkeleton parse(const ast::AtomicFunctionSkeletonTotalCost& node, C return function_skeleton; } -pddl::FunctionSkeleton parse(const ast::AtomicFunctionSkeletonGeneral& node, Context& context) +FunctionSkeleton parse(const ast::AtomicFunctionSkeletonGeneral& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::NUMERIC_FLUENTS)) + if (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.positions.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::NUMERIC_FLUENTS); + context.references.untrack(RequirementEnum::NUMERIC_FLUENTS); context.scopes.open_scope(); auto function_parameters = boost::apply_visitor(ParameterListVisitor(context), node.arguments); context.scopes.close_scope(); - assert(context.scopes.get("number").has_value()); - const auto [type, _position, _error_handler] = context.scopes.get("number").value(); + assert(context.scopes.get("number").has_value()); + const auto [type, _position, _error_handler] = context.scopes.get("number").value(); auto function_name = parse(node.function_symbol.name); - auto function_skeleton = context.factories.function_skeletons.get_or_create(function_name, function_parameters, type); + auto function_skeleton = context.factories.get_or_create_function_skeleton(function_name, function_parameters, type); test_multiple_definition(function_skeleton, node.function_symbol.name, context); insert_context_information(function_skeleton, node.function_symbol.name, context); @@ -199,9 +197,9 @@ pddl::FunctionSkeleton parse(const ast::AtomicFunctionSkeletonGeneral& node, Con AtomicFunctionSkeletonVisitor::AtomicFunctionSkeletonVisitor(Context& context_) : context(context_) {} /* FunctionSkeletonList */ -static pddl::FunctionSkeletonList parse_function_skeleton_definitions(const std::vector& nodes, Context& context) +static FunctionSkeletonList parse_function_skeleton_definitions(const std::vector& nodes, Context& context) { - auto function_skeleton_list = pddl::FunctionSkeletonList(); + auto function_skeleton_list = FunctionSkeletonList(); for (const auto& node : nodes) { auto function_skeleton = boost::apply_visitor(AtomicFunctionSkeletonVisitor(context), node); @@ -210,13 +208,13 @@ static pddl::FunctionSkeletonList parse_function_skeleton_definitions(const std: return function_skeleton_list; } -pddl::FunctionSkeletonList parse(const std::vector& formula_skeleton_nodes, Context& context) +FunctionSkeletonList parse(const std::vector& formula_skeleton_nodes, Context& context) { auto function_skeleton_list = parse_function_skeleton_definitions(formula_skeleton_nodes, context); return function_skeleton_list; } -pddl::FunctionSkeletonList parse(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& function_skeleton_list_recursively_node, Context& context) +FunctionSkeletonList parse(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& function_skeleton_list_recursively_node, Context& context) { auto function_skeleton_list = parse_function_skeleton_definitions(function_skeleton_list_recursively_node.atomic_function_skeletons, context); @@ -230,7 +228,7 @@ pddl::FunctionSkeletonList parse(const ast::FunctionTypedListOfAtomicFunctionSke return function_skeleton_list; } -pddl::FunctionSkeletonList parse(const ast::Functions& functions_node, Context& context) +FunctionSkeletonList parse(const ast::Functions& functions_node, Context& context) { return boost::apply_visitor(FunctionSkeletonListVisitor(context), functions_node.function_types_list_of_atomic_function_skeletons); } @@ -238,31 +236,29 @@ pddl::FunctionSkeletonList parse(const ast::Functions& functions_node, Context& FunctionSkeletonListVisitor::FunctionSkeletonListVisitor(Context& context_) : context(context_) {} /* FunctionExpression */ -pddl::FunctionExpression parse(const ast::MetricFunctionExpressionNumber& node, Context& context) +FunctionExpression parse(const ast::MetricFunctionExpressionNumber& node, Context& context) { const auto number = parse(node.number); - const auto function_expression = context.factories.function_expressions.get_or_create(number); + const auto function_expression = context.factories.get_or_create_function_expression_number(number); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::MetricFunctionExpressionBinaryOperator& node, Context& context) +FunctionExpression parse(const ast::MetricFunctionExpressionBinaryOperator& node, Context& context) { const auto binary_operator = boost::apply_visitor(BinaryOperatorVisitor(), node.binary_operator); const auto left_function_expression = parse(node.metric_function_expression_left, context); const auto right_function_expression = parse(node.metric_function_expression_right, context); const auto function_expression = - context.factories.function_expressions.get_or_create(binary_operator, - left_function_expression, - right_function_expression); + context.factories.get_or_create_function_expression_binary_operator(binary_operator, left_function_expression, right_function_expression); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::MetricFunctionExpressionMultiOperator& node, Context& context) +FunctionExpression parse(const ast::MetricFunctionExpressionMultiOperator& node, Context& context) { const auto multi_operator = boost::apply_visitor(MultiOperatorVisitor(), node.multi_operator); - auto function_expressions = pddl::FunctionExpressionList(); + auto function_expressions = FunctionExpressionList(); const auto first_function_expression = parse(node.metric_function_expression_first, context); function_expressions.push_back(first_function_expression); for (const auto& child_node : node.metric_function_expression_remaining) @@ -270,39 +266,38 @@ pddl::FunctionExpression parse(const ast::MetricFunctionExpressionMultiOperator& const auto next_function_expression = parse(child_node, context); function_expressions.push_back(next_function_expression); } - const auto function_expression = - context.factories.function_expressions.get_or_create(multi_operator, function_expressions); + const auto function_expression = context.factories.get_or_create_function_expression_multi_operator(multi_operator, function_expressions); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::MetricFunctionExpressionMinus& node, Context& context) +FunctionExpression parse(const ast::MetricFunctionExpressionMinus& node, Context& context) { const auto child_function_expression = parse(node.metric_function_expression, context); - const auto function_expression = context.factories.function_expressions.get_or_create(child_function_expression); + const auto function_expression = context.factories.get_or_create_function_expression_minus(child_function_expression); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::MetricFunctionExpressionBasicFunctionTerm& node, Context& context) +FunctionExpression parse(const ast::MetricFunctionExpressionBasicFunctionTerm& node, Context& context) { const auto function = parse(node.basic_function_term, context); - const auto function_expression = context.factories.function_expressions.get_or_create(function); + const auto function_expression = context.factories.get_or_create_function_expression_function(function); context.positions.push_back(function_expression, node); return function_expression; } -pddl::FunctionExpression parse(const ast::MetricFunctionExpressionTotalTime& /*node*/, Context& /*context*/) +FunctionExpression parse(const ast::MetricFunctionExpressionTotalTime& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::MetricFunctionExpressionTotalTime& node, Context& context)"); } -pddl::FunctionExpression parse(const ast::MetricFunctionExpressionPreferences& /*node*/, Context& /*context*/) +FunctionExpression parse(const ast::MetricFunctionExpressionPreferences& /*node*/, Context& /*context*/) { throw NotImplementedError("parse(const ast::MetricFunctionExpressionPreferences& node, Context& context)"); } -pddl::FunctionExpression parse(const ast::MetricFunctionExpression& node, Context& context) +FunctionExpression parse(const ast::MetricFunctionExpression& node, Context& context) { return boost::apply_visitor(MetricFunctionExpressionDeclarationVisitor(context), node); } @@ -310,19 +305,19 @@ pddl::FunctionExpression parse(const ast::MetricFunctionExpression& node, Contex MetricFunctionExpressionDeclarationVisitor::MetricFunctionExpressionDeclarationVisitor(Context& context_) : context(context_) {} /* Function */ -pddl::Function parse(const ast::BasicFunctionTerm& node, Context& context) +Function parse(const ast::BasicFunctionTerm& node, Context& context) { const auto function_skeleton = parse_function_skeleton_reference(node.function_symbol, context); - auto term_list = pddl::TermList(); + auto term_list = TermList(); for (const auto& name_node : node.names) { - term_list.push_back(context.factories.terms.get_or_create(parse_object_reference(name_node, context))); + term_list.push_back(context.factories.get_or_create_term_object(parse_object_reference(name_node, context))); } if (function_skeleton->get_parameters().size() != term_list.size()) { throw MismatchedFunctionSkeletonTermListError(function_skeleton, term_list, context.scopes.get_error_handler()(node, "")); } - const auto function = context.factories.functions.get_or_create(function_skeleton, term_list); + const auto function = context.factories.get_or_create_function(function_skeleton, term_list); context.positions.push_back(function, node); return function; } diff --git a/src/pddl/parser/functions.hpp b/src/pddl/parser/functions.hpp index e2b6aba9..f1299811 100644 --- a/src/pddl/parser/functions.hpp +++ b/src/pddl/parser/functions.hpp @@ -29,34 +29,34 @@ namespace loki { /* MultiOperator */ -struct MultiOperatorVisitor : boost::static_visitor +struct MultiOperatorVisitor : boost::static_visitor { - pddl::MultiOperatorEnum operator()(const ast::MultiOperatorMul& node) const; - pddl::MultiOperatorEnum operator()(const ast::MultiOperatorPlus& node) const; + MultiOperatorEnum operator()(const ast::MultiOperatorMul& node) const; + MultiOperatorEnum operator()(const ast::MultiOperatorPlus& node) const; }; /* BinaryOperator */ -struct MultiToBinaryOperatorVisitor : boost::static_visitor +struct MultiToBinaryOperatorVisitor : boost::static_visitor { - pddl::BinaryOperatorEnum operator()(const ast::MultiOperatorMul& node) const; - pddl::BinaryOperatorEnum operator()(const ast::MultiOperatorPlus& node) const; + BinaryOperatorEnum operator()(const ast::MultiOperatorMul& node) const; + BinaryOperatorEnum operator()(const ast::MultiOperatorPlus& node) const; }; -struct BinaryOperatorVisitor : boost::static_visitor +struct BinaryOperatorVisitor : boost::static_visitor { - pddl::BinaryOperatorEnum operator()(const ast::BinaryOperatorDiv& node) const; - pddl::BinaryOperatorEnum operator()(const ast::BinaryOperatorMinus& node) const; - pddl::BinaryOperatorEnum operator()(const ast::MultiOperator& node) const; + BinaryOperatorEnum operator()(const ast::BinaryOperatorDiv& node) const; + BinaryOperatorEnum operator()(const ast::BinaryOperatorMinus& node) const; + BinaryOperatorEnum operator()(const ast::MultiOperator& node) const; }; /* FunctionExpression */ -extern pddl::FunctionExpression parse(const ast::FunctionExpressionNumber& node, Context& context); -extern pddl::FunctionExpression parse(const ast::FunctionExpressionBinaryOp& node, Context& context); -extern pddl::FunctionExpression parse(const ast::FunctionExpressionMinus& node, Context& context); -extern pddl::FunctionExpression parse(const ast::FunctionExpressionHead node, Context& context); -extern pddl::FunctionExpression parse(const ast::FunctionExpression& node, Context& context); +extern FunctionExpression parse(const ast::FunctionExpressionNumber& node, Context& context); +extern FunctionExpression parse(const ast::FunctionExpressionBinaryOp& node, Context& context); +extern FunctionExpression parse(const ast::FunctionExpressionMinus& node, Context& context); +extern FunctionExpression parse(const ast::FunctionExpressionHead node, Context& context); +extern FunctionExpression parse(const ast::FunctionExpression& node, Context& context); -class FunctionExpressionVisitor : boost::static_visitor +class FunctionExpressionVisitor : boost::static_visitor { private: Context& context; @@ -65,21 +65,21 @@ class FunctionExpressionVisitor : boost::static_visitor - pddl::FunctionExpression operator()(const Node& node) const + FunctionExpression operator()(const Node& node) const { return parse(node, context); } }; /* Function */ -extern pddl::Function parse(const ast::FunctionHead& node, Context& context); +extern Function parse(const ast::FunctionHead& node, Context& context); /* FunctionSkeleton */ -extern pddl::FunctionSkeleton parse_function_skeleton_reference(const ast::FunctionSymbol& node, Context& context); -extern pddl::FunctionSkeleton parse(const ast::AtomicFunctionSkeletonTotalCost& node); -extern pddl::FunctionSkeleton parse(const ast::AtomicFunctionSkeletonGeneral& node); +extern FunctionSkeleton parse_function_skeleton_reference(const ast::FunctionSymbol& node, Context& context); +extern FunctionSkeleton parse(const ast::AtomicFunctionSkeletonTotalCost& node); +extern FunctionSkeleton parse(const ast::AtomicFunctionSkeletonGeneral& node); -class AtomicFunctionSkeletonVisitor : boost::static_visitor +class AtomicFunctionSkeletonVisitor : boost::static_visitor { private: Context& context; @@ -88,18 +88,18 @@ class AtomicFunctionSkeletonVisitor : boost::static_visitor - pddl::FunctionSkeleton operator()(const Node& node) + FunctionSkeleton operator()(const Node& node) { return parse(node, context); } }; /* FunctionSkeletonList */ -extern pddl::FunctionSkeletonList parse(const std::vector& formula_skeleton_nodes); -extern pddl::FunctionSkeletonList parse(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& function_skeleton_list_recursively_node); -extern pddl::FunctionSkeletonList parse(const ast::Functions& functions_node, Context& context); +extern FunctionSkeletonList parse(const std::vector& formula_skeleton_nodes); +extern FunctionSkeletonList parse(const ast::FunctionTypedListOfAtomicFunctionSkeletonsRecursively& function_skeleton_list_recursively_node); +extern FunctionSkeletonList parse(const ast::Functions& functions_node, Context& context); -class FunctionSkeletonListVisitor : boost::static_visitor +class FunctionSkeletonListVisitor : boost::static_visitor { private: Context& context; @@ -108,23 +108,23 @@ class FunctionSkeletonListVisitor : boost::static_visitor - pddl::FunctionSkeletonList operator()(const Node& node) + FunctionSkeletonList operator()(const Node& node) { return parse(node, context); } }; /* FunctionExpression */ -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpression& node, Context& context); -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpressionNumber& node, Context& context); -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpressionBinaryOperator& node, Context& context); -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpressionMultiOperator& node, Context& context); -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpressionMinus& node, Context& context); -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpressionBasicFunctionTerm& node, Context& context); -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpressionTotalTime& node, Context& context); -extern pddl::FunctionExpression parse(const ast::MetricFunctionExpressionPreferences& node, Context& context); - -class MetricFunctionExpressionDeclarationVisitor : boost::static_visitor +extern FunctionExpression parse(const ast::MetricFunctionExpression& node, Context& context); +extern FunctionExpression parse(const ast::MetricFunctionExpressionNumber& node, Context& context); +extern FunctionExpression parse(const ast::MetricFunctionExpressionBinaryOperator& node, Context& context); +extern FunctionExpression parse(const ast::MetricFunctionExpressionMultiOperator& node, Context& context); +extern FunctionExpression parse(const ast::MetricFunctionExpressionMinus& node, Context& context); +extern FunctionExpression parse(const ast::MetricFunctionExpressionBasicFunctionTerm& node, Context& context); +extern FunctionExpression parse(const ast::MetricFunctionExpressionTotalTime& node, Context& context); +extern FunctionExpression parse(const ast::MetricFunctionExpressionPreferences& node, Context& context); + +class MetricFunctionExpressionDeclarationVisitor : boost::static_visitor { private: Context& context; @@ -133,14 +133,14 @@ class MetricFunctionExpressionDeclarationVisitor : boost::static_visitor - pddl::FunctionExpression operator()(const Node& node) const + FunctionExpression operator()(const Node& node) const { return parse(node, context); } }; /* Function */ -extern pddl::Function parse(const ast::BasicFunctionTerm& node, Context& context); +extern Function parse(const ast::BasicFunctionTerm& node, Context& context); } diff --git a/src/pddl/parser/goal.cpp b/src/pddl/parser/goal.cpp index 6d2977c0..ed470a4a 100644 --- a/src/pddl/parser/goal.cpp +++ b/src/pddl/parser/goal.cpp @@ -25,7 +25,7 @@ namespace loki { -pddl::Condition parse(const ast::Goal& node, Context& context) +Condition parse(const ast::Goal& node, Context& context) { const auto condition = parse(node.precondition_goal_descriptor, context); return condition; diff --git a/src/pddl/parser/goal.hpp b/src/pddl/parser/goal.hpp index ff44ed43..452bf6fc 100644 --- a/src/pddl/parser/goal.hpp +++ b/src/pddl/parser/goal.hpp @@ -24,7 +24,7 @@ namespace loki { -extern pddl::Condition parse(const ast::Goal& node, Context& context); +extern Condition parse(const ast::Goal& node, Context& context); } diff --git a/src/pddl/parser/ground_literal.cpp b/src/pddl/parser/ground_literal.cpp index a59de8a4..cbb19f95 100644 --- a/src/pddl/parser/ground_literal.cpp +++ b/src/pddl/parser/ground_literal.cpp @@ -25,15 +25,15 @@ namespace loki { /* Atom */ -pddl::GroundAtom parse(const ast::AtomicFormulaOfNamesPredicate& node, Context& context) +GroundAtom parse(const ast::AtomicFormulaOfNamesPredicate& node, Context& context) { const auto name = parse(node.predicate.name); - const auto binding = context.scopes.get(name); + const auto binding = context.scopes.get(name); if (!binding.has_value()) { throw UndefinedPredicateError(name, context.scopes.get_error_handler()(node, "")); } - auto object_list = pddl::ObjectList(); + auto object_list = ObjectList(); for (const auto& name_node : node.names) { object_list.push_back(parse_object_reference(name_node, context)); @@ -43,49 +43,46 @@ pddl::GroundAtom parse(const ast::AtomicFormulaOfNamesPredicate& node, Context& { throw MismatchedPredicateObjectListError(predicate, object_list, context.scopes.get_error_handler()(node, "")); } - const auto atom = context.factories.ground_atoms.get_or_create(predicate, object_list); + const auto atom = context.factories.get_or_create_ground_atom(predicate, object_list); context.positions.push_back(atom, node); return atom; } -pddl::GroundAtom parse(const ast::AtomicFormulaOfNamesEquality& node, Context& context) +GroundAtom parse(const ast::AtomicFormulaOfNamesEquality& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::EQUALITY)) + if (!context.requirements->test(RequirementEnum::EQUALITY)) { - throw UndefinedRequirementError(pddl::RequirementEnum::EQUALITY, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::EQUALITY, context.scopes.get_error_handler()(node, "")); } - assert(context.scopes.get("=").has_value()); - const auto [equal_predicate, _position, _error_handler] = context.scopes.get("=").value(); + assert(context.scopes.get("=").has_value()); + const auto [equal_predicate, _position, _error_handler] = context.scopes.get("=").value(); const auto object_left = parse_object_reference(node.name_left, context); const auto object_right = parse_object_reference(node.name_right, context); - const auto atom = context.factories.ground_atoms.get_or_create(equal_predicate, pddl::ObjectList { object_left, object_right }); + const auto atom = context.factories.get_or_create_ground_atom(equal_predicate, ObjectList { object_left, object_right }); context.positions.push_back(atom, node); return atom; } -pddl::GroundAtom parse(const ast::AtomicFormulaOfNames& node, Context& context) -{ - return boost::apply_visitor(GroundAtomicFormulaOfNamesVisitor(context), node); -} +GroundAtom parse(const ast::AtomicFormulaOfNames& node, Context& context) { return boost::apply_visitor(GroundAtomicFormulaOfNamesVisitor(context), node); } GroundAtomicFormulaOfNamesVisitor::GroundAtomicFormulaOfNamesVisitor(Context& context_) : context(context_) {} /* Literal */ -pddl::GroundLiteral parse(const ast::GroundAtom& node, Context& context) +GroundLiteral parse(const ast::GroundAtom& node, Context& context) { - const auto literal = context.factories.ground_literals.get_or_create(false, parse(node.atomic_formula_of_names, context)); + const auto literal = context.factories.get_or_create_ground_literal(false, parse(node.atomic_formula_of_names, context)); context.positions.push_back(literal, node); return literal; } -pddl::GroundLiteral parse(const ast::NegatedGroundAtom& node, Context& context) +GroundLiteral parse(const ast::NegatedGroundAtom& node, Context& context) { - const auto literal = context.factories.ground_literals.get_or_create(true, parse(node.atomic_formula_of_names, context)); + const auto literal = context.factories.get_or_create_ground_literal(true, parse(node.atomic_formula_of_names, context)); context.positions.push_back(literal, node); return literal; } -pddl::GroundLiteral parse(const ast::GroundLiteral& node, Context& context) { return boost::apply_visitor(GroundLiteralVisitor(context), node); } +GroundLiteral parse(const ast::GroundLiteral& node, Context& context) { return boost::apply_visitor(GroundLiteralVisitor(context), node); } GroundLiteralVisitor::GroundLiteralVisitor(Context& context_) : context(context_) {} diff --git a/src/pddl/parser/ground_literal.hpp b/src/pddl/parser/ground_literal.hpp index 00cfcd52..a1b22d10 100644 --- a/src/pddl/parser/ground_literal.hpp +++ b/src/pddl/parser/ground_literal.hpp @@ -25,11 +25,11 @@ namespace loki { /* Atom */ -extern pddl::GroundAtom parse(const ast::AtomicFormulaOfNamesPredicate& node, Context& context); -extern pddl::GroundAtom parse(const ast::AtomicFormulaOfNamesEquality& node, Context& context); -extern pddl::GroundAtom parse(const ast::AtomicFormulaOfNames& node, Context& context); +extern GroundAtom parse(const ast::AtomicFormulaOfNamesPredicate& node, Context& context); +extern GroundAtom parse(const ast::AtomicFormulaOfNamesEquality& node, Context& context); +extern GroundAtom parse(const ast::AtomicFormulaOfNames& node, Context& context); -class GroundAtomicFormulaOfNamesVisitor : boost::static_visitor +class GroundAtomicFormulaOfNamesVisitor : boost::static_visitor { private: Context& context; @@ -38,18 +38,18 @@ class GroundAtomicFormulaOfNamesVisitor : boost::static_visitor - pddl::GroundAtom operator()(const Node& node) const + GroundAtom operator()(const Node& node) const { return parse(node, context); } }; /* Literal */ -extern pddl::GroundLiteral parse(const ast::GroundAtom& node, Context& context); -extern pddl::GroundLiteral parse(const ast::NegatedGroundAtom& node, Context& context); -extern pddl::GroundLiteral parse(const ast::GroundLiteral& node, Context& context); +extern GroundLiteral parse(const ast::GroundAtom& node, Context& context); +extern GroundLiteral parse(const ast::NegatedGroundAtom& node, Context& context); +extern GroundLiteral parse(const ast::GroundLiteral& node, Context& context); -class GroundLiteralVisitor : boost::static_visitor +class GroundLiteralVisitor : boost::static_visitor { private: Context& context; @@ -58,7 +58,7 @@ class GroundLiteralVisitor : boost::static_visitor GroundLiteralVisitor(Context& context_); template - pddl::GroundLiteral operator()(const Node& node) const + GroundLiteral operator()(const Node& node) const { return parse(node, context); } diff --git a/src/pddl/parser/initial.cpp b/src/pddl/parser/initial.cpp index e168f278..375b0457 100644 --- a/src/pddl/parser/initial.cpp +++ b/src/pddl/parser/initial.cpp @@ -26,9 +26,9 @@ namespace loki { -std::vector> parse(const ast::Initial& initial_node, Context& context) +std::vector> parse(const ast::Initial& initial_node, Context& context) { - auto initial_element_list = std::vector>(); + auto initial_element_list = std::vector>(); for (const auto& initial_element : initial_node.initial_elements) { initial_element_list.push_back(boost::apply_visitor(InitialElementVisitor(context), initial_element)); @@ -36,44 +36,44 @@ std::vector> parse(const return initial_element_list; } -std::variant parse(const ast::InitialElementLiteral& node, Context& context) { return parse(node.literal, context); } +std::variant parse(const ast::InitialElementLiteral& node, Context& context) { return parse(node.literal, context); } -std::variant parse(const ast::InitialElementTimedLiterals& /*node*/, Context& /*context*/) +std::variant parse(const ast::InitialElementTimedLiterals& /*node*/, Context& /*context*/) { throw NotImplementedError("InitialElementVisitor::operator()(const ast::InitialElementTimedLiterals& node)"); } -std::variant parse(const ast::InitialElementNumericFluentsTotalCost& node, Context& context) +std::variant parse(const ast::InitialElementNumericFluentsTotalCost& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::ACTION_COSTS)) + if (!context.requirements->test(RequirementEnum::ACTION_COSTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::ACTION_COSTS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::ACTION_COSTS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::ACTION_COSTS); + context.references.untrack(RequirementEnum::ACTION_COSTS); const auto function_skeleton = parse_function_skeleton_reference(node.function_symbol_total_cost, context); - const auto basic_function_term = context.factories.functions.get_or_create(function_skeleton, pddl::TermList {}); + const auto basic_function_term = context.factories.get_or_create_function(function_skeleton, TermList {}); double number = parse(node.number); if (number < 0) { throw NegativeCostError(context.positions.get_error_handler()(node.number, "")); } - return context.factories.numeric_fluents.get_or_create(basic_function_term, number); + return context.factories.get_or_create_numeric_fluent(basic_function_term, number); } -std::variant parse(const ast::InitialElementNumericFluentsGeneral& node, Context& context) +std::variant parse(const ast::InitialElementNumericFluentsGeneral& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::NUMERIC_FLUENTS)) + if (!context.requirements->test(RequirementEnum::NUMERIC_FLUENTS)) { - throw UndefinedRequirementError(pddl::RequirementEnum::NUMERIC_FLUENTS, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::NUMERIC_FLUENTS, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::NUMERIC_FLUENTS); + context.references.untrack(RequirementEnum::NUMERIC_FLUENTS); const auto basic_function_term = parse(node.basic_function_term, context); double number = parse(node.number); - if (number < 0 && context.requirements->test(pddl::RequirementEnum::ACTION_COSTS)) + if (number < 0 && context.requirements->test(RequirementEnum::ACTION_COSTS)) { throw NegativeCostError(context.positions.get_error_handler()(node.number, "")); } - return context.factories.numeric_fluents.get_or_create(basic_function_term, number); + return context.factories.get_or_create_numeric_fluent(basic_function_term, number); } InitialElementVisitor::InitialElementVisitor(Context& context_) : context(context_) {} diff --git a/src/pddl/parser/initial.hpp b/src/pddl/parser/initial.hpp index 825b568d..5275f366 100644 --- a/src/pddl/parser/initial.hpp +++ b/src/pddl/parser/initial.hpp @@ -27,14 +27,14 @@ namespace loki { /* Init */ -extern std::vector> parse(const ast::Initial& initial_node, Context& context); +extern std::vector> parse(const ast::Initial& initial_node, Context& context); -extern std::variant parse(const ast::InitialElementLiteral& node); -extern std::variant parse(const ast::InitialElementTimedLiterals& node); -extern std::variant parse(const ast::InitialElementNumericFluentsTotalCost& node); -extern std::variant parse(const ast::InitialElementNumericFluentsGeneral& node); +extern std::variant parse(const ast::InitialElementLiteral& node); +extern std::variant parse(const ast::InitialElementTimedLiterals& node); +extern std::variant parse(const ast::InitialElementNumericFluentsTotalCost& node); +extern std::variant parse(const ast::InitialElementNumericFluentsGeneral& node); -class InitialElementVisitor : boost::static_visitor> +class InitialElementVisitor : boost::static_visitor> { private: Context& context; @@ -43,7 +43,7 @@ class InitialElementVisitor : boost::static_visitor - std::variant operator()(const Node& node) const + std::variant operator()(const Node& node) const { return parse(node, context); } diff --git a/src/pddl/parser/literal.cpp b/src/pddl/parser/literal.cpp index 8e5e2894..335e2cf2 100644 --- a/src/pddl/parser/literal.cpp +++ b/src/pddl/parser/literal.cpp @@ -23,15 +23,15 @@ namespace loki { -pddl::Atom parse(const ast::AtomicFormulaOfTermsPredicate& node, Context& context) +Atom parse(const ast::AtomicFormulaOfTermsPredicate& node, Context& context) { auto predicate_name = parse(node.predicate.name); - auto binding = context.scopes.get(predicate_name); + auto binding = context.scopes.get(predicate_name); if (!binding.has_value()) { throw UndefinedPredicateError(predicate_name, context.scopes.get_error_handler()(node.predicate, "")); } - auto term_list = pddl::TermList(); + auto term_list = TermList(); for (const auto& term_node : node.terms) { term_list.push_back(boost::apply_visitor(TermReferenceTermVisitor(context), term_node)); @@ -42,47 +42,47 @@ pddl::Atom parse(const ast::AtomicFormulaOfTermsPredicate& node, Context& contex throw MismatchedPredicateTermListError(predicate, term_list, context.scopes.get_error_handler()(node, "")); } context.references.untrack(predicate); - const auto atom = context.factories.atoms.get_or_create(predicate, term_list); + const auto atom = context.factories.get_or_create_atom(predicate, term_list); context.positions.push_back(atom, node); return atom; } -pddl::Atom parse(const ast::AtomicFormulaOfTermsEquality& node, Context& context) +Atom parse(const ast::AtomicFormulaOfTermsEquality& node, Context& context) { // requires :equality - if (!context.requirements->test(pddl::RequirementEnum::EQUALITY)) + if (!context.requirements->test(RequirementEnum::EQUALITY)) { - throw UndefinedRequirementError(pddl::RequirementEnum::EQUALITY, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::EQUALITY, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::EQUALITY); - assert(context.scopes.get("=").has_value()); - const auto [equal_predicate, _position, _error_handler] = context.scopes.get("=").value(); + context.references.untrack(RequirementEnum::EQUALITY); + assert(context.scopes.get("=").has_value()); + const auto [equal_predicate, _position, _error_handler] = context.scopes.get("=").value(); auto left_term = boost::apply_visitor(TermReferenceTermVisitor(context), node.term_left); auto right_term = boost::apply_visitor(TermReferenceTermVisitor(context), node.term_right); - const auto atom = context.factories.atoms.get_or_create(equal_predicate, pddl::TermList { left_term, right_term }); + const auto atom = context.factories.get_or_create_atom(equal_predicate, TermList { left_term, right_term }); context.positions.push_back(atom, node); return atom; } -pddl::Atom parse(const ast::AtomicFormulaOfTerms& node, Context& context) { return boost::apply_visitor(AtomicFormulaOfTermsVisitor(context), node); } +Atom parse(const ast::AtomicFormulaOfTerms& node, Context& context) { return boost::apply_visitor(AtomicFormulaOfTermsVisitor(context), node); } AtomicFormulaOfTermsVisitor::AtomicFormulaOfTermsVisitor(Context& context_) : context(context_) {} -pddl::Literal parse(const ast::Atom& node, Context& context) +Literal parse(const ast::Atom& node, Context& context) { - const auto literal = context.factories.literals.get_or_create(false, parse(node.atomic_formula_of_terms, context)); + const auto literal = context.factories.get_or_create_literal(false, parse(node.atomic_formula_of_terms, context)); context.positions.push_back(literal, node); return literal; } -pddl::Literal parse(const ast::NegatedAtom& node, Context& context) +Literal parse(const ast::NegatedAtom& node, Context& context) { - const auto literal = context.factories.literals.get_or_create(true, parse(node.atomic_formula_of_terms, context)); + const auto literal = context.factories.get_or_create_literal(true, parse(node.atomic_formula_of_terms, context)); context.positions.push_back(literal, node); return literal; } -pddl::Literal parse(const ast::Literal& node, Context& context) { return boost::apply_visitor(LiteralVisitor(context), node); } +Literal parse(const ast::Literal& node, Context& context) { return boost::apply_visitor(LiteralVisitor(context), node); } LiteralVisitor::LiteralVisitor(Context& context_) : context(context_) {} diff --git a/src/pddl/parser/literal.hpp b/src/pddl/parser/literal.hpp index 34b8bd57..7d650b27 100644 --- a/src/pddl/parser/literal.hpp +++ b/src/pddl/parser/literal.hpp @@ -25,36 +25,36 @@ namespace loki { /* Atom */ -extern pddl::Atom parse(const ast::AtomicFormulaOfTermsPredicate& node, Context& context); -extern pddl::Atom parse(const ast::AtomicFormulaOfTermsEquality& node, Context& context); -extern pddl::Atom parse(const ast::AtomicFormulaOfTerms& node, Context& context); +extern Atom parse(const ast::AtomicFormulaOfTermsPredicate& node, Context& context); +extern Atom parse(const ast::AtomicFormulaOfTermsEquality& node, Context& context); +extern Atom parse(const ast::AtomicFormulaOfTerms& node, Context& context); -struct AtomicFormulaOfTermsVisitor : boost::static_visitor +struct AtomicFormulaOfTermsVisitor : boost::static_visitor { Context& context; AtomicFormulaOfTermsVisitor(Context& context_); template - pddl::Atom operator()(const Node& node) const + Atom operator()(const Node& node) const { return parse(node, context); } }; /* Literal */ -extern pddl::Literal parse(const ast::Atom& node, Context& context); -extern pddl::Literal parse(const ast::NegatedAtom& node, Context& context); -extern pddl::Literal parse(const ast::Literal& node, Context& context); +extern Literal parse(const ast::Atom& node, Context& context); +extern Literal parse(const ast::NegatedAtom& node, Context& context); +extern Literal parse(const ast::Literal& node, Context& context); -struct LiteralVisitor : boost::static_visitor +struct LiteralVisitor : boost::static_visitor { Context& context; LiteralVisitor(Context& context_); template - pddl::Literal operator()(const Node& node) const + Literal operator()(const Node& node) const { return parse(node, context); } diff --git a/src/pddl/parser/metric.cpp b/src/pddl/parser/metric.cpp index 3da59057..a1cc4af2 100644 --- a/src/pddl/parser/metric.cpp +++ b/src/pddl/parser/metric.cpp @@ -27,37 +27,34 @@ namespace loki { /* OptimizationMetricEnum */ -pddl::OptimizationMetricEnum parse(const ast::Optimization& node, Context& context) -{ - return boost::apply_visitor(OptimizationDeclarationVisitor(context), node); -} +OptimizationMetricEnum parse(const ast::Optimization& node, Context& context) { return boost::apply_visitor(OptimizationDeclarationVisitor(context), node); } -pddl::OptimizationMetricEnum parse(const ast::OptimizationMinimize& /*node*/, Context& /*context*/) { return pddl::OptimizationMetricEnum::MINIMIZE; } +OptimizationMetricEnum parse(const ast::OptimizationMinimize& /*node*/, Context& /*context*/) { return OptimizationMetricEnum::MINIMIZE; } -pddl::OptimizationMetricEnum parse(const ast::OptimizationMaximize& /*node*/, Context& /*context*/) { return pddl::OptimizationMetricEnum::MAXIMIZE; } +OptimizationMetricEnum parse(const ast::OptimizationMaximize& /*node*/, Context& /*context*/) { return OptimizationMetricEnum::MAXIMIZE; } OptimizationDeclarationVisitor::OptimizationDeclarationVisitor(Context& context_) : context(context_) {} /* OptimizationMetric */ -pddl::OptimizationMetric parse(const ast::MetricSpecification& node, Context& context) +OptimizationMetric parse(const ast::MetricSpecification& node, Context& context) { return boost::apply_visitor(MetricSpecificationDeclarationVisitor(context), node); } -pddl::OptimizationMetric parse(const ast::MetricSpecificationTotalCost& node, Context& context) +OptimizationMetric parse(const ast::MetricSpecificationTotalCost& node, Context& context) { - const auto optimization = pddl::OptimizationMetricEnum::MINIMIZE; + const auto optimization = OptimizationMetricEnum::MINIMIZE; const auto function_skeleton = parse_function_skeleton_reference(node.function_symbol_total_cost, context); - const auto function = context.factories.functions.get_or_create(function_skeleton, pddl::TermList {}); - const auto function_expression = context.factories.function_expressions.get_or_create(function); - return context.factories.optimization_metrics.get_or_create(optimization, function_expression); + const auto function = context.factories.get_or_create_function(function_skeleton, TermList {}); + const auto function_expression = context.factories.get_or_create_function_expression_function(function); + return context.factories.get_or_create_optimization_metric(optimization, function_expression); } -pddl::OptimizationMetric parse(const ast::MetricSpecificationGeneral& node, Context& context) +OptimizationMetric parse(const ast::MetricSpecificationGeneral& node, Context& context) { const auto optimization = parse(node.optimization, context); const auto function_expression = parse(node.metric_function_expression, context); - return context.factories.optimization_metrics.get_or_create(optimization, function_expression); + return context.factories.get_or_create_optimization_metric(optimization, function_expression); } MetricSpecificationDeclarationVisitor::MetricSpecificationDeclarationVisitor(Context& context_) : context(context_) {} diff --git a/src/pddl/parser/metric.hpp b/src/pddl/parser/metric.hpp index 79c0e1bb..a7083644 100644 --- a/src/pddl/parser/metric.hpp +++ b/src/pddl/parser/metric.hpp @@ -25,11 +25,11 @@ namespace loki { /* OptimizationMetricEnum */ -extern pddl::OptimizationMetricEnum parse(const ast::Optimization& node, Context& context); -extern pddl::OptimizationMetricEnum parse(const ast::OptimizationMinimize& node, Context& context); -extern pddl::OptimizationMetricEnum parse(const ast::OptimizationMaximize& node, Context& context); +extern OptimizationMetricEnum parse(const ast::Optimization& node, Context& context); +extern OptimizationMetricEnum parse(const ast::OptimizationMinimize& node, Context& context); +extern OptimizationMetricEnum parse(const ast::OptimizationMaximize& node, Context& context); -class OptimizationDeclarationVisitor : boost::static_visitor +class OptimizationDeclarationVisitor : boost::static_visitor { private: Context& context; @@ -38,18 +38,18 @@ class OptimizationDeclarationVisitor : boost::static_visitor - pddl::OptimizationMetricEnum operator()(const Node& node) const + OptimizationMetricEnum operator()(const Node& node) const { return parse(node, context); } }; /* OptimizationMetric */ -extern pddl::OptimizationMetric parse(const ast::MetricSpecification& node, Context& context); -extern pddl::OptimizationMetric parse(const ast::MetricSpecificationTotalCost& node, Context& context); -extern pddl::OptimizationMetric parse(const ast::MetricSpecificationGeneral& node, Context& context); +extern OptimizationMetric parse(const ast::MetricSpecification& node, Context& context); +extern OptimizationMetric parse(const ast::MetricSpecificationTotalCost& node, Context& context); +extern OptimizationMetric parse(const ast::MetricSpecificationGeneral& node, Context& context); -class MetricSpecificationDeclarationVisitor : boost::static_visitor +class MetricSpecificationDeclarationVisitor : boost::static_visitor { private: Context& context; @@ -58,7 +58,7 @@ class MetricSpecificationDeclarationVisitor : boost::static_visitor - pddl::OptimizationMetric operator()(const Node& node) const + OptimizationMetric operator()(const Node& node) const { return parse(node, context); } diff --git a/src/pddl/parser/objects.cpp b/src/pddl/parser/objects.cpp index 6ce879b9..019450f8 100644 --- a/src/pddl/parser/objects.cpp +++ b/src/pddl/parser/objects.cpp @@ -28,10 +28,10 @@ namespace loki ObjectListVisitor::ObjectListVisitor(Context& context_) : context(context_) {} -pddl::Object parse_object_reference(const ast::Name& name_node, Context& context) +Object parse_object_reference(const ast::Name& name_node, Context& context) { const auto name = parse(name_node); - const auto binding = context.scopes.get(name); + const auto binding = context.scopes.get(name); if (!binding.has_value()) { throw UndefinedObjectError(name, context.scopes.get_error_handler()(name_node, "")); @@ -44,7 +44,7 @@ pddl::Object parse_object_reference(const ast::Name& name_node, Context& context static void test_multiple_definition_object(const std::string& object_name, const ast::Name& name_node, const Context& context) { - const auto binding = context.scopes.get(object_name); + const auto binding = context.scopes.get(object_name); if (binding.has_value()) { const auto message_1 = context.scopes.get_error_handler()(name_node, "Defined here:"); @@ -58,19 +58,19 @@ static void test_multiple_definition_object(const std::string& object_name, cons } } -static pddl::Object parse_object_definition(const ast::Name& name_node, const pddl::TypeList& type_list, Context& context) +static Object parse_object_definition(const ast::Name& name_node, const TypeList& type_list, Context& context) { const auto name = parse(name_node); test_multiple_definition_object(name, name_node, context); - const auto object = context.factories.objects.get_or_create(name, type_list); + const auto object = context.factories.get_or_create_object(name, type_list); context.positions.push_back(object, name_node); context.scopes.insert(name, object, name_node); return object; } -static pddl::ObjectList parse_object_definitions(const std::vector& name_nodes, const pddl::TypeList& type_list, Context& context) +static ObjectList parse_object_definitions(const std::vector& name_nodes, const TypeList& type_list, Context& context) { - auto object_list = pddl::ObjectList(); + auto object_list = ObjectList(); for (const auto& name_node : name_nodes) { object_list.emplace_back(parse_object_definition(name_node, type_list, context)); @@ -78,22 +78,22 @@ static pddl::ObjectList parse_object_definitions(const std::vector& n return object_list; } -pddl::ObjectList ObjectListVisitor::operator()(const std::vector& name_nodes) +ObjectList ObjectListVisitor::operator()(const std::vector& name_nodes) { // std::vector has single base type "object" - assert(context.scopes.get("object").has_value()); - const auto [type, _position, _error_handler] = context.scopes.get("object").value(); - auto object_list = parse_object_definitions(name_nodes, pddl::TypeList { type }, context); + assert(context.scopes.get("object").has_value()); + const auto [type, _position, _error_handler] = context.scopes.get("object").value(); + auto object_list = parse_object_definitions(name_nodes, TypeList { type }, context); return object_list; } -pddl::ObjectList ObjectListVisitor::operator()(const ast::TypedListOfNamesRecursively& node) +ObjectList ObjectListVisitor::operator()(const ast::TypedListOfNamesRecursively& node) { - if (!context.requirements->test(pddl::RequirementEnum::TYPING)) + if (!context.requirements->test(RequirementEnum::TYPING)) { - throw UndefinedRequirementError(pddl::RequirementEnum::TYPING, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::TYPING, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::TYPING); + context.references.untrack(RequirementEnum::TYPING); // TypedListOfNamesRecursively has user defined base types const auto type_list = boost::apply_visitor(TypeReferenceTypeVisitor(context), node.type); auto object_list = parse_object_definitions(node.names, type_list, context); @@ -103,7 +103,7 @@ pddl::ObjectList ObjectListVisitor::operator()(const ast::TypedListOfNamesRecurs return object_list; } -pddl::ObjectList parse(const ast::Objects& objects_node, Context& context) +ObjectList parse(const ast::Objects& objects_node, Context& context) { return boost::apply_visitor(ObjectListVisitor(context), objects_node.typed_list_of_names); } diff --git a/src/pddl/parser/objects.hpp b/src/pddl/parser/objects.hpp index cafc11f2..efae46c1 100644 --- a/src/pddl/parser/objects.hpp +++ b/src/pddl/parser/objects.hpp @@ -25,11 +25,11 @@ namespace loki { /* Object */ -extern pddl::Object parse_object_reference(const ast::Name& name_node, Context& context); +extern Object parse_object_reference(const ast::Name& name_node, Context& context); -extern pddl::ObjectList parse(const ast::Objects& objects_node, Context& context); +extern ObjectList parse(const ast::Objects& objects_node, Context& context); -class ObjectListVisitor : boost::static_visitor +class ObjectListVisitor : boost::static_visitor { private: Context& context; @@ -37,9 +37,9 @@ class ObjectListVisitor : boost::static_visitor public: ObjectListVisitor(Context& context_); - pddl::ObjectList operator()(const std::vector& name_nodes); + ObjectList operator()(const std::vector& name_nodes); - pddl::ObjectList operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node); + ObjectList operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node); }; } diff --git a/src/pddl/parser/parameters.cpp b/src/pddl/parser/parameters.cpp index a54e9005..de638b0e 100644 --- a/src/pddl/parser/parameters.cpp +++ b/src/pddl/parser/parameters.cpp @@ -26,9 +26,9 @@ using namespace std; namespace loki { -static void test_multiple_definition(const pddl::Variable& variable, const ast::Variable& node, const Context& context) +static void test_multiple_definition(const Variable& variable, const ast::Variable& node, const Context& context) { - const auto binding = context.scopes.get(variable->get_name()); + const auto binding = context.scopes.get(variable->get_name()); if (binding.has_value()) { const auto message_1 = context.scopes.get_error_handler()(node, "Defined here:"); @@ -42,25 +42,25 @@ static void test_multiple_definition(const pddl::Variable& variable, const ast:: } } -static void insert_context_information(const pddl::Variable& variable, const ast::Variable& node, Context& context) +static void insert_context_information(const Variable& variable, const ast::Variable& node, Context& context) { context.scopes.insert(variable->get_name(), variable, node); } -static pddl::Parameter parse_parameter_definition(const ast::Variable& variable_node, const pddl::TypeList& type_list, Context& context) +static Parameter parse_parameter_definition(const ast::Variable& variable_node, const TypeList& type_list, Context& context) { const auto variable = parse(variable_node, context); test_multiple_definition(variable, variable_node, context); insert_context_information(variable, variable_node, context); - const auto parameter = context.factories.parameters.get_or_create(variable, type_list); + const auto parameter = context.factories.get_or_create_parameter(variable, type_list); context.positions.push_back(parameter, variable_node); return parameter; } -static pddl::ParameterList parse_parameter_definitions(const std::vector& variable_nodes, const pddl::TypeList& type_list, Context& context) +static ParameterList parse_parameter_definitions(const std::vector& variable_nodes, const TypeList& type_list, Context& context) { - auto parameter_list = pddl::ParameterList(); + auto parameter_list = ParameterList(); for (const auto& variable_node : variable_nodes) { parameter_list.push_back(parse_parameter_definition(variable_node, type_list, context)); @@ -70,22 +70,22 @@ static pddl::ParameterList parse_parameter_definitions(const std::vector& nodes) +ParameterList ParameterListVisitor::operator()(const std::vector& nodes) { // std::vector has single base type "object" - const auto type = context.factories.types.get_or_create("object", pddl::TypeList()); - auto parameter_list = parse_parameter_definitions(nodes, pddl::TypeList { type }, context); + const auto type = context.factories.get_or_create_type("object", TypeList()); + auto parameter_list = parse_parameter_definitions(nodes, TypeList { type }, context); return parameter_list; } -pddl::ParameterList ParameterListVisitor::operator()(const ast::TypedListOfVariablesRecursively& node) +ParameterList ParameterListVisitor::operator()(const ast::TypedListOfVariablesRecursively& node) { // requires :typing - if (!context.requirements->test(pddl::RequirementEnum::TYPING)) + if (!context.requirements->test(RequirementEnum::TYPING)) { - throw UndefinedRequirementError(pddl::RequirementEnum::TYPING, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::TYPING, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::TYPING); + context.references.untrack(RequirementEnum::TYPING); const auto type_list = boost::apply_visitor(TypeReferenceTypeVisitor(context), node.type); // TypedListOfVariablesRecursively has user defined types auto parameter_list = parse_parameter_definitions(node.variables, type_list, context); diff --git a/src/pddl/parser/parameters.hpp b/src/pddl/parser/parameters.hpp index 0558a1bf..aed260c3 100644 --- a/src/pddl/parser/parameters.hpp +++ b/src/pddl/parser/parameters.hpp @@ -27,7 +27,7 @@ namespace loki { /* ParameterList */ -class ParameterListVisitor : boost::static_visitor +class ParameterListVisitor : boost::static_visitor { private: Context& context; @@ -35,9 +35,9 @@ class ParameterListVisitor : boost::static_visitor public: ParameterListVisitor(Context& context_); - pddl::ParameterList operator()(const std::vector& nodes); + ParameterList operator()(const std::vector& nodes); - pddl::ParameterList operator()(const ast::TypedListOfVariablesRecursively& node); + ParameterList operator()(const ast::TypedListOfVariablesRecursively& node); }; } diff --git a/src/pddl/parser/predicates.cpp b/src/pddl/parser/predicates.cpp index c3972ae4..a95b80ca 100644 --- a/src/pddl/parser/predicates.cpp +++ b/src/pddl/parser/predicates.cpp @@ -24,10 +24,10 @@ namespace loki { -static void test_multiple_definition(const pddl::Predicate& predicate, const ast::Predicate& node, const Context& context) +static void test_multiple_definition(const Predicate& predicate, const ast::Predicate& node, const Context& context) { const auto predicate_name = predicate->get_name(); - const auto binding = context.scopes.get(predicate_name); + const auto binding = context.scopes.get(predicate_name); if (binding.has_value()) { const auto message_1 = context.scopes.get_error_handler()(node, "Defined here:"); @@ -41,27 +41,27 @@ static void test_multiple_definition(const pddl::Predicate& predicate, const ast } } -static void insert_context_information(const pddl::Predicate& predicate, const ast::Predicate& node, Context& context) +static void insert_context_information(const Predicate& predicate, const ast::Predicate& node, Context& context) { context.positions.push_back(predicate, node); context.scopes.insert(predicate->get_name(), predicate, node); } -static pddl::Predicate parse_predicate_definition(const ast::AtomicFormulaSkeleton& node, Context& context) +static Predicate parse_predicate_definition(const ast::AtomicFormulaSkeleton& node, Context& context) { context.scopes.open_scope(); const auto parameters = boost::apply_visitor(ParameterListVisitor(context), node.typed_list_of_variables); context.scopes.close_scope(); const auto predicate_name = parse(node.predicate.name); - const auto predicate = context.factories.predicates.get_or_create(predicate_name, parameters); + const auto predicate = context.factories.get_or_create_predicate(predicate_name, parameters); test_multiple_definition(predicate, node.predicate, context); insert_context_information(predicate, node.predicate, context); return predicate; } -static pddl::PredicateList parse_predicate_definitions(const std::vector& nodes, Context& context) +static PredicateList parse_predicate_definitions(const std::vector& nodes, Context& context) { - auto predicate_list = pddl::PredicateList(); + auto predicate_list = PredicateList(); for (const auto& node : nodes) { predicate_list.push_back(parse_predicate_definition(node, context)); @@ -69,17 +69,17 @@ static pddl::PredicateList parse_predicate_definitions(const std::vector(predicate_list.begin(), predicate_list.end()); + context.derived_predicates = std::unordered_set(predicate_list.begin(), predicate_list.end()); return predicate_list; } diff --git a/src/pddl/parser/predicates.hpp b/src/pddl/parser/predicates.hpp index 93c21acf..14b37bc6 100644 --- a/src/pddl/parser/predicates.hpp +++ b/src/pddl/parser/predicates.hpp @@ -26,9 +26,9 @@ namespace loki { /* PredicateList */ -extern pddl::PredicateList parse(const ast::Predicates& predicates_node, Context& context); +extern PredicateList parse(const ast::Predicates& predicates_node, Context& context); -extern pddl::PredicateList parse(const ast::DerivedPredicates& derived_predicates_node, Context& context); +extern PredicateList parse(const ast::DerivedPredicates& derived_predicates_node, Context& context); } diff --git a/src/pddl/parser/reference_utils.cpp b/src/pddl/parser/reference_utils.cpp index 6de8a474..73102d18 100644 --- a/src/pddl/parser/reference_utils.cpp +++ b/src/pddl/parser/reference_utils.cpp @@ -22,7 +22,7 @@ namespace loki { -void track_variable_references(const pddl::ParameterList& parameter_list, Context& context) +void track_variable_references(const ParameterList& parameter_list, Context& context) { for (const auto& parameter : parameter_list) { @@ -30,19 +30,19 @@ void track_variable_references(const pddl::ParameterList& parameter_list, Contex } } -void test_variable_references(const pddl::ParameterList& parameter_list, const Context& context) +void test_variable_references(const ParameterList& parameter_list, const Context& context) { for (const auto& parameter : parameter_list) { if (context.references.exists(parameter->get_variable())) { - const auto [variable, position, error_handler] = context.scopes.get(parameter->get_variable()->get_name()).value(); + const auto [variable, position, error_handler] = context.scopes.get(parameter->get_variable()->get_name()).value(); throw UnusedVariableError(variable->get_name(), error_handler(position.value(), "")); } } } -void track_predicate_references(const pddl::PredicateList& predicate_list, Context& context) +void track_predicate_references(const PredicateList& predicate_list, Context& context) { for (const auto& predicate : predicate_list) { @@ -50,19 +50,19 @@ void track_predicate_references(const pddl::PredicateList& predicate_list, Conte } } -void test_predicate_references(const pddl::PredicateList& predicate_list, const Context& context) +void test_predicate_references(const PredicateList& predicate_list, const Context& context) { for (const auto& predicate : predicate_list) { if (context.references.exists(predicate)) { - const auto [_predicate, position, error_handler] = context.scopes.get(predicate->get_name()).value(); + const auto [_predicate, position, error_handler] = context.scopes.get(predicate->get_name()).value(); throw UnusedPredicateError(predicate->get_name(), error_handler(position.value(), "")); } } } -void track_function_skeleton_references(const pddl::FunctionSkeletonList& function_skeleton_list, Context& context) +void track_function_skeleton_references(const FunctionSkeletonList& function_skeleton_list, Context& context) { for (const auto& function_skeleton : function_skeleton_list) { @@ -70,19 +70,19 @@ void track_function_skeleton_references(const pddl::FunctionSkeletonList& functi } } -void test_function_skeleton_references(const pddl::FunctionSkeletonList& function_skeleton_list, const Context& context) +void test_function_skeleton_references(const FunctionSkeletonList& function_skeleton_list, const Context& context) { for (const auto& function_skeleton : function_skeleton_list) { if (context.references.exists(function_skeleton)) { - const auto [_function_skeleton, position, error_handler] = context.scopes.get(function_skeleton->get_name()).value(); + const auto [_function_skeleton, position, error_handler] = context.scopes.get(function_skeleton->get_name()).value(); throw UnusedFunctionSkeletonError(function_skeleton->get_name(), error_handler(position.value(), "")); } } } -void track_object_references(const pddl::ObjectList& object_list, Context& context) +void track_object_references(const ObjectList& object_list, Context& context) { for (const auto& object : object_list) { @@ -90,13 +90,13 @@ void track_object_references(const pddl::ObjectList& object_list, Context& conte } } -void test_object_references(const pddl::ObjectList& object_list, const Context& context) +void test_object_references(const ObjectList& object_list, const Context& context) { for (const auto& object : object_list) { if (context.references.exists(object)) { - const auto [_object, position, error_handler] = context.scopes.get(object->get_name()).value(); + const auto [_object, position, error_handler] = context.scopes.get(object->get_name()).value(); throw UnusedObjectError(object->get_name(), error_handler(position.value(), "")); } } diff --git a/src/pddl/parser/reference_utils.hpp b/src/pddl/parser/reference_utils.hpp index d28d6dd3..8eb40fab 100644 --- a/src/pddl/parser/reference_utils.hpp +++ b/src/pddl/parser/reference_utils.hpp @@ -27,21 +27,21 @@ namespace loki // For tracking an untracking of lists of pddl objects -extern void track_variable_references(const pddl::ParameterList& parameter_list, Context& context); +extern void track_variable_references(const ParameterList& parameter_list, Context& context); -extern void test_variable_references(const pddl::ParameterList& parameter_list, const Context& context); +extern void test_variable_references(const ParameterList& parameter_list, const Context& context); -extern void track_predicate_references(const pddl::PredicateList& predicate_list, Context& context); +extern void track_predicate_references(const PredicateList& predicate_list, Context& context); -extern void test_predicate_references(const pddl::PredicateList& predicate_list, const Context& context); +extern void test_predicate_references(const PredicateList& predicate_list, const Context& context); -extern void track_function_skeleton_references(const pddl::FunctionSkeletonList& function_skeleton_list, Context& context); +extern void track_function_skeleton_references(const FunctionSkeletonList& function_skeleton_list, Context& context); -extern void test_function_skeleton_references(const pddl::FunctionSkeletonList& function_skeleton_list, const Context& context); +extern void test_function_skeleton_references(const FunctionSkeletonList& function_skeleton_list, const Context& context); -extern void track_object_references(const pddl::ObjectList& object_list, Context& context); +extern void track_object_references(const ObjectList& object_list, Context& context); -extern void test_object_references(const pddl::ObjectList& object_list, const Context& context); +extern void test_object_references(const ObjectList& object_list, const Context& context); } diff --git a/src/pddl/parser/requirements.cpp b/src/pddl/parser/requirements.cpp index c36128af..67db2bfa 100644 --- a/src/pddl/parser/requirements.cpp +++ b/src/pddl/parser/requirements.cpp @@ -22,180 +22,178 @@ namespace loki { -pddl::RequirementEnumSet parse(const ast::RequirementStrips&, Context& /*context*/) +RequirementEnumSet parse(const ast::RequirementStrips&, Context& /*context*/) { // Strips as the minimal requirement must not be tracked. - return { pddl::RequirementEnum::STRIPS }; + return { RequirementEnum::STRIPS }; } -pddl::RequirementEnumSet parse(const ast::RequirementTyping&, Context& context) +RequirementEnumSet parse(const ast::RequirementTyping&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::TYPING); - return { pddl::RequirementEnum::TYPING }; + context.references.track(RequirementEnum::TYPING); + return { RequirementEnum::TYPING }; } -pddl::RequirementEnumSet parse(const ast::RequirementNegativePreconditions&, Context& context) +RequirementEnumSet parse(const ast::RequirementNegativePreconditions&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS); - return { pddl::RequirementEnum::NEGATIVE_PRECONDITIONS }; + context.references.track(RequirementEnum::NEGATIVE_PRECONDITIONS); + return { RequirementEnum::NEGATIVE_PRECONDITIONS }; } -pddl::RequirementEnumSet parse(const ast::RequirementDisjunctivePreconditions&, Context& context) +RequirementEnumSet parse(const ast::RequirementDisjunctivePreconditions&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS); - return { pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS }; + context.references.track(RequirementEnum::DISJUNCTIVE_PRECONDITIONS); + return { RequirementEnum::DISJUNCTIVE_PRECONDITIONS }; } -pddl::RequirementEnumSet parse(const ast::RequirementEquality&, Context& context) +RequirementEnumSet parse(const ast::RequirementEquality&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::EQUALITY); - return { pddl::RequirementEnum::EQUALITY }; + context.references.track(RequirementEnum::EQUALITY); + return { RequirementEnum::EQUALITY }; } -pddl::RequirementEnumSet parse(const ast::RequirementExistentialPreconditions&, Context& context) +RequirementEnumSet parse(const ast::RequirementExistentialPreconditions&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS); - return { pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS }; + context.references.track(RequirementEnum::EXISTENTIAL_PRECONDITIONS); + return { RequirementEnum::EXISTENTIAL_PRECONDITIONS }; } -pddl::RequirementEnumSet parse(const ast::RequirementUniversalPreconditions&, Context& context) +RequirementEnumSet parse(const ast::RequirementUniversalPreconditions&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS); - return { pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS }; + context.references.track(RequirementEnum::UNIVERSAL_PRECONDITIONS); + return { RequirementEnum::UNIVERSAL_PRECONDITIONS }; } -pddl::RequirementEnumSet parse(const ast::RequirementQuantifiedPreconditions&, Context& context) +RequirementEnumSet parse(const ast::RequirementQuantifiedPreconditions&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::QUANTIFIED_PRECONDITIONS); - context.references.track(pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS); - context.references.track(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS); - return { pddl::RequirementEnum::QUANTIFIED_PRECONDITIONS, - pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS, - pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS }; + context.references.track(RequirementEnum::QUANTIFIED_PRECONDITIONS); + context.references.track(RequirementEnum::EXISTENTIAL_PRECONDITIONS); + context.references.track(RequirementEnum::UNIVERSAL_PRECONDITIONS); + return { RequirementEnum::QUANTIFIED_PRECONDITIONS, RequirementEnum::EXISTENTIAL_PRECONDITIONS, RequirementEnum::UNIVERSAL_PRECONDITIONS }; } -pddl::RequirementEnumSet parse(const ast::RequirementConditionalEffects&, Context& context) +RequirementEnumSet parse(const ast::RequirementConditionalEffects&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::CONDITIONAL_EFFECTS); - return { pddl::RequirementEnum::CONDITIONAL_EFFECTS }; + context.references.track(RequirementEnum::CONDITIONAL_EFFECTS); + return { RequirementEnum::CONDITIONAL_EFFECTS }; } -pddl::RequirementEnumSet parse(const ast::RequirementFluents&, Context& context) +RequirementEnumSet parse(const ast::RequirementFluents&, Context& context) { // Track // FLUENTS as a composite must not be tracked - context.references.track(pddl::RequirementEnum::OBJECT_FLUENTS); - context.references.track(pddl::RequirementEnum::NUMERIC_FLUENTS); - return { pddl::RequirementEnum::FLUENTS, pddl::RequirementEnum::OBJECT_FLUENTS, pddl::RequirementEnum::NUMERIC_FLUENTS }; + context.references.track(RequirementEnum::OBJECT_FLUENTS); + context.references.track(RequirementEnum::NUMERIC_FLUENTS); + return { RequirementEnum::FLUENTS, RequirementEnum::OBJECT_FLUENTS, RequirementEnum::NUMERIC_FLUENTS }; } -pddl::RequirementEnumSet parse(const ast::RequirementObjectFluents& node, Context& context) +RequirementEnumSet parse(const ast::RequirementObjectFluents& node, Context& context) { // Track - context.references.track(pddl::RequirementEnum::OBJECT_FLUENTS); - throw UnsupportedRequirementError(pddl::RequirementEnum::OBJECT_FLUENTS, context.scopes.get_error_handler()(node, "")); + context.references.track(RequirementEnum::OBJECT_FLUENTS); + throw UnsupportedRequirementError(RequirementEnum::OBJECT_FLUENTS, context.scopes.get_error_handler()(node, "")); - return { pddl::RequirementEnum::OBJECT_FLUENTS }; + return { RequirementEnum::OBJECT_FLUENTS }; } -pddl::RequirementEnumSet parse(const ast::RequirementNumericFluents&, Context& context) +RequirementEnumSet parse(const ast::RequirementNumericFluents&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::NUMERIC_FLUENTS); - return { pddl::RequirementEnum::NUMERIC_FLUENTS }; + context.references.track(RequirementEnum::NUMERIC_FLUENTS); + return { RequirementEnum::NUMERIC_FLUENTS }; } -pddl::RequirementEnumSet parse(const ast::RequirementAdl&, Context& context) +RequirementEnumSet parse(const ast::RequirementAdl&, Context& context) { // Track // Strips as the minimal requirement must not be tracked. // ADL as a composite must not be tracked - context.references.track(pddl::RequirementEnum::TYPING); - context.references.track(pddl::RequirementEnum::NEGATIVE_PRECONDITIONS); - context.references.track(pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS); - context.references.track(pddl::RequirementEnum::EQUALITY); - context.references.track(pddl::RequirementEnum::QUANTIFIED_PRECONDITIONS); - context.references.track(pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS); - context.references.track(pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS); - context.references.track(pddl::RequirementEnum::CONDITIONAL_EFFECTS); - return { pddl::RequirementEnum::ADL, - pddl::RequirementEnum::STRIPS, - pddl::RequirementEnum::TYPING, - pddl::RequirementEnum::NEGATIVE_PRECONDITIONS, - pddl::RequirementEnum::DISJUNCTIVE_PRECONDITIONS, - pddl::RequirementEnum::EQUALITY, - pddl::RequirementEnum::QUANTIFIED_PRECONDITIONS, - pddl::RequirementEnum::EXISTENTIAL_PRECONDITIONS, - pddl::RequirementEnum::UNIVERSAL_PRECONDITIONS, - pddl::RequirementEnum::CONDITIONAL_EFFECTS }; + context.references.track(RequirementEnum::TYPING); + context.references.track(RequirementEnum::NEGATIVE_PRECONDITIONS); + context.references.track(RequirementEnum::DISJUNCTIVE_PRECONDITIONS); + context.references.track(RequirementEnum::EQUALITY); + context.references.track(RequirementEnum::QUANTIFIED_PRECONDITIONS); + context.references.track(RequirementEnum::EXISTENTIAL_PRECONDITIONS); + context.references.track(RequirementEnum::UNIVERSAL_PRECONDITIONS); + context.references.track(RequirementEnum::CONDITIONAL_EFFECTS); + return { RequirementEnum::ADL, + RequirementEnum::STRIPS, + RequirementEnum::TYPING, + RequirementEnum::NEGATIVE_PRECONDITIONS, + RequirementEnum::DISJUNCTIVE_PRECONDITIONS, + RequirementEnum::EQUALITY, + RequirementEnum::QUANTIFIED_PRECONDITIONS, + RequirementEnum::EXISTENTIAL_PRECONDITIONS, + RequirementEnum::UNIVERSAL_PRECONDITIONS, + RequirementEnum::CONDITIONAL_EFFECTS }; } -pddl::RequirementEnumSet parse(const ast::RequirementDurativeActions& node, Context& context) +RequirementEnumSet parse(const ast::RequirementDurativeActions& node, Context& context) { - throw UnsupportedRequirementError(pddl::RequirementEnum::DURATIVE_ACTIONS, context.scopes.get_error_handler()(node, "")); + throw UnsupportedRequirementError(RequirementEnum::DURATIVE_ACTIONS, context.scopes.get_error_handler()(node, "")); // Track - context.references.track(pddl::RequirementEnum::DURATIVE_ACTIONS); - return { pddl::RequirementEnum::DURATIVE_ACTIONS }; + context.references.track(RequirementEnum::DURATIVE_ACTIONS); + return { RequirementEnum::DURATIVE_ACTIONS }; } -pddl::RequirementEnumSet parse(const ast::RequirementDerivedPredicates&, Context& context) +RequirementEnumSet parse(const ast::RequirementDerivedPredicates&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::DERIVED_PREDICATES); - return { pddl::RequirementEnum::DERIVED_PREDICATES }; + context.references.track(RequirementEnum::DERIVED_PREDICATES); + return { RequirementEnum::DERIVED_PREDICATES }; } -pddl::RequirementEnumSet parse(const ast::RequirementTimedInitialLiterals& node, Context& context) +RequirementEnumSet parse(const ast::RequirementTimedInitialLiterals& node, Context& context) { - throw UnsupportedRequirementError(pddl::RequirementEnum::TIMED_INITIAL_LITERALS, context.scopes.get_error_handler()(node, "")); + throw UnsupportedRequirementError(RequirementEnum::TIMED_INITIAL_LITERALS, context.scopes.get_error_handler()(node, "")); // Track - context.references.track(pddl::RequirementEnum::TIMED_INITIAL_LITERALS); - context.references.track(pddl::RequirementEnum::DURATIVE_ACTIONS); - return { pddl::RequirementEnum::TIMED_INITIAL_LITERALS, pddl::RequirementEnum::DURATIVE_ACTIONS }; + context.references.track(RequirementEnum::TIMED_INITIAL_LITERALS); + context.references.track(RequirementEnum::DURATIVE_ACTIONS); + return { RequirementEnum::TIMED_INITIAL_LITERALS, RequirementEnum::DURATIVE_ACTIONS }; } -pddl::RequirementEnumSet parse(const ast::RequirementPreferences& node, Context& context) +RequirementEnumSet parse(const ast::RequirementPreferences& node, Context& context) { - throw UnsupportedRequirementError(pddl::RequirementEnum::PREFERENCES, context.scopes.get_error_handler()(node, "")); + throw UnsupportedRequirementError(RequirementEnum::PREFERENCES, context.scopes.get_error_handler()(node, "")); // Track - context.references.track(pddl::RequirementEnum::PREFERENCES); - return { pddl::RequirementEnum::PREFERENCES }; + context.references.track(RequirementEnum::PREFERENCES); + return { RequirementEnum::PREFERENCES }; } -pddl::RequirementEnumSet parse(const ast::RequirementConstraints& node, Context& context) +RequirementEnumSet parse(const ast::RequirementConstraints& node, Context& context) { - throw UnsupportedRequirementError(pddl::RequirementEnum::CONSTRAINTS, context.scopes.get_error_handler()(node, "")); + throw UnsupportedRequirementError(RequirementEnum::CONSTRAINTS, context.scopes.get_error_handler()(node, "")); // Track - context.references.track(pddl::RequirementEnum::CONSTRAINTS); - return { pddl::RequirementEnum::CONSTRAINTS }; + context.references.track(RequirementEnum::CONSTRAINTS); + return { RequirementEnum::CONSTRAINTS }; } -pddl::RequirementEnumSet parse(const ast::RequirementActionCosts&, Context& context) +RequirementEnumSet parse(const ast::RequirementActionCosts&, Context& context) { // Track - context.references.track(pddl::RequirementEnum::ACTION_COSTS); - return { pddl::RequirementEnum::ACTION_COSTS }; + context.references.track(RequirementEnum::ACTION_COSTS); + return { RequirementEnum::ACTION_COSTS }; } -pddl::RequirementEnumSet parse(const ast::Requirement& node, Context& context) { return boost::apply_visitor(RequirementVisitor(context), node); } +RequirementEnumSet parse(const ast::Requirement& node, Context& context) { return boost::apply_visitor(RequirementVisitor(context), node); } RequirementVisitor::RequirementVisitor(Context& context_) : context(context_) {} -pddl::RequirementEnumSet parse(const ast::Requirements& requirements_node, Context& context) +RequirementEnumSet parse(const ast::Requirements& requirements_node, Context& context) { - auto requirements = pddl::RequirementEnumSet(); + auto requirements = RequirementEnumSet(); for (const auto& requirement : requirements_node.requirements) { auto additional_requirements = parse(requirement, context); diff --git a/src/pddl/parser/requirements.hpp b/src/pddl/parser/requirements.hpp index 2279a775..7e81c12a 100644 --- a/src/pddl/parser/requirements.hpp +++ b/src/pddl/parser/requirements.hpp @@ -26,36 +26,36 @@ namespace loki { /* Requirements */ -extern pddl::RequirementEnumSet parse(const ast::Requirements& requirements_node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementStrips& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementTyping& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementNegativePreconditions& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementDisjunctivePreconditions& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementEquality& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementExistentialPreconditions& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementUniversalPreconditions& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementQuantifiedPreconditions& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementConditionalEffects& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementFluents& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementObjectFluents& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementNumericFluents& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementAdl& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementDurativeActions& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementDerivedPredicates& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementTimedInitialLiterals& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementPreferences& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementConstraints& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::RequirementActionCosts& node, Context& context); -extern pddl::RequirementEnumSet parse(const ast::Requirement& node, Context& context); +extern RequirementEnumSet parse(const ast::Requirements& requirements_node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementStrips& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementTyping& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementNegativePreconditions& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementDisjunctivePreconditions& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementEquality& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementExistentialPreconditions& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementUniversalPreconditions& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementQuantifiedPreconditions& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementConditionalEffects& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementFluents& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementObjectFluents& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementNumericFluents& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementAdl& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementDurativeActions& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementDerivedPredicates& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementTimedInitialLiterals& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementPreferences& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementConstraints& node, Context& context); +extern RequirementEnumSet parse(const ast::RequirementActionCosts& node, Context& context); +extern RequirementEnumSet parse(const ast::Requirement& node, Context& context); -struct RequirementVisitor : boost::static_visitor +struct RequirementVisitor : boost::static_visitor { Context& context; RequirementVisitor(Context& context_); template - pddl::RequirementEnumSet operator()(const Node& node) const + RequirementEnumSet operator()(const Node& node) const { return parse(node, context); } diff --git a/src/pddl/parser/structure.cpp b/src/pddl/parser/structure.cpp index 5973b69c..59ca90f0 100644 --- a/src/pddl/parser/structure.cpp +++ b/src/pddl/parser/structure.cpp @@ -31,14 +31,14 @@ namespace loki { -std::tuple, std::optional> parse(const ast::ActionBody& node, Context& context) +std::tuple, std::optional> parse(const ast::ActionBody& node, Context& context) { - std::optional condition; + std::optional condition; if (node.precondition_goal_descriptor.has_value()) { condition = parse(node.precondition_goal_descriptor.value(), context); } - std::optional effect; + std::optional effect; if (node.effect.has_value()) { effect = parse(node.effect.value(), context); @@ -46,7 +46,7 @@ std::tuple, std::optional> parse(co return { condition, effect }; } -pddl::Action parse(const ast::Action& node, Context& context) +Action parse(const ast::Action& node, Context& context) { context.scopes.open_scope(); auto name = parse(node.action_symbol.name); @@ -55,18 +55,18 @@ pddl::Action parse(const ast::Action& node, Context& context) auto [condition, effect] = parse(node.action_body, context); test_variable_references(parameter_list, context); context.scopes.close_scope(); - const auto action = context.factories.actions.get_or_create(name, parameter_list, condition, effect); + const auto action = context.factories.get_or_create_action(name, parameter_list, condition, effect); context.positions.push_back(action, node); return action; } -pddl::Axiom parse(const ast::Axiom& node, Context& context) +Axiom parse(const ast::Axiom& node, Context& context) { - if (!context.requirements->test(pddl::RequirementEnum::DERIVED_PREDICATES)) + if (!context.requirements->test(RequirementEnum::DERIVED_PREDICATES)) { - throw UndefinedRequirementError(pddl::RequirementEnum::DERIVED_PREDICATES, context.scopes.get_error_handler()(node, "")); + throw UndefinedRequirementError(RequirementEnum::DERIVED_PREDICATES, context.scopes.get_error_handler()(node, "")); } - context.references.untrack(pddl::RequirementEnum::DERIVED_PREDICATES); + context.references.untrack(RequirementEnum::DERIVED_PREDICATES); const auto literal = parse(node.literal, context); if (context.derived_predicates.count(literal->get_atom()->get_predicate()) == 0) @@ -75,13 +75,13 @@ pddl::Axiom parse(const ast::Axiom& node, Context& context) } const auto condition = parse(node.goal_descriptor, context); - const auto axiom = context.factories.axioms.get_or_create(literal, condition); + const auto axiom = context.factories.get_or_create_axiom(literal, condition); context.positions.push_back(axiom, node); return axiom; } StructureVisitor::StructureVisitor(Context& context_) : context(context_) {} -boost::variant parse(const ast::Structure& node, Context& context) { return boost::apply_visitor(StructureVisitor(context), node); } +boost::variant parse(const ast::Structure& node, Context& context) { return boost::apply_visitor(StructureVisitor(context), node); } } diff --git a/src/pddl/parser/structure.hpp b/src/pddl/parser/structure.hpp index eee42bce..053a2712 100644 --- a/src/pddl/parser/structure.hpp +++ b/src/pddl/parser/structure.hpp @@ -26,27 +26,27 @@ namespace loki { -extern std::tuple, std::optional> parse(const ast::ActionBody& node, Context& context); +extern std::tuple, std::optional> parse(const ast::ActionBody& node, Context& context); -extern pddl::Action parse(const ast::Action& node, Context& context); +extern Action parse(const ast::Action& node, Context& context); -extern pddl::Axiom parse(const ast::Axiom& node, Context& context); +extern Axiom parse(const ast::Axiom& node, Context& context); -struct StructureVisitor : boost::static_visitor> +struct StructureVisitor : boost::static_visitor> { Context& context; StructureVisitor(Context& context_); template - boost::variant operator()(const Node& node) const + boost::variant operator()(const Node& node) const { return parse(node, context); } }; // TODO return durative action in the future as well. -extern boost::variant parse(const ast::Structure& node, Context& context); +extern boost::variant parse(const ast::Structure& node, Context& context); } diff --git a/src/pddl/parser/types.cpp b/src/pddl/parser/types.cpp index c046899f..066c9df2 100644 --- a/src/pddl/parser/types.cpp +++ b/src/pddl/parser/types.cpp @@ -29,32 +29,32 @@ namespace loki TypeDeclarationTypeVisitor::TypeDeclarationTypeVisitor(Context& context_) : context(context_) {} -pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeObject& node) +TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeObject& node) { - const auto type = context.factories.types.get_or_create("object", pddl::TypeList()); + const auto type = context.factories.get_or_create_type("object", TypeList()); context.positions.push_back(type, node); return { type }; } -pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeNumber& node) +TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeNumber& node) { - const auto type = context.factories.types.get_or_create("number", pddl::TypeList()); + const auto type = context.factories.get_or_create_type("number", TypeList()); context.positions.push_back(type, node); return { type }; } -pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::Name& node) +TypeList TypeDeclarationTypeVisitor::operator()(const ast::Name& node) { auto name = parse(node); - const auto type = context.factories.types.get_or_create(name, pddl::TypeList()); + const auto type = context.factories.get_or_create_type(name, TypeList()); context.positions.push_back(type, node); return { type }; } -pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeEither& node) +TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeEither& node) { // we flatten nested either types - pddl::TypeList type_list; + TypeList type_list; for (auto& child_node : node.types) { auto types = boost::apply_visitor(TypeDeclarationTypeVisitor(context), child_node); @@ -67,26 +67,26 @@ pddl::TypeList TypeDeclarationTypeVisitor::operator()(const ast::TypeEither& nod TypeReferenceTypeVisitor::TypeReferenceTypeVisitor(const Context& context_) : context(context_) {} -pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeObject&) +TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeObject&) { - const auto binding = context.scopes.get("object"); + const auto binding = context.scopes.get("object"); assert(binding.has_value()); const auto [type, _position, _error_handler] = binding.value(); return { type }; } -pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeNumber&) +TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeNumber&) { - const auto binding = context.scopes.get("number"); + const auto binding = context.scopes.get("number"); assert(binding.has_value()); const auto [type, _position, _error_handler] = binding.value(); return { type }; } -pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::Name& node) +TypeList TypeReferenceTypeVisitor::operator()(const ast::Name& node) { auto name = parse(node); - auto binding = context.scopes.get(name); + auto binding = context.scopes.get(name); if (!binding.has_value()) { throw UndefinedTypeError(name, context.scopes.get_error_handler()(node, "")); @@ -96,10 +96,10 @@ pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::Name& node) return { type }; } -pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeEither& node) +TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeEither& node) { // we flatten nested either types - auto type_list = pddl::TypeList(); + auto type_list = TypeList(); for (auto& child_node : node.types) { auto types = boost::apply_visitor(TypeReferenceTypeVisitor(context), child_node); @@ -109,10 +109,10 @@ pddl::TypeList TypeReferenceTypeVisitor::operator()(const ast::TypeEither& node) } /* TypeDeclarationTypedListOfNamesVisitor */ -static void test_multiple_definition(const pddl::Type& type, const ast::Name& node, const Context& context) +static void test_multiple_definition(const Type& type, const ast::Name& node, const Context& context) { const auto type_name = type->get_name(); - const auto binding = context.scopes.get(type_name); + const auto binding = context.scopes.get(type_name); if (binding.has_value()) { const auto message_1 = context.scopes.get_error_handler()(node, "Defined here:"); @@ -126,7 +126,7 @@ static void test_multiple_definition(const pddl::Type& type, const ast::Name& no } } -static void test_reserved_type(const pddl::Type& type, const ast::Name& node, const Context& context) +static void test_reserved_type(const Type& type, const ast::Name& node, const Context& context) { if (type->get_name() == "object") { @@ -140,25 +140,25 @@ static void test_reserved_type(const pddl::Type& type, const ast::Name& node, co } } -static void insert_context_information(const pddl::Type& type, const ast::Name& node, Context& context) +static void insert_context_information(const Type& type, const ast::Name& node, Context& context) { context.positions.push_back(type, node); context.scopes.insert(type->get_name(), type, node); } -static pddl::Type parse_type_definition(const ast::Name& node, const pddl::TypeList& type_list, Context& context) +static Type parse_type_definition(const ast::Name& node, const TypeList& type_list, Context& context) { const auto name = parse(node); - const auto type = context.factories.types.get_or_create(name, type_list); + const auto type = context.factories.get_or_create_type(name, type_list); test_reserved_type(type, node, context); test_multiple_definition(type, node, context); insert_context_information(type, node, context); return type; } -static pddl::TypeList parse_type_definitions(const std::vector& nodes, const pddl::TypeList& parent_type_list, Context& context) +static TypeList parse_type_definitions(const std::vector& nodes, const TypeList& parent_type_list, Context& context) { - auto type_list = pddl::TypeList(); + auto type_list = TypeList(); for (const auto& node : nodes) { type_list.push_back(parse_type_definition(node, parent_type_list, context)); @@ -168,23 +168,23 @@ static pddl::TypeList parse_type_definitions(const std::vector& nodes TypeDeclarationTypedListOfNamesVisitor::TypeDeclarationTypedListOfNamesVisitor(Context& context_) : context(context_) {} -pddl::TypeList TypeDeclarationTypedListOfNamesVisitor::operator()(const std::vector& name_nodes) +TypeList TypeDeclarationTypedListOfNamesVisitor::operator()(const std::vector& name_nodes) { // std::vector has single base type "object" - assert(context.scopes.get("object").has_value()); - const auto [type_object, _position, _error_handler] = context.scopes.get("object").value(); - const auto type_list = parse_type_definitions(name_nodes, pddl::TypeList { type_object }, context); + assert(context.scopes.get("object").has_value()); + const auto [type_object, _position, _error_handler] = context.scopes.get("object").value(); + const auto type_list = parse_type_definitions(name_nodes, TypeList { type_object }, context); return type_list; } -pddl::TypeList TypeDeclarationTypedListOfNamesVisitor::operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node) +TypeList TypeDeclarationTypedListOfNamesVisitor::operator()(const ast::TypedListOfNamesRecursively& typed_list_of_names_recursively_node) { // requires :typing - if (!context.requirements->test(pddl::RequirementEnum::TYPING)) + if (!context.requirements->test(RequirementEnum::TYPING)) { - throw UndefinedRequirementError(pddl::RequirementEnum::TYPING, context.scopes.get_error_handler()(typed_list_of_names_recursively_node, "")); + throw UndefinedRequirementError(RequirementEnum::TYPING, context.scopes.get_error_handler()(typed_list_of_names_recursively_node, "")); } - context.references.untrack(pddl::RequirementEnum::TYPING); + context.references.untrack(RequirementEnum::TYPING); // TypedListOfNamesRecursively has user defined base types. const auto parent_type_list = boost::apply_visitor(TypeDeclarationTypeVisitor(context), typed_list_of_names_recursively_node.type); auto type_list = parse_type_definitions(typed_list_of_names_recursively_node.names, parent_type_list, context); @@ -197,7 +197,7 @@ pddl::TypeList TypeDeclarationTypedListOfNamesVisitor::operator()(const ast::Typ /* Other functions */ -pddl::TypeList parse(const ast::Types& types_node, Context& context) +TypeList parse(const ast::Types& types_node, Context& context) { return boost::apply_visitor(TypeDeclarationTypedListOfNamesVisitor(context), types_node.typed_list_of_names); } diff --git a/src/pddl/parser/types.hpp b/src/pddl/parser/types.hpp index e5cd90a1..639d23bc 100644 --- a/src/pddl/parser/types.hpp +++ b/src/pddl/parser/types.hpp @@ -25,7 +25,7 @@ namespace loki { -class TypeDeclarationTypeVisitor : boost::static_visitor +class TypeDeclarationTypeVisitor : boost::static_visitor { private: Context& context; @@ -33,16 +33,16 @@ class TypeDeclarationTypeVisitor : boost::static_visitor public: TypeDeclarationTypeVisitor(Context& context_); - pddl::TypeList operator()(const ast::TypeObject& node); + TypeList operator()(const ast::TypeObject& node); - pddl::TypeList operator()(const ast::TypeNumber& node); + TypeList operator()(const ast::TypeNumber& node); - pddl::TypeList operator()(const ast::Name& node); + TypeList operator()(const ast::Name& node); - pddl::TypeList operator()(const ast::TypeEither& node); + TypeList operator()(const ast::TypeEither& node); }; -class TypeReferenceTypeVisitor : boost::static_visitor +class TypeReferenceTypeVisitor : boost::static_visitor { private: const Context& context; @@ -50,16 +50,16 @@ class TypeReferenceTypeVisitor : boost::static_visitor public: TypeReferenceTypeVisitor(const Context& context_); - pddl::TypeList operator()(const ast::TypeObject& node); + TypeList operator()(const ast::TypeObject& node); - pddl::TypeList operator()(const ast::TypeNumber& node); + TypeList operator()(const ast::TypeNumber& node); - pddl::TypeList operator()(const ast::Name& node); + TypeList operator()(const ast::Name& node); - pddl::TypeList operator()(const ast::TypeEither& node); + TypeList operator()(const ast::TypeEither& node); }; -class TypeDeclarationTypedListOfNamesVisitor : boost::static_visitor +class TypeDeclarationTypedListOfNamesVisitor : boost::static_visitor { private: Context& context; @@ -67,12 +67,12 @@ class TypeDeclarationTypedListOfNamesVisitor : boost::static_visitor& nodes); + TypeList operator()(const std::vector& nodes); - pddl::TypeList operator()(const ast::TypedListOfNamesRecursively& node); + TypeList operator()(const ast::TypedListOfNamesRecursively& node); }; -extern pddl::TypeList parse(const ast::Types& node, Context& context); +extern TypeList parse(const ast::Types& node, Context& context); } diff --git a/src/pddl/predicate.cpp b/src/pddl/predicate.cpp index 7b2a8088..8c73ffd1 100644 --- a/src/pddl/predicate.cpp +++ b/src/pddl/predicate.cpp @@ -24,7 +24,7 @@ #include -namespace loki::pddl +namespace loki { PredicateImpl::PredicateImpl(int identifier, std::string name, ParameterList parameters) : Base(identifier), diff --git a/src/pddl/problem.cpp b/src/pddl/problem.cpp index 4497f687..3d09255d 100644 --- a/src/pddl/problem.cpp +++ b/src/pddl/problem.cpp @@ -35,7 +35,7 @@ using namespace std; -namespace loki::pddl +namespace loki { ProblemImpl::ProblemImpl(int identifier, Domain domain, @@ -102,7 +102,7 @@ void ProblemImpl::str_impl(std::ostream& out, const FormattingOptions& options) if (!m_objects.empty()) { out << string(nested_options.indent, ' ') << "(:objects "; - std::unordered_map> objects_by_types; + std::unordered_map> objects_by_types; for (const auto& object : m_objects) { objects_by_types[object->get_bases()].push_back(object); diff --git a/src/pddl/requirements.cpp b/src/pddl/requirements.cpp index b73e6e79..f457140b 100644 --- a/src/pddl/requirements.cpp +++ b/src/pddl/requirements.cpp @@ -21,7 +21,7 @@ #include -namespace loki::pddl +namespace loki { std::unordered_map requirement_enum_to_string = { { RequirementEnum::STRIPS, ":strips" }, @@ -44,7 +44,7 @@ std::unordered_map requirement_enum_to_string = { { RequirementEnum::CONSTRAINTS, ":constraints" }, { RequirementEnum::ACTION_COSTS, ":action-costs" } }; -const std::string& to_string(pddl::RequirementEnum requirement) +const std::string& to_string(RequirementEnum requirement) { assert(requirement_enum_to_string.count(requirement)); return requirement_enum_to_string.at(requirement); diff --git a/src/pddl/term.cpp b/src/pddl/term.cpp index 0412b99b..b1278375 100644 --- a/src/pddl/term.cpp +++ b/src/pddl/term.cpp @@ -22,7 +22,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { /* TermObjectImpl */ diff --git a/src/pddl/type.cpp b/src/pddl/type.cpp index 13db7dad..d47b14e2 100644 --- a/src/pddl/type.cpp +++ b/src/pddl/type.cpp @@ -20,7 +20,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { TypeImpl::TypeImpl(int identifier, std::string name, TypeList bases) : Base(identifier), m_name(std::move(name)), m_bases(std::move(bases)) {} diff --git a/src/pddl/variable.cpp b/src/pddl/variable.cpp index 532280d7..a55143dc 100644 --- a/src/pddl/variable.cpp +++ b/src/pddl/variable.cpp @@ -20,7 +20,7 @@ #include "loki/utils/collections.hpp" #include "loki/utils/hash.hpp" -namespace loki::pddl +namespace loki { VariableImpl::VariableImpl(int identifier, std::string name) : Base(identifier), m_name(std::move(name)) {} diff --git a/tests/unit/pddl/reference.cpp b/tests/unit/pddl/reference.cpp index f41d1e1f..31085f83 100644 --- a/tests/unit/pddl/reference.cpp +++ b/tests/unit/pddl/reference.cpp @@ -25,9 +25,9 @@ namespace loki::domain::tests TEST(LokiTests, ReferenceTest) { - PDDLFactory factory(2); - const auto object_0 = factory.get_or_create("object_0", pddl::TypeList()); - const auto object_1 = factory.get_or_create("object_1", pddl::TypeList()); + PDDLFactory factory(2); + const auto object_0 = factory.get_or_create("object_0", TypeList()); + const auto object_1 = factory.get_or_create("object_1", TypeList()); ReferencedPDDLObjects references; EXPECT_TRUE(!references.exists(object_0)); diff --git a/tests/unit/utils/persistent_factory.cpp b/tests/unit/utils/persistent_factory.cpp index e405f712..daf0d6ad 100644 --- a/tests/unit/utils/persistent_factory.cpp +++ b/tests/unit/utils/persistent_factory.cpp @@ -24,20 +24,20 @@ namespace loki::domain::tests TEST(LokiTests, PersistentFactoryTest) { - PDDLFactory factory(2); + PDDLFactory factory(2); EXPECT_EQ(factory.size(), 0); // Test uniqueness: insert the same element twice - const auto object_0_0 = factory.get_or_create("object_0", pddl::TypeList()); + const auto object_0_0 = factory.get_or_create("object_0", TypeList()); EXPECT_EQ(factory.size(), 1); EXPECT_EQ(object_0_0->get_identifier(), 0); EXPECT_EQ(object_0_0->get_name(), "object_0"); - const auto object_0_1 = factory.get_or_create("object_0", pddl::TypeList()); + const auto object_0_1 = factory.get_or_create("object_0", TypeList()); EXPECT_EQ(factory.size(), 1); EXPECT_EQ(object_0_0, object_0_1); - const auto object_1 = factory.get_or_create("object_1", pddl::TypeList()); + const auto object_1 = factory.get_or_create("object_1", TypeList()); EXPECT_EQ(factory.size(), 2); EXPECT_NE(object_0_0, object_1); EXPECT_EQ(object_1->get_identifier(), 1);