expr: add constructor for boolean expressions Also add a 'bool set' to the ExprDef union, instead of using 'ival' as a bool. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 3522dc8..37b9338 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -60,14 +60,14 @@ static const ExprDef constTrue = {
.common = { .type = STMT_EXPR, .next = NULL },
.op = EXPR_VALUE,
.value_type = EXPR_TYPE_BOOLEAN,
- .value = { .ival = 1 },
+ .value = { .set = true },
};
static const ExprDef constFalse = {
.common = { .type = STMT_EXPR, .next = NULL },
.op = EXPR_VALUE,
.value_type = EXPR_TYPE_BOOLEAN,
- .value = { .ival = 0 },
+ .value = { .set = false },
};
enum action_field {
diff --git a/src/xkbcomp/ast-build.c b/src/xkbcomp/ast-build.c
index 2130e26..6330fb9 100644
--- a/src/xkbcomp/ast-build.c
+++ b/src/xkbcomp/ast-build.c
@@ -110,6 +110,18 @@ ExprCreateInteger(int ival)
}
ExprDef *
+ExprCreateBoolean(bool set)
+{
+ ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_BOOLEAN);
+ if (!expr)
+ return NULL;
+
+ expr->value.set = set;
+
+ return expr;
+}
+
+ExprDef *
ExprCreateKeyName(xkb_atom_t key_name)
{
ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_KEYNAME);
@@ -261,18 +273,10 @@ VarCreate(ExprDef *name, ExprDef *value)
}
VarDef *
-BoolVarCreate(xkb_atom_t nameToken, unsigned set)
+BoolVarCreate(xkb_atom_t ident, bool set)
{
- ExprDef *name, *value;
- VarDef *def;
-
- name = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
- name->value.ident = nameToken;
- value = ExprCreate(EXPR_VALUE, EXPR_TYPE_BOOLEAN);
- value->value.uval = set;
- def = VarCreate(name, value);
-
- return def;
+ return VarCreate(ExprCreateIdent(ident),
+ ExprCreateBoolean(set));
}
InterpDef *
diff --git a/src/xkbcomp/ast-build.h b/src/xkbcomp/ast-build.h
index b92b88b..2df7cd0 100644
--- a/src/xkbcomp/ast-build.h
+++ b/src/xkbcomp/ast-build.h
@@ -37,6 +37,9 @@ ExprDef *
ExprCreateInteger(int ival);
ExprDef *
+ExprCreateBoolean(bool set);
+
+ExprDef *
ExprCreateKeyName(xkb_atom_t key_name);
ExprDef *
@@ -68,7 +71,7 @@ VarDef *
VarCreate(ExprDef *name, ExprDef *value);
VarDef *
-BoolVarCreate(xkb_atom_t nameToken, unsigned set);
+BoolVarCreate(xkb_atom_t ident, bool set);
InterpDef *
InterpCreate(xkb_keysym_t sym, ExprDef *match);
diff --git a/src/xkbcomp/ast.h b/src/xkbcomp/ast.h
index d94550f..3e9f517 100644
--- a/src/xkbcomp/ast.h
+++ b/src/xkbcomp/ast.h
@@ -188,7 +188,7 @@ typedef struct _Expr {
struct _Expr *child;
xkb_atom_t ident;
xkb_atom_t str;
- unsigned uval;
+ bool set;
int ival;
xkb_atom_t keyName;
} value;
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 4d61609..227f351 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -135,7 +135,7 @@ ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr,
expr_value_type_to_string(expr->value_type));
return false;
}
- *set_rtrn = !!expr->value.ival;
+ *set_rtrn = expr->value.set;
return true;
case EXPR_IDENT:
@@ -205,7 +205,7 @@ ExprResolveKeyCode(struct xkb_context *ctx, const ExprDef *expr,
return false;
}
- *kc = expr->value.uval;
+ *kc = (xkb_keycode_t) expr->value.ival;
return true;
case EXPR_ADD:
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 34bcdc0..4d1859f 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -380,9 +380,9 @@ Decl : OptMergeMode VarDecl
VarDecl : Lhs EQUALS Expr SEMI
{ $$ = VarCreate($1, $3); }
| Ident SEMI
- { $$ = BoolVarCreate($1, 1); }
+ { $$ = BoolVarCreate($1, true); }
| EXCLAM Ident SEMI
- { $$ = BoolVarCreate($2, 0); }
+ { $$ = BoolVarCreate($2, false); }
;
KeyNameDecl : KEYNAME EQUALS KeyCode SEMI
@@ -448,8 +448,8 @@ SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); }
| Lhs EQUALS ArrayInit { $$ = VarCreate($1, $3); }
- | Ident { $$ = BoolVarCreate($1, 1); }
- | EXCLAM Ident { $$ = BoolVarCreate($2, 0); }
+ | Ident { $$ = BoolVarCreate($1, true); }
+ | EXCLAM Ident { $$ = BoolVarCreate($2, false); }
| ArrayInit { $$ = VarCreate(NULL, $1); }
;