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

Chris Lattner sabre at nondot.org
Sun Apr 6 14:58:47 PDT 2008


Author: lattner
Date: Sun Apr  6 16:58:47 2008
New Revision: 49286

URL: http://llvm.org/viewvc/llvm-project?rev=49286&view=rev
Log:
add a helper EnumType object for asking about tagtypes for enums.

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Apr  6 16:58:47 2008
@@ -1001,6 +1001,46 @@
   friend class Type;
 };
 
+/// 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 {
+  RecordType(); // DO NOT IMPLEMENT
+public:
+    
+  RecordDecl *getDecl() const {
+    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
+  }
+  
+  // FIXME: This predicate is a helper to QualType/Type. It needs to 
+  // recursively check all fields for const-ness. If any field is declared
+  // const, it needs to return false. 
+  bool hasConstFields() const { return false; }
+
+  // FIXME: RecordType needs to check when it is created that all fields are in
+  // the same address space, and return that.
+  unsigned getAddressSpace() const { return 0; }
+  
+  static bool classof(const Type *T);
+  static bool classof(const RecordType *) { return true; }
+};
+
+/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
+/// to detect TagType objects of enums.
+class EnumType : public TagType {
+  EnumType(); // DO NOT IMPLEMENT
+public:
+    
+  EnumDecl *getDecl() const {
+    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
+  }
+  
+  static bool classof(const Type *T);
+  static bool classof(const EnumType *) { return true; }
+};
+
+
+  
+  
 class ObjCInterfaceType : public Type {
   ObjCInterfaceDecl *Decl;
 protected:
@@ -1094,29 +1134,6 @@
     
 };
   
-/// 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 {
-  RecordType(); // DO NOT IMPLEMENT
-public:
-    
-  RecordDecl *getDecl() const {
-    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
-  }
-  
-  // FIXME: This predicate is a helper to QualType/Type. It needs to 
-  // recursively check all fields for const-ness. If any field is declared
-  // const, it needs to return false. 
-  bool hasConstFields() const { return false; }
-
-  // FIXME: RecordType needs to check when it is created that all fields are in
-  // the same address space, and return that.
-  unsigned getAddressSpace() const { return 0; }
-  
-  static bool classof(const Type *T);
-  static bool classof(const RecordType *) { return true; }
-};
-
 
 // Inline function definitions.
 

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Apr  6 16:58:47 2008
@@ -745,6 +745,12 @@
   return false;
 }
 
+bool EnumType::classof(const Type *T) {
+  if (const TagType *TT = dyn_cast<TagType>(T))
+    return isa<EnumDecl>(TT->getDecl());
+  return false;
+}
+
 
 //===----------------------------------------------------------------------===//
 // Type Printing





More information about the cfe-commits mailing list