AST references

I have the following file:

@protocol MyProtocol

  • (void)someProtocolMethod;
    @end

@interface MyBaseClass {
id myIvar;
}
@end

When printing out the AST node for the @protocol declaration, I get:

$4 = {
DeclKind = clang::Decl::ObjCProtocol,
ExternalLexicalStorage = false,
ExternalVisibleStorage = false,
LookupPtr = 0x0,
FirstDecl = 0x1033160c0,
LastDecl = 0x1033160c0
}

However, when I print out the AST node for , I get a different value:

$5 = {
clang::Decl = {
_vptr$Decl = 0x1016f80d0,
NextDeclInContext = 0x103316150,
DeclCtx = {
Val = {
Value = 4348516192
}
},
Loc = {
ID = 2
},
DeclKind = clang::Decl::ObjCProtocol,
InvalidDecl = 0,
HasAttrs = 0,
Implicit = false,
Used = false,
IdentifierNamespace = 16,
Access = 0
},
members of clang::NamedDecl:
Name = {
Ptr = 4353910984
}
}

I was under the impression that clang would resolve references. So MyProtocol would be the same in both places. If not, how do I resolve these references?

Thanks.

Kevin

Hi Kevin,

In the example below, Protocol references are resolved by the ObjCInterfaceDecl API (e.g. the iterator on ObjCInterfaceDecl should return the ObjCProtocolDecl for ‘MyProtocol’).

In the debug output below, $4 looks like a ‘DeclContext’ (which ObjCProtocolDecl inherits from indirectly).

Let me know if you need further assistance,

snaroff