[clang-tools-extra] r343788 - [clang-tidy] Added pointer types to clang-tidy readability-identifier-naming check.
Jonas Toth via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 4 08:47:57 PDT 2018
Author: jonastoth
Date: Thu Oct 4 08:47:57 2018
New Revision: 343788
URL: http://llvm.org/viewvc/llvm-project?rev=343788&view=rev
Log:
[clang-tidy] Added pointer types to clang-tidy readability-identifier-naming check.
Summary:
Option to check for different naming conventions on the following types:
- GlobalConstantPointer
- GlobalPointer
- LocalConstantPointer
- LocalPointer
- PointerParameter
- ConstantPointerParameter
When not specified, the conventions for the non pointer types will be applied (GlobalConstant, GlobalVariable, LocalConstant, ...).
Patch by ffigueras!
Reviewers: alexfh, kbobyrev
Reviewed By: alexfh
Subscribers: xazax.hun, cfe-commits
Differential Revision: https://reviews.llvm.org/D52882
Modified:
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=343788&r1=343787&r2=343788&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp Thu Oct 4 08:47:57 2018
@@ -77,8 +77,12 @@ namespace readability {
m(ClassConstant) \
m(ClassMember) \
m(GlobalConstant) \
+ m(GlobalConstantPointer) \
+ m(GlobalPointer) \
m(GlobalVariable) \
m(LocalConstant) \
+ m(LocalConstantPointer) \
+ m(LocalPointer) \
m(LocalVariable) \
m(StaticConstant) \
m(StaticVariable) \
@@ -87,6 +91,8 @@ namespace readability {
m(ConstantParameter) \
m(ParameterPack) \
m(Parameter) \
+ m(PointerParameter) \
+ m(ConstantPointerParameter) \
m(AbstractClass) \
m(Struct) \
m(Class) \
@@ -486,6 +492,9 @@ static StyleKind findStyleKind(
return SK_ConstexprVariable;
if (!Type.isNull() && Type.isConstQualified()) {
+ if (Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_ConstantPointerParameter])
+ return SK_ConstantPointerParameter;
+
if (NamingStyles[SK_ConstantParameter])
return SK_ConstantParameter;
@@ -496,6 +505,9 @@ static StyleKind findStyleKind(
if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
return SK_ParameterPack;
+ if (!Type.isNull() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_PointerParameter])
+ return SK_PointerParameter;
+
if (NamingStyles[SK_Parameter])
return SK_Parameter;
@@ -512,12 +524,18 @@ static StyleKind findStyleKind(
if (Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
return SK_ClassConstant;
+ if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_GlobalConstantPointer])
+ return SK_GlobalConstantPointer;
+
if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
return SK_GlobalConstant;
if (Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
return SK_StaticConstant;
+ if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_LocalConstantPointer])
+ return SK_LocalConstantPointer;
+
if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
return SK_LocalConstant;
@@ -531,11 +549,17 @@ static StyleKind findStyleKind(
if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember])
return SK_ClassMember;
+ if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_GlobalPointer])
+ return SK_GlobalPointer;
+
if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalVariable])
return SK_GlobalVariable;
if (Decl->isStaticLocal() && NamingStyles[SK_StaticVariable])
return SK_StaticVariable;
+
+ if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_LocalPointer])
+ return SK_LocalPointer;
if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalVariable])
return SK_LocalVariable;
Modified: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp?rev=343788&r1=343787&r2=343788&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp Thu Oct 4 08:47:57 2018
@@ -67,7 +67,19 @@
// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
// RUN: {key: readability-identifier-naming.TypeAliasCase, value: camel_Snake_Back}, \
// RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
-// RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
+// RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0}, \
+// RUN: {key: readability-identifier-naming.GlobalPointerCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.GlobalPointerSuffix, value: '_Ptr'}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.GlobalConstantPointerSuffix, value: '_Ptr'}, \
+// RUN: {key: readability-identifier-naming.PointerParameterCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.PointerParameterPrefix, value: 'p_'}, \
+// RUN: {key: readability-identifier-naming.ConstantPointerParameterCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.ConstantPointerParameterPrefix, value: 'cp_'}, \
+// RUN: {key: readability-identifier-naming.LocalPointerCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalPointerPrefix, value: 'l_'}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPointerCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.LocalConstantPointerPrefix, value: 'lc_'}, \
// RUN: ]}' -- -std=c++11 -fno-delayed-template-parsing \
// RUN: -I%S/Inputs/readability-identifier-naming \
// RUN: -isystem %S/Inputs/readability-identifier-naming/system
@@ -235,8 +247,8 @@ public:
CMyWellNamedClass2() = default;
CMyWellNamedClass2(CMyWellNamedClass2 const&) = default;
CMyWellNamedClass2(CMyWellNamedClass2 &&) = default;
- CMyWellNamedClass2(t_t a_v, void *a_p) : my_class(a_p), my_Bad_Member(a_v) {}
- // CHECK-FIXES: {{^}} CMyWellNamedClass2(t_t a_v, void *a_p) : CMyClass(a_p), __my_Bad_Member(a_v) {}{{$}}
+ CMyWellNamedClass2(t_t a_v, void *p_p) : my_class(p_p), my_Bad_Member(a_v) {}
+ // CHECK-FIXES: {{^}} CMyWellNamedClass2(t_t a_v, void *p_p) : CMyClass(p_p), __my_Bad_Member(a_v) {}{{$}}
CMyWellNamedClass2(t_t a_v) : my_class(), my_Bad_Member(a_v), my_Other_Bad_Member(11) {}
// CHECK-FIXES: {{^}} CMyWellNamedClass2(t_t a_v) : CMyClass(), __my_Bad_Member(a_v), __my_Other_Bad_Member(11) {}{{$}}
@@ -474,3 +486,18 @@ unsigned MY_GLOBAL_array[] = {1,2,3};
unsigned const MyConstGlobal_array[] = {1,2,3};
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global constant 'MyConstGlobal_array'
// CHECK-FIXES: {{^}}unsigned const MY_CONST_GLOBAL_ARRAY[] = {1,2,3};{{$}}
+
+int * MyGlobal_Ptr;// -> ok
+int * const MyConstantGlobalPointer = nullptr;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global constant pointer 'MyConstantGlobalPointer'
+// CHECK-FIXES: {{^}}int * const MY_CONSTANT_GLOBAL_POINTER_Ptr = nullptr;{{$}}
+
+void MyPoiterFunction(int * p_normal_pointer, int * const constant_ptr){
+// CHECK-MESSAGES: :[[@LINE-1]]:59: warning: invalid case style for constant pointer parameter 'constant_ptr'
+// CHECK-FIXES: {{^}}void MyPoiterFunction(int * p_normal_pointer, int * const cp_ConstantPtr){{{$}}
+ int * l_PointerA;
+ int * const pointer_b = nullptr;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for local constant pointer 'pointer_b'
+// CHECK-FIXES: {{^}} int * const lc_PointerB = nullptr;{{$}}
+}
+
More information about the cfe-commits
mailing list