dougpuob updated this revision to Diff 290099.
dougpuob added a comment.

Improved suggestions of code review. (All suggestions from aaron.ballman)

1. Changed variables named with `Decl` to `InputDecl`.
2. Changed `TypeName.length()` --> `!TypeName.empty()`.
3. Added partial Microsft data types to the `HungarianNotationTable`.
4. Added `long long`, `long double`, `ptrdiff_t` to the 
`HungarianNotationTable`.
5. Added `char8_t`, `char16_t`, `char32_t` to the `HungarianNotationTable`. 
Variables name with `char8_t*` type start with `pc8`, Eg. `char8_t *pc8Value = 
0;`
6. Supported name of function pointer start with `fn`.
7. Supported to remove the `restrict` keyword in 
IdentifierNamingCheck::getDeclTypeName().
8. Removed `const_cast` from Keywords list.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86671/new/

https://reviews.llvm.org/D86671

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-hungarian-notation.cpp
@@ -1,120 +1,266 @@
-#include <stddef.h>
-#include <stdint.h>
+typedef signed char         int8_t;     // NOLINT
+typedef short               int16_t;    // NOLINT
+typedef long                int32_t;    // NOLINT
+typedef long long           int64_t;    // NOLINT
+
+typedef unsigned char       uint8_t;    // NOLINT
+typedef unsigned short      uint16_t;   // NOLINT
+typedef unsigned long       uint32_t;   // NOLINT
+typedef unsigned long long  uint64_t;   // NOLINT
+
+typedef unsigned int        size_t;     // NOLINT
+typedef long                intptr_t;   // NOLINT
+typedef unsigned long       uintptr_t;  // NOLINT
+typedef long int            ptrdiff_t;  // NOLINT
+
+typedef unsigned char       BYTE;       // NOLINT
+typedef unsigned short      WORD;       // NOLINT
+typedef unsigned long       DWORD;      // NOLINT
+
+typedef int                 BOOL;       // NOLINT
+typedef BYTE                BOOLEAN;    // NOLINT
+
+#define NULL                (0)         // NOLINT
 
 // RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
 // RUN:   -config="{CheckOptions: [\
-// RUN:   {key: readability-identifier-naming.VariableCase, value: szHungarianNotation}, \
+// RUN:     {key: readability-identifier-naming.FunctionCase       , value: CamelCase },           \
+// RUN:     {key: readability-identifier-naming.ClassCase          , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.TypedefCase        , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.MemberCase         , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.ClassMemberCase    , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.ConstantMemberCase , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.VariableCase       , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.ParameterCase      , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.GlobalPointerCase  , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.GlobalVariableCase , value: szHungarianNotation }, \
+// RUN:     {key: readability-identifier-naming.GlobalFunctionCase , value: CamelCase }, \
 // RUN:   ]}"
 
-class UnlistedClass {};
-UnlistedClass Unlisted1;
-// CHECK-NOT: :[[@LINE-2]]
+class UnlistedClass { public: mutable int ValInt; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: invalid case style for member 'ValInt' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}class UnlistedClass { public: mutable int iValInt; };
 
 UnlistedClass cUnlisted2;
-// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for variable 'cUnlisted2' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'cUnlisted2' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}UnlistedClass Unlisted2;
 
 UnlistedClass objUnlistedClass3;
-// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for variable 'objUnlistedClass3' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: invalid case style for global variable 'objUnlistedClass3' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}UnlistedClass UnlistedClass3;
 
 typedef int INDEX;
 INDEX iIndex = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for variable 'iIndex' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'iIndex' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}INDEX Index = 0;
 
+struct DataBuffer {
+    mutable size_t Size;
+};
+// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: invalid case style for member 'Size' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}    mutable size_t nSize;
+
+int &RefValueIndex = iIndex;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'RefValueIndex' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int &iRefValueIndex = Index;
+
+typedef void (*FUNC_PTR_HELLO)();
+FUNC_PTR_HELLO Hello = NULL;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for global pointer 'Hello' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}FUNC_PTR_HELLO fnHello = 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;
+
+ptrdiff_t PtrDiff = NULL;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'PtrDiff' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}ptrdiff_t pPtrDiff = NULL;
+
 const char *NamePtr = "Name";
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for variable 'NamePtr' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global pointer 'NamePtr' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}const char *szNamePtr = "Name";
 
 const char NameArray[] = "Name";
-// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for variable 'NameArray' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'NameArray' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}const char szNameArray[] = "Name";
 
-void *BufferPtr1 = NULL;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for variable 'BufferPtr1' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}void *pBufferPtr1 = NULL;
+const char *NamePtrArray[] = {"AA", "BB"};
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'NamePtrArray' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}const char *pszNamePtrArray[] = {"AA", "BB"};
+
+int DataInt[1] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'DataInt' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int aDataInt[1] = {0};
+
+int *DataIntPtr[1] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'DataIntPtr' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int *paDataIntPtr[1] = {0};
+
+void *BufferPtr1;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global pointer 'BufferPtr1' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}void *pBufferPtr1;
+
+void **BufferPtr2;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global pointer 'BufferPtr2' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}void **ppBufferPtr2;
+
+void **pBufferPtr3;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global pointer 'pBufferPtr3' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}void **ppBufferPtr3;
+
+int *pBufferPtr4;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global pointer 'pBufferPtr4' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int *piBufferPtr4;
+
+int DataArray[2] = {0};
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'DataArray' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int aDataArray[2] = {0};
 
-void **BufferPtr2 = NULL;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for variable 'BufferPtr2' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}void **ppBufferPtr2 = NULL;
+int8_t *ValueI8Ptr;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global pointer 'ValueI8Ptr' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int8_t *pi8ValueI8Ptr;
 
-void **pBufferPtr3 = NULL;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for variable 'pBufferPtr3' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}void **ppBufferPtr3 = NULL;
+uint8_t *ValueU8Ptr;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global pointer 'ValueU8Ptr' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}uint8_t *pu8ValueU8Ptr;
 
-int8_t ValueI8 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for variable 'ValueI8' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}int8_t i8ValueI8 = 0;
+int8_t ValueI8;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueI8' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int8_t i8ValueI8;
 
 int16_t ValueI16 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for variable 'ValueI16' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI16' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}int16_t i16ValueI16 = 0;
 
 int32_t ValueI32 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for variable 'ValueI32' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI32' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}int32_t i32ValueI32 = 0;
 
 int64_t ValueI64 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for variable 'ValueI64' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueI64' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}int64_t i64ValueI64 = 0;
 
 uint8_t ValueU8 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for variable 'ValueU8' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueU8' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}uint8_t u8ValueU8 = 0;
 
 uint16_t ValueU16 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for variable 'ValueU16' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU16' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}uint16_t u16ValueU16 = 0;
 
 uint32_t ValueU32 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for variable 'ValueU32' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU32' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}uint32_t u32ValueU32 = 0;
 
 uint64_t ValueU64 = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for variable 'ValueU64' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueU64' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}uint64_t u64ValueU64 = 0;
 
 float ValueFloat = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for variable 'ValueFloat' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'ValueFloat' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}float fValueFloat = 0;
 
 double ValueDouble = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for variable 'ValueDouble' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueDouble' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}double dValueDouble = 0;
 
 char ValueChar = 'c';
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for variable 'ValueChar' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'ValueChar' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}char cValueChar = 'c';
 
 bool ValueBool = true;
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for variable 'ValueBool' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'ValueBool' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}bool bValueBool = true;
 
 int ValueInt = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for variable 'ValueInt' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'ValueInt' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}int iValueInt = 0;
 
+int &RefValueInt = ValueInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'RefValueInt' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}int &iRefValueInt = iValueInt;
+
 size_t ValueSize = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for variable 'ValueSize' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueSize' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}size_t nValueSize = 0;
 
 wchar_t ValueWchar = 'w';
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for variable 'ValueWchar' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'ValueWchar' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}wchar_t wcValueWchar = 'w';
 
 short ValueShort = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for variable 'ValueShort' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'ValueShort' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}short sValueShort = 0;
 
 unsigned ValueUnsigned = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for variable 'ValueUnsigned' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for global variable 'ValueUnsigned' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}unsigned uValueUnsigned = 0;
 
 signed ValueSigned = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for variable 'ValueSigned' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for global variable 'ValueSigned' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}signed iValueSigned = 0;
 
 long ValueLong = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for variable 'ValueLong' [readability-identifier-naming]
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'ValueLong' [readability-identifier-naming]
 // CHECK-FIXES: {{^}}long lValueLong = 0;
+
+long long ValueLongLong = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global variable 'ValueLongLong' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}long long llValueLongLong = 0;
+
+long long &RefValueLongLong = ValueLongLong;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'RefValueLongLong' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}long long &llRefValueLongLong = llValueLongLong;
+
+long double ValueLongDouble = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for global variable 'ValueLongDouble' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}long double ldValueLongDouble = 0;
+
+volatile int VolatileInt = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for global variable 'VolatileInt' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}volatile int iVolatileInt = 0;
+
+const int &ConstRefValue = ValueInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ConstRefValue' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}const int &iConstRefValue = iValueInt;
+
+thread_local int ThreadLocalValueInt = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for global variable 'ThreadLocalValueInt' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}thread_local int iThreadLocalValueInt = 0;
+
+extern int ExternValueInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global variable 'ExternValueInt' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}extern int iExternValueInt;
+
+void MyFunc1(int Val){}
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'Val' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}void MyFunc1(int iVal){}
+
+void MyFunc2(void* Val){}
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for parameter 'Val' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}void MyFunc2(void* pVal){}
+
+static constexpr int const &ConstExprInt = 42;
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: invalid case style for global variable 'ConstExprInt' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}static constexpr int const &iConstExprInt = 42;
+
+DWORD MsDword = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for global variable 'MsDword' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}DWORD dwMsDword = 0;
+
+BYTE MsByte = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsByte' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}BYTE byMsByte = 0;
+
+WORD MsWord = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsWord' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}WORD wMsWord = 0;
+
+BOOL MsBool = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global variable 'MsBool' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}BOOL bMsBool = 0;
+
+BOOLEAN MsBoolean = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for global variable 'MsBoolean' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}BOOLEAN bMsBoolean = 0;
Index: clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -31,6 +31,67 @@
 but not where they are overridden, as it can't be fixed locally there.
 This also applies for pseudo-override patterns like CRTP.
 
+Hungarian Notation casing type
+------------------------------
+
+In Hungarian notation, a variable name starts with a group of lower-case 
+letters which are mnemonics for the type or purpose of that variable, followed
+by whatever name the programmer has chosen; this last part is sometimes 
+distinguished as the given name. The first character of the given name can be 
+capitalized to separate it from the type indicators (see also CamelCase). 
+Otherwise the case of this character denotes scope.
+
+============ ============= ================ ============= =========== ==============
+Primitive Types                                           Microsoft data types
+--------------------------------------------------------- --------------------------
+    Type        Prefix          Type           Prefix        Type        Prefix
+============ ============= ================ ============= =========== ==============
+int8_t       i8            short            s             BOOL        b         
+int16_t      i16           signed           i             BOOLEAN     b         
+int32_t      i32           unsigned         u             BYTE        by        
+int64_t      i64           long             l             WORD        w         
+uint8_t      u8            long long        ll            DWORD       dw        
+uint16_t     u16           unsigned long    ul                                  
+uint32_t     u32           long double      ld                                  
+uint64_t     u64           ptrdiff_t        p                                   
+char8_t      c8                                                                 
+char16_t     c16                                                                
+char32_t     c32                                                                
+float        f                                                                  
+double       d                                                                  
+char         c                                                                  
+bool         b                                                                  
+_Bool        b                                                                  
+int          i                                                                  
+size_t       n                                                                  
+============ ============= ================ ============= =========== ==============
+
+
+
+- **Pointer type starts with `p`,**
+
+  .. code-block:: c++
+
+     void    *pData   = NULL;
+     void   **ppData  = NULL;
+     uint8_t *pu8Data = NULL;
+
+- **Array type start with `a`,**
+
+  .. code-block:: c++
+
+    int    aDataInt[1]     = {0};
+    int*   paDataIntPtr[1] = {0};
+
+- **Null terminated string starts with `sz`**
+
+  .. code-block:: c++
+
+    char   szNameArray[] = {"Text"};
+    char  *szNamePtr     = {"Text"};
+    char **pszNamePtr    = {"Text"};
+ 
+
 Options
 -------
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -182,13 +182,14 @@
 
 static const std::string
 getHungarianNotationTypePrefix(const std::string &TypeName,
-                               const NamedDecl *Decl) {
-  if (0 == TypeName.length()) {
+                               const NamedDecl *InputDecl) {
+  if (!InputDecl || TypeName.empty()) {
     return TypeName;
   }
 
   // clang-format off
   const static llvm::StringMap<StringRef> HungarianNotationTable = {
+        // Primitive types
         {"int8_t",          "i8"},
         {"int16_t",         "i16"},
         {"int32_t",         "i32"},
@@ -197,6 +198,9 @@
         {"uint16_t",        "u16"},
         {"uint32_t",        "u32"},
         {"uint64_t",        "u64"},
+        {"char8_t",         "c8"},
+        {"char16_t",        "c16"},
+        {"char32_t",        "c32"},
         {"float",           "f"},
         {"double",          "d"},
         {"char",            "c"},
@@ -208,16 +212,28 @@
         {"short",           "s"},
         {"signed",          "i"},
         {"unsigned",        "u"},
-        {"long",            "l"}};
+        {"long",            "l"},
+        {"long long",       "ll"},
+        {"unsigned long",   "ul"},
+        {"long double",     "ld"},
+        {"ptrdiff_t",       "p"},
+        // Windows data types
+        {"BOOL",            "b"},
+        {"BOOLEAN",         "b"},
+        {"BYTE",            "by"},
+        {"WORD",            "w"},
+        {"DWORD",           "dw"}};
   // clang-format on
 
   std::string ClonedTypeName = TypeName;
 
   // Handle null string
   std::string PrefixStr;
-  if (const auto *TD = dyn_cast<ValueDecl>(Decl)) {
+  if (const auto *TD = dyn_cast<ValueDecl>(InputDecl)) {
     auto QT = TD->getType();
-    if (QT->isPointerType()) {
+    if (QT->isFunctionPointerType()) {
+      PrefixStr = "fn"; // Function Pointer
+    } else if (QT->isPointerType()) {
       // clang-format off
       const static llvm::StringMap<StringRef> NullString = {
         {"char*",     "sz"},
@@ -247,6 +263,14 @@
           break;
         }
       }
+      if (PrefixStr.empty()) {
+        PrefixStr = 'a'; // Array
+      }
+    } else if (QT->isReferenceType()) {
+      size_t Pos = ClonedTypeName.find_last_of("&");
+      if (Pos != std::string::npos) {
+        ClonedTypeName = ClonedTypeName.substr(0, Pos);
+      }
     }
   }
 
@@ -272,11 +296,13 @@
     }(ClonedTypeName, "*", "");
   }
 
-  for (const auto &Type : HungarianNotationTable) {
-    const auto &Key = Type.getKey();
-    if (ClonedTypeName == Key) {
-      PrefixStr = Type.getValue().str();
-      break;
+  if (PrefixStr.empty()) {
+    for (const auto &Type : HungarianNotationTable) {
+      const auto &Key = Type.getKey();
+      if (ClonedTypeName == Key) {
+        PrefixStr = Type.getValue().str();
+        break;
+      }
     }
   }
 
@@ -306,15 +332,15 @@
     std::string Type(Begin, StrLen);
 
     const static std::list<std::string> Keywords = {
+        // Constexpr specifiers
+        "constexpr", "constinit", "consteval",
         // Qualifier
-        "const", "volatile",
+        "const", "volatile", "restrict", "mutable",
         // Storage class specifiers
-        "auto", "register", "static", "extern", "thread_local",
-        // Constexpr specifiers
-        "constexpr", "constinit", "const_cast", "consteval"};
+        "auto", "register", "static", "extern", "thread_local"};
 
     // Remove keywords
-    for (const auto &Kw : Keywords) {
+    for (const std::string &Kw : Keywords) {
       for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;) {
         Type.replace(Pos, Kw.length(), "");
       }
@@ -332,6 +358,12 @@
       Type.replace(Pos, strlen(" *"), "*");
     }
 
+    // Replace " &" with "&"
+    for (size_t Pos = 0; (Pos = Type.find(" &", Pos)) != std::string::npos;
+         Pos += strlen("&")) {
+      Type.replace(Pos, strlen(" &"), "&");
+    }
+
     Type = Type.erase(Type.find_last_not_of(" ") + 1);
     Type = Type.erase(0, Type.find_first_not_of(" "));
     TypeName = Type;
@@ -381,7 +413,7 @@
 }
 
 static std::string fixupWithCase(const StringRef &Type, const StringRef &Name,
-                                 const Decl *pDecl,
+                                 const Decl *InputDecl,
                                  IdentifierNamingCheck::CaseType Case) {
   static llvm::Regex Splitter(
       "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
@@ -475,14 +507,14 @@
     break;
 
   case IdentifierNamingCheck::CT_HungarianNotation: {
-    const NamedDecl *pNamedDecl = dyn_cast<NamedDecl>(pDecl);
+    const NamedDecl *pNamedDecl = dyn_cast<NamedDecl>(InputDecl);
     const std::string TypePrefix =
         getHungarianNotationTypePrefix(Type.str(), pNamedDecl);
     Fixup = TypePrefix;
     for (size_t Idx = 0; Idx < Words.size(); Idx++) {
-      // Skip first part if it's a lowercase string
+      // Skip first part if it's a lowercase string.
       if (Idx == 0) {
-        const bool LowerAlnum =
+        bool LowerAlnum =
             std::all_of(Words[Idx].begin(), Words[Idx].end(),
                         [](const char c) { return isdigit(c) || islower(c); });
         if (LowerAlnum)
@@ -560,9 +592,9 @@
 static std::string
 fixupWithStyle(const StringRef &Type, const StringRef &Name,
                const IdentifierNamingCheck::NamingStyle &Style,
-               const Decl *Decl) {
+               const Decl *InputDecl) {
   const std::string Fixed = fixupWithCase(
-      Type, Name, Decl,
+      Type, Name, InputDecl,
       Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase));
   StringRef Mid = StringRef(Fixed).trim("_");
   if (Mid.empty())
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to