blob: 26184a57378315f4423c8689ce272f79500e4303 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===--- 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
18namespace clang {
19namespace tidy {
20namespace utils {
21
22typedef llvm::SmallSet<llvm::StringRef, 5> FileExtensionsSet;
23
24/// Checks whether expansion location of \p Loc is in header file.
25bool isExpansionLocInHeaderFile(SourceLocation Loc, const SourceManager &SM,
26 const FileExtensionsSet &HeaderFileExtensions);
27
28/// Checks whether presumed location of \p Loc is in header file.
29bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
30 const FileExtensionsSet &HeaderFileExtensions);
31
32/// Checks whether spelling location of \p Loc is in header file.
33bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
34 const FileExtensionsSet &HeaderFileExtensions);
35
36/// Returns recommended default value for the list of header file
37/// extensions.
38inline StringRef defaultHeaderFileExtensions() { return ";h;hh;hpp;hxx"; }
39
40/// Returns recommended default value for the list of implementation file
41/// extensions.
42inline StringRef defaultImplementationFileExtensions() {
43 return "c;cc;cpp;cxx";
44}
45
46/// Returns recommended default value for the list of file extension
47/// delimiters.
48inline StringRef defaultFileExtensionDelimiters() { return ",;"; }
49
50/// Parses header file extensions from a semicolon-separated list.
51bool 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.
57llvm::Optional<StringRef>
58getFileExtension(StringRef FileName, const FileExtensionsSet &FileExtensions);
59
60/// Decides whether a file has one of the specified file extensions.
61bool 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