1 //===- ExternalASTSource.cpp - Abstract External AST Interface ------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file provides the default implementation of the ExternalASTSource 10 // interface, which enables construction of AST nodes from some external 11 // source. 12 // 13 //===----------------------------------------------------------------------===// 14 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 "clang/Basic/SourceManager.h" 22 #include "llvm/ADT/None.h" 23 #include "llvm/Support/ErrorHandling.h" 24 #include <cstdint> 25 26 using namespace clang; 27 28 char ExternalASTSource::ID; 29 30 ExternalASTSource::~ExternalASTSource() = default; 31 32 llvm::Optional<ExternalASTSource::ASTSourceDescriptor> 33 ExternalASTSource::getSourceDescriptor(unsigned ID) { 34 return None; 35 } 36 37 ExternalASTSource::ExtKind 38 ExternalASTSource::hasExternalDefinitions(const Decl *D) { 39 return EK_ReplyHazy; 40 } 41 42 ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M) 43 : Signature(M.Signature), ClangModule(&M) { 44 if (M.Directory) 45 Path = M.Directory->getName(); 46 if (auto *File = M.getASTFile()) 47 ASTFile = File->getName(); 48 } 49 50 std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const { 51 if (ClangModule) 52 return ClangModule->Name; 53 else 54 return std::string(PCHModuleName); 55 } 56 57 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset, 58 unsigned Length, 59 SmallVectorImpl<Decl *> &Decls) {} 60 61 void ExternalASTSource::CompleteRedeclChain(const Decl *D) {} 62 63 void ExternalASTSource::CompleteType(TagDecl *Tag) {} 64 65 void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {} 66 67 void ExternalASTSource::ReadComments() {} 68 69 void ExternalASTSource::StartedDeserializing() {} 70 71 void ExternalASTSource::FinishedDeserializing() {} 72 73 void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {} 74 75 void ExternalASTSource::PrintStats() {} 76 77 bool ExternalASTSource::layoutRecordType( 78 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, 79 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, 80 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, 81 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) { 82 return false; 83 } 84 85 Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) { 86 return nullptr; 87 } 88 89 Selector ExternalASTSource::GetExternalSelector(uint32_t ID) { 90 return Selector(); 91 } 92 93 uint32_t ExternalASTSource::GetNumExternalSelectors() { 94 return 0; 95 } 96 97 Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) { 98 return nullptr; 99 } 100 101 CXXCtorInitializer ** 102 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) { 103 return nullptr; 104 } 105 106 CXXBaseSpecifier * 107 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) { 108 return nullptr; 109 } 110 111 bool 112 ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC, 113 DeclarationName Name) { 114 return false; 115 } 116 117 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {} 118 119 void ExternalASTSource::FindExternalLexicalDecls( 120 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, 121 SmallVectorImpl<Decl *> &Result) {} 122 123 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {} 124 125 uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { 126 uint32_t OldGeneration = CurrentGeneration; 127 128 // Make sure the generation of the topmost external source for the context is 129 // incremented. That might not be us. 130 auto *P = C.getExternalSource(); 131 if (P && P != this) 132 CurrentGeneration = P->incrementGeneration(C); 133 else { 134 // FIXME: Only bump the generation counter if the current generation number 135 // has been observed? 136 if (!++CurrentGeneration) 137 llvm::report_fatal_error("generation counter overflowed", false); 138 } 139 140 return OldGeneration; 141 } 142