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