std::string RecName = clsDeclared->getIdentifier()->getName();
RecName += "_IMPL";
IdentifierInfo *II = &Context->Idents.get(RecName.c_str());
- RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
+ RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl,
SourceLocation(), II, 0);
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
std::string RecName = clsDeclared->getIdentifier()->getName();
RecName += "_IMPL";
IdentifierInfo *II = &Context->Idents.get(RecName.c_str());
- RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
+ RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl,
SourceLocation(), II, 0);
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
void RewriteObjC::SynthMsgSendSuperFunctionDecl() {
IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_msgSendSuper");
llvm::SmallVector<QualType, 16> ArgTys;
- RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
+ RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl,
SourceLocation(),
&Context->Idents.get("objc_super"), 0);
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
IdentifierInfo *msgSendIdent =
&Context->Idents.get("objc_msgSendSuper_stret");
llvm::SmallVector<QualType, 16> ArgTys;
- RecordDecl *RD = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
+ RecordDecl *RD = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl,
SourceLocation(),
&Context->Idents.get("objc_super"), 0);
QualType argT = Context->getPointerType(Context->getTagDeclType(RD));
// struct objc_super { struct objc_object *receiver; struct objc_class *super; };
QualType RewriteObjC::getSuperStructType() {
if (!SuperStructDecl) {
- SuperStructDecl = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
+ SuperStructDecl = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl,
SourceLocation(),
&Context->Idents.get("objc_super"), 0);
QualType FieldTypes[2];
QualType RewriteObjC::getConstantStringStructType() {
if (!ConstantStringDecl) {
- ConstantStringDecl = RecordDecl::Create(*Context, Decl::Struct, TUDecl,
+ ConstantStringDecl = RecordDecl::Create(*Context, TagDecl::TK_struct, TUDecl,
SourceLocation(),
&Context->Idents.get("__NSConstantStringImpl"), 0);
QualType FieldTypes[4];
}
+
+
/// TagDecl - Represents the declaration of a struct/union/class/enum.
class TagDecl : public TypeDecl {
+public:
+ enum TagKind {
+ TK_struct,
+ TK_union,
+ TK_class,
+ TK_enum
+ };
+
+private:
/// IsDefinition - True if this is a definition ("struct foo {};"), false if
/// it is a declaration ("struct foo;").
bool IsDefinition : 1;
}
const char *getKindName() const {
+ switch (getTagKind()) {
+ default: assert(0 && "Unknown TagKind!");
+ case TK_struct: return "struct";
+ case TK_union: return "union";
+ case TK_class: return "class";
+ case TK_enum: return "enum";
+ }
+ }
+
+ TagKind getTagKind() const {
switch (getKind()) {
default: assert(0 && "Unknown TagDecl!");
- case Struct: return "struct";
- case Union: return "union";
- case Class: return "class";
- case Enum: return "enum";
+ case Struct: case CXXStruct: return TK_struct;
+ case Union: case CXXUnion: return TK_union;
+ case Class: case CXXClass: return TK_class;
+ case Enum: return TK_enum;
}
}
+
+ bool isStruct() const { return getKind() == Struct || getKind() == CXXStruct;}
+ bool isClass() const { return getKind() == Class || getKind() == CXXClass; }
+ bool isUnion() const { return getKind() == Union || getKind() == CXXUnion; }
+ bool isEnum() const { return getKind() == Enum; }
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {
}
public:
- static RecordDecl *Create(ASTContext &C, Kind DK, DeclContext *DC,
+ static RecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
ScopedDecl *PrevDecl);
assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
}
public:
- static CXXRecordDecl *Create(ASTContext &C, Kind DK, DeclContext *DC,
+ static CXXRecordDecl *Create(ASTContext &C, TagKind TK, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
ScopedDecl *PrevDecl);
++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;
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(),
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];
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);
}
return new (Mem) CXXFieldDecl(RD, L, Id, T, BW);\r
}\r
\r
-CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, Kind DK, DeclContext *DC,\r
+CXXRecordDecl *CXXRecordDecl::Create(ASTContext &C, TagKind TK, DeclContext *DC,\r
SourceLocation L, IdentifierInfo *Id,\r
ScopedDecl *PrevDecl) {\r
+ Kind DK;\r
+ switch (TK) {\r
+ case TK_enum: assert(0 && "Enum TagKind passed for Record!");\r
+ case TK_struct: DK = Struct; break;\r
+ case TK_union: DK = Union; break;\r
+ case TK_class: DK = Class; break;\r
+ }\r
void *Mem = C.getAllocator().Allocate<CXXRecordDecl>();\r
return new (Mem) CXXRecordDecl(DK, DC, L, Id, PrevDecl);\r
}\r
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;
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;
}
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
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
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();
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();
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;
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))
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;
}
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;
}
// Okay, this is a definition of a type. Compile the implementation now.
- if (TD->getKind() == Decl::Enum) {
+ if (TD->isEnum()) {
// Don't bother storing enums in TagDeclTypes.
return ConvertTypeRecursive(cast<EnumDecl>(TD)->getIntegerType());
}
const llvm::Type *ResultType;
const RecordDecl *RD = cast<const RecordDecl>(TD);
- if (TD->getKind() == Decl::Struct || TD->getKind() == Decl::Class) {
+ if (TD->isStruct() || TD->isClass()) {
// Layout fields.
RecordOrganizer RO(*this, *RD);
RO.getPaddingFields());
ResultType = RO.getLLVMType();
- } else if (TD->getKind() == Decl::Union) {
+ } else if (TD->isUnion()) {
// Just use the largest element of the union, breaking ties with the
// highest aligned member.
if (RD->getNumMembers() != 0) {
PushOnScopeChains(IDecl, TUScope);
// Synthesize "typedef struct objc_selector *SEL;"
- RecordDecl *SelTag = RecordDecl::Create(Context, Decl::Struct, CurContext,
+ RecordDecl *SelTag = RecordDecl::Create(Context, TagDecl::TK_struct, CurContext,
SourceLocation(),
&Context.Idents.get("objc_selector"),
0);
TranslationUnitDecl *TUDecl = Context.getTranslationUnitDecl();
// Synthesize "typedef struct objc_class *Class;"
- RecordDecl *ClassTag = RecordDecl::Create(Context, Decl::Struct,
+ RecordDecl *ClassTag = RecordDecl::Create(Context, TagDecl::TK_struct,
TUDecl,
SourceLocation(),
&IT.get("objc_class"), 0);
// Synthesize "typedef struct objc_object { Class isa; } *id;"
RecordDecl *ObjectTag =
- RecordDecl::Create(Context, Decl::Struct, TUDecl,
+ RecordDecl::Create(Context, TagDecl::TK_struct, TUDecl,
SourceLocation(),
&IT.get("objc_object"), 0);
FieldDecl *IsaDecl = FieldDecl::Create(Context, SourceLocation(),
assert((Name != 0 || TK == TK_Definition) &&
"Nameless record must be a definition!");
- Decl::Kind Kind;
+ TagDecl::TagKind Kind;
switch (TagType) {
default: assert(0 && "Unknown tag type!");
- case DeclSpec::TST_struct: Kind = Decl::Struct; break;
- case DeclSpec::TST_union: Kind = Decl::Union; break;
- case DeclSpec::TST_class: Kind = Decl::Class; break;
- case DeclSpec::TST_enum: Kind = Decl::Enum; break;
+ case DeclSpec::TST_struct: Kind = TagDecl::TK_struct; break;
+ case DeclSpec::TST_union: Kind = TagDecl::TK_union; break;
+ case DeclSpec::TST_class: Kind = TagDecl::TK_class; break;
+ case DeclSpec::TST_enum: Kind = TagDecl::TK_enum; break;
}
// If this is a named struct, check to see if there was a previous forward
IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
// Make sure that this wasn't declared as an enum and now used as a struct
// or something similar.
- if (PrevDecl->getKind() != Kind) {
+ if (PrevTagDecl->getTagKind() != Kind) {
Diag(KWLoc, diag::err_use_with_wrong_tag, Name->getName());
Diag(PrevDecl->getLocation(), diag::err_previous_use);
}
// Otherwise, if this is the first time we've seen this tag, create the decl.
TagDecl *New;
- switch (Kind) {
- default: assert(0 && "Unknown tag kind!");
- case Decl::Enum:
+ if (Kind == TagDecl::TK_enum) {
// FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
// enum X { A, B, C } D; D should chain to X.
New = EnumDecl::Create(Context, CurContext, Loc, Name, 0);
// If this is an undefined enum, warn.
if (TK != TK_Definition) Diag(Loc, diag::ext_forward_ref_enum);
- break;
- case Decl::Union:
- case Decl::Struct:
- case Decl::Class:
+ } else {
+ // struct/union/class
+
// FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
// struct X { int A; } D; D should chain to X.
New = RecordDecl::Create(Context, Kind, CurContext, Loc, Name, 0);
- break;
}
// If this has an identifier, add it to the scope stack.
continue;
}
if (i != NumFields-1 || // ... that the last member ...
- Record->getKind() != Decl::Struct || // ... of a structure ...
+ !Record->isStruct() || // ... of a structure ...
!FDTy->isArrayType()) { //... may have incomplete array type.
Diag(FD->getLocation(), diag::err_field_incomplete, FD->getName());
FD->setInvalidDecl();
if (const RecordType *FDTTy = FDTy->getAsRecordType()) {
if (FDTTy->getDecl()->hasFlexibleArrayMember()) {
// If this is a member of a union, then entire union becomes "flexible".
- if (Record && Record->getKind() == Decl::Union) {
+ if (Record && Record->isUnion()) {
Record->setHasFlexibleArrayMember(true);
} else {
// If this is a struct/class and this is not the last element, reject
// C++ [class.union]p1:
// A union shall not have base classes.
- if (Decl->getKind() == Decl::Union) {
+ if (Decl->isUnion()) {
Diag(Decl->getLocation(), diag::err_base_clause_on_union,
SpecifierRange);
Decl->setInvalidDecl();
for (int i = 0; i < structDecl->getNumMembers(); i++)
if (structDecl->getMember(i)->getIdentifier())
++InitializableMembers;
- if (structDecl->getKind() == Decl::Union)
+ if (structDecl->isUnion())
return std::min(InitializableMembers, 1);
return InitializableMembers - structDecl->hasFlexibleArrayMember();
}