2011-02-28 19:22:50 +08:00
|
|
|
//===- ExternalASTSource.cpp - Abstract External AST Interface --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides the default implementation of the ExternalASTSource
|
|
|
|
// interface, which enables construction of AST nodes from some external
|
|
|
|
// source.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/ExternalASTSource.h"
|
If a declaration is loaded, and then a module import adds a redeclaration, then
ensure that querying the first declaration for its most recent declaration
checks for redeclarations from the imported module.
This works as follows:
* The 'most recent' pointer on a canonical declaration grows a pointer to the
external AST source and a generation number (space- and time-optimized for
the case where there is no external source).
* Each time the 'most recent' pointer is queried, if it has an external source,
we check whether it's up to date, and update it if not.
* The ancillary data stored on the canonical declaration is allocated lazily
to avoid filling it in for declarations that end up being non-canonical.
We'll still perform a redundant (ASTContext) allocation if someone asks for
the most recent declaration from a decl before setPreviousDecl is called,
but such cases are probably all bugs, and are now easy to find.
Some finessing is still in order here -- in particular, we use a very general
mechanism for handling the DefinitionData pointer on CXXRecordData, and a more
targeted approach would be more compact.
Also, the MayHaveOutOfDateDef mechanism should now be expunged, since it was
addressing only a corner of the full problem space here. That's not covered
by this patch.
Early performance benchmarks show that this makes no measurable difference to
Clang performance without modules enabled (and fixes a major correctness issue
with modules enabled). I'll revert if a full performance comparison shows any
problems.
llvm-svn: 209046
2014-05-17 07:01:30 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2011-02-28 19:22:50 +08:00
|
|
|
#include "clang/AST/DeclarationName.h"
|
If a declaration is loaded, and then a module import adds a redeclaration, then
ensure that querying the first declaration for its most recent declaration
checks for redeclarations from the imported module.
This works as follows:
* The 'most recent' pointer on a canonical declaration grows a pointer to the
external AST source and a generation number (space- and time-optimized for
the case where there is no external source).
* Each time the 'most recent' pointer is queried, if it has an external source,
we check whether it's up to date, and update it if not.
* The ancillary data stored on the canonical declaration is allocated lazily
to avoid filling it in for declarations that end up being non-canonical.
We'll still perform a redundant (ASTContext) allocation if someone asks for
the most recent declaration from a decl before setPreviousDecl is called,
but such cases are probably all bugs, and are now easy to find.
Some finessing is still in order here -- in particular, we use a very general
mechanism for handling the DefinitionData pointer on CXXRecordData, and a more
targeted approach would be more compact.
Also, the MayHaveOutOfDateDef mechanism should now be expunged, since it was
addressing only a corner of the full problem space here. That's not covered
by this patch.
Early performance benchmarks show that this makes no measurable difference to
Clang performance without modules enabled (and fixes a major correctness issue
with modules enabled). I'll revert if a full performance comparison shows any
problems.
llvm-svn: 209046
2014-05-17 07:01:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-02-28 19:22:50 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
ExternalASTSource::~ExternalASTSource() { }
|
|
|
|
|
|
|
|
void ExternalASTSource::PrintStats() { }
|
|
|
|
|
|
|
|
Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) {
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-02-28 19:22:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Selector ExternalASTSource::GetExternalSelector(uint32_t ID) {
|
|
|
|
return Selector();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ExternalASTSource::GetNumExternalSelectors() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) {
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-02-28 19:22:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXXBaseSpecifier *
|
|
|
|
ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-02-28 19:22:50 +08:00
|
|
|
}
|
|
|
|
|
2013-02-07 11:30:24 +08:00
|
|
|
bool
|
2011-02-28 19:22:50 +08:00
|
|
|
ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
|
|
|
|
DeclarationName Name) {
|
2013-02-07 11:30:24 +08:00
|
|
|
return false;
|
2011-02-28 19:22:50 +08:00
|
|
|
}
|
|
|
|
|
2012-04-16 10:51:46 +08:00
|
|
|
void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalLoadResult
|
2011-02-28 19:22:50 +08:00
|
|
|
ExternalASTSource::FindExternalLexicalDecls(const DeclContext *DC,
|
|
|
|
bool (*isKindWeWant)(Decl::Kind),
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVectorImpl<Decl*> &Result) {
|
2011-07-16 05:46:17 +08:00
|
|
|
return ELR_AlreadyLoaded;
|
2011-02-28 19:22:50 +08:00
|
|
|
}
|
2011-05-04 20:59:24 +08:00
|
|
|
|
|
|
|
void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { }
|
If a declaration is loaded, and then a module import adds a redeclaration, then
ensure that querying the first declaration for its most recent declaration
checks for redeclarations from the imported module.
This works as follows:
* The 'most recent' pointer on a canonical declaration grows a pointer to the
external AST source and a generation number (space- and time-optimized for
the case where there is no external source).
* Each time the 'most recent' pointer is queried, if it has an external source,
we check whether it's up to date, and update it if not.
* The ancillary data stored on the canonical declaration is allocated lazily
to avoid filling it in for declarations that end up being non-canonical.
We'll still perform a redundant (ASTContext) allocation if someone asks for
the most recent declaration from a decl before setPreviousDecl is called,
but such cases are probably all bugs, and are now easy to find.
Some finessing is still in order here -- in particular, we use a very general
mechanism for handling the DefinitionData pointer on CXXRecordData, and a more
targeted approach would be more compact.
Also, the MayHaveOutOfDateDef mechanism should now be expunged, since it was
addressing only a corner of the full problem space here. That's not covered
by this patch.
Early performance benchmarks show that this makes no measurable difference to
Clang performance without modules enabled (and fixes a major correctness issue
with modules enabled). I'll revert if a full performance comparison shows any
problems.
llvm-svn: 209046
2014-05-17 07:01:30 +08:00
|
|
|
|
|
|
|
uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
|
|
|
|
uint32_t OldGeneration = CurrentGeneration;
|
|
|
|
|
|
|
|
// Make sure the generation of the topmost external source for the context is
|
|
|
|
// incremented. That might not be us.
|
|
|
|
auto *P = C.getExternalSource();
|
|
|
|
if (P && P != this)
|
|
|
|
CurrentGeneration = P->incrementGeneration(C);
|
|
|
|
else {
|
|
|
|
// FIXME: Only bump the generation counter if the current generation number
|
|
|
|
// has been observed?
|
|
|
|
if (!++CurrentGeneration)
|
|
|
|
llvm::report_fatal_error("generation counter overflowed", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OldGeneration;
|
|
|
|
}
|