What is a TypeRef, and how do you use it? (clang-c)

Hi again,

Having a few more dramas with the clang-c api. Particularly Typedef’s seem to behave oddly.

If I do a dump of the ast for this code:

struct x {
int y;
};

typedef struct x MyThing;

extern MyThing *example;

I get something along the lines of this from the parser:

Symbol: x, Type: struct, Raw Kind: CXCursor_StructDecl
Symbol: y, Type: int, Raw Kind: CXCursor_FieldDecl
Symbol: MyThing, Type: record, Raw Kind: CXCursor_TypedefDecl
Symbol: struct x, Type: record, Raw Kind: CXCursor_TypeRef
Symbol: example, Type: record *, Raw Kind: CXCursor_VarDecl
Symbol: MyThing, Type: record, Raw Kind: CXCursor_TypeRef

In a slightly better format that’s basically:

x (struct) → y (field)
MyThing (Typedef)
struct x (Typeref)
example (Var)
MyThing (Typeref)

I’ll just add to that, there’s no problem getting the actual type for the typedef vardecl; that works fine.

The problems I’m having are:

  1. There’s an extra symbol in the AST that doesn’t seem to be related to anything.

  2. There’s no obvious way to mark a param or var via its typedef rather than the base type itself.