1 //===- ExternalASTSource.cpp - Abstract External AST Interface ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file provides the default implementation of the ExternalASTSource
11 //  interface, which enables construction of AST nodes from some external
12 //  source.
13 //
14 //===----------------------------------------------------------------------===//
15 
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"
24 #include <cstdint>
25 
26 using namespace clang;
27 
28 ExternalASTSource::~ExternalASTSource() = default;
29 
30 llvm::Optional<ExternalASTSource::ASTSourceDescriptor>
getSourceDescriptor(unsigned ID)31 ExternalASTSource::getSourceDescriptor(unsigned ID) {
32   return None;
33 }
34 
35 ExternalASTSource::ExtKind
hasExternalDefinitions(const Decl * D)36 ExternalASTSource::hasExternalDefinitions(const Decl *D) {
37   return EK_ReplyHazy;
38 }
39 
ASTSourceDescriptor(const Module & M)40 ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M)
41   : Signature(M.Signature), ClangModule(&M) {
42   if (M.Directory)
43     Path = M.Directory->getName();
44   if (auto *File = M.getASTFile())
45     ASTFile = File->getName();
46 }
47 
getModuleName() const48 std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const {
49   if (ClangModule)
50     return ClangModule->Name;
51   else
52     return PCHModuleName;
53 }
54 
FindFileRegionDecls(FileID File,unsigned Offset,unsigned Length,SmallVectorImpl<Decl * > & Decls)55 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
56                                             unsigned Length,
57                                             SmallVectorImpl<Decl *> &Decls) {}
58 
CompleteRedeclChain(const Decl * D)59 void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
60 
CompleteType(TagDecl * Tag)61 void ExternalASTSource::CompleteType(TagDecl *Tag) {}
62 
CompleteType(ObjCInterfaceDecl * Class)63 void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
64 
ReadComments()65 void ExternalASTSource::ReadComments() {}
66 
StartedDeserializing()67 void ExternalASTSource::StartedDeserializing() {}
68 
FinishedDeserializing()69 void ExternalASTSource::FinishedDeserializing() {}
70 
StartTranslationUnit(ASTConsumer * Consumer)71 void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
72 
PrintStats()73 void ExternalASTSource::PrintStats() {}
74 
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)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) {
80   return false;
81 }
82 
GetExternalDecl(uint32_t ID)83 Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) {
84   return nullptr;
85 }
86 
GetExternalSelector(uint32_t ID)87 Selector ExternalASTSource::GetExternalSelector(uint32_t ID) {
88   return Selector();
89 }
90 
GetNumExternalSelectors()91 uint32_t ExternalASTSource::GetNumExternalSelectors() {
92    return 0;
93 }
94 
GetExternalDeclStmt(uint64_t Offset)95 Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) {
96   return nullptr;
97 }
98 
99 CXXCtorInitializer **
GetExternalCXXCtorInitializers(uint64_t Offset)100 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
101   return nullptr;
102 }
103 
104 CXXBaseSpecifier *
GetExternalCXXBaseSpecifiers(uint64_t Offset)105 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
106   return nullptr;
107 }
108 
109 bool
FindExternalVisibleDeclsByName(const DeclContext * DC,DeclarationName Name)110 ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
111                                                   DeclarationName Name) {
112   return false;
113 }
114 
completeVisibleDeclsMap(const DeclContext * DC)115 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
116 
FindExternalLexicalDecls(const DeclContext * DC,llvm::function_ref<bool (Decl::Kind)> IsKindWeWant,SmallVectorImpl<Decl * > & Result)117 void ExternalASTSource::FindExternalLexicalDecls(
118     const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
119     SmallVectorImpl<Decl *> &Result) {}
120 
getMemoryBufferSizes(MemoryBufferSizes & sizes) const121 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
122 
incrementGeneration(ASTContext & C)123 uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
124   uint32_t OldGeneration = CurrentGeneration;
125 
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();
129   if (P && P != this)
130     CurrentGeneration = P->incrementGeneration(C);
131   else {
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);
136   }
137 
138   return OldGeneration;
139 }
140