[cfe-dev] one question about SourceLocation

Yang Chen chenyang at cs.utah.edu
Mon Nov 19 11:57:48 PST 2012


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
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>   




More information about the cfe-dev mailing list