Skip to content

Commit

Permalink
Objective-C. Assortment of improvements pretty printing
Browse files Browse the repository at this point in the history
objective-C declarations, including printing of availability
attributes on methods.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219013 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Fariborz Jahanian committed Oct 3, 2014
1 parent 7f5bedf commit 15f47d4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,11 +954,12 @@ void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {

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 << ';';
Expand All @@ -968,13 +969,15 @@ void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
std::string I = OID->getNameAsString();
ObjCInterfaceDecl *SID = OID->getSuperClass();

bool eolnOut = false;
if (SID)
Out << "@implementation " << I << " : " << *SID;
else
Out << "@implementation " << I;

if (OID->ivar_size() > 0) {
Out << "{\n";
eolnOut = true;
Indentation += Policy.Indentation;
for (const auto *I : OID->ivars()) {
Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
Expand All @@ -983,7 +986,13 @@ void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
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";
}

Expand Down Expand Up @@ -1022,14 +1031,14 @@ void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
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...
}
Expand Down
41 changes: 41 additions & 0 deletions test/Misc/ast-print-objectivec.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s

@interface NSObject @end

@protocol P
- (void)MethP __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)));
@end

@interface I : NSObject <P>
- (void)MethI __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)));
@end

@interface I(CAT)
- (void)MethCAT __attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)));
@end

@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))) {}
@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

0 comments on commit 15f47d4

Please sign in to comment.