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/IdentifierTable.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/Module.h"
21 #include "llvm/ADT/None.h"
22 #include "llvm/Support/ErrorHandling.h"
25 using namespace clang;
27 char ExternalASTSource::ID;
29 ExternalASTSource::~ExternalASTSource() = default;
31 llvm::Optional<ExternalASTSource::ASTSourceDescriptor>
32 ExternalASTSource::getSourceDescriptor(unsigned ID) {
36 ExternalASTSource::ExtKind
37 ExternalASTSource::hasExternalDefinitions(const Decl *D) {
41 ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M)
42 : Signature(M.Signature), ClangModule(&M) {
44 Path = M.Directory->getName();
45 if (auto *File = M.getASTFile())
46 ASTFile = File->getName();
49 std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const {
51 return ClangModule->Name;
56 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
58 SmallVectorImpl<Decl *> &Decls) {}
60 void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
62 void ExternalASTSource::CompleteType(TagDecl *Tag) {}
64 void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
66 void ExternalASTSource::ReadComments() {}
68 void ExternalASTSource::StartedDeserializing() {}
70 void ExternalASTSource::FinishedDeserializing() {}
72 void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
74 void ExternalASTSource::PrintStats() {}
76 bool ExternalASTSource::layoutRecordType(
77 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
78 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
79 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
80 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) {
84 Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) {
88 Selector ExternalASTSource::GetExternalSelector(uint32_t ID) {
92 uint32_t ExternalASTSource::GetNumExternalSelectors() {
96 Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) {
100 CXXCtorInitializer **
101 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
106 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
111 ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
112 DeclarationName Name) {
116 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
118 void ExternalASTSource::FindExternalLexicalDecls(
119 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
120 SmallVectorImpl<Decl *> &Result) {}
122 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
124 uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
125 uint32_t OldGeneration = CurrentGeneration;
127 // Make sure the generation of the topmost external source for the context is
128 // incremented. That might not be us.
129 auto *P = C.getExternalSource();
131 CurrentGeneration = P->incrementGeneration(C);
133 // FIXME: Only bump the generation counter if the current generation number
134 // has been observed?
135 if (!++CurrentGeneration)
136 llvm::report_fatal_error("generation counter overflowed", false);
139 return OldGeneration;