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> 31 ExternalASTSource::getSourceDescriptor(unsigned ID) { 32 return None; 33 } 34 35 ExternalASTSource::ExtKind 36 ExternalASTSource::hasExternalDefinitions(const Decl *D) { 37 return EK_ReplyHazy; 38 } 39 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 48 std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const { 49 if (ClangModule) 50 return ClangModule->Name; 51 else 52 return PCHModuleName; 53 } 54 55 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset, 56 unsigned Length, 57 SmallVectorImpl<Decl *> &Decls) {} 58 59 void ExternalASTSource::CompleteRedeclChain(const Decl *D) {} 60 61 void ExternalASTSource::CompleteType(TagDecl *Tag) {} 62 63 void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {} 64 65 void ExternalASTSource::ReadComments() {} 66 67 void ExternalASTSource::StartedDeserializing() {} 68 69 void ExternalASTSource::FinishedDeserializing() {} 70 71 void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {} 72 73 void ExternalASTSource::PrintStats() {} 74 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 83 Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) { 84 return nullptr; 85 } 86 87 Selector ExternalASTSource::GetExternalSelector(uint32_t ID) { 88 return Selector(); 89 } 90 91 uint32_t ExternalASTSource::GetNumExternalSelectors() { 92 return 0; 93 } 94 95 Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) { 96 return nullptr; 97 } 98 99 CXXCtorInitializer ** 100 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) { 101 return nullptr; 102 } 103 104 CXXBaseSpecifier * 105 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) { 106 return nullptr; 107 } 108 109 bool 110 ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC, 111 DeclarationName Name) { 112 return false; 113 } 114 115 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {} 116 117 void ExternalASTSource::FindExternalLexicalDecls( 118 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, 119 SmallVectorImpl<Decl *> &Result) {} 120 121 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {} 122 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