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 |
} |
} |