Skip to content

Commit f554b79

Browse files
committed
[Macros] Drop members made unnecessary by macro declarations.
1 parent 3c967ec commit f554b79

File tree

7 files changed

+85
-275
lines changed

7 files changed

+85
-275
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(SwiftSyntaxBuilder STATIC
10+
ExpressionMacro.swift
11+
Macro.swift
12+
MacroEvaluationContext.swift
13+
MacroResult.swift
14+
MacroSystem+Builtin.swift
15+
MacroSystem+Examples.swift
16+
MacroSystem.swift
17+
Syntax+MacroEvaluation.swift
18+
)
19+
20+
target_link_libraries(SwiftSyntaxBuilder PUBLIC
21+
SwiftParser
22+
SwiftSyntaxBuilder
23+
)
24+
25+
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftParser)
26+
27+
# NOTE: workaround for CMake not setting up include flags yet
28+
set_target_properties(SwiftSyntaxBuilder PROPERTIES
29+
INTERFACE_INCLUDE_DIRECTORIES
30+
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")
31+
32+
install(TARGETS SwiftSyntaxBuilder
33+
EXPORT SwiftSyntaxTargets
34+
ARCHIVE DESTINATION lib
35+
LIBRARY DESTINATION lib
36+
RUNTIME DESTINATION bin)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(_SwiftSyntaxMacros STATIC
10+
ExpressionMacro.swift
11+
Macro.swift
12+
MacroEvaluationContext.swift
13+
MacroResult.swift
14+
MacroSystem+Builtin.swift
15+
MacroSystem+Examples.swift
16+
MacroSystem.swift
17+
Syntax+MacroEvaluation.swift
18+
)

Sources/_SwiftSyntaxMacros/Macro.swift

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -18,101 +18,4 @@ public typealias _CompilerPlugin = Any
1818
#endif
1919

2020
/// Describes a macro.
21-
public protocol Macro: _CompilerPlugin {
22-
/// The name of this macro.
23-
static var name: String { get }
24-
25-
/// Documentation for this macro.
26-
///
27-
/// This documentation should be written in the Markdown format used for
28-
/// commenting Swift declarations.
29-
static var documentation: String { get }
30-
31-
/// The generic signature to use when describing the type of this macro.
32-
static var genericSignature: GenericParameterClauseSyntax? { get }
33-
34-
/// The type signature for this macro.
35-
///
36-
/// A function type indicates a function-like macro (such as
37-
/// `#colorLiteral(red: r, green: b, blue: b, alpha: a)`) that takes
38-
/// arguments, whereas any other type indicates a value-like macro (such
39-
/// as `#line`) that does not. This is a syntactic distinction, not a
40-
/// semantic one.
41-
static var signature: TypeSyntax { get }
42-
43-
/// The module that "owns" this macro.
44-
///
45-
/// This module must be imported by any code that wishes to use the macro.
46-
static var owningModule: String { get }
47-
48-
/// Additional imports requires to describe the signature of the macro.
49-
///
50-
/// For example, if your macro is owned by module A, but its signature also
51-
/// contains types from another module B that is used by A, then the module
52-
/// B should be
53-
static var supplementalSignatureModules: [String] { get }
54-
}
55-
56-
extension Macro {
57-
/// Default, empty documentation string for macros.
58-
public static var documentation: String { "" }
59-
60-
/// Default, empty set of supplemental signature modules.
61-
///
62-
/// Many macros won't need any supplemental signature modules beyond the
63-
/// default "Swift" import.
64-
public static var supplementalSignatureModules: [String] { [] }
65-
}
66-
67-
#if canImport(_CompilerPluginSupport)
68-
extension Macro {
69-
public static func _name() -> (UnsafePointer<UInt8>, count: Int) {
70-
var name = name
71-
return name.withUTF8 { buffer in
72-
let result = UnsafeMutablePointer<UInt8>.allocate(capacity: buffer.count)
73-
result.initialize(from: buffer.baseAddress!, count: buffer.count)
74-
return (UnsafePointer(result), count: buffer.count)
75-
}
76-
}
77-
78-
public static func _genericSignature() -> (UnsafePointer<UInt8>?, count: Int) {
79-
guard let genericSignature = genericSignature else {
80-
return (nil, count: 0)
81-
}
82-
var signature = "\(genericSignature)"
83-
return signature.withUTF8 { buffer in
84-
let result = UnsafeMutablePointer<UInt8>.allocate(capacity: buffer.count)
85-
result.initialize(from: buffer.baseAddress!, count: buffer.count)
86-
return (UnsafePointer(result), count: buffer.count)
87-
}
88-
}
89-
90-
public static func _typeSignature() -> (UnsafePointer<UInt8>, count: Int) {
91-
var signature = "\(signature)"
92-
return signature.withUTF8 { buffer in
93-
let result = UnsafeMutablePointer<UInt8>.allocate(capacity: buffer.count)
94-
result.initialize(from: buffer.baseAddress!, count: buffer.count)
95-
return (UnsafePointer(result), count: buffer.count)
96-
}
97-
}
98-
99-
public static func _owningModule() -> (UnsafePointer<UInt8>, count: Int) {
100-
var module = "\(owningModule)"
101-
return module.withUTF8 { buffer in
102-
let result = UnsafeMutablePointer<UInt8>.allocate(capacity: buffer.count)
103-
result.initialize(from: buffer.baseAddress!, count: buffer.count)
104-
return (UnsafePointer(result), count: buffer.count)
105-
}
106-
}
107-
108-
public static func _supplementalSignatureModules()
109-
-> (UnsafePointer<UInt8>, count: Int) {
110-
var allModulesJoined = supplementalSignatureModules.joined(separator:";")
111-
return allModulesJoined.withUTF8 { buffer in
112-
let result = UnsafeMutablePointer<UInt8>.allocate(capacity: buffer.count)
113-
result.initialize(from: buffer.baseAddress!, count: buffer.count)
114-
return (UnsafePointer(result), count: buffer.count)
115-
}
116-
}
117-
}
118-
#endif
21+
public protocol Macro: _CompilerPlugin { }

0 commit comments

Comments
 (0)