get sizeof(*) 's value

Hi,
    I'm using a RecursiveASTVisitor and its VisitCallExpr method. I want to
find out all location using malloc. How to get the sizeof(*)'s value?

    for example:

     code:
          char* a = (char*)malloc(sizeof(char));
          int* b = (int*)malloc(sizeof(int));
     result:
          a, fun:malloc, alloc size:1bytes
          b, fun:malloc, alloc size:4bytes

     I want to know somthing like this.

    Thanks

Expr::EvaluateAsInt is the most general way.

John.

I wirte the VisitCallExpr() like this. But I can't find the Expr's AstContext
to use EvaluateAsInt() Function. How to do next?

bool VisitCallExpr(CallExpr *expr){
        FunctionDecl* call = expr->getDirectCallee();
        if (call->getNameAsString() == "malloc"){
            for (int i=0;i < expr->getNumArgs();i++){
                Expr* arg = expr->getArg(i);
                Stmt::StmtClass stmt = arg->getStmtClass();
                if (arg->getStmtClass() ==
Stmt::UnaryExprOrTypeTraitExprClass){
                    UnaryExprOrTypeTraitExpr* de_expr =
dyn_cast<UnaryExprOrTypeTraitExpr>(arg);
                    //get the size
                    de_expr->EvaluateAsInt();//Problem
                }
             }
         }
}

Thanks a lot ~

Chen.

How did you create this AST in the first place? Generally you make an
ASTContext as part of that.

John.