diff --git a/ql/src/codeql_ruby/ast/Scope.qll b/ql/src/codeql_ruby/ast/Scope.qll index 3969eb0b77f..bbc34bc81fb 100644 --- a/ql/src/codeql_ruby/ast/Scope.qll +++ b/ql/src/codeql_ruby/ast/Scope.qll @@ -12,4 +12,13 @@ class Scope extends AstNode, Scope::ScopeType { /** Gets the scope in which this scope is nested, if any. */ Scope getOuterScope() { result = range.getOuterScope() } + + /** Gets a variable that is declared in this scope. */ + final Variable getAVariable() { result.getDeclaringScope() = this } + + /** Gets the variable with the given name that is declared in this scope. */ + final Variable getVariable(string name) { + result = this.getAVariable() and + result.getName() = name + } } diff --git a/ql/src/codeql_ruby/ast/Variable.qll b/ql/src/codeql_ruby/ast/Variable.qll index e45c81e1d07..955723399dd 100644 --- a/ql/src/codeql_ruby/ast/Variable.qll +++ b/ql/src/codeql_ruby/ast/Variable.qll @@ -4,18 +4,6 @@ private import codeql_ruby.AST private import codeql.Locations private import internal.Variable -/** A scope in which variables can be declared. */ -class VariableScope extends Scope { - /** Gets a variable that is declared in this scope. */ - final Variable getAVariable() { result.getDeclaringScope() = this } - - /** Gets the variable with the given name that is declared in this scope. */ - final Variable getVariable(string name) { - result = this.getAVariable() and - result.getName() = name - } -} - /** A variable declared in a scope. */ class Variable extends TVariable { Variable::Range range; @@ -32,7 +20,7 @@ class Variable extends TVariable { final Location getLocation() { result = range.getLocation() } /** Gets the scope this variable is declared in. */ - final VariableScope getDeclaringScope() { result = range.getDeclaringScope() } + final Scope getDeclaringScope() { result = range.getDeclaringScope() } /** Gets an access to this variable. */ VariableAccess getAnAccess() { result.getVariable() = this } diff --git a/ql/test/library-tests/variables/varaccess.ql b/ql/test/library-tests/variables/varaccess.ql index df7f516efb4..fff11bb421f 100644 --- a/ql/test/library-tests/variables/varaccess.ql +++ b/ql/test/library-tests/variables/varaccess.ql @@ -1,7 +1,7 @@ import codeql_ruby.AST import codeql_ruby.ast.Variable -query predicate variableAccess(VariableAccess access, Variable variable, VariableScope scope) { +query predicate variableAccess(VariableAccess access, Variable variable, Scope scope) { variable = access.getVariable() and scope = variable.getDeclaringScope() } diff --git a/ql/test/library-tests/variables/varscopes.ql b/ql/test/library-tests/variables/varscopes.ql index e0272ce17af..8a8af82355b 100644 --- a/ql/test/library-tests/variables/varscopes.ql +++ b/ql/test/library-tests/variables/varscopes.ql @@ -1,3 +1,3 @@ -import codeql_ruby.ast.Variable +import codeql_ruby.ast.Scope -select any(VariableScope x) +select any(Scope x)