one question about SourceLocation

Hi,
for this program:
for (i = 0; i < 5; i++)
{
    // have anything at here;
    
printf
("%d",
num
[i]);
   //other Codes at here;
     }
I want to get the SourceLocation by This codes:
if(isa<ArraySubscriptExpr>(s))
       {
          ArraySubscriptExpr *Decl2=cast<ArraySubscriptExpr>(s);
          Expr *lhs=Decl2->getRHS();
          SourceLocation ST=lhs->getExprLoc();
       }
But I only get the Location before num[i],How can I get the SourceLocation
about "printf"?
I look forward your help.

Rambo wrote:

Hi,
for this program:
for (i = 0; i < 5; i++)
{
    // have anything at here;
     printf
("%d",
num
[i]);
   //other Codes at here; } I want to get the SourceLocation by This codes:
if(isa<ArraySubscriptExpr>(s))
       {
          ArraySubscriptExpr *Decl2=cast<ArraySubscriptExpr>(s);
          Expr *lhs=Decl2->getRHS();
          SourceLocation ST=lhs->getExprLoc();
       }
But I only get the Location before num[i],How can I get the SourceLocation
about "printf"?
I look forward your help.

You will need to get the Stmt node which represents the ``printf" statement in AST. Then you can use Stmt::getLocStart.

- Yang

How can I get that Stmt node?can you explain it more carefully.