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

Argiris Kirtzidis akyrtzi at gmail.com
Thu Aug 7 13:55:34 PDT 2008


Author: akirtzidis
Date: Thu Aug  7 15:55:28 2008
New Revision: 54488

URL: http://llvm.org/viewvc/llvm-project?rev=54488&view=rev
Log:
Add CXXRecordType class.

Modified:
    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/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=54488&r1=54487&r2=54488&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Aug  7 15:55:28 2008
@@ -31,6 +31,7 @@
   class TypedefDecl;
   class TagDecl;
   class RecordDecl;
+  class CXXRecordDecl;
   class EnumDecl;
   class FieldDecl;
   class ObjCInterfaceDecl;
@@ -1042,6 +1043,7 @@
 /// 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 {
+protected:
   explicit RecordType(RecordDecl *D) : TagType(cast<TagDecl>(D), QualType()) { }
   friend class ASTContext;   // ASTContext creates these.
 public:
@@ -1066,6 +1068,25 @@
   static bool classof(const RecordType *) { return true; }
 };
 
+/// CXXRecordType - This is a helper class that allows the use of
+/// isa/cast/dyncast to detect TagType objects of C++ structs/unions/classes.
+class CXXRecordType : public RecordType {
+  explicit CXXRecordType(CXXRecordDecl *D)
+    : RecordType(reinterpret_cast<RecordDecl*>(D)) { }
+  friend class ASTContext;   // ASTContext creates these.
+public:
+
+  CXXRecordDecl *getDecl() const {
+    return reinterpret_cast<CXXRecordDecl*>(RecordType::getDecl());
+  }
+
+  static bool classof(const TagType *T);
+  static bool classof(const Type *T) {
+    return isa<TagType>(T) && classof(cast<TagType>(T));
+  }
+  static bool classof(const CXXRecordType *) { 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 {

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Aug  7 15:55:28 2008
@@ -13,6 +13,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallVector.h"
@@ -851,16 +852,18 @@
   else if (ObjCInterfaceDecl *ObjCInterface 
              = dyn_cast_or_null<ObjCInterfaceDecl>(Decl))
     return getObjCInterfaceType(ObjCInterface);
-  else if (RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Decl)) {
+
+  if (CXXRecordDecl *CXXRecord = dyn_cast_or_null<CXXRecordDecl>(Decl))
+    Decl->TypeForDecl = new CXXRecordType(CXXRecord);
+  else if (RecordDecl *Record = dyn_cast_or_null<RecordDecl>(Decl))
     Decl->TypeForDecl = new RecordType(Record);
-    Types.push_back(Decl->TypeForDecl);
-    return QualType(Decl->TypeForDecl, 0);
-  } else if (EnumDecl *Enum = dyn_cast_or_null<EnumDecl>(Decl)) {
+  else if (EnumDecl *Enum = dyn_cast_or_null<EnumDecl>(Decl))
     Decl->TypeForDecl = new EnumType(Enum);
-    Types.push_back(Decl->TypeForDecl);
-    return QualType(Decl->TypeForDecl, 0);    
-  } else
+  else
     assert(false && "TypeDecl without a type?");
+
+  Types.push_back(Decl->TypeForDecl);
+  return QualType(Decl->TypeForDecl, 0);
 }
 
 /// getTypedefType - Return the unique reference to the type for the

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Thu Aug  7 15:55:28 2008
@@ -13,6 +13,7 @@
 
 #include "clang/AST/Type.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Expr.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -739,6 +740,10 @@
   return isa<RecordDecl>(TT->getDecl());
 }
 
+bool CXXRecordType::classof(const TagType *TT) {
+  return isa<CXXRecordDecl>(TT->getDecl());
+}
+
 bool EnumType::classof(const TagType *TT) {
   return isa<EnumDecl>(TT->getDecl());
 }





More information about the cfe-commits mailing list