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 push(Layer layer);
|
||||||
void pop();
|
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;
|
bool contains(const ast::VariableDeclaration &variableDeclaration) const;
|
||||||
|
|
||||||
private:
|
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)
|
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 isAnonymousVariable = (strcmp(variable.name, "_") == 0);
|
||||||
const auto isUndeclaredUserVariable = !matchingVariableDeclaration;
|
const auto isUndeclaredUserVariable = !matchingVariableDeclaration;
|
||||||
const auto isUndeclared = isAnonymousVariable || isUndeclaredUserVariable;
|
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 =
|
const auto variableNameMatches =
|
||||||
[&variableName](const auto &variableDeclaration)
|
[&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++)
|
for (auto i = m_layers.rbegin(); i != m_layers.rend(); i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user