Blame SOURCES/0018-parser-add-a-helper-for-concat-expression-handling.patch

f1d1c0
From 160d84fb761c54a5f757aff907fc197d259196bd Mon Sep 17 00:00:00 2001
f1d1c0
From: Phil Sutter <psutter@redhat.com>
f1d1c0
Date: Mon, 17 Feb 2020 15:26:42 +0100
f1d1c0
Subject: [PATCH] parser: add a helper for concat expression handling
f1d1c0
f1d1c0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1795224
f1d1c0
Upstream Status: nftables commit 10f114806ccd9
f1d1c0
f1d1c0
commit 10f114806ccd9d64f9d72eaa813babb04d719688
f1d1c0
Author: Florian Westphal <fw@strlen.de>
f1d1c0
Date:   Wed Dec 11 14:31:44 2019 +0100
f1d1c0
f1d1c0
    parser: add a helper for concat expression handling
f1d1c0
f1d1c0
    Cull the repeated copy&paste snippets and add/use a helper for this.
f1d1c0
f1d1c0
    Signed-off-by: Florian Westphal <fw@strlen.de>
f1d1c0
---
f1d1c0
 src/parser_bison.y | 99 ++++++++++++++++++++++++------------------------------
f1d1c0
 1 file changed, 43 insertions(+), 56 deletions(-)
f1d1c0
f1d1c0
diff --git a/src/parser_bison.y b/src/parser_bison.y
f1d1c0
index 707f467..0fd9b94 100644
f1d1c0
--- a/src/parser_bison.y
f1d1c0
+++ b/src/parser_bison.y
f1d1c0
@@ -102,6 +102,25 @@ static void location_update(struct location *loc, struct location *rhs, int n)
f1d1c0
 	}
f1d1c0
 }
f1d1c0
 
f1d1c0
+static struct expr *handle_concat_expr(const struct location *loc,
f1d1c0
+					 struct expr *expr,
f1d1c0
+					 struct expr *expr_l, struct expr *expr_r,
f1d1c0
+					 struct location loc_rhs[3])
f1d1c0
+{
f1d1c0
+	if (expr->etype != EXPR_CONCAT) {
f1d1c0
+		expr = concat_expr_alloc(loc);
f1d1c0
+		compound_expr_add(expr, expr_l);
f1d1c0
+	} else {
f1d1c0
+		location_update(&expr_r->location, loc_rhs, 2);
f1d1c0
+
f1d1c0
+		expr = expr_l;
f1d1c0
+		expr->location = *loc;
f1d1c0
+	}
f1d1c0
+
f1d1c0
+	compound_expr_add(expr, expr_r);
f1d1c0
+	return expr;
f1d1c0
+}
f1d1c0
+
f1d1c0
 #define YYLLOC_DEFAULT(Current, Rhs, N)	location_update(&Current, Rhs, N)
f1d1c0
 
f1d1c0
 #define symbol_value(loc, str) \
f1d1c0
@@ -1878,20 +1897,12 @@ data_type_atom_expr	:	type_identifier
f1d1c0
 data_type_expr		:	data_type_atom_expr
f1d1c0
 			|	data_type_expr	DOT	data_type_atom_expr
f1d1c0
 			{
f1d1c0
-				if ($1->etype != EXPR_CONCAT) {
f1d1c0
-					$$ = concat_expr_alloc(&@$);
f1d1c0
-					compound_expr_add($$, $1);
f1d1c0
-				} else {
f1d1c0
-					struct location rhs[] = {
f1d1c0
-						[1]	= @2,
f1d1c0
-						[2]	= @3,
f1d1c0
-					};
f1d1c0
-					location_update(&$3->location, rhs, 2);
f1d1c0
-
f1d1c0
-					$$ = $1;
f1d1c0
-					$$->location = @$;
f1d1c0
-				}
f1d1c0
-				compound_expr_add($$, $3);
f1d1c0
+				struct location rhs[] = {
f1d1c0
+					[1]	= @2,
f1d1c0
+					[2]	= @3,
f1d1c0
+				};
f1d1c0
+
f1d1c0
+				$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
f1d1c0
 			}
f1d1c0
 			;
f1d1c0
 
f1d1c0
@@ -2992,20 +3003,12 @@ basic_stmt_expr		:	inclusive_or_stmt_expr
f1d1c0
 concat_stmt_expr	:	basic_stmt_expr
f1d1c0
 			|	concat_stmt_expr	DOT	primary_stmt_expr
f1d1c0
 			{
f1d1c0
-				if ($$->etype != EXPR_CONCAT) {
f1d1c0
-					$$ = concat_expr_alloc(&@$);
f1d1c0
-					compound_expr_add($$, $1);
f1d1c0
-				} else {
f1d1c0
-					struct location rhs[] = {
f1d1c0
-						[1]	= @2,
f1d1c0
-						[2]	= @3,
f1d1c0
-					};
f1d1c0
-					location_update(&$3->location, rhs, 2);
f1d1c0
-
f1d1c0
-					$$ = $1;
f1d1c0
-					$$->location = @$;
f1d1c0
-				}
f1d1c0
-				compound_expr_add($$, $3);
f1d1c0
+				struct location rhs[] = {
f1d1c0
+					[1]	= @2,
f1d1c0
+					[2]	= @3,
f1d1c0
+				};
f1d1c0
+
f1d1c0
+				$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
f1d1c0
 			}
f1d1c0
 			;
f1d1c0
 
f1d1c0
@@ -3525,20 +3528,12 @@ basic_expr		:	inclusive_or_expr
f1d1c0
 concat_expr		:	basic_expr
f1d1c0
 			|	concat_expr		DOT		basic_expr
f1d1c0
 			{
f1d1c0
-				if ($$->etype != EXPR_CONCAT) {
f1d1c0
-					$$ = concat_expr_alloc(&@$);
f1d1c0
-					compound_expr_add($$, $1);
f1d1c0
-				} else {
f1d1c0
-					struct location rhs[] = {
f1d1c0
-						[1]	= @2,
f1d1c0
-						[2]	= @3,
f1d1c0
-					};
f1d1c0
-					location_update(&$3->location, rhs, 2);
f1d1c0
-
f1d1c0
-					$$ = $1;
f1d1c0
-					$$->location = @$;
f1d1c0
-				}
f1d1c0
-				compound_expr_add($$, $3);
f1d1c0
+				struct location rhs[] = {
f1d1c0
+					[1]	= @2,
f1d1c0
+					[2]	= @3,
f1d1c0
+				};
f1d1c0
+
f1d1c0
+				$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
f1d1c0
 			}
f1d1c0
 			;
f1d1c0
 
f1d1c0
@@ -3946,20 +3941,12 @@ basic_rhs_expr		:	inclusive_or_rhs_expr
f1d1c0
 concat_rhs_expr		:	basic_rhs_expr
f1d1c0
 			|	concat_rhs_expr	DOT	basic_rhs_expr
f1d1c0
 			{
f1d1c0
-				if ($$->etype != EXPR_CONCAT) {
f1d1c0
-					$$ = concat_expr_alloc(&@$);
f1d1c0
-					compound_expr_add($$, $1);
f1d1c0
-				} else {
f1d1c0
-					struct location rhs[] = {
f1d1c0
-						[1]	= @2,
f1d1c0
-						[2]	= @3,
f1d1c0
-					};
f1d1c0
-					location_update(&$3->location, rhs, 2);
f1d1c0
-
f1d1c0
-					$$ = $1;
f1d1c0
-					$$->location = @$;
f1d1c0
-				}
f1d1c0
-				compound_expr_add($$, $3);
f1d1c0
+				struct location rhs[] = {
f1d1c0
+					[1]	= @2,
f1d1c0
+					[2]	= @3,
f1d1c0
+				};
f1d1c0
+
f1d1c0
+				$$ = handle_concat_expr(&@$, $$, $1, $3, rhs);
f1d1c0
 			}
f1d1c0
 			;
f1d1c0
 
f1d1c0
-- 
f1d1c0
1.8.3.1
f1d1c0