2017-11-08 08:39:18 +08:00
|
|
|
//===- ExternalASTSource.cpp - Abstract External AST Interface ------------===//
|
2011-02-28 19:22:50 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-02-28 19:22:50 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2018-07-31 03:24:48 +08:00
|
|
|
// This file provides the default implementation of the ExternalASTSource
|
2011-02-28 19:22:50 +08:00
|
|
|
// 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"
|
2020-03-01 01:10:42 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
2017-11-08 08:39:18 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
|
|
|
#include "clang/Basic/LLVM.h"
|
2015-09-19 08:10:32 +08:00
|
|
|
#include "clang/Basic/Module.h"
|
2020-02-28 03:01:58 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2017-11-08 08:39:18 +08:00
|
|
|
#include "llvm/ADT/None.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"
|
2017-11-08 08:39:18 +08:00
|
|
|
#include <cstdint>
|
2011-02-28 19:22:50 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2019-12-15 23:09:20 +08:00
|
|
|
char ExternalASTSource::ID;
|
|
|
|
|
2017-11-08 08:39:18 +08:00
|
|
|
ExternalASTSource::~ExternalASTSource() = default;
|
2011-02-28 19:22:50 +08:00
|
|
|
|
2020-02-28 10:13:54 +08:00
|
|
|
llvm::Optional<ASTSourceDescriptor>
|
2015-07-01 01:39:43 +08:00
|
|
|
ExternalASTSource::getSourceDescriptor(unsigned ID) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2017-01-30 13:00:26 +08:00
|
|
|
ExternalASTSource::ExtKind
|
2017-04-12 05:13:37 +08:00
|
|
|
ExternalASTSource::hasExternalDefinitions(const Decl *D) {
|
2017-01-30 13:00:26 +08:00
|
|
|
return EK_ReplyHazy;
|
|
|
|
}
|
|
|
|
|
2014-05-21 22:19:22 +08:00
|
|
|
void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
|
|
|
|
unsigned Length,
|
|
|
|
SmallVectorImpl<Decl *> &Decls) {}
|
|
|
|
|
|
|
|
void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
|
|
|
|
|
|
|
|
void ExternalASTSource::CompleteType(TagDecl *Tag) {}
|
|
|
|
|
|
|
|
void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
|
|
|
|
|
|
|
|
void ExternalASTSource::ReadComments() {}
|
|
|
|
|
|
|
|
void ExternalASTSource::StartedDeserializing() {}
|
|
|
|
|
|
|
|
void ExternalASTSource::FinishedDeserializing() {}
|
|
|
|
|
|
|
|
void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
|
|
|
|
|
2017-11-08 08:39:18 +08:00
|
|
|
void ExternalASTSource::PrintStats() {}
|
2011-02-28 19:22:50 +08:00
|
|
|
|
2014-05-21 22:19:22 +08:00
|
|
|
bool ExternalASTSource::layoutRecordType(
|
|
|
|
const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
|
|
|
|
llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
|
|
|
|
llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
|
|
|
|
llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-28 19:22:50 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-24 14:36:48 +08:00
|
|
|
CXXCtorInitializer **
|
|
|
|
ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-08-06 06:41:45 +08:00
|
|
|
void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
|
2012-04-16 10:51:46 +08:00
|
|
|
|
2015-08-06 06:41:45 +08:00
|
|
|
void ExternalASTSource::FindExternalLexicalDecls(
|
|
|
|
const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
|
|
|
|
SmallVectorImpl<Decl *> &Result) {}
|
2011-05-04 20:59:24 +08:00
|
|
|
|
2015-08-06 06:41:45 +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;
|
|
|
|
}
|