Finish metadata system for struct members, fix parsing bugs for consts

This commit is contained in:
doyle 2019-04-05 23:09:07 +11:00
parent 4a794b2492
commit 3c447706c9
3 changed files with 246 additions and 204 deletions

View File

@ -51,24 +51,24 @@
struct DqnInspectMetadata
{
enum DqnInspectMetaType meta_type;
enum DqnInspectDeclType decl_type;
void const *data;
enum struct DqnInspectDeclType decl_type;
enum struct DqnInspectMetaType meta_type;
void const *data;
};
struct DqnInspectMember
{
enum DqnInspectMemberType type_enum;
char const * type;
int type_len;
char const * name;
int name_len;
char const * template_expr;
int template_expr_len;
int array_dimensions; // > 0 means array
enum struct DqnInspectMemberType type_enum;
char const * type;
int type_len;
char const * name;
int name_len;
char const * template_expr;
int template_expr_len;
int array_dimensions; // > 0 means array
DqnInspectMetadata const *metadata;
int metadata_len;
DqnInspectMetadata const *metadata;
int metadata_len;
};
struct DqnInspectStruct
@ -353,10 +353,10 @@ Slice<char> Asprintf(MemArena *arena, char const *fmt, ...)
va_list va;
va_start(va, fmt);
Slice<char> result = {};
result.len = vsnprintf(nullptr, 0, fmt, va) + 1;
result.str = MEM_ARENA_ALLOC_ARRAY(arena, char, result.len);
vsnprintf(result.str, result.len, fmt, va);
result.str[result.len - 1] = 0;
result.len = vsnprintf(nullptr, 0, fmt, va);
result.str = MEM_ARENA_ALLOC_ARRAY(arena, char, result.len + 1);
vsnprintf(result.str, result.len + 1, fmt, va);
result.str[result.len] = 0;
va_end(va);
return result;
}
@ -440,7 +440,7 @@ struct CPPTokeniser
int indent_level;
};
void SprintfToFile(FILE *output_file, int indent_level, char const *fmt, ...)
void FprintfIndented(FILE *output_file, int indent_level, char const *fmt, ...)
{
int const num_spaces = SPACES_PER_INDENT * indent_level;
fprintf(output_file, "%*s", num_spaces, "");
@ -451,14 +451,6 @@ void SprintfToFile(FILE *output_file, int indent_level, char const *fmt, ...)
va_end(va);
}
void SprintfToFileNoIndenting(FILE *output_file, char const *fmt, ...)
{
va_list va;
va_start(va, fmt);
vfprintf(output_file, fmt, va);
va_end(va);
}
CPPToken CPPTokeniser_NextToken(CPPTokeniser *tokeniser, int amount = 1)
{
CPPToken result = tokeniser->tokens[tokeniser->tokens_index];
@ -509,10 +501,10 @@ bool CPPTokeniser_AcceptTokenIfType(CPPTokeniser *tokeniser, CPPTokenType type,
{
CPPToken check = CPPTokeniser_PeekToken(tokeniser);
bool result = (check.type == type);
if (result && token)
if (result)
{
CPPTokeniser_NextToken(tokeniser);
*token = check;
if (token) *token = check;
}
return result;
@ -723,14 +715,31 @@ CPPDeclLinkedList<CPPVariableDecl> *ParseCPPTypeAndVariableDecl(CPPTokeniser *to
Slice<char> comma_to_var_name = {};
comma_to_var_name.str = rewind_token.str + 1;
comma_to_var_name.len = static_cast<int>(variable_name.str - comma_to_var_name.str);
comma_to_var_name = TrimSpaceAround(comma_to_var_name);
comma_to_var_name = TrimSpaceAround(comma_to_var_name);
variable_type_str_lit = Asprintf(&global_main_arena,
"%.*s %.*s",
variable_type.len,
variable_type.str,
comma_to_var_name.len,
comma_to_var_name.str);
if (parse_function_param)
{
variable_type_str_lit = Asprintf(&global_main_arena,
"%.*s",
comma_to_var_name.len,
comma_to_var_name.str);
}
else
{
// If not function param, we're parsing something of the likes
// int var, const *var1
// In which case you want to pull the base variable type,
// crrently stored in variable_type and then you want to
// pull in everything from the comma to var1, to grab the
// pointer modifiers on the type.
variable_type_str_lit = Asprintf(&global_main_arena,
"%.*s %.*s",
variable_type.len,
variable_type.str,
comma_to_var_name.len,
comma_to_var_name.str);
}
}
}
variable_type_str_lit = TrimSpaceAround(variable_type_str_lit);
@ -805,6 +814,7 @@ CPPDeclLinkedList<CPPVariableDecl> *ParseCPPInspectMeta(CPPTokeniser *tokeniser)
if (!ExpectToken(token, CPPTokenType::OpenParen)) return nullptr;
CPPDeclLinkedList<CPPVariableDecl> *result = ParseCPPTypeAndVariableDecl(tokeniser, true);
CPPTokeniser_AcceptTokenIfType(tokeniser, CPPTokenType::CloseParen, nullptr);
return result;
}
@ -1329,6 +1339,28 @@ char *EnumOrStructOrFunctionLexer(CPPTokeniser *tokeniser, char *ptr, b32 lexing
return ptr;
}
void FprintDeclType(FILE *output_file, Slice<char> const type)
{
for (int i = 0; i < type.len; ++i)
{
char ch = type.str[i];
if (ch == '*')
{
char prev_ch = type.str[i - 1];
if (prev_ch != ' ' && prev_ch != '*') fputc('_', output_file);
fputs("Ptr", output_file);
if (i < (type.len - 1)) fputc('_', output_file);
}
else
{
if (ch == ' ') ch = '_';
fputc(ch, output_file);
}
}
fprintf(output_file, "_");
}
int main(int argc, char *argv[])
{
if (argc < 1)
@ -1537,7 +1569,7 @@ int main(int argc, char *argv[])
// NOTE: Build the global definition table
//
int indent_level = 0;
SprintfToFile(output_file, indent_level, "enum struct DqnInspectMemberType\n{\n");
FprintfIndented(output_file, indent_level, "enum struct DqnInspectMemberType\n{\n");
indent_level++;
for (ParsingResult &parsing_results : parsing_results_per_file)
{
@ -1548,12 +1580,12 @@ int main(int argc, char *argv[])
case ParsedCodeType::Enum:
{
ParsedEnum const *parsed_enum = &code.parsed_enum;
SprintfToFile(output_file, indent_level, "%.*s,\n", parsed_enum->name.len, parsed_enum->name.str);
FprintfIndented(output_file, indent_level, "%.*s,\n", parsed_enum->name.len, parsed_enum->name.str);
for (CPPDeclLinkedList<Slice<char>> const *link = parsed_enum->members;
link;
link = link->next)
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"%.*s_%.*s,\n",
parsed_enum->name.len, parsed_enum->name.str,
link->value.len, link->value.str
@ -1566,12 +1598,12 @@ int main(int argc, char *argv[])
case ParsedCodeType::Struct:
{
ParsedStruct const *parsed_struct = &code.parsed_struct;
SprintfToFile(output_file, indent_level, "%.*s,\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "%.*s,\n", parsed_struct->name.len, parsed_struct->name.str);
for (CPPDeclLinkedList<CPPVariableDecl> const *link = parsed_struct->members;
link;
link = link->next)
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"%.*s_%.*s,\n",
parsed_struct->name.len, parsed_struct->name.str,
link->value.name.len, link->value.name.str
@ -1583,7 +1615,7 @@ int main(int argc, char *argv[])
}
}
indent_level--;
SprintfToFile(output_file, indent_level, "};\n\n");
FprintfIndented(output_file, indent_level, "};\n\n");
//
// NOTE: Build the global type table
@ -1614,12 +1646,20 @@ int main(int argc, char *argv[])
{
CPPVariableDecl const *decl = &link->value;
Slice<char> type_name = {};
if (decl->template_expr.len > 0)
type_name = Asprintf(&global_main_arena, "%.*s<%.*s>", decl->type.len, decl->type.str, decl->template_expr.len, decl->template_expr.str);
else
type_name = Asprintf(&global_main_arena, "%.*s", decl->type.len, decl->type.str);
if (decl->template_expr.len > 0) type_name = Asprintf(&global_main_arena, "%.*s<%.*s>", decl->type.len, decl->type.str, decl->template_expr.len, decl->template_expr.str);
else type_name = Asprintf(&global_main_arena, "%.*s", decl->type.len, decl->type.str);
unique_decl_type_table.insert(type_name);
for (CPPDeclLinkedList<CPPVariableDecl> const *meta_link = link->metadata_list;
meta_link;
meta_link = meta_link->next)
{
CPPVariableDecl const *meta_decl = &meta_link->value;
Slice<char> meta_type_name = {};
if (meta_decl->template_expr.len > 0) meta_type_name = Asprintf(&global_main_arena, "%.*s<%.*s>", meta_decl->type.len, meta_decl->type.str, meta_decl->template_expr.len, meta_decl->template_expr.str);
else meta_type_name = Asprintf(&global_main_arena, "%.*s", meta_decl->type.len, meta_decl->type.str);
unique_decl_type_table.insert(meta_type_name);
}
}
}
break;
@ -1627,12 +1667,16 @@ int main(int argc, char *argv[])
}
}
SprintfToFile(output_file, indent_level, "enum struct DqnInspectDeclType\n{\n");
FprintfIndented(output_file, indent_level, "enum struct DqnInspectDeclType\n{\n");
indent_level++;
for(Slice<char> const &type : unique_decl_type_table )
SprintfToFile(output_file, indent_level, "%.*s,\n", type.len, type.str);
{
FprintfIndented(output_file, indent_level, "");
FprintDeclType(output_file, type);
fprintf(output_file, ",\n");
}
indent_level--;
SprintfToFile(output_file, indent_level, "};\n\n");
FprintfIndented(output_file, indent_level, "};\n\n");
}
//
@ -1665,12 +1709,12 @@ int main(int argc, char *argv[])
}
}
SprintfToFile(output_file, indent_level, "enum struct DqnInspectMetaType\n{\n");
FprintfIndented(output_file, indent_level, "enum struct DqnInspectMetaType\n{\n");
indent_level++;
for (Slice<char> const &metadata : unique_meta_types)
SprintfToFile(output_file, indent_level, "%.*s,\n", metadata.len, metadata.str);
FprintfIndented(output_file, indent_level, "%.*s,\n", metadata.len, metadata.str);
indent_level--;
SprintfToFile(output_file, indent_level, "};\n\n");
FprintfIndented(output_file, indent_level, "};\n\n");
}
assert(indent_level == 0);
@ -1687,29 +1731,29 @@ int main(int argc, char *argv[])
// NOTE: Write Stringified Enum Array
//
{
SprintfToFile(output_file, indent_level, "char const *DqnInspect_%.*s_Strings[] = {", parsed_enum->name.len, parsed_enum->name.str);
FprintfIndented(output_file, indent_level, "char const *DqnInspect_%.*s_Strings[] = {", parsed_enum->name.len, parsed_enum->name.str);
indent_level++;
for (CPPDeclLinkedList<Slice<char>> const *link = parsed_enum->members; link; link = link->next)
{
Slice<char> const enum_value = link->value;
SprintfToFileNoIndenting(output_file, "\"%.*s\", ", enum_value.len, enum_value.str);
fprintf(output_file, "\"%.*s\", ", enum_value.len, enum_value.str);
}
indent_level--;
SprintfToFile(output_file, indent_level, "};\n\n");
FprintfIndented(output_file, indent_level, "};\n\n");
}
//
// Write InspectEnumString Function
//
{
SprintfToFile(output_file, indent_level, "char const *DqnInspectEnum_Stringify(%.*s val, int *len = nullptr)\n{\n", parsed_enum->name.len, parsed_enum->name.str);
FprintfIndented(output_file, indent_level, "char const *DqnInspectEnum_Stringify(%.*s val, int *len = nullptr)\n{\n", parsed_enum->name.len, parsed_enum->name.str);
indent_level++;
DEFER
{
SprintfToFile(output_file, indent_level, "return nullptr;\n");
FprintfIndented(output_file, indent_level, "return nullptr;\n");
indent_level--;
SprintfToFile(output_file, indent_level, "}\n\n");
FprintfIndented(output_file, indent_level, "}\n\n");
};
struct SourceCode
@ -1756,8 +1800,8 @@ int main(int argc, char *argv[])
{
Slice<char> enum_value = src_code_ptr->value.enum_value;
int padding = longest_decl_len - src_code_ptr->value.decl.len;
SprintfToFile(output_file, indent_level, "%.*s%*s", src_code_ptr->value.decl.len, src_code_ptr->value.decl.str, padding, "");
SprintfToFileNoIndenting(output_file,
FprintfIndented(output_file, indent_level, "%.*s%*s", src_code_ptr->value.decl.len, src_code_ptr->value.decl.str, padding, "");
fprintf(output_file,
"{ if (len) *len = CHAR_COUNT(\"%.*s\"); return DqnInspect_%.*s_Strings[%d]; }\n",
enum_value.len, enum_value.str,
parsed_enum->name.len, parsed_enum->name.str,
@ -1821,7 +1865,7 @@ int main(int argc, char *argv[])
Slice<char const> const char_type = SLICE_LITERAL("char");
if (metadata.type.len >= char_type.len && strncmp(metadata.type.str, char_type.str, char_type.len) == 0)
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"%.*s DqnInspectMetadata_%.*s(%.*s val)\n{\n",
metadata.type.len, metadata.type.str,
metadata.name.len, metadata.name.str,
@ -1830,9 +1874,9 @@ int main(int argc, char *argv[])
indent_level++;
DEFER
{
SprintfToFile(output_file, indent_level, "return nullptr;\n");
FprintfIndented(output_file, indent_level, "return nullptr;\n");
indent_level--;
SprintfToFile(output_file, indent_level, "}\n\n");
FprintfIndented(output_file, indent_level, "}\n\n");
};
for (CPPDeclToMetaValue const &decl_to_val : metadata.cpp_decl_to_val)
@ -1842,23 +1886,23 @@ int main(int argc, char *argv[])
if (parsed_enum->struct_or_class_decl)
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"if (val == %.*s::%.*s) ",
parsed_enum->name.len, parsed_enum->name.str,
cpp_decl->len, cpp_decl->str);
}
else
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"if (val == %.*s) ",
cpp_decl->len, cpp_decl->str);
}
SprintfToFileNoIndenting(output_file, "{ return %.*s; }\n", value->len, value->str);
fprintf(output_file, "{ return %.*s; }\n", value->len, value->str);
}
}
else
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"bool DqnInspectMetadata_%.*s(%.*s val, %.*s *value)\n{\n",
metadata.name.len, metadata.name.str,
parsed_enum->name.len, parsed_enum->name.str,
@ -1868,9 +1912,9 @@ int main(int argc, char *argv[])
indent_level++;
DEFER
{
SprintfToFile(output_file, indent_level, "return false;\n");
FprintfIndented(output_file, indent_level, "return false;\n");
indent_level--;
SprintfToFile(output_file, indent_level, "}\n\n");
FprintfIndented(output_file, indent_level, "}\n\n");
};
for (CPPDeclToMetaValue const &decl_to_val : metadata.cpp_decl_to_val)
@ -1880,18 +1924,18 @@ int main(int argc, char *argv[])
if (parsed_enum->struct_or_class_decl)
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"if (val == %.*s::%.*s) ",
parsed_enum->name.len, parsed_enum->name.str,
cpp_decl->len, cpp_decl->str);
}
else
{
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"if (val == %.*s) ",
cpp_decl->len, cpp_decl->str);
}
SprintfToFileNoIndenting(output_file, "{ *value = %.*s; return true; }\n", value->len, value->str);
fprintf(output_file, "{ *value = %.*s; return true; }\n", value->len, value->str);
}
}
@ -1914,7 +1958,7 @@ int main(int argc, char *argv[])
metadata_link = metadata_link->next)
{
CPPVariableDecl const *metadata = &metadata_link->value;
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"%.*s DqnInspectMetadata_%.*s_%.*s_%.*s = %.*s;\n",
metadata->type.len, metadata->type.str,
parsed_struct->name.len, parsed_struct->name.str,
@ -1924,10 +1968,10 @@ int main(int argc, char *argv[])
);
}
}
SprintfToFile(output_file, indent_level, "\n");
FprintfIndented(output_file, indent_level, "\n");
//
// NOTE: Write metadata variants for each member
// NOTE: Write metadata for each member
//
for (CPPDeclLinkedList<CPPVariableDecl> const *member = parsed_struct->members; member; member = member->next)
{
@ -1936,7 +1980,7 @@ int main(int argc, char *argv[])
if (!member->metadata_list)
continue;
SprintfToFile(output_file, indent_level,
FprintfIndented(output_file, indent_level,
"DqnInspectMetadata const DqnInspectMetadata_%.*s_%.*s[] =\n{\n",
parsed_struct->name.len, parsed_struct->name.str,
decl->name.len, decl->name.str
@ -1948,79 +1992,79 @@ int main(int argc, char *argv[])
metadata_link = metadata_link->next)
{
CPPVariableDecl const *metadata = &metadata_link->value;
SprintfToFile(output_file, indent_level,
"{ DqnInspectDeclType::%.*s_, DqnInspectMetaType::%.*s, &DqnInspectMetadata_%.*s_%.*s_%.*s},\n",
metadata->type.len, metadata->type.str,
FprintfIndented(output_file, indent_level, "{ DqnInspectDeclType::");
FprintDeclType(output_file, metadata->type);
fprintf(output_file,
", DqnInspectMetaType::%.*s, &DqnInspectMetadata_%.*s_%.*s_%.*s},\n",
metadata->name.len, metadata->name.str,
metadata->name.len, metadata->name.str,
// NOTE: Assign variant data to void *, &DqnInspectMetdata ...
parsed_struct->name.len, parsed_struct->name.str,
decl->name.len, decl->name.str,
metadata->name.len, metadata->name.str
);
// NOTE: Assign variant data to void *, &DqnInspectMetdata ...
parsed_struct->name.len, parsed_struct->name.str,
decl->name.len, decl->name.str,
metadata->name.len, metadata->name.str
);
}
indent_level--;
SprintfToFile(output_file, indent_level, "};\n\n");
FprintfIndented(output_file, indent_level, "};\n\n");
}
//
// NOTE: Write DqnInspectStructMembers Definition
// NOTE: Write DqnInspectMember Definition
//
{
SprintfToFile(output_file, indent_level, "DqnInspectStructMember const DqnInspect_%.*s_StructMembers[] =\n{\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "DqnInspectMember const DqnInspect_%.*s_Members[] =\n{\n", parsed_struct->name.len, parsed_struct->name.str);
indent_level++;
for (CPPDeclLinkedList<CPPVariableDecl> const *member = parsed_struct->members; member; member = member->next)
{
CPPVariableDecl const *decl = &member->value;
SprintfToFile(output_file, indent_level, "{\n");
FprintfIndented(output_file, indent_level, "{\n");
indent_level++;
SprintfToFile(output_file, indent_level, "DqnInspectMemberType::%.*s_%.*s,\n", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
SprintfToFile(output_file, indent_level, "STR_AND_LEN(\"%.*s\"), ", decl->type.len, decl->type.str);
SprintfToFileNoIndenting(output_file, "STR_AND_LEN(\"%.*s\"),\n", decl->name.len, decl->name.str);
FprintfIndented(output_file, indent_level, "DqnInspectMemberType::%.*s_%.*s,\n", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
FprintfIndented(output_file, indent_level, "STR_AND_LEN(\"%.*s\"), ", decl->type.len, decl->type.str);
fprintf(output_file, "STR_AND_LEN(\"%.*s\"),\n", decl->name.len, decl->name.str);
if (decl->template_expr.len <= 0)
SprintfToFile(output_file, indent_level, "nullptr, 0, // template_expr and template_expr_len\n");
FprintfIndented(output_file, indent_level, "nullptr, 0, // template_expr and template_expr_len\n");
else
SprintfToFile(output_file, indent_level, "STR_AND_LEN(\"%.*s\"), // template_expr\n", decl->template_expr.len, decl->template_expr.str);
FprintfIndented(output_file, indent_level, "STR_AND_LEN(\"%.*s\"), // template_expr\n", decl->template_expr.len, decl->template_expr.str);
SprintfToFile(output_file, indent_level, "%d // array_dimensions,\n", decl->array_dimensions);
FprintfIndented(output_file, indent_level, "%d, // array_dimensions\n", decl->array_dimensions);
if (member->metadata_list)
{
SprintfToFile(output_file, indent_level, "DqnInspectVariant_%.*s_%.*s, ", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
SprintfToFileNoIndenting(output_file, "ARRAY_COUNT(DqnInspectVariant_%.*s_%.*s),", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
FprintfIndented(output_file, indent_level, "DqnInspectMetadata_%.*s_%.*s, ", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
fprintf(output_file, "ARRAY_COUNT(DqnInspectMetadata_%.*s_%.*s),", parsed_struct->name.len, parsed_struct->name.str, decl->name.len, decl->name.str);
}
else
{
SprintfToFile(output_file, indent_level, "nullptr, 0,");
FprintfIndented(output_file, indent_level, "nullptr, 0,");
}
SprintfToFileNoIndenting(output_file, " // metadata array\n");
fprintf(output_file, " // metadata array\n");
indent_level--;
SprintfToFile(output_file, indent_level, "},\n");
FprintfIndented(output_file, indent_level, "},\n");
}
indent_level--;
SprintfToFile(output_file, indent_level, "};\n\n");
FprintfIndented(output_file, indent_level, "};\n\n");
}
//
// NOTE: Write DqnInspect_Struct Definition
//
{
SprintfToFile(output_file, indent_level, "DqnInspectStruct const DqnInspect_%.*s_Struct =\n{\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "DqnInspectStruct const DqnInspect_%.*s_Struct =\n{\n", parsed_struct->name.len, parsed_struct->name.str);
indent_level++;
SprintfToFile(output_file, indent_level, "STR_AND_LEN(\"%.*s\"),\n", parsed_struct->name.len, parsed_struct->name.str);
SprintfToFile(output_file, indent_level, "DqnInspect_%.*s_StructMembers, // members\n", parsed_struct->name.len, parsed_struct->name.str);
SprintfToFile(output_file, indent_level, "ARRAY_COUNT(DqnInspect_%.*s_StructMembers) // members_len\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "STR_AND_LEN(\"%.*s\"),\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "DqnInspect_%.*s_Members, // members\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "ARRAY_COUNT(DqnInspect_%.*s_Members) // members_len\n", parsed_struct->name.len, parsed_struct->name.str);
indent_level--;
SprintfToFile(output_file, indent_level, "};\n\n");
FprintfIndented(output_file, indent_level, "};\n\n");
assert(indent_level == 0);
}
@ -2028,13 +2072,13 @@ int main(int argc, char *argv[])
// NOTE: Write DqnInspect_Struct getter
//
{
SprintfToFile(output_file, indent_level, "DqnInspectStruct const *DqnInspect_Struct(%.*s const *)\n", parsed_struct->name.len, parsed_struct->name.str);
SprintfToFile(output_file, indent_level, "{\n");
FprintfIndented(output_file, indent_level, "DqnInspectStruct const *DqnInspect_Struct(%.*s const *)\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "{\n");
indent_level++;
SprintfToFile(output_file, indent_level, "DqnInspect_Struct const *result = &DqnInspect_%.*s_Struct;\n", parsed_struct->name.len, parsed_struct->name.str);
SprintfToFile(output_file, indent_level, "return result;\n");
FprintfIndented(output_file, indent_level, "DqnInspectStruct const *result = &DqnInspect_%.*s_Struct;\n", parsed_struct->name.len, parsed_struct->name.str);
FprintfIndented(output_file, indent_level, "return result;\n");
indent_level--;
SprintfToFile(output_file, indent_level, "}\n\n");
FprintfIndented(output_file, indent_level, "}\n\n");
}
}
@ -2048,14 +2092,14 @@ int main(int argc, char *argv[])
Slice<char> func_name = parsed_func->name;
int spaces_remaining = parsing_results.max_func_return_type_decl_len - return_type.len;
SprintfToFile(output_file, indent_level, "%.*s ", return_type.len, return_type.str);
for (int i = 0; i < spaces_remaining; ++i) SprintfToFileNoIndenting(output_file, " ");
FprintfIndented(output_file, indent_level, "%.*s ", return_type.len, return_type.str);
for (int i = 0; i < spaces_remaining; ++i) fprintf(output_file, " ");
spaces_remaining = parsing_results.max_func_name_decl_len - func_name.len;
SprintfToFile(output_file, indent_level, "%.*s", func_name.len, func_name.str);
for (int i = 0; i < spaces_remaining; ++i) SprintfToFileNoIndenting(output_file, " ");
FprintfIndented(output_file, indent_level, "%.*s", func_name.len, func_name.str);
for (int i = 0; i < spaces_remaining; ++i) fprintf(output_file, " ");
SprintfToFile(output_file, indent_level, "(");
FprintfIndented(output_file, indent_level, "(");
}
for (CPPDeclLinkedList<CPPVariableDecl> *param_link = parsed_func->members; param_link; param_link = param_link->next)
@ -2077,20 +2121,20 @@ int main(int argc, char *argv[])
hack_decl_name = Slice<char>(name_start, static_cast<int>(name_end - name_start));
}
#endif
SprintfToFileNoIndenting(output_file, "%.*s", decl->type.len, decl->type.str);
fprintf(output_file, "%.*s", decl->type.len, decl->type.str);
if (decl->template_expr.len > 0)
SprintfToFileNoIndenting(output_file, "<%.*s>", decl->template_expr.len, decl->template_expr.str);
fprintf(output_file, "<%.*s>", decl->template_expr.len, decl->template_expr.str);
if (decl->name.len > 0)
SprintfToFileNoIndenting(output_file, " %.*s", decl->name.len, decl->name.str);
fprintf(output_file, " %.*s", decl->name.len, decl->name.str);
if (decl->default_value.len > 0)
SprintfToFileNoIndenting(output_file, " = %.*s", decl->default_value.len, decl->default_value.str);
fprintf(output_file, " = %.*s", decl->default_value.len, decl->default_value.str);
if (param_link->next)
SprintfToFileNoIndenting(output_file, ", ", parsed_func->return_type.len, parsed_func->return_type.str, parsed_func->name.len, parsed_func->name.str);
fprintf(output_file, ", ");
}
SprintfToFileNoIndenting(output_file, ");\n");
fprintf(output_file, ");\n");
}
break;
}

View File

@ -11,10 +11,9 @@ enum struct OpenGLShader { Vertex, Count, };
DQN_INSPECT struct SampleStruct
{
// TODO(doyle): This shit not support yet, you can imagine why
int ebo DQN_INSPECT_META(char const *DisplayName = "Element Buffer Object"), vbo, vao DQN_INSPECT_META(char const *DisplayName = "Vertex Array Object", int OpenGLVersion = 330);
const int *const a;
int const *const b, c, *d, *e;
int ebo DQN_INSPECT_META(char const *DisplayName = "Element Buffer Object"), vbo, vao DQN_INSPECT_META(char const *DisplayName = "Vertex Array Object", int OpenGLVersion = 330);
V4 draw_color DQN_INSPECT_META(char const *DisplayName = "HelloWorld");
// #if 0
// #endif

View File

@ -15,15 +15,14 @@
enum struct DqnInspectMemberType
{
SampleStruct,
SampleStruct_ebo,
SampleStruct_vbo,
SampleStruct_vao,
SampleStruct_a,
SampleStruct_b,
SampleStruct_c,
SampleStruct_d,
SampleStruct_e,
SampleStruct_ebo,
SampleStruct_DQN_INSPECT_META,
SampleStruct_DisplayName,
SampleStruct_int,
SampleStruct_draw_color,
SampleStruct_lights,
SampleStruct_camera_matrixes,
@ -48,219 +47,219 @@ enum struct DqnInspectMemberType
enum struct DqnInspectDeclType
{
V3,
V4,
int,
vao,
char,
Array,
int *,
void *,
char **,
int const,
int ******,
int *const,
int const*,
SampleStruct,
char const *,
EnumWithMetadata,
int const *const,
int *********const,
V3_,
V4_,
int_,
Array_,
int_Ptr_,
void_Ptr_,
char_Ptr_Ptr_,
int_const_,
int_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_,
int_Ptr_const_,
int_const_Ptr_,
SampleStruct_,
char_const_Ptr_,
EnumWithMetadata_,
int_const_Ptr_const_,
int_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_Ptr_const_,
};
enum struct DqnInspectMetaType
{
DisplayName,
OpenGLVersion,
};
char const * DqnInspectMetadata_SampleStruct_ebo_DisplayName = "Element Buffer Object";
char const * DqnInspectMetadata_SampleStruct_vao_DisplayName = "Vertex Array Object";
int DqnInspectMetadata_SampleStruct_vao_OpenGLVersion = 330;
char const * DqnInspectMetadata_SampleStruct_draw_color_DisplayName = "HelloWorld";
DqnInspectMetadata const DqnInspectMetadata_SampleStruct_ebo[] =
{
{ DqnInspectDeclType::char const *_, DqnInspectMetaType::DisplayName, &DqnInspectMetadata_SampleStruct_ebo_DisplayName},
{ DqnInspectDeclType::char_const_Ptr_, DqnInspectMetaType::DisplayName, &DqnInspectMetadata_SampleStruct_ebo_DisplayName},
};
DqnInspectMetadata const DqnInspectMetadata_SampleStruct_vao[] =
{
{ DqnInspectDeclType::char_const_Ptr_, DqnInspectMetaType::DisplayName, &DqnInspectMetadata_SampleStruct_vao_DisplayName},
{ DqnInspectDeclType::int_, DqnInspectMetaType::OpenGLVersion, &DqnInspectMetadata_SampleStruct_vao_OpenGLVersion},
};
DqnInspectMetadata const DqnInspectMetadata_SampleStruct_draw_color[] =
{
{ DqnInspectDeclType::char const *_, DqnInspectMetaType::DisplayName, &DqnInspectMetadata_SampleStruct_draw_color_DisplayName},
{ DqnInspectDeclType::char_const_Ptr_, DqnInspectMetaType::DisplayName, &DqnInspectMetadata_SampleStruct_draw_color_DisplayName},
};
DqnInspectStructMember const DqnInspect_SampleStruct_StructMembers[] =
DqnInspectMember const DqnInspect_SampleStruct_Members[] =
{
{
DqnInspectMemberType::SampleStruct_ebo,
STR_AND_LEN("int"), STR_AND_LEN("ebo"),
nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions
DqnInspectMetadata_SampleStruct_ebo, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_ebo), // metadata array
},
{
DqnInspectMemberType::SampleStruct_vbo,
STR_AND_LEN("int"), STR_AND_LEN("vbo"),
nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_vao,
STR_AND_LEN("int"), STR_AND_LEN("vao"),
nullptr, 0, // template_expr and template_expr_len
0, // array_dimensions
DqnInspectMetadata_SampleStruct_vao, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_vao), // metadata array
},
{
DqnInspectMemberType::SampleStruct_a,
STR_AND_LEN("int *const"), STR_AND_LEN("a"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_b,
STR_AND_LEN("int const *const"), STR_AND_LEN("b"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_c,
STR_AND_LEN("int"), STR_AND_LEN("c"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_d,
STR_AND_LEN("int *"), STR_AND_LEN("d"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_e,
STR_AND_LEN("int *"), STR_AND_LEN("e"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_ebo,
STR_AND_LEN("int"), STR_AND_LEN("ebo"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
DqnInspectVariant_SampleStruct_ebo, ARRAY_COUNT(DqnInspectVariant_SampleStruct_ebo), // metadata array
},
{
DqnInspectMemberType::SampleStruct_DQN_INSPECT_META,
STR_AND_LEN("vao"), STR_AND_LEN("DQN_INSPECT_META"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_DisplayName,
STR_AND_LEN("char const *"), STR_AND_LEN("DisplayName"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_int,
STR_AND_LEN("char"), STR_AND_LEN("int"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_draw_color,
STR_AND_LEN("V4"), STR_AND_LEN("draw_color"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
DqnInspectVariant_SampleStruct_draw_color, ARRAY_COUNT(DqnInspectVariant_SampleStruct_draw_color), // metadata array
0, // array_dimensions
DqnInspectMetadata_SampleStruct_draw_color, ARRAY_COUNT(DqnInspectMetadata_SampleStruct_draw_color), // metadata array
},
{
DqnInspectMemberType::SampleStruct_lights,
STR_AND_LEN("Array"), STR_AND_LEN("lights"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_camera_matrixes,
STR_AND_LEN("Array"), STR_AND_LEN("camera_matrixes"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_bitmaps,
STR_AND_LEN("char **"), STR_AND_LEN("bitmaps"),
nullptr, 0, // template_expr and template_expr_len
2 // array_dimensions,
2, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_shaders,
STR_AND_LEN("int"), STR_AND_LEN("shaders"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_win32_handle,
STR_AND_LEN("void *"), STR_AND_LEN("win32_handle"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_lighting_ambient_coeff,
STR_AND_LEN("V3"), STR_AND_LEN("lighting_ambient_coeff"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_draw_call_count,
STR_AND_LEN("int"), STR_AND_LEN("draw_call_count"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_f,
STR_AND_LEN("int"), STR_AND_LEN("f"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_g,
STR_AND_LEN("int const"), STR_AND_LEN("g"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_h,
STR_AND_LEN("int *const"), STR_AND_LEN("h"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_i,
STR_AND_LEN("int const*"), STR_AND_LEN("i"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_j,
STR_AND_LEN("int *********const"), STR_AND_LEN("j"),
nullptr, 0, // template_expr and template_expr_len
9 // array_dimensions,
9, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_k,
STR_AND_LEN("int"), STR_AND_LEN("k"),
nullptr, 0, // template_expr and template_expr_len
0 // array_dimensions,
0, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_l,
STR_AND_LEN("int ******"), STR_AND_LEN("l"),
nullptr, 0, // template_expr and template_expr_len
6 // array_dimensions,
6, // array_dimensions
nullptr, 0, // metadata array
},
{
DqnInspectMemberType::SampleStruct_m,
STR_AND_LEN("int *"), STR_AND_LEN("m"),
nullptr, 0, // template_expr and template_expr_len
1 // array_dimensions,
1, // array_dimensions
nullptr, 0, // metadata array
},
};
@ -268,13 +267,13 @@ DqnInspectStructMember const DqnInspect_SampleStruct_StructMembers[] =
DqnInspectStruct const DqnInspect_SampleStruct_Struct =
{
STR_AND_LEN("SampleStruct"),
DqnInspect_SampleStruct_StructMembers, // members
ARRAY_COUNT(DqnInspect_SampleStruct_StructMembers) // members_len
DqnInspect_SampleStruct_Members, // members
ARRAY_COUNT(DqnInspect_SampleStruct_Members) // members_len
};
DqnInspectStruct const *DqnInspect_Struct(SampleStruct const *)
{
DqnInspect_Struct const *result = &DqnInspect_SampleStruct_Struct;
DqnInspectStruct const *result = &DqnInspect_SampleStruct_Struct;
return result;
}
@ -301,7 +300,7 @@ bool DqnInspectMetadata_Coords(EnumWithMetadata val, V3 *value)
return false;
}
void Function1(int a, float b = {}, char char const * c = nullptr, bool e = false, int f = 1, char char * g = "Hello world");
void Function1(int a, float b = {}, char const * c = nullptr, bool e = false, int f = 1, char * g = "Hello world");
void * Function2(V3 foo = V3(10, 20, 50), V3 bar = {120, 150, 20}, ...);
Array<int const *, 3> const *const Function3(Array<int, 32> const * foobar);
#endif // DQN_INSPECT_DQNINSPECT_TESTDATA_H