mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
add more test cases, fix bug by adding getFullName() predicate
This commit is contained in:
@@ -40,6 +40,16 @@ class ConstantAccess extends Expr, TConstantAccess {
|
||||
*/
|
||||
predicate hasGlobalScope() { none() }
|
||||
|
||||
// gets the full name
|
||||
string getFullName() {
|
||||
exists(ConstantAccess ca | this.getScopeExpr() = ca |
|
||||
result = ca.getFullName() + "::" + this.getName())
|
||||
or
|
||||
// TODO if the getScopeExpr is not a constant, try to figure out which constants it could be?
|
||||
not exists(ConstantAccess ca | this.getScopeExpr() = ca) and
|
||||
result = this.getName()
|
||||
}
|
||||
|
||||
override string toString() { result = this.getName() }
|
||||
|
||||
override AstNode getAChild(string pred) {
|
||||
@@ -188,12 +198,12 @@ class ConstantWriteAccess extends ConstantAccess {
|
||||
string getQualifiedName() {
|
||||
/* get the qualified name for the parent module, then append w */
|
||||
exists(ConstantWriteAccess parent | parent = this.getEnclosingModule() |
|
||||
result = parent.getQualifiedName() + "::" + this.getName()
|
||||
result = parent.getQualifiedName() + "::" + this.getFullName()
|
||||
)
|
||||
or
|
||||
/* base case - there's no parent module */
|
||||
not exists(ConstantWriteAccess parent | parent = this.getEnclosingModule()) and
|
||||
result = this.getName()
|
||||
result = this.getFullName()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,14 @@ constantAccess
|
||||
| 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 |
|
||||
| constants.rb:44:1:47:3 | ModuleB | write | ModuleB | ModuleDeclaration |
|
||||
| constants.rb:44:8:44:14 | ModuleA | read | ModuleA | ConstantReadAccess |
|
||||
| constants.rb:45:3:46:5 | ClassB | write | ClassB | ClassDeclaration |
|
||||
| constants.rb:45:18:45:21 | Base | read | Base | ConstantReadAccess |
|
||||
| constants.rb:49:1:52:3 | ModuleA | write | ModuleA | ModuleDeclaration |
|
||||
| constants.rb:50:3:51:5 | ClassB | write | ClassB | ClassDeclaration |
|
||||
| constants.rb:50:9:50:15 | ModuleB | read | ModuleB | ConstantReadAccess |
|
||||
| constants.rb:50:27:50:30 | Base | read | Base | 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" |
|
||||
@@ -67,4 +75,8 @@ constantWriteAccessQualifiedName
|
||||
| constants.rb:20:5:20:9 | Names | Names |
|
||||
| constants.rb:31:1:32:3 | ClassD | ModuleA::ClassD |
|
||||
| constants.rb:34:1:35:3 | ModuleC | ModuleA::ModuleC |
|
||||
| constants.rb:37:1:37:26 | MAX_SIZE | MAX_SIZE |
|
||||
| constants.rb:37:1:37:26 | MAX_SIZE | ModuleA::ModuleB::MAX_SIZE |
|
||||
| constants.rb:44:1:47:3 | ModuleB | ModuleA::ModuleB |
|
||||
| constants.rb:45:3:46:5 | ClassB | ModuleA::ModuleB::ClassB |
|
||||
| constants.rb:49:1:52:3 | ModuleA | ModuleA |
|
||||
| constants.rb:50:3:51:5 | ClassB | ModuleA::ModuleB::ClassB |
|
||||
@@ -40,3 +40,13 @@ puts ModuleA::ModuleB::MAX_SIZE
|
||||
|
||||
puts GREETING
|
||||
puts ::GREETING
|
||||
|
||||
module ModuleA::ModuleB
|
||||
class ClassB < Base
|
||||
end
|
||||
end
|
||||
|
||||
module ModuleA
|
||||
class ModuleB::ClassB < Base
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user