Add partial template parsing

This commit is contained in:
Doyle 2019-02-23 14:59:03 +11:00
parent 5297511118
commit db04f7d9f0
2 changed files with 50 additions and 3 deletions

View File

@ -111,6 +111,8 @@ struct DqnInspect_StructMember
char const *name; char const *name;
int name_len; int name_len;
int array_dimensions; // > 0 means array int array_dimensions; // > 0 means array
char const *template_expr;
int template_expr_len;
DqnInspect_StructMemberMetadata const *metadata; DqnInspect_StructMemberMetadata const *metadata;
int metadata_len; int metadata_len;
@ -406,6 +408,7 @@ struct CPPVariableDecl
{ {
StringLiteral type; StringLiteral type;
StringLiteral name; StringLiteral name;
StringLiteral template_expr;
int array_dimensions; int array_dimensions;
}; };
@ -486,6 +489,19 @@ CPPToken *CPPTokeniser_MakeToken(CPPTokeniser *tokeniser)
return result; return result;
} }
void CPPTokeniser_SkipToIndentLevel(CPPTokeniser *tokeniser, int indent_level)
{
assert(tokeniser->indent_level >= indent_level);
if (tokeniser->indent_level == indent_level) return;
for (CPPToken token = CPPTokeniser_NextToken(tokeniser);
tokeniser->indent_level > indent_level && token.type != CPPTokenType::EndOfStream;
)
{
token = CPPTokeniser_NextToken(tokeniser);
}
}
// //
// CPP Parsing Helpers // CPP Parsing Helpers
// //
@ -835,6 +851,32 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
CPPToken const variable_type = token; CPPToken const variable_type = token;
for (int total_asterisks_count = 0;;) for (int total_asterisks_count = 0;;)
{ {
CPPToken peek_token = CPPTokeniser_PeekToken(tokeniser);
StringLiteral variable_template_expr = {};
if (peek_token.type == CPPTokenType::LessThan)
{
token = CPPTokeniser_NextToken(tokeniser);
int template_depth = 1;
while (template_depth != 0 && token.type != CPPTokenType::EndOfStream)
{
token = CPPTokeniser_NextToken(tokeniser);
if (token.type == CPPTokenType::LessThan)
template_depth++;
else if (token.type == CPPTokenType::GreaterThan)
template_depth--;
}
if (template_depth == 0)
{
char *expr_start = peek_token.str + 1;
char *expr_end = token.str - 1;
int expr_len = static_cast<int>(expr_end - expr_start);
variable_template_expr.str = expr_start;
variable_template_expr.len = expr_len;
}
}
total_asterisks_count = ConsumeAsterisks(tokeniser); total_asterisks_count = ConsumeAsterisks(tokeniser);
if (ConsumeConstIdentifier(tokeniser)) if (ConsumeConstIdentifier(tokeniser))
{ {
@ -842,7 +884,7 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
ConsumeConstIdentifier(tokeniser); ConsumeConstIdentifier(tokeniser);
} }
CPPToken peek_token = CPPTokeniser_PeekToken(tokeniser); peek_token = CPPTokeniser_PeekToken(tokeniser);
CPPToken variable_name = peek_token; CPPToken variable_name = peek_token;
if (variable_name.type != CPPTokenType::Identifier) if (variable_name.type != CPPTokenType::Identifier)
break; break;
@ -856,6 +898,7 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
link->value.type = StringLiteral(variable_type.str, variable_type.len); link->value.type = StringLiteral(variable_type.str, variable_type.len);
link->value.name = StringLiteral(variable_name.str, variable_name.len); link->value.name = StringLiteral(variable_name.str, variable_name.len);
link->value.template_expr = variable_template_expr;
link->value.array_dimensions = total_asterisks_count; link->value.array_dimensions = total_asterisks_count;
CPPTokeniser_NextToken(tokeniser); CPPTokeniser_NextToken(tokeniser);
@ -946,6 +989,10 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
CPPTokeniser_SprintfToFileNoIndenting(tokeniser, "STR_AND_LEN(\"%.*s\"),\n", decl->name.len, decl->name.str); CPPTokeniser_SprintfToFileNoIndenting(tokeniser, "STR_AND_LEN(\"%.*s\"),\n", decl->name.len, decl->name.str);
CPPTokeniser_SprintfToFile(tokeniser, "%d, // array_dimensions\n", decl->array_dimensions); CPPTokeniser_SprintfToFile(tokeniser, "%d, // array_dimensions\n", decl->array_dimensions);
if (decl->template_expr.len <= 0) CPPTokeniser_SprintfToFile(tokeniser, "nullptr, // template_expr\n");
else CPPTokeniser_SprintfToFile(tokeniser, "\"%.*s\",\n", decl->template_expr.len, decl->template_expr.str);
CPPTokeniser_SprintfToFile(tokeniser, "%d // template_expr_len\n", decl->template_expr.len);
if (member->metadata_array.len <= 0) CPPTokeniser_SprintfToFile(tokeniser, "nullptr, // metadata\n"); if (member->metadata_array.len <= 0) CPPTokeniser_SprintfToFile(tokeniser, "nullptr, // metadata\n");
else CPPTokeniser_SprintfToFile(tokeniser, "DqnInspect_%.*s_%.*s_StructMemberMetadata,\n", name.len, name.str, decl->name.len, decl->name.str); else CPPTokeniser_SprintfToFile(tokeniser, "DqnInspect_%.*s_%.*s_StructMemberMetadata,\n", name.len, name.str, decl->name.len, decl->name.str);
CPPTokeniser_SprintfToFile(tokeniser, "%d // metadata_len\n", member->metadata_array.len); CPPTokeniser_SprintfToFile(tokeniser, "%d // metadata_len\n", member->metadata_array.len);

View File

@ -28,14 +28,14 @@ DQN_INSPECT struct OpenGLState
{ {
// #if 0 // #if 0
// #endif // #endif
FixedArray<RendererLight, 32> lights;
FixedArray<Mat4, 32> camera_matrixes;
u32 shaders[(int)OpenGLShader::Count]; u32 shaders[(int)OpenGLShader::Count];
void *win32_handle; void *win32_handle;
int ebo DQN_INSPECT_META(DisplayName = "Element Buffer Object"), vbo, vao DQN_INSPECT_META(DisplayName = "Vertex Array Object", OpenGLVersion = "330"); int ebo DQN_INSPECT_META(DisplayName = "Element Buffer Object"), vbo, vao DQN_INSPECT_META(DisplayName = "Vertex Array Object", OpenGLVersion = "330");
V4 draw_color DQN_INSPECT_META(DisplayName = "HelloWorld"); V4 draw_color DQN_INSPECT_META(DisplayName = "HelloWorld");
V3 lighting_ambient_coeff; V3 lighting_ambient_coeff;
char **bitmaps; char **bitmaps;
// FixedArray<RendererLight, 32> lights;
// FixedArray<Mat4, 32> camera_matrixes;
int draw_call_count; int draw_call_count;
const int *const a; const int *const a;