| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | #include "clang/Frontend/ASTUnit.h" |
| 9 | #include "clang/AST/ASTContext.h" |
| 10 | #include "clang/AST/ASTDiagnostic.h" |
| 11 | #include "clang/AST/ASTImporter.h" |
| 12 | #include "clang/AST/ASTImporterLookupTable.h" |
| 13 | #include "clang/Basic/Diagnostic.h" |
| 14 | #include "clang/Frontend/CompilerInstance.h" |
| 15 | #include "clang/Frontend/FrontendActions.h" |
| 16 | |
| 17 | using namespace clang; |
| 18 | |
| 19 | std::unique_ptr<ASTConsumer> |
| 20 | ASTMergeAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { |
| 21 | return AdaptedAction->CreateASTConsumer(CI, InFile); |
| 22 | } |
| 23 | |
| 24 | bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI) { |
| 25 | |
| 26 | |
| 27 | |
| 28 | AdaptedAction->setCurrentInput(getCurrentInput(), takeCurrentASTUnit()); |
| 29 | AdaptedAction->setCompilerInstance(&CI); |
| 30 | return AdaptedAction->BeginSourceFileAction(CI); |
| 31 | } |
| 32 | |
| 33 | void ASTMergeAction::ExecuteAction() { |
| 34 | CompilerInstance &CI = getCompilerInstance(); |
| 35 | CI.getDiagnostics().getClient()->BeginSourceFile( |
| 36 | CI.getASTContext().getLangOpts()); |
| 37 | CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument, |
| 38 | &CI.getASTContext()); |
| 39 | IntrusiveRefCntPtr<DiagnosticIDs> |
| 40 | DiagIDs(CI.getDiagnostics().getDiagnosticIDs()); |
| 41 | ASTImporterLookupTable LookupTable( |
| 42 | *CI.getASTContext().getTranslationUnitDecl()); |
| 43 | for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) { |
| 44 | IntrusiveRefCntPtr<DiagnosticsEngine> |
| 45 | Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(), |
| 46 | new ForwardingDiagnosticConsumer( |
| 47 | *CI.getDiagnostics().getClient()), |
| 48 | )); |
| 49 | std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile( |
| 50 | ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags, |
| 51 | CI.getFileSystemOpts(), false); |
| 52 | |
| 53 | if (!Unit) |
| 54 | continue; |
| 55 | |
| 56 | ASTImporter Importer(CI.getASTContext(), CI.getFileManager(), |
| 57 | Unit->getASTContext(), Unit->getFileManager(), |
| 58 | , &LookupTable); |
| 59 | |
| 60 | TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); |
| 61 | for (auto *D : TU->decls()) { |
| 62 | |
| 63 | if (const auto *ND = dyn_cast<NamedDecl>(D)) |
| 64 | if (IdentifierInfo *II = ND->getIdentifier()) |
| 65 | if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list")) |
| 66 | continue; |
| 67 | |
| 68 | Decl *ToD = Importer.Import(D); |
| 69 | |
| 70 | if (ToD) { |
| 71 | DeclGroupRef DGR(ToD); |
| 72 | CI.getASTConsumer().HandleTopLevelDecl(DGR); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | AdaptedAction->ExecuteAction(); |
| 78 | CI.getDiagnostics().getClient()->EndSourceFile(); |
| 79 | } |
| 80 | |
| 81 | void ASTMergeAction::EndSourceFileAction() { |
| 82 | return AdaptedAction->EndSourceFileAction(); |
| 83 | } |
| 84 | |
| 85 | ASTMergeAction::ASTMergeAction(std::unique_ptr<FrontendAction> adaptedAction, |
| 86 | ArrayRef<std::string> ASTFiles) |
| 87 | : AdaptedAction(std::move(adaptedAction)), ASTFiles(ASTFiles.begin(), ASTFiles.end()) { |
| 88 | (0) . __assert_fail ("AdaptedAction && \"ASTMergeAction needs an action to adapt\"", "/home/seafit/code_projects/clang_source/clang/lib/Frontend/ASTMerge.cpp", 88, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(AdaptedAction && "ASTMergeAction needs an action to adapt"); |
| 89 | } |
| 90 | |
| 91 | ASTMergeAction::~ASTMergeAction() { |
| 92 | } |
| 93 | |
| 94 | bool ASTMergeAction::usesPreprocessorOnly() const { |
| 95 | return AdaptedAction->usesPreprocessorOnly(); |
| 96 | } |
| 97 | |
| 98 | TranslationUnitKind ASTMergeAction::getTranslationUnitKind() { |
| 99 | return AdaptedAction->getTranslationUnitKind(); |
| 100 | } |
| 101 | |
| 102 | bool ASTMergeAction::hasPCHSupport() const { |
| 103 | return AdaptedAction->hasPCHSupport(); |
| 104 | } |
| 105 | |
| 106 | bool ASTMergeAction::hasASTFileSupport() const { |
| 107 | return AdaptedAction->hasASTFileSupport(); |
| 108 | } |
| 109 | |
| 110 | bool ASTMergeAction::hasCodeCompletionSupport() const { |
| 111 | return AdaptedAction->hasCodeCompletionSupport(); |
| 112 | } |
| 113 | |