From eebbc7e505471625cb9b1e86fbb7e454d1b16ad9 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Fri, 26 Mar 2021 16:00:24 +0100 Subject: [PATCH] AST: rename Class/Module to ClassDefinition/ModuleDefinition --- ql/src/codeql_ruby/ast/Module.qll | 24 +++---- .../internal/ControlFlowGraphImpl.qll | 8 +-- ql/test/library-tests/ast/Ast.expected | 72 +++++++++---------- .../ast/constants/constants.expected | 14 ++-- .../ast/modules/classes.expected | 26 +++---- ql/test/library-tests/ast/modules/classes.ql | 22 +++--- .../ast/modules/module_base.expected | 42 +++++------ .../library-tests/ast/modules/module_base.ql | 4 +- .../ast/modules/modules.expected | 28 ++++---- ql/test/library-tests/ast/modules/modules.ql | 14 ++-- .../ast/modules/singleton_classes.expected | 2 +- 11 files changed, 131 insertions(+), 125 deletions(-) diff --git a/ql/src/codeql_ruby/ast/Module.qll b/ql/src/codeql_ruby/ast/Module.qll index 0eff778dbb8..6279a7e8a15 100644 --- a/ql/src/codeql_ruby/ast/Module.qll +++ b/ql/src/codeql_ruby/ast/Module.qll @@ -14,16 +14,16 @@ class ModuleBase extends BodyStmt, TModuleBase { MethodBase getMethod(string name) { result = this.getAMethod() and result.getName() = name } /** Gets a class defined in this module/class. */ - Class getAClass() { result = this.getAStmt() } + ClassDefinition getAClass() { result = this.getAStmt() } /** Gets the class named `name` in this module/class, if any. */ - Class getClass(string name) { result = this.getAClass() and result.getName() = name } + ClassDefinition getClass(string name) { result = this.getAClass() and result.getName() = name } /** Gets a module defined in this module/class. */ - Module getAModule() { result = this.getAStmt() } + ModuleDefinition getAModule() { result = this.getAStmt() } /** Gets the module named `name` in this module/class, if any. */ - Module getModule(string name) { result = this.getAModule() and result.getName() = name } + ModuleDefinition getModule(string name) { result = this.getAModule() and result.getName() = name } } /** @@ -150,12 +150,12 @@ class Namespace extends ModuleBase, ConstantWriteAccess, TNamespace { * end * ``` */ -class Class extends Namespace, TClass { +class ClassDefinition extends Namespace, TClass { private Generated::Class g; - Class() { this = TClass(g) } + ClassDefinition() { this = TClass(g) } - final override string getAPrimaryQlClass() { result = "Class" } + final override string getAPrimaryQlClass() { result = "ClassDefinition" } /** * Gets the `Expr` used as the superclass in the class definition, if any. @@ -214,7 +214,7 @@ class SingletonClass extends ModuleBase, TSingletonClass { SingletonClass() { this = TSingletonClass(g) } - final override string getAPrimaryQlClass() { result = "Class" } + final override string getAPrimaryQlClass() { result = "ClassDefinition" } /** * Gets the expression resulting in the object on which the singleton class @@ -249,7 +249,7 @@ class SingletonClass extends ModuleBase, TSingletonClass { * N.B. this class represents a single instance of a module definition. In the * following example, classes `Bar` and `Baz` are both defined in the module * `Foo`, but in two syntactically distinct definitions, meaning that there - * will be two instances of `Module` in the database. + * will be two instances of `ModuleDefinition` in the database. * * ```rb * module Foo @@ -261,12 +261,12 @@ class SingletonClass extends ModuleBase, TSingletonClass { * end * ``` */ -class Module extends Namespace, TModule { +class ModuleDefinition extends Namespace, TModule { private Generated::Module g; - Module() { this = TModule(g) } + ModuleDefinition() { this = TModule(g) } - final override string getAPrimaryQlClass() { result = "Module" } + final override string getAPrimaryQlClass() { result = "ModuleDefinition" } final override string getName() { result = g.getName().(Generated::Token).getValue() or diff --git a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll index 15097a58d85..3f54a5d49a0 100644 --- a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll +++ b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll @@ -598,7 +598,7 @@ module Trees { private class CharacterTree extends LeafTree, CharacterLiteral { } - private class ClassTree extends BodyStmtPreOrderTree, Class { + private class ClassTree extends BodyStmtPreOrderTree, ClassDefinition { /** Gets the `i`th child in the body of this block. */ final override AstNode getBodyChild(int i, boolean rescuable) { result = this.getScopeExpr() and i = 0 and rescuable = false @@ -673,8 +673,8 @@ module Trees { private class ConstantAccessTree extends PostOrderTree, ConstantAccess { ConstantAccessTree() { - not this instanceof Class and - not this instanceof Module + not this instanceof ClassDefinition and + not this instanceof ModuleDefinition } final override predicate propagatesAbnormal(AstNode child) { child = this.getScopeExpr() } @@ -934,7 +934,7 @@ module Trees { } } - private class ModuleTree extends BodyStmtPreOrderTree, Module { + private class ModuleTree extends BodyStmtPreOrderTree, ModuleDefinition { /** Gets the `i`th child in the body of this block. */ final override AstNode getBodyChild(int i, boolean rescuable) { result = this.getScopeExpr() and i = 0 and rescuable = false diff --git a/ql/test/library-tests/ast/Ast.expected b/ql/test/library-tests/ast/Ast.expected index 5c411c581b7..1085019743b 100644 --- a/ql/test/library-tests/ast/Ast.expected +++ b/ql/test/library-tests/ast/Ast.expected @@ -128,19 +128,19 @@ calls/calls.rb: # 111| getBody: [StmtSequence] then ... # 112| getStmt: [MethodCall] call to baz # 112| getReceiver: [ConstantReadAccess] X -# 116| getStmt: [Class] MyClass +# 116| getStmt: [ClassDefinition] MyClass # 117| getStmt: [MethodCall] call to foo # 118| getStmt: [MethodCall] call to bar # 118| getReceiver: [ConstantReadAccess] X -# 122| getStmt: [Class] MyClass +# 122| getStmt: [ClassDefinition] MyClass # 122| getSuperclassExpr: [MethodCall] call to foo -# 124| getStmt: [Class] MyClass2 +# 124| getStmt: [ClassDefinition] MyClass2 # 124| getSuperclassExpr: [MethodCall] call to foo # 124| getReceiver: [ConstantReadAccess] X -# 128| getStmt: [Class] class << ... +# 128| getStmt: [ClassDefinition] class << ... # 128| getValue: [MethodCall] call to foo # 129| getStmt: [MethodCall] call to bar -# 131| getStmt: [Class] class << ... +# 131| getStmt: [ClassDefinition] class << ... # 131| getValue: [MethodCall] call to foo # 131| getReceiver: [ConstantReadAccess] X # 132| getStmt: [MethodCall] call to bar @@ -172,7 +172,7 @@ calls/calls.rb: # 156| getDefiningAccess: [LocalVariableAccess] param # 156| getDefaultValue: [MethodCall] call to foo # 156| getReceiver: [ConstantReadAccess] X -# 160| getStmt: [Module] SomeModule +# 160| getStmt: [ModuleDefinition] SomeModule # 161| getStmt: [MethodCall] call to foo # 162| getStmt: [MethodCall] call to bar # 162| getReceiver: [ConstantReadAccess] X @@ -376,7 +376,7 @@ calls/calls.rb: # 279| getKey: [SymbolLiteral] :blah # 279| getValue: [MethodCall] call to bar # 279| getReceiver: [ConstantReadAccess] X -# 284| getStmt: [Class] MyClass +# 284| getStmt: [ClassDefinition] MyClass # 285| getStmt: [Method] my_method # 286| getStmt: [SuperCall] call to super # 287| getStmt: [SuperCall] call to super @@ -419,7 +419,7 @@ calls/calls.rb: # 293| getStmt: [AddExpr] ... + ... # 293| getAnOperand/getLeftOperand: [LocalVariableAccess] x # 293| getAnOperand/getRightOperand: [IntegerLiteral] 200 -# 301| getStmt: [Class] AnotherClass +# 301| getStmt: [ClassDefinition] AnotherClass # 302| getStmt: [Method] another_method # 303| getStmt: [MethodCall] call to super # 303| getReceiver: [MethodCall] call to foo @@ -522,16 +522,16 @@ control/cases.rb: # 21| getStmt: [IntegerLiteral] 30 modules/classes.rb: # 2| [Toplevel] classes.rb -# 3| getStmt: [Class] Foo -# 7| getStmt: [Class] Bar +# 3| getStmt: [ClassDefinition] Foo +# 7| getStmt: [ClassDefinition] Bar # 7| getSuperclassExpr: [ConstantReadAccess] BaseClass -# 11| getStmt: [Class] Baz +# 11| getStmt: [ClassDefinition] Baz # 11| getSuperclassExpr: [MethodCall] call to superclass_for # 11| getArgument: [SymbolLiteral] :baz -# 15| getStmt: [Module] MyModule -# 16| getStmt: [Class] MyClass +# 15| getStmt: [ModuleDefinition] MyModule +# 16| getStmt: [ClassDefinition] MyClass # 16| getScopeExpr: [ConstantReadAccess] MyModule -# 20| getStmt: [Class] Wibble +# 20| getStmt: [ClassDefinition] Wibble # 21| getStmt: [Method] method_a # 22| getStmt: [MethodCall] call to puts # 22| getArgument: [StringLiteral] "a" @@ -544,13 +544,13 @@ modules/classes.rb: # 30| getStmt: [AssignExpr] ... = ... # 30| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var # 30| getAnOperand/getRightOperand: [IntegerLiteral] 123 -# 32| getStmt: [Class] ClassInWibble -# 35| getStmt: [Module] ModuleInWibble +# 32| getStmt: [ClassDefinition] ClassInWibble +# 35| getStmt: [ModuleDefinition] ModuleInWibble # 40| getStmt: [AssignExpr] ... = ... # 40| getAnOperand/getLeftOperand: [LocalVariableAccess] x # 40| getAnOperand/getRightOperand: [StringLiteral] "hello" # 40| getComponent: [StringTextComponent] hello -# 41| getStmt: [Class] class << ... +# 41| getStmt: [ClassDefinition] class << ... # 41| getValue: [LocalVariableAccess] x # 42| getStmt: [Method] length # 43| getStmt: [MulExpr] ... * ... @@ -564,7 +564,7 @@ modules/classes.rb: # 51| getStmt: [AssignExpr] ... = ... # 51| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var2 # 51| getAnOperand/getRightOperand: [IntegerLiteral] 456 -# 55| getStmt: [Class] MyClassInGlobalScope +# 55| getStmt: [ClassDefinition] MyClassInGlobalScope control/conditionals.rb: # 1| [Toplevel] conditionals.rb # 2| getStmt: [AssignExpr] ... = ... @@ -687,12 +687,12 @@ control/conditionals.rb: # 69| getStmt: [LocalVariableAccess] c constants/constants.rb: # 1| [Toplevel] constants.rb -# 1| getStmt: [Module] ModuleA -# 2| getStmt: [Class] ClassA -# 5| getStmt: [Module] ModuleB -# 6| getStmt: [Class] ClassB +# 1| getStmt: [ModuleDefinition] ModuleA +# 2| getStmt: [ClassDefinition] ClassA +# 5| getStmt: [ModuleDefinition] ModuleB +# 6| getStmt: [ClassDefinition] ClassB # 6| getSuperclassExpr: [ConstantReadAccess] Base -# 9| getStmt: [Class] ClassC +# 9| getStmt: [ClassDefinition] ClassC # 9| getSuperclassExpr: [ConstantReadAccess] Z # 9| getScopeExpr: [ConstantReadAccess] Y # 9| getScopeExpr: [ConstantReadAccess] X @@ -725,9 +725,9 @@ constants/constants.rb: # 25| getStmt: [MethodCall] call to Array # 25| getArgument: [StringLiteral] "foo" # 25| getComponent: [StringTextComponent] foo -# 28| getStmt: [Class] ClassD +# 28| getStmt: [ClassDefinition] ClassD # 28| getScopeExpr: [ConstantReadAccess] ModuleA -# 31| getStmt: [Module] ModuleC +# 31| getStmt: [ModuleDefinition] ModuleC # 31| getScopeExpr: [ConstantReadAccess] ModuleA # 34| getStmt: [AssignExpr] ... = ... # 34| getAnOperand/getLeftOperand: [ConstantAssignment] MAX_SIZE @@ -1322,10 +1322,10 @@ misc/misc.rb: # 10| getComponent: [StringTextComponent] foo modules/modules.rb: # 1| [Toplevel] modules.rb -# 1| getStmt: [Module] Empty -# 4| getStmt: [Module] Foo -# 5| getStmt: [Module] Bar -# 6| getStmt: [Class] ClassInFooBar +# 1| getStmt: [ModuleDefinition] Empty +# 4| getStmt: [ModuleDefinition] Foo +# 5| getStmt: [ModuleDefinition] Bar +# 6| getStmt: [ClassDefinition] ClassInFooBar # 9| getStmt: [Method] method_in_foo_bar # 12| getStmt: [MethodCall] call to puts # 12| getArgument: [StringLiteral] "module Foo::Bar" @@ -1334,23 +1334,23 @@ modules/modules.rb: # 13| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var # 13| getAnOperand/getRightOperand: [IntegerLiteral] 0 # 16| getStmt: [Method] method_in_foo -# 19| getStmt: [Class] ClassInFoo +# 19| getStmt: [ClassDefinition] ClassInFoo # 22| getStmt: [MethodCall] call to puts # 22| getArgument: [StringLiteral] "module Foo" # 22| getComponent: [StringTextComponent] module Foo # 23| getStmt: [AssignExpr] ... = ... # 23| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var # 23| getAnOperand/getRightOperand: [IntegerLiteral] 1 -# 26| getStmt: [Module] Foo +# 26| getStmt: [ModuleDefinition] Foo # 27| getStmt: [Method] method_in_another_definition_of_foo -# 30| getStmt: [Class] ClassInAnotherDefinitionOfFoo +# 30| getStmt: [ClassDefinition] ClassInAnotherDefinitionOfFoo # 33| getStmt: [MethodCall] call to puts # 33| getArgument: [StringLiteral] "module Foo again" # 33| getComponent: [StringTextComponent] module Foo again # 34| getStmt: [AssignExpr] ... = ... # 34| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var # 34| getAnOperand/getRightOperand: [IntegerLiteral] 2 -# 37| getStmt: [Module] Bar +# 37| getStmt: [ModuleDefinition] Bar # 38| getStmt: [Method] method_a # 41| getStmt: [Method] method_b # 44| getStmt: [MethodCall] call to puts @@ -1359,9 +1359,9 @@ modules/modules.rb: # 45| getStmt: [AssignExpr] ... = ... # 45| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var # 45| getAnOperand/getRightOperand: [IntegerLiteral] 3 -# 48| getStmt: [Module] Bar +# 48| getStmt: [ModuleDefinition] Bar # 48| getScopeExpr: [ConstantReadAccess] Foo -# 49| getStmt: [Class] ClassInAnotherDefinitionOfFooBar +# 49| getStmt: [ClassDefinition] ClassInAnotherDefinitionOfFooBar # 52| getStmt: [Method] method_in_another_definition_of_foo_bar # 55| getStmt: [MethodCall] call to puts # 55| getArgument: [StringLiteral] "module Foo::Bar again" @@ -1369,7 +1369,7 @@ modules/modules.rb: # 56| getStmt: [AssignExpr] ... = ... # 56| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var # 56| getAnOperand/getRightOperand: [IntegerLiteral] 4 -# 60| getStmt: [Module] MyModuleInGlobalScope +# 60| getStmt: [ModuleDefinition] MyModuleInGlobalScope operations/operations.rb: # 1| [Toplevel] operations.rb # 3| getStmt: [AssignExpr] ... = ... diff --git a/ql/test/library-tests/ast/constants/constants.expected b/ql/test/library-tests/ast/constants/constants.expected index c29abf34181..60362f161f4 100644 --- a/ql/test/library-tests/ast/constants/constants.expected +++ b/ql/test/library-tests/ast/constants/constants.expected @@ -1,9 +1,9 @@ -| constants.rb:1:1:12:3 | ModuleA | write | ModuleA | Module | -| constants.rb:2:5:3:7 | ClassA | write | ClassA | Class | -| constants.rb:5:5:11:7 | ModuleB | write | ModuleB | Module | -| constants.rb:6:9:7:11 | ClassB | write | ClassB | Class | +| constants.rb:1:1:12:3 | ModuleA | write | ModuleA | ModuleDefinition | +| constants.rb:2:5:3:7 | ClassA | write | ClassA | ClassDefinition | +| constants.rb:5:5:11:7 | ModuleB | write | ModuleB | ModuleDefinition | +| constants.rb:6:9:7:11 | ClassB | write | ClassB | ClassDefinition | | constants.rb:6:24:6:27 | Base | read | Base | ConstantReadAccess | -| constants.rb:9:9:10:11 | ClassC | write | ClassC | Class | +| constants.rb:9:9:10:11 | ClassC | write | ClassC | ClassDefinition | | constants.rb:9:24:9:24 | X | read | X | ConstantReadAccess | | constants.rb:9:24:9:27 | Y | read | Y | ConstantReadAccess | | constants.rb:9:24:9:30 | Z | read | Z | ConstantReadAccess | @@ -11,9 +11,9 @@ | constants.rb:17:5:17:9 | Names | write | Names | ConstantAssignment | | constants.rb:19:5:19:9 | Names | read | Names | ConstantReadAccess | | constants.rb:20:18:20:25 | GREETING | read | GREETING | ConstantReadAccess | -| constants.rb:28:1:29:3 | ClassD | write | ClassD | Class | +| constants.rb:28:1:29:3 | ClassD | write | ClassD | ClassDefinition | | constants.rb:28:7:28:13 | ModuleA | read | ModuleA | ConstantReadAccess | -| constants.rb:31:1:32:3 | ModuleC | write | ModuleC | Module | +| constants.rb:31:1:32:3 | ModuleC | write | ModuleC | ModuleDefinition | | constants.rb:31:8:31:14 | ModuleA | read | ModuleA | ConstantReadAccess | | constants.rb:34:1:34:7 | ModuleA | read | ModuleA | ConstantReadAccess | | constants.rb:34:1:34:16 | ModuleB | read | ModuleB | ConstantReadAccess | diff --git a/ql/test/library-tests/ast/modules/classes.expected b/ql/test/library-tests/ast/modules/classes.expected index 9eb7604f0df..5d9b7dfae33 100644 --- a/ql/test/library-tests/ast/modules/classes.expected +++ b/ql/test/library-tests/ast/modules/classes.expected @@ -1,15 +1,15 @@ classes -| classes.rb:3:1:4:3 | Foo | Class | Foo | -| classes.rb:7:1:8:3 | Bar | Class | Bar | -| classes.rb:11:1:12:3 | Baz | Class | Baz | -| classes.rb:16:1:17:3 | MyClass | Class | MyClass | -| classes.rb:20:1:37:3 | Wibble | Class | Wibble | -| classes.rb:32:3:33:5 | ClassInWibble | Class | ClassInWibble | -| classes.rb:55:1:56:3 | MyClassInGlobalScope | Class | MyClassInGlobalScope | -| modules.rb:6:5:7:7 | ClassInFooBar | Class | ClassInFooBar | -| modules.rb:19:3:20:5 | ClassInFoo | Class | ClassInFoo | -| modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | Class | ClassInAnotherDefinitionOfFoo | -| modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | Class | ClassInAnotherDefinitionOfFooBar | +| classes.rb:3:1:4:3 | Foo | ClassDefinition | Foo | +| classes.rb:7:1:8:3 | Bar | ClassDefinition | Bar | +| classes.rb:11:1:12:3 | Baz | ClassDefinition | Baz | +| classes.rb:16:1:17:3 | MyClass | ClassDefinition | MyClass | +| classes.rb:20:1:37:3 | Wibble | ClassDefinition | Wibble | +| classes.rb:32:3:33:5 | ClassInWibble | ClassDefinition | ClassInWibble | +| classes.rb:55:1:56:3 | MyClassInGlobalScope | ClassDefinition | MyClassInGlobalScope | +| modules.rb:6:5:7:7 | ClassInFooBar | ClassDefinition | ClassInFooBar | +| modules.rb:19:3:20:5 | ClassInFoo | ClassDefinition | ClassInFoo | +| modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | ClassDefinition | ClassInAnotherDefinitionOfFoo | +| modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | ClassDefinition | ClassInAnotherDefinitionOfFooBar | classesWithNameScopeExprs | classes.rb:16:1:17:3 | MyClass | classes.rb:16:7:16:14 | MyModule | classesWithGlobalNameScopeExprs @@ -19,8 +19,8 @@ exprsInClasses | classes.rb:20:1:37:3 | Wibble | 1 | classes.rb:25:3:27:5 | method_b | Method | | classes.rb:20:1:37:3 | Wibble | 2 | classes.rb:29:3:29:20 | call to some_method_call | MethodCall | | classes.rb:20:1:37:3 | Wibble | 3 | classes.rb:30:3:30:19 | ... = ... | AssignExpr | -| classes.rb:20:1:37:3 | Wibble | 4 | classes.rb:32:3:33:5 | ClassInWibble | Class | -| classes.rb:20:1:37:3 | Wibble | 5 | classes.rb:35:3:36:5 | ModuleInWibble | Module | +| classes.rb:20:1:37:3 | Wibble | 4 | classes.rb:32:3:33:5 | ClassInWibble | ClassDefinition | +| classes.rb:20:1:37:3 | Wibble | 5 | classes.rb:35:3:36:5 | ModuleInWibble | ModuleDefinition | methodsInClasses | classes.rb:20:1:37:3 | Wibble | classes.rb:21:3:23:5 | method_a | method_a | | classes.rb:20:1:37:3 | Wibble | classes.rb:25:3:27:5 | method_b | method_b | diff --git a/ql/test/library-tests/ast/modules/classes.ql b/ql/test/library-tests/ast/modules/classes.ql index 52d6ed21e51..ce347830b06 100644 --- a/ql/test/library-tests/ast/modules/classes.ql +++ b/ql/test/library-tests/ast/modules/classes.ql @@ -1,21 +1,27 @@ import ruby -query predicate classes(Class c, string pClass, string name) { +query predicate classes(ClassDefinition c, string pClass, string name) { pClass = c.getAPrimaryQlClass() and name = c.getName() } -query predicate classesWithNameScopeExprs(Class c, Expr se) { se = c.getScopeExpr() } +query predicate classesWithNameScopeExprs(ClassDefinition c, Expr se) { se = c.getScopeExpr() } -query predicate classesWithGlobalNameScopeExprs(Class c) { c.hasGlobalScope() } +query predicate classesWithGlobalNameScopeExprs(ClassDefinition c) { c.hasGlobalScope() } -query predicate exprsInClasses(Class c, int i, Expr e, string eClass) { +query predicate exprsInClasses(ClassDefinition c, int i, Expr e, string eClass) { e = c.getStmt(i) and eClass = e.getAPrimaryQlClass() } -query predicate methodsInClasses(Class c, Method m, string name) { m = c.getMethod(name) } +query predicate methodsInClasses(ClassDefinition c, Method m, string name) { m = c.getMethod(name) } -query predicate classesInClasses(Class c, Class child, string name) { child = c.getClass(name) } +query predicate classesInClasses(ClassDefinition c, ClassDefinition child, string name) { + child = c.getClass(name) +} -query predicate modulesInClasses(Class c, Module m, string name) { m = c.getModule(name) } +query predicate modulesInClasses(ClassDefinition c, ModuleDefinition m, string name) { + m = c.getModule(name) +} -query predicate classesWithASuperclass(Class c, Expr scExpr) { scExpr = c.getSuperclassExpr() } +query predicate classesWithASuperclass(ClassDefinition c, Expr scExpr) { + scExpr = c.getSuperclassExpr() +} diff --git a/ql/test/library-tests/ast/modules/module_base.expected b/ql/test/library-tests/ast/modules/module_base.expected index 1e26e369d5f..99d40f49e22 100644 --- a/ql/test/library-tests/ast/modules/module_base.expected +++ b/ql/test/library-tests/ast/modules/module_base.expected @@ -1,27 +1,27 @@ moduleBases | classes.rb:2:1:56:3 | classes.rb | Toplevel | -| classes.rb:3:1:4:3 | Foo | Class | -| classes.rb:7:1:8:3 | Bar | Class | -| classes.rb:11:1:12:3 | Baz | Class | -| classes.rb:15:1:15:20 | MyModule | Module | -| classes.rb:16:1:17:3 | MyClass | Class | -| classes.rb:20:1:37:3 | Wibble | Class | -| classes.rb:32:3:33:5 | ClassInWibble | Class | -| classes.rb:35:3:36:5 | ModuleInWibble | Module | -| classes.rb:41:1:52:3 | class << ... | Class | -| classes.rb:55:1:56:3 | MyClassInGlobalScope | Class | -| modules.rb:1:1:2:3 | Empty | Module | +| classes.rb:3:1:4:3 | Foo | ClassDefinition | +| classes.rb:7:1:8:3 | Bar | ClassDefinition | +| classes.rb:11:1:12:3 | Baz | ClassDefinition | +| classes.rb:15:1:15:20 | MyModule | ModuleDefinition | +| classes.rb:16:1:17:3 | MyClass | ClassDefinition | +| classes.rb:20:1:37:3 | Wibble | ClassDefinition | +| classes.rb:32:3:33:5 | ClassInWibble | ClassDefinition | +| classes.rb:35:3:36:5 | ModuleInWibble | ModuleDefinition | +| classes.rb:41:1:52:3 | class << ... | ClassDefinition | +| classes.rb:55:1:56:3 | MyClassInGlobalScope | ClassDefinition | +| modules.rb:1:1:2:3 | Empty | ModuleDefinition | | modules.rb:1:1:61:3 | modules.rb | Toplevel | -| modules.rb:4:1:24:3 | Foo | Module | -| modules.rb:5:3:14:5 | Bar | Module | -| modules.rb:6:5:7:7 | ClassInFooBar | Class | -| modules.rb:19:3:20:5 | ClassInFoo | Class | -| modules.rb:26:1:35:3 | Foo | Module | -| modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | Class | -| modules.rb:37:1:46:3 | Bar | Module | -| modules.rb:48:1:57:3 | Bar | Module | -| modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | Class | -| modules.rb:60:1:61:3 | MyModuleInGlobalScope | Module | +| modules.rb:4:1:24:3 | Foo | ModuleDefinition | +| modules.rb:5:3:14:5 | Bar | ModuleDefinition | +| modules.rb:6:5:7:7 | ClassInFooBar | ClassDefinition | +| modules.rb:19:3:20:5 | ClassInFoo | ClassDefinition | +| modules.rb:26:1:35:3 | Foo | ModuleDefinition | +| modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | ClassDefinition | +| modules.rb:37:1:46:3 | Bar | ModuleDefinition | +| modules.rb:48:1:57:3 | Bar | ModuleDefinition | +| modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | ClassDefinition | +| modules.rb:60:1:61:3 | MyModuleInGlobalScope | ModuleDefinition | | toplevel.rb:1:1:5:23 | toplevel.rb | Toplevel | moduleBaseClasses | classes.rb:2:1:56:3 | classes.rb | classes.rb:3:1:4:3 | Foo | diff --git a/ql/test/library-tests/ast/modules/module_base.ql b/ql/test/library-tests/ast/modules/module_base.ql index e4e72ed1c69..4b41e4ad03b 100644 --- a/ql/test/library-tests/ast/modules/module_base.ql +++ b/ql/test/library-tests/ast/modules/module_base.ql @@ -2,8 +2,8 @@ import ruby query predicate moduleBases(ModuleBase mb, string pClass) { pClass = mb.getAPrimaryQlClass() } -query predicate moduleBaseClasses(ModuleBase mb, Class c) { c = mb.getAClass() } +query predicate moduleBaseClasses(ModuleBase mb, ClassDefinition c) { c = mb.getAClass() } query predicate moduleBaseMethods(ModuleBase mb, Method m) { m = mb.getAMethod() } -query predicate moduleBaseModules(ModuleBase mb, Module m) { m = mb.getAModule() } +query predicate moduleBaseModules(ModuleBase mb, ModuleDefinition m) { m = mb.getAModule() } diff --git a/ql/test/library-tests/ast/modules/modules.expected b/ql/test/library-tests/ast/modules/modules.expected index b21ae05c813..1cb4c50c9e7 100644 --- a/ql/test/library-tests/ast/modules/modules.expected +++ b/ql/test/library-tests/ast/modules/modules.expected @@ -1,36 +1,36 @@ modules -| classes.rb:15:1:15:20 | MyModule | Module | MyModule | -| classes.rb:35:3:36:5 | ModuleInWibble | Module | ModuleInWibble | -| modules.rb:1:1:2:3 | Empty | Module | Empty | -| modules.rb:4:1:24:3 | Foo | Module | Foo | -| modules.rb:5:3:14:5 | Bar | Module | Bar | -| modules.rb:26:1:35:3 | Foo | Module | Foo | -| modules.rb:37:1:46:3 | Bar | Module | Bar | -| modules.rb:48:1:57:3 | Bar | Module | Bar | -| modules.rb:60:1:61:3 | MyModuleInGlobalScope | Module | MyModuleInGlobalScope | +| classes.rb:15:1:15:20 | MyModule | ModuleDefinition | MyModule | +| classes.rb:35:3:36:5 | ModuleInWibble | ModuleDefinition | ModuleInWibble | +| modules.rb:1:1:2:3 | Empty | ModuleDefinition | Empty | +| modules.rb:4:1:24:3 | Foo | ModuleDefinition | Foo | +| modules.rb:5:3:14:5 | Bar | ModuleDefinition | Bar | +| modules.rb:26:1:35:3 | Foo | ModuleDefinition | Foo | +| modules.rb:37:1:46:3 | Bar | ModuleDefinition | Bar | +| modules.rb:48:1:57:3 | Bar | ModuleDefinition | Bar | +| modules.rb:60:1:61:3 | MyModuleInGlobalScope | ModuleDefinition | MyModuleInGlobalScope | modulesWithScopeExprs | modules.rb:48:1:57:3 | Bar | modules.rb:48:8:48:10 | Foo | modulesWithGlobalNameScopeExprs | modules.rb:60:1:61:3 | MyModuleInGlobalScope | exprsInModules -| modules.rb:4:1:24:3 | Foo | 0 | modules.rb:5:3:14:5 | Bar | Module | +| modules.rb:4:1:24:3 | Foo | 0 | modules.rb:5:3:14:5 | Bar | ModuleDefinition | | modules.rb:4:1:24:3 | Foo | 1 | modules.rb:16:3:17:5 | method_in_foo | Method | -| modules.rb:4:1:24:3 | Foo | 2 | modules.rb:19:3:20:5 | ClassInFoo | Class | +| modules.rb:4:1:24:3 | Foo | 2 | modules.rb:19:3:20:5 | ClassInFoo | ClassDefinition | | modules.rb:4:1:24:3 | Foo | 3 | modules.rb:22:3:22:19 | call to puts | MethodCall | | modules.rb:4:1:24:3 | Foo | 4 | modules.rb:23:3:23:17 | ... = ... | AssignExpr | -| modules.rb:5:3:14:5 | Bar | 0 | modules.rb:6:5:7:7 | ClassInFooBar | Class | +| modules.rb:5:3:14:5 | Bar | 0 | modules.rb:6:5:7:7 | ClassInFooBar | ClassDefinition | | modules.rb:5:3:14:5 | Bar | 1 | modules.rb:9:5:10:7 | method_in_foo_bar | Method | | modules.rb:5:3:14:5 | Bar | 2 | modules.rb:12:5:12:26 | call to puts | MethodCall | | modules.rb:5:3:14:5 | Bar | 3 | modules.rb:13:5:13:19 | ... = ... | AssignExpr | | modules.rb:26:1:35:3 | Foo | 0 | modules.rb:27:3:28:5 | method_in_another_definition_of_foo | Method | -| modules.rb:26:1:35:3 | Foo | 1 | modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | Class | +| modules.rb:26:1:35:3 | Foo | 1 | modules.rb:30:3:31:5 | ClassInAnotherDefinitionOfFoo | ClassDefinition | | modules.rb:26:1:35:3 | Foo | 2 | modules.rb:33:3:33:25 | call to puts | MethodCall | | modules.rb:26:1:35:3 | Foo | 3 | modules.rb:34:3:34:17 | ... = ... | AssignExpr | | modules.rb:37:1:46:3 | Bar | 0 | modules.rb:38:3:39:5 | method_a | Method | | modules.rb:37:1:46:3 | Bar | 1 | modules.rb:41:3:42:5 | method_b | Method | | modules.rb:37:1:46:3 | Bar | 2 | modules.rb:44:3:44:19 | call to puts | MethodCall | | modules.rb:37:1:46:3 | Bar | 3 | modules.rb:45:3:45:17 | ... = ... | AssignExpr | -| modules.rb:48:1:57:3 | Bar | 0 | modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | Class | +| modules.rb:48:1:57:3 | Bar | 0 | modules.rb:49:3:50:5 | ClassInAnotherDefinitionOfFooBar | ClassDefinition | | modules.rb:48:1:57:3 | Bar | 1 | modules.rb:52:3:53:5 | method_in_another_definition_of_foo_bar | Method | | modules.rb:48:1:57:3 | Bar | 2 | modules.rb:55:3:55:30 | call to puts | MethodCall | | modules.rb:48:1:57:3 | Bar | 3 | modules.rb:56:3:56:17 | ... = ... | AssignExpr | diff --git a/ql/test/library-tests/ast/modules/modules.ql b/ql/test/library-tests/ast/modules/modules.ql index cce336c8b5c..d0942303fb5 100644 --- a/ql/test/library-tests/ast/modules/modules.ql +++ b/ql/test/library-tests/ast/modules/modules.ql @@ -1,25 +1,25 @@ import ruby -query predicate modules(Module m, string pClass, string name) { +query predicate modules(ModuleDefinition m, string pClass, string name) { pClass = m.getAPrimaryQlClass() and name = m.getName() } -query predicate modulesWithScopeExprs(Module m, Expr se) { se = m.getScopeExpr() } +query predicate modulesWithScopeExprs(ModuleDefinition m, Expr se) { se = m.getScopeExpr() } -query predicate modulesWithGlobalNameScopeExprs(Module m) { m.hasGlobalScope() } +query predicate modulesWithGlobalNameScopeExprs(ModuleDefinition m) { m.hasGlobalScope() } -query predicate exprsInModules(Module m, int i, Expr e, string eClass) { +query predicate exprsInModules(ModuleDefinition m, int i, Expr e, string eClass) { e = m.getStmt(i) and eClass = e.getAPrimaryQlClass() } -query predicate methodsInModules(Module mod, Method method, string name) { +query predicate methodsInModules(ModuleDefinition mod, Method method, string name) { method = mod.getMethod(name) } -query predicate classesInModules(Module mod, Class klass, string name) { +query predicate classesInModules(ModuleDefinition mod, ClassDefinition klass, string name) { klass = mod.getClass(name) } -query predicate modulesInModules(Module mod, Module child, string name) { +query predicate modulesInModules(ModuleDefinition mod, ModuleDefinition child, string name) { child = mod.getModule(name) } diff --git a/ql/test/library-tests/ast/modules/singleton_classes.expected b/ql/test/library-tests/ast/modules/singleton_classes.expected index 845afe551e7..c5746395fba 100644 --- a/ql/test/library-tests/ast/modules/singleton_classes.expected +++ b/ql/test/library-tests/ast/modules/singleton_classes.expected @@ -1,5 +1,5 @@ singletonClasses -| classes.rb:41:1:52:3 | class << ... | Class | classes.rb:41:10:41:10 | x | +| classes.rb:41:1:52:3 | class << ... | ClassDefinition | classes.rb:41:10:41:10 | x | exprsInSingletonClasses | classes.rb:41:1:52:3 | class << ... | 0 | classes.rb:42:3:44:5 | length | Method | | classes.rb:41:1:52:3 | class << ... | 1 | classes.rb:46:3:48:5 | wibble | Method |