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