-Changes to TagDecl:
Added TagKind enum.
Added getTagKind() method.
Added convenience methods: isEnum(), isStruct(), isUnion(), isClass().
-RecordDecl/CXXRecordDecl::Create() accept a TagKind enum instead of a DeclKind one.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52160 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index d8e2c06..11ca78a 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -70,12 +70,12 @@
++NumTypeName;
else if (TagType *TT = dyn_cast<TagType>(T)) {
++NumTagged;
- switch (TT->getDecl()->getKind()) {
+ switch (TT->getDecl()->getTagKind()) {
default: assert(0 && "Unknown tagged type!");
- case Decl::Struct: ++NumTagStruct; break;
- case Decl::Union: ++NumTagUnion; break;
- case Decl::Class: ++NumTagClass; break;
- case Decl::Enum: ++NumTagEnum; break;
+ case TagDecl::TK_struct: ++NumTagStruct; break;
+ case TagDecl::TK_union: ++NumTagUnion; break;
+ case TagDecl::TK_class: ++NumTagClass; break;
+ case TagDecl::TK_enum: ++NumTagEnum; break;
}
} else if (isa<ObjCInterfaceType>(T))
++NumObjCInterfaces;
@@ -458,7 +458,7 @@
NewEntry->InitializeLayout(D->getNumMembers());
bool StructIsPacked = D->getAttr<PackedAttr>();
- bool IsUnion = (D->getKind() == Decl::Union);
+ bool IsUnion = D->isUnion();
if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
NewEntry->SetAlignment(std::max(NewEntry->getAlignment(),
@@ -1214,7 +1214,7 @@
QualType ASTContext::getCFConstantStringType() {
if (!CFConstantStringTypeDecl) {
CFConstantStringTypeDecl =
- RecordDecl::Create(*this, Decl::Struct, TUDecl, SourceLocation(),
+ RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(),
&Idents.get("NSConstantString"), 0);
QualType FieldTypes[4];
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index b5dba10..47334f5 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -101,10 +101,17 @@
return new (Mem) EnumDecl(DC, L, Id, PrevDecl);
}
-RecordDecl *RecordDecl::Create(ASTContext &C, Kind DK, DeclContext *DC,
+RecordDecl *RecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
ScopedDecl *PrevDecl) {
void *Mem = C.getAllocator().Allocate<RecordDecl>();
+ Kind DK;
+ switch (TK) {
+ case TK_enum: assert(0 && "Enum TagKind passed for Record!");
+ case TK_struct: DK = Struct; break;
+ case TK_union: DK = Union; break;
+ case TK_class: DK = Class; break;
+ }
return new (Mem) RecordDecl(DK, DC, L, Id, PrevDecl);
}
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index c319191..b62ca58 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -26,9 +26,16 @@
return new (Mem) CXXFieldDecl(RD, L, Id, T, BW);
}
-CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, Kind DK, DeclContext *DC,
+CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
ScopedDecl *PrevDecl) {
+ Kind DK;
+ switch (TK) {
+ case TK_enum: assert(0 && "Enum TagKind passed for Record!");
+ case TK_struct: DK = Struct; break;
+ case TK_union: DK = Union; break;
+ case TK_class: DK = Class; break;
+ }
void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();
return new (Mem) CXXRecordDecl(DK, DC, L, Id, PrevDecl);
}
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index e561a10..7e09bb1 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -63,8 +63,7 @@
return true;
case Tagged: {
const TagType *TT = cast<TagType>(CanonicalType);
- const Decl::Kind Kind = TT->getDecl()->getKind();
- return Kind == Decl::Struct || Kind == Decl::Union;
+ return !TT->getDecl()->isEnum();
}
default:
return false;
@@ -73,19 +72,19 @@
bool Type::isClassType() const {
if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType))
- if (RT->getDecl()->getKind() == Decl::Class)
+ if (RT->getDecl()->isClass())
return true;
return false;
}
bool Type::isStructureType() const {
if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType))
- if (RT->getDecl()->getKind() == Decl::Struct)
+ if (RT->getDecl()->isStruct())
return true;
return false;
}
bool Type::isUnionType() const {
if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType))
- if (RT->getDecl()->getKind() == Decl::Union)
+ if (RT->getDecl()->isUnion())
return true;
return false;
}
@@ -349,13 +348,13 @@
const RecordType *Type::getAsStructureType() const {
// If this is directly a structure type, return it.
if (const RecordType *RT = dyn_cast<RecordType>(this)) {
- if (RT->getDecl()->getKind() == Decl::Struct)
+ if (RT->getDecl()->isStruct())
return RT;
}
// If the canonical form of this type isn't the right kind, reject it.
if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
- if (RT->getDecl()->getKind() != Decl::Struct)
+ if (!RT->getDecl()->isStruct())
return 0;
// If this is a typedef for a structure type, strip the typedef off without
@@ -371,13 +370,13 @@
const RecordType *Type::getAsUnionType() const {
// If this is directly a union type, return it.
if (const RecordType *RT = dyn_cast<RecordType>(this)) {
- if (RT->getDecl()->getKind() == Decl::Union)
+ if (RT->getDecl()->isUnion())
return RT;
}
// If the canonical form of this type isn't the right kind, reject it.
if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
- if (RT->getDecl()->getKind() != Decl::Union)
+ if (!RT->getDecl()->isUnion())
return 0;
// If this is a typedef for a union type, strip the typedef off without
@@ -470,7 +469,7 @@
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::LongLong;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
- if (TT->getDecl()->getKind() == Decl::Enum)
+ if (TT->getDecl()->isEnum())
return true;
if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
return VT->getElementType()->isIntegerType();
@@ -484,7 +483,7 @@
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::LongLong;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
- if (TT->getDecl()->getKind() == Decl::Enum)
+ if (TT->getDecl()->isEnum())
return true;
if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
return ASQT->getBaseType()->isIntegralType();
@@ -493,7 +492,7 @@
bool Type::isEnumeralType() const {
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
- return TT->getDecl()->getKind() == Decl::Enum;
+ return TT->getDecl()->isEnum();
if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
return ASQT->getBaseType()->isEnumeralType();
return false;
@@ -587,7 +586,7 @@
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::LongDouble;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
- return TT->getDecl()->getKind() == Decl::Enum;
+ return TT->getDecl()->isEnum();
if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
return VT->getElementType()->isRealType();
if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
@@ -611,7 +610,7 @@
if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
return BT->getKind() != BuiltinType::Void;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
- if (TT->getDecl()->getKind() == Decl::Enum)
+ if (TT->getDecl()->isEnum())
return true;
return false;
}
@@ -623,7 +622,7 @@
bool Type::isAggregateType() const {
if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
- if (TT->getDecl()->getKind() == Decl::Struct)
+ if (TT->getDecl()->isStruct())
return true;
return false;
}