2024-01-31 12:49:23 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// $$$$$$$$\ $$\ $$\ $$$$$$$\ $$$$$$$$\ $$$$$$\ $$\ $$\ $$$$$$$$\ $$$$$$\
|
|
|
|
// \__$$ __|\$$\ $$ |$$ __$$\ $$ _____| \_$$ _|$$$\ $$ |$$ _____|$$ __$$\
|
|
|
|
// $$ | \$$\ $$ / $$ | $$ |$$ | $$ | $$$$\ $$ |$$ | $$ / $$ |
|
|
|
|
// $$ | \$$$$ / $$$$$$$ |$$$$$\ $$ | $$ $$\$$ |$$$$$\ $$ | $$ |
|
|
|
|
// $$ | \$$ / $$ ____/ $$ __| $$ | $$ \$$$$ |$$ __| $$ | $$ |
|
|
|
|
// $$ | $$ | $$ | $$ | $$ | $$ |\$$$ |$$ | $$ | $$ |
|
|
|
|
// $$ | $$ | $$ | $$$$$$$$\ $$$$$$\ $$ | \$$ |$$ | $$$$$$ |
|
|
|
|
// \__| \__| \__| \________| \______|\__| \__|\__| \______/
|
|
|
|
//
|
|
|
|
// dqn_type_info.h -- C++ type introspection
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2024-02-25 11:37:14 +00:00
|
|
|
enum Dqn_TypeKind
|
2024-01-31 12:49:23 +00:00
|
|
|
{
|
2024-02-25 11:37:14 +00:00
|
|
|
Dqn_TypeKind_Nil,
|
|
|
|
Dqn_TypeKind_Basic,
|
|
|
|
Dqn_TypeKind_Enum,
|
|
|
|
Dqn_TypeKind_Struct,
|
2024-01-31 12:49:23 +00:00
|
|
|
};
|
|
|
|
|
2024-02-25 11:37:14 +00:00
|
|
|
struct Dqn_TypeField
|
2024-01-31 12:49:23 +00:00
|
|
|
{
|
|
|
|
uint16_t index;
|
|
|
|
Dqn_Str8 name;
|
2024-02-25 11:37:14 +00:00
|
|
|
Dqn_isize value;
|
|
|
|
Dqn_usize offset_of;
|
|
|
|
Dqn_usize size_of;
|
|
|
|
Dqn_Str8 type_decl;
|
|
|
|
uint32_t type_enum;
|
2024-01-31 12:49:23 +00:00
|
|
|
bool is_pointer;
|
2024-02-25 11:37:14 +00:00
|
|
|
uint16_t array_size;
|
|
|
|
Dqn_TypeField const * array_size_field;
|
2024-01-31 12:49:23 +00:00
|
|
|
};
|
|
|
|
|
2024-02-25 11:37:14 +00:00
|
|
|
struct Dqn_TypeInfo
|
2024-01-31 12:49:23 +00:00
|
|
|
{
|
2024-02-25 11:37:14 +00:00
|
|
|
Dqn_Str8 name;
|
|
|
|
Dqn_TypeKind kind;
|
|
|
|
Dqn_TypeField const *fields;
|
|
|
|
uint16_t fields_count;
|
2024-01-31 12:49:23 +00:00
|
|
|
};
|
|
|
|
|
2024-02-25 11:37:14 +00:00
|
|
|
struct Dqn_TypeGetField
|
2024-01-31 12:49:23 +00:00
|
|
|
{
|
2024-02-25 11:37:14 +00:00
|
|
|
bool success;
|
|
|
|
Dqn_usize index;
|
|
|
|
Dqn_TypeField *field;
|
2024-01-31 12:49:23 +00:00
|
|
|
};
|
2024-02-25 11:37:14 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|