xref: /freebsd/contrib/llvm-project/clang/lib/AST/ExternalASTSource.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===- ExternalASTSource.cpp - Abstract External AST Interface ------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric //  This file provides the default implementation of the ExternalASTSource
100b57cec5SDimitry Andric //  interface, which enables construction of AST nodes from some external
110b57cec5SDimitry Andric //  source.
120b57cec5SDimitry Andric //
130b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #include "clang/AST/ExternalASTSource.h"
160b57cec5SDimitry Andric #include "clang/AST/ASTContext.h"
170b57cec5SDimitry Andric #include "clang/AST/DeclarationName.h"
18*0fca6ea1SDimitry Andric #include "clang/Basic/ASTSourceDescriptor.h"
195ffd83dbSDimitry Andric #include "clang/Basic/FileManager.h"
200b57cec5SDimitry Andric #include "clang/Basic/IdentifierTable.h"
210b57cec5SDimitry Andric #include "clang/Basic/LLVM.h"
225ffd83dbSDimitry Andric #include "clang/Basic/SourceManager.h"
230b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
240b57cec5SDimitry Andric #include <cstdint>
25bdd1243dSDimitry Andric #include <optional>
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric using namespace clang;
280b57cec5SDimitry Andric 
29480093f4SDimitry Andric char ExternalASTSource::ID;
30480093f4SDimitry Andric 
310b57cec5SDimitry Andric ExternalASTSource::~ExternalASTSource() = default;
320b57cec5SDimitry Andric 
33bdd1243dSDimitry Andric std::optional<ASTSourceDescriptor>
getSourceDescriptor(unsigned ID)340b57cec5SDimitry Andric ExternalASTSource::getSourceDescriptor(unsigned ID) {
35bdd1243dSDimitry Andric   return std::nullopt;
360b57cec5SDimitry Andric }
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric ExternalASTSource::ExtKind
hasExternalDefinitions(const Decl * D)390b57cec5SDimitry Andric ExternalASTSource::hasExternalDefinitions(const Decl *D) {
400b57cec5SDimitry Andric   return EK_ReplyHazy;
410b57cec5SDimitry Andric }
420b57cec5SDimitry Andric 
FindFileRegionDecls(FileID File,unsigned Offset,unsigned Length,SmallVectorImpl<Decl * > & Decls)430b57cec5SDimitry Andric void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
440b57cec5SDimitry Andric                                             unsigned Length,
450b57cec5SDimitry Andric                                             SmallVectorImpl<Decl *> &Decls) {}
460b57cec5SDimitry Andric 
CompleteRedeclChain(const Decl * D)470b57cec5SDimitry Andric void ExternalASTSource::CompleteRedeclChain(const Decl *D) {}
480b57cec5SDimitry Andric 
CompleteType(TagDecl * Tag)490b57cec5SDimitry Andric void ExternalASTSource::CompleteType(TagDecl *Tag) {}
500b57cec5SDimitry Andric 
CompleteType(ObjCInterfaceDecl * Class)510b57cec5SDimitry Andric void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {}
520b57cec5SDimitry Andric 
ReadComments()530b57cec5SDimitry Andric void ExternalASTSource::ReadComments() {}
540b57cec5SDimitry Andric 
StartedDeserializing()550b57cec5SDimitry Andric void ExternalASTSource::StartedDeserializing() {}
560b57cec5SDimitry Andric 
FinishedDeserializing()570b57cec5SDimitry Andric void ExternalASTSource::FinishedDeserializing() {}
580b57cec5SDimitry Andric 
StartTranslationUnit(ASTConsumer * Consumer)590b57cec5SDimitry Andric void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {}
600b57cec5SDimitry Andric 
PrintStats()610b57cec5SDimitry Andric void ExternalASTSource::PrintStats() {}
620b57cec5SDimitry Andric 
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)630b57cec5SDimitry Andric bool ExternalASTSource::layoutRecordType(
640b57cec5SDimitry Andric     const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
650b57cec5SDimitry Andric     llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
660b57cec5SDimitry Andric     llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
670b57cec5SDimitry Andric     llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) {
680b57cec5SDimitry Andric   return false;
690b57cec5SDimitry Andric }
700b57cec5SDimitry Andric 
GetExternalDecl(GlobalDeclID ID)71*0fca6ea1SDimitry Andric Decl *ExternalASTSource::GetExternalDecl(GlobalDeclID ID) { return nullptr; }
720b57cec5SDimitry Andric 
GetExternalSelector(uint32_t ID)730b57cec5SDimitry Andric Selector ExternalASTSource::GetExternalSelector(uint32_t ID) {
740b57cec5SDimitry Andric   return Selector();
750b57cec5SDimitry Andric }
760b57cec5SDimitry Andric 
GetNumExternalSelectors()770b57cec5SDimitry Andric uint32_t ExternalASTSource::GetNumExternalSelectors() {
780b57cec5SDimitry Andric    return 0;
790b57cec5SDimitry Andric }
800b57cec5SDimitry Andric 
GetExternalDeclStmt(uint64_t Offset)810b57cec5SDimitry Andric Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) {
820b57cec5SDimitry Andric   return nullptr;
830b57cec5SDimitry Andric }
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric CXXCtorInitializer **
GetExternalCXXCtorInitializers(uint64_t Offset)860b57cec5SDimitry Andric ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
870b57cec5SDimitry Andric   return nullptr;
880b57cec5SDimitry Andric }
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric CXXBaseSpecifier *
GetExternalCXXBaseSpecifiers(uint64_t Offset)910b57cec5SDimitry Andric ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) {
920b57cec5SDimitry Andric   return nullptr;
930b57cec5SDimitry Andric }
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric bool
FindExternalVisibleDeclsByName(const DeclContext * DC,DeclarationName Name)960b57cec5SDimitry Andric ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC,
970b57cec5SDimitry Andric                                                   DeclarationName Name) {
980b57cec5SDimitry Andric   return false;
990b57cec5SDimitry Andric }
1000b57cec5SDimitry Andric 
completeVisibleDeclsMap(const DeclContext * DC)1010b57cec5SDimitry Andric void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {}
1020b57cec5SDimitry Andric 
FindExternalLexicalDecls(const DeclContext * DC,llvm::function_ref<bool (Decl::Kind)> IsKindWeWant,SmallVectorImpl<Decl * > & Result)1030b57cec5SDimitry Andric void ExternalASTSource::FindExternalLexicalDecls(
1040b57cec5SDimitry Andric     const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1050b57cec5SDimitry Andric     SmallVectorImpl<Decl *> &Result) {}
1060b57cec5SDimitry Andric 
getMemoryBufferSizes(MemoryBufferSizes & sizes) const1070b57cec5SDimitry Andric void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {}
1080b57cec5SDimitry Andric 
incrementGeneration(ASTContext & C)1090b57cec5SDimitry Andric uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) {
1100b57cec5SDimitry Andric   uint32_t OldGeneration = CurrentGeneration;
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric   // Make sure the generation of the topmost external source for the context is
1130b57cec5SDimitry Andric   // incremented. That might not be us.
1140b57cec5SDimitry Andric   auto *P = C.getExternalSource();
1150b57cec5SDimitry Andric   if (P && P != this)
1160b57cec5SDimitry Andric     CurrentGeneration = P->incrementGeneration(C);
1170b57cec5SDimitry Andric   else {
1180b57cec5SDimitry Andric     // FIXME: Only bump the generation counter if the current generation number
1190b57cec5SDimitry Andric     // has been observed?
1200b57cec5SDimitry Andric     if (!++CurrentGeneration)
1210b57cec5SDimitry Andric       llvm::report_fatal_error("generation counter overflowed", false);
1220b57cec5SDimitry Andric   }
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric   return OldGeneration;
1250b57cec5SDimitry Andric }
126