summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-17 00:42:38 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-17 00:42:38 +0000
commitdee1be8e959e63c99cf87258f72beda0e5ae3c1d (patch)
tree930a3c0df948866360984f2376d1cac46151a316 /clang/lib/AST/Decl.cpp
parent1c6549db6f982a2e916104e077ce353ab4b0fefe (diff)
downloadbcm5719-llvm-dee1be8e959e63c99cf87258f72beda0e5ae3c1d.tar.gz
bcm5719-llvm-dee1be8e959e63c99cf87258f72beda0e5ae3c1d.zip
Teach DeclContext how to find the primary declaration for any TagDecl
even when we are still defining the TagDecl. This is required so that qualified name lookup of a class name within its definition works (see the new bits in test/SemaCXX/qualified-id-lookup.cpp). As part of this, move the nested redefinition checking code into ActOnTag. This gives us diagnostics earlier (when we try to perform the nested redefinition, rather than when we try to complete the 2nd definition) and removes some code duplication. llvm-svn: 62386
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r--clang/lib/AST/Decl.cpp28
1 files changed, 16 insertions, 12 deletions
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();
}
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud