]> granicus.if.org Git - clang/commitdiff
Implemented parsing of objctive-c protocol conforming type used in
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 11 Oct 2007 18:08:47 +0000 (18:08 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 11 Oct 2007 18:08:47 +0000 (18:08 +0000)
an identifier statement. Fixed up pretty priting to print this type
correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42866 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Type.cpp
Parse/ParseStmt.cpp
test/Parser/objc-type-printing.m [new file with mode: 0644]

index 7deee66070d7d6cfde4f3bcc8c07202b73980e56..af07d7a1be8c89a33b8957dd17c504664da974ed 100644 (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 {
index ad6f3932f6ebe0b108acdc91bd042e423c1971c5..9df20b4adefc363ebd58af8a36a0843d69a1959a 100644 (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);
diff --git a/test/Parser/objc-type-printing.m b/test/Parser/objc-type-printing.m
new file mode 100644 (file)
index 0000000..5d3cbd9
--- /dev/null
@@ -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;
+}