-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
3,740 additions
and
15 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
MemoryLeak.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-syntax", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-syntax.git", | ||
"state" : { | ||
"revision" : "2c49d66d34dfd6f8130afdba889de77504b58ec0", | ||
"version" : "508.0.1" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
84 changes: 84 additions & 0 deletions
84
MemoryLeak.xcodeproj/xcshareddata/xcschemes/MemoryLeak.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1430" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "33971E202A7C690900058593" | ||
BuildableName = "MemoryLeak" | ||
BlueprintName = "MemoryLeak" | ||
ReferencedContainer = "container:MemoryLeak.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES" | ||
viewDebuggingEnabled = "No"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "33971E202A7C690900058593" | ||
BuildableName = "MemoryLeak" | ||
BlueprintName = "MemoryLeak" | ||
ReferencedContainer = "container:MemoryLeak.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
<CommandLineArguments> | ||
<CommandLineArgument | ||
argument = "/Users/dabdelaziz/Downloads/swift-leak-check-master/Tests/SwiftLeakCheckTests/Snippets" | ||
isEnabled = "YES"> | ||
</CommandLineArgument> | ||
</CommandLineArguments> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "33971E202A7C690900058593" | ||
BuildableName = "MemoryLeak" | ||
BlueprintName = "MemoryLeak" | ||
ReferencedContainer = "container:MemoryLeak.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
MemoryLeak/Sources/SwiftLeakCheck/BackwardCompatiblity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Tmp.swift | ||
// SwiftLeakCheck | ||
// | ||
// Created by Hoang Le Pham on 07/02/2021. | ||
// | ||
|
||
import SwiftSyntax | ||
|
||
// For backward-compatible with Swift compiler 4.2 type names | ||
public typealias FunctionCallArgumentListSyntax = TupleExprElementListSyntax | ||
public typealias FunctionCallArgumentSyntax = TupleExprElementSyntax |
24 changes: 24 additions & 0 deletions
24
MemoryLeak/Sources/SwiftLeakCheck/BaseSyntaxTreeLeakDetector.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// BaseSyntaxTreeLeakDetector.swift | ||
// SwiftLeakCheck | ||
// | ||
// Copyright 2020 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved. | ||
// Use of this source code is governed by an MIT-style license that can be found in the LICENSE file | ||
// | ||
// Created by Hoang Le Pham on 09/12/2019. | ||
// | ||
|
||
import SwiftSyntax | ||
|
||
open class BaseSyntaxTreeLeakDetector: LeakDetector { | ||
public init() {} | ||
|
||
public func detect(content: String) throws -> [Leak] { | ||
let node = try SyntaxRetrieval.request(content: content) | ||
return detect(node) | ||
} | ||
|
||
open func detect(_ sourceFileNode: SourceFileSyntax) -> [Leak] { | ||
fatalError("Implemented by subclass") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// DirectoryScanner.swift | ||
// SwiftLeakCheck | ||
// | ||
// Copyright 2020 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved. | ||
// Use of this source code is governed by an MIT-style license that can be found in the LICENSE file | ||
// | ||
// Created by Hoang Le Pham on 09/12/2019. | ||
// | ||
|
||
import Foundation | ||
|
||
public final class DirectoryScanner { | ||
private let callback: (URL, inout Bool) -> Void | ||
private var shouldStop = false | ||
|
||
public init(callback: @escaping (URL, inout Bool) -> Void) { | ||
self.callback = callback | ||
} | ||
|
||
public func scan(url: URL) { | ||
if shouldStop { | ||
shouldStop = false // Clear | ||
return | ||
} | ||
|
||
let isDirectory = (try? url.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false | ||
if !isDirectory { | ||
callback(url, &shouldStop) | ||
} else { | ||
let enumerator = FileManager.default.enumerator( | ||
at: url, | ||
includingPropertiesForKeys: nil, | ||
options: [.skipsSubdirectoryDescendants], | ||
errorHandler: nil | ||
)! | ||
|
||
for childPath in enumerator { | ||
if let url = childPath as? URL { | ||
scan(url: url) | ||
if shouldStop { | ||
return | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Function.swift | ||
// SwiftLeakCheck | ||
// | ||
// Copyright 2020 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved. | ||
// Use of this source code is governed by an MIT-style license that can be found in the LICENSE file | ||
// | ||
// Created by Hoang Le Pham on 18/11/2019. | ||
// | ||
|
||
import SwiftSyntax | ||
|
||
public typealias Function = FunctionDeclSyntax | ||
|
||
public extension Function { | ||
enum MatchResult: Equatable { | ||
public struct MappingInfo: Equatable { | ||
let argumentToParamMapping: [FunctionCallArgumentSyntax: FunctionParameterSyntax] | ||
let trailingClosureArgumentToParam: FunctionParameterSyntax? | ||
} | ||
|
||
case nameMismatch | ||
case argumentMismatch | ||
case matched(MappingInfo) | ||
|
||
var isMatched: Bool { | ||
switch self { | ||
case .nameMismatch, | ||
.argumentMismatch: | ||
return false | ||
case .matched: | ||
return true | ||
} | ||
} | ||
} | ||
|
||
func match(_ functionCallExpr: FunctionCallExprSyntax) -> MatchResult { | ||
let (signature, mapping) = FunctionSignature.from(functionDeclExpr: self) | ||
switch signature.match(functionCallExpr) { | ||
case .nameMismatch: | ||
return .nameMismatch | ||
case .argumentMismatch: | ||
return .argumentMismatch | ||
case .matched(let matchedInfo): | ||
return .matched(.init( | ||
argumentToParamMapping: matchedInfo.argumentToParamMapping.mapValues { mapping[$0]! }, | ||
trailingClosureArgumentToParam: matchedInfo.trailingClosureArgumentToParam.flatMap { mapping[$0] })) | ||
} | ||
} | ||
} |
Oops, something went wrong.