[cfe-dev] Wrapping if and for body with brackets

via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 11 11:41:26 PDT 2017


Hi,
I want to wrap body of is statement inside a bracket.
Ex if()a=b; ---> if (){a=b}
I am doing with the help of
if(IfStmt *ifStmt = dyn_cast<IfStmt>(st)){
                rewriter.InsertTextBefore(ifStmt->getThen()->getLocStart(),"{\n");
                rewriter.InsertTextAfterToken(ifStmt->getThen()->getLocEnd(),";\n}//");
                if(ifStmt->getElse() != NULL){
                    rewriter.InsertTextBefore(ifStmt->getElseLoc(),"\n");
                    rewriter.InsertTextBefore(ifStmt->getElse()->getLocStart(),"{\n");
                    rewriter.InsertTextAfterToken(ifStmt->getElse()->getLocEnd(),";\n}//");
                }

But it is giving me weird answer like closing bracket missing or on
wrapping when if has single line body. Can someone inform me where I am
doing wrong.

-- 
Thanks and Regards
Awanish Pandey
PhD, CSE
IIT Kanpur




More information about the cfe-dev mailing list