[clang-tools-extra] r249127 - Handle trailing underscores on modernize-loop-convert variable namer.
Angel Garcia Gomez via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 06:20:11 PDT 2015
Author: angelgarcia
Date: Fri Oct 2 08:20:11 2015
New Revision: 249127
URL: http://llvm.org/viewvc/llvm-project?rev=249127&view=rev
Log:
Handle trailing underscores on modernize-loop-convert variable namer.
Summary: https://llvm.org/bugs/show_bug.cgi?id=24961.
Reviewers: klimek
Subscribers: cfe-commits, alexfh
Differential Revision: http://reviews.llvm.org/D13381
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-lowercase.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-uppercase.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=249127&r1=249126&r2=249127&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Fri Oct 2 08:20:11 2015
@@ -819,6 +819,14 @@ std::string VariableNamer::createIndexNa
size_t Len = ContainerName.size();
if (Len > 1 && ContainerName.endswith(Style == NS_UpperCase ? "S" : "s")) {
IteratorName = ContainerName.substr(0, Len - 1);
+ // E.g.: (auto thing : things)
+ if (!declarationExists(IteratorName))
+ return IteratorName;
+ }
+
+ if (Len > 2 && ContainerName.endswith(Style == NS_UpperCase ? "S_" : "s_")) {
+ IteratorName = ContainerName.substr(0, Len - 2);
+ // E.g.: (auto thing : things_)
if (!declarationExists(IteratorName))
return IteratorName;
}
@@ -835,14 +843,17 @@ std::string VariableNamer::createIndexNa
case NS_UpperCase:
Elem = "ELEM";
}
+ // E.g.: (auto elem : container)
if (!declarationExists(Elem))
return Elem;
IteratorName = AppendWithStyle(ContainerName, OldIndex->getName());
+ // E.g.: (auto container_i : container)
if (!declarationExists(IteratorName))
return IteratorName;
IteratorName = AppendWithStyle(ContainerName, Elem);
+ // E.g.: (auto container_elem : container)
if (!declarationExists(IteratorName))
return IteratorName;
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-lowercase.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-lowercase.cpp?rev=249127&r1=249126&r2=249127&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-lowercase.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-lowercase.cpp Fri Oct 2 08:20:11 2015
@@ -7,6 +7,7 @@
const int n = 10;
int arr[n];
int nums[n];
+int nums_[n];
void naming() {
for (int i = 0; i < n; ++i) {
@@ -23,6 +24,13 @@ void naming() {
// CHECK-FIXES: for (auto & num : nums)
// CHECK-FIXES-NEXT: printf("%d\n", num);
+ for (int i = 0; i < n; ++i) {
+ printf("%d\n", nums_[i]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+ // CHECK-FIXES: for (auto & num : nums_)
+ // CHECK-FIXES-NEXT: printf("%d\n", num);
+
int num = 0;
for (int i = 0; i < n; ++i) {
printf("%d\n", nums[i] + num);
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-uppercase.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-uppercase.cpp?rev=249127&r1=249126&r2=249127&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-uppercase.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-uppercase.cpp Fri Oct 2 08:20:11 2015
@@ -7,6 +7,7 @@
const int N = 10;
int ARR[N];
int NUMS[N];
+int NUMS_[N];
void naming() {
for (int I = 0; I < N; ++I) {
@@ -23,6 +24,13 @@ void naming() {
// CHECK-FIXES: for (auto & NUM : NUMS)
// CHECK-FIXES-NEXT: printf("%d\n", NUM);
+ for (int I = 0; I < N; ++I) {
+ printf("%d\n", NUMS_[I]);
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+ // CHECK-FIXES: for (auto & NUM : NUMS_)
+ // CHECK-FIXES-NEXT: printf("%d\n", NUM);
+
int NUM = 0;
for (int I = 0; I < N; ++I) {
printf("%d\n", NUMS[I] + NUM);
More information about the cfe-commits
mailing list