Restricting variable stack look-up to user-defined variables.

This commit is contained in:
Patrick Lühne 2017-05-30 16:39:44 +02:00
parent f78c0e4da5
commit 2964dd1309
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 5 additions and 4 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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++)