ast: use a separate expr struct for action list

Currently it's under UnaryExpr, which just doesn't make sense.

Signed-off-by: Ran Benita <ran@unusedvar.com>
master
Ran Benita 2019-11-12 20:04:13 +02:00
parent 8c62d48c0c
commit 400cc84911
5 changed files with 28 additions and 4 deletions

View File

@ -206,6 +206,16 @@ ExprCreateAction(xkb_atom_t name, ExprDef *args)
return expr; return expr;
} }
ExprDef *
ExprCreateActionList(ExprDef *actions)
{
ExprDef *expr = ExprCreate(EXPR_ACTION_LIST, EXPR_TYPE_ACTIONS, sizeof(ExprActionList));
if (!expr)
return NULL;
expr->actions.actions = actions;
return expr;
}
ExprDef * ExprDef *
ExprCreateKeysymList(xkb_keysym_t sym) ExprCreateKeysymList(xkb_keysym_t sym)
{ {
@ -592,7 +602,6 @@ FreeExpr(ExprDef *expr)
return; return;
switch (expr->expr.op) { switch (expr->expr.op) {
case EXPR_ACTION_LIST:
case EXPR_NEGATE: case EXPR_NEGATE:
case EXPR_UNARY_PLUS: case EXPR_UNARY_PLUS:
case EXPR_NOT: case EXPR_NOT:
@ -613,6 +622,10 @@ FreeExpr(ExprDef *expr)
FreeStmt((ParseCommon *) expr->action.args); FreeStmt((ParseCommon *) expr->action.args);
break; break;
case EXPR_ACTION_LIST:
FreeStmt((ParseCommon *) expr->actions.actions);
break;
case EXPR_ARRAY_REF: case EXPR_ARRAY_REF:
FreeStmt((ParseCommon *) expr->array_ref.entry); FreeStmt((ParseCommon *) expr->array_ref.entry);
break; break;
@ -812,6 +825,7 @@ static const char *expr_value_type_strings[_EXPR_TYPE_NUM_VALUES] = {
[EXPR_TYPE_FLOAT] = "float", [EXPR_TYPE_FLOAT] = "float",
[EXPR_TYPE_STRING] = "string", [EXPR_TYPE_STRING] = "string",
[EXPR_TYPE_ACTION] = "action", [EXPR_TYPE_ACTION] = "action",
[EXPR_TYPE_ACTIONS] = "actions",
[EXPR_TYPE_KEYNAME] = "keyname", [EXPR_TYPE_KEYNAME] = "keyname",
[EXPR_TYPE_SYMBOLS] = "symbols", [EXPR_TYPE_SYMBOLS] = "symbols",
}; };

View File

@ -64,6 +64,9 @@ ExprCreateArrayRef(xkb_atom_t element, xkb_atom_t field, ExprDef *entry);
ExprDef * ExprDef *
ExprCreateAction(xkb_atom_t name, ExprDef *args); ExprCreateAction(xkb_atom_t name, ExprDef *args);
ExprDef *
ExprCreateActionList(ExprDef *actions);
ExprDef * ExprDef *
ExprCreateMultiKeysymList(ExprDef *list); ExprCreateMultiKeysymList(ExprDef *list);

View File

@ -98,6 +98,7 @@ enum expr_value_type {
EXPR_TYPE_FLOAT, EXPR_TYPE_FLOAT,
EXPR_TYPE_STRING, EXPR_TYPE_STRING,
EXPR_TYPE_ACTION, EXPR_TYPE_ACTION,
EXPR_TYPE_ACTIONS,
EXPR_TYPE_KEYNAME, EXPR_TYPE_KEYNAME,
EXPR_TYPE_SYMBOLS, EXPR_TYPE_SYMBOLS,
@ -228,6 +229,11 @@ typedef struct {
ExprDef *args; ExprDef *args;
} ExprAction; } ExprAction;
typedef struct {
ExprCommon expr;
ExprDef *actions;
} ExprActionList;
typedef struct { typedef struct {
ExprCommon expr; ExprCommon expr;
darray(xkb_keysym_t) syms; darray(xkb_keysym_t) syms;
@ -249,6 +255,7 @@ union ExprDef {
ExprFieldRef field_ref; ExprFieldRef field_ref;
ExprArrayRef array_ref; ExprArrayRef array_ref;
ExprAction action; ExprAction action;
ExprActionList actions;
ExprKeysymList keysym_list; ExprKeysymList keysym_list;
}; };

View File

@ -454,7 +454,7 @@ SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); }
ArrayInit : OBRACKET OptKeySymList CBRACKET ArrayInit : OBRACKET OptKeySymList CBRACKET
{ $$ = $2; } { $$ = $2; }
| OBRACKET ActionList CBRACKET | OBRACKET ActionList CBRACKET
{ $$ = ExprCreateUnary(EXPR_ACTION_LIST, EXPR_TYPE_ACTION, $2); } { $$ = ExprCreateActionList($2); }
; ;
GroupCompatDecl : GROUP Integer EQUALS Expr SEMI GroupCompatDecl : GROUP Integer EQUALS Expr SEMI

View File

@ -753,7 +753,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
} }
nActs = 0; nActs = 0;
for (act = value->unary.child; act; act = (ExprDef *) act->common.next) for (act = value->actions.actions; act; act = (ExprDef *) act->common.next)
nActs++; nActs++;
if (darray_size(groupi->levels) < nActs) if (darray_size(groupi->levels) < nActs)
@ -761,7 +761,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
groupi->defined |= GROUP_FIELD_ACTS; groupi->defined |= GROUP_FIELD_ACTS;
act = value->unary.child; act = value->actions.actions;
for (unsigned i = 0; i < nActs; i++) { for (unsigned i = 0; i < nActs; i++) {
union xkb_action *toAct = &darray_item(groupi->levels, i).action; union xkb_action *toAct = &darray_item(groupi->levels, i).action;