Skip to content

Commit

Permalink
[clang-tidy] add primitive types for hungarian identifier-naming (uns…
Browse files Browse the repository at this point in the history
…igned char and void)

Add `unsigned char` and `void` types to recognized PrimitiveTypes.
Fixes: #60670

Depends on D144037

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D144041
  • Loading branch information
amurzeau authored and PiotrZSL committed Feb 20, 2023
1 parent 38b1a17 commit 37e6a4f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
Expand Up @@ -173,13 +173,15 @@ static StringRef const StyleNames[] = {
m(unsigned-short-int) \
m(unsigned-short) \
m(unsigned-int) \
m(unsigned-char) \
m(unsigned) \
m(long-long-int) \
m(long-double) \
m(long-long) \
m(long-int) \
m(long) \
m(ptrdiff_t) \
m(void) \

static StringRef const HungarainNotationPrimitiveTypes[] = {
#define STRINGIZE(v) #v,
Expand Down Expand Up @@ -751,13 +753,15 @@ void IdentifierNamingCheck::HungarianNotation::loadDefaultConfig(
{"unsigned short int", "usi" },
{"unsigned short", "us" },
{"unsigned int", "ui" },
{"unsigned char", "uc" },
{"unsigned", "u" },
{"long long int", "lli" },
{"long double", "ld" },
{"long long", "ll" },
{"long int", "li" },
{"long", "l" },
{"ptrdiff_t", "p" }};
{"ptrdiff_t", "p" },
{"void", "" }};
// clang-format on
for (const auto &PT : PrimitiveTypes)
HNOption.PrimitiveType.try_emplace(PT.first, PT.second);
Expand Down
Expand Up @@ -200,6 +200,8 @@ CheckOptions:
value: us
- key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-int
value: ui
- key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned-char
value: uc
- key: readability-identifier-naming.HungarianNotation.PrimitiveType.unsigned
value: u
- key: readability-identifier-naming.HungarianNotation.PrimitiveType.long-long-int
Expand All @@ -214,6 +216,8 @@ CheckOptions:
value: l
- key: readability-identifier-naming.HungarianNotation.PrimitiveType.ptrdiff_t
value: p
- key: readability-identifier-naming.HungarianNotation.PrimitiveType.void
value: v
- key: readability-identifier-naming.HungarianNotation.UserDefinedType.BOOL
value: b
- key: readability-identifier-naming.HungarianNotation.UserDefinedType.BOOLEAN
Expand Down
Expand Up @@ -366,15 +366,15 @@ int *DataIntPtr[1] = {0};

void *BufferPtr1;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global pointer 'BufferPtr1' [readability-identifier-naming]
// CHECK-FIXES: {{^}}void *pBufferPtr1;
// CHECK-FIXES: {{^}}void *pvBufferPtr1;

void **BufferPtr2;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global pointer 'BufferPtr2' [readability-identifier-naming]
// CHECK-FIXES: {{^}}void **ppBufferPtr2;
// CHECK-FIXES: {{^}}void **ppvBufferPtr2;

void **pBufferPtr3;
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global pointer 'pBufferPtr3' [readability-identifier-naming]
// CHECK-FIXES: {{^}}void **ppBufferPtr3;
// CHECK-FIXES: {{^}}void **ppvBufferPtr3;

int *pBufferPtr4;
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global pointer 'pBufferPtr4' [readability-identifier-naming]
Expand All @@ -387,7 +387,7 @@ FUNC_PTR_HELLO Hello = NULL;

void *ValueVoidPtr = NULL;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global pointer 'ValueVoidPtr' [readability-identifier-naming]
// CHECK-FIXES: {{^}}void *pValueVoidPtr = NULL;
// CHECK-FIXES: {{^}}void *pvValueVoidPtr = NULL;

ptrdiff_t PtrDiff = NULL;
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'PtrDiff' [readability-identifier-naming]
Expand All @@ -403,7 +403,7 @@ uint8_t *ValueU8Ptr;

void MyFunc2(void* Val){}
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for pointer parameter 'Val' [readability-identifier-naming]
// CHECK-FIXES: {{^}}void MyFunc2(void* pVal){}
// CHECK-FIXES: {{^}}void MyFunc2(void* pvVal){}


//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -567,6 +567,10 @@ unsigned int ValueUnsignedInt = 0;
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'ValueUnsignedInt' [readability-identifier-naming]
// CHECK-FIXES: {{^}}unsigned int uiValueUnsignedInt = 0;

unsigned char ValueUnsignedChar = 0;
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'ValueUnsignedChar' [readability-identifier-naming]
// CHECK-FIXES: {{^}}unsigned char ucValueUnsignedChar = 0;

long int ValueLongInt = 0;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueLongInt' [readability-identifier-naming]
// CHECK-FIXES: {{^}}long int liValueLongInt = 0;
Expand Down
Expand Up @@ -567,6 +567,10 @@ unsigned int ValueUnsignedInt = 0;
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'ValueUnsignedInt' [readability-identifier-naming]
// CHECK-FIXES: {{^}}unsigned int uiValueUnsignedInt = 0;

unsigned char ValueUnsignedChar = 0;
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'ValueUnsignedChar' [readability-identifier-naming]
// CHECK-FIXES: {{^}}unsigned char ucValueUnsignedChar = 0;

long int ValueLongInt = 0;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueLongInt' [readability-identifier-naming]
// CHECK-FIXES: {{^}}long int liValueLongInt = 0;
Expand Down

0 comments on commit 37e6a4f

Please sign in to comment.