Implemented type requirement checking for problem objects.

This commit is contained in:
Patrick Lühne 2016-06-08 01:51:45 +02:00
parent bf0e636d57
commit 993d14d409
3 changed files with 24 additions and 6 deletions

View File

@ -25,6 +25,7 @@ class Constant: public Expression
static void parseTypedDeclaration(Context &context, Domain &domain);
static void parseTypedDeclarations(Context &context, Domain &domain);
static void parseTypedDeclaration(Context &context, Problem &problem);
static void parseTypedDeclarations(Context &context, Problem &problem);
static Constant *parseAndFind(Context &context, const ExpressionContext &expressionContext);

View File

@ -235,12 +235,7 @@ void Problem::parseObjectSection()
m_context.parser.skipWhiteSpace();
// Store constants
while (m_context.parser.currentCharacter() != ')')
{
expressions::Constant::parseTypedDeclaration(m_context, *this);
m_context.parser.skipWhiteSpace();
}
expressions::Constant::parseTypedDeclarations(m_context, *this);
m_context.parser.expect<std::string>(")");
}

View File

@ -113,6 +113,28 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Constant::parseTypedDeclarations(Context &context, Problem &problem)
{
while (context.parser.currentCharacter() != ')')
parseTypedDeclaration(context, problem);
if (problem.objects().empty())
return;
// Check correct use of typing requirement
const auto typingUsed = (problem.objects().back()->type() != nullptr);
const auto typingDeclared = problem.domain().hasRequirement(Requirement::Type::Typing)
|| problem.hasRequirement(Requirement::Type::Typing);
if (!typingUsed && typingDeclared)
throw utils::ParserException(context.parser, "Constant has undeclared type");
if (typingUsed && !typingDeclared)
throw utils::ParserException(context.parser, "Typing used but not declared as a requirement");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Constant *Constant::parseAndFind(Context &context, const ExpressionContext &expressionContext)
{
context.parser.skipWhiteSpace();