Finished refactoring of expressions.
This commit is contained in:
@@ -130,6 +130,8 @@ void Domain::parseSection(utils::Parser &parser)
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: make naming consistent
|
||||
// TODO: check order of the sections
|
||||
if (sectionIdentifier == "requirements")
|
||||
parseRequirementsSection(parser);
|
||||
else if (sectionIdentifier == "types")
|
||||
@@ -258,7 +260,7 @@ void Domain::parseConstantSection(utils::Parser &parser)
|
||||
// Store constants
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
expressions::Constant::parseDeclaration(parser, m_context);
|
||||
expressions::Constant::parseTypedDeclaration(parser, m_context);
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
}
|
||||
|
@@ -36,6 +36,8 @@ ConstantPointer Constant::parseDeclaration(utils::Parser &parser, Context &conte
|
||||
|
||||
constant->m_name = parser.parseIdentifier(isIdentifier);
|
||||
|
||||
BOOST_ASSERT(constant->m_name != "-");
|
||||
|
||||
// Flag constant for potentially upcoming type declaration
|
||||
constant->setDirty();
|
||||
|
||||
|
@@ -26,31 +26,43 @@ PrimitiveType::PrimitiveType()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PrimitiveTypePointer PrimitiveType::parseDeclaration(utils::Parser &parser, Context &context)
|
||||
PrimitiveType *PrimitiveType::parseDeclaration(utils::Parser &parser, Context &context)
|
||||
{
|
||||
// TODO: refactor
|
||||
if (context.primitiveTypes.empty())
|
||||
{
|
||||
auto object = std::make_unique<PrimitiveType>(PrimitiveType());
|
||||
object->m_name = "object";
|
||||
object->setDirty();
|
||||
object->setDeclared();
|
||||
|
||||
context.primitiveTypes.emplace_back(std::move(object));
|
||||
}
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
const auto typeName = parser.parseIdentifier(isIdentifier);
|
||||
|
||||
// TODO: use hash map
|
||||
const auto match = std::find_if(context.primitiveTypes.cbegin(), context.primitiveTypes.cend(),
|
||||
[&](const auto &primitiveType)
|
||||
{
|
||||
return primitiveType->name() == typeName;
|
||||
});
|
||||
|
||||
// Return existing primitive type
|
||||
if (match != context.primitiveTypes.cend())
|
||||
{
|
||||
auto *type = match->get();
|
||||
|
||||
type->setDirty();
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
// Create new primitive type if not already existing
|
||||
auto type = std::make_unique<PrimitiveType>(PrimitiveType());
|
||||
|
||||
type->m_name = parser.parseIdentifier(isIdentifier);
|
||||
type->m_name = typeName;
|
||||
|
||||
BOOST_ASSERT(!type->m_name.empty());
|
||||
|
||||
// Flag type for potentially upcoming parent type declaration
|
||||
type->setDirty();
|
||||
|
||||
// TODO: Store constant in hash map
|
||||
context.primitiveTypes.emplace_back(std::move(type));
|
||||
|
||||
return type;
|
||||
return context.primitiveTypes.back().get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -58,9 +70,7 @@ PrimitiveTypePointer PrimitiveType::parseDeclaration(utils::Parser &parser, Cont
|
||||
void PrimitiveType::parseTypedDeclaration(utils::Parser &parser, Context &context)
|
||||
{
|
||||
// Parse and store type
|
||||
context.primitiveTypes.emplace_back(parseDeclaration(parser, context));
|
||||
|
||||
const auto &type = context.primitiveTypes.back();
|
||||
auto *type = parseDeclaration(parser, context);
|
||||
|
||||
// Flag type as correctly declared in the types section
|
||||
type->setDeclared();
|
||||
@@ -86,7 +96,7 @@ void PrimitiveType::parseTypedDeclaration(utils::Parser &parser, Context &contex
|
||||
if (!childType->isDirty())
|
||||
return;
|
||||
|
||||
childType->addParentType(parentType);
|
||||
childType->m_parentTypes.push_back(parentType);
|
||||
childType->setDirty(false);
|
||||
});
|
||||
}
|
||||
@@ -135,13 +145,6 @@ const std::string &PrimitiveType::name() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void PrimitiveType::addParentType(const PrimitiveType *parentType)
|
||||
{
|
||||
m_parentTypes.push_back(parentType);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::vector<const PrimitiveType *> &PrimitiveType::parentTypes() const
|
||||
{
|
||||
return m_parentTypes;
|
||||
|
@@ -77,11 +77,18 @@ void Variable::parseTypedDeclaration(utils::Parser &parser, Context &context, Va
|
||||
});
|
||||
};
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
// Parse argument of "either" type (always begins with opening parenthesis)
|
||||
if (parser.currentCharacter() == '(')
|
||||
{
|
||||
parser.expect<std::string>("(");
|
||||
parser.expect<std::string>("either");
|
||||
|
||||
parameter->m_eitherExpression = Either::parse(parser, context, parameters, parseExistingPrimitiveType);
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
setType(parameter->m_eitherExpression.get());
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user