xref: /freebsd/contrib/llvm-project/clang/lib/AST/ExternalASTSource.cpp (revision e64bea71c21eb42e97aa615188ba91f6cce0d36d)
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 bool ExternalASTSource::wasThisDeclarationADefinition(const FunctionDecl *FD) {
42   return false;
43 }
44 
45 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
46                                             unsigned Length,
47                                             SmallVectorImpl<Decl *> &Decls) {}
48 
49 void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
50 
51 void ExternalASTSource::CompleteType(TagDecl *Tag) {}
52 
53 void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
54 
55 void ExternalASTSource::ReadComments() {}
56 
57 void ExternalASTSource::StartedDeserializing() {}
58 
59 void ExternalASTSource::FinishedDeserializing() {}
60 
61 void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
62 
63 void ExternalASTSource::PrintStats() {}
64 
65 bool 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 
73 Decl *ExternalASTSource::GetExternalDecl(GlobalDeclID ID) { return nullptr; }
74 
75 Selector ExternalASTSource::GetExternalSelector(uint32_t ID) {
76   return Selector();
77 }
78 
79 uint32_t ExternalASTSource::GetNumExternalSelectors() {
80    return 0;
81 }
82 
83 Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) {
84   return nullptr;
85 }
86 
87 CXXCtorInitializer **
88 ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
89   return nullptr;
90 }
91 
92 CXXBaseSpecifier *
93 ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
94   return nullptr;
95 }
96 
97 bool ExternalASTSource::FindExternalVisibleDeclsByName(
98     const DeclContext *DC, DeclarationName Name,
99     const DeclContext *OriginalDC) {
100   return false;
101 }
102 
103 bool ExternalASTSource::LoadExternalSpecializations(const Decl *D, bool) {
104   return false;
105 }
106 
107 bool ExternalASTSource::LoadExternalSpecializations(
108     const Decl *D, ArrayRef<TemplateArgument>) {
109   return false;
110 }
111 
112 void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
113 
114 void ExternalASTSource::FindExternalLexicalDecls(
115     const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
116     SmallVectorImpl<Decl *> &Result) {}
117 
118 void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
119 
120 uint32_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("generation counter overflowed");
133   }
134 
135   return OldGeneration;
136 }
137