mirror of
https://github.com/github/codeql.git
synced 2026-02-20 08:53:49 +01:00
Merge pull request #114 from github/aibaars/fix-scopes
Correct the scope of class/method names etc.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
private import codeql_ruby.ast.internal.TreeSitter::Generated
|
||||
private import AstNodes
|
||||
private import codeql_ruby.ast.internal.Variable
|
||||
private import codeql_ruby.controlflow.ControlFlowGraph
|
||||
private import Completion
|
||||
private import SuccessorTypes
|
||||
@@ -146,7 +147,7 @@ module CfgScope {
|
||||
}
|
||||
|
||||
private AstNode parent(AstNode n) {
|
||||
result.getAFieldOrChild() = n and
|
||||
result = parentOf(n) and
|
||||
not n instanceof CfgScope
|
||||
}
|
||||
|
||||
@@ -1262,7 +1263,7 @@ cached
|
||||
private module Cached {
|
||||
/** Gets the CFG scope of node `n`. */
|
||||
cached
|
||||
CfgScope getCfgScope(AstNode n) { result = unique(CfgScope scope | scope = parent+(n)) }
|
||||
CfgScope getCfgScope(AstNode n) { result = unique(CfgScope scope | scope = parent*(parentOf(n))) }
|
||||
|
||||
private predicate isAbnormalExitType(SuccessorType t) {
|
||||
t instanceof RaiseSuccessor or t instanceof ExitSuccessor
|
||||
|
||||
Reference in New Issue
Block a user