Selector splitting: the first parameter name is always relevant.

Swift SVN r15923
This commit is contained in:
Doug Gregor
2014-04-04 04:14:34 +00:00
parent ba67a09362
commit 4bcc4daa3d
2 changed files with 25 additions and 0 deletions

View File

@@ -29,6 +29,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/raw_ostream.h"
#include "swift/Basic/Range.h"
#include "swift/Basic/StringExtras.h"
#include "clang/Basic/CharInfo.h"
#include "clang/AST/DeclObjC.h"
@@ -2209,6 +2210,17 @@ StringRef FuncDecl::getObjCSelector(SmallVectorImpl<char> &buffer) const {
return out.str();
// Otherwise, it's at least a unary selector.
// If the first tuple element has a name, uppercase and emit it.
if (tuple && getASTContext().LangOpts.SplitPrepositions) {
llvm::SmallString<16> scratch;
if (auto named = dyn_cast<NamedPattern>(
tuple->getFields()[0].getPattern()
->getSemanticsProvidingPattern())) {
out << camel_case::toSentencecase(named->getBoundName().str(), scratch);
}
}
out << ':';
// If it's a unary selector, we're done.

View File

@@ -0,0 +1,13 @@
// RUN: rm -rf %t/clang-module-cache
// RUN: %swift -split-objc-selectors -target x86_64-apple-darwin10 %s -emit-ir | FileCheck %s
// CHECK: @"\01L_selector_data(bazInt:)" = internal constant [8 x i8] c"bazInt:\00", section "__TEXT,__objc_methname,cstring_literals", align 1
// CHECK: @"\01L_selector_data(fooWithInt:)" = internal constant [12 x i8] c"fooWithInt:\00", section "__TEXT,__objc_methname,cstring_literals", align 1
class Foo {
@objc func baz(int: Int) {}
@objc(fooWithInt:) func foo(int: Int) {}
}