mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
Ruby: Cache ConstantReadAccess::getValue
This commit is contained in:
@@ -224,21 +224,7 @@ class ConstantReadAccess extends ConstantAccess {
|
||||
*
|
||||
* the value being read at `M::CONST` is `"const"`.
|
||||
*/
|
||||
Expr getValue() {
|
||||
not exists(this.getScopeExpr()) and
|
||||
result = lookupConst(this.getEnclosingModule+().getModule(), this.getName()) and
|
||||
// For now, we restrict the scope of top-level declarations to their file.
|
||||
// This may remove some plausible targets, but also removes a lot of
|
||||
// implausible targets
|
||||
if result.getEnclosingModule() instanceof Toplevel
|
||||
then result.getFile() = this.getFile()
|
||||
else any()
|
||||
or
|
||||
this.hasGlobalScope() and
|
||||
result = lookupConst(TResolved("Object"), this.getName())
|
||||
or
|
||||
result = lookupConst(resolveConstantReadAccess(this.getScopeExpr()), this.getName())
|
||||
}
|
||||
Expr getValue() { result = getConstantReadAccessValue(this) }
|
||||
|
||||
final override string getAPrimaryQlClass() { result = "ConstantReadAccess" }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
private import codeql.ruby.AST
|
||||
private import codeql.ruby.ast.internal.Literal
|
||||
private import codeql.ruby.ast.internal.Module
|
||||
private import codeql.ruby.controlflow.CfgNodes
|
||||
private import codeql.ruby.dataflow.SSA
|
||||
private import ExprNodes
|
||||
@@ -441,6 +442,23 @@ private module Cached {
|
||||
result.isNil() and
|
||||
isNilExpr(e)
|
||||
}
|
||||
|
||||
cached
|
||||
Expr getConstantReadAccessValue(ConstantReadAccess read) {
|
||||
not exists(read.getScopeExpr()) and
|
||||
result = lookupConst(read.getEnclosingModule+().getModule(), read.getName()) and
|
||||
// For now, we restrict the scope of top-level declarations to their file.
|
||||
// This may remove some plausible targets, but also removes a lot of
|
||||
// implausible targets
|
||||
if result.getEnclosingModule() instanceof Toplevel
|
||||
then result.getFile() = read.getFile()
|
||||
else any()
|
||||
or
|
||||
read.hasGlobalScope() and
|
||||
result = lookupConst(TResolved("Object"), read.getName())
|
||||
or
|
||||
result = lookupConst(resolveConstantReadAccess(read.getScopeExpr()), read.getName())
|
||||
}
|
||||
}
|
||||
|
||||
import Cached
|
||||
|
||||
Reference in New Issue
Block a user