clang 20.0.0git
APIIgnoresList.cpp
Go to the documentation of this file.
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
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/Support/Error.h"
19
20using namespace clang;
21using namespace clang::extractapi;
22using namespace llvm;
23
25
26void IgnoresFileNotFound::log(llvm::raw_ostream &os) const {
27 os << "Could not find API ignores file " << Path;
28}
29
31 return llvm::inconvertibleErrorCode();
32}
33
35APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
36 FileManager &FM) {
38 BufferList symbolBufferList;
39
40 for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
41 auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
42
43 if (!BufferOrErr)
44 return make_error<IgnoresFileNotFound>(CurrentIgnoresFilePath);
45
46 auto Buffer = std::move(BufferOrErr.get());
47 Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
48 /*KeepEmpty*/ false);
49 symbolBufferList.push_back(std::move(Buffer));
50 }
51
52 // Symbol names don't have spaces in them, let's just remove these in case
53 // the input is slighlty malformed.
54 transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
55 sort(Lines);
56 return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
57}
58
59bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
60 auto It = lower_bound(SymbolsToIgnore, SymbolName);
61 return (It != SymbolsToIgnore.end()) && (*It == SymbolName);
62}
Defines the clang::FileManager interface and associated types.
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(FileEntryRef Entry, bool isVolatile=false, bool RequiresNullTerminator=true, std::optional< int64_t > MaybeLimit=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
std::vector< std::string > FilePathList
bool shouldIgnore(llvm::StringRef SymbolName) const
Check if SymbolName is specified in the APIIgnoresList and if it should therefore be ignored.
static llvm::Expected< APIIgnoresList > create(const FilePathList &IgnoresFilePathList, FileManager &FM)
The API to use for generating from the files at IgnoresFilePathList.
virtual void log(llvm::raw_ostream &os) const override
virtual std::error_code convertToErrorCode() const override