Flesh out DqnReflect_StructMember to support metadata

This commit is contained in:
Doyle 2019-02-23 02:25:19 +11:00
parent e5e699c05f
commit dc73407721
2 changed files with 67 additions and 12 deletions

View File

@ -9,12 +9,10 @@ enum struct DqnReflect_StructMemberMetadataType { String, Int, Float };
struct DqnReflect_StructMemberMetadata
{
DqnReflect_StructMemberMetadataType type;
union
{
char *str_val;
int int_val;
float flt_val;
};
char const *key;
int key_len;
char const *val_str; // Metadata value is always reflected to a string
int val_str_len;
};
struct DqnReflect_StructMember
@ -24,8 +22,10 @@ struct DqnReflect_StructMember
char const *name;
int name_len;
#if 0
DqnReflect_StructMemberMetadata *metadata;
int metadata_len;
#endif
};
struct DqnReflect_Struct
@ -36,6 +36,9 @@ struct DqnReflect_Struct
int members_len;
};
// #include "../Data/DqnReflect_TestData.h"
// #include "Output.cpp"
//
// HOW TO REFLECT ANNOTATED CODE
// 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);
return result;
@ -831,7 +835,7 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
// 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++;
CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\", // name\n", name.len, name.str);
@ -844,10 +848,49 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
CPPVariableDecl const *decl = &link->value;
CPPTokeniser_SprintfToFile(tokeniser, "{\n");
tokeniser->indent_level++;
// member->type
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);
// member->name
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);
// 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--;
CPPTokeniser_SprintfToFile(tokeniser, "},\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, "{\n");
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, "return result;\n");
tokeniser->indent_level--;

View File

@ -13,6 +13,17 @@ DQN_REFLECT enum struct OpenGLShader
#define MAXIMUM_MACRO(a, b) (a > b) ? (a) : (b)
#endif
struct V3
{
float test;
};
struct V4
{
float test;
};
DQN_REFLECT struct OpenGLState
{
// #if 0