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