From 2964dd13091e268176a24ed8b16929152b76306a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 30 May 2017 16:39:44 +0200 Subject: [PATCH] Restricting variable stack look-up to user-defined variables. --- include/anthem/ASTUtils.h | 2 +- include/anthem/Term.h | 2 +- src/anthem/ASTUtils.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/anthem/ASTUtils.h b/include/anthem/ASTUtils.h index 550415d..d9d0af6 100644 --- a/include/anthem/ASTUtils.h +++ b/include/anthem/ASTUtils.h @@ -26,7 +26,7 @@ class VariableStack void push(Layer layer); void pop(); - std::experimental::optional findVariableDeclaration(const char *variableName) const; + std::experimental::optional findUserVariableDeclaration(const char *variableName) const; bool contains(const ast::VariableDeclaration &variableDeclaration) const; private: diff --git a/include/anthem/Term.h b/include/anthem/Term.h index c220cf3..f92e245 100644 --- a/include/anthem/Term.h +++ b/include/anthem/Term.h @@ -85,7 +85,7 @@ struct TermTranslateVisitor std::experimental::optional 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; diff --git a/src/anthem/ASTUtils.cpp b/src/anthem/ASTUtils.cpp index f7b84a3..61cb799 100644 --- a/src/anthem/ASTUtils.cpp +++ b/src/anthem/ASTUtils.cpp @@ -27,12 +27,13 @@ void VariableStack::pop() //////////////////////////////////////////////////////////////////////////////////////////////////// -std::experimental::optional VariableStack::findVariableDeclaration(const char *variableName) const +std::experimental::optional 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++)