Skip to content

Commit 0543f24

Browse files
authored
Merge pull request #8964 from CodaFi/porque-no-las-dos
2 parents a67c6d0 + 4b45b49 commit 0543f24

File tree

6 files changed

+202
-5
lines changed

6 files changed

+202
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Name: ImportAsMember
2+
Globals:
3+
- Name: IAMStruct1APINoteVar
4+
SwiftName: Struct1.newApiNoteVar
5+
- Name: IAMStruct1APINoteVarInSwift4
6+
SwiftName: Struct1.apiNoteVarInSwift4
7+
Functions:
8+
- Name: IAMStruct1APINoteFunction
9+
SwiftName: "Struct1.newApiNoteMethod()"
10+
- Name: IAMStruct1APINoteCreateFunction
11+
SwiftName: "Struct1.init(newLabel:)"
12+
Typedefs:
13+
- Name: IAMStruct1APINoteType
14+
SwiftName: Struct1.NewApiNoteType
15+
SwiftVersions:
16+
- Version: 3
17+
Globals:
18+
- Name: IAMStruct1APINoteVar
19+
SwiftName: Struct1.oldApiNoteVar
20+
- Name: IAMStruct1APINoteVarInSwift4
21+
SwiftName: IAMStruct1APINoteVarInSwift4
22+
Functions:
23+
- Name: IAMStruct1APINoteFunction
24+
SwiftName: "Struct1.oldApiNoteMethod()"
25+
- Name: IAMStruct1APINoteCreateFunction
26+
SwiftName: "Struct1.init(oldLabel:)"
27+
Typedefs:
28+
- Name: IAMStruct1APINoteType
29+
SwiftName: Struct1.OldApiNoteType
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#ifndef IMPORT_AS_MEMBER_H
2+
#define IMPORT_AS_MEMBER_H
3+
4+
struct __attribute__((swift_name("Struct1"))) IAMStruct1 {
5+
double x, y, z;
6+
};
7+
8+
extern double IAMStruct1GlobalVar
9+
__attribute__((swift_name("Struct1.globalVar")));
10+
11+
extern struct IAMStruct1 IAMStruct1CreateSimple(double value)
12+
__attribute__((swift_name("Struct1.init(value:)")));
13+
14+
extern struct IAMStruct1 IAMStruct1CreateSpecialLabel(void)
15+
__attribute__((swift_name("Struct1.init(specialLabel:)")));
16+
17+
extern struct IAMStruct1 IAMStruct1Invert(struct IAMStruct1 s)
18+
__attribute__((swift_name("Struct1.inverted(self:)")));
19+
20+
extern void IAMStruct1InvertInPlace(struct IAMStruct1 *s)
21+
__attribute__((swift_name("Struct1.invert(self:)")));
22+
23+
extern struct IAMStruct1 IAMStruct1Rotate(const struct IAMStruct1 *s,
24+
double radians)
25+
__attribute__((swift_name("Struct1.translate(self:radians:)")));
26+
27+
extern struct IAMStruct1 IAMStruct1Scale(struct IAMStruct1 s,
28+
double radians)
29+
__attribute__((swift_name("Struct1.scale(self:_:)")));
30+
31+
extern double IAMStruct1GetRadius(const struct IAMStruct1 *s)
32+
__attribute__((swift_name("getter:Struct1.radius(self:)")));
33+
34+
extern void IAMStruct1SetRadius(struct IAMStruct1 s, double radius)
35+
__attribute__((swift_name("setter:Struct1.radius(self:_:)")));
36+
37+
extern double IAMStruct1GetAltitude(struct IAMStruct1 s)
38+
__attribute__((swift_name("getter:Struct1.altitude(self:)")));
39+
40+
extern void IAMStruct1SetAltitude(struct IAMStruct1 *s, double altitude)
41+
__attribute__((swift_name("setter:Struct1.altitude(self:_:)")));
42+
43+
extern double IAMStruct1GetMagnitude(struct IAMStruct1 s)
44+
__attribute__((swift_name("getter:Struct1.magnitude(self:)")));
45+
46+
extern int IAMStruct1StaticMethod(void)
47+
__attribute__((swift_name("Struct1.staticMethod()")));
48+
extern int IAMStruct1StaticGetProperty(void)
49+
__attribute__((swift_name("getter:Struct1.property()")));
50+
extern int IAMStruct1StaticSetProperty(int i)
51+
__attribute__((swift_name("setter:Struct1.property(i:)")));
52+
extern int IAMStruct1StaticGetOnlyProperty(void)
53+
__attribute__((swift_name("getter:Struct1.getOnlyProperty()")));
54+
55+
extern void IAMStruct1SelfComesLast(double x, struct IAMStruct1 s)
56+
__attribute__((swift_name("Struct1.selfComesLast(x:self:)")));
57+
extern void IAMStruct1SelfComesThird(int a, float b, struct IAMStruct1 s, double x)
58+
__attribute__((swift_name("Struct1.selfComesThird(a:b:self:x:)")));
59+
60+
#endif // IMPORT_AS_MEMBER_H

test/ClangImporter/Inputs/custom-modules/Newtype.h

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,104 @@
11
@import Foundation;
2+
@import CoreFoundation;
3+
4+
typedef NSString *__nonnull SNTErrorDomain __attribute((swift_newtype(struct)))
5+
__attribute((swift_name("ErrorDomain")));
6+
7+
extern void SNTErrorDomainProcess(SNTErrorDomain d)
8+
__attribute((swift_name("ErrorDomain.process(self:)")));
9+
10+
typedef struct {} Food;
11+
12+
extern const SNTErrorDomain SNTErrOne
13+
__attribute((swift_name("ErrorDomain.one")));
14+
extern const SNTErrorDomain SNTErrTwo;
15+
extern const SNTErrorDomain SNTErrorDomainThree;
16+
extern const SNTErrorDomain SNTFourErrorDomain;
17+
extern const SNTErrorDomain SNTFive
18+
__attribute((swift_name("stillAMember")));
19+
extern const SNTErrorDomain SNTElsewhere
20+
__attribute((swift_name("Food.err")));
21+
22+
typedef NSString *__nullable SNTClosedEnum __attribute((swift_newtype(enum)))
23+
__attribute((swift_name("ClosedEnum")));
24+
25+
extern const SNTClosedEnum SNTFirstClosedEntryEnum;
26+
extern const SNTClosedEnum SNTSecondEntry;
27+
extern const SNTClosedEnum SNTClosedEnumThirdEntry;
28+
29+
typedef NSString * IUONewtype __attribute((swift_newtype(struct)));
30+
31+
typedef float MyFloat __attribute((swift_newtype(struct)));
32+
extern const MyFloat globalFloat;
33+
extern const MyFloat kPI;
34+
extern const MyFloat kVersion;
35+
36+
typedef int MyInt __attribute((swift_newtype(struct)));
37+
extern const MyInt kMyIntZero;
38+
extern const MyInt kMyIntOne;
39+
extern const int kRawInt;
40+
extern void takesMyInt(MyInt);
41+
42+
typedef NSString * NSURLResourceKey __attribute((swift_newtype(struct)));
43+
extern NSURLResourceKey const NSURLIsRegularFileKey;
44+
extern NSURLResourceKey const NSURLIsDirectoryKey;
45+
extern NSURLResourceKey const NSURLLocalizedNameKey;
46+
47+
// Special case: Notifications
48+
extern const NSString *FooNotification;
49+
extern const NSString *kBarNotification;
50+
extern const NSString *NSWibbleNotification;
51+
52+
// But not just 'Notification'
53+
extern const NSString *kNotification;
54+
extern const NSString *Notification;
55+
56+
// Nor when explicitly swift_name-ed
57+
extern const NSString *kSNNotification
58+
__attribute((swift_name("swiftNamedNotification")));
59+
60+
// Test CFStringRef
61+
typedef CFStringRef CFNewType __attribute((swift_newtype(struct)));
62+
63+
// CF audited
64+
_Pragma("clang arc_cf_code_audited begin")
65+
extern const CFNewType MyCFNewTypeValue;
66+
extern CFNewType FooAudited(void);
67+
_Pragma("clang arc_cf_code_audited end")
68+
extern const CFNewType MyCFNewTypeValueUnauditedButConst;
69+
70+
// un-audited CFStringRef
71+
extern CFNewType MyCFNewTypeValueUnaudited;
72+
extern CFNewType FooUnaudited(void);
73+
74+
// Tests to show identical calling convention / binary representation for
75+
// new_type and non-new_type
76+
typedef CFStringRef MyABINewType __attribute((swift_newtype(struct)));
77+
typedef CFStringRef MyABIOldType;
78+
_Pragma("clang arc_cf_code_audited begin")
79+
extern const MyABINewType kMyABINewTypeGlobal;
80+
extern const MyABIOldType kMyABIOldTypeGlobal;
81+
extern MyABINewType getMyABINewType(void);
82+
extern MyABIOldType getMyABIOldType(void);
83+
extern void takeMyABINewType(MyABINewType);
84+
extern void takeMyABIOldType(MyABIOldType);
85+
86+
extern void takeMyABINewTypeNonNull(__nonnull MyABINewType);
87+
extern void takeMyABIOldTypeNonNull(__nonnull MyABIOldType);
88+
_Pragma("clang arc_cf_code_audited end")
89+
90+
typedef NSString *MyABINewTypeNS __attribute((swift_newtype(struct)));
91+
typedef NSString *MyABIOldTypeNS;
92+
extern MyABINewTypeNS getMyABINewTypeNS(void);
93+
extern MyABIOldTypeNS getMyABIOldTypeNS(void);
94+
extern void takeMyABINewTypeNonNullNS(__nonnull MyABINewTypeNS);
95+
extern void takeMyABIOldTypeNonNullNS(__nonnull MyABIOldTypeNS);
96+
97+
// Nested types
98+
typedef struct {int i;} NSSomeContext;
99+
100+
typedef NSString *NSSomeContextName __attribute((swift_newtype(struct)))
101+
__attribute((swift_name("NSSomeContext.Name")));
102+
103+
extern const NSSomeContextName NSMyContextName;
2104

3-
typedef NSString *__nonnull SNTErrorDomain __attribute((swift_newtype(struct)));
4-
typedef NSInteger MyInt __attribute((swift_newtype(struct)));

test/ClangImporter/Inputs/custom-modules/module.map

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ module Newtype {
7777
header "Newtype.h"
7878
}
7979

80+
module ImportAsMember {
81+
export *
82+
83+
module A {
84+
header "ImportAsMember.h"
85+
}
86+
}
87+
8088
module ObjCIRExtras {
8189
header "ObjCIRExtras.h"
8290
export *

test/ClangImporter/objc_parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ func testNSUInteger(_ obj: NSUIntegerTests, uint: UInt, int: Int) {
624624
}
625625

626626
class NewtypeUser {
627-
@objc func stringNewtype(a: SNTErrorDomain) {}
628-
@objc func stringNewtypeOptional(a: SNTErrorDomain?) {}
627+
@objc func stringNewtype(a: SNTErrorDomain) {} // expected-error {{'SNTErrorDomain' has been renamed to 'ErrorDomain'}}{{31-45=ErrorDomain}}
628+
@objc func stringNewtypeOptional(a: SNTErrorDomain?) {} // expected-error {{'SNTErrorDomain' has been renamed to 'ErrorDomain'}}{{39-53=ErrorDomain}}
629629
@objc func intNewtype(a: MyInt) {}
630630
@objc func intNewtypeOptional(a: MyInt?) {} // expected-error {{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
631631
}

test/ClangImporter/swift2_warnings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk -I %S/../IDE/Inputs/custom-modules) -emit-sil -I %S/Inputs/custom-modules %s -verify
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -I %S/Inputs/custom-modules %s -verify
22

33
// REQUIRES: objc_interop
44

0 commit comments

Comments
 (0)