diff --git a/swift/ql/lib/codeql/swift/elements/AstNodeImpl.qll b/swift/ql/lib/codeql/swift/elements/AstNodeImpl.qll index 24cb90b2a303a..018db3e94f38f 100644 --- a/swift/ql/lib/codeql/swift/elements/AstNodeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/AstNodeImpl.qll @@ -5,80 +5,82 @@ private import codeql.swift.elements.expr.ClosureExpr private import codeql.swift.elements.Callable private import codeql.swift.generated.ParentChild -private module Cached { - private Element getEnclosingDeclStep(Element e) { - not e instanceof Decl and - result = getImmediateParent(e) - } +module Impl { + private module Cached { + private Element getEnclosingDeclStep(Element e) { + not e instanceof Decl and + result = getImmediateParent(e) + } - cached - Decl getEnclosingDecl(AstNode ast) { result = getEnclosingDeclStep*(getImmediateParent(ast)) } + cached + Decl getEnclosingDecl(AstNode ast) { result = getEnclosingDeclStep*(getImmediateParent(ast)) } - private Element getEnclosingFunctionStep(Element e) { - not e instanceof Function and - result = getEnclosingDecl(e) - } + private Element getEnclosingFunctionStep(Element e) { + not e instanceof Function and + result = getEnclosingDecl(e) + } - cached - Function getEnclosingFunction(AstNode ast) { - result = getEnclosingFunctionStep*(getEnclosingDecl(ast)) - } + cached + Function getEnclosingFunction(AstNode ast) { + result = getEnclosingFunctionStep*(getEnclosingDecl(ast)) + } - private Element getEnclosingClosureStep(Element e) { - not e instanceof Callable and - result = getImmediateParent(e) - } + private Element getEnclosingClosureStep(Element e) { + not e instanceof Callable and + result = getImmediateParent(e) + } - cached - ClosureExpr getEnclosingClosure(AstNode ast) { - result = getEnclosingClosureStep*(getImmediateParent(ast)) + cached + ClosureExpr getEnclosingClosure(AstNode ast) { + result = getEnclosingClosureStep*(getImmediateParent(ast)) + } } -} -/** - * A node in the abstract syntax tree. - */ -class AstNode extends Generated::AstNode { /** - * Gets the nearest function definition that contains this AST node, if any. - * This includes functions, methods, (de)initializers, and accessors, but not closures. - * - * For example, in the following code, the AST node for `n + 1` has `foo` as its - * enclosing function (via `getEnclosingFunction`), whereas its enclosing callable is - * the closure `{(n : Int) in n + 1 }` (via `getEnclosingCallable`): - * - * ```swift - * func foo() { - * var f = { (n : Int) in n + 1 } - * } - * ``` + * A node in the abstract syntax tree. */ - final Function getEnclosingFunction() { result = Cached::getEnclosingFunction(this) } + class AstNode extends Generated::AstNode { + /** + * Gets the nearest function definition that contains this AST node, if any. + * This includes functions, methods, (de)initializers, and accessors, but not closures. + * + * For example, in the following code, the AST node for `n + 1` has `foo` as its + * enclosing function (via `getEnclosingFunction`), whereas its enclosing callable is + * the closure `{(n : Int) in n + 1 }` (via `getEnclosingCallable`): + * + * ```swift + * func foo() { + * var f = { (n : Int) in n + 1 } + * } + * ``` + */ + final Function getEnclosingFunction() { result = Cached::getEnclosingFunction(this) } - /** - * Gets the nearest declaration that contains this AST node, if any. - * - * Note that the nearest declaration may be an extension of a type declaration. If you always - * want the type declaration and not the extension, use `getEnclosingDecl().asNominalTypeDecl()`. - */ - final Decl getEnclosingDecl() { result = Cached::getEnclosingDecl(this) } + /** + * Gets the nearest declaration that contains this AST node, if any. + * + * Note that the nearest declaration may be an extension of a type declaration. If you always + * want the type declaration and not the extension, use `getEnclosingDecl().asNominalTypeDecl()`. + */ + final Decl getEnclosingDecl() { result = Cached::getEnclosingDecl(this) } - /** - * Gets the nearest `Callable` that contains this AST node, if any. - * This includes (auto)closures, functions, methods, (de)initializers, and accessors. - * - * For example, in the following code, the AST node for `n + 1` has the closure - * `{(n : Int) in n + 1 }` as its enclosing callable. - * - * ```swift - * func foo() { - * var f = { (n : Int) in n + 1 } - * } - * ``` - */ - final Callable getEnclosingCallable() { - if exists(Cached::getEnclosingClosure(this)) - then result = Cached::getEnclosingClosure(this) - else result = Cached::getEnclosingFunction(this) + /** + * Gets the nearest `Callable` that contains this AST node, if any. + * This includes (auto)closures, functions, methods, (de)initializers, and accessors. + * + * For example, in the following code, the AST node for `n + 1` has the closure + * `{(n : Int) in n + 1 }` as its enclosing callable. + * + * ```swift + * func foo() { + * var f = { (n : Int) in n + 1 } + * } + * ``` + */ + final Callable getEnclosingCallable() { + if exists(Cached::getEnclosingClosure(this)) + then result = Cached::getEnclosingClosure(this) + else result = Cached::getEnclosingFunction(this) + } } } diff --git a/swift/ql/lib/codeql/swift/elements/AvailabilityInfoImpl.qll b/swift/ql/lib/codeql/swift/elements/AvailabilityInfoImpl.qll index 6e04261dc4f95..caa478fbc2de3 100644 --- a/swift/ql/lib/codeql/swift/elements/AvailabilityInfoImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/AvailabilityInfoImpl.qll @@ -1,25 +1,27 @@ private import codeql.swift.generated.AvailabilityInfo -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * An availability condition of an `if`, `while`, or `guard` statements. - * - * Examples: - * ``` - * if #available(iOS 12, *) { - * // Runs on iOS 12 and above - * } else { - * // Runs only anything below iOS 12 - * } - * if #unavailable(macOS 10.14, *) { - * // Runs only on macOS 10 and below - * } - * ``` - */ -class AvailabilityInfo extends Generated::AvailabilityInfo { - override string toString() { - result = "#available" and not this.isUnavailable() - or - result = "#unavailable" and this.isUnavailable() +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * An availability condition of an `if`, `while`, or `guard` statements. + * + * Examples: + * ``` + * if #available(iOS 12, *) { + * // Runs on iOS 12 and above + * } else { + * // Runs only anything below iOS 12 + * } + * if #unavailable(macOS 10.14, *) { + * // Runs only on macOS 10 and below + * } + * ``` + */ + class AvailabilityInfo extends Generated::AvailabilityInfo { + override string toString() { + result = "#available" and not this.isUnavailable() + or + result = "#unavailable" and this.isUnavailable() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/CallableImpl.qll b/swift/ql/lib/codeql/swift/elements/CallableImpl.qll index 367741ecd7c3e..7b03eaa5f6ecf 100644 --- a/swift/ql/lib/codeql/swift/elements/CallableImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/CallableImpl.qll @@ -2,18 +2,20 @@ private import codeql.swift.generated.Callable private import codeql.swift.elements.AstNode private import codeql.swift.elements.decl.Decl -class Callable extends Generated::Callable, AstNode { - /** - * Holds if this Callable is a function named `funcName`. - */ - predicate hasName(string funcName) { this.getName() = funcName } +module Impl { + class Callable extends Generated::Callable { + /** + * Holds if this Callable is a function named `funcName`. + */ + predicate hasName(string funcName) { this.getName() = funcName } - /** - * Holds if this Callable is a function named `funcName` defined in a module - * called `moduleName`. - */ - predicate hasName(string moduleName, string funcName) { - this.hasName(funcName) and - this.(Decl).getModule().getFullName() = moduleName + /** + * Holds if this Callable is a function named `funcName` defined in a module + * called `moduleName`. + */ + predicate hasName(string moduleName, string funcName) { + this.hasName(funcName) and + this.(Decl).getModule().getFullName() = moduleName + } } } diff --git a/swift/ql/lib/codeql/swift/elements/CommentImpl.qll b/swift/ql/lib/codeql/swift/elements/CommentImpl.qll index b6dd7cd45458d..142cb03689a88 100644 --- a/swift/ql/lib/codeql/swift/elements/CommentImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/CommentImpl.qll @@ -1,35 +1,37 @@ private import codeql.swift.generated.Comment -class Comment extends Generated::Comment { - /** toString */ - override string toString() { result = this.getText() } -} +module Impl { + class Comment extends Generated::Comment { + /** toString */ + override string toString() { result = this.getText() } + } -class SingleLineComment extends Comment { - SingleLineComment() { - this.getText().matches("//%") and - not this instanceof SingleLineDocComment + class SingleLineComment extends Comment { + SingleLineComment() { + this.getText().matches("//%") and + not this instanceof SingleLineDocComment + } } -} -class MultiLineComment extends Comment { - MultiLineComment() { - this.getText().matches("/*%") and - not this instanceof MultiLineDocComment + class MultiLineComment extends Comment { + MultiLineComment() { + this.getText().matches("/*%") and + not this instanceof MultiLineDocComment + } } -} -class DocComment extends Comment { - DocComment() { - this instanceof SingleLineDocComment or - this instanceof MultiLineDocComment + class DocComment extends Comment { + DocComment() { + this instanceof SingleLineDocComment or + this instanceof MultiLineDocComment + } } -} -class SingleLineDocComment extends Comment { - SingleLineDocComment() { this.getText().matches("///%") } -} + class SingleLineDocComment extends Comment { + SingleLineDocComment() { this.getText().matches("///%") } + } -class MultiLineDocComment extends Comment { - MultiLineDocComment() { this.getText().matches("/**%") } + class MultiLineDocComment extends Comment { + MultiLineDocComment() { this.getText().matches("/**%") } + } } diff --git a/swift/ql/lib/codeql/swift/elements/DiagnosticsImpl.qll b/swift/ql/lib/codeql/swift/elements/DiagnosticsImpl.qll index a0ec9995355b6..3e5b3a77ca52d 100644 --- a/swift/ql/lib/codeql/swift/elements/DiagnosticsImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/DiagnosticsImpl.qll @@ -1,49 +1,51 @@ private import codeql.swift.generated.Diagnostics -/** - * A compiler-generated error, warning, note or remark. - */ -class Diagnostics extends Generated::Diagnostics { - override string toString() { result = this.getSeverity() + ": " + this.getText() } - +module Impl { /** - * Gets a string representing the severity of this compiler diagnostic. + * A compiler-generated error, warning, note or remark. */ - string getSeverity() { - this.getKind() = 1 and result = "error" - or - this.getKind() = 2 and result = "warning" - or - this.getKind() = 3 and result = "note" - or - this.getKind() = 4 and result = "remark" + class Diagnostics extends Generated::Diagnostics { + override string toString() { result = this.getSeverity() + ": " + this.getText() } + + /** + * Gets a string representing the severity of this compiler diagnostic. + */ + string getSeverity() { + this.getKind() = 1 and result = "error" + or + this.getKind() = 2 and result = "warning" + or + this.getKind() = 3 and result = "note" + or + this.getKind() = 4 and result = "remark" + } } -} -/** - * A compiler error message. - */ -class CompilerError extends Diagnostics { - CompilerError() { this.getSeverity() = "error" } -} + /** + * A compiler error message. + */ + class CompilerError extends Diagnostics { + CompilerError() { this.getSeverity() = "error" } + } -/** - * A compiler-generated warning. - */ -class CompilerWarning extends Diagnostics { - CompilerWarning() { this.getSeverity() = "warning" } -} + /** + * A compiler-generated warning. + */ + class CompilerWarning extends Diagnostics { + CompilerWarning() { this.getSeverity() = "warning" } + } -/** - * A compiler-generated note (typically attached to an error or warning). - */ -class CompilerNote extends Diagnostics { - CompilerNote() { this.getSeverity() = "note" } -} + /** + * A compiler-generated note (typically attached to an error or warning). + */ + class CompilerNote extends Diagnostics { + CompilerNote() { this.getSeverity() = "note" } + } -/** - * A compiler-generated remark (milder than a warning, this does not indicate an issue). - */ -class CompilerRemark extends Diagnostics { - CompilerRemark() { this.getSeverity() = "remark" } + /** + * A compiler-generated remark (milder than a warning, this does not indicate an issue). + */ + class CompilerRemark extends Diagnostics { + CompilerRemark() { this.getSeverity() = "remark" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/ElementImpl.qll b/swift/ql/lib/codeql/swift/elements/ElementImpl.qll index 394d1caab3b22..882e7eda383c0 100644 --- a/swift/ql/lib/codeql/swift/elements/ElementImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/ElementImpl.qll @@ -1,20 +1,22 @@ private import codeql.swift.generated.Element -class Element extends Generated::Element { - private predicate resolvesFrom(Element e) { e.getResolveStep() = this } +module Impl { + class Element extends Generated::Element { + private predicate resolvesFrom(Element e) { e.getResolveStep() = this } - override string toString() { result = this.getPrimaryQlClasses() } + override string toString() { result = this.getPrimaryQlClasses() } - Element getFullyUnresolved() { - not this.resolvesFrom(_) and result = this - or - exists(Element e | - this.resolvesFrom(e) and - result = e.getFullyUnresolved() - ) + Element getFullyUnresolved() { + not this.resolvesFrom(_) and result = this + or + exists(Element e | + this.resolvesFrom(e) and + result = e.getFullyUnresolved() + ) + } } -} -class UnknownElement extends Element { - UnknownElement() { this.isUnknown() } + class UnknownElement extends Element { + UnknownElement() { this.isUnknown() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/FileImpl.qll b/swift/ql/lib/codeql/swift/elements/FileImpl.qll index 823430ee7ee90..2aac757e248ef 100644 --- a/swift/ql/lib/codeql/swift/elements/FileImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/FileImpl.qll @@ -2,106 +2,110 @@ private import codeql.swift.generated.File private import codeql.swift.elements.Location private import codeql.swift.elements.UnknownLocation -class File extends Generated::File { - /** toString */ - override string toString() { result = this.getAbsolutePath() } +module Impl { + class File extends Generated::File { + /** toString */ + override string toString() { result = this.getAbsolutePath() } - /** Gets the absolute path of this file. */ - string getAbsolutePath() { result = this.getName() } + /** Gets the absolute path of this file. */ + string getAbsolutePath() { result = this.getName() } - /** Gets the full name of this file. */ - string getFullName() { result = this.getAbsolutePath() } + /** Gets the full name of this file. */ + string getFullName() { result = this.getAbsolutePath() } - /** Gets the URL of this file. */ - string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" } + /** Gets the URL of this file. */ + string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" } - /** - * Holds if either, - * - `part` is the base name of this container and `i = 1`, or - * - `part` is the stem of this container and `i = 2`, or - * - `part` is the extension of this container and `i = 3`. - */ - cached - private predicate splitAbsolutePath(string part, int i) { - part = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", i) - } + /** + * Holds if either, + * - `part` is the base name of this container and `i = 1`, or + * - `part` is the stem of this container and `i = 2`, or + * - `part` is the extension of this container and `i = 3`. + */ + cached + private predicate splitAbsolutePath(string part, int i) { + part = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", i) + } - /** Gets the base name of this file. */ - string getBaseName() { this.splitAbsolutePath(result, 1) } + /** Gets the base name of this file. */ + string getBaseName() { this.splitAbsolutePath(result, 1) } - /** - * Gets the extension of this container, that is, the suffix of its base name - * after the last dot character, if any. - * - * In particular, - * - * - if the name does not include a dot, there is no extension, so this - * predicate has no result; - * - if the name ends in a dot, the extension is the empty string; - * - if the name contains multiple dots, the extension follows the last dot. - * - * Here are some examples of absolute paths and the corresponding extensions - * (surrounded with quotes to avoid ambiguity): - * - * - * - * - * - * - * - * - *
Absolute pathExtension
"/tmp/tst.txt""txt"
"/tmp/.classpath""classpath"
"/bin/bash"not defined
"/tmp/tst2."""
"/tmp/x.tar.gz""gz"
- */ - string getExtension() { this.splitAbsolutePath(result, 3) } + /** + * Gets the extension of this container, that is, the suffix of its base name + * after the last dot character, if any. + * + * In particular, + * + * - if the name does not include a dot, there is no extension, so this + * predicate has no result; + * - if the name ends in a dot, the extension is the empty string; + * - if the name contains multiple dots, the extension follows the last dot. + * + * Here are some examples of absolute paths and the corresponding extensions + * (surrounded with quotes to avoid ambiguity): + * + * + * + * + * + * + * + * + *
Absolute pathExtension
"/tmp/tst.txt""txt"
"/tmp/.classpath""classpath"
"/bin/bash"not defined
"/tmp/tst2."""
"/tmp/x.tar.gz""gz"
+ */ + string getExtension() { this.splitAbsolutePath(result, 3) } - /** - * Gets the stem of this container, that is, the prefix of its base name up to - * (but not including) the last dot character if there is one, or the entire - * base name if there is not. - * - * Here are some examples of absolute paths and the corresponding stems - * (surrounded with quotes to avoid ambiguity): - * - * - * - * - * - * - * - * - *
Absolute pathStem
"/tmp/tst.txt""tst"
"/tmp/.classpath"""
"/bin/bash""bash"
"/tmp/tst2.""tst2"
"/tmp/x.tar.gz""x.tar"
- */ - string getStem() { this.splitAbsolutePath(result, 2) } + /** + * Gets the stem of this container, that is, the prefix of its base name up to + * (but not including) the last dot character if there is one, or the entire + * base name if there is not. + * + * Here are some examples of absolute paths and the corresponding stems + * (surrounded with quotes to avoid ambiguity): + * + * + * + * + * + * + * + * + *
Absolute pathStem
"/tmp/tst.txt""tst"
"/tmp/.classpath"""
"/bin/bash""bash"
"/tmp/tst2.""tst2"
"/tmp/x.tar.gz""x.tar"
+ */ + string getStem() { this.splitAbsolutePath(result, 2) } - /** - * Gets the number of lines containing code in this file. This value - * is approximate. - */ - int getNumberOfLinesOfCode() { - result = - count(int line | - exists(Location loc | - not loc instanceof UnknownLocation and loc.getFile() = this and loc.getStartLine() = line + /** + * Gets the number of lines containing code in this file. This value + * is approximate. + */ + int getNumberOfLinesOfCode() { + result = + count(int line | + exists(Location loc | + not loc instanceof UnknownLocation and + loc.getFile() = this and + loc.getStartLine() = line + ) ) - ) - } + } - /** - * Gets the relative path of this file from the root folder of the - * analyzed source location. The relative path of the root folder itself - * would be the empty string. - * - * This has no result if the file is outside the source root, that is, - * if the root folder is not a reflexive, transitive parent of this file. - */ - string getRelativePath() { - exists(string absPath, string pref | - absPath = this.getAbsolutePath() and sourceLocationPrefix(pref) - | - absPath = pref and result = "" - or - absPath = pref.regexpReplaceAll("/$", "") + "/" + result and - not result.matches("/%") - ) + /** + * Gets the relative path of this file from the root folder of the + * analyzed source location. The relative path of the root folder itself + * would be the empty string. + * + * This has no result if the file is outside the source root, that is, + * if the root folder is not a reflexive, transitive parent of this file. + */ + string getRelativePath() { + exists(string absPath, string pref | + absPath = this.getAbsolutePath() and sourceLocationPrefix(pref) + | + absPath = pref and result = "" + or + absPath = pref.regexpReplaceAll("/$", "") + "/" + result and + not result.matches("/%") + ) + } } } diff --git a/swift/ql/lib/codeql/swift/elements/KeyPathComponentImpl.qll b/swift/ql/lib/codeql/swift/elements/KeyPathComponentImpl.qll index cc5fd523dee57..be837022a7c36 100644 --- a/swift/ql/lib/codeql/swift/elements/KeyPathComponentImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/KeyPathComponentImpl.qll @@ -1,62 +1,64 @@ private import codeql.swift.generated.KeyPathComponent private import swift -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A component of a `KeyPathExpr`. - */ -class KeyPathComponent extends Generated::KeyPathComponent { +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file /** - * Property access like `.bar` in `\Foo.bar`. + * A component of a `KeyPathExpr`. */ - predicate isProperty() { this.getKind() = 3 } + class KeyPathComponent extends Generated::KeyPathComponent { + /** + * Property access like `.bar` in `\Foo.bar`. + */ + predicate isProperty() { this.getKind() = 3 } - /** - * Array or dictionary subscript like `[1]` or `["a", "b"]`. - */ - predicate isSubscript() { this.getKind() = 4 } + /** + * Array or dictionary subscript like `[1]` or `["a", "b"]`. + */ + predicate isSubscript() { this.getKind() = 4 } - /** - * Optional forcing `!`. - */ - predicate isOptionalForcing() { this.getKind() = 5 } + /** + * Optional forcing `!`. + */ + predicate isOptionalForcing() { this.getKind() = 5 } - /** - * Optional chaining `?`. - */ - predicate isOptionalChaining() { this.getKind() = 6 } + /** + * Optional chaining `?`. + */ + predicate isOptionalChaining() { this.getKind() = 6 } - /** - * Implicit optional wrapping component inserted by the compiler when an optional chain ends in a non-optional value. - */ - predicate isOptionalWrapping() { this.getKind() = 7 } + /** + * Implicit optional wrapping component inserted by the compiler when an optional chain ends in a non-optional value. + */ + predicate isOptionalWrapping() { this.getKind() = 7 } - /** - * Reference to the entire object; the `self` in `\Foo.self`. - */ - predicate isSelf() { this.getKind() = 8 } + /** + * Reference to the entire object; the `self` in `\Foo.self`. + */ + predicate isSelf() { this.getKind() = 8 } - /** - * Tuple indexing like `.1`. - */ - predicate isTupleIndexing() { this.getKind() = 9 } + /** + * Tuple indexing like `.1`. + */ + predicate isTupleIndexing() { this.getKind() = 9 } - /** Gets the underlying key-path expression which this is a component of. */ - KeyPathExpr getKeyPathExpr() { result.getAComponent() = this } + /** Gets the underlying key-path expression which this is a component of. */ + KeyPathExpr getKeyPathExpr() { result.getAComponent() = this } - /** Holds if this component is the i'th component of the underling key-path expression. */ - predicate hasIndex(int i) { any(KeyPathExpr e).getComponent(i) = this } + /** Holds if this component is the i'th component of the underling key-path expression. */ + predicate hasIndex(int i) { any(KeyPathExpr e).getComponent(i) = this } - /** Gets the next component of the underlying key-path expression. */ - KeyPathComponent getNextComponent() { - exists(int i, KeyPathExpr e | - hasKeyPathExprAndIndex(e, i, this) and - hasKeyPathExprAndIndex(e, i + 1, result) - ) + /** Gets the next component of the underlying key-path expression. */ + KeyPathComponent getNextComponent() { + exists(int i, KeyPathExpr e | + hasKeyPathExprAndIndex(e, i, this) and + hasKeyPathExprAndIndex(e, i + 1, result) + ) + } } -} -pragma[nomagic] -private predicate hasKeyPathExprAndIndex(KeyPathExpr e, int i, KeyPathComponent c) { - e.getComponent(i) = c + pragma[nomagic] + private predicate hasKeyPathExprAndIndex(KeyPathExpr e, int i, KeyPathComponent c) { + e.getComponent(i) = c + } } diff --git a/swift/ql/lib/codeql/swift/elements/LocatableImpl.qll b/swift/ql/lib/codeql/swift/elements/LocatableImpl.qll index 25877d7f07471..6c23fe7ba85f0 100644 --- a/swift/ql/lib/codeql/swift/elements/LocatableImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/LocatableImpl.qll @@ -2,17 +2,19 @@ private import codeql.swift.generated.Locatable private import codeql.swift.elements.File private import codeql.swift.elements.UnknownLocation -class Locatable extends Generated::Locatable { - pragma[nomagic] - override Location getLocation() { - result = Generated::Locatable.super.getLocation() - or - not exists(Generated::Locatable.super.getLocation()) and - result instanceof UnknownLocation - } +module Impl { + class Locatable extends Generated::Locatable { + pragma[nomagic] + override Location getLocation() { + result = Generated::Locatable.super.getLocation() + or + not exists(Generated::Locatable.super.getLocation()) and + result instanceof UnknownLocation + } - /** - * Gets the primary file where this element occurs. - */ - File getFile() { result = this.getLocation().getFile() } + /** + * Gets the primary file where this element occurs. + */ + File getFile() { result = this.getLocation().getFile() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/LocationImpl.qll b/swift/ql/lib/codeql/swift/elements/LocationImpl.qll index 6d4f3138a17aa..acb7e788e87d5 100644 --- a/swift/ql/lib/codeql/swift/elements/LocationImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/LocationImpl.qll @@ -1,28 +1,32 @@ private import codeql.swift.generated.Location -/** - * A location of a program element. - */ -class Location extends Generated::Location { +module Impl { /** - * Holds if this location is described by `path`, `startLine`, `startColumn`, `endLine` and `endColumn`. + * A location of a program element. */ - predicate hasLocationInfo(string path, int startLine, int startColumn, int endLine, int endColumn) { - path = this.getFile().getFullName() and - startLine = this.getStartLine() and - startColumn = this.getStartColumn() and - endLine = this.getEndLine() and - endColumn = this.getEndColumn() - } + class Location extends Generated::Location { + /** + * Holds if this location is described by `path`, `startLine`, `startColumn`, `endLine` and `endColumn`. + */ + predicate hasLocationInfo( + string path, int startLine, int startColumn, int endLine, int endColumn + ) { + path = this.getFile().getFullName() and + startLine = this.getStartLine() and + startColumn = this.getStartColumn() and + endLine = this.getEndLine() and + endColumn = this.getEndColumn() + } - /** - * Gets a textual representation of this location. - */ - override string toString() { - exists(string filePath, int startLine, int startColumn, int endLine, int endColumn | - this.hasLocationInfo(filePath, startLine, startColumn, endLine, endColumn) - | - toUrl(filePath, startLine, startColumn, endLine, endColumn, result) - ) + /** + * Gets a textual representation of this location. + */ + override string toString() { + exists(string filePath, int startLine, int startColumn, int endLine, int endColumn | + this.hasLocationInfo(filePath, startLine, startColumn, endLine, endColumn) + | + toUrl(filePath, startLine, startColumn, endLine, endColumn, result) + ) + } } } diff --git a/swift/ql/lib/codeql/swift/elements/MacroRoleImpl.qll b/swift/ql/lib/codeql/swift/elements/MacroRoleImpl.qll index 969a3329702f7..8ba4f5ff484b3 100644 --- a/swift/ql/lib/codeql/swift/elements/MacroRoleImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/MacroRoleImpl.qll @@ -4,97 +4,101 @@ private import codeql.swift.generated.MacroRole -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * The role of a macro, for example #freestanding(declaration) or @attached(member). - */ -class MacroRole extends Generated::MacroRole { +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file /** - * String representation of the role kind. + * The role of a macro, for example #freestanding(declaration) or @attached(member). */ - string getKindName() { - this.isExpressionKind() and result = "expression" - or - this.isDeclarationKind() and result = "declaration" - or - this.isAccessorKind() and result = "accessor" - or - this.isMemberAttributeKind() and result = "memberAttribute" - or - this.isMemberKind() and result = "member" - or - this.isPeerKind() and result = "peer" - or - this.isConformanceKind() and result = "conformance" - or - this.isCodeItemKind() and result = "codeItem" - or - this.isExtensionKind() and result = "extension" - } + class MacroRole extends Generated::MacroRole { + /** + * String representation of the role kind. + */ + string getKindName() { + this.isExpressionKind() and result = "expression" + or + this.isDeclarationKind() and result = "declaration" + or + this.isAccessorKind() and result = "accessor" + or + this.isMemberAttributeKind() and result = "memberAttribute" + or + this.isMemberKind() and result = "member" + or + this.isPeerKind() and result = "peer" + or + this.isConformanceKind() and result = "conformance" + or + this.isCodeItemKind() and result = "codeItem" + or + this.isExtensionKind() and result = "extension" + } - /** - * Holds for `expression` roles. - */ - predicate isExpressionKind() { this.getKind() = 1 } + /** + * Holds for `expression` roles. + */ + predicate isExpressionKind() { this.getKind() = 1 } - /** - * Holds for `declaration` roles. - */ - predicate isDeclarationKind() { this.getKind() = 2 } + /** + * Holds for `declaration` roles. + */ + predicate isDeclarationKind() { this.getKind() = 2 } - /** - * Holds for `accessor` roles. - */ - predicate isAccessorKind() { this.getKind() = 4 } + /** + * Holds for `accessor` roles. + */ + predicate isAccessorKind() { this.getKind() = 4 } - /** - * Holds for `memberAttribute` roles. - */ - predicate isMemberAttributeKind() { this.getKind() = 8 } + /** + * Holds for `memberAttribute` roles. + */ + predicate isMemberAttributeKind() { this.getKind() = 8 } - /** - * Holds for `member` roles. - */ - predicate isMemberKind() { this.getKind() = 16 } + /** + * Holds for `member` roles. + */ + predicate isMemberKind() { this.getKind() = 16 } - /** - * Holds for `peer` roles. - */ - predicate isPeerKind() { this.getKind() = 32 } + /** + * Holds for `peer` roles. + */ + predicate isPeerKind() { this.getKind() = 32 } - /** - * Holds for `conformance` roles. - */ - predicate isConformanceKind() { this.getKind() = 64 } + /** + * Holds for `conformance` roles. + */ + predicate isConformanceKind() { this.getKind() = 64 } - /** - * Holds for `codeItem` roles. - */ - predicate isCodeItemKind() { this.getKind() = 128 } + /** + * Holds for `codeItem` roles. + */ + predicate isCodeItemKind() { this.getKind() = 128 } - /** - * Holds for `extension` roles. - */ - predicate isExtensionKind() { this.getKind() = 256 } + /** + * Holds for `extension` roles. + */ + predicate isExtensionKind() { this.getKind() = 256 } - /** - * String representation of the macro syntax. - */ - string getMacroSyntaxName() { - this.isFreestandingMacroSyntax() and result = "#freestanding" - or - this.isAttachedMacroSyntax() and result = "@attached" - } + /** + * String representation of the macro syntax. + */ + string getMacroSyntaxName() { + this.isFreestandingMacroSyntax() and result = "#freestanding" + or + this.isAttachedMacroSyntax() and result = "@attached" + } - /** - * Holds for #freestanding macros. - */ - predicate isFreestandingMacroSyntax() { this.getMacroSyntax() = 0 } + /** + * Holds for #freestanding macros. + */ + predicate isFreestandingMacroSyntax() { this.getMacroSyntax() = 0 } - /** - * Holds for @attached macros. - */ - predicate isAttachedMacroSyntax() { this.getMacroSyntax() = 1 } + /** + * Holds for @attached macros. + */ + predicate isAttachedMacroSyntax() { this.getMacroSyntax() = 1 } - override string toString() { result = this.getMacroSyntaxName() + "(" + this.getKindName() + ")" } + override string toString() { + result = this.getMacroSyntaxName() + "(" + this.getKindName() + ")" + } + } } diff --git a/swift/ql/lib/codeql/swift/elements/OtherAvailabilitySpecImpl.qll b/swift/ql/lib/codeql/swift/elements/OtherAvailabilitySpecImpl.qll index bd36adab002f7..84135e66a264d 100644 --- a/swift/ql/lib/codeql/swift/elements/OtherAvailabilitySpecImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/OtherAvailabilitySpecImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.OtherAvailabilitySpec -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A wildcard availability spec `*` - */ -class OtherAvailabilitySpec extends Generated::OtherAvailabilitySpec { - override string toString() { result = "*" } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * A wildcard availability spec `*` + */ + class OtherAvailabilitySpec extends Generated::OtherAvailabilitySpec { + override string toString() { result = "*" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/PlatformVersionAvailabilitySpecImpl.qll b/swift/ql/lib/codeql/swift/elements/PlatformVersionAvailabilitySpecImpl.qll index b66212353135e..5d17697b7fb85 100644 --- a/swift/ql/lib/codeql/swift/elements/PlatformVersionAvailabilitySpecImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/PlatformVersionAvailabilitySpecImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.PlatformVersionAvailabilitySpec -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * An availability spec based on platform and version, for example `macOS 12` or `watchOS 14` - */ -class PlatformVersionAvailabilitySpec extends Generated::PlatformVersionAvailabilitySpec { - override string toString() { result = this.getPlatform() + " " + this.getVersion() } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * An availability spec based on platform and version, for example `macOS 12` or `watchOS 14` + */ + class PlatformVersionAvailabilitySpec extends Generated::PlatformVersionAvailabilitySpec { + override string toString() { result = this.getPlatform() + " " + this.getVersion() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/UnknownFileImpl.qll b/swift/ql/lib/codeql/swift/elements/UnknownFileImpl.qll index 796c29de6ac5e..79e070bbee0cc 100644 --- a/swift/ql/lib/codeql/swift/elements/UnknownFileImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/UnknownFileImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.UnknownFile -class UnknownFile extends Generated::UnknownFile { - override string getName() { result = "" } +module Impl { + class UnknownFile extends Generated::UnknownFile { + override string getName() { result = "" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/UnknownLocationImpl.qll b/swift/ql/lib/codeql/swift/elements/UnknownLocationImpl.qll index df8823fe02899..a39b8ed218009 100644 --- a/swift/ql/lib/codeql/swift/elements/UnknownLocationImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/UnknownLocationImpl.qll @@ -2,19 +2,21 @@ private import codeql.swift.generated.UnknownLocation private import codeql.swift.elements.UnknownFile private import codeql.swift.elements.File -/** - * A `Location` that is given to something that is not associated with any position in the source code. - */ -class UnknownLocation extends Generated::UnknownLocation { - override File getFile() { result instanceof UnknownFile } +module Impl { + /** + * A `Location` that is given to something that is not associated with any position in the source code. + */ + class UnknownLocation extends Generated::UnknownLocation { + override File getFile() { result instanceof UnknownFile } - override int getStartLine() { result = 0 } + override int getStartLine() { result = 0 } - override int getStartColumn() { result = 0 } + override int getStartColumn() { result = 0 } - override int getEndLine() { result = 0 } + override int getEndLine() { result = 0 } - override int getEndColumn() { result = 0 } + override int getEndColumn() { result = 0 } - override string toString() { result = "UnknownLocation" } + override string toString() { result = "UnknownLocation" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/UnspecifiedElementImpl.qll b/swift/ql/lib/codeql/swift/elements/UnspecifiedElementImpl.qll index b062beeb19792..e2d7c5a32d9ba 100644 --- a/swift/ql/lib/codeql/swift/elements/UnspecifiedElementImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/UnspecifiedElementImpl.qll @@ -2,22 +2,24 @@ private import codeql.swift.generated.UnspecifiedElement import codeql.swift.elements.Location import codeql.swift.elements.Locatable -class UnspecifiedElement extends Generated::UnspecifiedElement { - override string toString() { - exists(string source, string index | - ( - source = " from " + this.getParent().getPrimaryQlClasses() - or - not this.hasParent() and source = "" - ) and - ( - index = "[" + this.getIndex() + "]" - or - not this.hasIndex() and index = "" - ) and - result = "missing " + this.getProperty() + index + source - ) - } +module Impl { + class UnspecifiedElement extends Generated::UnspecifiedElement { + override string toString() { + exists(string source, string index | + ( + source = " from " + this.getParent().getPrimaryQlClasses() + or + not this.hasParent() and source = "" + ) and + ( + index = "[" + this.getIndex() + "]" + or + not this.hasIndex() and index = "" + ) and + result = "missing " + this.getProperty() + index + source + ) + } - override Location getLocation() { result = this.getParent().(Locatable).getLocation() } + override Location getLocation() { result = this.getParent().(Locatable).getLocation() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/AccessorExt.qll b/swift/ql/lib/codeql/swift/elements/decl/AccessorExt.qll new file mode 100644 index 0000000000000..19367186d8afc --- /dev/null +++ b/swift/ql/lib/codeql/swift/elements/decl/AccessorExt.qll @@ -0,0 +1,9 @@ +private import Accessor + +final class WillSetObserver extends Accessor { + WillSetObserver() { this.isWillSet() } +} + +class DidSetObserver extends Accessor { + DidSetObserver() { this.isDidSet() } +} diff --git a/swift/ql/lib/codeql/swift/elements/decl/AccessorImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/AccessorImpl.qll index 2440ff28d686c..652f349ba698c 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/AccessorImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/AccessorImpl.qll @@ -1,40 +1,35 @@ private import codeql.swift.generated.decl.Accessor +private import AccessorExt -private predicate isKnownAccessorKind(Accessor decl, string kind) { - decl.isGetter() and kind = "get" - or - decl.isSetter() and kind = "set" - or - decl.isWillSet() and kind = "willSet" - or - decl.isDidSet() and kind = "didSet" - or - decl.isRead() and kind = "_read" - or - decl.isModify() and kind = "_modify" - or - decl.isUnsafeAddress() and kind = "unsafeAddress" - or - decl.isUnsafeMutableAddress() and kind = "unsafeMutableAddress" -} - -class Accessor extends Generated::Accessor { - predicate isPropertyObserver() { - this instanceof WillSetObserver or this instanceof DidSetObserver - } - - override string toString() { - isKnownAccessorKind(this, result) +module Impl { + private predicate isKnownAccessorKind(Accessor decl, string kind) { + decl.isGetter() and kind = "get" + or + decl.isSetter() and kind = "set" + or + decl.isWillSet() and kind = "willSet" + or + decl.isDidSet() and kind = "didSet" or - not isKnownAccessorKind(this, _) and - result = super.toString() + decl.isRead() and kind = "_read" + or + decl.isModify() and kind = "_modify" + or + decl.isUnsafeAddress() and kind = "unsafeAddress" + or + decl.isUnsafeMutableAddress() and kind = "unsafeMutableAddress" } -} -class WillSetObserver extends Accessor { - WillSetObserver() { this.isWillSet() } -} + class Accessor extends Generated::Accessor { + predicate isPropertyObserver() { + this instanceof WillSetObserver or this instanceof DidSetObserver + } -class DidSetObserver extends Accessor { - DidSetObserver() { this.isDidSet() } + override string toString() { + isKnownAccessorKind(this, result) + or + not isKnownAccessorKind(this, _) and + result = super.toString() + } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/CapturedDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/CapturedDeclImpl.qll index fe9ea0ed32b50..0d07f7c6eee2e 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/CapturedDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/CapturedDeclImpl.qll @@ -2,22 +2,24 @@ private import codeql.swift.generated.decl.CapturedDecl private import codeql.swift.elements.Callable private import codeql.swift.elements.expr.DeclRefExpr -/** - * A captured variable or function parameter in the scope of a closure. - */ -class CapturedDecl extends Generated::CapturedDecl { - override string toString() { result = this.getDecl().toString() } - +module Impl { /** - * Gets the closure or function that captures this variable. + * A captured variable or function parameter in the scope of a closure. */ - Callable getScope() { result.getACapture() = this } + class CapturedDecl extends Generated::CapturedDecl { + override string toString() { result = this.getDecl().toString() } - /** - * Get an access to this capture within the scope of its closure. - */ - DeclRefExpr getAnAccess() { - result.getEnclosingCallable() = this.getScope() and - result.getDecl() = this.getDecl() + /** + * Gets the closure or function that captures this variable. + */ + Callable getScope() { result.getACapture() = this } + + /** + * Get an access to this capture within the scope of its closure. + */ + DeclRefExpr getAnAccess() { + result.getEnclosingCallable() = this.getScope() and + result.getDecl() = this.getDecl() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/DeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/DeclImpl.qll index c1a8d3fdf8172..eb05a3b25b5ef 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/DeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/DeclImpl.qll @@ -2,21 +2,23 @@ private import codeql.swift.generated.decl.Decl private import codeql.swift.elements.decl.NominalTypeDecl private import codeql.swift.elements.decl.ExtensionDecl -class Decl extends Generated::Decl { - override string toString() { result = super.toString() } +module Impl { + class Decl extends Generated::Decl { + override string toString() { result = super.toString() } - /** - * Gets the `NominalTypeDecl` corresponding to this `Decl`, if any. This - * resolves an `ExtensionDecl` to the `NominalTypeDecl` that it extends. - */ - NominalTypeDecl asNominalTypeDecl() { - result = this - or - result = this.(ExtensionDecl).getExtendedTypeDecl() - } + /** + * Gets the `NominalTypeDecl` corresponding to this `Decl`, if any. This + * resolves an `ExtensionDecl` to the `NominalTypeDecl` that it extends. + */ + NominalTypeDecl asNominalTypeDecl() { + result = this + or + result = this.(ExtensionDecl).getExtendedTypeDecl() + } - /** - * Gets the declaration that declares this declaration as a member, if any. - */ - Decl getDeclaringDecl() { this = result.getAMember() } + /** + * Gets the declaration that declares this declaration as a member, if any. + */ + Decl getDeclaringDecl() { this = result.getAMember() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/DeinitializerImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/DeinitializerImpl.qll index 7e16de32d26dc..c46bb3867d279 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/DeinitializerImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/DeinitializerImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.decl.Deinitializer private import codeql.swift.elements.decl.Method -/** - * A deinitializer of a class. - */ -class Deinitializer extends Generated::Deinitializer, Method { - override string toString() { result = this.getSelfParam().getType() + "." + super.toString() } +module Impl { + /** + * A deinitializer of a class. + */ + class Deinitializer extends Generated::Deinitializer { + override string toString() { result = this.getSelfParam().getType() + "." + super.toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/EnumCaseDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/EnumCaseDeclImpl.qll index 4533adf2d85b4..8e2ea03a70d60 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/EnumCaseDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/EnumCaseDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.EnumCaseDecl -class EnumCaseDecl extends Generated::EnumCaseDecl { - override string toString() { result = "case ..." } +module Impl { + class EnumCaseDecl extends Generated::EnumCaseDecl { + override string toString() { result = "case ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/EnumDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/EnumDeclImpl.qll index 91f597c8d384d..9eff4077f933d 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/EnumDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/EnumDeclImpl.qll @@ -3,34 +3,36 @@ private import codeql.swift.elements.decl.EnumCaseDecl private import codeql.swift.elements.decl.EnumElementDecl private import codeql.swift.elements.decl.Decl -/** - * An enumeration declaration, for example: - * ``` - * enum MyColours { - * case red - * case green - * case blue - * } - * ``` - */ -class EnumDecl extends Generated::EnumDecl { +module Impl { /** - * Gets the `index`th enumeration element of this enumeration (0-based). + * An enumeration declaration, for example: + * ``` + * enum MyColours { + * case red + * case green + * case blue + * } + * ``` */ - final EnumElementDecl getEnumElement(int index) { - result = - rank[index + 1](int memberIndex, Decl d | - d = this.getMember(memberIndex) and - d instanceof EnumElementDecl - | - d order by memberIndex - ) - } + class EnumDecl extends Generated::EnumDecl { + /** + * Gets the `index`th enumeration element of this enumeration (0-based). + */ + final EnumElementDecl getEnumElement(int index) { + result = + rank[index + 1](int memberIndex, Decl d | + d = this.getMember(memberIndex) and + d instanceof EnumElementDecl + | + d order by memberIndex + ) + } - /** - * Gets an enumeration element of this enumeration. - */ - final EnumElementDecl getAnEnumElement() { - result = this.getMember(_).(EnumCaseDecl).getElement(_) + /** + * Gets an enumeration element of this enumeration. + */ + final EnumElementDecl getAnEnumElement() { + result = this.getMember(_).(EnumCaseDecl).getElement(_) + } } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/EnumElementDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/EnumElementDeclImpl.qll index 8dfc22001629d..d2234b9a0f98e 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/EnumElementDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/EnumElementDeclImpl.qll @@ -1,37 +1,39 @@ private import codeql.swift.generated.decl.EnumElementDecl private import codeql.swift.elements.decl.EnumDecl -/** - * An enum element declaration, for example `enumElement` and `anotherEnumElement` in: - * ``` - * enum MyEnum { - * case enumElement - * case anotherEnumElement(Int) - * } - * ``` - */ -class EnumElementDecl extends Generated::EnumElementDecl { - override string toString() { result = this.getName() } - +module Impl { /** - * Holds if this enum element declaration is called `enumElementName` and is a member of an - * enum called `enumName`. + * An enum element declaration, for example `enumElement` and `anotherEnumElement` in: + * ``` + * enum MyEnum { + * case enumElement + * case anotherEnumElement(Int) + * } + * ``` */ - cached - predicate hasQualifiedName(string enumName, string enumElementName) { - this.getName() = enumElementName and - exists(EnumDecl d | - d.getFullName() = enumName and - d.getAMember() = this - ) - } + class EnumElementDecl extends Generated::EnumElementDecl { + override string toString() { result = this.getName() } - /** - * Holds if this enum element declaration is called `enumElementName` and is a member of an - * enumcalled `enumName` in a module called `moduleName`. - */ - predicate hasQualifiedName(string moduleName, string enumName, string enumElementName) { - this.hasQualifiedName(enumName, enumElementName) and - this.getModule().getFullName() = moduleName + /** + * Holds if this enum element declaration is called `enumElementName` and is a member of an + * enum called `enumName`. + */ + cached + predicate hasQualifiedName(string enumName, string enumElementName) { + this.getName() = enumElementName and + exists(EnumDecl d | + d.getFullName() = enumName and + d.getAMember() = this + ) + } + + /** + * Holds if this enum element declaration is called `enumElementName` and is a member of an + * enumcalled `enumName` in a module called `moduleName`. + */ + predicate hasQualifiedName(string moduleName, string enumName, string enumElementName) { + this.hasQualifiedName(enumName, enumElementName) and + this.getModule().getFullName() = moduleName + } } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/ExtensionDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/ExtensionDeclImpl.qll index 625229fcb13a6..1d31a99a53573 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/ExtensionDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/ExtensionDeclImpl.qll @@ -1,11 +1,13 @@ private import codeql.swift.generated.decl.ExtensionDecl -class ExtensionDecl extends Generated::ExtensionDecl { - override string toString() { - result = - "extension of " + unique(NominalTypeDecl td | td = this.getExtendedTypeDecl()).toString() - or - count(this.getExtendedTypeDecl()) != 1 and - result = "extension" +module Impl { + class ExtensionDecl extends Generated::ExtensionDecl { + override string toString() { + result = + "extension of " + unique(NominalTypeDecl td | td = this.getExtendedTypeDecl()).toString() + or + count(this.getExtendedTypeDecl()) != 1 and + result = "extension" + } } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/FunctionImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/FunctionImpl.qll index 7fc5b5b215595..054b0b81e50bb 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/FunctionImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/FunctionImpl.qll @@ -1,26 +1,28 @@ private import codeql.swift.generated.decl.Function private import codeql.swift.elements.decl.Method -/** - * A function. - */ -class Function extends Generated::Function, Callable { - override string toString() { result = this.getName() } - +module Impl { /** - * Gets the name of this function, without the argument list. For example - * a function with name `myFunction(arg:)` has short name `myFunction`. + * A function. */ - string getShortName() { - // match as many characters as possible that are not `(`. - // (`*+` is possessive matching) - result = this.getName().regexpCapture("([^(]*+).*", 1) + class Function extends Generated::Function { + override string toString() { result = this.getName() } + + /** + * Gets the name of this function, without the argument list. For example + * a function with name `myFunction(arg:)` has short name `myFunction`. + */ + string getShortName() { + // match as many characters as possible that are not `(`. + // (`*+` is possessive matching) + result = this.getName().regexpCapture("([^(]*+).*", 1) + } } -} -/** - * A free (non-member) function. - */ -class FreeFunction extends Function { - FreeFunction() { not this instanceof Method } + /** + * A free (non-member) function. + */ + class FreeFunction extends Function { + FreeFunction() { not this instanceof Method } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/IfConfigDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/IfConfigDeclImpl.qll index d5f825c31f281..395409992d5ae 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/IfConfigDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/IfConfigDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.IfConfigDecl -class IfConfigDecl extends Generated::IfConfigDecl { - override string toString() { result = "#if ..." } +module Impl { + class IfConfigDecl extends Generated::IfConfigDecl { + override string toString() { result = "#if ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/ImportDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/ImportDeclImpl.qll index 08f5820f103bc..2e0aa369bd175 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/ImportDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/ImportDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.ImportDecl -class ImportDecl extends Generated::ImportDecl { - override string toString() { result = "import ..." } +module Impl { + class ImportDecl extends Generated::ImportDecl { + override string toString() { result = "import ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/InitializerImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/InitializerImpl.qll index 2b2c903cfcb2c..3e52508cce1de 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/InitializerImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/InitializerImpl.qll @@ -3,15 +3,17 @@ private import codeql.swift.elements.decl.Method private import codeql.swift.elements.type.FunctionType private import codeql.swift.elements.type.OptionalType -/** - * An initializer of a class, struct, enum or protocol. - */ -class Initializer extends Generated::Initializer, Method { - override string toString() { result = this.getSelfParam().getType() + "." + super.toString() } +module Impl { + /** + * An initializer of a class, struct, enum or protocol. + */ + class Initializer extends Generated::Initializer { + override string toString() { result = this.getSelfParam().getType() + "." + super.toString() } - /** Holds if this initializer returns an optional type. Failable initializers are written as `init?`. */ - predicate isFailable() { - this.getInterfaceType().(FunctionType).getResult().(FunctionType).getResult() instanceof - OptionalType + /** Holds if this initializer returns an optional type. Failable initializers are written as `init?`. */ + predicate isFailable() { + this.getInterfaceType().(FunctionType).getResult().(FunctionType).getResult() instanceof + OptionalType + } } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/MissingMemberDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/MissingMemberDeclImpl.qll index a89fb9c67561e..51c9744ceea8d 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/MissingMemberDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/MissingMemberDeclImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.decl.MissingMemberDecl -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A placeholder for missing declarations that can arise on object deserialization. - */ -class MissingMemberDecl extends Generated::MissingMemberDecl { - override string toString() { result = this.getName() + " (missing)" } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * A placeholder for missing declarations that can arise on object deserialization. + */ + class MissingMemberDecl extends Generated::MissingMemberDecl { + override string toString() { result = this.getName() + " (missing)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/NominalTypeDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/NominalTypeDeclImpl.qll index 4b337322818f9..826505f0a97e2 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/NominalTypeDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/NominalTypeDeclImpl.qll @@ -1,6 +1,8 @@ private import codeql.swift.generated.decl.NominalTypeDecl -/** - * A class, struct, enum or protocol. - */ -class NominalTypeDecl extends Generated::NominalTypeDecl { } +module Impl { + /** + * A class, struct, enum or protocol. + */ + class NominalTypeDecl extends Generated::NominalTypeDecl { } +} diff --git a/swift/ql/lib/codeql/swift/elements/decl/OperatorDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/OperatorDeclImpl.qll index b5e13c9f2ac47..cee4d691c89f6 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/OperatorDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/OperatorDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.OperatorDecl -class OperatorDecl extends Generated::OperatorDecl { - override string toString() { result = this.getName() } +module Impl { + class OperatorDecl extends Generated::OperatorDecl { + override string toString() { result = this.getName() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/ParamDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/ParamDeclImpl.qll index 93b749d988102..f5fcd04f6b2b3 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/ParamDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/ParamDeclImpl.qll @@ -1,24 +1,26 @@ private import codeql.swift.generated.decl.ParamDecl private import codeql.swift.elements.Callable -class ParamDecl extends Generated::ParamDecl { - /** Gets the function which declares this parameter. */ - Callable getDeclaringFunction() { result.getAParam() = this } +module Impl { + class ParamDecl extends Generated::ParamDecl { + /** Gets the function which declares this parameter. */ + Callable getDeclaringFunction() { result.getAParam() = this } - /** - * Gets the index of this parameter in its declaring function's parameter list, - * or -1 if this is `self`. - */ - int getIndex() { exists(Callable func | func.getParam(result) = this) } -} + /** + * Gets the index of this parameter in its declaring function's parameter list, + * or -1 if this is `self`. + */ + int getIndex() { exists(Callable func | func.getParam(result) = this) } + } -/** A `self` parameter. */ -class SelfParamDecl extends ParamDecl { - Callable call; + /** A `self` parameter. */ + class SelfParamDecl extends ParamDecl { + Callable call; - SelfParamDecl() { call.getSelfParam() = this } + SelfParamDecl() { call.getSelfParam() = this } - override Callable getDeclaringFunction() { result = call } + override Callable getDeclaringFunction() { result = call } - override int getIndex() { result = -1 } + override int getIndex() { result = -1 } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/PatternBindingDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/PatternBindingDeclImpl.qll index b8b04651684d7..5cca53c3d4825 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/PatternBindingDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/PatternBindingDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.PatternBindingDecl -class PatternBindingDecl extends Generated::PatternBindingDecl { - override string toString() { result = "var ... = ..." } +module Impl { + class PatternBindingDecl extends Generated::PatternBindingDecl { + override string toString() { result = "var ... = ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/PoundDiagnosticDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/PoundDiagnosticDeclImpl.qll index ce435d3eb6277..b7e9caab00aeb 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/PoundDiagnosticDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/PoundDiagnosticDeclImpl.qll @@ -1,17 +1,19 @@ private import codeql.swift.generated.decl.PoundDiagnosticDecl -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A diagnostic directive, which is either `#error` or `#warning`. - */ -class PoundDiagnosticDecl extends Generated::PoundDiagnosticDecl { - override string toString() { - this.isError() and result = "#error(...)" - or - this.isWarning() and result = "#warning(...)" - } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * A diagnostic directive, which is either `#error` or `#warning`. + */ + class PoundDiagnosticDecl extends Generated::PoundDiagnosticDecl { + override string toString() { + this.isError() and result = "#error(...)" + or + this.isWarning() and result = "#warning(...)" + } - predicate isError() { this.getKind() = 1 } + predicate isError() { this.getKind() = 1 } - predicate isWarning() { this.getKind() = 2 } + predicate isWarning() { this.getKind() = 2 } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/PrecedenceGroupDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/PrecedenceGroupDeclImpl.qll index 3125054ea8ba0..1f85a0d563d3c 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/PrecedenceGroupDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/PrecedenceGroupDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.PrecedenceGroupDecl -class PrecedenceGroupDecl extends Generated::PrecedenceGroupDecl { - override string toString() { result = "precedencegroup ..." } +module Impl { + class PrecedenceGroupDecl extends Generated::PrecedenceGroupDecl { + override string toString() { result = "precedencegroup ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/SubscriptDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/SubscriptDeclImpl.qll index 3cb0e84498973..32a9633405446 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/SubscriptDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/SubscriptDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.SubscriptDecl -class SubscriptDecl extends Generated::SubscriptDecl { - override string toString() { result = "subscript ..." } +module Impl { + class SubscriptDecl extends Generated::SubscriptDecl { + override string toString() { result = "subscript ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/TopLevelCodeDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/TopLevelCodeDeclImpl.qll index cf421c65b39bf..f3f8e0683be25 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/TopLevelCodeDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/TopLevelCodeDeclImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.decl.TopLevelCodeDecl -class TopLevelCodeDecl extends Generated::TopLevelCodeDecl { - override string toString() { result = this.getBody().toString() } +module Impl { + class TopLevelCodeDecl extends Generated::TopLevelCodeDecl { + override string toString() { result = this.getBody().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/TypeAliasDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/TypeAliasDeclImpl.qll index 96b7dc19737b5..14b5f9c944d72 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/TypeAliasDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/TypeAliasDeclImpl.qll @@ -1,10 +1,12 @@ private import codeql.swift.generated.decl.TypeAliasDecl -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A declaration of a type alias to another type. For example: - * ``` - * typealias MyInt = Int - * ``` - */ -class TypeAliasDecl extends Generated::TypeAliasDecl { } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * A declaration of a type alias to another type. For example: + * ``` + * typealias MyInt = Int + * ``` + */ + class TypeAliasDecl extends Generated::TypeAliasDecl { } +} diff --git a/swift/ql/lib/codeql/swift/elements/decl/TypeDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/TypeDeclImpl.qll index 15c6bd1609c6d..1ddadd790ffec 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/TypeDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/TypeDeclImpl.qll @@ -2,113 +2,118 @@ private import codeql.swift.generated.decl.TypeDecl private import codeql.swift.elements.type.AnyGenericType private import swift -/** - * A Swift type declaration, for example a class, struct, enum or protocol - * declaration. - * - * Type declarations are distinct from types. A type declaration represents - * the code that declares a type, for example: - * ``` - * class MyClass { - * ... - * } - * ``` - * Not all types have type declarations, for example built-in types do not - * have type declarations. - */ -class TypeDecl extends Generated::TypeDecl { - override string toString() { result = this.getName() } - +module Impl { /** - * Gets the `index`th base type of this type declaration (0-based). + * A Swift type declaration, for example a class, struct, enum or protocol + * declaration. * - * This is the same as `getImmediateInheritedType`. - * DEPRECATED: either use `getImmediateInheritedType` or unindexed `getABaseType`. - */ - deprecated Type getImmediateBaseType(int index) { result = this.getImmediateInheritedType(index) } - - /** - * Gets the `index`th base type of this type declaration (0-based). - * This is the same as `getInheritedType`. - * DEPRECATED: use `getInheritedType` or unindexed `getABaseType`. - */ - deprecated Type getBaseType(int index) { result = this.getInheritedType(index) } - - /** - * Gets any of the base types of this type declaration. Expands protocols added in - * extensions and expands type aliases. For example in the following code, `B` has - * base type `A`: + * Type declarations are distinct from types. A type declaration represents + * the code that declares a type, for example: * ``` - * typealias A_alias = A - * - * class B : A_alias {} + * class MyClass { + * ... + * } * ``` + * Not all types have type declarations, for example built-in types do not + * have type declarations. */ - Type getABaseType() { - // direct base type - result = this.getAnInheritedType().getUnderlyingType() - or - // protocol added in an extension of the type - exists(ExtensionDecl ed | - ed.getExtendedTypeDecl() = this and - ed.getAProtocol().getType() = result - ) - } + class TypeDecl extends Generated::TypeDecl { + override string toString() { result = this.getName() } - /** - * Gets the declaration of the `index`th base type of this type declaration (0-based). - * DEPRECATED: The index is not very meaningful here. Use `getABaseTypeDecl`. - */ - deprecated TypeDecl getBaseTypeDecl(int i) { - result = this.getBaseType(i).(AnyGenericType).getDeclaration() - } + /** + * Gets the `index`th base type of this type declaration (0-based). + * + * This is the same as `getImmediateInheritedType`. + * DEPRECATED: either use `getImmediateInheritedType` or unindexed `getABaseType`. + */ + deprecated Type getImmediateBaseType(int index) { + result = this.getImmediateInheritedType(index) + } - /** - * Gets the declaration of any of the base types of this type declaration. Expands - * protocols added in extensions and expands type aliases. For example in the following - * code, `B` has base type `A`. - * ``` - * typealias A_alias = A - * - * class B : A_alias {} - * ``` - */ - TypeDecl getABaseTypeDecl() { result = this.getABaseType().(AnyGenericType).getDeclaration() } + /** + * Gets the `index`th base type of this type declaration (0-based). + * This is the same as `getInheritedType`. + * DEPRECATED: use `getInheritedType` or unindexed `getABaseType`. + */ + deprecated Type getBaseType(int index) { result = this.getInheritedType(index) } - /** - * Gets the declaration of any type derived from this type declaration. Expands protocols - * added in extensions and expands type aliases. For example in the following code, `B` - * is derived from `A`. - * ``` - * typealias A_alias = A - * - * class B : A_alias {} - * ``` - */ - TypeDecl getADerivedTypeDecl() { result.getABaseTypeDecl() = this } + /** + * Gets any of the base types of this type declaration. Expands protocols added in + * extensions and expands type aliases. For example in the following code, `B` has + * base type `A`: + * ``` + * typealias A_alias = A + * + * class B : A_alias {} + * ``` + */ + Type getABaseType() { + // direct base type + result = this.getAnInheritedType().getUnderlyingType() + or + // protocol added in an extension of the type + exists(ExtensionDecl ed | + ed.getExtendedTypeDecl() = this and + ed.getAProtocol().getType() = result + ) + } - /** - * Gets the full name of this `TypeDecl`. For example in: - * ```swift - * struct A { - * struct B { - * // ... - * } - * } - * ``` - * The name and full name of `A` is `A`. The name of `B` is `B`, but the - * full name of `B` is `A.B`. - */ - cached - string getFullName() { - not this.getEnclosingDecl() instanceof TypeDecl and - not count(this.getEnclosingDecl().(ExtensionDecl).getExtendedTypeDecl()) = 1 and - result = this.getName() - or - result = this.getEnclosingDecl().(TypeDecl).getFullName() + "." + this.getName() - or - result = - unique(NominalTypeDecl td | td = this.getEnclosingDecl().(ExtensionDecl).getExtendedTypeDecl()) - .getFullName() + "." + this.getName() + /** + * Gets the declaration of the `index`th base type of this type declaration (0-based). + * DEPRECATED: The index is not very meaningful here. Use `getABaseTypeDecl`. + */ + deprecated TypeDecl getBaseTypeDecl(int i) { + result = this.getBaseType(i).(AnyGenericType).getDeclaration() + } + + /** + * Gets the declaration of any of the base types of this type declaration. Expands + * protocols added in extensions and expands type aliases. For example in the following + * code, `B` has base type `A`. + * ``` + * typealias A_alias = A + * + * class B : A_alias {} + * ``` + */ + TypeDecl getABaseTypeDecl() { result = this.getABaseType().(AnyGenericType).getDeclaration() } + + /** + * Gets the declaration of any type derived from this type declaration. Expands protocols + * added in extensions and expands type aliases. For example in the following code, `B` + * is derived from `A`. + * ``` + * typealias A_alias = A + * + * class B : A_alias {} + * ``` + */ + TypeDecl getADerivedTypeDecl() { result.getABaseTypeDecl() = this } + + /** + * Gets the full name of this `TypeDecl`. For example in: + * ```swift + * struct A { + * struct B { + * // ... + * } + * } + * ``` + * The name and full name of `A` is `A`. The name of `B` is `B`, but the + * full name of `B` is `A.B`. + */ + cached + string getFullName() { + not this.getEnclosingDecl() instanceof TypeDecl and + not count(this.getEnclosingDecl().(ExtensionDecl).getExtendedTypeDecl()) = 1 and + result = this.getName() + or + result = this.getEnclosingDecl().(TypeDecl).getFullName() + "." + this.getName() + or + result = + unique(NominalTypeDecl td | + td = this.getEnclosingDecl().(ExtensionDecl).getExtendedTypeDecl() + ).getFullName() + "." + this.getName() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/ValueDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/ValueDeclImpl.qll index 4598815fcec78..a0cf7640911f9 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/ValueDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/ValueDeclImpl.qll @@ -2,22 +2,24 @@ private import codeql.swift.generated.decl.ValueDecl private import codeql.swift.elements.decl.CapturedDecl private import codeql.swift.elements.expr.DeclRefExpr -/** - * A declaration that introduces a value with a type. - */ -class ValueDecl extends Generated::ValueDecl { +module Impl { /** - * Gets a capture of this declaration in the scope of a closure. + * A declaration that introduces a value with a type. */ - CapturedDecl asCapturedDecl() { result.getDecl() = this } + class ValueDecl extends Generated::ValueDecl { + /** + * Gets a capture of this declaration in the scope of a closure. + */ + CapturedDecl asCapturedDecl() { result.getDecl() = this } - /** - * Holds if this declaration is captured by a closure. - */ - predicate isCaptured() { exists(this.asCapturedDecl()) } + /** + * Holds if this declaration is captured by a closure. + */ + predicate isCaptured() { exists(this.asCapturedDecl()) } - /** - * Gets an expression that references this declaration. - */ - DeclRefExpr getAnAccess() { result.getDecl() = this } + /** + * Gets an expression that references this declaration. + */ + DeclRefExpr getAnAccess() { result.getDecl() = this } + } } diff --git a/swift/ql/lib/codeql/swift/elements/decl/VarDeclImpl.qll b/swift/ql/lib/codeql/swift/elements/decl/VarDeclImpl.qll index 7f479a9341e0d..0a28fec7e57cb 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/VarDeclImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/VarDeclImpl.qll @@ -1,56 +1,58 @@ private import codeql.swift.generated.decl.VarDecl private import codeql.swift.elements.decl.Decl -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A declaration of a variable such as - * * a local variable in a function: - * ``` - * func foo() { - * var x = 42 // <- - * let y = "hello" // <- - * ... - * } - * ``` - * * a member of a `struct` or `class`: - * ``` - * struct S { - * var size : Int // <- - * } - * ``` - * * ... - */ -class VarDecl extends Generated::VarDecl { - override string toString() { result = this.getName() } -} - -/** - * A field declaration. That is, a variable declaration that is a member of a - * class, struct, enum or protocol. - */ -class FieldDecl extends VarDecl { - FieldDecl() { this = any(Decl ctx).getAMember() } - +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file /** - * Holds if this field is called `fieldName` and is a member of a - * class, struct, extension, enum or protocol called `typeName`. + * A declaration of a variable such as + * * a local variable in a function: + * ``` + * func foo() { + * var x = 42 // <- + * let y = "hello" // <- + * ... + * } + * ``` + * * a member of a `struct` or `class`: + * ``` + * struct S { + * var size : Int // <- + * } + * ``` + * * ... */ - cached - predicate hasQualifiedName(string typeName, string fieldName) { - this.getName() = fieldName and - exists(Decl d | - d.asNominalTypeDecl().getFullName() = typeName and - d.getAMember() = this - ) + class VarDecl extends Generated::VarDecl { + override string toString() { result = this.getName() } } /** - * Holds if this field is called `fieldName` and is a member of a - * class, struct, extension, enum or protocol called `typeName` in a module - * called `moduleName`. + * A field declaration. That is, a variable declaration that is a member of a + * class, struct, enum or protocol. */ - predicate hasQualifiedName(string moduleName, string typeName, string fieldName) { - this.hasQualifiedName(typeName, fieldName) and - this.getModule().getFullName() = moduleName + class FieldDecl extends VarDecl { + FieldDecl() { this = any(Decl ctx).getAMember() } + + /** + * Holds if this field is called `fieldName` and is a member of a + * class, struct, extension, enum or protocol called `typeName`. + */ + cached + predicate hasQualifiedName(string typeName, string fieldName) { + this.getName() = fieldName and + exists(Decl d | + d.asNominalTypeDecl().getFullName() = typeName and + d.getAMember() = this + ) + } + + /** + * Holds if this field is called `fieldName` and is a member of a + * class, struct, extension, enum or protocol called `typeName` in a module + * called `moduleName`. + */ + predicate hasQualifiedName(string moduleName, string typeName, string fieldName) { + this.hasQualifiedName(typeName, fieldName) and + this.getModule().getFullName() = moduleName + } } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ApplyExprExt.qll b/swift/ql/lib/codeql/swift/elements/expr/ApplyExprExt.qll new file mode 100644 index 0000000000000..dfa7bab154de5 --- /dev/null +++ b/swift/ql/lib/codeql/swift/elements/expr/ApplyExprExt.qll @@ -0,0 +1,17 @@ +private import ApplyExpr +private import codeql.swift.generated.expr.ApplyExpr +private import codeql.swift.elements.expr.ApplyExprImpl +private import codeql.swift.elements.expr.MethodLookupExpr +private import codeql.swift.elements.decl.Method + +final private class MethodApplyExprImpl extends Impl::ApplyExpr { + private MethodLookupExpr method; + + MethodApplyExprImpl() { method = this.getFunction() } + + override Method getStaticTarget() { result = method.getMethod() } + + override Expr getQualifier() { result = method.getBase() } +} + +final class MethodApplyExpr extends MethodApplyExprImpl, ApplyExpr { } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ApplyExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ApplyExprImpl.qll index e90937cf15cb6..78bf7e17a943b 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ApplyExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ApplyExprImpl.qll @@ -6,54 +6,46 @@ private import codeql.swift.elements.expr.DotSyntaxBaseIgnoredExpr private import codeql.swift.elements.expr.AutoClosureExpr private import codeql.swift.elements.decl.Method -class ApplyExpr extends Generated::ApplyExpr { - Callable getStaticTarget() { result = this.getFunction().(DeclRefExpr).getDecl() } - - /** Gets the method qualifier, if this is applying a method */ - Expr getQualifier() { none() } - - /** - * Gets the argument of this `ApplyExpr` called `label` (if any). - */ - final Argument getArgumentWithLabel(string label) { - result = this.getAnArgument() and - result.getLabel() = label +module Impl { + class ApplyExpr extends Generated::ApplyExpr { + Callable getStaticTarget() { result = this.getFunction().(DeclRefExpr).getDecl() } + + /** Gets the method qualifier, if this is applying a method */ + Expr getQualifier() { none() } + + /** + * Gets the argument of this `ApplyExpr` called `label` (if any). + */ + final Argument getArgumentWithLabel(string label) { + result = this.getAnArgument() and + result.getLabel() = label + } + + override string toString() { + result = "call to " + this.getStaticTarget().toString() + or + not exists(this.getStaticTarget()) and + result = "call to ..." + } } - override string toString() { - result = "call to " + this.getStaticTarget().toString() - or - not exists(this.getStaticTarget()) and - result = "call to ..." - } -} - -class MethodApplyExpr extends ApplyExpr { - private MethodLookupExpr method; + private class PartialDotSyntaxBaseIgnoredApplyExpr extends ApplyExpr { + private DotSyntaxBaseIgnoredExpr expr; - MethodApplyExpr() { method = this.getFunction() } - - override Method getStaticTarget() { result = method.getMethod() } - - override Expr getQualifier() { result = method.getBase() } -} + PartialDotSyntaxBaseIgnoredApplyExpr() { expr = this.getFunction() } -private class PartialDotSyntaxBaseIgnoredApplyExpr extends ApplyExpr { - private DotSyntaxBaseIgnoredExpr expr; + override AutoClosureExpr getStaticTarget() { result = expr.getSubExpr() } - PartialDotSyntaxBaseIgnoredApplyExpr() { expr = this.getFunction() } + override Expr getQualifier() { result = expr.getQualifier() } - override AutoClosureExpr getStaticTarget() { result = expr.getSubExpr() } - - override Expr getQualifier() { result = expr.getQualifier() } - - override string toString() { result = "call to " + expr } -} + override string toString() { result = "call to " + expr } + } -private class FullDotSyntaxBaseIgnoredApplyExpr extends ApplyExpr { - private PartialDotSyntaxBaseIgnoredApplyExpr expr; + private class FullDotSyntaxBaseIgnoredApplyExpr extends ApplyExpr { + private PartialDotSyntaxBaseIgnoredApplyExpr expr; - FullDotSyntaxBaseIgnoredApplyExpr() { expr = this.getFunction() } + FullDotSyntaxBaseIgnoredApplyExpr() { expr = this.getFunction() } - override AutoClosureExpr getStaticTarget() { result = expr.getStaticTarget().getExpr() } + override AutoClosureExpr getStaticTarget() { result = expr.getStaticTarget().getExpr() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ArgumentImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ArgumentImpl.qll index d95e410f0815c..dd46a84a21d3c 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ArgumentImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ArgumentImpl.qll @@ -1,10 +1,12 @@ private import codeql.swift.generated.expr.Argument private import codeql.swift.elements.expr.ApplyExpr -class Argument extends Generated::Argument { - override string toString() { result = this.getLabel() + ": " + this.getExpr().toString() } +module Impl { + class Argument extends Generated::Argument { + override string toString() { result = this.getLabel() + ": " + this.getExpr().toString() } - int getIndex() { any(ApplyExpr apply).getArgument(result) = this } + int getIndex() { any(ApplyExpr apply).getArgument(result) = this } - ApplyExpr getApplyExpr() { result.getAnArgument() = this } + ApplyExpr getApplyExpr() { result.getAnArgument() = this } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ArrayExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ArrayExprImpl.qll index 1beef5e34b8ca..e2b04c7c01762 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ArrayExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ArrayExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.ArrayExpr -class ArrayExpr extends Generated::ArrayExpr { - override string toString() { result = "[...]" } +module Impl { + class ArrayExpr extends Generated::ArrayExpr { + override string toString() { result = "[...]" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/AssignExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/AssignExprImpl.qll index 809297b315163..a9e3d60cfc85f 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/AssignExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/AssignExprImpl.qll @@ -1,254 +1,256 @@ private import codeql.swift.generated.expr.AssignExpr private import codeql.swift.elements.expr.BinaryExpr -/** - * An assignment expression. For example: - * ``` - * x = 0 - * y += 1 - * z <<= 1 - * ``` - */ -class Assignment extends Expr { - Assignment() { - this instanceof AssignExpr or - this instanceof AssignArithmeticOperationEx or - this instanceof AssignBitwiseOperationEx or - this instanceof AssignPointwiseOperationEx +module Impl { + /** + * An assignment expression. For example: + * ``` + * x = 0 + * y += 1 + * z <<= 1 + * ``` + */ + class Assignment extends Expr { + Assignment() { + this instanceof AssignExpr or + this instanceof AssignArithmeticOperationEx or + this instanceof AssignBitwiseOperationEx or + this instanceof AssignPointwiseOperationEx + } + + /** + * Gets the destination of this assignment. For example `x` in: + * ``` + * x = y + * ``` + */ + Expr getDest() { + result = this.(AssignExpr).getDest() or + result = this.(AssignOperation).getLeftOperand() + } + + /** + * Gets the source of this assignment. For example `y` in: + * ``` + * x = y + * ``` + */ + Expr getSource() { + result = this.(AssignExpr).getSource() or + result = this.(AssignOperation).getRightOperand() + } + + /** + * Holds if this assignment expression uses an overflow operator, that is, + * an operator that truncates overflow rather than reporting an error. + * ``` + * x &+= y + * ``` + */ + predicate hasOverflowOperator() { + this.(AssignOperation).getOperator().getName() = + ["&*=(_:_:)", "&+=(_:_:)", "&-=(_:_:)", "&<<=(_:_:)", "&>>=(_:_:)"] + } } /** - * Gets the destination of this assignment. For example `x` in: + * A simple assignment expression using the `=` operator: * ``` - * x = y + * x = 0 * ``` */ - Expr getDest() { - result = this.(AssignExpr).getDest() or - result = this.(AssignOperation).getLeftOperand() + class AssignExpr extends Generated::AssignExpr { + override string toString() { result = " ... = ..." } } /** - * Gets the source of this assignment. For example `y` in: + * An assignment expression apart from `=`. For example: * ``` - * x = y + * x += 1 + * y &= z * ``` */ - Expr getSource() { - result = this.(AssignExpr).getSource() or - result = this.(AssignOperation).getRightOperand() + class AssignOperation extends Assignment, BinaryExpr { + AssignOperation() { + this instanceof AssignArithmeticOperationEx or + this instanceof AssignBitwiseOperationEx or + this instanceof AssignPointwiseOperationEx + } } /** - * Holds if this assignment expression uses an overflow operator, that is, - * an operator that truncates overflow rather than reporting an error. + * An arithmetic assignment expression. For example: * ``` - * x &+= y + * x += 1 + * y *= z * ``` */ - predicate hasOverflowOperator() { - this.(AssignOperation).getOperator().getName() = - ["&*=(_:_:)", "&+=(_:_:)", "&-=(_:_:)", "&<<=(_:_:)", "&>>=(_:_:)"] - } -} + class AssignArithmeticOperation extends AssignOperation instanceof AssignArithmeticOperationEx { } -/** - * A simple assignment expression using the `=` operator: - * ``` - * x = 0 - * ``` - */ -class AssignExpr extends Generated::AssignExpr { - override string toString() { result = " ... = ..." } -} + /** + * Private abstract class, extended to define the scope of `AssignArithmeticOperation`. + */ + abstract private class AssignArithmeticOperationEx extends BinaryExpr { } -/** - * An assignment expression apart from `=`. For example: - * ``` - * x += 1 - * y &= z - * ``` - */ -class AssignOperation extends Assignment, BinaryExpr { - AssignOperation() { - this instanceof AssignArithmeticOperationEx or - this instanceof AssignBitwiseOperationEx or - this instanceof AssignPointwiseOperationEx - } -} + /** + * A bitwise assignment expression. For example: + * ``` + * x &= y + * z <<= 1 + * ``` + */ + class AssignBitwiseOperation extends AssignOperation instanceof AssignBitwiseOperationEx { } -/** - * An arithmetic assignment expression. For example: - * ``` - * x += 1 - * y *= z - * ``` - */ -class AssignArithmeticOperation extends AssignOperation instanceof AssignArithmeticOperationEx { } - -/** - * Private abstract class, extended to define the scope of `AssignArithmeticOperation`. - */ -abstract private class AssignArithmeticOperationEx extends BinaryExpr { } - -/** - * A bitwise assignment expression. For example: - * ``` - * x &= y - * z <<= 1 - * ``` - */ -class AssignBitwiseOperation extends AssignOperation instanceof AssignBitwiseOperationEx { } - -/** - * Private abstract class, extended to define the scope of `AssignBitwiseOperation`. - */ -abstract private class AssignBitwiseOperationEx extends BinaryExpr { } - -/** - * A pointwise assignment expression. For example: - * ``` - * x .&= y - * ``` - */ -class AssignPointwiseOperation extends AssignOperation instanceof AssignPointwiseOperationEx { } - -/** - * Private abstract class, extended to define the scope of `AssignPointwiseOperation`. - */ -abstract private class AssignPointwiseOperationEx extends BinaryExpr { } - -/** - * An addition assignment expression: - * ``` - * a += b - * a &+= b - * ``` - */ -class AssignAddExpr extends AssignArithmeticOperationEx { - AssignAddExpr() { this.getOperator().getName() = ["+=(_:_:)", "&+=(_:_:)"] } -} + /** + * Private abstract class, extended to define the scope of `AssignBitwiseOperation`. + */ + abstract private class AssignBitwiseOperationEx extends BinaryExpr { } -/** - * A subtraction assignment expression: - * ``` - * a -= b - * a &-= b - * ``` - */ -class AssignSubExpr extends AssignArithmeticOperationEx { - AssignSubExpr() { this.getOperator().getName() = ["-=(_:_:)", "&-=(_:_:)"] } -} + /** + * A pointwise assignment expression. For example: + * ``` + * x .&= y + * ``` + */ + class AssignPointwiseOperation extends AssignOperation instanceof AssignPointwiseOperationEx { } -/** - * A multiplication assignment expression: - * ``` - * a *= b - * a &*= b - * ``` - */ -class AssignMulExpr extends AssignArithmeticOperationEx { - AssignMulExpr() { this.getOperator().getName() = ["*=(_:_:)", "&*=(_:_:)"] } -} + /** + * Private abstract class, extended to define the scope of `AssignPointwiseOperation`. + */ + abstract private class AssignPointwiseOperationEx extends BinaryExpr { } -/** - * A division assignment expression: - * ``` - * a /= b - * ``` - */ -class AssignDivExpr extends AssignArithmeticOperationEx { - AssignDivExpr() { this.getOperator().getName() = "/=(_:_:)" } -} + /** + * An addition assignment expression: + * ``` + * a += b + * a &+= b + * ``` + */ + class AssignAddExpr extends AssignArithmeticOperationEx { + AssignAddExpr() { this.getOperator().getName() = ["+=(_:_:)", "&+=(_:_:)"] } + } -/** - * A remainder assignment expression: - * ``` - * a %= b - * ``` - */ -class AssignRemExpr extends AssignArithmeticOperationEx { - AssignRemExpr() { this.getOperator().getName() = "%=(_:_:)" } -} + /** + * A subtraction assignment expression: + * ``` + * a -= b + * a &-= b + * ``` + */ + class AssignSubExpr extends AssignArithmeticOperationEx { + AssignSubExpr() { this.getOperator().getName() = ["-=(_:_:)", "&-=(_:_:)"] } + } -/** - * A left-shift assignment expression: - * ``` - * a <<= b - * a &<<= b - * ``` - */ -class AssignLShiftExpr extends AssignBitwiseOperationEx { - AssignLShiftExpr() { this.getOperator().getName() = ["<<=(_:_:)", "&<<=(_:_:)"] } -} + /** + * A multiplication assignment expression: + * ``` + * a *= b + * a &*= b + * ``` + */ + class AssignMulExpr extends AssignArithmeticOperationEx { + AssignMulExpr() { this.getOperator().getName() = ["*=(_:_:)", "&*=(_:_:)"] } + } -/** - * A right-shift assignment expression: - * ``` - * a >>= b - * a &>>= b - * ``` - */ -class AssignRShiftExpr extends AssignBitwiseOperationEx { - AssignRShiftExpr() { this.getOperator().getName() = [">>=(_:_:)", "&>>=(_:_:)"] } -} + /** + * A division assignment expression: + * ``` + * a /= b + * ``` + */ + class AssignDivExpr extends AssignArithmeticOperationEx { + AssignDivExpr() { this.getOperator().getName() = "/=(_:_:)" } + } -/** - * A bitwise-and assignment expression: - * ``` - * a &= b - * ``` - */ -class AssignAndExpr extends AssignBitwiseOperationEx { - AssignAndExpr() { this.getOperator().getName() = "&=(_:_:)" } -} + /** + * A remainder assignment expression: + * ``` + * a %= b + * ``` + */ + class AssignRemExpr extends AssignArithmeticOperationEx { + AssignRemExpr() { this.getOperator().getName() = "%=(_:_:)" } + } -/** - * A bitwise-or assignment expression: - * ``` - * a |= b - * ``` - */ -class AssignOrExpr extends AssignBitwiseOperationEx { - AssignOrExpr() { this.getOperator().getName() = "|=(_:_:)" } -} + /** + * A left-shift assignment expression: + * ``` + * a <<= b + * a &<<= b + * ``` + */ + class AssignLShiftExpr extends AssignBitwiseOperationEx { + AssignLShiftExpr() { this.getOperator().getName() = ["<<=(_:_:)", "&<<=(_:_:)"] } + } -/** - * A bitwise exclusive-or assignment expression: - * ``` - * a ^= b - * ``` - */ -class AssignXorExpr extends AssignBitwiseOperationEx { - AssignXorExpr() { this.getOperator().getName() = "^=(_:_:)" } -} + /** + * A right-shift assignment expression: + * ``` + * a >>= b + * a &>>= b + * ``` + */ + class AssignRShiftExpr extends AssignBitwiseOperationEx { + AssignRShiftExpr() { this.getOperator().getName() = [">>=(_:_:)", "&>>=(_:_:)"] } + } -/** - * A pointwise bitwise-and assignment expression: - * ``` - * a .&= b - * ``` - */ -class AssignPointwiseAndExpr extends AssignPointwiseOperationEx { - AssignPointwiseAndExpr() { this.getOperator().getName() = ".&=(_:_:)" } -} + /** + * A bitwise-and assignment expression: + * ``` + * a &= b + * ``` + */ + class AssignAndExpr extends AssignBitwiseOperationEx { + AssignAndExpr() { this.getOperator().getName() = "&=(_:_:)" } + } -/** - * A pointwise bitwise-or assignment expression: - * ``` - * a .|= b - * ``` - */ -class AssignPointwiseOrExpr extends AssignPointwiseOperationEx { - AssignPointwiseOrExpr() { this.getOperator().getName() = ".|=(_:_:)" } -} + /** + * A bitwise-or assignment expression: + * ``` + * a |= b + * ``` + */ + class AssignOrExpr extends AssignBitwiseOperationEx { + AssignOrExpr() { this.getOperator().getName() = "|=(_:_:)" } + } + + /** + * A bitwise exclusive-or assignment expression: + * ``` + * a ^= b + * ``` + */ + class AssignXorExpr extends AssignBitwiseOperationEx { + AssignXorExpr() { this.getOperator().getName() = "^=(_:_:)" } + } + + /** + * A pointwise bitwise-and assignment expression: + * ``` + * a .&= b + * ``` + */ + class AssignPointwiseAndExpr extends AssignPointwiseOperationEx { + AssignPointwiseAndExpr() { this.getOperator().getName() = ".&=(_:_:)" } + } -/** - * A pointwise bitwise exclusive-or assignment expression: - * ``` - * a .^= b - * ``` - */ -class AssignPointwiseXorExpr extends AssignPointwiseOperationEx { - AssignPointwiseXorExpr() { this.getOperator().getName() = ".^=(_:_:)" } + /** + * A pointwise bitwise-or assignment expression: + * ``` + * a .|= b + * ``` + */ + class AssignPointwiseOrExpr extends AssignPointwiseOperationEx { + AssignPointwiseOrExpr() { this.getOperator().getName() = ".|=(_:_:)" } + } + + /** + * A pointwise bitwise exclusive-or assignment expression: + * ``` + * a .^= b + * ``` + */ + class AssignPointwiseXorExpr extends AssignPointwiseOperationEx { + AssignPointwiseXorExpr() { this.getOperator().getName() = ".^=(_:_:)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExprImpl.qll index 6061db1fdf74c..69633e2dcc7fe 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/AutoClosureExprImpl.qll @@ -2,29 +2,31 @@ private import codeql.swift.generated.expr.AutoClosureExpr private import codeql.swift.elements.stmt.ReturnStmt private import codeql.swift.elements.expr.Expr -/** - * A Swift autoclosure expression, that is, a closure automatically generated - * around an argument when the parameter has the `@autoclosure` attribute or - * for the right-hand operand of short-circuiting logical operations. For - * example, there is an `AutoClosureExpr` around the value `0` in: - * ``` - * func myFunction(_ expr: @autoclosure () -> Int) { - * ... - * } - * - * myFunction(0) - * ``` - */ -class AutoClosureExpr extends Generated::AutoClosureExpr { +module Impl { /** - * Gets the implicit return statement generated by this autoclosure expression. + * A Swift autoclosure expression, that is, a closure automatically generated + * around an argument when the parameter has the `@autoclosure` attribute or + * for the right-hand operand of short-circuiting logical operations. For + * example, there is an `AutoClosureExpr` around the value `0` in: + * ``` + * func myFunction(_ expr: @autoclosure () -> Int) { + * ... + * } + * + * myFunction(0) + * ``` */ - ReturnStmt getReturn() { result = unique( | | this.getBody().getAnElement()) } + class AutoClosureExpr extends Generated::AutoClosureExpr { + /** + * Gets the implicit return statement generated by this autoclosure expression. + */ + ReturnStmt getReturn() { result = unique( | | this.getBody().getAnElement()) } - /** - * Gets the expression returned by this autoclosure expression. - */ - Expr getExpr() { result = this.getReturn().getResult() } + /** + * Gets the expression returned by this autoclosure expression. + */ + Expr getExpr() { result = this.getReturn().getResult() } - override string toString() { result = this.getBody().toString() } + override string toString() { result = this.getBody().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/AwaitExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/AwaitExprImpl.qll index 9aed11c780348..afae7e0bc5bc4 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/AwaitExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/AwaitExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.AwaitExpr -class AwaitExpr extends Generated::AwaitExpr { - override string toString() { result = "await ..." } +module Impl { + class AwaitExpr extends Generated::AwaitExpr { + override string toString() { result = "await ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/BinaryExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/BinaryExprImpl.qll index 88355ad2d6067..e823c08375d87 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/BinaryExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/BinaryExprImpl.qll @@ -2,35 +2,37 @@ private import codeql.swift.generated.expr.BinaryExpr private import codeql.swift.elements.expr.Expr private import codeql.swift.elements.decl.Function -/** - * A Swift binary expression, that is, an expression that appears between its - * two operands. For example: - * ``` - * x + y - * ``` - */ -class BinaryExpr extends Generated::BinaryExpr { +module Impl { /** - * Gets the left operand (left expression) of this binary expression. + * A Swift binary expression, that is, an expression that appears between its + * two operands. For example: + * ``` + * x + y + * ``` */ - Expr getLeftOperand() { result = this.getArgument(0).getExpr() } + class BinaryExpr extends Generated::BinaryExpr { + /** + * Gets the left operand (left expression) of this binary expression. + */ + Expr getLeftOperand() { result = this.getArgument(0).getExpr() } - /** - * Gets the right operand (right expression) of this binary expression. - */ - Expr getRightOperand() { result = this.getArgument(1).getExpr() } + /** + * Gets the right operand (right expression) of this binary expression. + */ + Expr getRightOperand() { result = this.getArgument(1).getExpr() } - /** - * Gets the operator of this binary expression (the function that is called). - */ - Function getOperator() { result = this.getStaticTarget() } + /** + * Gets the operator of this binary expression (the function that is called). + */ + Function getOperator() { result = this.getStaticTarget() } - /** - * Gets an operand of this binary expression (left or right). - */ - Expr getAnOperand() { result = [this.getLeftOperand(), this.getRightOperand()] } + /** + * Gets an operand of this binary expression (left or right). + */ + Expr getAnOperand() { result = [this.getLeftOperand(), this.getRightOperand()] } - override string toString() { result = "... " + this.getFunction().toString() + " ..." } + override string toString() { result = "... " + this.getFunction().toString() + " ..." } - override Function getStaticTarget() { result = super.getStaticTarget() } + override Function getStaticTarget() { result = super.getStaticTarget() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/BindOptionalExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/BindOptionalExprImpl.qll index 44a82c661ed3c..3a50de5166e0a 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/BindOptionalExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/BindOptionalExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.BindOptionalExpr -class BindOptionalExpr extends Generated::BindOptionalExpr { - override string toString() { result = "...?" } +module Impl { + class BindOptionalExpr extends Generated::BindOptionalExpr { + override string toString() { result = "...?" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/BooleanLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/BooleanLiteralExprImpl.qll index 552dbaf880824..abb23239bb2e0 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/BooleanLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/BooleanLiteralExprImpl.qll @@ -1,13 +1,15 @@ private import codeql.swift.generated.expr.BooleanLiteralExpr -/** - * A boolean literal. For example `true` in: - * ``` - * let x = true - * ``` - */ -class BooleanLiteralExpr extends Generated::BooleanLiteralExpr { - override string toString() { result = this.getValue().toString() } +module Impl { + /** + * A boolean literal. For example `true` in: + * ``` + * let x = true + * ``` + */ + class BooleanLiteralExpr extends Generated::BooleanLiteralExpr { + override string toString() { result = this.getValue().toString() } - override string getValueString() { result = this.getValue().toString() } + override string getValueString() { result = this.getValue().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/BuiltinLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/BuiltinLiteralExprImpl.qll index 22de6008e968c..f2d9433e71106 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/BuiltinLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/BuiltinLiteralExprImpl.qll @@ -4,12 +4,14 @@ private import codeql.swift.generated.expr.BuiltinLiteralExpr -/** - * A Swift literal of a kind that is built in to the Swift language. - */ -class BuiltinLiteralExpr extends Generated::BuiltinLiteralExpr { +module Impl { /** - * Gets the value of this literal expression (as a string). + * A Swift literal of a kind that is built in to the Swift language. */ - string getValueString() { none() } + class BuiltinLiteralExpr extends Generated::BuiltinLiteralExpr { + /** + * Gets the value of this literal expression (as a string). + */ + string getValueString() { none() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/CaptureListExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/CaptureListExprImpl.qll index 834684d017304..05cb4ff9725ea 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/CaptureListExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/CaptureListExprImpl.qll @@ -1,11 +1,13 @@ private import codeql.swift.generated.expr.CaptureListExpr private import codeql.swift.elements.pattern.NamedPattern -class CaptureListExpr extends Generated::CaptureListExpr { - override string toString() { result = this.getClosureBody().toString() } +module Impl { + class CaptureListExpr extends Generated::CaptureListExpr { + override string toString() { result = this.getClosureBody().toString() } - override VarDecl getVariable(int index) { - // all capture binding declarations consist of a single named pattern - result = this.getBindingDecl(index).getPattern(0).(NamedPattern).getVarDecl() + override VarDecl getVariable(int index) { + // all capture binding declarations consist of a single named pattern + result = this.getBindingDecl(index).getPattern(0).(NamedPattern).getVarDecl() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ClosureExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ClosureExprImpl.qll index 4b542d9f38d8c..198f22c32e015 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ClosureExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ClosureExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.ClosureExpr -class ClosureExpr extends Generated::ClosureExpr { - override string toString() { result = "{ ... }" } +module Impl { + class ClosureExpr extends Generated::ClosureExpr { + override string toString() { result = "{ ... }" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DeclRefExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DeclRefExprImpl.qll index 8493f85d3c72d..0429b61613073 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DeclRefExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DeclRefExprImpl.qll @@ -1,23 +1,25 @@ private import codeql.swift.generated.expr.DeclRefExpr private import codeql.swift.elements.decl.CapturedDecl -/** - * An expression that references or accesses a declaration. - */ -class DeclRefExpr extends Generated::DeclRefExpr { - override string toString() { - if exists(this.getDecl().toString()) - then result = this.getDecl().toString() - else result = "(unknown declaration)" - } - +module Impl { /** - * Gets the closure capture referenced by this expression, if any. + * An expression that references or accesses a declaration. */ - CapturedDecl getCapturedDecl() { result.getAnAccess() = this } + class DeclRefExpr extends Generated::DeclRefExpr { + override string toString() { + if exists(this.getDecl().toString()) + then result = this.getDecl().toString() + else result = "(unknown declaration)" + } - /** - * Holds if this expression references a closure capture. - */ - predicate hasCapturedDecl() { exists(this.getCapturedDecl()) } + /** + * Gets the closure capture referenced by this expression, if any. + */ + CapturedDecl getCapturedDecl() { result.getAnAccess() = this } + + /** + * Holds if this expression references a closure capture. + */ + predicate hasCapturedDecl() { exists(this.getCapturedDecl()) } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DefaultArgumentExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DefaultArgumentExprImpl.qll index 452beb072c126..21481301dfb91 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DefaultArgumentExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DefaultArgumentExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.DefaultArgumentExpr -class DefaultArgumentExpr extends Generated::DefaultArgumentExpr { - override string toString() { result = "default " + this.getParamDecl().getName() } +module Impl { + class DefaultArgumentExpr extends Generated::DefaultArgumentExpr { + override string toString() { result = "default " + this.getParamDecl().getName() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DictionaryExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DictionaryExprImpl.qll index 4e98d5ac3fa0c..92517497864d0 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DictionaryExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DictionaryExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.DictionaryExpr -class DictionaryExpr extends Generated::DictionaryExpr { - override string toString() { result = "[...]" } +module Impl { + class DictionaryExpr extends Generated::DictionaryExpr { + override string toString() { result = "[...]" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DifferentiableFunctionExtractOriginalExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DifferentiableFunctionExtractOriginalExprImpl.qll index db77a4a3e841b..78ba648cfbcf7 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DifferentiableFunctionExtractOriginalExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DifferentiableFunctionExtractOriginalExprImpl.qll @@ -1,4 +1,6 @@ private import codeql.swift.generated.expr.DifferentiableFunctionExtractOriginalExpr -class DifferentiableFunctionExtractOriginalExpr extends Generated::DifferentiableFunctionExtractOriginalExpr -{ } +module Impl { + class DifferentiableFunctionExtractOriginalExpr extends Generated::DifferentiableFunctionExtractOriginalExpr + { } +} diff --git a/swift/ql/lib/codeql/swift/elements/expr/DiscardAssignmentExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DiscardAssignmentExprImpl.qll index 1a8bd47e69d57..5516e13db11df 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DiscardAssignmentExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DiscardAssignmentExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.DiscardAssignmentExpr -class DiscardAssignmentExpr extends Generated::DiscardAssignmentExpr { - override string toString() { result = "_" } +module Impl { + class DiscardAssignmentExpr extends Generated::DiscardAssignmentExpr { + override string toString() { result = "_" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DotSelfExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DotSelfExprImpl.qll index 378672d9b8fd0..b9652363eb3bc 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DotSelfExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DotSelfExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.DotSelfExpr -class DotSelfExpr extends Generated::DotSelfExpr { - override string toString() { result = ".self" } +module Impl { + class DotSelfExpr extends Generated::DotSelfExpr { + override string toString() { result = ".self" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DotSyntaxBaseIgnoredExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DotSyntaxBaseIgnoredExprImpl.qll index b6993f9e28f1b..3e9a72b37e04a 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DotSyntaxBaseIgnoredExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DotSyntaxBaseIgnoredExprImpl.qll @@ -4,38 +4,40 @@ private import codeql.swift.elements.expr.CallExpr private import codeql.swift.elements.expr.TypeExpr private import codeql.swift.elements.decl.Method -/** - * An expression representing a partially applied lookup of an instance property via the receiver's type object. - * - * An example is the sub-expression `SomeClass.instanceMethod` of - * `SomeClass.instanceMethod(someInstance)(arg, ...)`. - * - * Internally, the Swift compiler desugars this AST node type into a closure expression of the form - * `{ (someInstance: SomeClass) in { (arg, ...) in someInstance.instanceMethod(arg, ...) } }`, - * which in turn can be accessed using the `getSubExpr/0` predicate. - */ -class DotSyntaxBaseIgnoredExpr extends Generated::DotSyntaxBaseIgnoredExpr { - override string toString() { - result = - any(string base | - if exists(this.getQualifier().(TypeExpr).getTypeRepr().toString()) - then base = this.getQualifier().(TypeExpr).getTypeRepr().toString() + "." - else base = "." - ) + this.getMethod() - } - +module Impl { /** - * Gets the underlying instance method that is called when the result of this - * expression is fully applied. + * An expression representing a partially applied lookup of an instance property via the receiver's type object. + * + * An example is the sub-expression `SomeClass.instanceMethod` of + * `SomeClass.instanceMethod(someInstance)(arg, ...)`. + * + * Internally, the Swift compiler desugars this AST node type into a closure expression of the form + * `{ (someInstance: SomeClass) in { (arg, ...) in someInstance.instanceMethod(arg, ...) } }`, + * which in turn can be accessed using the `getSubExpr/0` predicate. */ - Method getMethod() { - result = - this.getSubExpr() - .(AutoClosureExpr) - .getExpr() - .(AutoClosureExpr) - .getExpr() - .(CallExpr) - .getStaticTarget() + class DotSyntaxBaseIgnoredExpr extends Generated::DotSyntaxBaseIgnoredExpr { + override string toString() { + result = + any(string base | + if exists(this.getQualifier().(TypeExpr).getTypeRepr().toString()) + then base = this.getQualifier().(TypeExpr).getTypeRepr().toString() + "." + else base = "." + ) + this.getMethod() + } + + /** + * Gets the underlying instance method that is called when the result of this + * expression is fully applied. + */ + Method getMethod() { + result = + this.getSubExpr() + .(AutoClosureExpr) + .getExpr() + .(AutoClosureExpr) + .getExpr() + .(CallExpr) + .getStaticTarget() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DynamicMemberRefExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DynamicMemberRefExprImpl.qll index 2de645bc4e2b8..7f03f564d0faa 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DynamicMemberRefExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DynamicMemberRefExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.DynamicMemberRefExpr -class DynamicMemberRefExpr extends Generated::DynamicMemberRefExpr { - override string toString() { result = "." + this.getMember().toString() } +module Impl { + class DynamicMemberRefExpr extends Generated::DynamicMemberRefExpr { + override string toString() { result = "." + this.getMember().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DynamicSubscriptExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DynamicSubscriptExprImpl.qll index e054e54f17ff3..fd18ae9f56792 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DynamicSubscriptExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DynamicSubscriptExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.DynamicSubscriptExpr -class DynamicSubscriptExpr extends Generated::DynamicSubscriptExpr { - override string toString() { result = this.getMember().toString() + "[...]" } +module Impl { + class DynamicSubscriptExpr extends Generated::DynamicSubscriptExpr { + override string toString() { result = this.getMember().toString() + "[...]" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/DynamicTypeExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/DynamicTypeExprImpl.qll index 27f2bf489277b..2ed7a8734e227 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/DynamicTypeExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/DynamicTypeExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.DynamicTypeExpr -class DynamicTypeExpr extends Generated::DynamicTypeExpr { - override string toString() { result = "type(of: ...)" } +module Impl { + class DynamicTypeExpr extends Generated::DynamicTypeExpr { + override string toString() { result = "type(of: ...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/EnumIsCaseExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/EnumIsCaseExprImpl.qll index ae1ea5a0b3d73..941591e77fa61 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/EnumIsCaseExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/EnumIsCaseExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.EnumIsCaseExpr -class EnumIsCaseExpr extends Generated::EnumIsCaseExpr { - override string toString() { result = "... is " + this.getElement().toString() } +module Impl { + class EnumIsCaseExpr extends Generated::EnumIsCaseExpr { + override string toString() { result = "... is " + this.getElement().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ExplicitCastExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ExplicitCastExprImpl.qll index ff608b58ba9c8..9e961502ccd1a 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ExplicitCastExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ExplicitCastExprImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.expr.ExplicitCastExpr -class ExplicitCastExpr extends Generated::ExplicitCastExpr { - override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } +module Impl { + class ExplicitCastExpr extends Generated::ExplicitCastExpr { + override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } - override string toString() { result = "(" + this.getType() + ") ..." } + override string toString() { result = "(" + this.getType() + ") ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ExplicitClosureExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ExplicitClosureExprImpl.qll index d7700f85b2917..573b2fc99115a 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ExplicitClosureExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ExplicitClosureExprImpl.qll @@ -1,8 +1,10 @@ private import codeql.swift.generated.expr.ExplicitClosureExpr -/** - * A Swift explicit closure expr, that is, a closure written using - * `{ ... -> ... in ... }` syntax rather than automatically generated by the - * compiler. - */ -class ExplicitClosureExpr extends Generated::ExplicitClosureExpr { } +module Impl { + /** + * A Swift explicit closure expr, that is, a closure written using + * `{ ... -> ... in ... }` syntax rather than automatically generated by the + * compiler. + */ + class ExplicitClosureExpr extends Generated::ExplicitClosureExpr { } +} diff --git a/swift/ql/lib/codeql/swift/elements/expr/ExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ExprImpl.qll index f348dbe1815aa..d3de2b05c7f38 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ExprImpl.qll @@ -1,27 +1,29 @@ private import codeql.swift.generated.expr.Expr -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * The base class for all expressions in Swift. - */ -class Expr extends Generated::Expr { - final override Expr getResolveStep() { this.convertsFrom(result) } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * The base class for all expressions in Swift. + */ + class Expr extends Generated::Expr { + final override Expr getResolveStep() { this.convertsFrom(result) } - predicate convertsFrom(Expr e) { none() } // overridden by subclasses + predicate convertsFrom(Expr e) { none() } // overridden by subclasses - Expr getConversion() { result.convertsFrom(this) } + Expr getConversion() { result.convertsFrom(this) } - Expr getConversion(int n) { - n = 0 and result = this.getConversion() - or - result = this.getConversion(n - 1).getConversion() - } + Expr getConversion(int n) { + n = 0 and result = this.getConversion() + or + result = this.getConversion(n - 1).getConversion() + } - predicate isConversion() { this.convertsFrom(_) } + predicate isConversion() { this.convertsFrom(_) } - predicate hasConversions() { exists(this.getConversion()) } + predicate hasConversions() { exists(this.getConversion()) } - Expr getFullyConverted() { result = this.getFullyUnresolved() } + Expr getFullyConverted() { result = this.getFullyUnresolved() } - Expr getUnconverted() { result = this.resolve() } + Expr getUnconverted() { result = this.resolve() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/FloatLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/FloatLiteralExprImpl.qll index 527a55c6d231a..c7a7f1c714f40 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/FloatLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/FloatLiteralExprImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.expr.FloatLiteralExpr -class FloatLiteralExpr extends Generated::FloatLiteralExpr { - override string toString() { result = this.getStringValue() } +module Impl { + class FloatLiteralExpr extends Generated::FloatLiteralExpr { + override string toString() { result = this.getStringValue() } - override string getValueString() { result = this.getStringValue() } + override string getValueString() { result = this.getStringValue() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ForceTryExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ForceTryExprImpl.qll index 36e3a395d09bf..2f53e51381516 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ForceTryExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ForceTryExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.ForceTryExpr -class ForceTryExpr extends Generated::ForceTryExpr { - override string toString() { result = "try! ..." } +module Impl { + class ForceTryExpr extends Generated::ForceTryExpr { + override string toString() { result = "try! ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ForceValueExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ForceValueExprImpl.qll index c54455ce7b79b..84e89108c9499 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ForceValueExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ForceValueExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.ForceValueExpr -class ForceValueExpr extends Generated::ForceValueExpr { - override string toString() { result = "...!" } +module Impl { + class ForceValueExpr extends Generated::ForceValueExpr { + override string toString() { result = "...!" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/IdentityExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/IdentityExprImpl.qll index ecfe0dd3e1af7..f51b49e2def08 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/IdentityExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/IdentityExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.IdentityExpr -class IdentityExpr extends Generated::IdentityExpr { - override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } +module Impl { + class IdentityExpr extends Generated::IdentityExpr { + override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/IfExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/IfExprImpl.qll index 3afcc992089ab..359d3ff509456 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/IfExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/IfExprImpl.qll @@ -1,13 +1,15 @@ private import codeql.swift.generated.expr.IfExpr -class IfExpr extends Generated::IfExpr { - Expr getBranch(boolean b) { - b = true and - result = this.getThenExpr() - or - b = false and - result = this.getElseExpr() - } +module Impl { + class IfExpr extends Generated::IfExpr { + Expr getBranch(boolean b) { + b = true and + result = this.getThenExpr() + or + b = false and + result = this.getElseExpr() + } - override string toString() { result = "... ? ... : ..." } + override string toString() { result = "... ? ... : ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ImplicitConversionExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ImplicitConversionExprImpl.qll index 37138ed372427..f4ab0120cf877 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ImplicitConversionExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ImplicitConversionExprImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.expr.ImplicitConversionExpr -class ImplicitConversionExpr extends Generated::ImplicitConversionExpr { - override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } +module Impl { + class ImplicitConversionExpr extends Generated::ImplicitConversionExpr { + override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } - override string toString() { result = "(" + this.getType().toString() + ") ..." } + override string toString() { result = "(" + this.getType().toString() + ") ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/InOutExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/InOutExprImpl.qll index 7326cabfdd939..54acc229a957f 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/InOutExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/InOutExprImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.expr.InOutExpr -class InOutExpr extends Generated::InOutExpr { - override string toString() { result = "&..." } +module Impl { + class InOutExpr extends Generated::InOutExpr { + override string toString() { result = "&..." } - override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } + override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/IntegerLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/IntegerLiteralExprImpl.qll index 45b442ca5cf70..3256c7cd9b361 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/IntegerLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/IntegerLiteralExprImpl.qll @@ -1,13 +1,15 @@ private import codeql.swift.generated.expr.IntegerLiteralExpr -/** - * An integer literal. For example `1` in: - * ``` - * let x = 1 - * ``` - */ -class IntegerLiteralExpr extends Generated::IntegerLiteralExpr { - override string toString() { result = this.getStringValue() } +module Impl { + /** + * An integer literal. For example `1` in: + * ``` + * let x = 1 + * ``` + */ + class IntegerLiteralExpr extends Generated::IntegerLiteralExpr { + override string toString() { result = this.getStringValue() } - override string getValueString() { result = this.getStringValue() } + override string getValueString() { result = this.getStringValue() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/InterpolatedStringLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/InterpolatedStringLiteralExprImpl.qll index f21b4492e8eba..01e2ab92c2ab3 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/InterpolatedStringLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/InterpolatedStringLiteralExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.InterpolatedStringLiteralExpr -class InterpolatedStringLiteralExpr extends Generated::InterpolatedStringLiteralExpr { - override string toString() { result = "\"...\"" } +module Impl { + class InterpolatedStringLiteralExpr extends Generated::InterpolatedStringLiteralExpr { + override string toString() { result = "\"...\"" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/IsExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/IsExprImpl.qll index 8eae10827e2cd..69a5855b017ac 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/IsExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/IsExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.IsExpr -class IsExpr extends Generated::IsExpr { - override string toString() { result = "... is ..." } +module Impl { + class IsExpr extends Generated::IsExpr { + override string toString() { result = "... is ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/KeyPathApplicationExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/KeyPathApplicationExprImpl.qll index 1f996cf1e7d50..f94532ccbcd95 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/KeyPathApplicationExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/KeyPathApplicationExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.KeyPathApplicationExpr -class KeyPathApplicationExpr extends Generated::KeyPathApplicationExpr { - override string toString() { result = "\\...[...]" } +module Impl { + class KeyPathApplicationExpr extends Generated::KeyPathApplicationExpr { + override string toString() { result = "\\...[...]" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/KeyPathDotExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/KeyPathDotExprImpl.qll index 535d393e05774..105644cfed0eb 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/KeyPathDotExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/KeyPathDotExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.KeyPathDotExpr -class KeyPathDotExpr extends Generated::KeyPathDotExpr { - override string toString() { result = "\\...." } +module Impl { + class KeyPathDotExpr extends Generated::KeyPathDotExpr { + override string toString() { result = "\\...." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/KeyPathExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/KeyPathExprImpl.qll index 889fa973f76a1..88a526cc32401 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/KeyPathExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/KeyPathExprImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.expr.KeyPathExpr -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A key-path expression. - */ -class KeyPathExpr extends Generated::KeyPathExpr { - override string toString() { result = "#keyPath(...)" } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * A key-path expression. + */ + class KeyPathExpr extends Generated::KeyPathExpr { + override string toString() { result = "#keyPath(...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/LazyInitializationExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/LazyInitializationExprImpl.qll index 43ecade877969..ed81fc84c287a 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/LazyInitializationExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/LazyInitializationExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.LazyInitializationExpr -class LazyInitializationExpr extends Generated::LazyInitializationExpr { - override string toString() { result = this.getSubExpr().toString() } +module Impl { + class LazyInitializationExpr extends Generated::LazyInitializationExpr { + override string toString() { result = this.getSubExpr().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/LiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/LiteralExprImpl.qll index 632d65b8e0f6c..a85174c4b6362 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/LiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/LiteralExprImpl.qll @@ -4,9 +4,11 @@ private import codeql.swift.generated.expr.LiteralExpr -/** - * A Swift literal. - * - * This is the root class for all literals. - */ -class LiteralExpr extends Generated::LiteralExpr { } +module Impl { + /** + * A Swift literal. + * + * This is the root class for all literals. + */ + class LiteralExpr extends Generated::LiteralExpr { } +} diff --git a/swift/ql/lib/codeql/swift/elements/expr/MagicIdentifierLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/MagicIdentifierLiteralExprImpl.qll index acbff48d149d8..3e561f5f5b038 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/MagicIdentifierLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/MagicIdentifierLiteralExprImpl.qll @@ -1,13 +1,15 @@ private import codeql.swift.generated.expr.MagicIdentifierLiteralExpr -/** - * An identifier literal that is expanded at compile time. For example `#file` in: - * ``` - * let x = #file - * ``` - */ -class MagicIdentifierLiteralExpr extends Generated::MagicIdentifierLiteralExpr { - override string toString() { result = "#..." } +module Impl { + /** + * An identifier literal that is expanded at compile time. For example `#file` in: + * ``` + * let x = #file + * ``` + */ + class MagicIdentifierLiteralExpr extends Generated::MagicIdentifierLiteralExpr { + override string toString() { result = "#..." } - override string getValueString() { none() } // TODO: value not yet extracted + override string getValueString() { none() } // TODO: value not yet extracted + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/MakeTemporarilyEscapableExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/MakeTemporarilyEscapableExprImpl.qll index a38e5b3ad293e..e9e036bf055ed 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/MakeTemporarilyEscapableExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/MakeTemporarilyEscapableExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.MakeTemporarilyEscapableExpr -class MakeTemporarilyEscapableExpr extends Generated::MakeTemporarilyEscapableExpr { - override string toString() { result = this.getSubExpr().toString() } +module Impl { + class MakeTemporarilyEscapableExpr extends Generated::MakeTemporarilyEscapableExpr { + override string toString() { result = this.getSubExpr().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/MemberRefExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/MemberRefExprImpl.qll index acbe3cb943c2f..1304062a7a9ed 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/MemberRefExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/MemberRefExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.MemberRefExpr -class MemberRefExpr extends Generated::MemberRefExpr { - override string toString() { result = "." + this.getMember().toString() } +module Impl { + class MemberRefExpr extends Generated::MemberRefExpr { + override string toString() { result = "." + this.getMember().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/MethodLookupExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/MethodLookupExprImpl.qll index ba036ddafcf1f..3818817adae11 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/MethodLookupExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/MethodLookupExprImpl.qll @@ -7,25 +7,27 @@ private import codeql.swift.elements.decl.Method private import codeql.swift.generated.Raw private import codeql.swift.generated.Synth -class MethodLookupExpr extends Generated::MethodLookupExpr { - override string toString() { result = "." + this.getMember().toString() } +module Impl { + class MethodLookupExpr extends Generated::MethodLookupExpr { + override string toString() { result = "." + this.getMember().toString() } - override Expr getImmediateBase() { - result = Synth::convertExprFromRaw(this.getUnderlying().getBase()) - } + override Expr getImmediateBase() { + result = Synth::convertExprFromRaw(this.getUnderlying().getBase()) + } - override Decl getMember() { - result = this.getMethodRef().(DeclRefExpr).getDecl() - or - result = this.getMethodRef().(OtherInitializerRefExpr).getInitializer() - } + override Decl getMember() { + result = this.getMethodRef().(DeclRefExpr).getDecl() + or + result = this.getMethodRef().(OtherInitializerRefExpr).getInitializer() + } - override Expr getImmediateMethodRef() { - result = Synth::convertExprFromRaw(this.getUnderlying().getFunction()) - } + override Expr getImmediateMethodRef() { + result = Synth::convertExprFromRaw(this.getUnderlying().getFunction()) + } - Method getMethod() { result = this.getMember() } + Method getMethod() { result = this.getMember() } - cached - private Raw::SelfApplyExpr getUnderlying() { this = Synth::TMethodLookupExpr(result) } + cached + private Raw::SelfApplyExpr getUnderlying() { this = Synth::TMethodLookupExpr(result) } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/NilLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/NilLiteralExprImpl.qll index 6f264279f1e25..a80b29f1ab758 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/NilLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/NilLiteralExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.NilLiteralExpr -class NilLiteralExpr extends Generated::NilLiteralExpr { - override string toString() { result = "nil" } +module Impl { + class NilLiteralExpr extends Generated::NilLiteralExpr { + override string toString() { result = "nil" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ObjCSelectorExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ObjCSelectorExprImpl.qll index f57555858dabc..9d96b84a2f045 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ObjCSelectorExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ObjCSelectorExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.ObjCSelectorExpr -class ObjCSelectorExpr extends Generated::ObjCSelectorExpr { - override string toString() { result = "#selector(...)" } +module Impl { + class ObjCSelectorExpr extends Generated::ObjCSelectorExpr { + override string toString() { result = "#selector(...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ObjectLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ObjectLiteralExprImpl.qll index 183bdb49310d8..2d29e1a0cf530 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ObjectLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ObjectLiteralExprImpl.qll @@ -1,25 +1,27 @@ private import codeql.swift.generated.expr.ObjectLiteralExpr -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * An instance of `#fileLiteral`, `#imageLiteral` or `#colorLiteral` expressions, which are used in playgrounds. - */ -class ObjectLiteralExpr extends Generated::ObjectLiteralExpr { } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * An instance of `#fileLiteral`, `#imageLiteral` or `#colorLiteral` expressions, which are used in playgrounds. + */ + class ObjectLiteralExpr extends Generated::ObjectLiteralExpr { } -class FileLiteralExpr extends ObjectLiteralExpr { - FileLiteralExpr() { this.getKind() = 0 } + class FileLiteralExpr extends ObjectLiteralExpr { + FileLiteralExpr() { this.getKind() = 0 } - override string toString() { result = "#fileLiteral(...)" } -} + override string toString() { result = "#fileLiteral(...)" } + } -class ImageLiteralExpr extends ObjectLiteralExpr { - ImageLiteralExpr() { this.getKind() = 1 } + class ImageLiteralExpr extends ObjectLiteralExpr { + ImageLiteralExpr() { this.getKind() = 1 } - override string toString() { result = "#imageLiteral(...)" } -} + override string toString() { result = "#imageLiteral(...)" } + } -class ColorLiteralExpr extends ObjectLiteralExpr { - ColorLiteralExpr() { this.getKind() = 2 } + class ColorLiteralExpr extends ObjectLiteralExpr { + ColorLiteralExpr() { this.getKind() = 2 } - override string toString() { result = "#colorLiteral(...)" } + override string toString() { result = "#colorLiteral(...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/OneWayExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/OneWayExprImpl.qll index 27efdd4d402eb..f69a19547fe77 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/OneWayExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/OneWayExprImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.expr.OneWayExpr -class OneWayExpr extends Generated::OneWayExpr { - override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } +module Impl { + class OneWayExpr extends Generated::OneWayExpr { + override predicate convertsFrom(Expr e) { e = this.getImmediateSubExpr() } - override string toString() { result = this.getSubExpr().toString() } + override string toString() { result = this.getSubExpr().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/OptionalTryExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/OptionalTryExprImpl.qll index 98388c788588f..2e92c82e5a30a 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/OptionalTryExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/OptionalTryExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.OptionalTryExpr -class OptionalTryExpr extends Generated::OptionalTryExpr { - override string toString() { result = "try? ..." } +module Impl { + class OptionalTryExpr extends Generated::OptionalTryExpr { + override string toString() { result = "try? ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/OtherInitializerRefExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/OtherInitializerRefExprImpl.qll index 088dd30f486b1..50c9355f438ef 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/OtherInitializerRefExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/OtherInitializerRefExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.OtherInitializerRefExpr -class OtherInitializerRefExpr extends Generated::OtherInitializerRefExpr { - override string toString() { result = this.getInitializer().toString() } +module Impl { + class OtherInitializerRefExpr extends Generated::OtherInitializerRefExpr { + override string toString() { result = this.getInitializer().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/ParenExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/ParenExprImpl.qll index 072f47dd1bd9a..0db93aeb20c2c 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/ParenExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/ParenExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.ParenExpr -class ParenExpr extends Generated::ParenExpr { - override string toString() { result = "(...)" } +module Impl { + class ParenExpr extends Generated::ParenExpr { + override string toString() { result = "(...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExprImpl.qll index 1358f385fc94d..26a303d6f462e 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/PostfixUnaryExprImpl.qll @@ -2,21 +2,23 @@ private import codeql.swift.generated.expr.PostfixUnaryExpr private import codeql.swift.elements.expr.Expr private import codeql.swift.elements.decl.Function -/** - * A Swift postfix unary expression, that is, a unary expression that appears - * after its operand. For example: - * ``` - * x! - * ``` - */ -class PostfixUnaryExpr extends Generated::PostfixUnaryExpr { +module Impl { /** - * Gets the operand (expression) of this postfix unary expression. + * A Swift postfix unary expression, that is, a unary expression that appears + * after its operand. For example: + * ``` + * x! + * ``` */ - Expr getOperand() { result = this.getAnArgument().getExpr() } + class PostfixUnaryExpr extends Generated::PostfixUnaryExpr { + /** + * Gets the operand (expression) of this postfix unary expression. + */ + Expr getOperand() { result = this.getAnArgument().getExpr() } - /** - * Gets the operator of this postfix unary expression (the function that is called). - */ - Function getOperator() { result = this.getStaticTarget() } + /** + * Gets the operator of this postfix unary expression (the function that is called). + */ + Function getOperator() { result = this.getStaticTarget() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExprImpl.qll index 64b01eb263970..18dda27d4d59c 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/PrefixUnaryExprImpl.qll @@ -2,23 +2,25 @@ private import codeql.swift.generated.expr.PrefixUnaryExpr private import codeql.swift.elements.expr.Expr private import codeql.swift.elements.decl.Function -/** - * A Swift prefix unary expression, that is, a unary expression that appears - * before its operand. For example: - * ``` - * -x - * ``` - */ -class PrefixUnaryExpr extends Generated::PrefixUnaryExpr { +module Impl { /** - * Gets the operand (expression) of this prefix unary expression. + * A Swift prefix unary expression, that is, a unary expression that appears + * before its operand. For example: + * ``` + * -x + * ``` */ - Expr getOperand() { result = this.getAnArgument().getExpr() } + class PrefixUnaryExpr extends Generated::PrefixUnaryExpr { + /** + * Gets the operand (expression) of this prefix unary expression. + */ + Expr getOperand() { result = this.getAnArgument().getExpr() } - /** - * Gets the operator of this prefix unary expression (the function that is called). - */ - Function getOperator() { result = this.getStaticTarget() } + /** + * Gets the operator of this prefix unary expression (the function that is called). + */ + Function getOperator() { result = this.getStaticTarget() } - override Function getStaticTarget() { result = super.getStaticTarget() } + override Function getStaticTarget() { result = super.getStaticTarget() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/RebindSelfInInitializerExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/RebindSelfInInitializerExprImpl.qll index 25d20434189e0..7b74336ceedf7 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/RebindSelfInInitializerExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/RebindSelfInInitializerExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.RebindSelfInInitializerExpr -class RebindSelfInInitializerExpr extends Generated::RebindSelfInInitializerExpr { - override string toString() { result = "self = ..." } +module Impl { + class RebindSelfInInitializerExpr extends Generated::RebindSelfInInitializerExpr { + override string toString() { result = "self = ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/RegexLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/RegexLiteralExprImpl.qll index af8e18e42ee37..8d2271838aef1 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/RegexLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/RegexLiteralExprImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.expr.RegexLiteralExpr -// the following QLdoc is generated: if you need to edit it, do it in the schema file -/** - * A regular expression literal which is checked at compile time, for example `/a(a|b)*b/`. - */ -class RegexLiteralExpr extends Generated::RegexLiteralExpr { - override string toString() { result = this.getPattern() } +module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file + /** + * A regular expression literal which is checked at compile time, for example `/a(a|b)*b/`. + */ + class RegexLiteralExpr extends Generated::RegexLiteralExpr { + override string toString() { result = this.getPattern() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/StringLiteralExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/StringLiteralExprImpl.qll index c3ead49febbed..3e8f6e7592ec0 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/StringLiteralExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/StringLiteralExprImpl.qll @@ -1,13 +1,15 @@ private import codeql.swift.generated.expr.StringLiteralExpr -/** - * A string literal. For example `"abc"` in: - * ``` - * let x = "abc" - * ``` - */ -class StringLiteralExpr extends Generated::StringLiteralExpr { - override string toString() { result = this.getValue() } +module Impl { + /** + * A string literal. For example `"abc"` in: + * ``` + * let x = "abc" + * ``` + */ + class StringLiteralExpr extends Generated::StringLiteralExpr { + override string toString() { result = this.getValue() } - override string getValueString() { result = this.getValue() } + override string getValueString() { result = this.getValue() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/SubscriptExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/SubscriptExprImpl.qll index 143e18523f823..34e19ccfe61c4 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/SubscriptExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/SubscriptExprImpl.qll @@ -1,19 +1,21 @@ private import codeql.swift.generated.expr.SubscriptExpr -class SubscriptExpr extends Generated::SubscriptExpr { - Argument getFirstArgument() { - exists(int i | - result = this.getArgument(i) and - not exists(this.getArgument(i - 1)) - ) - } +module Impl { + class SubscriptExpr extends Generated::SubscriptExpr { + Argument getFirstArgument() { + exists(int i | + result = this.getArgument(i) and + not exists(this.getArgument(i - 1)) + ) + } - Argument getLastArgument() { - exists(int i | - result = this.getArgument(i) and - not exists(this.getArgument(i + 1)) - ) - } + Argument getLastArgument() { + exists(int i | + result = this.getArgument(i) and + not exists(this.getArgument(i + 1)) + ) + } - override string toString() { result = "...[...]" } + override string toString() { result = "...[...]" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/SuperRefExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/SuperRefExprImpl.qll index 5931f68488b21..d1afe5938967f 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/SuperRefExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/SuperRefExprImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.expr.SuperRefExpr private import codeql.swift.elements.decl.Method -/** A reference to `super`. */ -class SuperRefExpr extends Generated::SuperRefExpr { - override string toString() { result = "super" } +module Impl { + /** A reference to `super`. */ + class SuperRefExpr extends Generated::SuperRefExpr { + override string toString() { result = "super" } - Method getDeclaringMethod() { this.getSelf() = result.getSelfParam() } + Method getDeclaringMethod() { this.getSelf() = result.getSelfParam() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/TapExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/TapExprImpl.qll index 9dc8f0a44a424..2d109e0f2b625 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/TapExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/TapExprImpl.qll @@ -1,11 +1,13 @@ private import codeql.swift.generated.expr.TapExpr -/** - * A `TapExpr` is an internal expression generated by the Swift compiler. - * - * If `e` is a `TapExpr`, the semantics of evaluating `e` is: - * 1. Create a local variable `e.getVar()` and assign it the value `e.getSubExpr()`. - * 2. Execute `e.getBody()` which potentially modifies the local variable. - * 3. Return the value of the local variable. - */ -class TapExpr extends Generated::TapExpr { } +module Impl { + /** + * A `TapExpr` is an internal expression generated by the Swift compiler. + * + * If `e` is a `TapExpr`, the semantics of evaluating `e` is: + * 1. Create a local variable `e.getVar()` and assign it the value `e.getSubExpr()`. + * 2. Execute `e.getBody()` which potentially modifies the local variable. + * 3. Return the value of the local variable. + */ + class TapExpr extends Generated::TapExpr { } +} diff --git a/swift/ql/lib/codeql/swift/elements/expr/TryExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/TryExprImpl.qll index 88f3955ba45e4..b372e4f22e7b9 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/TryExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/TryExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.TryExpr -class TryExpr extends Generated::TryExpr { - override string toString() { result = "try ..." } +module Impl { + class TryExpr extends Generated::TryExpr { + override string toString() { result = "try ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/TupleElementExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/TupleElementExprImpl.qll index d2dd365234af5..18ff29f6832d6 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/TupleElementExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/TupleElementExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.TupleElementExpr -class TupleElementExpr extends Generated::TupleElementExpr { - override string toString() { result = "." + this.getIndex() } +module Impl { + class TupleElementExpr extends Generated::TupleElementExpr { + override string toString() { result = "." + this.getIndex() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/TupleExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/TupleExprImpl.qll index 0431ad5eb58fe..f2322ef2de1f3 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/TupleExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/TupleExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.TupleExpr -class TupleExpr extends Generated::TupleExpr { - override string toString() { result = "(...)" } +module Impl { + class TupleExpr extends Generated::TupleExpr { + override string toString() { result = "(...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/TypeExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/TypeExprImpl.qll index 1930c055f1c98..d2e3ad63ebeeb 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/TypeExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/TypeExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.TypeExpr -class TypeExpr extends Generated::TypeExpr { - override string toString() { result = this.getType().toString() } +module Impl { + class TypeExpr extends Generated::TypeExpr { + override string toString() { result = this.getType().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDeclRefExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDeclRefExprImpl.qll index 879ca417e7b25..92a534e9226ff 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDeclRefExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDeclRefExprImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.expr.UnresolvedDeclRefExpr -class UnresolvedDeclRefExpr extends Generated::UnresolvedDeclRefExpr { - override string toString() { - result = this.getName() + " (unresolved)" - or - not this.hasName() and result = "(unresolved)" +module Impl { + class UnresolvedDeclRefExpr extends Generated::UnresolvedDeclRefExpr { + override string toString() { + result = this.getName() + " (unresolved)" + or + not this.hasName() and result = "(unresolved)" + } } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDotExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDotExprImpl.qll index 82dcc0b4eec68..4ecd37ad0f72f 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDotExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/UnresolvedDotExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.UnresolvedDotExpr -class UnresolvedDotExpr extends Generated::UnresolvedDotExpr { - override string toString() { result = "... ." + this.getName() } +module Impl { + class UnresolvedDotExpr extends Generated::UnresolvedDotExpr { + override string toString() { result = "... ." + this.getName() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/expr/VarargExpansionExprImpl.qll b/swift/ql/lib/codeql/swift/elements/expr/VarargExpansionExprImpl.qll index 2547237c1e8ab..98ceee8e8e7b6 100644 --- a/swift/ql/lib/codeql/swift/elements/expr/VarargExpansionExprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/expr/VarargExpansionExprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.expr.VarargExpansionExpr -class VarargExpansionExpr extends Generated::VarargExpansionExpr { - override string toString() { result = this.getSubExpr().toString() } +module Impl { + class VarargExpansionExpr extends Generated::VarargExpansionExpr { + override string toString() { result = this.getSubExpr().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/AnyPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/AnyPatternImpl.qll index 0f57e9c7f832c..98e755da2c618 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/AnyPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/AnyPatternImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.pattern.AnyPattern -class AnyPattern extends Generated::AnyPattern { - override string toString() { result = "_" } +module Impl { + class AnyPattern extends Generated::AnyPattern { + override string toString() { result = "_" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/BindingPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/BindingPatternImpl.qll index 9f0cd057c3d6f..b896afe519020 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/BindingPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/BindingPatternImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.pattern.BindingPattern -class BindingPattern extends Generated::BindingPattern { - final override Pattern getResolveStep() { result = this.getImmediateSubPattern() } +module Impl { + class BindingPattern extends Generated::BindingPattern { + final override Pattern getResolveStep() { result = this.getImmediateSubPattern() } - override string toString() { result = "let ..." } + override string toString() { result = "let ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/BoolPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/BoolPatternImpl.qll index bbe3e57291f7e..471993c4b3b8b 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/BoolPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/BoolPatternImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.pattern.BoolPattern -class BoolPattern extends Generated::BoolPattern { - override string toString() { result = this.getValue().toString() } +module Impl { + class BoolPattern extends Generated::BoolPattern { + override string toString() { result = this.getValue().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/EnumElementPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/EnumElementPatternImpl.qll index 7321341abf2f9..c46a0b85a0886 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/EnumElementPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/EnumElementPatternImpl.qll @@ -1,22 +1,24 @@ private import codeql.swift.generated.pattern.EnumElementPattern private import codeql.swift.elements.pattern.TuplePattern -class EnumElementPattern extends Generated::EnumElementPattern { - /** - * Gets the `i`th element (0-based) of this enum element's tuple - * sub-pattern, if any, or the sub-pattern itself if it is not a tuple pattern. - */ - Pattern getSubPattern(int i) { - result = this.getSubPattern().(TuplePattern).getElement(i) - or - not this.getSubPattern() instanceof TuplePattern and - result = this.getSubPattern() and - i = 0 - } +module Impl { + class EnumElementPattern extends Generated::EnumElementPattern { + /** + * Gets the `i`th element (0-based) of this enum element's tuple + * sub-pattern, if any, or the sub-pattern itself if it is not a tuple pattern. + */ + Pattern getSubPattern(int i) { + result = this.getSubPattern().(TuplePattern).getElement(i) + or + not this.getSubPattern() instanceof TuplePattern and + result = this.getSubPattern() and + i = 0 + } - override string toString() { - if this.hasSubPattern() - then result = "." + this.getElement().toString() + "(...)" - else result = "." + this.getElement().toString() + override string toString() { + if this.hasSubPattern() + then result = "." + this.getElement().toString() + "(...)" + else result = "." + this.getElement().toString() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/ExprPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/ExprPatternImpl.qll index 16e0d3f024bfe..e313a5ce10da0 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/ExprPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/ExprPatternImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.pattern.ExprPattern -class ExprPattern extends Generated::ExprPattern { - override string toString() { result = "=~ ..." } +module Impl { + class ExprPattern extends Generated::ExprPattern { + override string toString() { result = "=~ ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/IsPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/IsPatternImpl.qll index c594952d83f53..9fb6e84cc2388 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/IsPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/IsPatternImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.pattern.IsPattern -class IsPattern extends Generated::IsPattern { - override string toString() { result = "... is ..." } +module Impl { + class IsPattern extends Generated::IsPattern { + override string toString() { result = "... is ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/NamedPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/NamedPatternImpl.qll index 689ebb8ab2953..fc6ebb52e7a6e 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/NamedPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/NamedPatternImpl.qll @@ -1,24 +1,26 @@ private import codeql.swift.generated.pattern.NamedPattern private import codeql.swift.elements.decl.VarDecl -/** - * A pattern that corresponds to a fresh variable binding. - * - * For example, `x` as in `if case let .some(x) = ...` is a `NamedPattern`, - * whereas `y` as in `if case .some(y) = ...` is instead an `ExprPattern`. - */ -class NamedPattern extends Generated::NamedPattern { +module Impl { /** - * Holds if this named pattern has a corresponding `VarDecl`, which is currently always true. + * A pattern that corresponds to a fresh variable binding. * - * DEPRECATED: unless there was a compilation error, this will always hold. + * For example, `x` as in `if case let .some(x) = ...` is a `NamedPattern`, + * whereas `y` as in `if case .some(y) = ...` is instead an `ExprPattern`. */ - deprecated predicate hasVarDecl() { exists(this.getVarDecl()) } + class NamedPattern extends Generated::NamedPattern { + /** + * Holds if this named pattern has a corresponding `VarDecl`, which is currently always true. + * + * DEPRECATED: unless there was a compilation error, this will always hold. + */ + deprecated predicate hasVarDecl() { exists(this.getVarDecl()) } - /** - * Gets the name of the variable bound by this pattern. - */ - string getName() { result = this.getVarDecl().getName() } + /** + * Gets the name of the variable bound by this pattern. + */ + string getName() { result = this.getVarDecl().getName() } - override string toString() { result = this.getName() } + override string toString() { result = this.getName() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/OptionalSomePatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/OptionalSomePatternImpl.qll index 870e24766a091..1c8aee702b009 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/OptionalSomePatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/OptionalSomePatternImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.pattern.OptionalSomePattern -class OptionalSomePattern extends Generated::OptionalSomePattern { - override string toString() { result = "let ...?" } +module Impl { + class OptionalSomePattern extends Generated::OptionalSomePattern { + override string toString() { result = "let ...?" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/ParenPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/ParenPatternImpl.qll index 40ffc318df1e7..fd5c9ab544317 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/ParenPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/ParenPatternImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.pattern.ParenPattern -class ParenPattern extends Generated::ParenPattern { - final override Pattern getResolveStep() { result = this.getImmediateSubPattern() } +module Impl { + class ParenPattern extends Generated::ParenPattern { + final override Pattern getResolveStep() { result = this.getImmediateSubPattern() } - override string toString() { result = "(...)" } + override string toString() { result = "(...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/PatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/PatternImpl.qll index 5136ee7123441..173254b84b3b4 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/PatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/PatternImpl.qll @@ -18,94 +18,96 @@ private import codeql.swift.elements.decl.PatternBindingDecl private import codeql.swift.elements.decl.EnumElementDecl private import codeql.swift.generated.ParentChild -/** - * A syntactic construct that can be matched against an expression, - * occurring in switch cases, conditions, and variable bindings. - */ -class Pattern extends Generated::Pattern { +module Impl { /** - * Gets the expression that this top-level pattern is matched against, if any. - * - * For example, in `switch e { case p: ... }`, the pattern `p` - * is immediately matched against the expression `e`. + * A syntactic construct that can be matched against an expression, + * occurring in switch cases, conditions, and variable bindings. */ - Expr getImmediateMatchingExpr() { - exists(ConditionElement c | - c.getPattern() = this and - result = c.getInitializer() - ) - or - exists(SwitchStmt s | - s.getExpr() = result and - s.getACase().getALabel().getPattern() = this - ) - or - exists(PatternBindingDecl v, int i | - v.getPattern(i) = pragma[only_bind_out](this) and - result = v.getInit(i) - ) - } + class Pattern extends Generated::Pattern { + /** + * Gets the expression that this top-level pattern is matched against, if any. + * + * For example, in `switch e { case p: ... }`, the pattern `p` + * is immediately matched against the expression `e`. + */ + Expr getImmediateMatchingExpr() { + exists(ConditionElement c | + c.getPattern() = this and + result = c.getInitializer() + ) + or + exists(SwitchStmt s | + s.getExpr() = result and + s.getACase().getALabel().getPattern() = this + ) + or + exists(PatternBindingDecl v, int i | + v.getPattern(i) = pragma[only_bind_out](this) and + result = v.getInit(i) + ) + } - /** - * Gets the expression that this pattern is matched against, if any. - * The expression and the pattern need not be top-level children of - * a pattern-matching construct, but they must match each other syntactically. - * - * For example, in `switch .some(e) { case let .some(p): ... }`, the pattern `p` - * is matched against the expression `e`. - */ - pragma[nomagic] - Expr getMatchingExpr() { - result = this.getImmediateMatchingExpr() - or - exists(Pattern p | p.getMatchingExpr() = result | - this = p.(IsPattern).getSubPattern() + /** + * Gets the expression that this pattern is matched against, if any. + * The expression and the pattern need not be top-level children of + * a pattern-matching construct, but they must match each other syntactically. + * + * For example, in `switch .some(e) { case let .some(p): ... }`, the pattern `p` + * is matched against the expression `e`. + */ + pragma[nomagic] + Expr getMatchingExpr() { + result = this.getImmediateMatchingExpr() or - this = p.(OptionalSomePattern).getSubPattern() + exists(Pattern p | p.getMatchingExpr() = result | + this = p.(IsPattern).getSubPattern() + or + this = p.(OptionalSomePattern).getSubPattern() + or + this = p.(TypedPattern).getSubPattern() + ) or - this = p.(TypedPattern).getSubPattern() - ) - or - exists(TuplePattern p, TupleExpr e, int i | - p.getMatchingExpr() = e and - this = p.getElement(i) and - result = e.getElement(i) - ) - or - exists(EnumElementPattern p, EnumElementExpr e, int i | - p.getMatchingExpr() = e and - this = p.getSubPattern(i) and - result = e.getArgument(i).getExpr() and - p.getElement() = e.getElement() - ) - } + exists(TuplePattern p, TupleExpr e, int i | + p.getMatchingExpr() = e and + this = p.getElement(i) and + result = e.getElement(i) + ) + or + exists(EnumElementPattern p, EnumElementExpr e, int i | + p.getMatchingExpr() = e and + this = p.getSubPattern(i) and + result = e.getArgument(i).getExpr() and + p.getElement() = e.getElement() + ) + } - /** Holds if this pattern is matched against an expression. */ - final predicate hasMatchingExpr() { exists(this.getMatchingExpr()) } + /** Holds if this pattern is matched against an expression. */ + final predicate hasMatchingExpr() { exists(this.getMatchingExpr()) } - /** - * Gets the parent pattern of this pattern, if any. - */ - final Pattern getEnclosingPattern() { - result = this.getFullyUnresolved().(Pattern).getImmediateEnclosingPattern() - } + /** + * Gets the parent pattern of this pattern, if any. + */ + final Pattern getEnclosingPattern() { + result = this.getFullyUnresolved().(Pattern).getImmediateEnclosingPattern() + } - /** - * Gets the parent pattern of this pattern, if any. - */ - Pattern getImmediateEnclosingPattern() { - this = result.(EnumElementPattern).getImmediateSubPattern() - or - this = result.(OptionalSomePattern).getImmediateSubPattern() - or - this = result.(TuplePattern).getImmediateElement(_) - or - this = result.(BindingPattern).getImmediateSubPattern() - or - this = result.(IsPattern).getImmediateSubPattern() - or - this = result.(ParenPattern).getImmediateSubPattern() - or - this = result.(TypedPattern).getImmediateSubPattern() + /** + * Gets the parent pattern of this pattern, if any. + */ + Pattern getImmediateEnclosingPattern() { + this = result.(EnumElementPattern).getImmediateSubPattern() + or + this = result.(OptionalSomePattern).getImmediateSubPattern() + or + this = result.(TuplePattern).getImmediateElement(_) + or + this = result.(BindingPattern).getImmediateSubPattern() + or + this = result.(IsPattern).getImmediateSubPattern() + or + this = result.(ParenPattern).getImmediateSubPattern() + or + this = result.(TypedPattern).getImmediateSubPattern() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/TuplePatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/TuplePatternImpl.qll index 03579631ca0a7..6ed969e4a106c 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/TuplePatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/TuplePatternImpl.qll @@ -1,14 +1,16 @@ private import codeql.swift.generated.pattern.TuplePattern -class TuplePattern extends Generated::TuplePattern { - Pattern getFirstElement() { result = this.getElement(0) } +module Impl { + class TuplePattern extends Generated::TuplePattern { + Pattern getFirstElement() { result = this.getElement(0) } - Pattern getLastElement() { - exists(int i | - result = this.getElement(i) and - not exists(this.getElement(i + 1)) - ) - } + Pattern getLastElement() { + exists(int i | + result = this.getElement(i) and + not exists(this.getElement(i + 1)) + ) + } - override string toString() { result = "(...)" } + override string toString() { result = "(...)" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/pattern/TypedPatternImpl.qll b/swift/ql/lib/codeql/swift/elements/pattern/TypedPatternImpl.qll index 852437a60f1f2..49b905f8d643d 100644 --- a/swift/ql/lib/codeql/swift/elements/pattern/TypedPatternImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/pattern/TypedPatternImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.pattern.TypedPattern -class TypedPattern extends Generated::TypedPattern { - override string toString() { - if exists(this.getSubPattern()) then result = "... as ..." else result = "is ..." +module Impl { + class TypedPattern extends Generated::TypedPattern { + override string toString() { + if exists(this.getSubPattern()) then result = "... as ..." else result = "is ..." + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/BraceStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/BraceStmtImpl.qll index 87bbfac852863..6f4cdbd377423 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/BraceStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/BraceStmtImpl.qll @@ -1,33 +1,35 @@ private import codeql.swift.generated.stmt.BraceStmt -class BraceStmt extends Generated::BraceStmt { - AstNode getFirstElement() { result = this.getElement(0) } +module Impl { + class BraceStmt extends Generated::BraceStmt { + AstNode getFirstElement() { result = this.getElement(0) } - AstNode getLastElement() { - exists(int i | - result = this.getElement(i) and - not exists(this.getElement(i + 1)) - ) - } + AstNode getLastElement() { + exists(int i | + result = this.getElement(i) and + not exists(this.getElement(i + 1)) + ) + } - override string toString() { result = "{ ... }" } + override string toString() { result = "{ ... }" } - override AstNode getImmediateElement(int index) { - result = - rank[index + 1](AstNode element, int i | - element = super.getImmediateElement(i) and - not element instanceof VarDecl - | - element order by i - ) - } + override AstNode getImmediateElement(int index) { + result = + rank[index + 1](AstNode element, int i | + element = super.getImmediateElement(i) and + not element instanceof VarDecl + | + element order by i + ) + } - override VarDecl getVariable(int index) { - result = - rank[index + 1](VarDecl variable, int i | - variable = super.getImmediateElement(i) - | - variable order by i - ) + override VarDecl getVariable(int index) { + result = + rank[index + 1](VarDecl variable, int i | + variable = super.getImmediateElement(i) + | + variable order by i + ) + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/BreakStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/BreakStmtImpl.qll index a92663eb72474..6f1b58aecd4e8 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/BreakStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/BreakStmtImpl.qll @@ -1,10 +1,12 @@ private import codeql.swift.generated.stmt.BreakStmt -class BreakStmt extends Generated::BreakStmt { - override string toString() { - result = "break " + this.getTargetName() - or - not this.hasTargetName() and - result = "break" +module Impl { + class BreakStmt extends Generated::BreakStmt { + override string toString() { + result = "break " + this.getTargetName() + or + not this.hasTargetName() and + result = "break" + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/CaseLabelItemImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/CaseLabelItemImpl.qll index bdd176d322a86..003d2b342b162 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/CaseLabelItemImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/CaseLabelItemImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.stmt.CaseLabelItem -class CaseLabelItem extends Generated::CaseLabelItem { - override string toString() { - if this.hasGuard() - then result = this.getPattern().toString() + " where ..." - else result = this.getPattern().toString() +module Impl { + class CaseLabelItem extends Generated::CaseLabelItem { + override string toString() { + if this.hasGuard() + then result = this.getPattern().toString() + " where ..." + else result = this.getPattern().toString() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/CaseStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/CaseStmtImpl.qll index 6236178ebb38b..17b9b64621444 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/CaseStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/CaseStmtImpl.qll @@ -1,14 +1,16 @@ private import codeql.swift.generated.stmt.CaseStmt -class CaseStmt extends Generated::CaseStmt { - CaseLabelItem getFirstLabel() { result = this.getLabel(0) } +module Impl { + class CaseStmt extends Generated::CaseStmt { + CaseLabelItem getFirstLabel() { result = this.getLabel(0) } - CaseLabelItem getLastLabel() { - exists(int i | - result = this.getLabel(i) and - not exists(this.getLabel(i + 1)) - ) - } + CaseLabelItem getLastLabel() { + exists(int i | + result = this.getLabel(i) and + not exists(this.getLabel(i + 1)) + ) + } - override string toString() { result = "case ..." } + override string toString() { result = "case ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/ConditionElementImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/ConditionElementImpl.qll index 2ee722f58a213..72740933998de 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/ConditionElementImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/ConditionElementImpl.qll @@ -1,12 +1,14 @@ private import codeql.swift.generated.stmt.ConditionElement private import codeql.swift.elements.AstNode -class ConditionElement extends Generated::ConditionElement { - override string toString() { - result = this.getBoolean().toString() - or - result = this.getPattern().toString() + " = ... " - or - result = this.getAvailability().toString() +module Impl { + class ConditionElement extends Generated::ConditionElement { + override string toString() { + result = this.getBoolean().toString() + or + result = this.getPattern().toString() + " = ... " + or + result = this.getAvailability().toString() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/ContinueStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/ContinueStmtImpl.qll index 44311720dd631..58747a44e4205 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/ContinueStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/ContinueStmtImpl.qll @@ -1,10 +1,12 @@ private import codeql.swift.generated.stmt.ContinueStmt -class ContinueStmt extends Generated::ContinueStmt { - override string toString() { - result = "continue " + this.getTargetName() - or - not this.hasTargetName() and - result = "continue" +module Impl { + class ContinueStmt extends Generated::ContinueStmt { + override string toString() { + result = "continue " + this.getTargetName() + or + not this.hasTargetName() and + result = "continue" + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/DeferStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/DeferStmtImpl.qll index 2f10e41750662..97e565d4160f8 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/DeferStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/DeferStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.DeferStmt -class DeferStmt extends Generated::DeferStmt { - override string toString() { result = "defer { ... }" } +module Impl { + class DeferStmt extends Generated::DeferStmt { + override string toString() { result = "defer { ... }" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/DoCatchStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/DoCatchStmtImpl.qll index 3795087b97bd8..20fb2b8ddbc39 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/DoCatchStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/DoCatchStmtImpl.qll @@ -1,14 +1,16 @@ private import codeql.swift.generated.stmt.DoCatchStmt -class DoCatchStmt extends Generated::DoCatchStmt { - CaseStmt getFirstCatch() { result = this.getCatch(0) } +module Impl { + class DoCatchStmt extends Generated::DoCatchStmt { + CaseStmt getFirstCatch() { result = this.getCatch(0) } - CaseStmt getLastCatch() { - exists(int i | - result = this.getCatch(i) and - not exists(this.getCatch(i + 1)) - ) - } + CaseStmt getLastCatch() { + exists(int i | + result = this.getCatch(i) and + not exists(this.getCatch(i + 1)) + ) + } - override string toString() { result = "do { ... } catch { ... }" } + override string toString() { result = "do { ... } catch { ... }" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/DoStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/DoStmtImpl.qll index 275f5dd53adbd..0e43521181fa5 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/DoStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/DoStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.DoStmt -class DoStmt extends Generated::DoStmt { - override string toString() { result = "do { ... }" } +module Impl { + class DoStmt extends Generated::DoStmt { + override string toString() { result = "do { ... }" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/FailStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/FailStmtImpl.qll index 8fa73e170c8cf..9ab2240102eb1 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/FailStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/FailStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.FailStmt -class FailStmt extends Generated::FailStmt { - override string toString() { result = "fail" } +module Impl { + class FailStmt extends Generated::FailStmt { + override string toString() { result = "fail" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/FallthroughStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/FallthroughStmtImpl.qll index 8ee330c72f900..85fa9e95a6550 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/FallthroughStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/FallthroughStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.FallthroughStmt -class FallthroughStmt extends Generated::FallthroughStmt { - override string toString() { result = "fallthrough" } +module Impl { + class FallthroughStmt extends Generated::FallthroughStmt { + override string toString() { result = "fallthrough" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/ForEachStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/ForEachStmtImpl.qll index e42f13e5664bb..bc8d67d013358 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/ForEachStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/ForEachStmtImpl.qll @@ -1,14 +1,16 @@ private import codeql.swift.generated.stmt.ForEachStmt -class ForEachStmt extends Generated::ForEachStmt { - override string toString() { - if this.hasWhere() - then result = "for ... in ... where ... { ... }" - else result = "for ... in ... { ... }" - } +module Impl { + class ForEachStmt extends Generated::ForEachStmt { + override string toString() { + if this.hasWhere() + then result = "for ... in ... where ... { ... }" + else result = "for ... in ... { ... }" + } - /** - * Gets the sequence which this statement is iterating over. - */ - final Expr getSequence() { result = this.getIteratorVar().getInit(0) } + /** + * Gets the sequence which this statement is iterating over. + */ + final Expr getSequence() { result = this.getIteratorVar().getInit(0) } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/GuardStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/GuardStmtImpl.qll index f3566ec40749b..d2281c8ef592c 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/GuardStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/GuardStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.GuardStmt -class GuardStmt extends Generated::GuardStmt { - override string toString() { result = "guard ... else { ... }" } +module Impl { + class GuardStmt extends Generated::GuardStmt { + override string toString() { result = "guard ... else { ... }" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/IfStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/IfStmtImpl.qll index 79da7b2441414..8d13496319821 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/IfStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/IfStmtImpl.qll @@ -1,22 +1,24 @@ private import codeql.swift.generated.stmt.IfStmt private import codeql.swift.elements.stmt.ConditionElement -class IfStmt extends Generated::IfStmt { - ConditionElement getACondition() { result = this.getCondition(_) } +module Impl { + class IfStmt extends Generated::IfStmt { + ConditionElement getACondition() { result = this.getCondition(_) } - ConditionElement getCondition(int i) { result = this.getCondition().getElement(i) } + ConditionElement getCondition(int i) { result = this.getCondition().getElement(i) } - Stmt getBranch(boolean b) { - b = true and - result = this.getThen() - or - b = false and - result = this.getElse() - } + Stmt getBranch(boolean b) { + b = true and + result = this.getThen() + or + b = false and + result = this.getElse() + } - override string toString() { - if this.hasElse() - then result = "if ... then { ... } else { ... }" - else result = "if ... then { ... }" + override string toString() { + if this.hasElse() + then result = "if ... then { ... } else { ... }" + else result = "if ... then { ... }" + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/LabeledStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/LabeledStmtImpl.qll index 1d31de51b8839..677e21f3e5ba0 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/LabeledStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/LabeledStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.LabeledStmt -class LabeledStmt extends Generated::LabeledStmt { - override string toString() { result = this.getLabel() + ": ..." } +module Impl { + class LabeledStmt extends Generated::LabeledStmt { + override string toString() { result = this.getLabel() + ": ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/PoundAssertStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/PoundAssertStmtImpl.qll index ed35a59f8ee72..e7d208998d4b8 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/PoundAssertStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/PoundAssertStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.PoundAssertStmt -class PoundAssertStmt extends Generated::PoundAssertStmt { - override string toString() { result = "#assert ..." } +module Impl { + class PoundAssertStmt extends Generated::PoundAssertStmt { + override string toString() { result = "#assert ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/RepeatWhileStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/RepeatWhileStmtImpl.qll index a21ed2c89ec62..867aee0d5de04 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/RepeatWhileStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/RepeatWhileStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.RepeatWhileStmt -class RepeatWhileStmt extends Generated::RepeatWhileStmt { - override string toString() { result = "repeat { ... } while ... " } +module Impl { + class RepeatWhileStmt extends Generated::RepeatWhileStmt { + override string toString() { result = "repeat { ... } while ... " } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/ReturnStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/ReturnStmtImpl.qll index 9ee511913b130..d53eb3d0eee06 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/ReturnStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/ReturnStmtImpl.qll @@ -1,7 +1,9 @@ private import codeql.swift.generated.stmt.ReturnStmt -class ReturnStmt extends Generated::ReturnStmt { - override string toString() { - if this.hasResult() then result = "return ..." else result = "return" +module Impl { + class ReturnStmt extends Generated::ReturnStmt { + override string toString() { + if this.hasResult() then result = "return ..." else result = "return" + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/StmtConditionImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/StmtConditionImpl.qll index 8344a631eeeeb..dd0e3ed1be5c3 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/StmtConditionImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/StmtConditionImpl.qll @@ -1,12 +1,14 @@ private import codeql.swift.generated.stmt.StmtCondition -class StmtCondition extends Generated::StmtCondition { - ConditionElement getFirstElement() { result = this.getElement(0) } +module Impl { + class StmtCondition extends Generated::StmtCondition { + ConditionElement getFirstElement() { result = this.getElement(0) } - ConditionElement getLastElement() { - exists(int i | - result = this.getElement(i) and - not exists(this.getElement(i + 1)) - ) + ConditionElement getLastElement() { + exists(int i | + result = this.getElement(i) and + not exists(this.getElement(i + 1)) + ) + } } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/SwitchStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/SwitchStmtImpl.qll index 41c531b2311f6..850f857bdccb2 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/SwitchStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/SwitchStmtImpl.qll @@ -1,14 +1,16 @@ private import codeql.swift.generated.stmt.SwitchStmt -class SwitchStmt extends Generated::SwitchStmt { - CaseStmt getFirstCase() { result = this.getCase(0) } +module Impl { + class SwitchStmt extends Generated::SwitchStmt { + CaseStmt getFirstCase() { result = this.getCase(0) } - CaseStmt getLastCase() { - exists(int i | - result = this.getCase(i) and - not exists(this.getCase(i + 1)) - ) - } + CaseStmt getLastCase() { + exists(int i | + result = this.getCase(i) and + not exists(this.getCase(i + 1)) + ) + } - override string toString() { result = "switch " + this.getExpr().toString() + " { ... }" } + override string toString() { result = "switch " + this.getExpr().toString() + " { ... }" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/ThrowStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/ThrowStmtImpl.qll index 74c5058c2d01e..2865061216d61 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/ThrowStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/ThrowStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.ThrowStmt -class ThrowStmt extends Generated::ThrowStmt { - override string toString() { result = "throw ..." } +module Impl { + class ThrowStmt extends Generated::ThrowStmt { + override string toString() { result = "throw ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/WhileStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/WhileStmtImpl.qll index 89eec1e4c64e0..9359c6ccd20ab 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/WhileStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/WhileStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.WhileStmt -class WhileStmt extends Generated::WhileStmt { - override string toString() { result = "while ... { ... }" } +module Impl { + class WhileStmt extends Generated::WhileStmt { + override string toString() { result = "while ... { ... }" } + } } diff --git a/swift/ql/lib/codeql/swift/elements/stmt/YieldStmtImpl.qll b/swift/ql/lib/codeql/swift/elements/stmt/YieldStmtImpl.qll index 9c830c5e655a0..aeb1623d9bb71 100644 --- a/swift/ql/lib/codeql/swift/elements/stmt/YieldStmtImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/stmt/YieldStmtImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.stmt.YieldStmt -class YieldStmt extends Generated::YieldStmt { - override string toString() { result = "yield ..." } +module Impl { + class YieldStmt extends Generated::YieldStmt { + override string toString() { result = "yield ..." } + } } diff --git a/swift/ql/lib/codeql/swift/elements/type/DynamicSelfTypeImpl.qll b/swift/ql/lib/codeql/swift/elements/type/DynamicSelfTypeImpl.qll index 53455f43e2a6f..2a325f96e0618 100644 --- a/swift/ql/lib/codeql/swift/elements/type/DynamicSelfTypeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/DynamicSelfTypeImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.type.DynamicSelfType -class DynamicSelfType extends Generated::DynamicSelfType { - override Type getResolveStep() { - // The type of qualifiers in a Swift constructor is assigned the type `Self` by the Swift compiler - // This `getResolveStep` replaces that `Self` type with the type of the enclosing class. - result = this.getImmediateStaticSelfType() +module Impl { + class DynamicSelfType extends Generated::DynamicSelfType { + override Type getResolveStep() { + // The type of qualifiers in a Swift constructor is assigned the type `Self` by the Swift compiler + // This `getResolveStep` replaces that `Self` type with the type of the enclosing class. + result = this.getImmediateStaticSelfType() + } } } diff --git a/swift/ql/lib/codeql/swift/elements/type/LValueTypeImpl.qll b/swift/ql/lib/codeql/swift/elements/type/LValueTypeImpl.qll index d6b4048bdd772..844e0f639a9be 100644 --- a/swift/ql/lib/codeql/swift/elements/type/LValueTypeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/LValueTypeImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.type.LValueType -class LValueType extends Generated::LValueType { - override Type getResolveStep() { result = this.getImmediateObjectType() } +module Impl { + class LValueType extends Generated::LValueType { + override Type getResolveStep() { result = this.getImmediateObjectType() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/type/NominalTypeImpl.qll b/swift/ql/lib/codeql/swift/elements/type/NominalTypeImpl.qll index bea26b684865d..291d90bdb5290 100644 --- a/swift/ql/lib/codeql/swift/elements/type/NominalTypeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/NominalTypeImpl.qll @@ -1,6 +1,8 @@ private import codeql.swift.generated.type.NominalType -/** - * A class, struct, enum or protocol. - */ -class NominalType extends Generated::NominalType { } +module Impl { + /** + * A class, struct, enum or protocol. + */ + class NominalType extends Generated::NominalType { } +} diff --git a/swift/ql/lib/codeql/swift/elements/type/TupleTypeImpl.qll b/swift/ql/lib/codeql/swift/elements/type/TupleTypeImpl.qll index 13f50a5d0d4cd..1c09edb5bfa5f 100644 --- a/swift/ql/lib/codeql/swift/elements/type/TupleTypeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/TupleTypeImpl.qll @@ -1,9 +1,11 @@ private import codeql.swift.generated.type.TupleType -/** - * A tuple type, for example: - * ``` - * (Int, String) - * ``` - */ -class TupleType extends Generated::TupleType { } +module Impl { + /** + * A tuple type, for example: + * ``` + * (Int, String) + * ``` + */ + class TupleType extends Generated::TupleType { } +} diff --git a/swift/ql/lib/codeql/swift/elements/type/TypeAliasTypeImpl.qll b/swift/ql/lib/codeql/swift/elements/type/TypeAliasTypeImpl.qll index d9e9e4e2cbe33..8f16e9a406e77 100644 --- a/swift/ql/lib/codeql/swift/elements/type/TypeAliasTypeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/TypeAliasTypeImpl.qll @@ -1,22 +1,24 @@ private import codeql.swift.elements.type.Type private import codeql.swift.generated.type.TypeAliasType -/** - * A type alias to another type. For example: - * ``` - * typealias MyInt = Int - * ``` - */ -class TypeAliasType extends Generated::TypeAliasType { +module Impl { /** - * Gets the aliased type of this type alias type. - * - * For example the aliased type of `MyInt` in the following code is `Int`: + * A type alias to another type. For example: * ``` * typealias MyInt = Int * ``` */ - Type getAliasedType() { result = this.getDecl().getAliasedType() } + class TypeAliasType extends Generated::TypeAliasType { + /** + * Gets the aliased type of this type alias type. + * + * For example the aliased type of `MyInt` in the following code is `Int`: + * ``` + * typealias MyInt = Int + * ``` + */ + Type getAliasedType() { result = this.getDecl().getAliasedType() } - override Type getUnderlyingType() { result = this.getAliasedType().getUnderlyingType() } + override Type getUnderlyingType() { result = this.getAliasedType().getUnderlyingType() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/type/TypeImpl.qll b/swift/ql/lib/codeql/swift/elements/type/TypeImpl.qll index b5d30140e83c5..625d5b5312df8 100644 --- a/swift/ql/lib/codeql/swift/elements/type/TypeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/TypeImpl.qll @@ -1,66 +1,68 @@ private import codeql.swift.generated.type.Type private import codeql.swift.elements.type.AnyGenericType -/** - * A Swift type. - * - * This QL class is the root of the Swift type hierarchy. - */ -class Type extends Generated::Type { - override string toString() { result = this.getFullName() } - +module Impl { /** - * Gets the name of this type. + * A Swift type. + * + * This QL class is the root of the Swift type hierarchy. */ - override string getName() { - // replace anything that looks like a full name `a.b.c` with just the - // short name `c`, by removing the `a.` and `b.` parts. Note that this - // has to be robust for tuple type names such as `(a, b.c)`. - result = super.getName().regexpReplaceAll("[^(),. ]++\\.(?!\\.)", "") - } + class Type extends Generated::Type { + override string toString() { result = this.getFullName() } - /** - * Gets the full name of this `Type`. For example in: - * ```swift - * struct A { - * struct B { - * // ... - * } - * } - * ``` - * The name and full name of `A` is `A`. The name of `B` is `B`, but the - * full name of `B` is `A.B`. - */ - string getFullName() { result = super.getName() } + /** + * Gets the name of this type. + */ + override string getName() { + // replace anything that looks like a full name `a.b.c` with just the + // short name `c`, by removing the `a.` and `b.` parts. Note that this + // has to be robust for tuple type names such as `(a, b.c)`. + result = super.getName().regexpReplaceAll("[^(),. ]++\\.(?!\\.)", "") + } - /** - * Gets this type after any type aliases have been resolved. For example in - * the following code, the underlying type of `MyInt` is `Int`: - * ``` - * typealias MyInt = Int - * ``` - */ - Type getUnderlyingType() { result = this } + /** + * Gets the full name of this `Type`. For example in: + * ```swift + * struct A { + * struct B { + * // ... + * } + * } + * ``` + * The name and full name of `A` is `A`. The name of `B` is `B`, but the + * full name of `B` is `A.B`. + */ + string getFullName() { result = super.getName() } - /** - * Gets any base type of this type. Expands protocols added in extensions and expands - * type aliases. For example in the following code, `B` has base type `A`: - * ``` - * typealias A_alias = A - * - * class B : A_alias {} - * ``` - */ - Type getABaseType() { result = this.(AnyGenericType).getDeclaration().getABaseType() } + /** + * Gets this type after any type aliases have been resolved. For example in + * the following code, the underlying type of `MyInt` is `Int`: + * ``` + * typealias MyInt = Int + * ``` + */ + Type getUnderlyingType() { result = this } - /** - * Gets a type derived from this type. Expands type aliases, for example in the following - * code, `B` derives from type `A`. - * ``` - * typealias A_alias = A - * - * class B : A_alias {} - * ``` - */ - Type getADerivedType() { result.getABaseType() = this } + /** + * Gets any base type of this type. Expands protocols added in extensions and expands + * type aliases. For example in the following code, `B` has base type `A`: + * ``` + * typealias A_alias = A + * + * class B : A_alias {} + * ``` + */ + Type getABaseType() { result = this.(AnyGenericType).getDeclaration().getABaseType() } + + /** + * Gets a type derived from this type. Expands type aliases, for example in the following + * code, `B` derives from type `A`. + * ``` + * typealias A_alias = A + * + * class B : A_alias {} + * ``` + */ + Type getADerivedType() { result.getABaseType() = this } + } } diff --git a/swift/ql/lib/codeql/swift/elements/type/TypeReprImpl.qll b/swift/ql/lib/codeql/swift/elements/type/TypeReprImpl.qll index ad870d4a868c4..98b4b0f05283a 100644 --- a/swift/ql/lib/codeql/swift/elements/type/TypeReprImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/TypeReprImpl.qll @@ -1,5 +1,7 @@ private import codeql.swift.generated.type.TypeRepr -class TypeRepr extends Generated::TypeRepr { - override string toString() { result = this.getType().toString() } +module Impl { + class TypeRepr extends Generated::TypeRepr { + override string toString() { result = this.getType().toString() } + } } diff --git a/swift/ql/lib/codeql/swift/elements/type/VariadicSequenceTypeImpl.qll b/swift/ql/lib/codeql/swift/elements/type/VariadicSequenceTypeImpl.qll index 3e64b313c9c05..8f35271cb8b78 100644 --- a/swift/ql/lib/codeql/swift/elements/type/VariadicSequenceTypeImpl.qll +++ b/swift/ql/lib/codeql/swift/elements/type/VariadicSequenceTypeImpl.qll @@ -1,12 +1,14 @@ private import codeql.swift.generated.type.VariadicSequenceType -/** - * A variadic sequence type, that is, an array-like type that holds - * variadic arguments. For example the type `Int...` of `args` in: - * ``` - * func myVarargsFunction(args: Int...) { - * ... - * } - * ``` - */ -class VariadicSequenceType extends Generated::VariadicSequenceType { } +module Impl { + /** + * A variadic sequence type, that is, an array-like type that holds + * variadic arguments. For example the type `Int...` of `args` in: + * ``` + * func myVarargsFunction(args: Int...) { + * ... + * } + * ``` + */ + class VariadicSequenceType extends Generated::VariadicSequenceType { } +} diff --git a/swift/ql/lib/swift.qll b/swift/ql/lib/swift.qll index 2ea5d3774f3f9..8a5b8f3b8b7d9 100644 --- a/swift/ql/lib/swift.qll +++ b/swift/ql/lib/swift.qll @@ -1,6 +1,7 @@ /** Top-level import for the Swift language pack */ import codeql.swift.elements +import codeql.swift.elements.expr.ApplyExprExt import codeql.swift.elements.expr.ArithmeticOperation import codeql.swift.elements.expr.BitwiseOperation import codeql.swift.elements.expr.LogicalOperation @@ -10,6 +11,7 @@ import codeql.swift.elements.expr.MethodCallExpr import codeql.swift.elements.expr.InitializerCallExpr import codeql.swift.elements.expr.SelfRefExpr import codeql.swift.elements.expr.EnumElementExpr +import codeql.swift.elements.decl.AccessorExt import codeql.swift.elements.decl.Method import codeql.swift.elements.decl.ClassOrStructDecl import codeql.swift.elements.type.NumericType