| Eugene Zelenko | 0d00c89 | 2017-11-08 00:39:18 +0000 | [diff] [blame^] | 1 | //===- ExternalASTSource.cpp - Abstract External AST Interface ------------===// | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
|  | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
|  | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
|  | 10 | //  This file provides the default implementation of the ExternalASTSource | 
|  | 11 | //  interface, which enables construction of AST nodes from some external | 
|  | 12 | //  source. | 
|  | 13 | // | 
|  | 14 | //===----------------------------------------------------------------------===// | 
|  | 15 |  | 
|  | 16 | #include "clang/AST/ExternalASTSource.h" | 
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclarationName.h" | 
| Eugene Zelenko | 0d00c89 | 2017-11-08 00:39:18 +0000 | [diff] [blame^] | 19 | #include "clang/Basic/IdentifierTable.h" | 
|  | 20 | #include "clang/Basic/LLVM.h" | 
| Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 21 | #include "clang/Basic/Module.h" | 
| Eugene Zelenko | 0d00c89 | 2017-11-08 00:39:18 +0000 | [diff] [blame^] | 22 | #include "llvm/ADT/None.h" | 
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ErrorHandling.h" | 
| Eugene Zelenko | 0d00c89 | 2017-11-08 00:39:18 +0000 | [diff] [blame^] | 24 | #include <cstdint> | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 25 |  | 
|  | 26 | using namespace clang; | 
|  | 27 |  | 
| Eugene Zelenko | 0d00c89 | 2017-11-08 00:39:18 +0000 | [diff] [blame^] | 28 | ExternalASTSource::~ExternalASTSource() = default; | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 29 |  | 
| Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 30 | llvm::Optional<ExternalASTSource::ASTSourceDescriptor> | 
|  | 31 | ExternalASTSource::getSourceDescriptor(unsigned ID) { | 
|  | 32 | return None; | 
|  | 33 | } | 
|  | 34 |  | 
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 35 | ExternalASTSource::ExtKind | 
| David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 36 | ExternalASTSource::hasExternalDefinitions(const Decl *D) { | 
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 37 | return EK_ReplyHazy; | 
|  | 38 | } | 
|  | 39 |  | 
| Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 40 | ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M) | 
| Adrian Prantl | 6083b08 | 2015-09-24 16:10:00 +0000 | [diff] [blame] | 41 | : Signature(M.Signature), ClangModule(&M) { | 
| Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 42 | if (M.Directory) | 
|  | 43 | Path = M.Directory->getName(); | 
|  | 44 | if (auto *File = M.getASTFile()) | 
|  | 45 | ASTFile = File->getName(); | 
| Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 46 | } | 
|  | 47 |  | 
| Adrian Prantl | 835e663 | 2015-09-24 16:10:10 +0000 | [diff] [blame] | 48 | std::string ExternalASTSource::ASTSourceDescriptor::getModuleName() const { | 
| Adrian Prantl | 6083b08 | 2015-09-24 16:10:00 +0000 | [diff] [blame] | 49 | if (ClangModule) | 
| Adrian Prantl | 835e663 | 2015-09-24 16:10:10 +0000 | [diff] [blame] | 50 | return ClangModule->Name; | 
| Adrian Prantl | 6083b08 | 2015-09-24 16:10:00 +0000 | [diff] [blame] | 51 | else | 
|  | 52 | return PCHModuleName; | 
|  | 53 | } | 
|  | 54 |  | 
| Rafael Espindola | f5bbe27 | 2014-05-21 14:19:22 +0000 | [diff] [blame] | 55 | void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset, | 
|  | 56 | unsigned Length, | 
|  | 57 | SmallVectorImpl<Decl *> &Decls) {} | 
|  | 58 |  | 
|  | 59 | void ExternalASTSource::CompleteRedeclChain(const Decl *D) {} | 
|  | 60 |  | 
|  | 61 | void ExternalASTSource::CompleteType(TagDecl *Tag) {} | 
|  | 62 |  | 
|  | 63 | void ExternalASTSource::CompleteType(ObjCInterfaceDecl *Class) {} | 
|  | 64 |  | 
|  | 65 | void ExternalASTSource::ReadComments() {} | 
|  | 66 |  | 
|  | 67 | void ExternalASTSource::StartedDeserializing() {} | 
|  | 68 |  | 
|  | 69 | void ExternalASTSource::FinishedDeserializing() {} | 
|  | 70 |  | 
|  | 71 | void ExternalASTSource::StartTranslationUnit(ASTConsumer *Consumer) {} | 
|  | 72 |  | 
| Eugene Zelenko | 0d00c89 | 2017-11-08 00:39:18 +0000 | [diff] [blame^] | 73 | void ExternalASTSource::PrintStats() {} | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 74 |  | 
| Rafael Espindola | f5bbe27 | 2014-05-21 14:19:22 +0000 | [diff] [blame] | 75 | bool ExternalASTSource::layoutRecordType( | 
|  | 76 | const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, | 
|  | 77 | llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, | 
|  | 78 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, | 
|  | 79 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets) { | 
|  | 80 | return false; | 
|  | 81 | } | 
|  | 82 |  | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 83 | Decl *ExternalASTSource::GetExternalDecl(uint32_t ID) { | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 84 | return nullptr; | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 85 | } | 
|  | 86 |  | 
|  | 87 | Selector ExternalASTSource::GetExternalSelector(uint32_t ID) { | 
|  | 88 | return Selector(); | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | uint32_t ExternalASTSource::GetNumExternalSelectors() { | 
|  | 92 | return 0; | 
|  | 93 | } | 
|  | 94 |  | 
|  | 95 | Stmt *ExternalASTSource::GetExternalDeclStmt(uint64_t Offset) { | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 96 | return nullptr; | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 97 | } | 
|  | 98 |  | 
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 99 | CXXCtorInitializer ** | 
|  | 100 | ExternalASTSource::GetExternalCXXCtorInitializers(uint64_t Offset) { | 
|  | 101 | return nullptr; | 
|  | 102 | } | 
|  | 103 |  | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 104 | CXXBaseSpecifier * | 
|  | 105 | ExternalASTSource::GetExternalCXXBaseSpecifiers(uint64_t Offset) { | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 106 | return nullptr; | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 107 | } | 
|  | 108 |  | 
| Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 109 | bool | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 110 | ExternalASTSource::FindExternalVisibleDeclsByName(const DeclContext *DC, | 
|  | 111 | DeclarationName Name) { | 
| Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 112 | return false; | 
| Axel Naumann | aa627ba | 2011-02-28 11:22:50 +0000 | [diff] [blame] | 113 | } | 
|  | 114 |  | 
| Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 115 | void ExternalASTSource::completeVisibleDeclsMap(const DeclContext *DC) {} | 
| Nick Lewycky | 2bd0ab2 | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 116 |  | 
| Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 117 | void ExternalASTSource::FindExternalLexicalDecls( | 
|  | 118 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, | 
|  | 119 | SmallVectorImpl<Decl *> &Result) {} | 
| Axel Naumann | ed35df1 | 2011-05-04 12:59:24 +0000 | [diff] [blame] | 120 |  | 
| Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 121 | void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {} | 
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 122 |  | 
|  | 123 | uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { | 
|  | 124 | uint32_t OldGeneration = CurrentGeneration; | 
|  | 125 |  | 
|  | 126 | // Make sure the generation of the topmost external source for the context is | 
|  | 127 | // incremented. That might not be us. | 
|  | 128 | auto *P = C.getExternalSource(); | 
|  | 129 | if (P && P != this) | 
|  | 130 | CurrentGeneration = P->incrementGeneration(C); | 
|  | 131 | else { | 
|  | 132 | // FIXME: Only bump the generation counter if the current generation number | 
|  | 133 | // has been observed? | 
|  | 134 | if (!++CurrentGeneration) | 
|  | 135 | llvm::report_fatal_error("generation counter overflowed", false); | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | return OldGeneration; | 
|  | 139 | } |