Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
dimohamdy committed Aug 4, 2023
1 parent a892c9f commit df22824
Show file tree
Hide file tree
Showing 32 changed files with 3,740 additions and 15 deletions.
187 changes: 183 additions & 4 deletions MemoryLeak.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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 MemoryLeak.xcodeproj/xcshareddata/xcschemes/MemoryLeak.xcscheme
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>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>33971E202A7C690900058593</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
12 changes: 12 additions & 0 deletions MemoryLeak/Sources/SwiftLeakCheck/BackwardCompatiblity.swift
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 MemoryLeak/Sources/SwiftLeakCheck/BaseSyntaxTreeLeakDetector.swift
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")
}
}
48 changes: 48 additions & 0 deletions MemoryLeak/Sources/SwiftLeakCheck/DirectoryScanner.swift
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
}
}
}
}
}
}
50 changes: 50 additions & 0 deletions MemoryLeak/Sources/SwiftLeakCheck/Function.swift
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] }))
}
}
}
Loading

0 comments on commit df22824

Please sign in to comment.