[cfe-commits] r42776 - in /cfe/trunk: CodeGen/CodeGenTypes.cpp Driver/ASTConsumers.cpp Parse/ParseObjc.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Type.h

Fariborz Jahanian fjahanian at apple.com
Mon Oct 8 16:06:41 PDT 2007


Author: fjahanian
Date: Mon Oct  8 18:06:41 2007
New Revision: 42776

URL: http://llvm.org/viewvc/llvm-project?rev=42776&view=rev
Log:
Added a new class for Interfaces qualified by protocol list.
Protocols are now sorted and made unique in the list.
Enhanced pretty printer for @interface (So, I can see the protocol list).

Modified:
    cfe/trunk/CodeGen/CodeGenTypes.cpp
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=42776&r1=42775&r2=42776&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.cpp Mon Oct  8 18:06:41 2007
@@ -140,6 +140,10 @@
   case Type::ObjcInterface:
     assert(0 && "FIXME: add missing functionality here");
     break;
+      
+  case Type::ObjcQualifiedInterface:
+    assert(0 && "FIXME: add missing functionality here");
+    break;
 
   case Type::Tagged:
     const TagType &TT = cast<TagType>(Ty);

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=42776&r1=42775&r2=42776&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon Oct  8 18:06:41 2007
@@ -74,8 +74,26 @@
 }
 
 static void PrintObjcInterfaceDecl(ObjcInterfaceDecl *OID) {
-  std::string S = OID->getName();
-  fprintf(stderr, "@interface %s;\n", S.c_str());
+  std::string I = OID->getName();
+  ObjcInterfaceDecl *SID = OID->getSuperClass();
+  if (SID) {
+    std::string S = SID->getName();
+    fprintf(stderr, "@interface %s : %s", I.c_str(), S.c_str());
+  }
+  else
+    fprintf(stderr, "@interface %s", I.c_str());
+  // Protocols?
+  int count = OID->getNumIntfRefProtocols();
+  if (count > 0) {
+    ObjcProtocolDecl **refProtocols = OID->getReferencedProtocols();
+    for (int i = 0; i < count; i++)
+      fprintf(stderr, "%c%s", (i == 0 ? '<' : ','), 
+              refProtocols[i]->getName());
+  }
+  if (count > 0)
+    fprintf(stderr, ">;\n");
+  else
+    fprintf(stderr, ";\n");
   // FIXME: implement the rest...
 }
 

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=42776&r1=42775&r2=42776&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Mon Oct  8 18:06:41 2007
@@ -618,6 +618,12 @@
                                         MethodAttrs, MethodImplKind);
 }
 
+/// CmpProtocolVals - Comparison predicate for sorting protocols.
+static bool CmpProtocolVals(const IdentifierInfo* const& lhs,
+                            const IdentifierInfo* const& rhs) {
+  return strcmp(lhs->getName(), rhs->getName()) < 0;
+}
+
 ///   objc-protocol-refs:
 ///     '<' identifier-list '>'
 ///
@@ -640,6 +646,15 @@
       break;
     ConsumeToken();
   }
+  
+  // Sort protocols, keyed by name.
+  // Later on, we remove duplicates.
+  std::stable_sort(ProtocolRefs.begin(), ProtocolRefs.end(), CmpProtocolVals);
+  
+  // Make protocol names unique.
+  ProtocolRefs.erase(std::unique(ProtocolRefs.begin(), ProtocolRefs.end()), 
+                     ProtocolRefs.end());
+
   // Consume the '>'.
   return ExpectAndConsume(tok::greater, diag::err_expected_greater);
 }

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=42776&r1=42775&r2=42776&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Mon Oct  8 18:06:41 2007
@@ -739,6 +739,7 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=42776&r1=42775&r2=42776&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Oct  8 18:06:41 2007
@@ -32,6 +32,7 @@
   class RecordDecl;
   class EnumDecl;
   class ObjcInterfaceDecl;
+  class ObjcProtocolDecl;
   class Expr;
   class SourceLocation;
   class PointerType;
@@ -204,7 +205,7 @@
     Vector, OCUVector,
     FunctionNoProto, FunctionProto,
     TypeName, Tagged, 
-    ObjcInterface,
+    ObjcInterface, ObjcQualifiedInterface,
     TypeOfExp, TypeOfTyp // GNU typeof extension.
   };
 private:
@@ -831,6 +832,28 @@
   static bool classof(const ObjcInterfaceType *) { return true; }
 };
 
+/// - ObjcQualifiedInterfaceType - This class represense interface types 
+/// conforming to a list of protocols; such as, INTF<Proto1, Proto2, Proto1>.
+class ObjcQualifiedInterfaceType : public Type {
+  // Interface type for this protocol conforming object type
+  ObjcInterfaceType *InterfaceType;
+
+  // List of protocols for this protocol conforming object type
+  // List is sorted on protocol name. No protocol is enterred more than once.
+  llvm::SmallVector<ObjcProtocolDecl*, 8> Protocols;
+
+  ObjcQualifiedInterfaceType(ObjcInterfaceType *T) : 
+    Type(ObjcQualifiedInterface, QualType()), InterfaceType(T) { }
+public:
+  
+  ObjcInterfaceType *getInterfaceType() const { return InterfaceType; }
+
+  static bool classof(const Type *T) { 
+    return T->getTypeClass() == ObjcQualifiedInterface; 
+  }
+  static bool classof(const ObjcQualifiedInterfaceType *) { return true; }
+};
+  
 /// RecordType - This is a helper class that allows the use of isa/cast/dyncast
 /// to detect TagType objects of structs/unions/classes.
 class RecordType : public TagType {





More information about the cfe-commits mailing list