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

View File

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