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

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