Dqn/dqn_type_info.h

68 lines
2.3 KiB
C

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// $$$$$$$$\ $$\ $$\ $$$$$$$\ $$$$$$$$\ $$$$$$\ $$\ $$\ $$$$$$$$\ $$$$$$\
// \__$$ __|\$$\ $$ |$$ __$$\ $$ _____| \_$$ _|$$$\ $$ |$$ _____|$$ __$$\
// $$ | \$$\ $$ / $$ | $$ |$$ | $$ | $$$$\ $$ |$$ | $$ / $$ |
// $$ | \$$$$ / $$$$$$$ |$$$$$\ $$ | $$ $$\$$ |$$$$$\ $$ | $$ |
// $$ | \$$ / $$ ____/ $$ __| $$ | $$ \$$$$ |$$ __| $$ | $$ |
// $$ | $$ | $$ | $$ | $$ | $$ |\$$$ |$$ | $$ | $$ |
// $$ | $$ | $$ | $$$$$$$$\ $$$$$$\ $$ | \$$ |$$ | $$$$$$ |
// \__| \__| \__| \________| \______|\__| \__|\__| \______/
//
// dqn_type_info.h -- C++ type introspection
//
////////////////////////////////////////////////////////////////////////////////////////////////////
enum Dqn_TypeKind
{
Dqn_TypeKind_Nil,
Dqn_TypeKind_Basic,
Dqn_TypeKind_Enum,
Dqn_TypeKind_Struct,
};
struct Dqn_TypeField
{
uint16_t index;
Dqn_Str8 name;
Dqn_isize value;
Dqn_usize offset_of;
Dqn_usize size_of;
Dqn_Str8 type_decl;
uint32_t type_enum;
bool is_pointer;
uint16_t array_size;
Dqn_TypeField const * array_size_field;
};
struct Dqn_TypeInfo
{
Dqn_Str8 name;
Dqn_TypeKind kind;
Dqn_usize size_of;
Dqn_TypeField const *fields;
uint16_t fields_count;
};
struct Dqn_TypeGetField
{
bool success;
Dqn_usize index;
Dqn_TypeField *field;
};
Dqn_TypeGetField Dqn_Type_GetField(Dqn_TypeInfo const *type_info, Dqn_Str8 name)
{
Dqn_TypeGetField result = {};
for (Dqn_usize index = 0; index < type_info->fields_count; index++) {
Dqn_TypeField const *type_field = type_info->fields + index;
if (type_field->name == name) {
result.success = true;
result.index = index;
result.field = DQN_CAST(Dqn_TypeField *)type_field;
break;
}
}
return result;
}