File indexing completed on 2026-05-10 08:36:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H
0011
0012 #include "../ClangTidyCheck.h"
0013 #include <optional>
0014 #include <string>
0015
0016 namespace clang::tidy {
0017 namespace utils {
0018
0019
0020
0021
0022
0023 class IncludeSorter {
0024 public:
0025
0026 enum IncludeStyle { IS_LLVM = 0, IS_Google = 1, IS_Google_ObjC };
0027
0028
0029 enum IncludeKinds {
0030 IK_MainTUInclude = 0,
0031 IK_CSystemInclude = 1,
0032 IK_CXXSystemInclude = 2,
0033 IK_NonSystemInclude = 3,
0034 IK_GeneratedInclude = 4,
0035 IK_InvalidInclude = 5
0036 };
0037
0038
0039
0040 IncludeSorter(const SourceManager *SourceMgr, const FileID FileID,
0041 StringRef FileName, IncludeStyle Style);
0042
0043
0044 void addInclude(StringRef FileName, bool IsAngled,
0045 SourceLocation HashLocation, SourceLocation EndLocation);
0046
0047
0048
0049
0050 std::optional<FixItHint> createIncludeInsertion(StringRef FileName,
0051 bool IsAngled);
0052
0053 private:
0054 using SourceRangeVector = SmallVector<SourceRange, 1>;
0055
0056 const SourceManager *SourceMgr;
0057 const IncludeStyle Style;
0058 FileID CurrentFileID;
0059
0060 StringRef CanonicalFile;
0061
0062 SourceRangeVector SourceLocations;
0063
0064 llvm::StringMap<SourceRangeVector> IncludeLocations;
0065
0066 SmallVector<std::string, 1> IncludeBucket[IK_InvalidInclude];
0067 };
0068
0069 }
0070
0071 template <> struct OptionEnumMapping<utils::IncludeSorter::IncludeStyle> {
0072 static ArrayRef<std::pair<utils::IncludeSorter::IncludeStyle, StringRef>>
0073 getEnumMapping();
0074 };
0075 }
0076 #endif