shithub: rgbds

Download patch

ref: ba051e10fbe2c339f78359eb3a9c1f0d8683d69b
parent: 9fee0603b13309fce63aea2360e7ba898608b322
author: ISSOtm <eldredhabert0@gmail.com>
date: Sun Sep 27 05:24:24 EDT 2020

Factor printing assert failures into functions

Saves some code duplication

--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -462,6 +462,36 @@
 	dest[destIndex] = 0;
 }
 
+static inline void failAssert(enum AssertionType type)
+{
+	switch (type) {
+		case ASSERT_FATAL:
+			fatalerror("Assertion failed");
+		case ASSERT_ERROR:
+			yyerror("Assertion failed");
+			break;
+		case ASSERT_WARN:
+			warning(WARNING_ASSERT,
+				"Assertion failed");
+			break;
+	}
+}
+
+static inline void failAssertMsg(enum AssertionType type, char const *msg)
+{
+	switch (type) {
+		case ASSERT_FATAL:
+			fatalerror("Assertion failed: %s", msg);
+		case ASSERT_ERROR:
+			yyerror("Assertion failed: %s", msg);
+			break;
+		case ASSERT_WARN:
+			warning(WARNING_ASSERT,
+				"Assertion failed: %s", msg);
+			break;
+	}
+}
+
 %}
 
 %union
@@ -817,17 +847,7 @@
 					yyerror("Assertion creation failed: %s",
 						strerror(errno));
 			} else if ($3.nVal == 0) {
-				switch ($2) {
-					case ASSERT_FATAL:
-						fatalerror("Assertion failed");
-					case ASSERT_ERROR:
-						yyerror("Assertion failed");
-						break;
-					case ASSERT_WARN:
-						warning(WARNING_ASSERT,
-							"Assertion failed");
-						break;
-				}
+				failAssert($2);
 			}
 			rpn_Free(&$3);
 		}
@@ -839,57 +859,19 @@
 					yyerror("Assertion creation failed: %s",
 						strerror(errno));
 			} else if ($3.nVal == 0) {
-				switch ($2) {
-					case ASSERT_FATAL:
-						fatalerror("Assertion failed: %s",
-							   $5);
-					case ASSERT_ERROR:
-						yyerror("Assertion failed: %s",
-							$5);
-						break;
-					case ASSERT_WARN:
-						warning(WARNING_ASSERT,
-							"Assertion failed: %s",
-							$5);
-						break;
-				}
+				failAssertMsg($2, $5);
 			}
 			rpn_Free(&$3);
 		}
 		| T_POP_STATIC_ASSERT assert_type const
 		{
-			if ($3 == 0) {
-				switch ($2) {
-					case ASSERT_FATAL:
-						fatalerror("Assertion failed");
-					case ASSERT_ERROR:
-						yyerror("Assertion failed");
-						break;
-					case ASSERT_WARN:
-						warning(WARNING_ASSERT,
-							"Assertion failed");
-						break;
-				}
-			}
+			if ($3 == 0)
+				failAssert($2);
 		}
 		| T_POP_STATIC_ASSERT assert_type const ',' string
 		{
-			if ($3 == 0) {
-				switch ($2) {
-					case ASSERT_FATAL:
-						fatalerror("Assertion failed: %s",
-							   $5);
-					case ASSERT_ERROR:
-						yyerror("Assertion failed: %s",
-							$5);
-						break;
-					case ASSERT_WARN:
-						warning(WARNING_ASSERT,
-							"Assertion failed: %s",
-							$5);
-						break;
-				}
-			}
+			if ($3 == 0)
+				failAssertMsg($2, $5);
 		}
 ;