Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/ExtractAPI/APIIgnoresList.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ExtractAPI/APIIgnoresList.cpp -------*- 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
///
9
/// \file
10
/// This file implements APIIgnoresList that allows users to specifiy a file
11
/// containing symbols to ignore during API extraction.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#include "clang/ExtractAPI/APIIgnoresList.h"
16
#include "clang/Basic/FileManager.h"
17
#include "llvm/ADT/STLExtras.h"
18
#include "llvm/Support/Error.h"
19
20
using namespace clang;
21
using namespace clang::extractapi;
22
using namespace llvm;
23
24
char IgnoresFileNotFound::ID;
25
26
0
void IgnoresFileNotFound::log(llvm::raw_ostream &os) const {
27
0
  os << "Could not find API ignores file " << Path;
28
0
}
29
30
0
std::error_code IgnoresFileNotFound::convertToErrorCode() const {
31
0
  return llvm::inconvertibleErrorCode();
32
0
}
33
34
Expected<APIIgnoresList>
35
APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
36
3
                       FileManager &FM) {
37
3
  SmallVector<StringRef, 32> Lines;
38
3
  BufferList symbolBufferList;
39
40
5
  for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
41
5
    auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
42
43
5
    if (!BufferOrErr)
44
1
      return make_error<IgnoresFileNotFound>(CurrentIgnoresFilePath);
45
46
4
    auto Buffer = std::move(BufferOrErr.get());
47
4
    Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
48
4
                              /*KeepEmpty*/ false);
49
4
    symbolBufferList.push_back(std::move(Buffer));
50
4
  }
51
52
  // Symbol names don't have spaces in them, let's just remove these in case
53
  // the input is slighlty malformed.
54
12
  
transform(Lines, Lines.begin(), [](StringRef Line) 2
{ return Line.trim(); });
55
2
  sort(Lines);
56
2
  return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
57
3
}
58
59
221
bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
60
221
  auto It = lower_bound(SymbolsToIgnore, SymbolName);
61
221
  return (It != SymbolsToIgnore.end()) && 
(*It == SymbolName)12
;
62
221
}