I want to do something to the CFG of Clang. Now I can get the CFG of the C File.<br>AfterI got the CFG, I can get the Stmt of the CFG.Now the question is that how I can get the SourceManager through the CFG.<br>At 2012-02-17 17:10:40,"Manuel Klimek" <klimek@google.com> wrote:<br>>On Fri, Feb 17, 2012 at 10:05 AM, redder_0210 <redder_0210@yeah.net> wrote:<br>>> Thanks for you replying.<br>>> The new question is that I cannot get the SourceManager only by the Stmt. So<br>>> the "SM.getSpellingLoc(Range.getBegin())" cannot work.<br>>> Thus, I want to how to get SourceManager from the Stmt or from the<br>>> SourceRange.<br>><br>>You can't. You need to get the SourceManager from the context. I could<br>>help you more if you give a little more context on how you're hooking<br>>into clang.<br>><br>>Cheers,<br>>/Manuel<br>><br>>> Hope Best!<br>>> /Redder<br>>><br>>> At 2012-02-13 17:25:26,"M!
 anuel Klimek" <klimek@google.com> wrote:<br>>>>On Mon, Feb 13, 2012 at 5:48 AM, redder_0210 <redder_0210@yeah.net> wrote:<br>>>>> Dear all,<br>>>>> I am interested in that how to translate from a statemnt to the<br>>>>> corresponding string.<br>>>>> For example,<br>>>>> in the CFG, there is a CFGStmt "int i = 0;",<br>>>>> now I want to get the string "int i = 0;",namely modify the type CFGStmt<br>>>>> to<br>>>>> the type string.<br>>>><br>>>>CFGStmt has a getStmt() which gets you a Stmt, which has a function<br>>>>getSourceRange which gives you the SourceRange.<br>>>>When you have a SourceRange you can get a CharSourceRange by calling<br>>>>CharSourceRange::getTokenRange(...).<br>>>>Then you get the start location by calling<br>>>>SM.getSpellingLoc(Range.getBegin()) (where Range is the<br>>>!
 >CharSourceRange).<br>>>>You can calculate the length of t
he text by calling getDecomposedLoc<br>>>>on the getBegin() and getEnd() of the spelling locations. You'll also<br>>>>need to add Lexer::MeasureTokenLength(EndLocation, ...) to the size,<br>>>>as the last element of a token range points to the begin of the last<br>>>>token.<br>>>>Finally you can call SM.getCharacterData with the begin and you'll<br>>>>have your text.<br>>>><br>>>>Unfortunately this is a little harder than it could be, mostly due to<br>>>>the different types of locations. (Note that if there are for example<br>>>>macros involved, it matters whether you use getSpellingLocation or<br>>>>not).<br>>>><br>>>>Cheers,<br>>>>/Manuel<br>>><br>>><br><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>