This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatchers] Add support of hasCondition for SwitchStmt.
ClosedPublic

Authored by etienneb on May 27 2016, 11:01 PM.

Details

Summary

The switch statement could be added to the hasCondition matcher.

Example:

clang-query> match switchStmt(hasCondition(ignoringImpCasts(declRefExpr())))

Output:

Match #1:

Binding for "root":
SwitchStmt 0x2f9b528 </usr/local/google/home/etienneb/examples/enum.cc:35:3, line:38:3>
|-<<<NULL>>>
|-ImplicitCastExpr 0x2f9b510 <line:35:11> 'int' <IntegralCast>
| `-ImplicitCastExpr 0x2f9b4f8 <col:11> 'enum Color' <LValueToRValue>
|   `-DeclRefExpr 0x2f9b4d0 <col:11> 'enum Color' lvalue Var 0x2f9a118 'C' 'enum Color'
`-CompoundStmt 0x2f9b610 <col:14, line:38:3>
  |-CaseStmt 0x2f9b578 <line:36:3, col:22>
  | |-ImplicitCastExpr 0x2f9b638 <col:8> 'int' <IntegralCast>
  | | `-DeclRefExpr 0x2f9b550 <col:8> 'enum Size' EnumConstant 0x2f99e40 'Small' 'enum Size'
  | |-<<<NULL>>>
  | `-ReturnStmt 0x2f9b5d0 <col:15, col:22>
  |   `-IntegerLiteral 0x2f9b5b0 <col:22> 'int' 1
  `-DefaultStmt 0x2f9b5f0 <line:37:3, col:12>
    `-BreakStmt 0x2f9b5e8 <col:12>

1 match.

Diff Detail

Event Timeline

etienneb updated this revision to Diff 58881.May 27 2016, 11:01 PM
etienneb retitled this revision from to [ASTMatchers] Add support of hasCondition for SwitchStmt..
etienneb updated this object.
etienneb added reviewers: aaron.ballman, sbenza.
etienneb added a subscriber: cfe-commits.
klimek accepted this revision.May 30 2016, 3:04 AM
klimek added a reviewer: klimek.

LG. Thx!

This revision is now accepted and ready to land.May 30 2016, 3:04 AM
etienneb closed this revision.May 30 2016, 8:31 AM