[cfe-dev] SourceRange for a macro-expanded function definition?

Michael Bolin bolinfest at gmail.com
Tue Apr 1 17:31:46 PDT 2014


Hi, I am traversing the AST for an obj-c file using a clang plugin. I have
a code snippet like the following:

#define JK_ATTRIBUTES(attr, ...)        __attribute__((attr, ##__VA_ARGS__))
#define JK_STATIC_INLINE static __inline__ JK_ATTRIBUTES(always_inline)

JK_STATIC_INLINE int jk_parse_skip_newline();

@implementation Hello
- (void)say:(int)i {
  if (i > 0) {
    NSLog(@"Hello, world! (%d)", i);
  }

  // Example of selector with unknown method declaration.
  [(id)@"Anything" length];
}
@end

JK_STATIC_INLINE int jk_parse_skip_newline() {
  return 0;
}

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. 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.

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.

Thank you,
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140401/a87e1e72/attachment.html>


More information about the cfe-dev mailing list