Commit 8c62d48c0c90afaed8045e67da2899d518fe87ac

Ran Benita 2019-11-12T19:16:08

ast-build: get rid of unhelpful macro Straightforward code is better here. Signed-off-by: Ran Benita <ran@unusedvar.com>

diff --git a/src/xkbcomp/ast-build.c b/src/xkbcomp/ast-build.c
index 365ff51..d01aa24 100644
--- a/src/xkbcomp/ast-build.c
+++ b/src/xkbcomp/ast-build.c
@@ -84,15 +84,12 @@ ExprCreate(enum expr_op_type op, enum expr_value_type type, size_t size)
     return expr;
 }
 
-#define EXPR_CREATE(type_, name_, op_, value_type_) \
-    ExprDef *name_ = ExprCreate(op_, value_type_, sizeof(type_)); \
-    if (!name_) \
-        return NULL;
-
 ExprDef *
 ExprCreateString(xkb_atom_t str)
 {
-    EXPR_CREATE(ExprString, expr, EXPR_VALUE, EXPR_TYPE_STRING);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_STRING, sizeof(ExprString));
+    if (!expr)
+        return NULL;
     expr->string.str = str;
     return expr;
 }
@@ -100,7 +97,9 @@ ExprCreateString(xkb_atom_t str)
 ExprDef *
 ExprCreateInteger(int ival)
 {
-    EXPR_CREATE(ExprInteger, expr, EXPR_VALUE, EXPR_TYPE_INT);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_INT, sizeof(ExprInteger));
+    if (!expr)
+        return NULL;
     expr->integer.ival = ival;
     return expr;
 }
@@ -108,14 +107,18 @@ ExprCreateInteger(int ival)
 ExprDef *
 ExprCreateFloat(void)
 {
-    EXPR_CREATE(ExprFloat, expr, EXPR_VALUE, EXPR_TYPE_FLOAT);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_FLOAT, sizeof(ExprFloat));
+    if (!expr)
+        return NULL;
     return expr;
 }
 
 ExprDef *
 ExprCreateBoolean(bool set)
 {
-    EXPR_CREATE(ExprBoolean, expr, EXPR_VALUE, EXPR_TYPE_BOOLEAN);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_BOOLEAN, sizeof(ExprBoolean));
+    if (!expr)
+        return NULL;
     expr->boolean.set = set;
     return expr;
 }
@@ -123,7 +126,9 @@ ExprCreateBoolean(bool set)
 ExprDef *
 ExprCreateKeyName(xkb_atom_t key_name)
 {
-    EXPR_CREATE(ExprKeyName, expr, EXPR_VALUE, EXPR_TYPE_KEYNAME);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_KEYNAME, sizeof(ExprKeyName));
+    if (!expr)
+        return NULL;
     expr->key_name.key_name = key_name;
     return expr;
 }
@@ -131,7 +136,9 @@ ExprCreateKeyName(xkb_atom_t key_name)
 ExprDef *
 ExprCreateIdent(xkb_atom_t ident)
 {
-    EXPR_CREATE(ExprIdent, expr, EXPR_IDENT, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN, sizeof(ExprIdent));
+    if (!expr)
+        return NULL;
     expr->ident.ident = ident;
     return expr;
 }
@@ -140,7 +147,9 @@ ExprDef *
 ExprCreateUnary(enum expr_op_type op, enum expr_value_type type,
                 ExprDef *child)
 {
-    EXPR_CREATE(ExprUnary, expr, op, type);
+    ExprDef *expr = ExprCreate(op, type, sizeof(ExprUnary));
+    if (!expr)
+        return NULL;
     expr->unary.child = child;
     return expr;
 }
@@ -148,7 +157,9 @@ ExprCreateUnary(enum expr_op_type op, enum expr_value_type type,
 ExprDef *
 ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right)
 {
-    EXPR_CREATE(ExprBinary, expr, op, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(op, EXPR_TYPE_UNKNOWN, sizeof(ExprBinary));
+    if (!expr)
+        return NULL;
 
     if (op == EXPR_ASSIGN || left->expr.value_type == EXPR_TYPE_UNKNOWN)
         expr->expr.value_type = right->expr.value_type;
@@ -164,7 +175,9 @@ ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right)
 ExprDef *
 ExprCreateFieldRef(xkb_atom_t element, xkb_atom_t field)
 {
-    EXPR_CREATE(ExprFieldRef, expr, EXPR_FIELD_REF, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_FIELD_REF, EXPR_TYPE_UNKNOWN, sizeof(ExprFieldRef));
+    if (!expr)
+        return NULL;
     expr->field_ref.element = element;
     expr->field_ref.field = field;
     return expr;
@@ -173,7 +186,9 @@ ExprCreateFieldRef(xkb_atom_t element, xkb_atom_t field)
 ExprDef *
 ExprCreateArrayRef(xkb_atom_t element, xkb_atom_t field, ExprDef *entry)
 {
-    EXPR_CREATE(ExprArrayRef, expr, EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN, sizeof(ExprArrayRef));
+    if (!expr)
+        return NULL;
     expr->array_ref.element = element;
     expr->array_ref.field = field;
     expr->array_ref.entry = entry;
@@ -183,7 +198,9 @@ ExprCreateArrayRef(xkb_atom_t element, xkb_atom_t field, ExprDef *entry)
 ExprDef *
 ExprCreateAction(xkb_atom_t name, ExprDef *args)
 {
-    EXPR_CREATE(ExprAction, expr, EXPR_ACTION_DECL, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_ACTION_DECL, EXPR_TYPE_UNKNOWN, sizeof(ExprAction));
+    if (!expr)
+        return NULL;
     expr->action.name = name;
     expr->action.args = args;
     return expr;
@@ -192,7 +209,9 @@ ExprCreateAction(xkb_atom_t name, ExprDef *args)
 ExprDef *
 ExprCreateKeysymList(xkb_keysym_t sym)
 {
-    EXPR_CREATE(ExprKeysymList, expr, EXPR_KEYSYM_LIST, EXPR_TYPE_SYMBOLS);
+    ExprDef *expr = ExprCreate(EXPR_KEYSYM_LIST, EXPR_TYPE_SYMBOLS, sizeof(ExprKeysymList));
+    if (!expr)
+        return NULL;
 
     darray_init(expr->keysym_list.syms);
     darray_init(expr->keysym_list.symsMapIndex);