ExternalASTSource.cpp 3.8 KB

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