-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ClangImporter] Ignore swift_name when calculating enum constant prefix
Enum constants are naturally going to be named after their ObjC name, not their Swift name. As such, ignore the swift_name attr on the enum decl when calculating the common prefix. It turns out this is actually simpler anyway as it also bypasses the swift_private handling that the code was already trying to work around.
- Loading branch information
Showing
3 changed files
with
60 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@import Foundation; | ||
|
||
#define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X))) | ||
|
||
#define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_EXTRA _name : _type | ||
|
||
typedef SWIFT_ENUM(NSInteger, Normal) { | ||
NormalOne = 0, | ||
NormalTwo, | ||
NormalThree | ||
}; | ||
|
||
// FIXME (#618): Use SWIFT_ENUM_NAMED() when support for that lands | ||
#undef SWIFT_ENUM | ||
#define SWIFT_ENUM(_type, _name) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_ENUM_NAME); enum SWIFT_COMPILE_NAME(SWIFT_ENUM_NAME) SWIFT_ENUM_EXTRA _name : _type | ||
|
||
#define SWIFT_ENUM_NAME "SwiftEnum" | ||
typedef SWIFT_ENUM(NSInteger, ObjCEnum) { | ||
ObjCEnumOne = 0, | ||
ObjCEnumTwo, | ||
ObjCEnumThree | ||
}; | ||
|
||
#undef SWIFT_ENUM_NAME | ||
#define SWIFT_ENUM_NAME "SwiftEnumTwo" | ||
typedef SWIFT_ENUM(NSInteger, ObjCEnumTwo) { | ||
// the following shouldn't have their prefixes stripped | ||
SwiftEnumTwoA, | ||
SwiftEnumTwoB, | ||
SwiftEnumTwoC | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// RUN: echo '#include "print_clang_header_swift_name.h"' > %t.m | ||
// RUN: %target-swift-ide-test -source-filename %s -print-header -header-to-print \ | ||
// RUN: %S/Inputs/print_clang_header_swift_name.h --cc-args %target-cc-options \ | ||
// RUN: -isysroot %clang-importer-sdk-path -fsyntax-only %t.m -I %S/Inputs | FileCheck %s | ||
|
||
// CHECK: enum Normal : Int { | ||
// CHECK-NOT: {{^}}} | ||
// CHECK: case One | ||
// CHECK-NEXT: case Two | ||
// CHECK-NEXT: case Three | ||
// CHECK-NEXT: } | ||
|
||
// CHECK: enum SwiftEnum : Int { | ||
// CHECK-NOT: {{^}}} | ||
// CHECK: case One | ||
// CHECK-NEXT: case Two | ||
// CHECK-NEXT: case Three | ||
// CHECK-NEXT: } | ||
|
||
// CHECK: enum SwiftEnumTwo : Int { | ||
// CHECK-NOT: {{^}}} | ||
// CHECK: case SwiftEnumTwoA | ||
// CHECK-NEXT: case SwiftEnumTwoB | ||
// CHECK-NEXT: case SwiftEnumTwoC | ||
// CHECK-NEXT: } |