Last active
November 11, 2019 19:00
-
-
Save knebekaizer/b4516e0daf300c0ca9a0a7cc3cfbadf8 to your computer and use it in GitHub Desktop.
The hack to convert ExtVector to CXType_Vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace clng { | |
// All the types below are POD and bitwise compatible with corresponding clang classes | |
struct PointerIntPair { | |
intptr_t Value = 0; | |
}; | |
struct QualType { | |
PointerIntPair Value; // llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>, Qualifiers::FastWidth> Value; | |
}; | |
struct Type; | |
struct ExtQualsTypeCommonBase { | |
Type * BaseType; | |
QualType CanonicalType; | |
}; | |
struct TypeBitfields { | |
/// TypeClass bitfield - Enum that specifies what subclass this belongs to. | |
unsigned TC : 8; | |
unsigned : 24; | |
}; | |
struct Type : public ExtQualsTypeCommonBase { | |
TypeBitfields TypeBits; | |
uint8_t getTypeClass() const { return TypeBits.TC; } | |
void setTypeClass(uint8_t tc) { TypeBits.TC = tc; } | |
}; | |
} // namesoace clng | |
bool tryCast2Vector(CXType type) { | |
type = clang_getCanonicalType(type); // always safe | |
auto *base = reinterpret_cast<clng::Type *>( reinterpret_cast<intptr_t>(type.data[0]) & ~0xf ); | |
if (base && base->getTypeClass() == 15) { | |
// This is ExtVectorType; pretend to be VectorType instead | |
base->setTypeClass(13); | |
return true; | |
} | |
return false; | |
} | |
// Usage: | |
// val type = clang_getCursorType(cursor) | |
// if (type.kind == CXType_Vector || tryCast2Vector(type)) { | |
// do_whatever_as_it_would_be_CXType_Vector(type) | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment