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>
master
Ran Benita 2013-11-30 23:24:18 +02:00
parent c5d859385f
commit c24b642025
6 changed files with 28 additions and 21 deletions

View File

@ -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 {

View File

@ -109,6 +109,18 @@ ExprCreateInteger(int ival)
return expr;
}
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)
{
@ -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 *

View File

@ -36,6 +36,9 @@ ExprCreateString(xkb_atom_t str);
ExprDef *
ExprCreateInteger(int ival);
ExprDef *
ExprCreateBoolean(bool set);
ExprDef *
ExprCreateKeyName(xkb_atom_t key_name);
@ -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);

View File

@ -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;

View File

@ -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:

View File

@ -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); }
;