Support pointer asterisks syntax

This commit is contained in:
Doyle 2019-02-23 14:04:35 +11:00
parent 2acaebaf77
commit a44603d3ca
2 changed files with 75 additions and 57 deletions

View File

@ -103,6 +103,7 @@ struct DqnInspect_StructMember
int type_len;
char const *name;
int name_len;
int array_dimensions; // > 0 means array
DqnInspect_StructMemberMetadata const *metadata;
int metadata_len;
@ -396,8 +397,7 @@ struct CPPVariableDecl
{
StringLiteral type;
StringLiteral name;
b32 is_array;
int array_len;
int array_dimensions;
};
struct CPPTokeniser
@ -765,6 +765,35 @@ void ParseCPPEnum(CPPTokeniser *tokeniser)
}
}
int ConsumeAsterisks(CPPTokeniser *tokeniser)
{
int result = 0;
for (CPPToken peek_token = CPPTokeniser_PeekToken(tokeniser);
peek_token.type == CPPTokenType::Asterisks;
++result)
{
CPPTokeniser_NextToken(tokeniser);
peek_token = CPPTokeniser_PeekToken(tokeniser);
}
return result;
}
b32 ConsumeConstIdentifier(CPPTokeniser *tokeniser)
{
b32 result = false;
for (CPPToken peek_token = CPPTokeniser_PeekToken(tokeniser);
IsIdentifierToken(peek_token, STR_LITERAL("const"));
)
{
result = true;
CPPTokeniser_NextToken(tokeniser);
peek_token = CPPTokeniser_PeekToken(tokeniser);
}
return result;
}
void ParseCPPStruct(CPPTokeniser *tokeniser)
{
CPPToken token = CPPTokeniser_NextToken(tokeniser);
@ -793,60 +822,48 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
{
if (token.type == CPPTokenType::Identifier)
{
if (IsIdentifierToken(token, STR_LITERAL("const")))
token = CPPTokeniser_NextToken(tokeniser);
#if 0
int asterisks_count = 0;
for (;; ++asterisks_count)
ConsumeConstIdentifier(tokeniser);
CPPToken const variable_type = token;
for (int total_asterisks_count = 0;;)
{
Token peek_token = CPPTokeniser_PeekToken(tokeniser);
if (peek_token == CPPTokenType::Asterisks) CPPTokeniser_NextToken(tokeniser);
else break;
}
#endif
CPPToken peek_token = CPPTokeniser_PeekToken(tokeniser);
if (peek_token.type == CPPTokenType::Identifier)
{
CPPToken const variable_type = token;
CPPToken variable_name = peek_token;
if (IsIdentifierToken(variable_name, STR_LITERAL("const")))
total_asterisks_count = ConsumeAsterisks(tokeniser);
if (ConsumeConstIdentifier(tokeniser))
{
token = CPPTokeniser_NextToken(tokeniser);
variable_name = CPPTokeniser_PeekToken(tokeniser);
total_asterisks_count += ConsumeAsterisks(tokeniser);
ConsumeConstIdentifier(tokeniser);
}
for (;;)
CPPToken peek_token = CPPTokeniser_PeekToken(tokeniser);
CPPToken variable_name = peek_token;
if (variable_name.type != CPPTokenType::Identifier)
break;
// Allocate A Member Declaration
auto *link = MEM_ARENA_ALLOC_STRUCT(&global_main_arena, CPPDeclLinkedList<CPPVariableDecl>);
*link = {};
if (!link_iterator) struct_members = link; // Set struct_members to first linked list entry
else link_iterator->next = link;
link_iterator = link;
link->value.type = StringLiteral(variable_type.str, variable_type.len);
link->value.name = StringLiteral(variable_name.str, variable_name.len);
link->value.array_dimensions = total_asterisks_count;
CPPTokeniser_NextToken(tokeniser);
peek_token = CPPTokeniser_PeekToken(tokeniser);
if (IsIdentifierToken(peek_token, STR_LITERAL("DQN_INSPECT_META")))
{
auto *link = MEM_ARENA_ALLOC_STRUCT(&global_main_arena, CPPDeclLinkedList<CPPVariableDecl>);
*link = {};
if (!link_iterator) struct_members = link; // Set struct_members to first linked list entry
else link_iterator->next = link;
link_iterator = link;
link->value.type = StringLiteral(variable_type.str, variable_type.len);
link->value.name = StringLiteral(variable_name.str, variable_name.len);
link->metadata_array = ParseCPPInspectMeta(tokeniser);
peek_token = CPPTokeniser_PeekToken(tokeniser);
}
if (peek_token.type == CPPTokenType::Comma)
{
CPPTokeniser_NextToken(tokeniser);
peek_token = CPPTokeniser_PeekToken(tokeniser);
if (IsIdentifierToken(peek_token, STR_LITERAL("DQN_INSPECT_META")))
{
link->metadata_array = ParseCPPInspectMeta(tokeniser);
peek_token = CPPTokeniser_PeekToken(tokeniser);
}
if (peek_token.type == CPPTokenType::Comma)
{
CPPTokeniser_NextToken(tokeniser);
variable_name = CPPTokeniser_PeekToken(tokeniser);
if (!ExpectToken(variable_name, CPPTokenType::Identifier))
return;
}
else
{
break;
}
}
else
{
break;
}
}
}
@ -909,6 +926,7 @@ void ParseCPPStruct(CPPTokeniser *tokeniser)
CPPTokeniser_SprintfToFile(tokeniser, "STR_AND_LEN(\"%.*s\"),\n", decl->type.len, decl->type.str);
CPPTokeniser_SprintfToFile(tokeniser, "STR_AND_LEN(\"%.*s\"),\n", decl->name.len, decl->name.str);
CPPTokeniser_SprintfToFile(tokeniser, "%d, // array_dimensions\n", decl->array_dimensions);
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);

View File

@ -28,10 +28,7 @@ DQN_INSPECT struct OpenGLState
{
// #if 0
// #endif
const int c;
int const d;
// 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");
// u32 shaders[(int)OpenGLShader::Count];
V4 draw_color DQN_INSPECT_META(DisplayName = "HelloWorld");
@ -41,8 +38,11 @@ DQN_INSPECT struct OpenGLState
// FixedArray<Mat4, 32> camera_matrixes;
int draw_call_count;
// const int *const a;
// int const *const b;
// int *const e;
// int const* f;
const int *const a;
int const *const b, c, const *const d, *const e;
const int f;
int const g;
int *const h;
int const* i;
int *********const j, k, ******l, const *m;
};