mirror of
https://github.com/github/codeql.git
synced 2026-05-25 00:27:09 +02:00
PS: Move a bunch of predicates into ScriptBlock.
This commit is contained in:
@@ -10,7 +10,7 @@ class ScriptBlock extends @script_block, Ast {
|
||||
else result = "{...}"
|
||||
}
|
||||
|
||||
override SourceLocation getLocation() { script_block_location(this, result) }
|
||||
override Location getLocation() { script_block_location(this, result) }
|
||||
|
||||
int getNumUsings() { script_block(this, result, _, _, _, _) }
|
||||
|
||||
@@ -51,6 +51,42 @@ class ScriptBlock extends @script_block, Ast {
|
||||
ModuleSpecification getAModuleSpecification() { result = this.getModuleSpecification(_) }
|
||||
|
||||
final override Scope getEnclosingScope() { result = this }
|
||||
|
||||
/**
|
||||
* Gets the `i`'th paramter in this scope.
|
||||
*
|
||||
* This may be both function paramters and parameter block parameters.
|
||||
*/
|
||||
Parameter getParameter(int i) {
|
||||
exists(Function func |
|
||||
func.getBody() = this and
|
||||
result = func.getParameter(i)
|
||||
)
|
||||
or
|
||||
this.isTopLevel() and
|
||||
result = this.getParamBlock().getParameter(i)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a paramter in this scope.
|
||||
*
|
||||
* This may be both function parameters and parameter block parameters.
|
||||
*/
|
||||
Parameter getAParameter() { result = this.getParameter(_) }
|
||||
|
||||
Parameter getThisParameter() {
|
||||
exists(Function func |
|
||||
func.getBody() = this and
|
||||
result = func.getThisParameter()
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the number of function parameters. */
|
||||
final int getNumberOfParameters() { result = count(this.getAParameter()) }
|
||||
|
||||
final Parameter getParameterExcludingPiplines(int i) {
|
||||
result = this.getParamBlock().getParameterExcludingPiplines(i)
|
||||
}
|
||||
}
|
||||
|
||||
/** A `process` block. */
|
||||
@@ -69,3 +105,7 @@ class ProcessBlock extends NamedBlock {
|
||||
result = scriptBlock.getEnclosingFunction().getAParameter()
|
||||
}
|
||||
}
|
||||
|
||||
class TopLevelScriptBlock extends ScriptBlock {
|
||||
TopLevelScriptBlock() { this.isTopLevel() }
|
||||
}
|
||||
|
||||
@@ -14,33 +14,7 @@ Scope scopeOf(Ast n) {
|
||||
* A variable scope. This is either a top-level (file), a module, a class,
|
||||
* or a callable.
|
||||
*/
|
||||
class Scope extends Ast, @script_block {
|
||||
class Scope extends Ast, ScriptBlock {
|
||||
/** Gets the outer scope, if any. */
|
||||
Scope getOuterScope() { result = scopeOf(this) }
|
||||
|
||||
/**
|
||||
* Gets the `i`'th paramter in this scope.
|
||||
*
|
||||
* This may be both function paramters and parameter block parameters.
|
||||
*/
|
||||
Parameter getParameter(int i) {
|
||||
exists(Function func |
|
||||
func.getBody() = this and
|
||||
result = func.getParameter(i)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a paramter in this scope.
|
||||
*
|
||||
* This may be both function paramters and parameter block parameters.
|
||||
*/
|
||||
Parameter getAParameter() { result = this.getParameter(_) }
|
||||
|
||||
Parameter getThisParameter() {
|
||||
exists(Function func |
|
||||
func.getBody() = this and
|
||||
result = func.getThisParameter()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user