Add macro for inspecting prototypes, fix string default val bug

This commit is contained in:
Doyle 2019-02-26 02:29:31 +11:00
parent b298eae175
commit a325ea6130
2 changed files with 63 additions and 35 deletions

View File

@ -222,6 +222,7 @@ DqnInspect_Struct const *DqnInspect_GetStruct(OpenGLState const *val)
#define DQN_INSPECT
#define DQN_INSPECT_META(...)
#define DQN_INSPECT_GENERATE_PROTOTYPE(...)
enum DqnInspect_StructMemberMetadataType { String, Int, Float };
@ -1270,6 +1271,11 @@ void ParseCPPInspectPrototype(CPPTokeniser *tokeniser)
token = CPPTokeniser_NextToken(tokeniser);
char *default_param_start = token.str;
// NOTE(doyle): Include the quotes in the param value
CPPToken prev_token = CPPTokeniser_PrevToken(tokeniser);
if (prev_token.type == CPPTokenType::String)
default_param_start--;
SkipFunctionParam(tokeniser);
CPPToken peek_token = CPPTokeniser_PeekToken(tokeniser);
if (peek_token.type != CPPTokenType::Comma && peek_token.type != CPPTokenType::CloseParen)
@ -1591,6 +1597,8 @@ int main(int argc, char *argv[])
file_include_contents_hash_define_len = extracted_file_name_len;
}
if (mode == InspectMode::Code)
{
fprintf(output_file,
"//\n"
"// %s\n"
@ -1610,6 +1618,24 @@ int main(int argc, char *argv[])
file_include_contents_hash_define_len,
file_include_contents_hash_define
);
}
else
{
fprintf(output_file,
"//\n"
"// %s\n"
"//\n"
"\n"
"#ifndef DQN_INSPECT_%.*s\n"
"#define DQN_INSPECT_%.*s\n"
"\n",
file_name,
file_include_contents_hash_define_len,
file_include_contents_hash_define,
file_include_contents_hash_define_len,
file_include_contents_hash_define
);
}
CPPTokeniser tokeniser = {};
tokeniser.spaces_per_indent = 4;
@ -1697,6 +1723,8 @@ int main(int argc, char *argv[])
break;
}
if (mode == InspectMode::Code)
{
fprintf(output_file,
"\n#undef ARRAY_COUNT\n"
"#undef CHAR_COUNT\n"
@ -1705,6 +1733,14 @@ int main(int argc, char *argv[])
file_include_contents_hash_define_len,
file_include_contents_hash_define);
}
else
{
fprintf(output_file,
"\n#endif // DQN_INSPECT_%.*s\n\n",
file_include_contents_hash_define_len,
file_include_contents_hash_define);
}
}
fclose(output_file);

View File

@ -7,11 +7,6 @@
#ifndef DQN_INSPECT_DQNINSPECT_TESTDATA_H
#define DQN_INSPECT_DQNINSPECT_TESTDATA_H
// NOTE: These macros are undefined at the end of the file so to not pollute namespace
#define ARRAY_COUNT(array) sizeof(array)/sizeof((array)[0])
#define CHAR_COUNT(str) (ARRAY_COUNT(str) - 1)
#define STR_AND_LEN(str) str, CHAR_COUNT(str)
char const *DqnInspect_OpenGLShader_Strings[] = {"Invalid", "Rect", "Text", "Count", };
char const *DqnInspect_EnumString(OpenGLShader val)
@ -233,10 +228,7 @@ DqnInspect_Struct const *DqnInspect_GetStruct(OpenGLState const *val)
return result;
}
void RenderRect(V3 pos, V2 size = {}, char const *texture = nullptr, bool depth_test = false, int type = 1, char *user_msg = Hello world");
void RenderRect(V3 pos, V2 size = {}, char const *texture = nullptr, bool depth_test = false, int type = 1, char *user_msg = "Hello world");
#undef ARRAY_COUNT
#undef CHAR_COUNT
#undef STR_AND_LEN
#endif // DQN_INSPECT_DQNINSPECT_TESTDATA_H