r219013 - Objective-C. Assortment of improvements pretty printing
Fariborz Jahanian
fjahanian at apple.com
Fri Oct 3 13:05:33 PDT 2014
Author: fjahanian
Date: Fri Oct 3 15:05:33 2014
New Revision: 219013
URL: http://llvm.org/viewvc/llvm-project?rev=219013&view=rev
Log:
Objective-C. Assortment of improvements pretty printing
objective-C declarations, including printing of availability
attributes on methods.
Added:
cfe/trunk/test/Misc/ast-print-objectivec.m
Modified:
cfe/trunk/lib/AST/DeclPrinter.cpp
Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=219013&r1=219012&r2=219013&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Fri Oct 3 15:05:33 2014
@@ -954,11 +954,12 @@ void DeclPrinter::VisitObjCMethodDecl(Ob
if (OMD->isVariadic())
Out << ", ...";
+
+ prettyPrintAttributes(OMD);
if (OMD->getBody() && !Policy.TerseOutput) {
Out << ' ';
OMD->getBody()->printPretty(Out, nullptr, Policy);
- Out << '\n';
}
else if (Policy.PolishForDeclaration)
Out << ';';
@@ -968,6 +969,7 @@ void DeclPrinter::VisitObjCImplementatio
std::string I = OID->getNameAsString();
ObjCInterfaceDecl *SID = OID->getSuperClass();
+ bool eolnOut = false;
if (SID)
Out << "@implementation " << I << " : " << *SID;
else
@@ -975,6 +977,7 @@ void DeclPrinter::VisitObjCImplementatio
if (OID->ivar_size() > 0) {
Out << "{\n";
+ eolnOut = true;
Indentation += Policy.Indentation;
for (const auto *I : OID->ivars()) {
Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
@@ -983,7 +986,13 @@ void DeclPrinter::VisitObjCImplementatio
Indentation -= Policy.Indentation;
Out << "}\n";
}
+ else if (SID || (OID->decls_begin() != OID->decls_end())) {
+ Out << "\n";
+ eolnOut = true;
+ }
VisitDeclContext(OID, false);
+ if (!eolnOut)
+ Out << "\n";
Out << "@end";
}
@@ -1022,14 +1031,14 @@ void DeclPrinter::VisitObjCInterfaceDecl
Indentation -= Policy.Indentation;
Out << "}\n";
}
- else if (SID) {
+ else if (SID || (OID->decls_begin() != OID->decls_end())) {
Out << "\n";
eolnOut = true;
}
VisitDeclContext(OID, false);
if (!eolnOut)
- Out << ' ';
+ Out << "\n";
Out << "@end";
// FIXME: implement the rest...
}
Added: cfe/trunk/test/Misc/ast-print-objectivec.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-objectivec.m?rev=219013&view=auto
==============================================================================
--- cfe/trunk/test/Misc/ast-print-objectivec.m (added)
+++ cfe/trunk/test/Misc/ast-print-objectivec.m Fri Oct 3 15:05:33 2014
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+
+ at interface NSObject @end
+
+ at protocol P
+- (void)MethP __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)));
+ at end
+
+ at interface I : NSObject <P>
+- (void)MethI __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)));
+ at end
+
+ at interface I(CAT)
+- (void)MethCAT __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)));
+ at end
+
+ at 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))) {}
+ at end
+
+// CHECK: @protocol P
+// CHECK: - (void) MethP __attribute__((availability(macosx, introduced=10.1.0, deprecated=10.2)));
+// CHECK: @end
+
+// CHECK: @interface I : NSObject<P>
+// CHECK: - (void) MethI __attribute__((availability(macosx, introduced=10.1.0, deprecated=10.2)));
+// CHECK: @end
+
+// CHECK: @interface I(CAT)
+// CHECK: - (void) MethCAT __attribute__((availability(macosx, introduced=10.1.0, deprecated=10.2)));
+// CHECK: @end
+
+// CHECK: @implementation I
+// CHECK: - (void) MethP __attribute__((availability(macosx, introduced=10.1.0, deprecated=10.2))) {
+// CHECK: }
+
+// CHECK: - (void) MethI __attribute__((availability(macosx, introduced=10.1.0, deprecated=10.2))) {
+// CHECK: }
+
+// CHECK: @end
More information about the cfe-commits
mailing list