patrick
/
plasp
Archived
1
0
Fork 0

Allowing types to be undeclared for increased compatibility.

This commit is contained in:
Patrick Lühne 2017-06-15 23:51:36 +02:00
parent 849faad134
commit 216decafc1
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
1 changed files with 5 additions and 9 deletions

View File

@ -32,18 +32,14 @@ ast::PrimitiveTypePointer parsePrimitiveType(Context &context, ast::Domain &doma
return primitiveTypeDeclaration->name == typeName;
});
// If the type has not been declared yet, add it but issue a warning
if (matchingType == types.end())
{
// Only “object” is allowed as an implicit type
if (typeName == "object" || typeName == "objects")
{
context.warningCallback(tokenizer.location(), "primitive type “" + typeName + "” should be declared");
types.emplace_back(std::make_unique<ast::PrimitiveTypeDeclaration>(std::move(typeName)));
context.warningCallback(tokenizer.location(), "primitive type “" + typeName + "” used without or before declaration");
return std::make_unique<ast::PrimitiveType>(types.back().get());
}
else
throw tokenize::TokenizerException(tokenizer.location(), "type “" + typeName + "” used but never declared");
types.emplace_back(std::make_unique<ast::PrimitiveTypeDeclaration>(std::move(typeName)));
return std::make_unique<ast::PrimitiveType>(types.back().get());
}
return std::make_unique<ast::PrimitiveType>(matchingType->get());