mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
Merge pull request #12508 from github/redsun82/swift-deduplication-test
Swift: add an initial draft for a deduplication test
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <swift/AST/ASTMangler.h>
|
||||
#include <swift/AST/Types.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace codeql {
|
||||
class SwiftMangler {
|
||||
public:
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
| Builtin.BridgeObject | BuiltinBridgeObjectType |
|
||||
| Builtin.Executor | BuiltinExecutorType |
|
||||
| Builtin.FPIEEE32 | BuiltinFloatType |
|
||||
| Builtin.FPIEEE64 | BuiltinFloatType |
|
||||
| Builtin.FPIEEE80 | BuiltinFloatType |
|
||||
| Builtin.Int1 | BuiltinIntegerType |
|
||||
| Builtin.Int8 | BuiltinIntegerType |
|
||||
| Builtin.Int16 | BuiltinIntegerType |
|
||||
| Builtin.Int32 | BuiltinIntegerType |
|
||||
| Builtin.Int64 | BuiltinIntegerType |
|
||||
| Builtin.IntLiteral | BuiltinIntegerLiteralType |
|
||||
| Builtin.Job | BuiltinJobType |
|
||||
| Builtin.NativeObject | BuiltinNativeObjectType |
|
||||
| Builtin.RawPointer | BuiltinRawPointerType |
|
||||
| Builtin.RawUnsafeContinuation | BuiltinRawUnsafeContinuationType |
|
||||
| Builtin.Vec2xFPIEEE32 | BuiltinVectorType |
|
||||
| Builtin.Vec2xFPIEEE64 | BuiltinVectorType |
|
||||
| Builtin.Vec2xInt8 | BuiltinVectorType |
|
||||
| Builtin.Vec2xInt16 | BuiltinVectorType |
|
||||
| Builtin.Vec2xInt32 | BuiltinVectorType |
|
||||
| Builtin.Vec2xInt64 | BuiltinVectorType |
|
||||
| Builtin.Vec4xFPIEEE32 | BuiltinVectorType |
|
||||
| Builtin.Vec4xFPIEEE64 | BuiltinVectorType |
|
||||
| Builtin.Vec4xInt8 | BuiltinVectorType |
|
||||
| Builtin.Vec4xInt16 | BuiltinVectorType |
|
||||
| Builtin.Vec4xInt32 | BuiltinVectorType |
|
||||
| Builtin.Vec4xInt64 | BuiltinVectorType |
|
||||
| Builtin.Vec8xFPIEEE32 | BuiltinVectorType |
|
||||
| Builtin.Vec8xFPIEEE64 | BuiltinVectorType |
|
||||
| Builtin.Vec8xInt8 | BuiltinVectorType |
|
||||
| Builtin.Vec8xInt16 | BuiltinVectorType |
|
||||
| Builtin.Vec8xInt32 | BuiltinVectorType |
|
||||
| Builtin.Vec8xInt64 | BuiltinVectorType |
|
||||
| Builtin.Vec16xFPIEEE32 | BuiltinVectorType |
|
||||
| Builtin.Vec16xFPIEEE64 | BuiltinVectorType |
|
||||
| Builtin.Vec16xInt8 | BuiltinVectorType |
|
||||
| Builtin.Vec16xInt16 | BuiltinVectorType |
|
||||
| Builtin.Vec16xInt32 | BuiltinVectorType |
|
||||
| Builtin.Vec16xInt64 | BuiltinVectorType |
|
||||
| Builtin.Vec32xFPIEEE32 | BuiltinVectorType |
|
||||
| Builtin.Vec32xFPIEEE64 | BuiltinVectorType |
|
||||
| Builtin.Vec32xInt8 | BuiltinVectorType |
|
||||
| Builtin.Vec32xInt16 | BuiltinVectorType |
|
||||
| Builtin.Vec32xInt32 | BuiltinVectorType |
|
||||
| Builtin.Vec32xInt64 | BuiltinVectorType |
|
||||
| Builtin.Vec64xFPIEEE32 | BuiltinVectorType |
|
||||
| Builtin.Vec64xFPIEEE64 | BuiltinVectorType |
|
||||
| Builtin.Vec64xInt8 | BuiltinVectorType |
|
||||
| Builtin.Vec64xInt16 | BuiltinVectorType |
|
||||
| Builtin.Vec64xInt32 | BuiltinVectorType |
|
||||
| Builtin.Vec64xInt64 | BuiltinVectorType |
|
||||
| Builtin.Word | BuiltinIntegerType |
|
||||
@@ -0,0 +1,6 @@
|
||||
import swift
|
||||
|
||||
from BuiltinType t
|
||||
// FPIEEE16 related stuff is not there on macOS
|
||||
where not t.toString().matches("%FPIEEE16")
|
||||
select t, t.getPrimaryQlClasses()
|
||||
@@ -0,0 +1,16 @@
|
||||
| Sources/deduplication/def.swift:1:1:1:9 | var ... = ... | PatternBindingDecl |
|
||||
| Sources/deduplication/def.swift:1:5:1:5 | x | ConcreteVarDecl |
|
||||
| Sources/deduplication/def.swift:3:1:3:20 | Generic | StructDecl |
|
||||
| Sources/deduplication/def.swift:3:8:3:8 | Generic<T>.init() | ConstructorDecl |
|
||||
| Sources/deduplication/def.swift:3:8:3:8 | self | ParamDecl |
|
||||
| Sources/deduplication/def.swift:3:16:3:16 | T | GenericTypeParamDecl |
|
||||
| Sources/deduplication/def.swift:5:1:5:41 | var ... = ... | PatternBindingDecl |
|
||||
| Sources/deduplication/def.swift:5:5:5:5 | instantiated_generic | ConcreteVarDecl |
|
||||
| Sources/deduplication/def.swift:7:1:7:42 | function(_:) | ConcreteFuncDecl |
|
||||
| Sources/deduplication/def.swift:7:15:7:18 | _ | ParamDecl |
|
||||
| Sources/deduplication/use.swift:1:1:1:13 | var ... = ... | PatternBindingDecl |
|
||||
| Sources/deduplication/use.swift:1:5:1:5 | use_x | ConcreteVarDecl |
|
||||
| Sources/deduplication/use.swift:2:1:2:32 | var ... = ... | PatternBindingDecl |
|
||||
| Sources/deduplication/use.swift:2:5:2:5 | use_instantiated_generic | ConcreteVarDecl |
|
||||
| Sources/deduplication/use.swift:3:1:3:20 | var ... = ... | PatternBindingDecl |
|
||||
| Sources/deduplication/use.swift:3:5:3:5 | use_function | ConcreteVarDecl |
|
||||
@@ -0,0 +1,6 @@
|
||||
import swift
|
||||
import Relevant
|
||||
|
||||
from Decl d
|
||||
where relevant(d)
|
||||
select d, d.getPrimaryQlClasses()
|
||||
@@ -0,0 +1,16 @@
|
||||
// swift-tools-version: 5.5
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "deduplication",
|
||||
products: [
|
||||
.library(
|
||||
name: "deduplication",
|
||||
targets: ["deduplication"]),
|
||||
],
|
||||
targets: [
|
||||
.target(name: "deduplication")
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,5 @@
|
||||
import swift
|
||||
|
||||
predicate relevant(Locatable loc) {
|
||||
loc.getLocation().getFile().getName().matches("%/swift/integration-tests/%/Sources/%")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
var x = 42
|
||||
|
||||
struct Generic<T> {}
|
||||
|
||||
var instantiated_generic = Generic<Int>()
|
||||
|
||||
func function(_: Int) -> Int { return 42 }
|
||||
@@ -0,0 +1,3 @@
|
||||
let use_x = x
|
||||
let use_instantiated_generic = instantiated_generic
|
||||
let use_function = function
|
||||
@@ -0,0 +1,10 @@
|
||||
| (Int) -> Int | FunctionType | function(_:) |
|
||||
| (Int) -> Int | FunctionType | use_function |
|
||||
| <T> (Generic<T>.Type) -> () -> Generic<T> | GenericFunctionType | Generic<T>.init() |
|
||||
| Generic<Int> | BoundGenericStructType | instantiated_generic |
|
||||
| Generic<Int> | BoundGenericStructType | use_instantiated_generic |
|
||||
| Generic<T> | BoundGenericStructType | self |
|
||||
| Generic<T>.Type | MetatypeType | Generic |
|
||||
| Int | StructType | _, x |
|
||||
| Int | StructType | use_x |
|
||||
| T.Type | MetatypeType | T |
|
||||
@@ -0,0 +1,7 @@
|
||||
import swift
|
||||
import Relevant
|
||||
|
||||
from Type t, string decls
|
||||
where
|
||||
decls = strictconcat(ValueDecl d | relevant(d) and t = d.getInterfaceType() | d.toString(), ", ")
|
||||
select t, t.getPrimaryQlClasses(), decls
|
||||
6
swift/integration-tests/posix-only/deduplication/test.py
Normal file
6
swift/integration-tests/posix-only/deduplication/test.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from create_database_utils import *
|
||||
|
||||
run_codeql_database_create([
|
||||
'swift package clean',
|
||||
'swift build',
|
||||
], lang='swift', keep_trap=True)
|
||||
Reference in New Issue
Block a user