Prefix integer variables with “N”

Instead of suffixing integer variables with “i,” this prefixes them with
“N” instead to make it consistent with common mathematical notations.
This commit is contained in:
Patrick Lühne 2018-04-22 21:10:20 +02:00
parent ea885f5fdb
commit 4a57a9e502
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 6 additions and 17 deletions

View File

@ -13,6 +13,7 @@ namespace anthem
constexpr const auto HeadVariablePrefix = "V";
constexpr const auto BodyVariablePrefix = "X";
constexpr const auto UserVariablePrefix = "U";
constexpr const auto IntegerVariablePrefix = "N";
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -35,6 +35,7 @@ struct PrintContext
std::map<const VariableDeclaration *, size_t> userVariableIDs;
std::map<const VariableDeclaration *, size_t> headVariableIDs;
std::map<const VariableDeclaration *, size_t> bodyVariableIDs;
std::map<const VariableDeclaration *, size_t> integerVariableIDs;
const Context &context;
};
@ -322,22 +323,6 @@ inline output::ColorStream &print(output::ColorStream &stream, const Variable &v
inline output::ColorStream &print(output::ColorStream &stream, const VariableDeclaration &variableDeclaration, PrintContext &printContext, bool)
{
const auto domainSuffix =
[&variableDeclaration]()
{
switch (variableDeclaration.domain)
{
case Domain::Unknown:
return "";
case Domain::Noninteger:
return "n";
case Domain::Integer:
return "i";
}
return "";
};
const auto printVariableDeclaration =
[&](const auto *prefix, auto &variableIDs) -> output::ColorStream &
{
@ -350,11 +335,14 @@ inline output::ColorStream &print(output::ColorStream &stream, const VariableDec
matchingVariableID = emplaceResult.first;
}
const auto variableName = std::string(prefix) + std::to_string(matchingVariableID->second) + domainSuffix();
const auto variableName = std::string(prefix) + std::to_string(matchingVariableID->second);
return (stream << output::Variable(variableName.c_str()));
};
if (variableDeclaration.domain == Domain::Integer)
return printVariableDeclaration(IntegerVariablePrefix, printContext.integerVariableIDs);
switch (variableDeclaration.type)
{
case VariableDeclaration::Type::UserDefined: