Merge pull request #114 from github/aibaars/fix-scopes

Correct the scope of class/method names etc.
This commit is contained in:
Arthur Baars
2021-02-04 17:22:25 +01:00
committed by GitHub
9 changed files with 91 additions and 17 deletions

View File

@@ -5,8 +5,23 @@ private import codeql_ruby.ast.internal.Expr
private import codeql_ruby.ast.internal.Method
private import codeql_ruby.ast.internal.Pattern
private Generated::AstNode parent(Generated::AstNode n) {
result = n.getParent() and
Generated::AstNode parentOf(Generated::AstNode n) {
exists(Generated::AstNode parent | parent = n.getParent() |
if
n =
[
parent.(Generated::Module).getName(), parent.(Generated::Class).getName(),
parent.(Generated::Class).getSuperclass(), parent.(Generated::SingletonClass).getValue(),
parent.(Generated::Method).getName(), parent.(Generated::SingletonMethod).getName(),
parent.(Generated::SingletonMethod).getObject()
]
then result = parent.getParent()
else result = parent
)
}
private Generated::AstNode parentOfNoScope(Generated::AstNode n) {
result = parentOf(n) and
not n = any(VariableScope s).getScopeElement()
}
@@ -134,7 +149,7 @@ private module Cached {
/** Gets the enclosing scope for `node`. */
cached
VariableScope enclosingScope(Generated::AstNode node) {
result.getScopeElement() = parent*(node.getParent())
result.getScopeElement() = parentOfNoScope*(parentOf(node))
}
cached