diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-06-09 23:19:58 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-06-09 23:19:58 +0000 |
commit | 39ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3 (patch) | |
tree | 0bd41bdbfdd41514deb4fbd92ddf3bade3030d8b /lib/Sema | |
parent | d3bb44f0f1a83cb208d3e61ee80afe6a4d20d2d8 (diff) |
-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
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 28 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaInit.cpp | 2 |
4 files changed, 17 insertions, 21 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 980717f15e..3861d04bf0 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -57,7 +57,7 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { 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); @@ -98,7 +98,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) 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); @@ -117,7 +117,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) // 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(), diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1b1e636a76..ba005b2c60 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1637,13 +1637,13 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK, 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 @@ -1662,7 +1662,7 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK, 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); } @@ -1705,22 +1705,18 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK, // 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. @@ -1959,7 +1955,7 @@ void Sema::ActOnFields(Scope* S, 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(); @@ -1982,7 +1978,7 @@ void Sema::ActOnFields(Scope* S, 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 diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index a7135ea4cf..45affcab16 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -285,7 +285,7 @@ void Sema::ActOnBaseSpecifier(DeclTy *classdecl, SourceRange SpecifierRange, // 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(); diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index e2377e18ba..0078cc149c 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -42,7 +42,7 @@ int InitListChecker::numStructUnionElements(QualType DeclType) { 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(); } |