I have a simple header parser based on clang and I get the typedefs from some source.
struct _poire {
int g;
tomate rouge;
};
typedef struct _poire kudamono;
It seems that you have raised an interesting point. I have figured out something, but since I can't actually test my intuition right now, I can't be 100% sure. Anyway here is what I would do :
If I parse your code (with a little extension to declare a kudamono variable), here is what I can say from this:
struct _poire {
int g;
char rouge; // tomate is probably one of your classes so I just changed the type of the field.
};
typedef struct _poire kudamono;
int maFonction(){
kudamono une_poire;
return 0;
}
When the typedef is parsed, here is what is yielded :
-TypedefDecl 0x23b4620
When I declare a variable of type kudamono
, here is below its AST-dump :
-VarDecl 0x2048040
NB : You can get the AST Dump of your code with this command line, it can be really handy to understand how your code will be parsed :
clang -Xclang -ast-dump -std=c++11 -fsyntax-only test.cpp (just remove -std=c++11 if you want to compile a file_name.c file)
Now, from what I understand, I will make a comparaison between the VarDecl
and the TypedefDecl
:
1°) This VarDecl
is named une_poire and has the type kudamono which is a typedef from the type struct _poire.
2°) This TypedefDecl
is named kudamono and has the type struct _poire which is a typedef from the type struct _poire
So, the weird part is right here. struct _poire is considered as typedef from struct _poire.
You'll note that I tried to make a typedef with a usual type :
typedef int numbers;
And this time, AST-dump yields :
TypedefDecl 0x25d9680
, so I guess the parser may have some troubles with handmade types (typically structs).
I can see one dirty way to know if your type is canonical or not (without getting false positives or false negatives) :
Check that the QualType and the canonical QualType are not the same
I don't know if a simple '=' between Qualtype
will make false positives or false negatives (as I can't test), but you can still compare the names of the types with strcmp
So, to sum up a little bit :
typedef int int32_t
).