diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-10-24 17:26:50 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-10-24 17:26:50 +0000 |
| commit | d170d844c4b2ba3c1890113dbf61b6056ce4a577 (patch) | |
| tree | f96d257fd664cdb459ec9c02005654e2b56699dd /clang/lib | |
| parent | 3ba70b89cf94c5090aae9962bf633de871c7d32d (diff) | |
| download | bcm5719-llvm-d170d844c4b2ba3c1890113dbf61b6056ce4a577.tar.gz bcm5719-llvm-d170d844c4b2ba3c1890113dbf61b6056ce4a577.zip | |
Start fleshing out ASTMutationListener; notify when a tag definition is completed.
In that case a chained PCH will record the updates to the DefinitionData pointer of forward references.
If a forward reference mutated into a definition re-write it into the chained PCH, this is too big of a change.
llvm-svn: 117239
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTCommon.h | 4 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 14 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 29 |
4 files changed, 50 insertions, 1 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index fc5b57f1485..42e762d56ab 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -21,6 +21,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/PrettyPrinter.h" +#include "clang/AST/ASTMutationListener.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/Specifiers.h" @@ -1713,6 +1714,9 @@ void TagDecl::completeDefinition() { IsDefinition = true; IsBeingDefined = false; + + if (ASTMutationListener *L = getASTMutationListener()) + L->CompletedTagDefinition(this); } TagDecl* TagDecl::getDefinition() const { diff --git a/clang/lib/Serialization/ASTCommon.h b/clang/lib/Serialization/ASTCommon.h index a0e2ecd8aa1..36958c75009 100644 --- a/clang/lib/Serialization/ASTCommon.h +++ b/clang/lib/Serialization/ASTCommon.h @@ -20,6 +20,10 @@ namespace clang { namespace serialization { +enum DeclUpdateKind { + UPD_CXX_SET_DEFINITIONDATA +}; + TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT); template <typename IdxForTypeTy> diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 45d729a2fc7..f4568a7e70e 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1588,5 +1588,17 @@ Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) { } void ASTDeclReader::UpdateDecl(Decl *D, const RecordData &Record) { - // No update is tracked yet. + unsigned Idx = 0; + while (Idx < Record.size()) { + switch ((DeclUpdateKind)Record[Idx++]) { + case UPD_CXX_SET_DEFINITIONDATA: { + CXXRecordDecl *RD = cast<CXXRecordDecl>(D); + CXXRecordDecl * + DefinitionDecl = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++])); + assert(!RD->DefinitionData && "DefinitionData is already set!"); + InitializeCXXDefinitionData(RD, DefinitionDecl, Record, Idx); + break; + } + } + } } diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index c6df2dd95d3..436525f1999 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -3297,3 +3297,32 @@ void ASTWriter::MacroDefinitionRead(serialization::MacroID ID, MacroDefinition *MD) { MacroDefinitions[MD] = ID; } + +void ASTWriter::CompletedTagDefinition(const TagDecl *D) { + assert(D->isDefinition()); + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) { + // We are interested when a PCH decl is modified. + if (RD->getPCHLevel() > 0) { + // A forward reference was mutated into a definition. Rewrite it. + // FIXME: This happens during template instantiation, should we + // have created a new definition decl instead ? + DeclsToRewrite.insert(RD); + } + + for (CXXRecordDecl::redecl_iterator + I = RD->redecls_begin(), E = RD->redecls_end(); I != E; ++I) { + CXXRecordDecl *Redecl = cast<CXXRecordDecl>(*I); + if (Redecl == RD) + continue; + + // We are interested when a PCH decl is modified. + if (Redecl->getPCHLevel() > 0) { + UpdateRecord &Record = DeclUpdates[Redecl]; + Record.push_back(UPD_CXX_SET_DEFINITIONDATA); + assert(Redecl->DefinitionData); + assert(Redecl->DefinitionData->Definition == D); + AddDeclRef(D, Record); // the DefinitionDecl + } + } + } +} |

