From fc65160a7858e00d49240127255381c3d5066c79 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 27 Apr 2023 13:26:24 +0100 Subject: [PATCH 1/2] Swift: Simplify the implemention of MethodDecl.hasQualifiedName. --- .../lib/codeql/swift/elements/decl/MethodDecl.qll | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/swift/ql/lib/codeql/swift/elements/decl/MethodDecl.qll b/swift/ql/lib/codeql/swift/elements/decl/MethodDecl.qll index f82a87eb872..39006022cc4 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/MethodDecl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/MethodDecl.qll @@ -32,16 +32,9 @@ class MethodDecl extends AbstractFunctionDecl { cached predicate hasQualifiedName(string typeName, string funcName) { this.getName() = funcName and - ( - exists(NominalTypeDecl c | - c.getFullName() = typeName and - c.getAMember() = this - ) - or - exists(ExtensionDecl e | - e.getExtendedTypeDecl().getFullName() = typeName and - e.getAMember() = this - ) + exists(Decl d | + d.asNominalTypeDecl().getFullName() = typeName and + d.getAMember() = this ) } From abb98be9965527266d0e26da80ffc48e88ba6736 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 27 Apr 2023 14:16:31 +0100 Subject: [PATCH 2/2] Swift: QLDoc Type.qll, TypeDecl.qll, and deprecate one of the predicates. --- .../codeql/swift/elements/decl/TypeDecl.qll | 32 +++++++++++++++++-- .../lib/codeql/swift/elements/type/Type.qll | 5 +++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/swift/ql/lib/codeql/swift/elements/decl/TypeDecl.qll b/swift/ql/lib/codeql/swift/elements/decl/TypeDecl.qll index 75189283435..d66418758fb 100644 --- a/swift/ql/lib/codeql/swift/elements/decl/TypeDecl.qll +++ b/swift/ql/lib/codeql/swift/elements/decl/TypeDecl.qll @@ -2,16 +2,44 @@ 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() } + /** + * Gets the declaration of the `index`th base type of this type declaration (0-based). + */ TypeDecl getBaseTypeDecl(int i) { result = this.getBaseType(i).(AnyGenericType).getDeclaration() } + /** + * Gets the declaration of any of the base types of this type declaration. + */ TypeDecl getABaseTypeDecl() { result = this.getBaseTypeDecl(_) } - TypeDecl getDerivedTypeDecl(int i) { result.getBaseTypeDecl(i) = this } + /** + * Gets a declaration that has this type as its `index`th base type. + * + * DEPRECATED: The index is not very meaningful here. Use `getADerivedTypeDecl` or `getBaseTypeDecl`. + */ + deprecated TypeDecl getDerivedTypeDecl(int i) { result.getBaseTypeDecl(i) = this } - TypeDecl getADerivedTypeDecl() { result = this.getDerivedTypeDecl(_) } + /** + * Gets the declaration of any type derived from this type declaration. + */ + TypeDecl getADerivedTypeDecl() { result.getBaseTypeDecl(_) = this } /** * Gets the full name of this `TypeDecl`. For example in: diff --git a/swift/ql/lib/codeql/swift/elements/type/Type.qll b/swift/ql/lib/codeql/swift/elements/type/Type.qll index ec72e8aa9fd..16547069499 100644 --- a/swift/ql/lib/codeql/swift/elements/type/Type.qll +++ b/swift/ql/lib/codeql/swift/elements/type/Type.qll @@ -1,5 +1,10 @@ private import codeql.swift.generated.type.Type +/** + * A Swift type. + * + * This QL class is the root of the Swift type hierarchy. + */ class Type extends Generated::Type { override string toString() { result = this.getName() }