diff --git a/Cargo.lock b/Cargo.lock index 47f52dc3da5..4965134079c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -589,7 +589,7 @@ dependencies = [ [[package]] name = "tree-sitter-ql" version = "0.19.0" -source = "git+https://github.com/tausbn/tree-sitter-ql.git?rev=e08901378e2fd5c33f1e88bbb59716fd36f094f7#e08901378e2fd5c33f1e88bbb59716fd36f094f7" +source = "git+https://github.com/tausbn/tree-sitter-ql.git?rev=a9348d405de3b2dde0e6d7e59d476ae91516b7af#a9348d405de3b2dde0e6d7e59d476ae91516b7af" dependencies = [ "cc", "tree-sitter", diff --git a/extractor/Cargo.toml b/extractor/Cargo.toml index e19913ed4a8..292755208bb 100644 --- a/extractor/Cargo.toml +++ b/extractor/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" flate2 = "1.0" node-types = { path = "../node-types" } tree-sitter = "0.19" -tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "e08901378e2fd5c33f1e88bbb59716fd36f094f7" } +tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "a9348d405de3b2dde0e6d7e59d476ae91516b7af" } clap = "2.33" tracing = "0.1" tracing-subscriber = { version = "0.2", features = ["env-filter"] } diff --git a/generator/Cargo.toml b/generator/Cargo.toml index ce609782065..0dab1945bec 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -10,4 +10,4 @@ edition = "2018" node-types = { path = "../node-types" } tracing = "0.1" tracing-subscriber = { version = "0.2", features = ["env-filter"] } -tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "e08901378e2fd5c33f1e88bbb59716fd36f094f7" } +tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "a9348d405de3b2dde0e6d7e59d476ae91516b7af" } diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index 297fdfbbb2c..4d8da8d8ee5 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -665,7 +665,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration { /** * Gets a super-type referenced in the `extends` part of the class declaration. */ - TypeExpr getASuperType() { toGenerated(result) = cls.getChild(_) } + TypeExpr getASuperType() { toGenerated(result) in [cls.getExtends(_), cls.getInstanceof(_)] } /** Gets the type that this class is defined to be an alias of. */ TypeExpr getAliasType() { diff --git a/ql/src/codeql_ql/ast/internal/TreeSitter.qll b/ql/src/codeql_ql/ast/internal/TreeSitter.qll index 8dc39b81af0..65ce161bb52 100644 --- a/ql/src/codeql_ql/ast/internal/TreeSitter.qll +++ b/ql/src/codeql_ql/ast/internal/TreeSitter.qll @@ -389,6 +389,12 @@ module Generated { /** Gets the location of this element. */ override Location getLocation() { dataclass_def(this, _, result) } + /** Gets the node corresponding to the field `extends`. */ + AstNode getExtends(int i) { dataclass_extends(this, i, result) } + + /** Gets the node corresponding to the field `instanceof`. */ + AstNode getInstanceof(int i) { dataclass_instanceof(this, i, result) } + /** Gets the node corresponding to the field `name`. */ ClassName getName() { dataclass_def(this, result, _) } @@ -397,7 +403,10 @@ module Generated { /** Gets a field or child node of this node. */ override AstNode getAFieldOrChild() { - dataclass_def(this, result, _) or dataclass_child(this, _, result) + dataclass_extends(this, _, result) or + dataclass_instanceof(this, _, result) or + dataclass_def(this, result, _) or + dataclass_child(this, _, result) } } diff --git a/ql/src/ql.dbscheme b/ql/src/ql.dbscheme index f71976215a8..edb987475c1 100644 --- a/ql/src/ql.dbscheme +++ b/ql/src/ql.dbscheme @@ -240,7 +240,25 @@ conjunction_def( int loc: @location ref ); -@dataclass_child_type = @class_member | @type_alias_body | @type_expr | @type_union_body +@dataclass_extends_type = @reserved_word | @type_expr + +#keyset[dataclass, index] +dataclass_extends( + int dataclass: @dataclass ref, + int index: int ref, + unique int extends: @dataclass_extends_type ref +); + +@dataclass_instanceof_type = @reserved_word | @type_expr + +#keyset[dataclass, index] +dataclass_instanceof( + int dataclass: @dataclass ref, + int index: int ref, + unique int instanceof: @dataclass_instanceof_type ref +); + +@dataclass_child_type = @class_member | @type_alias_body | @type_union_body #keyset[dataclass, index] dataclass_child(