summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST')
-rw-r--r--clang/lib/AST/ASTContext.cpp5
-rw-r--r--clang/lib/AST/Decl.cpp28
-rw-r--r--clang/lib/AST/DeclBase.cpp36
-rw-r--r--clang/lib/AST/TypeSerialization.cpp3
4 files changed, 25 insertions, 47 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 8e7410c47c7..7cb035b8680 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1076,11 +1076,6 @@ QualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) {
return QualType(Decl->TypeForDecl, 0);
}
-void ASTContext::setTagDefinition(TagDecl* D) {
- assert (D->isDefinition());
- cast<TagType>(D->TypeForDecl)->decl = D;
-}
-
/// getTypedefType - Return the unique reference to the type for the
/// specified typename decl.
QualType ASTContext::getTypedefType(TypedefDecl *Decl) {
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 0bc0043ccb8..8ae93110170 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -144,13 +144,8 @@ void EnumDecl::Destroy(ASTContext& C) {
void EnumDecl::completeDefinition(ASTContext &C, QualType NewType) {
assert(!isDefinition() && "Cannot redefine enums!");
- setDefinition(true);
-
IntegerType = NewType;
-
- // Let ASTContext know that this is the defining EnumDecl for this
- // type.
- C.setTagDefinition(this);
+ TagDecl::completeDefinition();
}
FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C,
@@ -311,6 +306,20 @@ OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const {
// TagDecl Implementation
//===----------------------------------------------------------------------===//
+void TagDecl::startDefinition() {
+ cast<TagType>(TypeForDecl)->decl.setPointer(this);
+ cast<TagType>(TypeForDecl)->decl.setInt(1);
+}
+
+void TagDecl::completeDefinition() {
+ assert((!TypeForDecl ||
+ cast<TagType>(TypeForDecl)->decl.getPointer() == this) &&
+ "Attempt to redefine a tag definition?");
+ IsDefinition = true;
+ cast<TagType>(TypeForDecl)->decl.setPointer(this);
+ cast<TagType>(TypeForDecl)->decl.setInt(0);
+}
+
TagDecl* TagDecl::getDefinition(ASTContext& C) const {
QualType T = C.getTypeDeclType(const_cast<TagDecl*>(this));
TagDecl* D = cast<TagDecl>(cast<TagType>(T)->getDecl());
@@ -351,12 +360,7 @@ void RecordDecl::Destroy(ASTContext& C) {
/// complete.
void RecordDecl::completeDefinition(ASTContext& C) {
assert(!isDefinition() && "Cannot redefine record!");
-
- setDefinition(true);
-
- // Let ASTContext know that this is the defining RecordDecl for this
- // type.
- C.setTagDefinition(this);
+ TagDecl::completeDefinition();
}
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 860a65a1e3e..28656873ab0 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -442,37 +442,15 @@ DeclContext *DeclContext::getPrimaryContext() {
return static_cast<NamespaceDecl*>(this)->getOriginalNamespace();
case Decl::Enum:
-#if 0
- // FIXME: See the comment for CXXRecord, below.
- // The declaration associated with the enumeration type is our
- // primary context.
- return Context.getTypeDeclType(static_cast<EnumDecl*>(this))
- ->getAsEnumType()->getDecl();
-#else
- return this;
-#endif
-
case Decl::Record:
- case Decl::CXXRecord: {
- // The declaration associated with the type is be our primary
- // context.
-#if 0
- // FIXME: This is what we expect to do. However, it doesn't work
- // because ASTContext::setTagDefinition changes the result of
- // Context.getTypeDeclType, meaning that our "primary" declaration
- // of a RecordDecl/CXXRecordDecl will change, and we won't be able
- // to find any values inserted into the earlier "primary"
- // declaration. We need better tracking of redeclarations and
- // definitions.
- QualType Type = Context.getTypeDeclType(static_cast<RecordDecl*>(this));
- return Type->getAsRecordType()->getDecl();
-#else
- // FIXME: This hack will work for now, because the declaration we
- // create when we're defining the record is the one we'll use as
- // the definition later.
+ case Decl::CXXRecord:
+ // If this is a tag type that has a definition or is currently
+ // being defined, that definition is our primary context.
+ if (TagType *TagT = cast_or_null<TagType>(cast<TagDecl>(this)->TypeForDecl))
+ if (TagT->isBeingDefined() ||
+ (TagT->getDecl() && TagT->getDecl()->isDefinition()))
+ return TagT->getDecl();
return this;
-#endif
- }
case Decl::ObjCMethod:
return this;
diff --git a/clang/lib/AST/TypeSerialization.cpp b/clang/lib/AST/TypeSerialization.cpp
index 42569da400a..4f3eeca28c6 100644
--- a/clang/lib/AST/TypeSerialization.cpp
+++ b/clang/lib/AST/TypeSerialization.cpp
@@ -258,7 +258,8 @@ Type* TagType::CreateImpl(ASTContext& Context, Deserializer& D) {
Types.push_back(T);
// Deserialize the decl.
- T->decl = cast<TagDecl>(D.ReadOwnedPtr<Decl>(Context));
+ T->decl.setPointer(cast<TagDecl>(D.ReadOwnedPtr<Decl>(Context)));
+ T->decl.setInt(0);
return T;
}
OpenPOWER on IntegriCloud