Switched to intrusive pointers for much easier maintenance.
This commit is contained in:
@@ -313,7 +313,7 @@ void TranslatorASP::translateConstants(const std::string &heading, const express
|
||||
<< utils::String(constant->name())
|
||||
<< "))." << std::endl;
|
||||
|
||||
const auto *type = constant->type();
|
||||
const auto type = constant->type();
|
||||
|
||||
if (type != nullptr)
|
||||
{
|
||||
@@ -366,7 +366,7 @@ void TranslatorASP::translateVariablesBody(const expressions::Variables &variabl
|
||||
if (variable.type()->expressionType() != Expression::Type::PrimitiveType)
|
||||
throw utils::TranslatorException("only primitive types supported currently");
|
||||
|
||||
const auto &type = *dynamic_cast<const expressions::PrimitiveType *>(variable.type());
|
||||
const auto &type = dynamic_cast<const expressions::PrimitiveType &>(*variable.type());
|
||||
|
||||
m_outputStream << utils::RuleName("has") << "("
|
||||
<< utils::Variable(variable.name()) << ", "
|
||||
|
@@ -35,7 +35,7 @@ ConstantPointer Constant::parseDeclaration(Context &context)
|
||||
{
|
||||
context.parser.skipWhiteSpace();
|
||||
|
||||
auto constant = std::make_unique<Constant>(Constant());
|
||||
auto constant = ConstantPointer(new Constant);
|
||||
|
||||
constant->m_name = context.parser.parseIdentifier();
|
||||
|
||||
@@ -75,7 +75,7 @@ void Constant::parseTypedDeclaration(Context &context, Domain &domain, Constants
|
||||
return;
|
||||
|
||||
// If existing, parse and store parent type
|
||||
auto *type = PrimitiveType::parseAndFind(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(),
|
||||
@@ -145,7 +145,7 @@ void Constant::parseTypedDeclarations(Context &context, Problem &problem)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Constant *Constant::parseAndFind(Context &context, const Domain &domain)
|
||||
ConstantPointer Constant::parseAndFind(Context &context, const Domain &domain)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
@@ -153,7 +153,7 @@ Constant *Constant::parseAndFind(Context &context, const Domain &domain)
|
||||
|
||||
const auto constantName = parser.parseIdentifier();
|
||||
|
||||
auto *constant = parseAndFind(constantName, domain.constants());
|
||||
auto constant = parseAndFind(constantName, domain.constants());
|
||||
|
||||
if (constant != nullptr)
|
||||
return constant;
|
||||
@@ -163,7 +163,7 @@ Constant *Constant::parseAndFind(Context &context, const Domain &domain)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Constant *Constant::parseAndFind(Context &context, const Problem &problem)
|
||||
ConstantPointer Constant::parseAndFind(Context &context, const Problem &problem)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
@@ -171,7 +171,7 @@ Constant *Constant::parseAndFind(Context &context, const Problem &problem)
|
||||
|
||||
const auto constantName = parser.parseIdentifier();
|
||||
|
||||
auto *constant = parseAndFind(constantName, problem.domain().constants());
|
||||
auto constant = parseAndFind(constantName, problem.domain().constants());
|
||||
|
||||
if (constant)
|
||||
return constant;
|
||||
@@ -186,7 +186,7 @@ Constant *Constant::parseAndFind(Context &context, const Problem &problem)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Constant *Constant::parseAndFind(const std::string &constantName, const Constants &constants)
|
||||
ConstantPointer Constant::parseAndFind(const std::string &constantName, const Constants &constants)
|
||||
{
|
||||
const auto match = std::find_if(constants.cbegin(), constants.cend(),
|
||||
[&](const auto &constant)
|
||||
@@ -225,14 +225,14 @@ const std::string &Constant::name() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Constant::setType(const PrimitiveType *type)
|
||||
void Constant::setType(PrimitiveTypePointer type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const PrimitiveType *Constant::type() const
|
||||
PrimitiveTypePointer Constant::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
@@ -26,10 +26,10 @@ ExpressionPointer Imply::normalize()
|
||||
BOOST_ASSERT(m_argumentStorage[0]);
|
||||
BOOST_ASSERT(m_argumentStorage[1]);
|
||||
|
||||
auto notArgument0 = std::make_unique<Not>();
|
||||
auto notArgument0 = NotPointer(new Not);
|
||||
notArgument0->setArgument(std::move(m_argumentStorage[0]));
|
||||
|
||||
auto orExpression = std::make_unique<Or>();
|
||||
auto orExpression = OrPointer(new Or);
|
||||
orExpression->addArgument(std::move(notArgument0));
|
||||
orExpression->addArgument(std::move(m_argumentStorage[1]));
|
||||
|
||||
|
@@ -54,7 +54,7 @@ PredicatePointer Predicate::parse(Context &context, ExpressionContext &expressio
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto predicate = std::make_unique<Predicate>(Predicate());
|
||||
auto predicate = PredicatePointer(new Predicate);
|
||||
|
||||
predicate->m_name = predicateName;
|
||||
|
||||
@@ -66,13 +66,13 @@ PredicatePointer Predicate::parse(Context &context, ExpressionContext &expressio
|
||||
// Parse variables
|
||||
if (context.parser.currentCharacter() == '?')
|
||||
{
|
||||
const auto *variable = Variable::parseAndFind(context, expressionContext);
|
||||
const auto variable = Variable::parseAndFind(context, expressionContext);
|
||||
predicate->m_arguments.emplace_back(variable);
|
||||
}
|
||||
// Parse constants
|
||||
else
|
||||
{
|
||||
const auto *constant = (expressionContext.problem == nullptr)
|
||||
const auto constant = (expressionContext.problem == nullptr)
|
||||
? Constant::parseAndFind(context, expressionContext.domain)
|
||||
: Constant::parseAndFind(context, *expressionContext.problem);
|
||||
predicate->m_arguments.emplace_back(constant);
|
||||
@@ -117,7 +117,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto predicate = std::make_unique<Predicate>(Predicate());
|
||||
auto predicate = PredicatePointer(new Predicate);
|
||||
|
||||
predicate->m_name = predicateName;
|
||||
|
||||
@@ -129,7 +129,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
|
||||
throw utils::ParserException(parser.coordinate(), "variables not allowed in this context");
|
||||
|
||||
// Parse objects and constants
|
||||
const auto *constant = Constant::parseAndFind(context, problem);
|
||||
const auto constant = Constant::parseAndFind(context, problem);
|
||||
predicate->m_arguments.emplace_back(constant);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ const std::string &Predicate::name() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::vector<const Expression *> &Predicate::arguments() const
|
||||
const std::vector<ExpressionPointer> &Predicate::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ void PredicateDeclaration::parse(Context &context, Domain &domain)
|
||||
{
|
||||
context.parser.expect<std::string>("(");
|
||||
|
||||
auto predicate = std::make_unique<PredicateDeclaration>(PredicateDeclaration());
|
||||
auto predicate = PredicateDeclarationPointer(new PredicateDeclaration);
|
||||
|
||||
predicate->m_name = context.parser.parseIdentifier();
|
||||
|
||||
|
@@ -61,7 +61,7 @@ void PrimitiveType::parseDeclaration(Context &context, Domain &domain)
|
||||
return;
|
||||
}
|
||||
|
||||
types.emplace_back(std::make_unique<PrimitiveType>(typeName));
|
||||
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -82,7 +82,7 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain)
|
||||
domain.checkRequirement(Requirement::Type::Typing);
|
||||
|
||||
// If existing, parse and store parent type
|
||||
auto *parentType = parseAndFind(context, domain);
|
||||
auto parentType = parseAndFind(context, domain);
|
||||
|
||||
parentType->setDirty(false);
|
||||
|
||||
@@ -100,7 +100,7 @@ void PrimitiveType::parseTypedDeclaration(Context &context, Domain &domain)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PrimitiveType *PrimitiveType::parseAndFind(Context &context, Domain &domain)
|
||||
PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domain)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
@@ -125,7 +125,7 @@ PrimitiveType *PrimitiveType::parseAndFind(Context &context, Domain &domain)
|
||||
if (typeName == "object" || typeName == "objects")
|
||||
{
|
||||
context.logger.logWarning(parser.coordinate(), "primitive type “" + typeName + "” should be declared");
|
||||
types.emplace_back(std::make_unique<expressions::PrimitiveType>(typeName));
|
||||
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
|
||||
}
|
||||
else
|
||||
throw utils::ParserException(parser.coordinate(), "type “" + typeName + "” used but never declared");
|
||||
@@ -162,7 +162,7 @@ const std::string &PrimitiveType::name() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::vector<const PrimitiveType *> &PrimitiveType::parentTypes() const
|
||||
const std::vector<PrimitiveTypePointer> &PrimitiveType::parentTypes() const
|
||||
{
|
||||
return m_parentTypes;
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ namespace expressions
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Expression *parseExistingPrimitiveType(Context &context, ExpressionContext &expressionContext)
|
||||
ExpressionPointer parseExistingPrimitiveType(Context &context, ExpressionContext &expressionContext)
|
||||
{
|
||||
return PrimitiveType::parseAndFind(context, expressionContext.domain);
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ UnsupportedPointer Unsupported::parse(Context &context)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
auto expression = std::make_unique<Unsupported>(Unsupported());
|
||||
auto expression = UnsupportedPointer(new Unsupported);
|
||||
|
||||
parser.expect<std::string>("(");
|
||||
|
||||
|
@@ -41,7 +41,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
|
||||
|
||||
parser.expect<std::string>("?");
|
||||
|
||||
auto variable = std::make_unique<Variable>(Variable());
|
||||
auto variable = VariablePointer(new Variable);
|
||||
|
||||
variable->m_name = parser.parseIdentifier();
|
||||
|
||||
@@ -58,7 +58,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
|
||||
// Flag variable for potentially upcoming type declaration
|
||||
variable->setDirty();
|
||||
|
||||
parameters.emplace_back(std::move(variable));
|
||||
parameters.emplace_back(variable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -80,7 +80,7 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
|
||||
return;
|
||||
|
||||
const auto setType =
|
||||
[&](const auto *type)
|
||||
[&](ExpressionPointer type)
|
||||
{
|
||||
// Set the argument type for all previously flagged arguments
|
||||
std::for_each(variables.begin(), variables.end(),
|
||||
@@ -96,17 +96,14 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
// Parse argument of "either" type (always begins with opening parenthesis)
|
||||
if ((variable->m_eitherExpression = Either::parse(context, expressionContext, parseExistingPrimitiveType)))
|
||||
{
|
||||
setType(variable->m_eitherExpression.get());
|
||||
return;
|
||||
}
|
||||
// Parse argument if it has "either" type (always begins with opening parenthesis)
|
||||
variable->m_type = Either::parse(context, expressionContext, parseExistingPrimitiveType);
|
||||
|
||||
// Parse primitive type
|
||||
const auto *type = PrimitiveType::parseAndFind(context, expressionContext.domain);
|
||||
// Else, try parsing it as a primitive type
|
||||
if (!variable->m_type)
|
||||
variable->m_type = PrimitiveType::parseAndFind(context, expressionContext.domain);
|
||||
|
||||
setType(type);
|
||||
setType(variable->m_type);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -138,7 +135,7 @@ void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expre
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Variable *Variable::parseAndFind(Context &context, const ExpressionContext &expressionContext)
|
||||
VariablePointer Variable::parseAndFind(Context &context, const ExpressionContext &expressionContext)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
@@ -178,7 +175,14 @@ const std::string &Variable::name() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Expression *Variable::type() const
|
||||
void Variable::setType(ExpressionPointer type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Variable::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
@@ -199,13 +203,6 @@ bool Variable::isDirty() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Variable::setType(const Expression *type)
|
||||
{
|
||||
m_type = type;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Variable::normalize()
|
||||
{
|
||||
return nullptr;
|
||||
|
Reference in New Issue
Block a user