mirror of
https://github.com/github/codeql.git
synced 2026-02-20 08:53:49 +01:00
Introduce Parameter::getAVariable()
This commit is contained in:
@@ -21,6 +21,15 @@ class Parameter extends AstNode {
|
||||
|
||||
/** Gets the zero-based position of this parameter. */
|
||||
final int getPosition() { result = pos }
|
||||
|
||||
/** Gets a variable introduced by this parameter. */
|
||||
Variable getAVariable() { none() }
|
||||
|
||||
/** Gets the variable named `name` introduced by this parameter. */
|
||||
final Variable getVariable(string name) {
|
||||
result = this.getAVariable() and
|
||||
result.getName() = name
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,6 +42,10 @@ class PatternParameter extends Parameter, Pattern { }
|
||||
/** A parameter defined using a tuple pattern. */
|
||||
class TuplePatternParameter extends PatternParameter, TuplePattern {
|
||||
final override string describeQlClass() { result = "TuplePatternParameter" }
|
||||
|
||||
final override Variable getAVariable() {
|
||||
result = this.getAnElement+().(VariablePattern).getVariable()
|
||||
}
|
||||
}
|
||||
|
||||
/** A named parameter. */
|
||||
@@ -45,6 +58,8 @@ class NamedParameter extends Parameter {
|
||||
/** Gets the variable introduced by this parameter. */
|
||||
Variable getVariable() { none() }
|
||||
|
||||
final override Variable getAVariable() { result = this.getVariable() }
|
||||
|
||||
/** Gets an access to this parameter. */
|
||||
final VariableAccess getAnAccess() { result = this.getVariable().getAnAccess() }
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import codeql_ruby.AST
|
||||
private import codeql_ruby.Generated
|
||||
private import codeql.Locations
|
||||
private import internal.Pattern
|
||||
private import internal.Variable
|
||||
private import Variable
|
||||
|
||||
/** A pattern. */
|
||||
@@ -16,8 +17,8 @@ class VariablePattern extends Pattern {
|
||||
/** Gets the name of the variable used in this pattern. */
|
||||
final string getVariableName() { result = generated.getValue() }
|
||||
|
||||
/** Gets the variable used in this pattern. */
|
||||
Variable getVariable() { this = result.getAnAccess() }
|
||||
/** Gets the variable used in (or introduced by) this pattern. */
|
||||
Variable getVariable() { access(this, result) }
|
||||
|
||||
override string toString() { result = this.getVariableName() }
|
||||
}
|
||||
|
||||
@@ -60,7 +60,11 @@ class VariableAccess extends AstNode, @token_identifier {
|
||||
override Generated::Identifier generated;
|
||||
Variable variable;
|
||||
|
||||
VariableAccess() { access(this, variable) }
|
||||
VariableAccess() {
|
||||
access(this, variable) and
|
||||
// Do not generate an access at the defining location
|
||||
not variable = TLocalVariable(_, _, this)
|
||||
}
|
||||
|
||||
/** Gets the variable this identifier refers to. */
|
||||
Variable getVariable() { result = variable }
|
||||
|
||||
@@ -123,11 +123,7 @@ private module Cached {
|
||||
|
||||
cached
|
||||
predicate access(Generated::Identifier access, Variable variable) {
|
||||
exists(string name |
|
||||
name = access.getValue() and
|
||||
// Do not generate an access at the defining location
|
||||
not variable = TLocalVariable(_, name, access)
|
||||
|
|
||||
exists(string name | name = access.getValue() |
|
||||
variable = enclosingScope(access).getVariable(name) and
|
||||
not strictlyBefore(access.getLocation(), variable.getLocation())
|
||||
or
|
||||
|
||||
Reference in New Issue
Block a user