diff options
author | Ran Benita <ran234@gmail.com> | 2013-11-30 23:24:18 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2013-12-01 10:47:56 +0200 |
commit | c24b6420252a92823ac1503d168d81f648830e42 (patch) | |
tree | 45c3d240982c7dc882fba1acb516405912517daa /src/xkbcomp | |
parent | c5d859385f1e65ce84e90beff384d92d1362646a (diff) | |
download | xorg-lib-libxkbcommon-c24b6420252a92823ac1503d168d81f648830e42.tar.gz |
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>
Diffstat (limited to 'src/xkbcomp')
-rw-r--r-- | src/xkbcomp/action.c | 4 | ||||
-rw-r--r-- | src/xkbcomp/ast-build.c | 26 | ||||
-rw-r--r-- | src/xkbcomp/ast-build.h | 5 | ||||
-rw-r--r-- | src/xkbcomp/ast.h | 2 | ||||
-rw-r--r-- | src/xkbcomp/expr.c | 4 | ||||
-rw-r--r-- | src/xkbcomp/parser.y | 8 |
6 files changed, 28 insertions, 21 deletions
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); } ; |