ExternalASTSource.cpp 4.2 KB

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