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