[cfe-commits] r42866 - in /cfe/trunk: AST/Type.cpp Parse/ParseStmt.cpp test/Parser/objc-type-printing.m

Fariborz Jahanian fjahanian at apple.com
Thu Oct 11 11:08:47 PDT 2007


Author: fjahanian
Date: Thu Oct 11 13:08:47 2007
New Revision: 42866

URL: http://llvm.org/viewvc/llvm-project?rev=42866&view=rev
Log:
Implemented parsing of objctive-c protocol conforming type used in 
an identifier statement. Fixed up pretty priting to print this type 
correctly.

Added:
    cfe/trunk/test/Parser/objc-type-printing.m
Modified:
    cfe/trunk/AST/Type.cpp
    cfe/trunk/Parse/ParseStmt.cpp

Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=42866&r1=42865&r2=42866&view=diff

==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Thu Oct 11 13:08:47 2007
@@ -858,14 +858,18 @@
 
 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 {

Modified: cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseStmt.cpp?rev=42866&r1=42865&r2=42866&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/Parse/ParseStmt.cpp Thu Oct 11 13:08:47 2007
@@ -235,6 +235,16 @@
                                        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);

Added: cfe/trunk/test/Parser/objc-type-printing.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-type-printing.m?rev=42866&view=auto

==============================================================================
--- cfe/trunk/test/Parser/objc-type-printing.m (added)
+++ cfe/trunk/test/Parser/objc-type-printing.m Thu Oct 11 13:08:47 2007
@@ -0,0 +1,19 @@
+// RUN: clang -ast-print %s
+
+ at protocol P1 @end
+ at protocol P2 @end
+ at protocol P3 @end
+
+ at interface INTF 
+- (INTF<P1>*) METH;
+ at 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;
+}





More information about the cfe-commits mailing list