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