1 //===- ExternalASTSource.cpp - Abstract External AST Interface ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides the default implementation of the ExternalASTSource
11 // interface, which enables construction of AST nodes from some external
14 //===----------------------------------------------------------------------===//
16 #include "clang/AST/ExternalASTSource.h"
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/DeclarationName.h"
19 #include "clang/Basic/IdentifierTable.h"
20 #include "clang/Basic/LLVM.h"
21 #include "clang/Basic/Module.h"
22 #include "llvm/ADT/None.h"
23 #include "llvm/Support/ErrorHandling.h"
26 using namespace clang;
28 ExternalASTSource::~ExternalASTSource() = default;
30 llvm::Optional<ExternalASTSource::ASTSourceDescriptor>
31 ExternalASTSource::getSourceDescriptor(unsigned ID) {
35 ExternalASTSource::ExtKind
36 ExternalASTSource::hasExternalDefinitions(const Decl *D) {
40 ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M)
41 : Signature(M.Signature), ClangModule(&M) {
43 Path = M.Directory->getName();
44 if (auto *File = M.getASTFile())
45 ASTFile = File->getName();
48 std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const {
50 return ClangModule->Name;
55 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
57 SmallVectorImpl<Decl *> &Decls) {}
59 void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
61 void ExternalASTSource::CompleteType(TagDecl *Tag) {}
63 void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
65 void ExternalASTSource::ReadComments() {}
67 void ExternalASTSource::StartedDeserializing() {}
69 void ExternalASTSource::FinishedDeserializing() {}
71 void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
73 void ExternalASTSource::PrintStats() {}
75 bool ExternalASTSource::layoutRecordType(
76 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
77 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
78 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
79 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) {
83 Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) {
87 Selector ExternalASTSource::GetExternalSelector(uint32_t ID) {
91 uint32_t ExternalASTSource::GetNumExternalSelectors() {
95 Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) {
100 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
105 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
110 ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
111 DeclarationName Name) {
115 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
117 void ExternalASTSource::FindExternalLexicalDecls(
118 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
119 SmallVectorImpl<Decl *> &Result) {}
121 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
123 uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
124 uint32_t OldGeneration = CurrentGeneration;
126 // Make sure the generation of the topmost external source for the context is
127 // incremented. That might not be us.
128 auto *P = C.getExternalSource();
130 CurrentGeneration = P->incrementGeneration(C);
132 // FIXME: Only bump the generation counter if the current generation number
133 // has been observed?
134 if (!++CurrentGeneration)
135 llvm::report_fatal_error("generation counter overflowed", false);
138 return OldGeneration;