Flesh out DqnReflect_StructMember to support metadata
This commit is contained in:
parent
e5e699c05f
commit
dc73407721
@ -9,12 +9,10 @@ enum struct DqnReflect_StructMemberMetadataType { String, Int, Float };
|
|||||||
struct DqnReflect_StructMemberMetadata
|
struct DqnReflect_StructMemberMetadata
|
||||||
{
|
{
|
||||||
DqnReflect_StructMemberMetadataType type;
|
DqnReflect_StructMemberMetadataType type;
|
||||||
union
|
char const *key;
|
||||||
{
|
int key_len;
|
||||||
char *str_val;
|
char const *val_str; // Metadata value is always reflected to a string
|
||||||
int int_val;
|
int val_str_len;
|
||||||
float flt_val;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DqnReflect_StructMember
|
struct DqnReflect_StructMember
|
||||||
@ -24,8 +22,10 @@ struct DqnReflect_StructMember
|
|||||||
char const *name;
|
char const *name;
|
||||||
int name_len;
|
int name_len;
|
||||||
|
|
||||||
|
#if 0
|
||||||
DqnReflect_StructMemberMetadata *metadata;
|
DqnReflect_StructMemberMetadata *metadata;
|
||||||
int metadata_len;
|
int metadata_len;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DqnReflect_Struct
|
struct DqnReflect_Struct
|
||||||
@ -36,6 +36,9 @@ struct DqnReflect_Struct
|
|||||||
int members_len;
|
int members_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// #include "../Data/DqnReflect_TestData.h"
|
||||||
|
// #include "Output.cpp"
|
||||||
|
|
||||||
//
|
//
|
||||||
// HOW TO REFLECT ANNOTATED CODE
|
// HOW TO REFLECT ANNOTATED CODE
|
||||||
// Define in the preprocessor, DQN_REFLECT_IMPLEMENTATION and compile
|
// Define in the preprocessor, DQN_REFLECT_IMPLEMENTATION and compile
|
||||||
@ -531,7 +534,8 @@ CPPReflectMetadataArray ParseCPPReflectMeta(CPPTokeniser *tokeniser)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (token.type != CPPTokenType::EndOfStream && token.type != CPPTokenType::Comma)
|
while (token.type != CPPTokenType::EndOfStream &&
|
||||||
|
(token.type != CPPTokenType::Comma && token.type != CPPTokenType::SemiColon))
|
||||||
token = CPPTokeniser_NextToken(tokeniser);
|
token = CPPTokeniser_NextToken(tokeniser);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -831,29 +835,68 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
|
|||||||
// Write DqnReflect_Struct Definition
|
// Write DqnReflect_Struct Definition
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "DqnReflect_Struct DqnReflect_%.*s_Struct =\n{\n", name.len, name.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "DqnReflect_Struct const DqnReflect_%.*s_Struct =\n{\n", name.len, name.str);
|
||||||
tokeniser->indent_level++;
|
tokeniser->indent_level++;
|
||||||
|
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\", // name \n", name.len, name.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\", // name\n", name.len, name.str);
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"), // name_len \n", name.len, name.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"), // name_len\n", name.len, name.str);
|
||||||
|
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "{ // members \n");
|
CPPTokeniser_SprintfToFile(tokeniser, "{ // members\n");
|
||||||
tokeniser->indent_level++;
|
tokeniser->indent_level++;
|
||||||
for (CPPDeclLinkedList<CPPVariableDecl> const *link = struct_members; link; link = link->next)
|
for (CPPDeclLinkedList<CPPVariableDecl> const *link = struct_members; link; link = link->next)
|
||||||
{
|
{
|
||||||
CPPVariableDecl const *decl = &link->value;
|
CPPVariableDecl const *decl = &link->value;
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "{\n");
|
CPPTokeniser_SprintfToFile(tokeniser, "{\n");
|
||||||
tokeniser->indent_level++;
|
tokeniser->indent_level++;
|
||||||
|
|
||||||
|
// member->type
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\",\n", decl->type.len, decl->type.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\",\n", decl->type.len, decl->type.str);
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"),\n", decl->type.len, decl->type.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"),\n", decl->type.len, decl->type.str);
|
||||||
|
|
||||||
|
// member->name
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\",\n", decl->name.len, decl->name.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\",\n", decl->name.len, decl->name.str);
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"),\n", decl->name.len, decl->name.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"),\n", decl->name.len, decl->name.str);
|
||||||
|
|
||||||
|
// member->metadata
|
||||||
|
if (1)
|
||||||
|
{
|
||||||
|
if (link->metadata_array.len <= 0)
|
||||||
|
{
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "nullptr, // metadata\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "{ // metadata\n");
|
||||||
|
tokeniser->indent_level++;
|
||||||
|
for (CPPReflectMetadataEntry const &entry : link->metadata_array)
|
||||||
|
{
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "{\n");
|
||||||
|
tokeniser->indent_level++;
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "DqnReflect_StructMemberMetadataType::String,\n");
|
||||||
|
|
||||||
|
// metadata->key
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\",\n", entry.key.len, entry.key.str);
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"),\n", entry.key.len, entry.key.str);
|
||||||
|
|
||||||
|
// metadata->value
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\",\n", entry.value.len, entry.value.str);
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "DQN_REFLECT_CHAR_COUNT(\"%.*s\"),\n", entry.value.len, entry.value.str);
|
||||||
|
|
||||||
|
tokeniser->indent_level--;
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "},\n");
|
||||||
|
}
|
||||||
|
tokeniser->indent_level--;
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "},\n");
|
||||||
|
}
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "%d // metadata_len\n", link->metadata_array.len);
|
||||||
|
}
|
||||||
|
|
||||||
tokeniser->indent_level--;
|
tokeniser->indent_level--;
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "},\n");
|
CPPTokeniser_SprintfToFile(tokeniser, "},\n");
|
||||||
}
|
}
|
||||||
tokeniser->indent_level--;
|
tokeniser->indent_level--;
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "},\n");
|
CPPTokeniser_SprintfToFile(tokeniser, "},\n");
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "%d // members_len \n", struct_members_len);
|
CPPTokeniser_SprintfToFile(tokeniser, "%d // members_len\n", struct_members_len);
|
||||||
|
|
||||||
tokeniser->indent_level--;
|
tokeniser->indent_level--;
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "};\n\n");
|
CPPTokeniser_SprintfToFile(tokeniser, "};\n\n");
|
||||||
@ -867,6 +910,7 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
|
|||||||
CPPTokeniser_SprintfToFile(tokeniser, "DqnReflect_Struct const *DqnReflect_GetStruct(%.*s const *val)\n", name.len, name.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "DqnReflect_Struct const *DqnReflect_GetStruct(%.*s const *val)\n", name.len, name.str);
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "{\n");
|
CPPTokeniser_SprintfToFile(tokeniser, "{\n");
|
||||||
tokeniser->indent_level++;
|
tokeniser->indent_level++;
|
||||||
|
CPPTokeniser_SprintfToFile(tokeniser, "(void)val;\n");
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "DqnReflect_Struct const *result = &DqnReflect_%.*s_Struct;\n", name.len, name.str);
|
CPPTokeniser_SprintfToFile(tokeniser, "DqnReflect_Struct const *result = &DqnReflect_%.*s_Struct;\n", name.len, name.str);
|
||||||
CPPTokeniser_SprintfToFile(tokeniser, "return result;\n");
|
CPPTokeniser_SprintfToFile(tokeniser, "return result;\n");
|
||||||
tokeniser->indent_level--;
|
tokeniser->indent_level--;
|
||||||
|
@ -13,6 +13,17 @@ DQN_REFLECT enum struct OpenGLShader
|
|||||||
#define MAXIMUM_MACRO(a, b) (a > b) ? (a) : (b)
|
#define MAXIMUM_MACRO(a, b) (a > b) ? (a) : (b)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct V3
|
||||||
|
{
|
||||||
|
float test;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct V4
|
||||||
|
{
|
||||||
|
float test;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
DQN_REFLECT struct OpenGLState
|
DQN_REFLECT struct OpenGLState
|
||||||
{
|
{
|
||||||
// #if 0
|
// #if 0
|
||||||
|
Loading…
Reference in New Issue
Block a user