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