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