[cfe-dev] how to get label from a statement and VisitLabelExpr

Richard Smith richard at metafoo.co.uk
Tue May 14 13:05:42 PDT 2013


On Tue, May 14, 2013 at 2:04 AM, Rajendra <rks at cse.iitb.ac.in> wrote:

> Here below is my code of VisitStmt() and VisitLabelStmt(), I know when to
> return true//false from visitor method and I have tried
> VisitLabelStmt(LabelStmt* s) and VisitLabelDecl(LabelDecl* d) too. No luck.
>
> bool MyProcessStmtBox::VisitStmt(Stmt *s)
> {
>   clang::SourceManager & sm = this->m_compilerInstance->getSourceManager();
>   clang::SourceLocation locStart = s->getLocStart();
>
>   std::cerr << "\n found stmt \n";
>   std::cerr << "\t" << stmtToStr(s) << " at ";
>   locStart.dump(sm);
>   std::cerr << "\n";
>   std::cerr << "StmtClassName = " << s->getStmtClassName();
>
>   if (strcmp(s->getStmtClassName(), "LabelStmt") == 0)
>   {
>       std::cerr << "\n found LabelStmt\n";
>       s->dump();
>   }
>   // Returning false from one of the overridden visitor functions
>   // will abort the entire traversal.
>   return true;
> }
>
> bool MyProcessStmtBox::VisitLabelStmt(Stmt* s)
> {
>   std::cerr << "\tLabelStmt: \n";
>   s->dump(); // TODO: remove
>
>   return false;
> }


We need more context than this. Are you deriving from StmtVisitor?
RecursiveASTVisitor? What code are you using to visit the body of the
function?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130514/9df77953/attachment.html>


More information about the cfe-dev mailing list