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