clang API Documentation
00001 //===--- BaseSubobject.h - BaseSubobject class ----------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file provides a definition of the BaseSubobject class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_BASESUBOBJECT_H 00015 #define LLVM_CLANG_AST_BASESUBOBJECT_H 00016 00017 #include "clang/AST/CharUnits.h" 00018 #include "llvm/ADT/DenseMap.h" 00019 #include "llvm/Support/DataTypes.h" 00020 #include "llvm/Support/type_traits.h" 00021 00022 namespace clang { 00023 class CXXRecordDecl; 00024 00025 // BaseSubobject - Uniquely identifies a direct or indirect base class. 00026 // Stores both the base class decl and the offset from the most derived class to 00027 // the base class. Used for vtable and VTT generation. 00028 class BaseSubobject { 00029 /// Base - The base class declaration. 00030 const CXXRecordDecl *Base; 00031 00032 /// BaseOffset - The offset from the most derived class to the base class. 00033 CharUnits BaseOffset; 00034 00035 public: 00036 BaseSubobject() { } 00037 BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset) 00038 : Base(Base), BaseOffset(BaseOffset) { } 00039 00040 /// getBase - Returns the base class declaration. 00041 const CXXRecordDecl *getBase() const { return Base; } 00042 00043 /// getBaseOffset - Returns the base class offset. 00044 CharUnits getBaseOffset() const { return BaseOffset; } 00045 00046 friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) { 00047 return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset; 00048 } 00049 }; 00050 00051 } // end namespace clang 00052 00053 namespace llvm { 00054 00055 template<> struct DenseMapInfo<clang::BaseSubobject> { 00056 static clang::BaseSubobject getEmptyKey() { 00057 return clang::BaseSubobject( 00058 DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(), 00059 clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getEmptyKey())); 00060 } 00061 00062 static clang::BaseSubobject getTombstoneKey() { 00063 return clang::BaseSubobject( 00064 DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(), 00065 clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getTombstoneKey())); 00066 } 00067 00068 static unsigned getHashValue(const clang::BaseSubobject &Base) { 00069 typedef std::pair<const clang::CXXRecordDecl *, clang::CharUnits> PairTy; 00070 return DenseMapInfo<PairTy>::getHashValue(PairTy(Base.getBase(), 00071 Base.getBaseOffset())); 00072 } 00073 00074 static bool isEqual(const clang::BaseSubobject &LHS, 00075 const clang::BaseSubobject &RHS) { 00076 return LHS == RHS; 00077 } 00078 }; 00079 00080 // It's OK to treat BaseSubobject as a POD type. 00081 template <> struct isPodLike<clang::BaseSubobject> { 00082 static const bool value = true; 00083 }; 00084 00085 } 00086 00087 #endif