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