[cfe-commits] r49300 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/Type.h lib/AST/ASTContext.cpp lib/AST/Type.cpp

Chris Lattner sabre at nondot.org
Sun Apr 6 17:27:04 PDT 2008


Author: lattner
Date: Sun Apr  6 19:27:04 2008
New Revision: 49300

URL: http://llvm.org/viewvc/llvm-project?rev=49300&view=rev
Log:
clean up some logic in objc type handling.  Specifically, make it so that
there are QualType::getAsObjc* type methods, and make isa<ObjCInterfaceType>
return true for ObjCQualifiedInterfaceType's.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/Type.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sun Apr  6 19:27:04 2008
@@ -353,23 +353,22 @@
     return T->getAsStructureType() == SelStructType;
   }
 
+  //===--------------------------------------------------------------------===//
+  //                    Serialization
+  //===--------------------------------------------------------------------===//
+
+  void Emit(llvm::Serializer& S) const;
+  static ASTContext* Create(llvm::Deserializer& D);  
+  
 private:
   ASTContext(const ASTContext&); // DO NOT IMPLEMENT
   void operator=(const ASTContext&); // DO NOT IMPLEMENT
   
   void InitBuiltinTypes();
   void InitBuiltinType(QualType &R, BuiltinType::Kind K);
-
+  
   /// helper function for Objective-C specific type checking.
   bool interfaceTypesAreCompatible(QualType, QualType);
-  
-  //===--------------------------------------------------------------------===//
-  //                    Serialization
-  //===--------------------------------------------------------------------===//
-
-public:
-  void Emit(llvm::Serializer& S) const;
-  static ASTContext* Create(llvm::Deserializer& D);  
 };
   
 }  // end namespace clang

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Apr  6 19:27:04 2008
@@ -52,6 +52,8 @@
   class FunctionType;
   class OCUVectorType;
   class BuiltinType;
+  class ObjCInterfaceType;
+  class ObjCQualifiedIdType;
   class ObjCQualifiedInterfaceType;
   class StmtIteratorBase;
   
@@ -153,9 +155,11 @@
   
   void dump(const char *s = 0) const;
 
+//private:
   /// getCanonicalType - Return the canonical version of this type, with the
   /// appropriate type qualifiers on it.
   inline QualType getCanonicalType() const;
+public:
   
   /// getAddressSpace - Return the address space of this type.
   inline unsigned getAddressSpace() const;
@@ -313,11 +317,12 @@
   bool isRecordType() const;
   bool isStructureType() const;   
   bool isUnionType() const;
-  bool isComplexIntegerType() const; // GCC complex int type.
-  bool isVectorType() const; // GCC vector type.
-  bool isOCUVectorType() const; // OCU vector type.
-  bool isObjCInterfaceType() const; // includes conforming protocol type
-  bool isObjCQualifiedIdType() const; // id includes conforming protocol type
+  bool isComplexIntegerType() const;            // GCC _Complex integer type.
+  bool isVectorType() const;                    // GCC vector type.
+  bool isOCUVectorType() const;                 // OCU vector type.
+  bool isObjCInterfaceType() const;             // NSString or NSString<foo>
+  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
+  bool isObjCQualifiedIdType() const;           // id<foo>
   
   // Type Checking Functions: Check to see if this type is structurally the
   // specified type, ignoring typedefs and qualifiers, and return a pointer to
@@ -338,6 +343,10 @@
   const ComplexType *getAsComplexType() const;
   const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
   const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
+  const ObjCInterfaceType *getAsObjCInterfaceType() const;
+  const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const;
+  const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const;
+
   
   /// getDesugaredType - Return the specified type with any "sugar" removed from
   /// type type.  This takes off typedefs, typeof's etc.  If the outer level of
@@ -1060,7 +1069,8 @@
   virtual void getAsStringInternal(std::string &InnerString) const;
   
   static bool classof(const Type *T) { 
-    return T->getTypeClass() == ObjCInterface; 
+    return T->getTypeClass() == ObjCInterface ||
+           T->getTypeClass() == ObjCQualifiedInterface; 
   }
   static bool classof(const ObjCInterfaceType *) { return true; }
 };
@@ -1204,8 +1214,10 @@
   return isa<OCUVectorType>(CanonicalType.getUnqualifiedType());
 }
 inline bool Type::isObjCInterfaceType() const {
-  return isa<ObjCInterfaceType>(CanonicalType)
-           || isa<ObjCQualifiedInterfaceType>(CanonicalType);
+  return isa<ObjCInterfaceType>(CanonicalType);
+}
+inline bool Type::isObjCQualifiedInterfaceType() const {
+  return isa<ObjCQualifiedInterfaceType>(CanonicalType);
 }
 inline bool Type::isObjCQualifiedIdType() const {
   return isa<ObjCQualifiedIdType>(CanonicalType);

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49300&r1=49299&r2=49300&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Apr  6 19:27:04 2008
@@ -1427,17 +1427,18 @@
     return true;
   else if (isObjCIdType(lhs) && rhs->isObjCInterfaceType())
     return true;
-  if (ObjCInterfaceType *lhsIT = 
-      dyn_cast<ObjCInterfaceType>(lhs.getCanonicalType().getTypePtr())) {
-    ObjCQualifiedInterfaceType *rhsQI = 
-      dyn_cast<ObjCQualifiedInterfaceType>(rhs.getCanonicalType().getTypePtr());
-    return rhsQI && (lhsIT->getDecl() == rhsQI->getDecl());
-  }
-  else if (ObjCInterfaceType *rhsIT = 
-           dyn_cast<ObjCInterfaceType>(rhs.getCanonicalType().getTypePtr())) {
-    ObjCQualifiedInterfaceType *lhsQI = 
-    dyn_cast<ObjCQualifiedInterfaceType>(lhs.getCanonicalType().getTypePtr());
-    return lhsQI && (rhsIT->getDecl() == lhsQI->getDecl());
+  
+  if (const ObjCInterfaceType *lhsIT = lhs->getAsObjCInterfaceType()) {
+    const ObjCQualifiedInterfaceType *rhsQI =
+      rhs->getAsObjCQualifiedInterfaceType();
+    if (!isa<ObjCQualifiedInterfaceType>(lhsIT))
+      return rhsQI && (lhsIT->getDecl() == rhsQI->getDecl());
+  }
+  if (const ObjCInterfaceType *rhsIT = rhs->getAsObjCInterfaceType()) {
+    const ObjCQualifiedInterfaceType *lhsQI = 
+      lhs->getAsObjCQualifiedInterfaceType();
+    if (!isa<ObjCQualifiedInterfaceType>(rhsIT))
+      return lhsQI && (rhsIT->getDecl() == lhsQI->getDecl());
   }
   return false;
 }

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Apr  6 19:27:04 2008
@@ -428,6 +428,46 @@
   return getDesugaredType()->getAsOCUVectorType();
 }
 
+const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
+  // Are we directly an ObjCInterface type?
+  if (const ObjCInterfaceType *VTy = dyn_cast<ObjCInterfaceType>(this))
+    return VTy;
+  
+  // If the canonical form of this type isn't the right kind, reject it.
+  if (!isa<ObjCInterfaceType>(CanonicalType)) {  
+    // Look through type qualifiers
+    if (isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()))
+      return CanonicalType.getUnqualifiedType()->getAsObjCInterfaceType();
+    return 0;
+  }
+  
+  // If this is a typedef for an objc interface type, strip the typedef off
+  // without losing all typedef information.
+  return getDesugaredType()->getAsObjCInterfaceType();
+}
+
+const ObjCQualifiedInterfaceType *
+Type::getAsObjCQualifiedInterfaceType() const {
+  // Are we directly an ObjCQualifiedInterfaceType?
+  if (const ObjCQualifiedInterfaceType *VTy =
+         dyn_cast<ObjCQualifiedInterfaceType>(this))
+    return VTy;
+  
+  // If the canonical form of this type isn't the right kind, reject it.
+  if (!isa<ObjCQualifiedInterfaceType>(CanonicalType)) {  
+    // Look through type qualifiers
+    if (isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()))
+      return CanonicalType.getUnqualifiedType()->
+         getAsObjCQualifiedInterfaceType();
+    return 0;
+  }
+  
+  // If this is a typedef for an objc qual interface type, strip the typedef off
+  // without losing all typedef information.
+  return getDesugaredType()->getAsObjCQualifiedInterfaceType();
+}
+
+
 bool Type::isIntegerType() const {
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() >= BuiltinType::Bool &&





More information about the cfe-commits mailing list