File for-postfix.cpp changed (mode: 100644) (index 0681922..e024d91) |
... |
... |
static StatementMatcher builtinMatcher = |
23 |
23 |
) |
) |
24 |
24 |
); |
); |
25 |
25 |
|
|
|
26 |
|
static StatementMatcher opMatcher = |
|
27 |
|
forStmt( // for ([init]; [condition]; [increment]) |
|
28 |
|
hasIncrement( // "increment" part of for-loop |
|
29 |
|
operatorCallExpr( // call of overloaded operator |
|
30 |
|
argumentCountIs(2) // that requires two arguments |
|
31 |
|
).bind("op") // bind matched unary op to "op" name |
|
32 |
|
) |
|
33 |
|
); |
|
34 |
|
|
26 |
35 |
class MatchHelper : public MatchFinder::MatchCallback |
class MatchHelper : public MatchFinder::MatchCallback |
27 |
36 |
{ |
{ |
28 |
37 |
public: |
public: |
|
... |
... |
public: |
31 |
40 |
using namespace clang; |
using namespace clang; |
32 |
41 |
|
|
33 |
42 |
typedef UnaryOperator UnOp; |
typedef UnaryOperator UnOp; |
|
43 |
|
typedef CXXOperatorCallExpr Call; |
34 |
44 |
|
|
35 |
45 |
if (const UnOp *op = result.Nodes.getNodeAs<UnOp>("op")) { |
if (const UnOp *op = result.Nodes.getNodeAs<UnOp>("op")) { |
36 |
46 |
if (op->isIncrementDecrementOp() && op->isPostfix()) { |
if (op->isIncrementDecrementOp() && op->isPostfix()) { |
37 |
|
op->dump(); |
|
38 |
|
std::cout << '\n'; |
|
|
47 |
|
printOut(result, op); |
|
48 |
|
} |
|
49 |
|
} else if (const Call *op = result.Nodes.getNodeAs<Call>("op")) { |
|
50 |
|
const OverloadedOperatorKind opKind = op->getOperator(); |
|
51 |
|
|
|
52 |
|
if (opKind == OO_PlusPlus || opKind == OO_MinusMinus) { |
|
53 |
|
printOut(result, op); |
39 |
54 |
} |
} |
40 |
55 |
} |
} |
41 |
56 |
} |
} |
|
57 |
|
|
|
58 |
|
private: |
|
59 |
|
void printOut(const MatchFinder::MatchResult &result, |
|
60 |
|
const clang::Expr *expr) const |
|
61 |
|
{ |
|
62 |
|
expr->dump(); |
|
63 |
|
std::cout << '\n'; |
|
64 |
|
} |
42 |
65 |
}; |
}; |
43 |
66 |
|
|
44 |
67 |
int |
int |
|
... |
... |
main(int argc, const char *argv[]) |
52 |
75 |
|
|
53 |
76 |
MatchFinder finder; |
MatchFinder finder; |
54 |
77 |
finder.addMatcher(builtinMatcher, &helper); |
finder.addMatcher(builtinMatcher, &helper); |
|
78 |
|
finder.addMatcher(opMatcher, &helper); |
55 |
79 |
|
|
56 |
80 |
return tool.run(newFrontendActionFactory(&finder)); |
return tool.run(newFrontendActionFactory(&finder)); |
57 |
81 |
} |
} |