How can I get the types' information in CStyleCastExpr

Hi all,

I want to get the types’ information in my checker. The method interface I am using is checkPostStmt(const CStyleCastExpr *cec, CheckerContext &C) const;

For example, there is a statement:
int *pi;
char *pc;
int a = 3;
pi = &a;
pc = (char *)pi;

After analysing “(char *)pi;”, I want to get the type-related information, that is, the original type is int*, the casted type is char *. So how can I get that target? Thanks a lot.

The simplest way to do this is Expr::getType. The type of the CastExpr is the casted type, the type of the CastExpr’s subexpression is the original type.

If you want to get more information here, look into ExplicitCastExpr::getTypeInfoAsWritten.

Hope that helps,
Jordan

Thank you Jordan. That’s a great help.