diff --git a/AST/Type.cpp b/AST/Type.cpp index 7deee66070..af07d7a1be 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -858,14 +858,18 @@ void ObjcInterfaceType::getAsStringInternal(std::string &InnerString) const { void ObjcQualifiedInterfaceType::getAsStringInternal( std::string &InnerString) const { - InnerString = getInterfaceType()->getDecl()->getName() + '<'; + if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. + InnerString = ' ' + InnerString; + std::string ObjcQIString = getInterfaceType()->getDecl()->getName(); + ObjcQIString += '<'; int num = getNumProtocols(); for (int i = 0; i < num; i++) { - InnerString += getProtocols(i)->getName(); + ObjcQIString += getProtocols(i)->getName(); if (i < num-1) - InnerString += ','; + ObjcQIString += ','; } - InnerString += '>'; + ObjcQIString += '>'; + InnerString = ObjcQIString + InnerString; } void TagType::getAsStringInternal(std::string &InnerString) const { diff --git a/Parse/ParseStmt.cpp b/Parse/ParseStmt.cpp index ad6f3932f6..9df20b4ade 100644 --- a/Parse/ParseStmt.cpp +++ b/Parse/ParseStmt.cpp @@ -235,6 +235,16 @@ Parser::StmtResult Parser::ParseIdentifierStatement(bool OnlyStatement) { IdentTok.getLocation(), PrevSpec, TypeRep); assert(!isInvalid && "First declspec can't be invalid!"); + if (Tok.is(tok::less)) { + llvm::SmallVector ProtocolRefs; + ParseObjCProtocolReferences(ProtocolRefs); + llvm::SmallVector *ProtocolDecl = + new llvm::SmallVector; + DS.setProtocolQualifiers(ProtocolDecl); + Actions.FindProtocolDeclaration(IdentTok.getLocation(), + &ProtocolRefs[0], ProtocolRefs.size(), + *ProtocolDecl); + } // ParseDeclarationSpecifiers will continue from there. ParseDeclarationSpecifiers(DS); diff --git a/test/Parser/objc-type-printing.m b/test/Parser/objc-type-printing.m new file mode 100644 index 0000000000..5d3cbd994f --- /dev/null +++ b/test/Parser/objc-type-printing.m @@ -0,0 +1,19 @@ +// RUN: clang -ast-print %s + +@protocol P1 @end +@protocol P2 @end +@protocol P3 @end + +@interface INTF +- (INTF*) METH; +@end + +void foo() +{ + INTF *pintf; + INTF* p1; + INTF* p2; + INTF* p3; + INTF* p4; + INTF* p5; +}