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 ExternalASTSource::~ExternalASTSource() = default;
29 llvm::Optional<ExternalASTSource::ASTSourceDescriptor>
30 ExternalASTSource::getSourceDescriptor(unsigned ID) {
34 ExternalASTSource::ExtKind
35 ExternalASTSource::hasExternalDefinitions(const Decl *D) {
39 ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M)
40 : Signature(M.Signature), ClangModule(&M) {
42 Path = M.Directory->getName();
43 if (auto *File = M.getASTFile())
44 ASTFile = File->getName();
47 std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const {
49 return ClangModule->Name;
54 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
56 SmallVectorImpl<Decl *> &Decls) {}
58 void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
60 void ExternalASTSource::CompleteType(TagDecl *Tag) {}
62 void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
64 void ExternalASTSource::ReadComments() {}
66 void ExternalASTSource::StartedDeserializing() {}
68 void ExternalASTSource::FinishedDeserializing() {}
70 void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
72 void ExternalASTSource::PrintStats() {}
74 bool ExternalASTSource::layoutRecordType(
75 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
76 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
77 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
78 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) {
82 Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) {
86 Selector ExternalASTSource::GetExternalSelector(uint32_t ID) {
90 uint32_t ExternalASTSource::GetNumExternalSelectors() {
94 Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) {
99 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
104 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
109 ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
110 DeclarationName Name) {
114 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
116 void ExternalASTSource::FindExternalLexicalDecls(
117 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
118 SmallVectorImpl<Decl *> &Result) {}
120 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
122 uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
123 uint32_t OldGeneration = CurrentGeneration;
125 // Make sure the generation of the topmost external source for the context is
126 // incremented. That might not be us.
127 auto *P = C.getExternalSource();
129 CurrentGeneration = P->incrementGeneration(C);
131 // FIXME: Only bump the generation counter if the current generation number
132 // has been observed?
133 if (!++CurrentGeneration)
134 llvm::report_fatal_error("generation counter overflowed", false);
137 return OldGeneration;