From: Michael Tremer Date: Thu, 20 May 2021 16:50:34 +0000 (+0000) Subject: parser: Simplify passing parent parser to if statement evaluation X-Git-Tag: 0.9.28~1285^2~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ac3e9f3d3a0568f02fe4a2bcf7519371ca2daf1;p=pakfire.git parser: Simplify passing parent parser to if statement evaluation Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 6a9a34753..3f7417993 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -87,7 +87,7 @@ static void yyerror(yyscan_t* scanner, Pakfire pakfire, PakfireParser* parser, } } -static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser parser, const enum operator op, +static PakfireParser make_if_stmt(Pakfire pakfire, const enum operator op, const char* val1, const char* val2, PakfireParser if_block, PakfireParser else_block); static int pakfire_parser_new_declaration( @@ -360,7 +360,7 @@ subparser_name : T_SUBPARSER if_stmt : T_IF T_STRING T_EQUALS T_STRING T_EOL subgrammar else_stmt T_END T_EOL { - $$ = make_if_stmt(pakfire, parent, OP_EQUALS, $2, $4, $6, $7); + $$ = make_if_stmt(pakfire, OP_EQUALS, $2, $4, $6, $7); if ($6) pakfire_parser_unref($6); @@ -440,7 +440,7 @@ int pakfire_parser_parse_data(PakfireParser parent, const char* data, size_t len return r; } -static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser parser, const enum operator op, +static PakfireParser make_if_stmt(Pakfire pakfire, const enum operator op, const char* val1, const char* val2, PakfireParser if_block, PakfireParser else_block) { switch (op) { case OP_EQUALS: @@ -448,11 +448,13 @@ static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser parser, const e break; } - DEBUG(pakfire, " parent = %p, if = %p, else = %p\n", parser, if_block, else_block); + PakfireParser parent = pakfire_parser_get_parent(if_block); + + DEBUG(pakfire, " parent = %p, if = %p, else = %p\n", parent, if_block, else_block); // Expand values - char* v1 = pakfire_parser_expand(parser, NULL, val1); - char* v2 = pakfire_parser_expand(parser, NULL, val2); + char* v1 = pakfire_parser_expand(parent, NULL, val1); + char* v2 = pakfire_parser_expand(parent, NULL, val2); PakfireParser result = NULL; @@ -470,6 +472,7 @@ static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser parser, const e free(v1); free(v2); + pakfire_parser_unref(parent); if (result) pakfire_parser_ref(result);