Coverage Report

Created: 2020-02-18 08:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/libclang/CXStoredDiagnostic.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- CXStoredDiagnostic.cpp - Diagnostics C Interface -------------------===//
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
//
9
// Implements part of the diagnostic functions of the Clang C interface.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "CIndexDiagnostic.h"
14
#include "CIndexer.h"
15
#include "CXTranslationUnit.h"
16
#include "CXSourceLocation.h"
17
#include "CXString.h"
18
19
#include "clang/Basic/DiagnosticIDs.h"
20
#include "clang/Frontend/ASTUnit.h"
21
#include "llvm/ADT/Twine.h"
22
23
using namespace clang;
24
using namespace clang::cxloc;
25
26
1.90k
CXDiagnosticSeverity CXStoredDiagnostic::getSeverity() const {
27
1.90k
  switch (Diag.getLevel()) {
28
0
    case DiagnosticsEngine::Ignored: return CXDiagnostic_Ignored;
29
606
    case DiagnosticsEngine::Note:    return CXDiagnostic_Note;
30
537
    case DiagnosticsEngine::Remark:
31
537
    // The 'Remark' level isn't represented in the stable API.
32
537
    case DiagnosticsEngine::Warning: return CXDiagnostic_Warning;
33
747
    case DiagnosticsEngine::Error:   return CXDiagnostic_Error;
34
537
    
case DiagnosticsEngine::Fatal: return CXDiagnostic_Fatal19
;
35
0
  }
36
0
  
37
0
  llvm_unreachable("Invalid diagnostic level");
38
0
}
39
40
1.90k
CXSourceLocation CXStoredDiagnostic::getLocation() const {
41
1.90k
  if (Diag.getLocation().isInvalid())
42
36
    return clang_getNullLocation();
43
1.87k
  
44
1.87k
  return translateSourceLocation(Diag.getLocation().getManager(),
45
1.87k
                                 LangOpts, Diag.getLocation());
46
1.87k
}
47
48
1.16k
CXString CXStoredDiagnostic::getSpelling() const {
49
1.16k
  return cxstring::createRef(Diag.getMessage());
50
1.16k
}
51
52
1.16k
CXString CXStoredDiagnostic::getDiagnosticOption(CXString *Disable) const {
53
1.16k
  unsigned ID = Diag.getID();
54
1.16k
  StringRef Option = DiagnosticIDs::getWarningOptionForDiag(ID);
55
1.16k
  if (!Option.empty()) {
56
324
    if (Disable)
57
0
      *Disable = cxstring::createDup((Twine("-Wno-") + Option).str());
58
324
    return cxstring::createDup((Twine("-W") + Option).str());
59
324
  }
60
845
  
61
845
  if (ID == diag::fatal_too_many_errors) {
62
0
    if (Disable)
63
0
      *Disable = cxstring::createRef("-ferror-limit=0");
64
0
    return cxstring::createRef("-ferror-limit=");
65
0
  }
66
845
67
845
  return cxstring::createEmpty();
68
845
}
69
70
0
unsigned CXStoredDiagnostic::getCategory() const {
71
0
  return DiagnosticIDs::getCategoryNumberForDiag(Diag.getID());
72
0
}
73
74
0
CXString CXStoredDiagnostic::getCategoryText() const {
75
0
  unsigned catID = DiagnosticIDs::getCategoryNumberForDiag(Diag.getID());
76
0
  return cxstring::createRef(DiagnosticIDs::getCategoryNameFromID(catID));
77
0
}
78
79
795
unsigned CXStoredDiagnostic::getNumRanges() const {
80
795
  if (Diag.getLocation().isInvalid())
81
0
    return 0;
82
795
  
83
795
  return Diag.range_size();
84
795
}
85
86
74
CXSourceRange CXStoredDiagnostic::getRange(unsigned int Range) const {
87
74
  assert(Diag.getLocation().isValid());
88
74
  return translateSourceRange(Diag.getLocation().getManager(),
89
74
                              LangOpts,
90
74
                              Diag.range_begin()[Range]);
91
74
}
92
93
758
unsigned CXStoredDiagnostic::getNumFixIts() const {
94
758
  if (Diag.getLocation().isInvalid())
95
0
    return 0;    
96
758
  return Diag.fixit_size();
97
758
}
98
99
CXString CXStoredDiagnostic::getFixIt(unsigned FixIt,
100
37
                                      CXSourceRange *ReplacementRange) const {  
101
37
  const FixItHint &Hint = Diag.fixit_begin()[FixIt];
102
37
  if (ReplacementRange) {
103
37
    // Create a range that covers the entire replacement (or
104
37
    // removal) range, adjusting the end of the range to point to
105
37
    // the end of the token.
106
37
    *ReplacementRange = translateSourceRange(Diag.getLocation().getManager(),
107
37
                                             LangOpts, Hint.RemoveRange);
108
37
  }
109
37
  return cxstring::createDup(Hint.CodeToInsert);
110
37
}
111