[PATCH] clang-tidy checker that enforce proper parentheses in macros

Alexander Kornienko alexfh at google.com
Mon Jun 8 07:13:10 PDT 2015


================
Comment at: include/clang/Lex/Token.h:97
@@ -96,1 +96,3 @@
   bool isNot(tok::TokenKind K) const { return Kind != K; }
+  bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const {
+    return is(K1) || is(K2);
----------------
Thanks! This should go in a separate patch though. And I would appreciate if you updated FormatToken::isOneOf to just redirect to this implementation.

================
Comment at: tools/extra/clang-tidy/misc/MacroParenthesesCheck.cpp:121
@@ +120,3 @@
+    // Only interested in identifiers.
+    if (!Tok.is(tok::identifier) && !Tok.is(tok::raw_identifier))
+      continue;
----------------
!Tok.isOneOf(tok::identifier, tok::raw_identifier)

================
Comment at: tools/extra/clang-tidy/misc/MacroParenthesesCheck.cpp:136
@@ +135,3 @@
+
+    const tok::TokenKind Prev = (TI - 1)->getKind();
+    const tok::TokenKind Next = (TI + 1)->getKind();
----------------
I'd make `Prev` and `Next` instances of `clang::Token` and used `is` and `isOneOf` below and inside all of your is.* methods.

================
Comment at: tools/extra/clang-tidy/misc/MacroParenthesesCheck.h:32
@@ +31,3 @@
+/// properly.
+
+class MacroParenthesesCheck : public ClangTidyCheck {
----------------
Please remove the empty line.

http://reviews.llvm.org/D9528

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list