Model local variables

This commit is contained in:
Arthur Baars
2020-11-19 13:24:44 +01:00
parent 6bd476ff30
commit c16a2e77d8
9 changed files with 415 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
def a
puts "method a"
end
class C
a = 5
module M
a = 4
module N
a = 3
class D
a = 2
def show_a
a = 1
puts a
a.times do |a|
a.times do | x; a|
a = 6
a.times { |x| puts a }
end
end
end
def show_a2 a
puts a
end
puts a
end
def self.show
puts a # not a variable, but a call to a()
end
class << self
a = 10
puts a
end
puts a
end
puts a
end
puts a
end
d = C::M::N::D.new
d.show_a

View File

@@ -0,0 +1,13 @@
def a ; "x" end
1.times do | x |
puts a # not a local variable
a = 3
puts a # local variable
end
a = 6
puts a
1.times do | x |
puts a # local variable from top-level
a = 3
puts a # local variable from top-level
end

View File

@@ -0,0 +1,71 @@
variableAccess
| nested_scopes.rb:5:3:5:3 | a | nested_scopes.rb:4:1:39:3 | class scope |
| nested_scopes.rb:7:5:7:5 | a | nested_scopes.rb:6:3:37:5 | module scope |
| nested_scopes.rb:9:7:9:7 | a | nested_scopes.rb:8:5:35:7 | module scope |
| nested_scopes.rb:11:9:11:9 | a | nested_scopes.rb:10:7:26:9 | class scope |
| nested_scopes.rb:13:11:13:11 | a | nested_scopes.rb:12:9:21:11 | method scope |
| nested_scopes.rb:14:16:14:16 | a | nested_scopes.rb:12:9:21:11 | method scope |
| nested_scopes.rb:15:11:15:11 | a | nested_scopes.rb:12:9:21:11 | method scope |
| nested_scopes.rb:15:23:15:23 | a | nested_scopes.rb:15:19:20:13 | block scope |
| nested_scopes.rb:16:13:16:13 | a | nested_scopes.rb:15:19:20:13 | block scope |
| nested_scopes.rb:16:26:16:26 | x | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:16:29:16:29 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:17:15:17:15 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:18:15:18:15 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:18:26:18:26 | x | nested_scopes.rb:18:23:18:36 | block scope |
| nested_scopes.rb:18:34:18:34 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:22:21:22:21 | a | nested_scopes.rb:22:9:24:11 | method scope |
| nested_scopes.rb:23:16:23:16 | a | nested_scopes.rb:22:9:24:11 | method scope |
| nested_scopes.rb:25:14:25:14 | a | nested_scopes.rb:10:7:26:9 | class scope |
| nested_scopes.rb:31:11:31:11 | a | nested_scopes.rb:30:7:33:9 | class scope |
| nested_scopes.rb:32:16:32:16 | a | nested_scopes.rb:30:7:33:9 | class scope |
| nested_scopes.rb:34:12:34:12 | a | nested_scopes.rb:8:5:35:7 | module scope |
| nested_scopes.rb:36:10:36:10 | a | nested_scopes.rb:6:3:37:5 | module scope |
| nested_scopes.rb:38:8:38:8 | a | nested_scopes.rb:4:1:39:3 | class scope |
| nested_scopes.rb:40:1:40:1 | d | nested_scopes.rb:1:1:42:1 | top-level scope |
| nested_scopes.rb:41:1:41:1 | d | nested_scopes.rb:1:1:42:1 | top-level scope |
| scopes.rb:2:14:2:14 | x | scopes.rb:2:9:6:3 | block scope |
| scopes.rb:4:4:4:4 | a | scopes.rb:2:9:6:3 | block scope |
| scopes.rb:5:9:5:9 | a | scopes.rb:2:9:6:3 | block scope |
| scopes.rb:7:1:7:1 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:8:6:8:6 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:9:14:9:14 | x | scopes.rb:9:9:13:3 | block scope |
| scopes.rb:10:9:10:9 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:11:4:11:4 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:12:9:12:9 | a | scopes.rb:1:1:13:3 | top-level scope |
parameterAccess
| nested_scopes.rb:15:23:15:23 | a | nested_scopes.rb:15:19:20:13 | block scope |
| nested_scopes.rb:16:13:16:13 | a | nested_scopes.rb:15:19:20:13 | block scope |
| nested_scopes.rb:16:26:16:26 | x | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:16:29:16:29 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:17:15:17:15 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:18:15:18:15 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:18:26:18:26 | x | nested_scopes.rb:18:23:18:36 | block scope |
| nested_scopes.rb:18:34:18:34 | a | nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:22:21:22:21 | a | nested_scopes.rb:22:9:24:11 | method scope |
| nested_scopes.rb:23:16:23:16 | a | nested_scopes.rb:22:9:24:11 | method scope |
| scopes.rb:2:14:2:14 | x | scopes.rb:2:9:6:3 | block scope |
| scopes.rb:9:14:9:14 | x | scopes.rb:9:9:13:3 | block scope |
localVariableAccess
| nested_scopes.rb:5:3:5:3 | a | nested_scopes.rb:4:1:39:3 | class scope |
| nested_scopes.rb:7:5:7:5 | a | nested_scopes.rb:6:3:37:5 | module scope |
| nested_scopes.rb:9:7:9:7 | a | nested_scopes.rb:8:5:35:7 | module scope |
| nested_scopes.rb:11:9:11:9 | a | nested_scopes.rb:10:7:26:9 | class scope |
| nested_scopes.rb:13:11:13:11 | a | nested_scopes.rb:12:9:21:11 | method scope |
| nested_scopes.rb:14:16:14:16 | a | nested_scopes.rb:12:9:21:11 | method scope |
| nested_scopes.rb:15:11:15:11 | a | nested_scopes.rb:12:9:21:11 | method scope |
| nested_scopes.rb:25:14:25:14 | a | nested_scopes.rb:10:7:26:9 | class scope |
| nested_scopes.rb:31:11:31:11 | a | nested_scopes.rb:30:7:33:9 | class scope |
| nested_scopes.rb:32:16:32:16 | a | nested_scopes.rb:30:7:33:9 | class scope |
| nested_scopes.rb:34:12:34:12 | a | nested_scopes.rb:8:5:35:7 | module scope |
| nested_scopes.rb:36:10:36:10 | a | nested_scopes.rb:6:3:37:5 | module scope |
| nested_scopes.rb:38:8:38:8 | a | nested_scopes.rb:4:1:39:3 | class scope |
| nested_scopes.rb:40:1:40:1 | d | nested_scopes.rb:1:1:42:1 | top-level scope |
| nested_scopes.rb:41:1:41:1 | d | nested_scopes.rb:1:1:42:1 | top-level scope |
| scopes.rb:4:4:4:4 | a | scopes.rb:2:9:6:3 | block scope |
| scopes.rb:5:9:5:9 | a | scopes.rb:2:9:6:3 | block scope |
| scopes.rb:7:1:7:1 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:8:6:8:6 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:10:9:10:9 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:11:4:11:4 | a | scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:12:9:12:9 | a | scopes.rb:1:1:13:3 | top-level scope |

View File

@@ -0,0 +1,13 @@
import codeql_ruby.Variables
query predicate variableAccess(VariableAccess var, VariableScope scope) {
scope = var.getVariable().getDeclaringScope()
}
query predicate parameterAccess(ParameterAccess var, VariableScope scope) {
scope = var.getVariable().getDeclaringScope()
}
query predicate localVariableAccess(LocalVariableAccess var, VariableScope scope) {
scope = var.getVariable().getDeclaringScope()
}

View File

@@ -0,0 +1,35 @@
variable
| nested_scopes.rb:5:3:5:3 | a |
| nested_scopes.rb:7:5:7:5 | a |
| nested_scopes.rb:9:7:9:7 | a |
| nested_scopes.rb:11:9:11:9 | a |
| nested_scopes.rb:13:11:13:11 | a |
| nested_scopes.rb:15:23:15:23 | a |
| nested_scopes.rb:16:26:16:26 | x |
| nested_scopes.rb:16:29:16:29 | a |
| nested_scopes.rb:18:26:18:26 | x |
| nested_scopes.rb:22:21:22:21 | a |
| nested_scopes.rb:31:11:31:11 | a |
| nested_scopes.rb:40:1:40:1 | d |
| scopes.rb:2:14:2:14 | x |
| scopes.rb:4:4:4:4 | a |
| scopes.rb:7:1:7:1 | a |
| scopes.rb:9:14:9:14 | x |
parameter
| nested_scopes.rb:15:23:15:23 | a |
| nested_scopes.rb:16:26:16:26 | x |
| nested_scopes.rb:16:29:16:29 | a |
| nested_scopes.rb:18:26:18:26 | x |
| nested_scopes.rb:22:21:22:21 | a |
| scopes.rb:2:14:2:14 | x |
| scopes.rb:9:14:9:14 | x |
localVariable
| nested_scopes.rb:5:3:5:3 | a |
| nested_scopes.rb:7:5:7:5 | a |
| nested_scopes.rb:9:7:9:7 | a |
| nested_scopes.rb:11:9:11:9 | a |
| nested_scopes.rb:13:11:13:11 | a |
| nested_scopes.rb:31:11:31:11 | a |
| nested_scopes.rb:40:1:40:1 | d |
| scopes.rb:4:4:4:4 | a |
| scopes.rb:7:1:7:1 | a |

View File

@@ -0,0 +1,7 @@
import codeql_ruby.Variables
query predicate variable(Variable v) { any() }
query predicate parameter(Parameter p) { any() }
query predicate localVariable(LocalVariable v) { any() }

View File

@@ -0,0 +1,17 @@
| nested_scopes.rb:1:1:3:3 | method scope |
| nested_scopes.rb:1:1:42:1 | top-level scope |
| nested_scopes.rb:4:1:39:3 | class scope |
| nested_scopes.rb:6:3:37:5 | module scope |
| nested_scopes.rb:8:5:35:7 | module scope |
| nested_scopes.rb:10:7:26:9 | class scope |
| nested_scopes.rb:12:9:21:11 | method scope |
| nested_scopes.rb:15:19:20:13 | block scope |
| nested_scopes.rb:16:21:19:15 | block scope |
| nested_scopes.rb:18:23:18:36 | block scope |
| nested_scopes.rb:22:9:24:11 | method scope |
| nested_scopes.rb:27:7:29:9 | method scope |
| nested_scopes.rb:30:7:33:9 | class scope |
| scopes.rb:1:1:1:15 | method scope |
| scopes.rb:1:1:13:3 | top-level scope |
| scopes.rb:2:9:6:3 | block scope |
| scopes.rb:9:9:13:3 | block scope |

View File

@@ -0,0 +1,3 @@
import codeql_ruby.Variables
select any(VariableScope x)