Implemented parsing of objctive-c protocol conforming type used in

an identifier statement. Fixed up pretty priting to print this type 
correctly.

llvm-svn: 42866
This commit is contained in:
Fariborz Jahanian 2007-10-11 18:08:47 +00:00
parent 007aa378ad
commit d797113659
3 changed files with 37 additions and 4 deletions

View File

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

View File

@ -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<IdentifierInfo *, 8> ProtocolRefs;
ParseObjCProtocolReferences(ProtocolRefs);
llvm::SmallVector<DeclTy *, 8> *ProtocolDecl =
new llvm::SmallVector<DeclTy *, 8>;
DS.setProtocolQualifiers(ProtocolDecl);
Actions.FindProtocolDeclaration(IdentTok.getLocation(),
&ProtocolRefs[0], ProtocolRefs.size(),
*ProtocolDecl);
}
// ParseDeclarationSpecifiers will continue from there.
ParseDeclarationSpecifiers(DS);

View File

@ -0,0 +1,19 @@
// RUN: clang -ast-print %s
@protocol P1 @end
@protocol P2 @end
@protocol P3 @end
@interface INTF
- (INTF<P1>*) METH;
@end
void foo()
{
INTF *pintf;
INTF<P1>* p1;
INTF<P1, P1>* p2;
INTF<P1, P3>* p3;
INTF<P1, P3, P2>* p4;
INTF<P2,P2, P3, P1>* p5;
}