1 //===- ExternalASTSource.cpp - Abstract External AST Interface ------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file provides the default implementation of the ExternalASTSource
10 // interface, which enables construction of AST nodes from some external
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/ExternalASTSource.h"
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclarationName.h"
18 #include "clang/Basic/FileManager.h"
19 #include "clang/Basic/IdentifierTable.h"
20 #include "clang/Basic/LLVM.h"
21 #include "clang/Basic/Module.h"
22 #include "clang/Basic/SourceManager.h"
23 #include "llvm/Support/ErrorHandling.h"
27 using namespace clang
;
29 char ExternalASTSource::ID
;
31 ExternalASTSource::~ExternalASTSource() = default;
33 std::optional
<ASTSourceDescriptor
>
34 ExternalASTSource::getSourceDescriptor(unsigned ID
) {
38 ExternalASTSource::ExtKind
39 ExternalASTSource::hasExternalDefinitions(const Decl
*D
) {
43 void ExternalASTSource::FindFileRegionDecls(FileID File
, unsigned Offset
,
45 SmallVectorImpl
<Decl
*> &Decls
) {}
47 void ExternalASTSource::CompleteRedeclChain(const Decl
*D
) {}
49 void ExternalASTSource::CompleteType(TagDecl
*Tag
) {}
51 void ExternalASTSource::CompleteType(ObjCInterfaceDecl
*Class
) {}
53 void ExternalASTSource::ReadComments() {}
55 void ExternalASTSource::StartedDeserializing() {}
57 void ExternalASTSource::FinishedDeserializing() {}
59 void ExternalASTSource::StartTranslationUnit(ASTConsumer
*Consumer
) {}
61 void ExternalASTSource::PrintStats() {}
63 bool ExternalASTSource::layoutRecordType(
64 const RecordDecl
*Record
, uint64_t &Size
, uint64_t &Alignment
,
65 llvm::DenseMap
<const FieldDecl
*, uint64_t> &FieldOffsets
,
66 llvm::DenseMap
<const CXXRecordDecl
*, CharUnits
> &BaseOffsets
,
67 llvm::DenseMap
<const CXXRecordDecl
*, CharUnits
> &VirtualBaseOffsets
) {
71 Decl
*ExternalASTSource::GetExternalDecl(uint32_t ID
) {
75 Selector
ExternalASTSource::GetExternalSelector(uint32_t ID
) {
79 uint32_t ExternalASTSource::GetNumExternalSelectors() {
83 Stmt
*ExternalASTSource::GetExternalDeclStmt(uint64_t Offset
) {
88 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset
) {
93 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset
) {
98 ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext
*DC
,
99 DeclarationName Name
) {
103 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext
*DC
) {}
105 void ExternalASTSource::FindExternalLexicalDecls(
106 const DeclContext
*DC
, llvm::function_ref
<bool(Decl::Kind
)> IsKindWeWant
,
107 SmallVectorImpl
<Decl
*> &Result
) {}
109 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes
&sizes
) const {}
111 uint32_t ExternalASTSource::incrementGeneration(ASTContext
&C
) {
112 uint32_t OldGeneration
= CurrentGeneration
;
114 // Make sure the generation of the topmost external source for the context is
115 // incremented. That might not be us.
116 auto *P
= C
.getExternalSource();
118 CurrentGeneration
= P
->incrementGeneration(C
);
120 // FIXME: Only bump the generation counter if the current generation number
121 // has been observed?
122 if (!++CurrentGeneration
)
123 llvm::report_fatal_error("generation counter overflowed", false);
126 return OldGeneration
;