one question about SourceLocation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

one question about SourceLocation

Rambo
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.
Reply | Threaded
Open this post in threaded view
|

Re: one question about SourceLocation

Yang Chen
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

>
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/one-question-about-SourceLocation-tp4028358.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>  

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: one question about SourceLocation

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