<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>(moved to swift-dev)<br></div>
<div> </div>
<div>I went ahead and implemented this over the weekend, but ran into some weird behavior when testing it. I defined a new macro<br></div>
<div> </div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"># if defined(__has_feature) && __has_feature(generalized_swift_name)</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"># define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name; enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_EXTRA _name : _type</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"># else</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"># define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name)</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"># endif</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div> </div>
<div>and taught ClangImporter to handle macros named SWIFT_ENUM_NAMED in addition to SWIFT_ENUM, and then I generated a header that contains<br></div>
<div> </div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">typedef SWIFT_ENUM_NAMED(NSInteger, FooBar, "Bar") {<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> FooBarBaz = 0,<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> FooBarQux = 1,<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">};<br></span></div>
<div> </div>
<div>When I add a module.modulemap and import the module into the swift integrated REPL, :print_module shows the enum<br></div>
<div> </div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">enum Bar : Int {<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> init?(rawValue: Int)<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> var rawValue: Int {<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> get {}<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> }<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> case FooBarBaz<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> case FooBarQux<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">}<br></span></div>
<div> </div>
<div>(I haven't touched case prefix stripping; presumably it's trying to strip the Swift name instead of the ObjC name)<br></div>
<div> </div>
<div>But if I actually try and reference the type Bar, it tells me it's an undeclared type! I tried dumping the importer lookup table with swift-ide-test, and while I don't actually understand the output format, from looking at the IDE/dump_swift_lookup_tables.swift test, I get the impression that the following is wrong (emphasis mine):<br></div>
<div> </div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><<Bridging header lookup table>><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">Base name -> entry mappings:<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> Bar:<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> TU: FooBar<br><b> FooBar:<br></b></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><b> TU: FooBar, FooBar</b><b><br></b></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><b></b> FooBarBaz:<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> FooBar: FooBarBaz<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> FooBarQux:<br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> FooBar: FooBarQux<br></span></div>
<div> </div>
<div>I suspect that using __attribute__((swift_name)) was never tested with enums, because there's no pre-existing enum macro that supports it. Should I just file this as a bug and submit my PR as-is? Or do you have any guidance on what might be going on here?<br></div>
<div> </div>
<div>-Kevin Ballard</div>
<div> </div>
<div>On Fri, Dec 11, 2015, at 10:05 PM, Douglas Gregor wrote:<br></div>
<blockquote type="cite"><div> </div>
<div><div>Hrm, that’s a good point. The generalized swift_name support is implemented in upstream Clang, but you’re right that Xcode 7.2 won’t be able to parse it. We can add a “__has_feature” entry for generalized swift_name in Clang and wrap this particular use of swift_name in<br></div>
<div> </div>
<div><span style="white-space:pre;"></span>#if __has_feature(generalized_swift_name)<br></div>
<div><span style="white-space:pre;"></span>// ...<br></div>
<div><span style="white-space:pre;"></span>#endif<br></div>
<div> </div>
<blockquote type="cite"><div><div><div>I'm also not sure offhand where you actually put the attribute on an enum, since the enum definition is actually 2 declarations, one for the typedef and one for the enum itself. Would it go after the `enum` keyword, in the place where SWIFT_ENUM_EXTRA is? <br></div>
</div>
</div>
</blockquote></div>
<div>Yes, that’s correct.<br></div>
<div> </div>
<div><span style="white-space:pre;"></span>- Doug<br></div>
<div> </div>
</blockquote><div> </div>
</body>
</html>