patrick
/
plasp
Archived
1
0
Fork 0

Added checks that used types are correctly declared previously.

This commit is contained in:
Patrick Lühne 2016-05-31 13:50:30 +02:00
parent 85da5024ea
commit 1395b62e60
3 changed files with 32 additions and 0 deletions

View File

@ -35,15 +35,20 @@ class Type
const std::string &name() const;
const std::vector<const Type *> &parentTypes() const;
bool isDeclared() const;
private:
Type(std::string name);
void setDirty(bool isDirty = true);
bool isDirty() const;
void setDeclared();
void addParentType(const Type &parentType);
bool m_isDirty;
bool m_isDeclared;
std::string m_name;

View File

@ -215,12 +215,21 @@ void Domain::parseTypingSection(utils::Parser &parser)
void Domain::checkConsistency()
{
// Verify that typing requirement is correctly declared if used
if (!m_context.types.empty() && !hasRequirement(Requirement::Type::Typing))
{
throw ConsistencyException("Domain contains typing information but does not declare typing requirement");
m_requirements.push_back(Requirement::Type::Typing);
}
// Verify that all used types have been declared
std::for_each(m_context.types.cbegin(), m_context.types.cend(),
[&](const auto &type)
{
if (!type.second.isDeclared())
throw ConsistencyException("Type \"" + type.second.name() + "\" used but never declared");
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -18,6 +18,7 @@ namespace pddl
Type::Type(std::string name)
: m_isDirty{false},
m_isDeclared{false},
m_name(name)
{
}
@ -51,6 +52,9 @@ void Type::parsePDDL(utils::Parser &parser, Context &context)
// Flag type for potentially upcoming parent type declaration
type.setDirty();
// Flag type as correctly declared in the types section
type.setDeclared();
return type;
};
@ -95,6 +99,20 @@ bool Type::isDirty() const
////////////////////////////////////////////////////////////////////////////////////////////////////
void Type::setDeclared()
{
m_isDeclared = true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
bool Type::isDeclared() const
{
return m_isDeclared;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
const std::string &Type::name() const
{
return m_name;