Skip to content

Commit

Permalink
Add make command to generate sourcekit type defines.
Browse files Browse the repository at this point in the history
  • Loading branch information
ainopara committed Nov 3, 2017
1 parent ac7cdea commit 782383e
Show file tree
Hide file tree
Showing 5 changed files with 410 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ docker_test:
docker_test_4:
docker run -v `pwd`:`pwd` -w `pwd` --rm norionomura/swift:4020170908a swift test

generate_sourcekit_defines:
clang -E -P Templates/TypeDefs.h -o Templates/SourceKitDef.swift
sourcery --sources Templates/SourceKitDef.swift --templates Templates/AutoEnumNameFix.stencil --output Templates/SourceKitDef.swift
mv Templates/SourceKitDef.swift Source/SourceKittenFramework

# http://irace.me/swift-profiling/
display_compilation_time:
$(BUILD_TOOL) $(XCODEFLAGS) OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" clean build-for-testing | grep -E ^[1-9]{1}[0-9]*.[0-9]+ms | sort -n
Expand Down
6 changes: 4 additions & 2 deletions Source/SourceKittenFramework/SourceKitDef.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Generated using Sourcery 0.8.0 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 0.9.0 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length

import Swift

// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length
public struct SourceKitDef {

public enum Key {
Expand Down Expand Up @@ -1641,6 +1642,7 @@ public struct SourceKitDef {
}
}


public extension SourceKitDef.Key {
public static let count: Int = 134
}
Expand Down
40 changes: 40 additions & 0 deletions Templates/AutoEnumNameFix.stencil
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Swift

// swiftlint:disable type_body_length function_body_length cyclomatic_complexity file_length
public struct SourceKitDef {
{% for enum in types.all %}

public enum {{ enum.name }} {
{% for case in enum.cases %}case {{ case.name|lowerFirst }}
{% endfor %}
case unrecognized(String)

public init(string: String) {
switch string {
{% for case in enum.cases %}case "{{ case.rawValue }}":
self = .{{ case.name|lowerFirst }}
{% endfor %}
default:
self = .unrecognized(string)
}
}

public var stringRepresentation: String {
switch self {
{% for case in enum.cases %}case .{{ case.name|lowerFirst }}:
return "{{ case.rawValue }}"
{% endfor %}
case let .unrecognized(string):
return string
}
}
}
{% endfor %}
}

{% for enum in types.all %}

public extension SourceKitDef.{{ enum.name }} {
public static let count: Int = {{ enum.cases.count }}
}
{% endfor %}

0 comments on commit 782383e

Please sign in to comment.