Path: blob/main/contrib/llvm-project/clang/lib/ExtractAPI/APIIgnoresList.cpp
35234 views
//===- ExtractAPI/APIIgnoresList.cpp -------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file implements APIIgnoresList that allows users to specifiy a file10/// containing symbols to ignore during API extraction.11///12//===----------------------------------------------------------------------===//1314#include "clang/ExtractAPI/APIIgnoresList.h"15#include "clang/Basic/FileManager.h"16#include "llvm/ADT/STLExtras.h"17#include "llvm/Support/Error.h"1819using namespace clang;20using namespace clang::extractapi;21using namespace llvm;2223char IgnoresFileNotFound::ID;2425void IgnoresFileNotFound::log(llvm::raw_ostream &os) const {26os << "Could not find API ignores file " << Path;27}2829std::error_code IgnoresFileNotFound::convertToErrorCode() const {30return llvm::inconvertibleErrorCode();31}3233Expected<APIIgnoresList>34APIIgnoresList::create(const FilePathList &IgnoresFilePathList,35FileManager &FM) {36SmallVector<StringRef, 32> Lines;37BufferList symbolBufferList;3839for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {40auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);4142if (!BufferOrErr)43return make_error<IgnoresFileNotFound>(CurrentIgnoresFilePath);4445auto Buffer = std::move(BufferOrErr.get());46Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,47/*KeepEmpty*/ false);48symbolBufferList.push_back(std::move(Buffer));49}5051// Symbol names don't have spaces in them, let's just remove these in case52// the input is slighlty malformed.53transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });54sort(Lines);55return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));56}5758bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {59auto It = lower_bound(SymbolsToIgnore, SymbolName);60return (It != SymbolsToIgnore.end()) && (*It == SymbolName);61}626364