From: Alex Lorenz Date: Fri, 2 Jun 2017 15:02:59 +0000 (+0000) Subject: ASTPrinter: Objective-C method declarations don't need a space after X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4530cfcf71b67629177695d40973b21cd57e3d9;p=clang ASTPrinter: Objective-C method declarations don't need a space after the return type rdar://32332039 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304553 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index bc8a34c936..6eeba88e40 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -1189,7 +1189,9 @@ void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { for (const auto *PI : OMD->parameters()) { // FIXME: selector is missing here! pos = name.find_first_of(':', lastPos); - Out << " " << name.substr(lastPos, pos - lastPos) << ':'; + if (lastPos != 0) + Out << " "; + Out << name.substr(lastPos, pos - lastPos) << ':'; PrintObjCMethodType(OMD->getASTContext(), PI->getObjCDeclQualifier(), PI->getType()); @@ -1198,7 +1200,7 @@ void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { } if (OMD->param_begin() == OMD->param_end()) - Out << " " << name; + Out << name; if (OMD->isVariadic()) Out << ", ..."; diff --git a/test/Misc/ast-print-objectivec.m b/test/Misc/ast-print-objectivec.m index e419237bbb..cb5aacc06a 100644 --- a/test/Misc/ast-print-objectivec.m +++ b/test/Misc/ast-print-objectivec.m @@ -17,25 +17,30 @@ @implementation I - (void)MethP __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2))) {} - (void)MethI __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2))) {} + +- (void)methodWithArg:(int)x andAnotherOne:(int)y { } @end // CHECK: @protocol P -// CHECK: - (void) MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))); +// CHECK: - (void)MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))); // CHECK: @end // CHECK: @interface I : NSObject

-// CHECK: - (void) MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))); +// CHECK: - (void)MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))); // CHECK: @end // CHECK: @interface I(CAT) -// CHECK: - (void) MethCAT __attribute__((availability(macos, introduced=10_1_0, deprecated=10_2))); +// CHECK: - (void)MethCAT __attribute__((availability(macos, introduced=10_1_0, deprecated=10_2))); // CHECK: @end // CHECK: @implementation I -// CHECK: - (void) MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) { +// CHECK: - (void)MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) { +// CHECK: } + +// CHECK: - (void)MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) { // CHECK: } -// CHECK: - (void) MethI __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2))) { +// CHECK: - (void)methodWithArg:(int)x andAnotherOne:(int)y { // CHECK: } // CHECK: @end diff --git a/test/Modules/lookup.m b/test/Modules/lookup.m index edf70639e5..b22e41f845 100644 --- a/test/Modules/lookup.m +++ b/test/Modules/lookup.m @@ -14,7 +14,7 @@ void test(id x) { // expected-note@Inputs/lookup_right.h:3{{also found}} } -// CHECK-PRINT: - (int) method; -// CHECK-PRINT: - (double) method +// CHECK-PRINT: - (int)method; +// CHECK-PRINT: - (double)method // CHECK-PRINT: void test(id x) diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp index e5a09a31f6..ae6d0f0dd2 100644 --- a/unittests/AST/DeclPrinterTest.cpp +++ b/unittests/AST/DeclPrinterTest.cpp @@ -1228,7 +1228,7 @@ TEST(DeclPrinter, TestObjCMethod1) { "@end\n", namedDecl(hasName("A:inRange:"), hasDescendant(namedDecl(hasName("printThis")))).bind("id"), - "- (int) A:(id)anObject inRange:(long)range")); + "- (int)A:(id)anObject inRange:(long)range")); } TEST(DeclPrinter, TestObjCProtocol1) {