Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Frontend/ASTMerge.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ASTMerge.cpp - AST Merging Frontend Action --------------*- C++ -*-===//
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
#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/ASTImporterSharedState.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
30
ASTMergeAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
21
30
  return AdaptedAction->CreateASTConsumer(CI, InFile);
22
30
}
23
24
30
bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI) {
25
30
  // FIXME: This is a hack. We need a better way to communicate the
26
30
  // AST file, compiler instance, and file name than member variables
27
30
  // of FrontendAction.
28
30
  AdaptedAction->setCurrentInput(getCurrentInput(), takeCurrentASTUnit());
29
30
  AdaptedAction->setCompilerInstance(&CI);
30
30
  return AdaptedAction->BeginSourceFileAction(CI);
31
30
}
32
33
30
void ASTMergeAction::ExecuteAction() {
34
30
  CompilerInstance &CI = getCompilerInstance();
35
30
  CI.getDiagnostics().getClient()->BeginSourceFile(
36
30
                                             CI.getASTContext().getLangOpts());
37
30
  CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
38
30
                                       &CI.getASTContext());
39
30
  IntrusiveRefCntPtr<DiagnosticIDs>
40
30
      DiagIDs(CI.getDiagnostics().getDiagnosticIDs());
41
30
  auto SharedState = std::make_shared<ASTImporterSharedState>(
42
30
      *CI.getASTContext().getTranslationUnitDecl());
43
79
  for (unsigned I = 0, N = ASTFiles.size(); I != N; 
++I49
) {
44
49
    IntrusiveRefCntPtr<DiagnosticsEngine>
45
49
        Diags(new DiagnosticsEngine(DiagIDs, &CI.getDiagnosticOpts(),
46
49
                                    new ForwardingDiagnosticConsumer(
47
49
                                          *CI.getDiagnostics().getClient()),
48
49
                                    /*ShouldOwnClient=*/true));
49
49
    std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
50
49
        ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
51
49
        CI.getFileSystemOpts(), false);
52
49
53
49
    if (!Unit)
54
0
      continue;
55
49
56
49
    ASTImporter Importer(CI.getASTContext(), CI.getFileManager(),
57
49
                         Unit->getASTContext(), Unit->getFileManager(),
58
49
                         /*MinimalImport=*/false, SharedState);
59
49
60
49
    TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
61
746
    for (auto *D : TU->decls()) {
62
746
      // Don't re-import __va_list_tag, __builtin_va_list.
63
746
      if (const auto *ND = dyn_cast<NamedDecl>(D))
64
741
        if (IdentifierInfo *II = ND->getIdentifier())
65
721
          if (II->isStr("__va_list_tag") || II->isStr("__builtin_va_list"))
66
49
            continue;
67
697
68
697
      llvm::Expected<Decl *> ToDOrError = Importer.Import(D);
69
697
70
697
      if (ToDOrError) {
71
691
        DeclGroupRef DGR(*ToDOrError);
72
691
        CI.getASTConsumer().HandleTopLevelDecl(DGR);
73
691
      } else {
74
6
        llvm::consumeError(ToDOrError.takeError());
75
6
      }
76
697
    }
77
49
  }
78
30
79
30
  AdaptedAction->ExecuteAction();
80
30
  CI.getDiagnostics().getClient()->EndSourceFile();
81
30
}
82
83
30
void ASTMergeAction::EndSourceFileAction() {
84
30
  return AdaptedAction->EndSourceFileAction();
85
30
}
86
87
ASTMergeAction::ASTMergeAction(std::unique_ptr<FrontendAction> adaptedAction,
88
                               ArrayRef<std::string> ASTFiles)
89
30
: AdaptedAction(std::move(adaptedAction)), ASTFiles(ASTFiles.begin(), ASTFiles.end()) {
90
30
  assert(AdaptedAction && "ASTMergeAction needs an action to adapt");
91
30
}
92
93
30
ASTMergeAction::~ASTMergeAction() {
94
30
}
95
96
30
bool ASTMergeAction::usesPreprocessorOnly() const {
97
30
  return AdaptedAction->usesPreprocessorOnly();
98
30
}
99
100
30
TranslationUnitKind ASTMergeAction::getTranslationUnitKind() {
101
30
  return AdaptedAction->getTranslationUnitKind();
102
30
}
103
104
0
bool ASTMergeAction::hasPCHSupport() const {
105
0
  return AdaptedAction->hasPCHSupport();
106
0
}
107
108
0
bool ASTMergeAction::hasASTFileSupport() const {
109
0
  return AdaptedAction->hasASTFileSupport();
110
0
}
111
112
0
bool ASTMergeAction::hasCodeCompletionSupport() const {
113
0
  return AdaptedAction->hasCodeCompletionSupport();
114
0
}