interface name SourceLocation?

Thanks Steve, this worked. Although I had to use a slightly different endBuf, because the Lexer was complaining:

const char *endBuf = SM->getBufferData(LocStart.getFileID()).second;

So that solution works for now, but it’s on my wish list for having in clang. Relatedly, one other thing for the wish list: the SourceLocation for the superclass name. For example, the location of token between the ‘:’ and the ‘{’ here:

@interface MyClass : MySuperClass {

Thanks again,

e

Be careful with this, this will explode violently if LocStart is a macro instantiation. Before calling “getFileID()” generally you want to call “isMacroID()”. If you have a macro ID, you need to decide how your refactoring will handle it. It seems pretty reasonable to just throw up your hands and say “can’t do it”, but you don’t want to abort :slight_smile:

An example would be something like:

#define X @interface foo

X : bar { …

-Chris

Thanks Steve, this worked. Although I had to use a slightly different endBuf, because the Lexer was complaining:

const char *endBuf = SM->getBufferData(LocStart.getFileID()).second;

So that solution works for now, but it’s on my wish list for having in clang. Relatedly, one other thing for the wish list: the SourceLocation for the superclass name. For example, the location of token between the ‘:’ and the ‘{’ here:

Adding locations for the class/superclass is trivial (I’ll add it today).

Solving the more general problem will require more thought. For example:

@interface C : S <P1, P2, P3> {

For example, now that we have a DeclContext (thanks, Argiris:-), I’d like to consider a “lazy” API that could provide all the location info without bloating the AST’s at birth. We could do this by having getParent() return a TranslationUnit which could (in turn) store a pointer to the respective SourceManager(). We could also pass the SourceManager() in explicitly, however that would make the API less self contained.

snaroff