| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H |
| 15 | #define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H |
| 16 | |
| 17 | #include "clang/AST/ASTImporterLookupTable.h" |
| 18 | #include "clang/Basic/LLVM.h" |
| 19 | #include "llvm/ADT/DenseMap.h" |
| 20 | #include "llvm/ADT/SmallPtrSet.h" |
| 21 | #include "llvm/ADT/StringMap.h" |
| 22 | #include "llvm/Support/Error.h" |
| 23 | |
| 24 | namespace clang { |
| 25 | class CompilerInstance; |
| 26 | class ASTContext; |
| 27 | class ASTImporter; |
| 28 | class ASTUnit; |
| 29 | class DeclContext; |
| 30 | class FunctionDecl; |
| 31 | class NamedDecl; |
| 32 | class TranslationUnitDecl; |
| 33 | |
| 34 | namespace cross_tu { |
| 35 | |
| 36 | enum class index_error_code { |
| 37 | unspecified = 1, |
| 38 | missing_index_file, |
| 39 | invalid_index_format, |
| 40 | multiple_definitions, |
| 41 | missing_definition, |
| 42 | failed_import, |
| 43 | failed_to_get_external_ast, |
| 44 | failed_to_generate_usr, |
| 45 | triple_mismatch, |
| 46 | lang_mismatch, |
| 47 | lang_dialect_mismatch |
| 48 | }; |
| 49 | |
| 50 | class IndexError : public llvm::ErrorInfo<IndexError> { |
| 51 | public: |
| 52 | static char ID; |
| 53 | IndexError(index_error_code C) : Code(C), LineNo(0) {} |
| 54 | IndexError(index_error_code C, std::string FileName, int LineNo = 0) |
| 55 | : Code(C), FileName(std::move(FileName)), LineNo(LineNo) {} |
| 56 | IndexError(index_error_code C, std::string FileName, std::string TripleToName, |
| 57 | std::string TripleFromName) |
| 58 | : Code(C), FileName(std::move(FileName)), |
| 59 | TripleToName(std::move(TripleToName)), |
| 60 | TripleFromName(std::move(TripleFromName)) {} |
| 61 | void log(raw_ostream &OS) const override; |
| 62 | std::error_code convertToErrorCode() const override; |
| 63 | index_error_code getCode() const { return Code; } |
| 64 | int getLineNum() const { return LineNo; } |
| 65 | std::string getFileName() const { return FileName; } |
| 66 | std::string getTripleToName() const { return TripleToName; } |
| 67 | std::string getTripleFromName() const { return TripleFromName; } |
| 68 | |
| 69 | private: |
| 70 | index_error_code Code; |
| 71 | std::string FileName; |
| 72 | int LineNo; |
| 73 | std::string TripleToName; |
| 74 | std::string TripleFromName; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | llvm::Expected<llvm::StringMap<std::string>> |
| 86 | parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir); |
| 87 | |
| 88 | std::string createCrossTUIndexString(const llvm::StringMap<std::string> &Index); |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | class CrossTranslationUnitContext { |
| 101 | public: |
| 102 | CrossTranslationUnitContext(CompilerInstance &CI); |
| 103 | ~CrossTranslationUnitContext(); |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | llvm::Expected<const FunctionDecl *> |
| 122 | getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir, |
| 123 | StringRef IndexName, bool DisplayCTUProgress = false); |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | llvm::Expected<ASTUnit *> loadExternalAST(StringRef LookupName, |
| 139 | StringRef CrossTUDir, |
| 140 | StringRef IndexName, |
| 141 | bool DisplayCTUProgress = false); |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | llvm::Expected<const FunctionDecl *> importDefinition(const FunctionDecl *FD); |
| 149 | |
| 150 | |
| 151 | static std::string getLookupName(const NamedDecl *ND); |
| 152 | |
| 153 | |
| 154 | void emitCrossTUDiagnostics(const IndexError &IE); |
| 155 | |
| 156 | private: |
| 157 | void lazyInitLookupTable(TranslationUnitDecl *ToTU); |
| 158 | ASTImporter &getOrCreateASTImporter(ASTContext &From); |
| 159 | const FunctionDecl *findFunctionInDeclContext(const DeclContext *DC, |
| 160 | StringRef LookupFnName); |
| 161 | |
| 162 | llvm::StringMap<std::unique_ptr<clang::ASTUnit>> FileASTUnitMap; |
| 163 | llvm::StringMap<clang::ASTUnit *> FunctionASTUnitMap; |
| 164 | llvm::StringMap<std::string> FunctionFileMap; |
| 165 | llvm::DenseMap<TranslationUnitDecl *, std::unique_ptr<ASTImporter>> |
| 166 | ASTUnitImporterMap; |
| 167 | CompilerInstance &CI; |
| 168 | ASTContext &Context; |
| 169 | std::unique_ptr<ASTImporterLookupTable> LookupTable; |
| 170 | }; |
| 171 | |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | #endif |
| 176 | |