-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make findAttribute/getAttributes always return a struct for the attri…
…bute.
- Loading branch information
1 parent
634e6e4
commit b072544
Showing
29 changed files
with
115 additions
and
63 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
public enum ComImportAttribute: AttributeType { | ||
public struct ComImportAttribute: AttributeType { | ||
public static var namespace: String? { "System.Runtime.InteropServices" } | ||
public static var name: String { "ComImportAttribute" } | ||
public static var validOn: AttributeTargets { .class | .interface } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { false } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Void { () } | ||
public static func decode(_ attribute: Attribute) throws -> Self { .init() } | ||
} |
12 changes: 9 additions & 3 deletions
12
Sources/DotNetMetadata/Attributes/ComVisibleAttribute.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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
public enum ComVisibleAttribute: AttributeType { | ||
public struct ComVisibleAttribute: AttributeType { | ||
public var value: Bool | ||
|
||
public init(_ value: Bool) { | ||
self.value = value | ||
} | ||
|
||
public static var namespace: String? { "System.Runtime.InteropServices" } | ||
public static var name: String { "ComVisibleAttribute" } | ||
public static var validOn: AttributeTargets { .assembly | .allTypes | .method | .property | .field } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { false } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Bool { | ||
public static func decode(_ attribute: Attribute) throws -> Self { | ||
let arguments = try attribute.arguments | ||
guard arguments.count == 1, | ||
case .constant(let constant) = arguments[0], | ||
case .boolean(let value) = constant else { throw InvalidMetadataError.attributeArguments } | ||
|
||
return value | ||
return .init(value) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/// Indicates that an enumeration can be treated as a bit field; that is, a set of flags. | ||
public enum FlagsAttribute: AttributeType { | ||
public struct FlagsAttribute: AttributeType { | ||
public static var namespace: String? { "System" } | ||
public static var name: String { "FlagsAttribute" } | ||
public static var validOn: AttributeTargets { .enum } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { false } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Void {} | ||
public static func decode(_ attribute: Attribute) throws -> Self { .init() } | ||
} |
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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
public enum GuidAttribute: AttributeType { | ||
public struct GuidAttribute: AttributeType { | ||
public var value: String | ||
|
||
public init(_ value: String) { | ||
self.value = value | ||
} | ||
|
||
public static var namespace: String? { "System.Runtime.InteropServices" } | ||
public static var name: String { "GuidAttribute" } | ||
public static var validOn: AttributeTargets { .assembly | .allTypes } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> String { | ||
public static func decode(_ attribute: Attribute) throws -> GuidAttribute { | ||
let arguments = try attribute.arguments | ||
guard arguments.count == 1, | ||
case .constant(let constant) = arguments[0], | ||
case .string(let value) = constant else { throw InvalidMetadataError.attributeArguments } | ||
return value | ||
return .init(value) | ||
} | ||
} |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...dowsMetadata/AllowMultipleAttribute.swift → ...a/Attributes/AllowMultipleAttribute.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import DotNetMetadata | ||
|
||
/// Indicates that multiple instances of a custom attribute can be applied to a target. | ||
public enum AllowMultipleAttribute: AttributeType { | ||
public struct AllowMultipleAttribute: AttributeType { | ||
public static var namespace: String? { "Windows.Foundation.Metadata" } | ||
public static var name: String { "AllowMultipleAttribute" } | ||
public static var validOn: AttributeTargets { .class } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Void {} | ||
public static func decode(_ attribute: Attribute) throws -> Self { .init() } | ||
} |
4 changes: 2 additions & 2 deletions
4
...indowsMetadata/ApiContractAttribute.swift → ...ata/Attributes/ApiContractAttribute.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import DotNetMetadata | ||
|
||
/// Specifies that the type represents an API contract. | ||
public enum ApiContractAttribute: AttributeType { | ||
public struct ApiContractAttribute: AttributeType { | ||
public static var namespace: String? { "Windows.Foundation.Metadata" } | ||
public static var name: String { "ApiContractAttribute" } | ||
public static var validOn: AttributeTargets { .enum } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Void {} | ||
public static func decode(_ attribute: Attribute) throws -> Self { .init() } | ||
} |
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...es/WindowsMetadata/DefaultAttribute.swift → ...etadata/Attributes/DefaultAttribute.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
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
File renamed without changes.
14 changes: 10 additions & 4 deletions
14
...sMetadata/DualApiPartitionAttribute.swift → ...ttributes/DualApiPartitionAttribute.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 |
---|---|---|
@@ -1,20 +1,26 @@ | ||
import DotNetMetadata | ||
|
||
public enum DualApiPartitionAttribute: AttributeType { | ||
public struct DualApiPartitionAttribute: AttributeType { | ||
public var version: Version | ||
|
||
public init(_ version: Version) { | ||
self.version = version | ||
} | ||
|
||
public static var namespace: String? { "Windows.Foundation.Metadata" } | ||
public static var name: String { "DualApiPartitionAttribute" } | ||
public static var validOn: AttributeTargets { .class } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Version { | ||
public static func decode(_ attribute: Attribute) throws -> Self { | ||
let namedArguments = try attribute.namedArguments | ||
if namedArguments.count == 0 { return Version(major: 0, minor: 0) } | ||
if namedArguments.count == 0 { return .init(Version(major: 0, minor: 0)) } | ||
guard namedArguments.count <= 1, | ||
case .field(let field) = namedArguments[0].target, | ||
field.name == "version", | ||
case .constant(let versionConstant) = namedArguments[0].value, | ||
case .uint32(let versionValue) = versionConstant else { throw InvalidMetadataError.attributeArguments } | ||
return Version(unpacking: versionValue) | ||
return .init(Version(unpacking: versionValue)) | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
...indowsMetadata/ExclusiveToAttribute.swift → ...ata/Attributes/ExclusiveToAttribute.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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import DotNetMetadata | ||
|
||
public enum ExclusiveToAttribute: AttributeType { | ||
public struct ExclusiveToAttribute: AttributeType { | ||
public var target: ClassDefinition | ||
|
||
public init(_ target: ClassDefinition) { | ||
self.target = target | ||
} | ||
|
||
public static var namespace: String? { "Windows.Foundation.Metadata" } | ||
public static var name: String { "ExclusiveToAttribute" } | ||
public static var validOn: AttributeTargets { .interface } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> ClassDefinition { | ||
public static func decode(_ attribute: Attribute) throws -> ExclusiveToAttribute { | ||
let arguments = try attribute.arguments | ||
guard arguments.count == 1, | ||
case .type(let target) = arguments[0], | ||
let targetClass = target as? ClassDefinition else { throw InvalidMetadataError.attributeArguments } | ||
return targetClass | ||
return .init(targetClass) | ||
} | ||
} |
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
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
4 changes: 2 additions & 2 deletions
4
...s/WindowsMetadata/InternalAttribute.swift → ...tadata/Attributes/InternalAttribute.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import DotNetMetadata | ||
|
||
/// Indicates that the interface contains internal methods. | ||
public enum InternalAttribute: AttributeType { | ||
public struct InternalAttribute: AttributeType { | ||
public static var namespace: String? { "Windows.Foundation.Metadata" } | ||
public static var name: String { "InternalAttribute" } | ||
public static var validOn: AttributeTargets { .none } // No attribute target for interface implementations | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Void {} | ||
public static func decode(_ attribute: Attribute) throws -> Self { .init() } | ||
} |
12 changes: 9 additions & 3 deletions
12
...s/WindowsMetadata/LengthIsAttribute.swift → ...tadata/Attributes/LengthIsAttribute.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 |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import DotNetMetadata | ||
|
||
/// Indicates the number of array elements. | ||
public enum LengthIsAttribute: AttributeType { | ||
public struct LengthIsAttribute: AttributeType { | ||
public var paramIndex: Int32 | ||
|
||
public init(_ paramIndex: Int32) { | ||
self.paramIndex = paramIndex | ||
} | ||
|
||
public static var namespace: String? { "Windows.Foundation.Metadata" } | ||
public static var name: String { "LengthIsAttribute" } | ||
public static var validOn: AttributeTargets { .param } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Int32 { | ||
public static func decode(_ attribute: Attribute) throws -> Self { | ||
let arguments = try attribute.arguments | ||
guard arguments.count == 1, | ||
case .constant(let constant) = arguments[0], | ||
case .int32(let value) = constant else { throw InvalidMetadataError.attributeArguments } | ||
return value | ||
return .init(value) | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
...etadata/MarshalingBehaviorAttribute.swift → ...ributes/MarshalingBehaviorAttribute.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
4 changes: 2 additions & 2 deletions
4
...indowsMetadata/NoExceptionAttribute.swift → ...ata/Attributes/NoExceptionAttribute.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import DotNetMetadata | ||
|
||
/// Indicates that the interface contains protected methods. | ||
public enum NoExceptionAttribute: AttributeType { | ||
public struct NoExceptionAttribute: AttributeType { | ||
public static var namespace: String? { "Windows.Foundation.Metadata" } | ||
public static var name: String { "NoExceptionAttribute" } | ||
public static var validOn: AttributeTargets { .method | .property } | ||
public static var allowMultiple: Bool { false } | ||
public static var inherited: Bool { true } | ||
|
||
public static func decode(_ attribute: Attribute) throws -> Void {} | ||
public static func decode(_ attribute: Attribute) throws -> Self { .init() } | ||
} |
Oops, something went wrong.