@@ -168,6 +168,13 @@ enum Mutability {
168
168
case Mutable
169
169
}
170
170
171
+ func getUnattributedType( _ type: TypeSyntax ) -> TypeSyntax {
172
+ if let attributedType = type. as ( AttributedTypeSyntax . self) {
173
+ return attributedType. baseType. trimmed
174
+ }
175
+ return type. trimmed
176
+ }
177
+
171
178
func getTypeName( _ type: TypeSyntax ) throws -> TokenSyntax {
172
179
switch type. kind {
173
180
case . memberType:
@@ -410,7 +417,7 @@ struct CxxSpanThunkBuilder: ParamPointerBoundsThunkBuilder {
410
417
func buildFunctionSignature( _ argTypes: [ Int : TypeSyntax ? ] , _ returnType: TypeSyntax ? ) throws
411
418
-> ( FunctionSignatureSyntax , Bool ) {
412
419
var types = argTypes
413
- let typeName = try getTypeName ( oldType) . text
420
+ let typeName = getUnattributedType ( oldType) . description
414
421
guard let desugaredType = typeMappings [ typeName] else {
415
422
throw DiagnosticError (
416
423
" unable to desugar type with name ' \( typeName) ' " , node: node)
@@ -426,7 +433,7 @@ struct CxxSpanThunkBuilder: ParamPointerBoundsThunkBuilder {
426
433
427
434
func buildFunctionCall( _ pointerArgs: [ Int : ExprSyntax ] ) throws -> ExprSyntax {
428
435
var args = pointerArgs
429
- let typeName = try getTypeName ( oldType) . text
436
+ let typeName = getUnattributedType ( oldType) . description
430
437
assert ( args [ index] == nil )
431
438
args [ index] = ExprSyntax ( " \( raw: typeName) ( \( raw: name) ) " )
432
439
return try base. buildFunctionCall ( args)
@@ -446,7 +453,7 @@ struct CxxSpanReturnThunkBuilder: BoundsCheckedThunkBuilder {
446
453
func buildFunctionSignature( _ argTypes: [ Int : TypeSyntax ? ] , _ returnType: TypeSyntax ? ) throws
447
454
-> ( FunctionSignatureSyntax , Bool ) {
448
455
assert ( returnType == nil )
449
- let typeName = try getTypeName ( signature. returnClause!. type) . text
456
+ let typeName = getUnattributedType ( signature. returnClause!. type) . description
450
457
guard let desugaredType = typeMappings [ typeName] else {
451
458
throw DiagnosticError (
452
459
" unable to desugar type with name ' \( typeName) ' " , node: node)
@@ -923,19 +930,15 @@ public struct SwiftifyImportMacro: PeerMacro {
923
930
return [ ]
924
931
}
925
932
var result : [ ParamInfo ] = [ ]
926
- let process = { type, expr, orig in
927
- do {
928
- let typeName = try getTypeName ( type) . text
929
- if let desugaredType = typeMappings [ typeName] {
930
- if let unqualifiedDesugaredType = getUnqualifiedStdName ( desugaredType) {
931
- if unqualifiedDesugaredType. starts ( with: " span< " ) {
932
- result. append ( CxxSpan ( pointerIndex: expr, nonescaping: false ,
933
- dependencies: [ ] , typeMappings: typeMappings, original: orig) )
934
- }
933
+ let process : ( TypeSyntax , SwiftifyExpr , SyntaxProtocol ) throws -> ( ) = { type, expr, orig in
934
+ let typeName = getUnattributedType ( type) . description
935
+ if let desugaredType = typeMappings [ typeName] {
936
+ if let unqualifiedDesugaredType = getUnqualifiedStdName ( desugaredType) {
937
+ if unqualifiedDesugaredType. starts ( with: " span< " ) {
938
+ result. append ( CxxSpan ( pointerIndex: expr, nonescaping: false ,
939
+ dependencies: [ ] , typeMappings: typeMappings, original: orig) )
935
940
}
936
941
}
937
- } catch is DiagnosticError {
938
- // type doesn't match expected pattern
939
942
}
940
943
}
941
944
for (idx, param) in signature. parameterClause. parameters. enumerated ( ) {
0 commit comments