From c1d5db2a7cacd9b07d2bd9d517d8a5b47a58922e Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 4 Jun 2018 02:02:37 -0700 Subject: [PATCH] Fix problem in config_var --- 4coder_config.cpp | 78 ++++++++++++++++++------------- meta/4ed_meta_generate_parser.cpp | 12 ++--- 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/4coder_config.cpp b/4coder_config.cpp index bec7147f..380b25c1 100644 --- a/4coder_config.cpp +++ b/4coder_config.cpp @@ -680,159 +680,173 @@ typed_array_reference_list(Partition *arena, Config *parsed, Config_Compound *co static bool32 config_has_var(Config *config, String var_name, int32_t subscript){ Config_Get_Result result = config_var(config, var_name, subscript); - return(result.success); + bool32 success = result.success && result.type == ConfigRValueType_NoType; + return(success); } static bool32 config_has_var(Config *config, char *var_name, int32_t subscript){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - return(result.success); + bool32 success = result.success && result.type == ConfigRValueType_NoType; + return(success); } static bool32 config_bool_var(Config *config, String var_name, int32_t subscript, bool32* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Boolean; + if (success){ *var_out = result.boolean; } - return(result.success); + return(success); } static bool32 config_bool_var(Config *config, char *var_name, int32_t subscript, bool32* var_out){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Boolean; + if (success){ *var_out = result.boolean; } - return(result.success); + return(success); } static bool32 config_int_var(Config *config, String var_name, int32_t subscript, int32_t* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Integer; + if (success){ *var_out = result.integer; } - return(result.success); + return(success); } static bool32 config_int_var(Config *config, char *var_name, int32_t subscript, int32_t* var_out){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Integer; + if (success){ *var_out = result.integer; } - return(result.success); + return(success); } static bool32 config_uint_var(Config *config, String var_name, int32_t subscript, uint32_t* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Integer; + if (success){ *var_out = result.uinteger; } - return(result.success); + return(success); } static bool32 config_uint_var(Config *config, char *var_name, int32_t subscript, uint32_t* var_out){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Integer; + if (success){ *var_out = result.uinteger; } - return(result.success); + return(success); } static bool32 config_string_var(Config *config, String var_name, int32_t subscript, String* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_String; + if (success){ *var_out = result.string; } - return(result.success); + return(success); } static bool32 config_string_var(Config *config, char *var_name, int32_t subscript, String* var_out){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_String; + if (success){ *var_out = result.string; } - return(result.success); + return(success); } static bool32 config_placed_string_var(Config *config, String var_name, int32_t subscript, String* var_out, char *space, int32_t space_size){ Config_Get_Result result = config_var(config, var_name, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_String; + if (success){ *var_out = result.string; } - bool32 success = result.success; if (success){ String str = *var_out; *var_out = make_string_cap(space, 0, space_size); copy(var_out, str); } - return(result.success); + return(success); } static bool32 config_placed_string_var(Config *config, char *var_name, int32_t subscript, String* var_out, char *space, int32_t space_size){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_String; + if (success){ *var_out = result.string; } - bool32 success = result.success; if (success){ String str = *var_out; *var_out = make_string_cap(space, 0, space_size); copy(var_out, str); } - return(result.success); + return(success); } static bool32 config_char_var(Config *config, String var_name, int32_t subscript, char* var_out){ Config_Get_Result result = config_var(config, var_name, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Character; + if (success){ *var_out = result.character; } - return(result.success); + return(success); } static bool32 config_char_var(Config *config, char *var_name, int32_t subscript, char* var_out){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Character; + if (success){ *var_out = result.character; } - return(result.success); + return(success); } static bool32 config_compound_var(Config *config, String var_name, int32_t subscript, Config_Compound** var_out){ Config_Get_Result result = config_var(config, var_name, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Compound; + if (success){ *var_out = result.compound; } - return(result.success); + return(success); } static bool32 config_compound_var(Config *config, char *var_name, int32_t subscript, Config_Compound** var_out){ String var_name_str = make_string_slowly(var_name); Config_Get_Result result = config_var(config, var_name_str, subscript); - if (result.success){ + bool32 success = result.success && result.type == ConfigRValueType_Compound; + if (success){ *var_out = result.compound; } - return(result.success); + return(success); } static bool32 diff --git a/meta/4ed_meta_generate_parser.cpp b/meta/4ed_meta_generate_parser.cpp index ccb05b6e..24d6e707 100644 --- a/meta/4ed_meta_generate_parser.cpp +++ b/meta/4ed_meta_generate_parser.cpp @@ -100,16 +100,16 @@ print_config_var(FILE *out, Operation *op){ fprintf(out, "%s", op->code_before); } fprintf(out, "Config_Get_Result result = config_var(config, var_name, subscript);\n"); + fprintf(out, "bool32 success = result.success && result.type == ConfigRValueType_%s;\n", type_names[op->r_type]); if (op->output_type != 0){ - fprintf(out, "if (result.success){\n"); + fprintf(out, "if (success){\n"); fprintf(out, "*var_out = result.%s;\n", op->result_type); fprintf(out, "}\n"); } if (op->code_after != 0){ - fprintf(out, "bool32 success = result.success;\n"); fprintf(out, "%s", op->code_after); } - fprintf(out, "return(result.success);\n"); + fprintf(out, "return(success);\n"); fprintf(out, "}\n\n"); fprintf(out, "static bool32\n"); @@ -127,16 +127,16 @@ print_config_var(FILE *out, Operation *op){ } fprintf(out, "String var_name_str = make_string_slowly(var_name);\n"); fprintf(out, "Config_Get_Result result = config_var(config, var_name_str, subscript);\n"); + fprintf(out, "bool32 success = result.success && result.type == ConfigRValueType_%s;\n", type_names[op->r_type]); if (op->output_type != 0){ - fprintf(out, "if (result.success){\n"); + fprintf(out, "if (success){\n"); fprintf(out, "*var_out = result.%s;\n", op->result_type); fprintf(out, "}\n"); } if (op->code_after != 0){ - fprintf(out, "bool32 success = result.success;\n"); fprintf(out, "%s", op->code_after); } - fprintf(out, "return(result.success);\n"); + fprintf(out, "return(success);\n"); fprintf(out, "}\n\n"); }