compositeprimes updated this revision to Diff 297728.
compositeprimes edited the summary of this revision.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89276/new/
https://reviews.llvm.org/D89276
Files:
clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
clang-tools-extra/clang-tidy/utils/IncludeSorter.h
clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===================================================================
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -137,6 +137,18 @@
}
};
+class ObjCGeneratedHeaderInserterCheck : public IncludeInserterCheckBase {
+public:
+ ObjCGeneratedHeaderInserterCheck(StringRef CheckName,
+ ClangTidyContext *Context)
+ : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google_ObjC) {}
+
+ std::vector<StringRef> headersToInclude() const override {
+ return {"clang_tidy/tests/generated_file.proto.h"};
+ }
+};
+
template <typename Check>
std::string runCheckOnCode(StringRef Code, StringRef Filename) {
std::vector<ClangTidyError> Errors;
@@ -156,6 +168,9 @@
{"path/to/z/header.h", "\n"},
{"path/to/header.h", "\n"},
{"path/to/header2.h", "\n"},
+ // Generated headers
+ {"clang_tidy/tests/"
+ "generated_file.proto.h", "\n"},
// Fake system headers.
{"stdlib.h", "\n"},
{"unistd.h", "\n"},
@@ -706,6 +721,37 @@
"insert_includes_test_header.mm"));
}
+TEST(IncludeInserterTest, InsertGeneratedHeaderObjectiveC) {
+ const char *PreCode = R"(
+#import "clang_tidy/tests/insert_includes_test_header.h"
+
+#include <list>
+#include <map>
+
+#include "path/to/a/header.h"
+
+void foo() {
+ int a = 0;
+})";
+ const char *PostCode = R"(
+#import "clang_tidy/tests/insert_includes_test_header.h"
+
+#include <list>
+#include <map>
+
+#include "path/to/a/header.h"
+
+#import "clang_tidy/tests/generated_file.proto.h"
+
+void foo() {
+ int a = 0;
+})";
+
+ EXPECT_EQ(PostCode, runCheckOnCode<ObjCGeneratedHeaderInserterCheck>(
+ PreCode, "devtools/cymbal/clang_tidy/tests/"
+ "insert_includes_test_header.mm"));
+}
+
} // anonymous namespace
} // namespace tidy
} // namespace clang
Index: clang-tools-extra/clang-tidy/utils/IncludeSorter.h
===================================================================
--- clang-tools-extra/clang-tidy/utils/IncludeSorter.h
+++ clang-tools-extra/clang-tidy/utils/IncludeSorter.h
@@ -31,7 +31,8 @@
IK_CSystemInclude = 1, ///< e.g. ``#include <stdio.h>``
IK_CXXSystemInclude = 2, ///< e.g. ``#include <vector>``
IK_NonSystemInclude = 3, ///< e.g. ``#include "bar.h"``
- IK_InvalidInclude = 4 ///< total number of valid ``IncludeKind``s
+ IK_GeneratedInclude = 4, ///< e.g. ``#include "bar.proto.h"``
+ IK_InvalidInclude = 5 ///< total number of valid ``IncludeKind``s
};
/// ``IncludeSorter`` constructor; takes the FileID and name of the file to be
Index: clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
+++ clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
@@ -91,6 +91,12 @@
return IncludeSorter::IK_MainTUInclude;
}
}
+ if (Style == IncludeSorter::IS_Google_ObjC) {
+ if (IncludeFile.endswith(".generated.h") ||
+ IncludeFile.endswith(".proto.h") || IncludeFile.endswith(".pbobjc.h")) {
+ return IncludeSorter::IK_GeneratedInclude;
+ }
+ }
return IncludeSorter::IK_NonSystemInclude;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits