<div dir="ltr">Here is a better example:<div><br></div><div><a href="https://gist.github.com/bolinfest/9984257">https://gist.github.com/bolinfest/9984257</a><br></div><div><br></div><div>Here are the key lines in the output:<br>
<br><pre class="" style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:16.799999237060547px;width:1155px;margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(0,0,0)"><div class="" id="file-c-preprocessor-affecting-sourcerange-LC37">
|-FunctionDecl 0x10450ca90 <./example.h:15:1, /System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:137:72> someFunction1 'NSString *(void)' extern</div><div class="" id="file-c-preprocessor-affecting-sourcerange-LC38">
|-FunctionDecl 0x10450cc00 <./example.h:16:1, /System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:137:72> someFunction2 'NSString *(void)' extern</div><div><br></div></pre>Ideally, I would like to be able to get the following instead:<br>
<br><pre class="" style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:16.799999237060547px;width:1155px;margin-top:0px;margin-bottom:0px;padding:0px;color:rgb(0,0,0)"><div class="" id="file-c-preprocessor-affecting-sourcerange-LC37">
|-FunctionDecl 0x10450ca90 <./example.h:15:1, ./example.h:15:61> someFunction1 'NSString *(void)' extern</div><div class="" id="file-c-preprocessor-affecting-sourcerange-LC38">|-FunctionDecl 0x10450cc00 <./example.h:16:1, ./example.h:16:61> someFunction2 'NSString *(void)' extern</div>
<div><br></div></pre>That is, I would like to be able to extract a SourceRange from a single file that I could delete (or comment out) to remove the definition or someFunction1 or someFunction2. Obviously the existing SourceRange that I get from the AST makes that hard to do.<br>
<br>Is it possible to get my desired SourceRange?</div><div><br></div><div>Thank you,</div><div>Michael</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 2, 2014 at 1:51 AM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.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"><div class="gmail_extra"><div class="gmail_quote"><div class="">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><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 class=""><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></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">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>
</blockquote></div><br></div>