xaizek / for-postfix (License: GPLv2+) (since 2018-12-07)
Clang-based standalone tool that detects for-loops with postfix operators.
Commit 5204d56b9f0c584364d4fec343960e04f718d34f

Match both increment and decrement operators
Author: xaizek
Author date (UTC): 2014-03-23 22:05
Committer name: xaizek
Committer date (UTC): 2014-03-23 22:07
Parent(s): 26acb3f484a316312494712f7bb7b38f927c27b4
Signing key:
Tree: 9364dff1ec9e24879864f7bfb1e6603a05df388b
File Lines added Lines deleted
for-postfix.cpp 4 4
File for-postfix.cpp changed (mode: 100644) (index 36d62e6..0681922)
... ... static llvm::cl::OptionCategory toolCategory("for-postfix options");
14 14
15 15 static llvm::cl::extrahelp commonHelp(CommonOptionsParser::HelpMessage); static llvm::cl::extrahelp commonHelp(CommonOptionsParser::HelpMessage);
16 16
17 static StatementMatcher incMatcher =
17 static StatementMatcher builtinMatcher =
18 18 forStmt( // for ([init]; [condition]; [increment]) forStmt( // for ([init]; [condition]; [increment])
19 19 hasIncrement( // "increment" part of for-loop hasIncrement( // "increment" part of for-loop
20 20 unaryOperator( // any unary op, e.g. *, &, -- unaryOperator( // any unary op, e.g. *, &, --
21 hasOperatorName("++") // exact unary op: ++
21
22 22 ).bind("op") // bind matched unary op to "op" name ).bind("op") // bind matched unary op to "op" name
23 23 ) )
24 24 ); );
 
... ... public:
33 33 typedef UnaryOperator UnOp; typedef UnaryOperator UnOp;
34 34
35 35 if (const UnOp *op = result.Nodes.getNodeAs<UnOp>("op")) { if (const UnOp *op = result.Nodes.getNodeAs<UnOp>("op")) {
36 if (op->isPostfix()) {
36 if (op->isIncrementDecrementOp() && op->isPostfix()) {
37 37 op->dump(); op->dump();
38 38 std::cout << '\n'; std::cout << '\n';
39 39 } }
 
... ... main(int argc, const char *argv[])
51 51 MatchHelper helper; MatchHelper helper;
52 52
53 53 MatchFinder finder; MatchFinder finder;
54 finder.addMatcher(incMatcher, &helper);
54 finder.addMatcher(builtinMatcher, &helper);
55 55
56 56 return tool.run(newFrontendActionFactory(&finder)); return tool.run(newFrontendActionFactory(&finder));
57 57 } }
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/for-postfix

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/for-postfix

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master