<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 2, 2014 at 2:31 AM, Michael Bolin <span dir="ltr"><<a href="mailto:bolinfest@gmail.com" target="_blank">bolinfest@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi, I am traversing the AST for an obj-c file using a clang plugin. I have a code snippet like the following:<div>
<br></div><div><div>#define JK_ATTRIBUTES(attr, ...) __attribute__((attr, ##__VA_ARGS__))</div>
<div>#define JK_STATIC_INLINE static __inline__ JK_ATTRIBUTES(always_inline)</div><div><br></div><div>JK_STATIC_INLINE int jk_parse_skip_newline();</div><div><br></div><div>@implementation Hello</div><div>- (void)say:(int)i {</div>
<div> if (i > 0) {</div><div> NSLog(@"Hello, world! (%d)", i);</div><div> }</div><div><br></div><div> // Example of selector with unknown method declaration.</div><div> [(id)@"Anything" length];</div>
<div>}</div><div>@end</div><div><br></div><div>JK_STATIC_INLINE int jk_parse_skip_newline() {</div><div> return 0;</div><div>}</div></div><div><br></div><div>so while traversing the AST, I am trying to find the SourceRange of the jk_parse_skip_newline() definition at the bottom of the file. For non-macro expanded functions, this is very straightforward. But due to the macro expansion, I get a SourceRange that spans from the start of the macro to the end of my code snippet.</div>
</div></blockquote><div><br></div><div>How do you get that? If you only use functions that handle SourceRanges (and never combine locations you get from getBegin() getEnd()) that should not be possible.</div><div>Take a look at Lexer::makeFileCharRange and Lexer::getSourceText for how to deal with macro-ized ranges.</div>
<div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div> That means that it also includes the Hello class, which has nothing to do with jk_parse_skip_newline(). This is a problem because I am trying to use the AST to determine where jk_parse_skip_newline is defined so I can comment it out of the source file.</div>
<div><br></div><div>Is it possible for me to get the necessary SourceRange from the clang API? Ideally, I would get a SourceRange that identifies only the last three lines of my code sample.</div><div><br></div><div>Thank you,</div>
<div>Michael</div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>