clang-tools  14.0.0git
FileExtensionsUtils.h
Go to the documentation of this file.
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.
38 inline StringRef defaultHeaderFileExtensions() { return ";h;hh;hpp;hxx"; }
39 
40 /// Returns recommended default value for the list of implementation file
41 /// extensions.
43  return "c;cc;cpp;cxx";
44 }
45 
46 /// Returns recommended default value for the list of file extension
47 /// delimiters.
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
Loc
SourceLocation Loc
Definition: KernelNameRestrictionCheck.cpp:45
clang::tidy::utils::getFileExtension
llvm::Optional< StringRef > getFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions)
Decides whether a file has a header file extension.
Definition: FileExtensionsUtils.cpp:57
clang::tidy::utils::isPresumedLocInHeaderFile
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether presumed location of Loc is in header file.
Definition: FileExtensionsUtils.cpp:23
clang::tidy::utils::parseFileExtensions
bool parseFileExtensions(StringRef AllFileExtensions, FileExtensionsSet &FileExtensions, StringRef Delimiters)
Parses header file extensions from a semicolon-separated list.
Definition: FileExtensionsUtils.cpp:35
clang::tidy::utils::isFileExtension
bool isFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions)
Decides whether a file has one of the specified file extensions.
Definition: FileExtensionsUtils.cpp:67
clang::tidy::utils::isSpellingLocInHeaderFile
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether spelling location of Loc is in header file.
Definition: FileExtensionsUtils.cpp:29
clang::tidy::utils::defaultFileExtensionDelimiters
StringRef defaultFileExtensionDelimiters()
Returns recommended default value for the list of file extension delimiters.
Definition: FileExtensionsUtils.h:48
FileName
StringRef FileName
Definition: KernelNameRestrictionCheck.cpp:46
clang::tidy::utils::isExpansionLocInHeaderFile
bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether expansion location of Loc is in header file.
Definition: FileExtensionsUtils.cpp:17
clang::tidy::utils::defaultImplementationFileExtensions
StringRef defaultImplementationFileExtensions()
Returns recommended default value for the list of implementation file extensions.
Definition: FileExtensionsUtils.h:42
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::utils::defaultHeaderFileExtensions
StringRef defaultHeaderFileExtensions()
Returns recommended default value for the list of header file extensions.
Definition: FileExtensionsUtils.h:38
clang::tidy::utils::FileExtensionsSet
llvm::SmallSet< llvm::StringRef, 5 > FileExtensionsSet
Definition: FileExtensionsUtils.h:22