APIIgnoresList.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "clang/ExtractAPI/APIIgnoresList.h"
  15. #include "clang/Basic/FileManager.h"
  16. #include "llvm/ADT/STLExtras.h"
  17. #include "llvm/Support/Error.h"
  18. using namespace clang;
  19. using namespace clang::extractapi;
  20. using namespace llvm;
  21. char IgnoresFileNotFound::ID;
  22. void IgnoresFileNotFound::log(llvm::raw_ostream &os) const {
  23. os << "Could not find API ignores file " << Path;
  24. }
  25. std::error_code IgnoresFileNotFound::convertToErrorCode() const {
  26. return llvm::inconvertibleErrorCode();
  27. }
  28. Expected<APIIgnoresList> APIIgnoresList::create(StringRef IgnoresFilePath,
  29. FileManager &FM) {
  30. auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
  31. if (!BufferOrErr)
  32. return make_error<IgnoresFileNotFound>(IgnoresFilePath);
  33. auto Buffer = std::move(BufferOrErr.get());
  34. SmallVector<StringRef, 32> Lines;
  35. Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
  36. // Symbol names don't have spaces in them, let's just remove these in case the
  37. // input is slighlty malformed.
  38. transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
  39. sort(Lines);
  40. return APIIgnoresList(std::move(Lines), std::move(Buffer));
  41. }
  42. bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {
  43. auto It = lower_bound(SymbolsToIgnore, SymbolName);
  44. return (It != SymbolsToIgnore.end()) && (*It == SymbolName);
  45. }