Implemented primitive type declaration check.
This commit is contained in:
parent
7bd2782fc8
commit
9b3f78559e
@ -25,7 +25,7 @@ class PrimitiveType: public Expression
|
||||
static void parseDeclaration(Context &context, Domain &domain);
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain);
|
||||
|
||||
static PrimitiveType *parseAndFindOrCreate(Context &context, Domain &domain);
|
||||
static PrimitiveType *parseAndFind(Context &context, Domain &domain);
|
||||
|
||||
public:
|
||||
PrimitiveType();
|
||||
|
@ -84,7 +84,7 @@ void Constant::parseTypedDeclaration(Context &context, Domain &domain, Constants
|
||||
return;
|
||||
|
||||
// If existing, parse and store parent type
|
||||
auto *type = PrimitiveType::parseAndFindOrCreate(context, domain);
|
||||
auto *type = PrimitiveType::parseAndFind(context, domain);
|
||||
|
||||
// Assign parent type to all types that were previously flagged
|
||||
std::for_each(constants.begin(), constants.end(),
|
||||
|
@ -85,7 +85,7 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain)
|
||||
throw utils::ParserException(context.parser, "Typing used but not declared as a requirement");
|
||||
|
||||
// If existing, parse and store parent type
|
||||
auto *parentType = parseAndFindOrCreate(context, domain);
|
||||
auto *parentType = parseAndFind(context, domain);
|
||||
|
||||
parentType->setDirty(false);
|
||||
|
||||
@ -103,7 +103,7 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PrimitiveType *PrimitiveType::parseAndFindOrCreate(Context &context, Domain &domain)
|
||||
PrimitiveType *PrimitiveType::parseAndFind(Context &context, Domain &domain)
|
||||
{
|
||||
auto &types = domain.types();
|
||||
|
||||
@ -122,8 +122,11 @@ PrimitiveType *PrimitiveType::parseAndFindOrCreate(Context &context, Domain &dom
|
||||
|
||||
if (match == types.cend())
|
||||
{
|
||||
// If necessary, insert new primitive type but don't declare it
|
||||
types.emplace_back(std::make_unique<expressions::PrimitiveType>(typeName));
|
||||
// Only "object" is allowed as an implicit type
|
||||
if (typeName == "object")
|
||||
types.emplace_back(std::make_unique<expressions::PrimitiveType>(typeName));
|
||||
else
|
||||
throw utils::ParserException(context.parser, "Type \"" + typeName + "\" used but never declared");
|
||||
|
||||
return types.back().get();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace expressions
|
||||
|
||||
ExpressionPointer parseExistingPrimitiveType(Context &context, ExpressionContext &expressionContext)
|
||||
{
|
||||
auto *primitiveType = PrimitiveType::parseAndFindOrCreate(context, expressionContext.domain);
|
||||
auto *primitiveType = PrimitiveType::parseAndFind(context, expressionContext.domain);
|
||||
|
||||
return std::make_unique<Reference<PrimitiveType>>(primitiveType);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
|
||||
}
|
||||
|
||||
// Parse primitive type
|
||||
const auto *type = PrimitiveType::parseAndFindOrCreate(context, expressionContext.domain);
|
||||
const auto *type = PrimitiveType::parseAndFind(context, expressionContext.domain);
|
||||
|
||||
setType(type);
|
||||
}
|
||||
|
Reference in New Issue
Block a user