Debian Codegraph @

llvm-project/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h

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