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/ASTSourceDescriptor.h"
19#include "clang/Basic/IdentifierTable.h"
20#include "clang/Basic/LLVM.h"
21#include "llvm/Support/ErrorHandling.h"
22#include <cstdint>
23#include <optional>
24
25using namespace clang;
26
27char ExternalASTSource::ID;
28
29ExternalASTSource::~ExternalASTSource() = default;
30
31std::optional<ASTSourceDescriptor>
32ExternalASTSource::getSourceDescriptor(unsigned ID) {
33 return std::nullopt;
34}
35
36ExternalASTSource::ExtKind
37ExternalASTSource::hasExternalDefinitions(const Decl *D) {
38 return EK_ReplyHazy;
39}
40
41bool ExternalASTSource::wasThisDeclarationADefinition(const FunctionDecl *FD) {
42 return false;
43}
44
45void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
46 unsigned Length,
47 SmallVectorImpl<Decl *> &Decls) {}
48
49void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
50
51void ExternalASTSource::CompleteType(TagDecl *Tag) {}
52
53void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
54
55void ExternalASTSource::ReadComments() {}
56
57void ExternalASTSource::StartedDeserializing() {}
58
59void ExternalASTSource::FinishedDeserializing() {}
60
61void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
62
63void ExternalASTSource::PrintStats() {}
64
65bool ExternalASTSource::layoutRecordType(
66 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
67 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
68 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
69 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) {
70 return false;
71}
72
73Decl *ExternalASTSource::GetExternalDecl(GlobalDeclID ID) { return nullptr; }
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 ExternalASTSource::FindExternalVisibleDeclsByName(
98 const DeclContext *DC, DeclarationName Name,
99 const DeclContext *OriginalDC) {
100 return false;
101}
102
103bool ExternalASTSource::LoadExternalSpecializations(const Decl *D, bool) {
104 return false;
105}
106
107bool ExternalASTSource::LoadExternalSpecializations(
108 const Decl *D, ArrayRef<TemplateArgument>) {
109 return false;
110}
111
112void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
113
114void ExternalASTSource::FindExternalLexicalDecls(
115 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
116 SmallVectorImpl<Decl *> &Result) {}
117
118void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
119
120uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
121 uint32_t OldGeneration = CurrentGeneration;
122
123 // Make sure the generation of the topmost external source for the context is
124 // incremented. That might not be us.
125 auto *P = C.getExternalSource();
126 if (P && P != this)
127 CurrentGeneration = P->incrementGeneration(C);
128 else {
129 // FIXME: Only bump the generation counter if the current generation number
130 // has been observed?
131 if (!++CurrentGeneration)
132 llvm::reportFatalUsageError(reason: "generation counter overflowed");
133 }
134
135 return OldGeneration;
136}
137