Does clang stores some sort of unique ID for type definitions? I could generate manually this id for each time I stumble upon a new QualType but I’m looking if this is already made by the library.
Another question, Is possible to verify if a QualType is of some class X? like:
Does clang stores some sort of unique ID for type definitions? I could
generate manually this id for each time I stumble upon a new QualType but
I'm looking if this is already made by the library.
libclang's USR's are probably the closest thing to this, but I don't
think that is what you are looking for.
Another question, Is possible to verify if a QualType is of some class X?
like:
QualType t;
if (t.isofclass<std::string>()) {
}
This is not generally possible. The compiler is on a "meta" level from
the code being compiled, so types inside the source code of the
compiler are not generally meaningful in this sense. You can ask "is
this class called `string` in namespace `std`?", but arbitrary C++
types "inside the compiler" are not related to types in the code being
compiled. It is basically a Godel, Escher, Bach scenario.
> Does clang stores some sort of unique ID for type definitions? I could
> generate manually this id for each time I stumble upon a new QualType but
> I'm looking if this is already made by the library.
libclang's USR's are probably the closest thing to this, but I don't
think that is what you are looking for.
Inside one TU type pointers have identity - that is, there's only one Type*
for the same type. That doesn't hold for QualTypes.
It doesn’t? QualTypes are PointerIntPairs (value objects); two QualTypes should be equal if they have the same qualifiers and the same underlying Type.
Also, you have to decide if you want to take typedefs into consideration; if not, you should make sure to call getCanonicalType before comparing your QualTypes.
> Does clang stores some sort of unique ID for type definitions? I could
> generate manually this id for each time I stumble upon a new QualType
but
> I'm looking if this is already made by the library.
libclang's USR's are probably the closest thing to this, but I don't
think that is what you are looking for.
Inside one TU type pointers have identity - that is, there's only one
Type* for the same type. That doesn't hold for QualTypes.
It doesn't? QualTypes are PointerIntPairs (value objects); two QualTypes
should be equal if they have the same qualifiers and the same underlying
Type.
That means that QualTypes don't have pointer identity (was all I was trying
to say - sorry if that was not clear.
Ah, okay. I thought you meant you can’t compare them with == and get a meaningful result, which you can. (Of course, usually I shoot my self in the foot by forgetting the canonicalization in cases where it’s needed…)