]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Simplify passing parent parser to if statement evaluation
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 May 2021 16:50:34 +0000 (16:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 May 2021 16:50:34 +0000 (16:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y

index 6a9a34753a4613ab00dfb6d1e819c4417a6e3e8c..3f7417993d979fa339f2a7dd746e50942cb6c304 100644 (file)
@@ -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);