Hi again,<div><br></div><div>Having a few more dramas with the clang-c api. Particularly Typedef's seem to behave oddly.</div><div><br></div><div>If I do a dump of the ast for this code:</div><div><br></div><div><div>struct x {</div>
<div> int y;</div><div>};</div><div><br></div><div>typedef struct x MyThing;</div><div><br></div><div>extern MyThing *example;</div><div><br></div><div>I get something along the lines of this from the parser:</div><div><br>
</div><div><div>Symbol: x, Type: struct, Raw Kind: CXCursor_StructDecl</div><div>Symbol: y, Type: int, Raw Kind: CXCursor_FieldDecl</div><div>Symbol: MyThing, Type: record, Raw Kind: CXCursor_TypedefDecl</div><div>Symbol: struct x, Type: record, Raw Kind: CXCursor_TypeRef</div>
<div>Symbol: example, Type: record *, Raw Kind: CXCursor_VarDecl</div><div>Symbol: MyThing, Type: record, Raw Kind: CXCursor_TypeRef</div></div></div><div><br></div><div>In a slightly better format that's basically:</div>
<div><br></div><div>x (struct) -> y (field)</div><div>MyThing (Typedef)</div><div>struct x (Typeref)</div><div>example (Var)</div><div>MyThing (Typeref)</div><div><br></div><div>-_-</div><div><br></div><div>What's going on here? Why is there a trailing Typeref symbol?</div>
<div><br></div><div>The docs from TypeRef say:</div><div><br></div><div><div> /**</div><div> * \brief A reference to a type declaration.</div><div> *</div><div> * A type reference occurs anywhere where a type is named but not</div>
<div> * declared. For example, given:</div><div> *</div><div> * \code</div><div> * typedef unsigned size_type;</div><div> * size_type size;</div><div> * \endcode</div><div> *</div><div> * The typedef is a declaration of size_type (CXCursor_TypedefDecl),</div>
<div> * while the type of the variable "size" is referenced. The cursor</div><div> * referenced by the type of size is the typedef for size_type.</div><div> */</div></div><div><br></div><div>So I suppose I'm supposed to use clang_getTypeDeclaration() on the Typeref to get the cursor for the typedef for something.</div>
<div><br></div><div>Fair enough; I can use that from the 'struct x' TypeRef -> the MyType typedef.</div><div><br></div><div><br></div><div>However, how can I relate the 'example' var to the related typedef? </div>
<div><br></div><div>I presume that there is supposed to be some way to relate the trailing MyType --> example, and then MyType ---> the typedef.</div><div><br></div><div><br></div><div>However, if I do a getSemanticParent() on the two nodes 'example' and 'MyType' (trailing) I get:</div>
<div><br></div><div>'example' -> (getSemanticParent) --> CXCursor_UnexposedDecl</div><div>'MyType' ->(getSemanticParent) --> CXCursor_FirstInvalid</div><div><br></div><div>so....</div><div><br>
</div><div>What now?</div><div><br></div><div>Is this just not supported?</div><div><br></div><div><br></div><div>help much appreciated!</div><div><br></div><div>cheers,</div><div>Doug. </div><div><br></div>