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