Address review comments

This commit is contained in:
Tom Hvitved
2021-07-14 11:05:55 +02:00
parent 23447e6d58
commit 9463927409
6 changed files with 45 additions and 2 deletions

View File

@@ -114,6 +114,9 @@ class ConstantReadAccess extends ConstantAccess {
then result.getFile() = this.getFile()
else any()
or
this.hasGlobalScope() and
result = lookupConst(TResolved("Object"), this.getName())
or
result = lookupConst(resolveScopeExpr(this.getScopeExpr()), this.getName())
}

View File

@@ -135,7 +135,16 @@ private module Cached {
Method lookupMethod(Module m, string name) { TMethod(result) = lookupMethodOrConst(m, name) }
cached
Expr lookupConst(Module m, string name) { TExpr(result) = lookupMethodOrConst(m, name) }
Expr lookupConst(Module m, string name) {
TExpr(result) = lookupMethodOrConst(m, name)
or
exists(AssignExpr ae, ConstantWriteAccess w |
w = ae.getLeftOperand() and
w.getName() = name and
m = resolveScopeExpr(w.getScopeExpr()) and
result = ae.getRightOperand()
)
}
}
import Cached

View File

@@ -867,6 +867,17 @@ constants/constants.rb:
# 37| getScopeExpr: [ConstantReadAccess] ModuleB
# 37| getScopeExpr: [ConstantReadAccess] ModuleA
# 37| getAnOperand/getRightOperand: [IntegerLiteral] 1024
# 39| getStmt: [MethodCall] call to puts
# 39| getReceiver: [Self] self
# 39| getArgument: [ConstantReadAccess] MAX_SIZE
# 39| getScopeExpr: [ConstantReadAccess] ModuleB
# 39| getScopeExpr: [ConstantReadAccess] ModuleA
# 41| getStmt: [MethodCall] call to puts
# 41| getReceiver: [Self] self
# 41| getArgument: [ConstantReadAccess] GREETING
# 42| getStmt: [MethodCall] call to puts
# 42| getReceiver: [Self] self
# 42| getArgument: [ConstantReadAccess] GREETING
literals/literals.rb:
# 1| [Toplevel] literals.rb
# 2| getStmt: [NilLiteral] nil

View File

@@ -28,6 +28,11 @@ constantAccess
| constants.rb:37:1:37:7 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:37:1:37:16 | ModuleB | read | ModuleB | ConstantReadAccess |
| constants.rb:37:1:37:26 | MAX_SIZE | write | MAX_SIZE | ConstantAssignment |
| constants.rb:39:6:39:12 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:39:6:39:21 | ModuleB | read | ModuleB | ConstantReadAccess |
| constants.rb:39:6:39:31 | MAX_SIZE | read | MAX_SIZE | ConstantReadAccess |
| constants.rb:41:6:41:13 | GREETING | read | GREETING | ConstantReadAccess |
| constants.rb:42:6:42:15 | GREETING | read | GREETING | ConstantReadAccess |
getConst
| constants.rb:1:1:15:3 | ModuleA | CONST_B | constants.rb:6:15:6:23 | "const_b" |
| constants.rb:2:5:4:7 | ModuleA::ClassA | CONST_A | constants.rb:3:19:3:27 | "const_a" |
@@ -36,8 +41,16 @@ lookupConst
| constants.rb:1:1:15:3 | ModuleA | CONST_B | constants.rb:6:15:6:23 | "const_b" |
| constants.rb:2:5:4:7 | ModuleA::ClassA | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:2:5:4:7 | ModuleA::ClassA | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:8:5:14:7 | ModuleA::ModuleB | MAX_SIZE | constants.rb:37:30:37:33 | 1024 |
| constants.rb:9:9:10:11 | ModuleA::ModuleB::ClassB | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:12:9:13:11 | ModuleA::ModuleB::ClassC | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:31:1:32:3 | ModuleA::ClassD | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:31:1:32:3 | ModuleA::ClassD | GREETING | constants.rb:17:12:17:64 | ... + ... |
| file://:0:0:0:0 | Object | GREETING | constants.rb:17:12:17:64 | ... + ... |
constantValue
| constants.rb:17:22:17:45 | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:17:49:17:64 | CONST_B | constants.rb:6:15:6:23 | "const_b" |
| constants.rb:23:18:23:25 | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:39:6:39:31 | MAX_SIZE | constants.rb:37:30:37:33 | 1024 |
| constants.rb:41:6:41:13 | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:42:6:42:15 | GREETING | constants.rb:17:12:17:64 | ... + ... |

View File

@@ -14,3 +14,5 @@ query predicate constantAccess(ConstantAccess a, string kind, string name, strin
query Expr getConst(Module m, string name) { result = M::ExposedForTestingOnly::getConst(m, name) }
query Expr lookupConst(Module m, string name) { result = M::lookupConst(m, name) }
query predicate constantValue(ConstantReadAccess a, Expr e) { e = a.getValue() }

View File

@@ -34,4 +34,9 @@ end
module ModuleA::ModuleC
end
ModuleA::ModuleB::MAX_SIZE = 1024
ModuleA::ModuleB::MAX_SIZE = 1024
puts ModuleA::ModuleB::MAX_SIZE
puts GREETING
puts ::GREETING