diff --git a/lib/pddlparse/src/pddlparse/detail/normalization/Precondition.cpp b/lib/pddlparse/src/pddlparse/detail/normalization/Precondition.cpp index f85c0ee..180cd38 100644 --- a/lib/pddlparse/src/pddlparse/detail/normalization/Precondition.cpp +++ b/lib/pddlparse/src/pddlparse/detail/normalization/Precondition.cpp @@ -23,12 +23,19 @@ namespace detail //////////////////////////////////////////////////////////////////////////////////////////////////// normalizedAST::Literal normalizeNested(ast::AndPointer &and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::Literal normalizeNested(ast::AtomicFormula &, normalizedAST::DerivedPredicateDeclarations &); normalizedAST::Literal normalizeNested(ast::ExistsPointer &exists, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::Literal normalizeNested(ast::ForAllPointer &forAll, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::Literal normalizeNested(ast::ForAllPointer &forAll, normalizedAST::DerivedPredicateDeclarations &); normalizedAST::Literal normalizeNested(ast::ImplyPointer &, normalizedAST::DerivedPredicateDeclarations &); normalizedAST::Literal normalizeNested(ast::NotPointer ¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); normalizedAST::Literal normalizeNested(ast::OrPointer &or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::Literal normalizeNested(ast::AtomicFormula &, normalizedAST::DerivedPredicateDeclarations &); +normalizedAST::AndPointer normalizeTopLevel(ast::AndPointer &&and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &&, normalizedAST::DerivedPredicateDeclarations &); +normalizedAST::Literal normalizeTopLevel(ast::ExistsPointer &&exists, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::Literal normalizeTopLevel(ast::ForAllPointer &&forAll, normalizedAST::DerivedPredicateDeclarations &); +normalizedAST::Literal normalizeTopLevel(ast::ImplyPointer &&, normalizedAST::DerivedPredicateDeclarations &); +normalizedAST::NotPointer normalizeTopLevel(ast::NotPointer &¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::Literal normalizeTopLevel(ast::OrPointer &&or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -80,6 +87,13 @@ normalizedAST::Literal normalizeNested(ast::AndPointer &and_, //////////////////////////////////////////////////////////////////////////////////////////////////// +normalizedAST::Literal normalizeNested(ast::AtomicFormula &atomicFormula, normalizedAST::DerivedPredicateDeclarations &) +{ + return normalize(std::move(atomicFormula)); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + normalizedAST::Literal normalizeNested(ast::ExistsPointer &exists, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) { std::vector parameters; @@ -174,13 +188,6 @@ normalizedAST::Literal normalizeNested(ast::OrPointer &or_, n //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::AtomicFormula &atomicFormula, normalizedAST::DerivedPredicateDeclarations &) -{ - return normalize(std::move(atomicFormula)); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &&atomicFormula, normalizedAST::DerivedPredicateDeclarations &) { return normalize(std::move(atomicFormula)); @@ -188,30 +195,6 @@ normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &&atomicFormul //////////////////////////////////////////////////////////////////////////////////////////////////// -// Normalize top-level negations -normalizedAST::NotPointer normalizeTopLevel(ast::NotPointer &¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) -{ - // “not” expressions may be nested one time to form simple literals - if (not_->argument.is()) - return std::make_unique>(normalize(std::move(not_->argument.get()))); - - auto normalizedArgument = not_->argument.match( - [&](auto &nested) -> normalizedAST::AtomicFormula - { - auto normalizedLiteral = normalizeNested(nested, derivedPredicates); - - // Multiple negations should be eliminated at this point - if (normalizedLiteral.template is>()) - throw std::logic_error("precondition not in normal form (multiple negation), please report to the bug tracker"); - - return std::move(normalizedLiteral.template get()); - }); - - return std::make_unique>(std::move(normalizedArgument)); -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - // Normalize top-level conjunctions normalizedAST::AndPointer normalizeTopLevel(ast::AndPointer &&and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) { @@ -270,6 +253,30 @@ normalizedAST::Literal normalizeTopLevel(ast::ImplyPointer && //////////////////////////////////////////////////////////////////////////////////////////////////// +// Normalize top-level negations +normalizedAST::NotPointer normalizeTopLevel(ast::NotPointer &¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +{ + // “not” expressions may be nested one time to form simple literals + if (not_->argument.is()) + return std::make_unique>(normalize(std::move(not_->argument.get()))); + + auto normalizedArgument = not_->argument.match( + [&](auto &nested) -> normalizedAST::AtomicFormula + { + auto normalizedLiteral = normalizeNested(nested, derivedPredicates); + + // Multiple negations should be eliminated at this point + if (normalizedLiteral.template is>()) + throw std::logic_error("precondition not in normal form (multiple negation), please report to the bug tracker"); + + return std::move(normalizedLiteral.template get()); + }); + + return std::make_unique>(std::move(normalizedArgument)); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + normalizedAST::Literal normalizeTopLevel(ast::OrPointer &&or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) { return normalizeNested(or_, derivedPredicates);