Restricting variable stack look-up to user-defined variables.
This commit is contained in:
parent
f78c0e4da5
commit
2964dd1309
@ -26,7 +26,7 @@ class VariableStack
|
||||
void push(Layer layer);
|
||||
void pop();
|
||||
|
||||
std::experimental::optional<ast::VariableDeclaration *> findVariableDeclaration(const char *variableName) const;
|
||||
std::experimental::optional<ast::VariableDeclaration *> findUserVariableDeclaration(const char *variableName) const;
|
||||
bool contains(const ast::VariableDeclaration &variableDeclaration) const;
|
||||
|
||||
private:
|
||||
|
@ -85,7 +85,7 @@ struct TermTranslateVisitor
|
||||
|
||||
std::experimental::optional<ast::Term> visit(const Clingo::AST::Variable &variable, const Clingo::AST::Term &, Context &, RuleContext &ruleContext, const ast::VariableStack &variableStack)
|
||||
{
|
||||
const auto matchingVariableDeclaration = variableStack.findVariableDeclaration(variable.name);
|
||||
const auto matchingVariableDeclaration = variableStack.findUserVariableDeclaration(variable.name);
|
||||
const auto isAnonymousVariable = (strcmp(variable.name, "_") == 0);
|
||||
const auto isUndeclaredUserVariable = !matchingVariableDeclaration;
|
||||
const auto isUndeclared = isAnonymousVariable || isUndeclaredUserVariable;
|
||||
|
@ -27,12 +27,13 @@ void VariableStack::pop()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::experimental::optional<ast::VariableDeclaration *> VariableStack::findVariableDeclaration(const char *variableName) const
|
||||
std::experimental::optional<ast::VariableDeclaration *> VariableStack::findUserVariableDeclaration(const char *variableName) const
|
||||
{
|
||||
const auto variableNameMatches =
|
||||
[&variableName](const auto &variableDeclaration)
|
||||
{
|
||||
return variableDeclaration->name == variableName;
|
||||
return variableDeclaration->type == VariableDeclaration::Type::UserDefined
|
||||
&& variableDeclaration->name == variableName;
|
||||
};
|
||||
|
||||
for (auto i = m_layers.rbegin(); i != m_layers.rend(); i++)
|
||||
|
Loading…
Reference in New Issue
Block a user