FileExtensionsUtils.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===--- FileExtensionsUtils.h - clang-tidy --------------------*- 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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILE_EXTENSIONS_UTILS_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILE_EXTENSIONS_UTILS_H
  10. #include "clang/Basic/SourceLocation.h"
  11. #include "clang/Basic/SourceManager.h"
  12. #include "llvm/ADT/SmallSet.h"
  13. #include "llvm/ADT/StringRef.h"
  14. #include <optional>
  15. namespace clang::tidy::utils {
  16. typedef llvm::SmallSet<llvm::StringRef, 5> FileExtensionsSet;
  17. /// Checks whether expansion location of \p Loc is in header file.
  18. bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
  19. const FileExtensionsSet &HeaderFileExtensions);
  20. /// Checks whether presumed location of \p Loc is in header file.
  21. bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
  22. const FileExtensionsSet &HeaderFileExtensions);
  23. /// Checks whether spelling location of \p Loc is in header file.
  24. bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
  25. const FileExtensionsSet &HeaderFileExtensions);
  26. /// Returns recommended default value for the list of header file
  27. /// extensions.
  28. inline StringRef defaultHeaderFileExtensions() { return ";h;hh;hpp;hxx"; }
  29. /// Returns recommended default value for the list of implementation file
  30. /// extensions.
  31. inline StringRef defaultImplementationFileExtensions() {
  32. return "c;cc;cpp;cxx";
  33. }
  34. /// Returns recommended default value for the list of file extension
  35. /// delimiters.
  36. inline StringRef defaultFileExtensionDelimiters() { return ",;"; }
  37. /// Parses header file extensions from a semicolon-separated list.
  38. bool parseFileExtensions(StringRef AllFileExtensions,
  39. FileExtensionsSet &FileExtensions,
  40. StringRef Delimiters);
  41. /// Decides whether a file has a header file extension.
  42. /// Returns the file extension, if included in the provided set.
  43. std::optional<StringRef>
  44. getFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions);
  45. /// Decides whether a file has one of the specified file extensions.
  46. bool isFileExtension(StringRef FileName,
  47. const FileExtensionsSet &FileExtensions);
  48. } // namespace clang::tidy::utils
  49. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_FILE_EXTENSIONS_UTILS_H