<div dir="auto">Hello!<div dir="auto"><br></div><div dir="auto">There is a cool tutorial how to work with Clang Tidy:</div><div dir="auto"><a href="https://youtu.be/1S2A0VWGOws">https://youtu.be/1S2A0VWGOws</a> (by Daniel Jasper and Manuel Klimek)<br></div><div dir="auto"><br></div><div dir="auto">I have already implemented this based on the video.</div><div dir="auto"><br></div><div dir="auto">Clang Tidy version:</div><div dir="auto"><br></div><div dir="auto"><div dir="auto">static StringRef exprToStr(const Expr *E,</div><div dir="auto"> const MatchFinder::MatchResult &Result) {</div><div dir="auto"> return Lexer::getSourceText(</div><div dir="auto"> CharSourceRange::getTokenRange(E->getSourceRange()),</div><div dir="auto"> *Result.SourceManager, Result.Context->getLangOpts(), 0);</div><div dir="auto">}</div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">Static Analyzer version: </div><div dir="auto"><br></div><div dir="auto"><div dir="auto">static StringRef exprToStr(const Expr *E, BugReporterContext &BRC) {</div><div dir="auto"> return Lexer::getSourceText(</div><div dir="auto"> CharSourceRange::getTokenRange(E->getSourceRange()),</div><div dir="auto"> BRC.getSourceManager(), BRC.getASTContext().getLangOpts(), 0);</div><div dir="auto">}</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018. dec. 6. 5:39 ezt írta ("Kihong Heo via cfe-dev" <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a>>):<br type="attribution"><blockquote class="m_2307377844970049010quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Thanks.<div><br></div><div>It seems Expr::getSourceRange() returns the range of the first token.</div><div>Then, in this particular case, what is the most common way to get the last token of the expression? How can I get “x < 10”?</div><div><br></div><div>Best,</div><div>Kihong<br><div><br><blockquote type="cite"><div>2018. 12. 2. 오후 1:30, Richard Smith <<a href="mailto:richard@metafoo.co.uk" rel="noreferrer noreferrer" target="_blank">richard@metafoo.co.uk</a>> 작성:</div><div class="m_2307377844970049010elided-text"><br class="m_2307377844970049010m_2913603088807541203Apple-interchange-newline"><div><div dir="auto" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div><div class="gmail_quote"><div dir="ltr">On Sat, 1 Dec 2018, 22:16 Alexey Sidorin via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a><span class="m_2307377844970049010m_2913603088807541203Apple-converted-space"> </span>wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi Kihong,<br>The problem in your particular case is that the begin location of<span class="m_2307377844970049010m_2913603088807541203Apple-converted-space"> </span><br>integer literal is reported as the end location (should we fix it in AST)?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">No, that's just how clang represents source ranges: source ranges are inclusive and source locations are the locations of tokens. So the start and end location of an integer literal should be the same, and the user needs to find the end of the last token themselves.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">As a workaround, you can try to use Lexer::getLocForEndOfToken() to get<span class="m_2307377844970049010m_2913603088807541203Apple-converted-space"> </span><br>the token end location for the location reported by getLocEnd().<br><br>02.12.2018 8:36, Kihong Heo via cfe-dev пишет:<br>> Hi all,<br>><br>> How can I get string representations of conditional expressions of IfStmt?<br>> The problem is as follows:<br>> For example;<br>> =============<br>> /* source code */<br>> if( x < 10) …<br>> =============<br>><br>> “IS->getCond()->getSourceRange()” represents only “x <“. It seems quite strange.<br>><br>> Thanks,<br>> Kihong<br>> _______________________________________________<br>> cfe-dev mailing list<br>><span class="m_2307377844970049010m_2913603088807541203Apple-converted-space"> </span><a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a><br>><span class="m_2307377844970049010m_2913603088807541203Apple-converted-space"> </span><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br><br><br>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></blockquote></div></div></div></div></div></blockquote></div><br></div></div><div class="m_2307377844970049010elided-text">_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</div></blockquote></div><br></div>