patrick
/
plasp
Archived
1
0
Fork 0

Checking that all variables in predicates have types if and only if typing is enabled.

This commit is contained in:
Patrick Lühne 2016-06-07 16:11:12 +02:00
parent 4228ca01dc
commit e6ddad5960
2 changed files with 21 additions and 3 deletions

View File

@ -352,15 +352,32 @@ void Domain::checkConsistency()
m_requirements.push_back(Requirement(Requirement::Type::Typing));
}
// Verify that all variables and constants have types
// Verify that all variables and constants have types if and only if typing enabled
if (hasRequirement(Requirement::Type::Typing))
{
const auto acceptType =
[&](const auto *type)
{
return ((type == nullptr) != hasRequirement(Requirement::Type::Typing));
};
std::for_each(m_constants.cbegin(), m_constants.cend(),
[&](const auto &constant)
{
if (constant->type() == nullptr)
if (!acceptType(constant->type()))
throw ConsistencyException("Constant \"" + constant->name() + "\" has no type");
});
std::for_each(m_predicateDeclarations.cbegin(), m_predicateDeclarations.cend(),
[&](const auto &predicateDeclaration)
{
std::for_each(predicateDeclaration->arguments().cbegin(), predicateDeclaration->arguments().cend(),
[&](const auto &argument)
{
if (!acceptType(argument->type()))
throw ConsistencyException("Variable \"" + argument->name() + "\" has no type");
});
});
}
// Verify that all used types have been declared

View File

@ -27,7 +27,8 @@ namespace expressions
////////////////////////////////////////////////////////////////////////////////////////////////////
Variable::Variable()
: m_isDirty{false}
: m_isDirty{false},
m_type{nullptr}
{
}