[cfe-dev] Finding Stmt Kind

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Sun Nov 18 10:23:45 PST 2018


On Sun, Nov 18, 2018 at 1:20 PM Pardis Pashakhanloo via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> Hi all,
>
> Is it possible to get the kind of a Stmt object in clang?
> The only solution that I know of is using dyn_cast. However, in this solution, I have to check for every kind of Stmt, e.g.
> if (CompoundStmt *CS = dyn_cast<CompoundStmt>(d))
>   ....
> else if (IfStmt *IS = dyn_cast<IfStmt>(d))
>   ....
>
> Is there a better solution or trick?

The usual approach is to use the casting machinery, but you can also
use the statement kind directly by calling Stmt::getStmtClass(),

~Aaron



More information about the cfe-dev mailing list