Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types

2016-07-20 Thread James Reynolds via cfe-commits
JamesReynolds added a comment.

Thank you! Can you land this for me please?

This is me done for the time being, but once our implementation gets into the 
swing of things I'll try and start picking up some bugs / enhancements.


https://reviews.llvm.org/D21472



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20856: [clang-tidy] readability-identifier-naming - Support for Type Aliases

2016-06-01 Thread James Reynolds via cfe-commits
JamesReynolds created this revision.
JamesReynolds added a reviewer: alexfh.
JamesReynolds added a subscriber: cfe-commits.

Added support for Type Alias declarations.

http://reviews.llvm.org/D20856

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,8 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: 
lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: 
UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 
'v_'}, \
+// RUN: {key: readability-identifier-naming.TypeAliasCase, value: 
lower_case}, \
+// RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, 
\
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
 // RUN:   ]}' -- -std=c++11 -fno-delayed-template-parsing \
 // RUN:   -I%S/Inputs/readability-identifier-naming \
@@ -191,8 +193,8 @@
 // CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass<  
CMyClass>, private CMyDerivedClass {};{{$}}
 
 template
-using MYSUPER_TPL = my_other_templated_class  <:: FOO_NS  ::my_class>;
-// CHECK-FIXES: {{^}}using MYSUPER_TPL = CMyOtherTemplatedClass  <:: foo_ns  
::CMyClass>;{{$}}
+using mysuper_tpl_t = my_other_templated_class  <:: FOO_NS  ::my_class>;
+// CHECK-FIXES: {{^}}using mysuper_tpl_t = CMyOtherTemplatedClass  <:: foo_ns  
::CMyClass>;{{$}}
 
 const int global_Constant = 6;
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global 
constant 'global_Constant'
@@ -305,6 +307,15 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 
'struct_type'
 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
 
+using my_struct_type = THIS___Structure;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 
'my_struct_type'
+// CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
+ 
+template
+using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 
'SomeOtherTemplate'
+// CHECK-FIXES: {{^}}using some_other_template_t = CMyOtherTemplatedClass  <:: 
foo_ns  ::CMyClass>;{{$}}
+
 static void static_Function() {
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 
'static_Function'
 // CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -65,6 +65,7 @@
 m(ValueTemplateParameter) \
 m(TemplateTemplateParameter) \
 m(TemplateParameter) \
+m(TypeAlias) \
 
 enum StyleKind {
 #define ENUMERATE(v) SK_ ## v,
@@ -258,6 +259,9 @@
   if (isa(D) && NamingStyles[SK_Typedef].isSet())
 return SK_Typedef;
 
+  if (isa(D) && NamingStyles[SK_TypeAlias].isSet())
+return SK_TypeAlias;
+
   if (const auto *Decl = dyn_cast(D)) {
 if (Decl->isAnonymousNamespace())
   return SK_Invalid;


Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,8 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
 // RUN:   ]}' -- -std=c++11 -fno-delayed-template-parsing \
 // RUN:   -I%S/Inputs/readability-identifier-naming \
@@ -191,8 +193,8 @@
 // CHECK-FIXES: {{^}}class CMyOtherTemplatedClass : CMyTemplatedClass<  CMyClass>, private CMyDerivedClass {};{{$}}
 
 template
-using MYSUPER_TPL = my_other_templated_class  <:: FOO_NS  ::my_class>;
-// CHECK-FIXES: {{^}}using MYSUPER_TPL = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
+using mysuper_tpl_t = my_other_templated_class  <:: FOO_NS  ::my_class>;
+// CHECK-FIXES: {{^}}using mysuper_tpl_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
 
 const int global_Constant = 6;
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'global_Constant'
@@ -305,6 +307,15 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typede

Re: [PATCH] D20856: [clang-tidy] readability-identifier-naming - Support for Type Aliases

2016-06-04 Thread James Reynolds via cfe-commits
JamesReynolds added a comment.

Great, and happy to help. I'm working on another couple that I should hopefully 
complete sometime next week. If you could commit this for me that would be 
great, thank you!


http://reviews.llvm.org/D20856



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-06 Thread James Reynolds via cfe-commits
JamesReynolds created this revision.
JamesReynolds added a reviewer: alexfh.
JamesReynolds added a subscriber: cfe-commits.

Added support for macro definitions.
--

1. Added a pre-processor callback to catch macro definitions
2. Changed the type of the failure map so that macros and declarations can 
share the same map
3. Added extra tests to ensure fix-ups work using the new map
4. Added fix-ups for type aliases in variable and function declarations as part 
of adding the new tests

http://reviews.llvm.org/D21020

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,7 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
 // RUN:   ]}' -- -std=c++11 -fno-delayed-template-parsing \
 // RUN:   -I%S/Inputs/readability-identifier-naming \
@@ -305,6 +306,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
 
+struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
+// CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
+struct_type typedef_test_1;
+// CHECK-FIXES: {{^}}struct_type_t typedef_test_1;
+}
+
 static void static_Function() {
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
 // CHECK-FIXES: {{^}}static void staticFunction() {{{$}}
@@ -318,5 +325,9 @@
 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
 }
 
+#define MY_TEST_Macro(X) X()
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
+// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
+
 }
 }
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -36,6 +36,7 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
   void onEndOfTranslationUnit() override;
 
   enum CaseType {
@@ -64,7 +65,7 @@
 
   /// \brief Holds an identifier name check failure, tracking the kind of the
   /// identifer, its possible fixup and the starting locations of all the
-  /// idenfiier usages.
+  /// identifier usages.
   struct NamingCheckFailure {
 std::string KindName;
 std::string Fixup;
@@ -81,9 +82,17 @@
 
 NamingCheckFailure() : ShouldFix(true) {}
   };
-  typedef llvm::DenseMap
+
+  struct NamingCheckId : std::pair {
+typedef std::pair Parent;
+using Parent::Parent;
+  };
+
+  typedef llvm::DenseMap
   NamingCheckFailureMap;
 
+  void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok);
+
 private:
   std::vector NamingStyles;
   bool IgnoreFailedSplit;
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -12,11 +12,53 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMapInfo.h"
 
 #define DEBUG_TYPE "clang-tidy"
 
 using namespace clang::ast_matchers;
 
+namespace llvm {
+/// Specialisation of DenseMapInfo to allow NamingCheckId objects in DenseMaps
+template <>
+struct DenseMapInfo<
+clang::tidy::readability::IdentifierNamingCheck::NamingCheckId> {
+  using NamingCheckId =
+  clang::tidy::readability::IdentifierNamingCheck::NamingCheckId;
+
+  static inline NamingCheckId getEmptyKey() {
+return NamingCheckId(
+clang::SourceLocation::getFromRawEncoding(static_cast(-1)),
+"EMPTY");
+  }
+
+  static inline NamingCheckId getTombstoneKey() {
+return NamingCheckId(
+clang::SourceLocation::getFromRawEncoding(static_cast(-2)),
+"TOMBSTONE");
+  }
+
+  static unsigned getHashValue(NamingCheckId Val) {
+assert(Va

Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-07 Thread James Reynolds via cfe-commits
JamesReynolds updated this revision to Diff 59857.
JamesReynolds added a comment.

Thanks Eugene, I've added a comment into docs/ReleaseNotes.rst to say this is 
in. I'll create a BugZilla account to update PR.

I've also added a new test and code to create FixIts for uses of the Macros as 
well as the definitions themselves.


http://reviews.llvm.org/D21020

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  docs/ReleaseNotes.rst
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,7 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
@@ -307,6 +308,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
 
+struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
+// CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
+struct_type typedef_test_1;
+// CHECK-FIXES: {{^}}struct_type_t typedef_test_1;
+}
+
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
 // CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
@@ -329,5 +336,11 @@
 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
 }
 
+#define MY_TEST_Macro(X) X()
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
+// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
+
+void MY_TEST_Macro(function) {}
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
 }
 }
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -259,6 +259,11 @@
   Does not only checks for correct signature but also for correct ``return``
   statements (returning ``*this``)
 
+- Updated `readability-identifier-naming-check
+  `_
+
+  Added support for enforcing the case of macro statements.
+
 Fixed bugs:
 
 - Crash when running on compile database with relative source files paths.
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -13,6 +13,9 @@
 #include "../ClangTidy.h"
 
 namespace clang {
+
+class MacroInfo;
+
 namespace tidy {
 namespace readability {
 
@@ -36,6 +39,7 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
   void onEndOfTranslationUnit() override;
 
   enum CaseType {
@@ -64,7 +68,7 @@
 
   /// \brief Holds an identifier name check failure, tracking the kind of the
   /// identifer, its possible fixup and the starting locations of all the
-  /// idenfiier usages.
+  /// identifier usages.
   struct NamingCheckFailure {
 std::string KindName;
 std::string Fixup;
@@ -81,9 +85,22 @@
 
 NamingCheckFailure() : ShouldFix(true) {}
   };
-  typedef llvm::DenseMap
+
+  struct NamingCheckId : std::pair {
+typedef std::pair Parent;
+using Parent::Parent;
+  };
+
+  typedef llvm::DenseMap
   NamingCheckFailureMap;
 
+  /// Check Macros for style violations
+  void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok,
+  const MacroInfo *MI);
+
+  /// Add a usage of a macro if it already has a violation
+  void expandMacro(const Token &MacroNameTok, const MacroInfo *MI);
+
 private:
   std::vector NamingStyles;
   bool IgnoreFailedSplit;
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -12,11 +12,53 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+

Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-08 Thread James Reynolds via cfe-commits
JamesReynolds marked an inline comment as done.
JamesReynolds added a comment.

http://reviews.llvm.org/D21020



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-08 Thread James Reynolds via cfe-commits
JamesReynolds updated this revision to Diff 60010.
JamesReynolds added a comment.

Changed the clang-tidy release notes addition to be in alphabetical order.


http://reviews.llvm.org/D21020

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  docs/ReleaseNotes.rst
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,7 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
@@ -307,6 +308,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
 
+struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
+// CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
+struct_type typedef_test_1;
+// CHECK-FIXES: {{^}}struct_type_t typedef_test_1;
+}
+
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
 // CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
@@ -329,5 +336,11 @@
 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
 }
 
+#define MY_TEST_Macro(X) X()
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
+// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
+
+void MY_TEST_Macro(function) {}
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
 }
 }
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -249,6 +249,11 @@
   Warns about defaulted constructors and assignment operators that are actually
   deleted.
 
+- Updated `readability-identifier-naming-check
+  `_
+
+  Added support for enforcing the case of macro statements.
+
 - New `readability-redundant-control-flow
   `_ check
 
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -13,6 +13,9 @@
 #include "../ClangTidy.h"
 
 namespace clang {
+
+class MacroInfo;
+
 namespace tidy {
 namespace readability {
 
@@ -36,6 +39,7 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
   void onEndOfTranslationUnit() override;
 
   enum CaseType {
@@ -64,7 +68,7 @@
 
   /// \brief Holds an identifier name check failure, tracking the kind of the
   /// identifer, its possible fixup and the starting locations of all the
-  /// idenfiier usages.
+  /// identifier usages.
   struct NamingCheckFailure {
 std::string KindName;
 std::string Fixup;
@@ -81,9 +85,22 @@
 
 NamingCheckFailure() : ShouldFix(true) {}
   };
-  typedef llvm::DenseMap
+
+  struct NamingCheckId : std::pair {
+typedef std::pair Parent;
+using Parent::Parent;
+  };
+
+  typedef llvm::DenseMap
   NamingCheckFailureMap;
 
+  /// Check Macros for style violations
+  void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok,
+  const MacroInfo *MI);
+
+  /// Add a usage of a macro if it already has a violation
+  void expandMacro(const Token &MacroNameTok, const MacroInfo *MI);
+
 private:
   std::vector NamingStyles;
   bool IgnoreFailedSplit;
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -12,11 +12,53 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/

Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-08 Thread James Reynolds via cfe-commits
JamesReynolds added inline comments.


Comment at: clang-tidy/readability/IdentifierNamingCheck.h:89
@@ +88,3 @@
+
+  typedef std::pair NamingCheckId;
+

I think I thought that this wouldn't get picked up by the specialization 
machinery - but you're right, a typedef works out fine! Maybe I was thinking of 
overloads...


http://reviews.llvm.org/D21020



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-08 Thread James Reynolds via cfe-commits
JamesReynolds marked an inline comment as done.
JamesReynolds added a comment.

http://reviews.llvm.org/D21020



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-08 Thread James Reynolds via cfe-commits
JamesReynolds marked an inline comment as done.
JamesReynolds added a comment.

http://reviews.llvm.org/D21020



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-08 Thread James Reynolds via cfe-commits
JamesReynolds updated this revision to Diff 60056.
JamesReynolds marked 5 inline comments as done.
JamesReynolds added a comment.

Applied suggested code changes.


http://reviews.llvm.org/D21020

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  docs/ReleaseNotes.rst
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,7 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
@@ -307,6 +308,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
 
+struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
+// CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
+struct_type typedef_test_1;
+// CHECK-FIXES: {{^}}struct_type_t typedef_test_1;
+}
+
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
 // CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
@@ -329,5 +336,11 @@
 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
 }
 
+#define MY_TEST_Macro(X) X()
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
+// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
+
+void MY_TEST_Macro(function) {}
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
 }
 }
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -249,6 +249,11 @@
   Warns about defaulted constructors and assignment operators that are actually
   deleted.
 
+- Updated `readability-identifier-naming-check
+  `_
+
+  Added support for enforcing the case of macro statements.
+
 - New `readability-redundant-control-flow
   `_ check
 
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -13,6 +13,9 @@
 #include "../ClangTidy.h"
 
 namespace clang {
+
+class MacroInfo;
+
 namespace tidy {
 namespace readability {
 
@@ -36,6 +39,7 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
   void onEndOfTranslationUnit() override;
 
   enum CaseType {
@@ -64,7 +68,7 @@
 
   /// \brief Holds an identifier name check failure, tracking the kind of the
   /// identifer, its possible fixup and the starting locations of all the
-  /// idenfiier usages.
+  /// identifier usages.
   struct NamingCheckFailure {
 std::string KindName;
 std::string Fixup;
@@ -81,9 +85,19 @@
 
 NamingCheckFailure() : ShouldFix(true) {}
   };
-  typedef llvm::DenseMap
+
+  typedef std::pair NamingCheckId;
+
+  typedef llvm::DenseMap
   NamingCheckFailureMap;
 
+  /// Check Macros for style violations
+  void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok,
+  const MacroInfo *MI);
+
+  /// Add a usage of a macro if it already has a violation
+  void expandMacro(const Token &MacroNameTok, const MacroInfo *MI);
+
 private:
   std::vector NamingStyles;
   bool IgnoreFailedSplit;
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -12,11 +12,53 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMapInfo.h"
 
 #define DEBUG_TYPE "clang-tidy"
 
 using n

Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-08 Thread James Reynolds via cfe-commits
JamesReynolds updated this revision to Diff 60058.
JamesReynolds marked an inline comment as not done.
JamesReynolds added a comment.

Missed one modification in last update.


http://reviews.llvm.org/D21020

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  docs/ReleaseNotes.rst
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,7 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
@@ -307,6 +308,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
 
+struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
+// CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
+struct_type typedef_test_1;
+// CHECK-FIXES: {{^}}struct_type_t typedef_test_1;
+}
+
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
 // CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
@@ -329,5 +336,11 @@
 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
 }
 
+#define MY_TEST_Macro(X) X()
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
+// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
+
+void MY_TEST_Macro(function) {}
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
 }
 }
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -249,6 +249,11 @@
   Warns about defaulted constructors and assignment operators that are actually
   deleted.
 
+- Updated `readability-identifier-naming-check
+  `_
+
+  Added support for enforcing the case of macro statements.
+
 - New `readability-redundant-control-flow
   `_ check
 
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -13,6 +13,9 @@
 #include "../ClangTidy.h"
 
 namespace clang {
+
+class MacroInfo;
+
 namespace tidy {
 namespace readability {
 
@@ -36,6 +39,7 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
   void onEndOfTranslationUnit() override;
 
   enum CaseType {
@@ -64,7 +68,7 @@
 
   /// \brief Holds an identifier name check failure, tracking the kind of the
   /// identifer, its possible fixup and the starting locations of all the
-  /// idenfiier usages.
+  /// identifier usages.
   struct NamingCheckFailure {
 std::string KindName;
 std::string Fixup;
@@ -81,9 +85,19 @@
 
 NamingCheckFailure() : ShouldFix(true) {}
   };
-  typedef llvm::DenseMap
+
+  typedef std::pair NamingCheckId;
+
+  typedef llvm::DenseMap
   NamingCheckFailureMap;
 
+  /// Check Macros for style violations
+  void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok,
+  const MacroInfo *MI);
+
+  /// Add a usage of a macro if it already has a violation
+  void expandMacro(const Token &MacroNameTok, const MacroInfo *MI);
+
 private:
   std::vector NamingStyles;
   bool IgnoreFailedSplit;
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -12,11 +12,53 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMapInfo.h"
 
 #define DEBUG_TYPE "clang-tidy

Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-17 Thread James Reynolds via cfe-commits
JamesReynolds updated this revision to Diff 61071.
JamesReynolds added a comment.

Fixed nits.


http://reviews.llvm.org/D21020

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  docs/ReleaseNotes.rst
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -61,6 +61,7 @@
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
+// RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
 // RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
@@ -307,6 +308,12 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for typedef 'struct_type'
 // CHECK-FIXES: {{^}}typedef this_structure struct_type_t;{{$}}
 
+struct_type GlobalTypedefTestFunction(struct_type a_argument1) {
+// CHECK-FIXES: {{^}}struct_type_t GlobalTypedefTestFunction(struct_type_t a_argument1) {
+struct_type typedef_test_1;
+// CHECK-FIXES: {{^}}struct_type_t typedef_test_1;
+}
+
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
 // CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
@@ -329,5 +336,11 @@
 // CHECK-FIXES: {{^}}  using ::foo_ns::inline_namespace::ce_function;{{$}}
 }
 
+#define MY_TEST_Macro(X) X()
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'MY_TEST_Macro'
+// CHECK-FIXES: {{^}}#define MY_TEST_MACRO(X) X()
+
+void MY_TEST_Macro(function) {}
+// CHECK-FIXES: {{^}}void MY_TEST_MACRO(function) {}
 }
 }
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -249,6 +249,11 @@
   Warns about defaulted constructors and assignment operators that are actually
   deleted.
 
+- Updated `readability-identifier-naming-check
+  `_
+
+  Added support for enforcing the case of macro statements.
+
 - New `readability-redundant-control-flow
   `_ check
 
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -13,6 +13,9 @@
 #include "../ClangTidy.h"
 
 namespace clang {
+
+class MacroInfo;
+
 namespace tidy {
 namespace readability {
 
@@ -36,6 +39,7 @@
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
   void onEndOfTranslationUnit() override;
 
   enum CaseType {
@@ -64,7 +68,7 @@
 
   /// \brief Holds an identifier name check failure, tracking the kind of the
   /// identifer, its possible fixup and the starting locations of all the
-  /// idenfiier usages.
+  /// identifier usages.
   struct NamingCheckFailure {
 std::string KindName;
 std::string Fixup;
@@ -81,9 +85,19 @@
 
 NamingCheckFailure() : ShouldFix(true) {}
   };
-  typedef llvm::DenseMap
+
+  typedef std::pair NamingCheckId;
+
+  typedef llvm::DenseMap
   NamingCheckFailureMap;
 
+  /// Check Macros for style violations.
+  void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok,
+  const MacroInfo *MI);
+
+  /// Add a usage of a macro if it already has a violation.
+  void expandMacro(const Token &MacroNameTok, const MacroInfo *MI);
+
 private:
   std::vector NamingStyles;
   bool IgnoreFailedSplit;
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -12,11 +12,53 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMapInfo.h"
 
 #define DEBUG_TYPE "clang-tidy"
 
 using namespace clang::ast_matchers;
 
+namespace llvm {
+/// Specialisat

Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-17 Thread James Reynolds via cfe-commits
JamesReynolds marked 2 inline comments as done.


Comment at: clang-tidy/readability/IdentifierNamingCheck.h:98
@@ +97,3 @@
+
+  /// Add a usage of a macro if it already has a violation.
+  void expandMacro(const Token &MacroNameTok, const MacroInfo *MI);

Fixed this one too.


http://reviews.llvm.org/D21020



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21020: [clang-tidy] readability-identifier-naming - Support for Macros

2016-06-17 Thread James Reynolds via cfe-commits
JamesReynolds marked an inline comment as done.
JamesReynolds added a comment.

Thanks! All fixed now. Could you land this for me please?


http://reviews.llvm.org/D21020



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types

2016-06-17 Thread James Reynolds via cfe-commits
JamesReynolds created this revision.
JamesReynolds added a reviewer: alexfh.
JamesReynolds added a subscriber: cfe-commits.

Added Stroustrup_Case and stroustrup_Back 
(http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-naming)

```
class Stroustrup_Case_Class_Name
{
  void private_Stroustrup_Back_Method_Name();
}
```

http://reviews.llvm.org/D21472

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -59,10 +59,10 @@
 // RUN: {key: readability-identifier-naming.UsingCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.ValueTemplateParameterCase, value: camelBack}, \
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
-// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: Stroustrup_Case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
 // RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
-// RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
+// RUN: {key: readability-identifier-naming.TypeAliasCase, value: stroustrup_Back}, \
 // RUN: {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN: {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
 // RUN:   ]}' -- -std=c++11 -fno-delayed-template-parsing \
@@ -261,7 +261,7 @@
 // CHECK-FIXES: {{^}}virtual ~AAbstractClass() = 0;{{$}}
 virtual void VIRTUAL_METHOD();
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
-// CHECK-FIXES: {{^}}virtual void v_VIRTUAL_METHOD();{{$}}
+// CHECK-FIXES: {{^}}virtual void v_Virtual_Method();{{$}}
 void non_Virtual_METHOD() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD'
 // CHECK-FIXES: {{^}}void __non_Virtual_METHOD() {}{{$}}
@@ -316,12 +316,12 @@
 
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
-// CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
+// CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
 
 template
 using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate'
-// CHECK-FIXES: {{^}}using some_other_template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
+// CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
 
 static void static_Function() {
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -48,6 +48,8 @@
 CT_CamelBack,
 CT_UpperCase,
 CT_CamelCase,
+CT_StroustrupCase,
+CT_StroustrupBack
   };
 
   struct NamingStyle {
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -163,6 +163,8 @@
 .Case("UPPER_CASE", CT_UpperCase)
 .Case("camelBack", CT_CamelBack)
 .Case("CamelCase", CT_CamelCase)
+.Case("Stroustrup_Case", CT_StroustrupCase)
+.Case("stroustrup_Back", CT_StroustrupBack)
 .Default(CT_AnyCase);
   };
 
@@ -189,6 +191,10 @@
   return "UPPER_CASE";
 case CT_CamelCase:
   return "CamelCase";
+case CT_StroustrupCase:
+  return "Stroustrup_Case";
+case CT_StroustrupBack:
+  return "stroustrup_Back";
 }
 
 llvm_unreachable("Unknown Case Type");
@@ -230,6 +236,8 @@
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
+  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
   };
 
   bool Matches = true;
@@ -319,6 +327,27 @@
   }
 }
 break;
+
+  case IdentifierNamingCheck::CT_StroustrupCase:
+for (auto const &Word : Words) {
+  if (&Word != &Words.front())
+Fixup += "_";
+  Fixup += Word.substr(0, 1).upper();
+  Fixup += Word.substr(1).lower();
+}
+break;
+
+  case IdentifierNamingCheck::CT_StroustrupBack:
+f

Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types

2016-06-17 Thread James Reynolds via cfe-commits
JamesReynolds added a comment.

I'm not 100% sure that my regexes are the best balance between readability and 
terseness - or that I've named the case types particularly well. If there are 
better ideas for either of those things I'm very happy to accept criticism!


http://reviews.llvm.org/D21472



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types

2016-07-04 Thread James Reynolds via cfe-commits
JamesReynolds added a comment.

Ah, I took this from a single example in the CPP core guidelines - that PDF is 
indeed a very different style. An idea we toyed with was "UpperSeparated" and 
"UpperSeparatedBack"? Would that work?

This comes from a concession to Window  developers in a large commercial 
codebase with a Windows origin. I'll admit it isn't my favourite style but for 
class names and functions it eventually grows on you. At least I got them to 
let go of the SHOUTING_TYPEDEFS..!


http://reviews.llvm.org/D21472



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21472: [clang-tidy] readability-identifier-naming - support for other case types

2016-07-11 Thread James Reynolds via cfe-commits
JamesReynolds updated the summary for this revision.
JamesReynolds updated this revision to Diff 63462.
JamesReynolds added a comment.

> You mean Upper_Separated and upper_Separated_Back? ;) Actually, these names 
> are not particularly clear. I've managed to find "Camel_Snake_Case"

>  used for exactly this naming convention (in the 
> https://github.com/t6/camel_snake_kebab library). Maybe "camel_Snake_Back" as 
> well?


Thank you, a very good find! I've changed the patch accordingly.


http://reviews.llvm.org/D21472

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -59,10 +59,10 @@
 // RUN: {key: readability-identifier-naming.UsingCase, value: lower_case}, \
 // RUN: {key: readability-identifier-naming.ValueTemplateParameterCase, value: camelBack}, \
 // RUN: {key: readability-identifier-naming.VariableCase, value: lower_case}, \
-// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
+// RUN: {key: readability-identifier-naming.VirtualMethodCase, value: Camel_Snake_Case}, \
 // RUN: {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
 // RUN: {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
-// RUN: {key: readability-identifier-naming.TypeAliasCase, value: lower_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:   ]}' -- -std=c++11 -fno-delayed-template-parsing \
@@ -261,7 +261,7 @@
 // CHECK-FIXES: {{^}}virtual ~AAbstractClass() = 0;{{$}}
 virtual void VIRTUAL_METHOD();
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
-// CHECK-FIXES: {{^}}virtual void v_VIRTUAL_METHOD();{{$}}
+// CHECK-FIXES: {{^}}virtual void v_Virtual_Method();{{$}}
 void non_Virtual_METHOD() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD'
 // CHECK-FIXES: {{^}}void __non_Virtual_METHOD() {}{{$}}
@@ -316,12 +316,12 @@
 
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
-// CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
+// CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
 
 template
 using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate'
-// CHECK-FIXES: {{^}}using some_other_template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
+// CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
 
 static void static_Function() {
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
Index: clang-tidy/readability/IdentifierNamingCheck.h
===
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -48,6 +48,8 @@
 CT_CamelBack,
 CT_UpperCase,
 CT_CamelCase,
+CT_CamelSnakeCase,
+CT_CamelSnakeBack
   };
 
   struct NamingStyle {
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -163,6 +163,8 @@
 .Case("UPPER_CASE", CT_UpperCase)
 .Case("camelBack", CT_CamelBack)
 .Case("CamelCase", CT_CamelCase)
+.Case("Camel_Snake_Case", CT_CamelSnakeCase)
+.Case("camel_Snake_Back", CT_CamelSnakeBack)
 .Default(CT_AnyCase);
   };
 
@@ -189,6 +191,10 @@
   return "UPPER_CASE";
 case CT_CamelCase:
   return "CamelCase";
+case CT_CamelSnakeCase:
+  return "Camel_Snake_Case";
+case CT_CamelSnakeBack:
+  return "camel_Snake_Back";
 }
 
 llvm_unreachable("Unknown Case Type");
@@ -230,6 +236,8 @@
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
+  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
   };
 
   bool Matches = true;
@@ -319,6 +327,27 @@
   }
 }
 break;
+
+  case IdentifierNamingCheck::CT_CamelSnakeCase:
+for (auto const &Word : Words) {
+  if (&Word != &Words.front())
+Fixu