@@ -10,13 +10,29 @@ private import codeql_ruby.ast.Scope
1010private string builtin ( ) { result = [ "Object" , "Kernel" , "BasicObject" , "Class" , "Module" ] }
1111
1212cached
13- newtype TModule =
14- TResolved ( string qName ) {
15- qName = builtin ( )
13+ module Cached {
14+ cached
15+ newtype TModule =
16+ TResolved ( string qName ) {
17+ qName = builtin ( )
18+ or
19+ qName = constantDefinition ( _)
20+ } or
21+ TUnresolved ( Namespace n ) { not exists ( constantDefinition ( n ) ) }
22+
23+ cached
24+ string constantDefinition ( ConstantWriteAccess n ) {
25+ isToplevel ( n ) and result = n .getName ( )
26+ or
27+ not isToplevel ( n ) and
28+ not exists ( n .getScopeExpr ( ) ) and
29+ result = scopeAppend ( constantDefinition ( n .getEnclosingModule ( ) ) , n .getName ( ) )
1630 or
17- qName = constantDefinition ( _)
18- } or
19- TUnresolved ( Namespace n ) { not exists ( constantDefinition ( n ) ) }
31+ result = scopeAppend ( resolveScopeExpr ( n .getScopeExpr ( ) ) , n .getName ( ) )
32+ }
33+ }
34+
35+ import Cached
2036
2137private predicate isToplevel ( ConstantAccess n ) {
2238 not exists ( n .getScopeExpr ( ) ) and
@@ -27,16 +43,6 @@ private predicate isToplevel(ConstantAccess n) {
2743 )
2844}
2945
30- string constantDefinition ( ConstantWriteAccess n ) {
31- isToplevel ( n ) and result = n .getName ( )
32- or
33- not isToplevel ( n ) and
34- not exists ( n .getScopeExpr ( ) ) and
35- result = scopeAppend ( constantDefinition ( n .getEnclosingModule ( ) ) , n .getName ( ) )
36- or
37- result = scopeAppend ( resolveScopeExpr ( n .getScopeExpr ( ) ) , n .getName ( ) )
38- }
39-
4046private predicate isDefinedConstant ( string qualifiedModuleName ) {
4147 qualifiedModuleName = [ builtin ( ) , constantDefinition0 ( _) ]
4248}
@@ -64,7 +70,6 @@ private string resolveScopeExpr(ConstantReadAccess r) {
6470 )
6571}
6672
67- cached
6873private int maxDepth ( ) { result = max ( ConstantAccess c | | count ( c .getEnclosingModule + ( ) ) ) }
6974
7075private ModuleBase enclosing ( ModuleBase m , int level ) {
0 commit comments