aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2015-05-17 12:31:12 +0000
committerAlexander Kornienko <alexfh@google.com>2015-05-17 12:31:12 +0000
commitfb3e2cd8ccea054cae31d6576f5b98b97f15f6ac (patch)
treeed0124d819b826dd38b813316cf5d5bcde951534 /clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
parent53958e187a624142498f42d4a67a8e64b65b1c6c (diff)
downloadllvm-fb3e2cd8ccea054cae31d6576f5b98b97f15f6ac.zip
llvm-fb3e2cd8ccea054cae31d6576f5b98b97f15f6ac.tar.gz
llvm-fb3e2cd8ccea054cae31d6576f5b98b97f15f6ac.tar.bz2
[clang-tidy] Enhance clang-tidy readability-simplify-boolean-expr check...
Enhance clang-tidy readability-simplify-boolean-expr check to handle chained conditional assignment and chained conditional return. Based on feedback from applying this tool to the clang/LLVM codebase, this changeset improves the readability-simplify-boolean-expr check so that conditional assignment or return statements at the end of a chain of if/else if statements are left unchanged unless a configuration option is supplied. http://reviews.llvm.org/D8996 Patch by Richard Thomson! llvm-svn: 237541
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h')
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
index 5bb67a4..365d821 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -30,15 +30,25 @@ namespace readability {
/// `e ? false : true` becomes `!e`
/// `if (true) t(); else f();` becomes `t();`
/// `if (false) t(); else f();` becomes `f();`
-/// `if (e) return true; else return false;` becomes `return (e);`
-/// `if (e) return false; else return true;` becomes `return !(e);`
+/// `if (e) return true; else return false;` becomes `return e;`
+/// `if (e) return false; else return true;` becomes `return !e;`
/// `if (e) b = true; else b = false;` becomes `b = e;`
-/// `if (e) b = false; else b = true;` becomes `b = !(e);`
+/// `if (e) b = false; else b = true;` becomes `b = !e;`
+///
+/// Parenthesis from the resulting expression `e` are removed whenever
+/// possible.
+///
+/// When a conditional boolean return or assignment appears at the end of a
+/// chain of `if`, `else if` statements, the conditional statement is left
+/// unchanged unless the option `ChainedConditionalReturn` or
+/// `ChainedConditionalAssignment`, respectively, is specified as non-zero.
+/// The default value for both options is zero.
///
class SimplifyBooleanExprCheck : public ClangTidyCheck {
public:
- SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
+ SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context);
+
+ void storeOptions(ClangTidyOptions::OptionMap &Options) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -92,6 +102,9 @@ private:
void
replaceWithAssignment(const ast_matchers::MatchFinder::MatchResult &Result,
const IfStmt *If, bool Negated = false);
+
+ const bool ChainedConditionalReturn;
+ const bool ChainedConditionalAssignment;
};
} // namespace readability