Added debug printing function to facilitate testing expression normalization.

This commit is contained in:
2016-09-04 22:26:17 +02:00
parent c9ecd0c020
commit ed2d64c1c9
23 changed files with 185 additions and 95 deletions

View File

@@ -1,6 +1,8 @@
#ifndef __PLASP__PDDL__EXPRESSION_H
#define __PLASP__PDDL__EXPRESSION_H
#include <iosfwd>
#include <boost/intrusive_ptr.hpp>
#include <plasp/utils/Parser.h>
@@ -110,6 +112,8 @@ class Expression
virtual ExpressionPointer normalized();
ExpressionPointer negated();
virtual void print(std::ostream &ostream) const = 0;
private:
friend void intrusive_ptr_add_ref(Expression *expression);
friend void intrusive_ptr_release(Expression *expression);

View File

@@ -39,6 +39,8 @@ class At: public ExpressionCRTP<At>
ExpressionPointer normalized() override;
void print(std::ostream &ostream) const override;
protected:
size_t m_timePoint;

View File

@@ -33,6 +33,8 @@ class Binary: public ExpressionCRTP<Derived>
ExpressionPointer normalized() override;
void print(std::ostream &ostream) const override;
protected:
std::array<ExpressionPointer, 2> m_arguments;
};
@@ -102,6 +104,23 @@ inline ExpressionPointer Binary<Derived>::normalized()
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
inline void Binary<Derived>::print(std::ostream &ostream) const
{
ostream << "(" << Derived::Identifier;
std::for_each(m_arguments.begin(), m_arguments.end(),
[&](auto &argument)
{
ostream << " ";
argument->print(ostream);
});
ostream << ")";
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@@ -35,6 +35,8 @@ class Constant: public ExpressionCRTP<Constant>
const std::string &name() const;
PrimitiveTypePointer type() const;
void print(std::ostream &ostream) const override;
private:
static ConstantPointer parseDeclaration(Context &context);
static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);

View File

@@ -21,12 +21,13 @@ class Dummy: public ExpressionCRTP<Dummy>
public:
static const Expression::Type ExpressionType = Expression::Type::Dummy;
bool isNormalized() const;
public:
Dummy(std::string name);
ExpressionPointer normalized() override;
void print(std::ostream &ostream) const override;
private:
bool m_isNormalized = false;
std::string m_name;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -35,6 +35,8 @@ class NAry: public ExpressionCRTP<Derived>
ExpressionPointer normalized() override;
void print(std::ostream &ostream) const override;
protected:
Expressions m_arguments;
};
@@ -132,6 +134,23 @@ inline ExpressionPointer NAry<Derived>::normalized()
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
inline void NAry<Derived>::print(std::ostream &ostream) const
{
ostream << "(" << Derived::Identifier;
std::for_each(m_arguments.begin(), m_arguments.end(),
[&](auto &argument)
{
ostream << " ";
argument->print(ostream);
});
ostream << ")";
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@@ -34,6 +34,8 @@ class Not: public ExpressionCRTP<Not>
ExpressionPointer normalized() override;
void print(std::ostream &ostream) const override;
protected:
ExpressionPointer m_argument;
};

View File

@@ -30,6 +30,8 @@ class Predicate: public ExpressionCRTP<Predicate>
bool isDeclared() const;
void print(std::ostream &ostream) const override;
private:
Predicate();

View File

@@ -31,6 +31,8 @@ class PredicateDeclaration: public ExpressionCRTP<PredicateDeclaration>
void normalizeParameterNames();
void print(std::ostream &ostream) const override;
private:
PredicateDeclaration();

View File

@@ -35,6 +35,8 @@ class PrimitiveType: public ExpressionCRTP<PrimitiveType>
const std::string &name() const;
const PrimitiveTypes &parentTypes() const;
void print(std::ostream &ostream) const override;
private:
void setDirty(bool isDirty = true);
bool isDirty() const;

View File

@@ -27,6 +27,8 @@ class Unsupported: public ExpressionCRTP<Unsupported>
public:
const std::string &type() const;
void print(std::ostream &ostream) const override;
private:
std::string m_type;
};

View File

@@ -37,6 +37,8 @@ class Variable: public ExpressionCRTP<Variable>
void setDirty(bool isDirty = true);
bool isDirty() const;
void print(std::ostream &ostream) const override;
private:
static void parseDeclaration(Context &context, Variables &parameters);