mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
gen_c11 segregated: metaprogram now splits stb_sprintf_h content between metadesk_deps header and source
This commit is contained in:
+63
-17
@@ -7,7 +7,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef GENERATE_SINGLEHEADER
|
||||
#define GENERATE_SINGLEHEADER 1
|
||||
#define GENERATE_SINGLEHEADER 0
|
||||
#endif
|
||||
|
||||
#define path_refactor_script path_gen_c11 "c11.refactor"
|
||||
@@ -28,20 +28,6 @@ int main()
|
||||
|
||||
register_library_macros();
|
||||
|
||||
gen_CodeBody tb_stb_printf_h_parsed = gen_parse_file(path_third_party "stb/stb_sprintf.h");
|
||||
gen_CodeBody tb_stb_printf_header = gen_def_body(CT_Global_Body);
|
||||
gen_CodeBody tb_stb_printf_source = gen_def_body(CT_Global_Body);
|
||||
|
||||
for (gen_Code stb_code = gen_iterator(CodeBody, tb_stb_printf_h_parsed, stb_code)) switch(stb_code->Type)
|
||||
{
|
||||
case CT_Preprocess_Define:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
gen_Str generation_notice = lit(
|
||||
"// This file was generated automatially by metadesk's gen_c11.c "
|
||||
"(See: https://github.com/Ed94/metadesk/tree/master)\n\n"
|
||||
@@ -122,6 +108,65 @@ int main()
|
||||
#pragma region Refactored / Formatted
|
||||
gen_Code r_tp_stb_sprintf_h = refactor(tp_stb_sprintf_h);
|
||||
|
||||
gen_CodeBody r_tp_stb_sprintf_h_parsed = gen_parse_global_body(tp_stb_sprintf_h->Content);
|
||||
gen_CodeBody r_tp_stb_sprintf_header = gen_def_body(CT_Global_Body);
|
||||
gen_CodeBody r_tp_stb_sprintf_source = gen_def_body(CT_Global_Body);
|
||||
|
||||
gen_b32 past_header = false;
|
||||
gen_b32 past_source = false;
|
||||
for (gen_Code stb_code = gen_iterator(CodeBody, r_tp_stb_sprintf_h_parsed, stb_code)) switch(stb_code->Type)
|
||||
{
|
||||
case CT_Preprocess_IfNotDef:
|
||||
{
|
||||
gen_CodePreprocessCond cond_if = gen_cast(gen_CodePreprocessCond, stb_code);
|
||||
if (gen_str_are_equal(cond_if->Content, lit("STB_SPRINTF_H_INCLUDE")))
|
||||
{
|
||||
gen_body_append(r_tp_stb_sprintf_header, cond_if);
|
||||
|
||||
gen_Code header_code = gen_next_CodeBody(r_tp_stb_sprintf_h_parsed, stb_code);
|
||||
while (header_code->Type != CT_Comment || !gen_str_contains(header_code->Content, lit("STB_SPRINTF_H_INCLUDE")))
|
||||
{
|
||||
gen_body_append(r_tp_stb_sprintf_header, header_code);
|
||||
header_code = gen_next_CodeBody(r_tp_stb_sprintf_h_parsed, header_code);
|
||||
}
|
||||
// should be: <// STB_SPRINTF_H_INCLUDE>
|
||||
gen_body_append(r_tp_stb_sprintf_header, header_code);
|
||||
past_header = true;
|
||||
|
||||
stb_code = gen_next_CodeBody(r_tp_stb_sprintf_h_parsed, header_code);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
gen_CodePreprocessCond cond_if = gen_cast(gen_CodePreprocessCond, stb_code);
|
||||
if (gen_str_are_equal(cond_if->Content, lit("STB_SPRINTF_IMPLEMENTATION")))
|
||||
{
|
||||
gen_body_append(r_tp_stb_sprintf_source, cond_if);
|
||||
|
||||
gen_Code source_code = gen_next_CodeBody(r_tp_stb_sprintf_h_parsed, stb_code);
|
||||
while (source_code->Type != CT_Comment || !gen_str_contains(source_code->Content, lit("STB_SPRINTF_IMPLEMENTATION")))
|
||||
{
|
||||
gen_body_append(r_tp_stb_sprintf_source, source_code);
|
||||
source_code = gen_next_CodeBody(r_tp_stb_sprintf_h_parsed, source_code);
|
||||
}
|
||||
// should be: <// STB_SPRINTF_IMPLEMENTATION>
|
||||
gen_body_append(r_tp_stb_sprintf_source, source_code);
|
||||
past_source = true;
|
||||
|
||||
stb_code = gen_next_CodeBody(r_tp_stb_sprintf_h_parsed, source_code);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( ! past_header || past_source) {
|
||||
gen_body_append(r_tp_stb_sprintf_header, stb_code);
|
||||
}
|
||||
gen_body_append(r_tp_stb_sprintf_source, stb_code);
|
||||
break;
|
||||
}
|
||||
|
||||
gen_Code r_base_context_cracking_h = refactor(base_context_cracking_h);
|
||||
gen_Code r_base_platform_h = refactor(base_platform_h);
|
||||
gen_Code r_base_linkage_h = refactor(base_linkage_h);
|
||||
@@ -393,7 +438,7 @@ int main()
|
||||
preprocess_endif();
|
||||
new_line();
|
||||
|
||||
print_section(r_tp_stb_sprintf_h, lit("STB snprintf Header"));
|
||||
print_section(refactor_and_format(r_tp_stb_sprintf_header), lit("STB snprintf Header"));
|
||||
new_line();
|
||||
|
||||
print_section(r_base_base_types_h, lit("Types"));
|
||||
@@ -490,7 +535,8 @@ int main()
|
||||
preprocess_endif();
|
||||
new_line();
|
||||
|
||||
print_section(r_tp_stb_sprintf_h, lit("STB snprintf Header"));
|
||||
define(lit("STB_SPRINTF_IMPLEMENTATION"), MT_Statement);
|
||||
print_section(refactor_and_format(r_tp_stb_sprintf_source), lit("STB snprintf Source"));
|
||||
new_line();
|
||||
|
||||
print_section(r_base_platform_c, lit("Platform"));
|
||||
|
||||
@@ -70,14 +70,14 @@ void register_library_macros()
|
||||
gen_register_macros( args(
|
||||
((gen_Macro) { lit("STB_SPRINTF_H_INCLUDE"), MT_Statement, }),
|
||||
((gen_Macro) { lit("STBSP__ASAN"), MT_Statement, MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__PUBLICDEC"), MT_Statement, MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__ATTRIBUTE_FORMAT"), MT_Statement, MF_Functional | MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__PUBLICDEC"), MT_Expression, MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__ATTRIBUTE_FORMAT"), MT_Expression, MF_Functional | MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__NOTUSED"), MT_Expression, MF_Functional | MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__NOTUSED"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("STB_SPRINTF_MIN"), MT_Expression, MF_Allow_As_Identifier }),
|
||||
((gen_Macro) { lit("STB_SPRINTF_DECORATE"), MT_Expression, MF_Functional | MF_Allow_As_Identifier }),
|
||||
((gen_Macro) { lit("STB_SPRINTF_MSVC_MODE"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__PUBLICDEF"), MT_Statement, MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__PUBLICDEF"), MT_Expression, MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__UNALIGNED"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("STBSP__SPECIAL"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__LEFTJUST"), MT_Expression, }),
|
||||
|
||||
Vendored
+5
-4
@@ -10105,7 +10105,7 @@ inline void gen_body_to_strbuilder_ref(gen_CodeBody body, gen_StrBuilder* result
|
||||
{
|
||||
gen_code_to_strbuilder_ref(curr, result);
|
||||
// gen_strbuilder_append_fmt( result, "%SB", gen_code_to_strbuilder(curr) );
|
||||
++curr;
|
||||
curr = curr->Next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16069,13 +16069,13 @@ void gen_body_to_strbuilder_export( gen_CodeBody body, gen_StrBuilder* result )
|
||||
GEN_ASSERT(result != gen_nullptr);
|
||||
gen_strbuilder_append_fmt( result, "export\n{\n" );
|
||||
|
||||
gen_Code curr = gen_cast(gen_Code, body);
|
||||
gen_Code curr = body->Front;
|
||||
gen_s32 left = body->NumEntries;
|
||||
while ( left-- )
|
||||
{
|
||||
gen_code_to_strbuilder_ref(curr, result);
|
||||
// gen_strbuilder_append_fmt( result, "%SB", gen_code_to_strbuilder(curr) );
|
||||
++curr;
|
||||
curr = curr->Next;
|
||||
}
|
||||
|
||||
gen_strbuilder_append_fmt( result, "};\n" );
|
||||
@@ -23953,7 +23953,7 @@ gen_internal gen_neverinline gen_CodeBody gen_parse_global_nspace(gen_CodeType w
|
||||
|
||||
case Tok_Preprocess_Macro_Expr:
|
||||
{
|
||||
if (gen_tok_is_attribute(currtok))
|
||||
if (!gen_tok_is_attribute(currtok))
|
||||
{
|
||||
gen_log_failure("Unbounded macro expression residing in class/struct body\n%S", gen_parser_to_strbuilder(gen__ctx->parser));
|
||||
return gen_InvalidCode;
|
||||
@@ -25364,6 +25364,7 @@ gen_internal gen_Code gen_parse_simple_preprocess(gen_TokType which)
|
||||
|
||||
Leave_Scope_Early:
|
||||
gen_Code result = gen_untyped_str(full_macro.Text);
|
||||
// gen_Code result = gen_untyped_str(gen_strbuilder_to_str(gen_strbuilder_fmt_buf(gen__ctx->Allocator_Temp, "%S ", full_macro.Text)));
|
||||
gen__ctx->parser.Scope->Name = full_macro.Text;
|
||||
|
||||
gen_parser_pop(&gen__ctx->parser);
|
||||
|
||||
Reference in New Issue
Block a user