1 //===- ExtractAPI/APIIgnoresList.h ---------------*- 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 This file defines APIIgnoresList which is a type that allows querying 10 /// files containing symbols to ignore when extracting API information. 11 /// 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_API_IGNORES_LIST_H 15 #define LLVM_CLANG_API_IGNORES_LIST_H 16 17 #include "clang/Basic/FileManager.h" 18 #include "llvm/ADT/SmallVector.h" 19 #include "llvm/ADT/StringRef.h" 20 #include "llvm/Support/Error.h" 21 #include "llvm/Support/raw_ostream.h" 22 23 #include <memory> 24 #include <system_error> 25 26 namespace llvm { 27 class MemoryBuffer; 28 } // namespace llvm 29 30 namespace clang { 31 namespace extractapi { 32 33 struct IgnoresFileNotFound : public llvm::ErrorInfo<IgnoresFileNotFound> { 34 std::string Path; 35 static char ID; 36 IgnoresFileNotFoundIgnoresFileNotFound37 explicit IgnoresFileNotFound(StringRef Path) : Path(Path) {} 38 39 virtual void log(llvm::raw_ostream &os) const override; 40 41 virtual std::error_code convertToErrorCode() const override; 42 }; 43 44 /// A type that provides access to a new line separated list of symbol names to 45 /// ignore when extracting API information. 46 struct APIIgnoresList { 47 using FilePathList = std::vector<std::string>; 48 49 /// The API to use for generating from the files at \p IgnoresFilePathList. 50 /// 51 /// \returns an initialized APIIgnoresList or an Error. 52 static llvm::Expected<APIIgnoresList> 53 create(const FilePathList &IgnoresFilePathList, FileManager &FM); 54 55 APIIgnoresList() = default; 56 57 /// Check if \p SymbolName is specified in the APIIgnoresList and if it should 58 /// therefore be ignored. 59 bool shouldIgnore(llvm::StringRef SymbolName) const; 60 61 private: 62 using SymbolNameList = llvm::SmallVector<llvm::StringRef, 32>; 63 using BufferList = llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>>; 64 APIIgnoresListAPIIgnoresList65 APIIgnoresList(SymbolNameList SymbolsToIgnore, BufferList Buffers) 66 : SymbolsToIgnore(std::move(SymbolsToIgnore)), 67 Buffers(std::move(Buffers)) {} 68 69 SymbolNameList SymbolsToIgnore; 70 BufferList Buffers; 71 }; 72 73 } // namespace extractapi 74 } // namespace clang 75 76 #endif // LLVM_CLANG_API_IGNORES_LIST_H 77