Coverage Report

Created: 2020-11-24 06:42

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