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