Convert defines to enums in xkbcomp.h

For statement / expression types.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-25 17:29:08 +03:00
parent 35fb8b94cb
commit 724f62c8e3
16 changed files with 404 additions and 392 deletions

View File

@ -243,8 +243,7 @@ CheckModifierField(struct xkb_keymap *keymap, unsigned action, ExprDef *value,
unsigned *flags_inout, xkb_mod_mask_t *mods_rtrn) unsigned *flags_inout, xkb_mod_mask_t *mods_rtrn)
{ {
ExprResult rtrn; ExprResult rtrn;
if (value->op == EXPR_IDENT) {
if (value->op == ExprIdent) {
const char *valStr; const char *valStr;
valStr = xkb_atom_text(keymap->ctx, value->value.str); valStr = xkb_atom_text(keymap->ctx, value->value.str);
if (valStr && (istreq(valStr, "usemodmapmods") || if (valStr && (istreq(valStr, "usemodmapmods") ||
@ -338,7 +337,7 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
ExprDef *spec; ExprDef *spec;
ExprResult rtrn; ExprResult rtrn;
if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) { if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
*flags_inout &= ~XkbSA_GroupAbsolute; *flags_inout &= ~XkbSA_GroupAbsolute;
spec = value->value.child; spec = value->value.child;
} }
@ -350,9 +349,9 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
if (!ExprResolveGroup(keymap->ctx, spec, &rtrn)) if (!ExprResolveGroup(keymap->ctx, spec, &rtrn))
return ReportMismatch(keymap, action, F_Group, return ReportMismatch(keymap, action, F_Group,
"integer (range 1..8)"); "integer (range 1..8)");
if (value->op == OpNegate) if (value->op == EXPR_NEGATE)
*grp_rtrn = -rtrn.ival; *grp_rtrn = -rtrn.ival;
else if (value->op == OpUnaryPlus) else if (value->op == EXPR_UNARY_PLUS)
*grp_rtrn = rtrn.ival; *grp_rtrn = rtrn.ival;
else else
*grp_rtrn = rtrn.ival - 1; *grp_rtrn = rtrn.ival - 1;
@ -435,7 +434,7 @@ HandleMovePtr(struct xkb_keymap *keymap, struct xkb_any_action *action,
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if ((field == F_X) || (field == F_Y)) { if ((field == F_X) || (field == F_Y)) {
if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
absolute = false; absolute = false;
else else
absolute = true; absolute = true;
@ -550,7 +549,7 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
ExprDef *btn; ExprDef *btn;
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) { if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
act->flags &= ~XkbSA_DfltBtnAbsolute; act->flags &= ~XkbSA_DfltBtnAbsolute;
btn = value->value.child; btn = value->value.child;
} }
@ -574,10 +573,8 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
"Illegal default button setting ignored\n"); "Illegal default button setting ignored\n");
return false; return false;
} }
if (value->op == OpNegate)
act->value = -rtrn.ival; act->value = (value->op == EXPR_NEGATE ? -rtrn.ival : rtrn.ival);
else
act->value = rtrn.ival;
return true; return true;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
@ -656,7 +653,7 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
ExprDef *scrn; ExprDef *scrn;
if (array_ndx != NULL) if (array_ndx != NULL)
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
if ((value->op == OpNegate) || (value->op == OpUnaryPlus)) { if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) {
act->flags &= ~XkbSA_SwitchAbsolute; act->flags &= ~XkbSA_SwitchAbsolute;
scrn = value->value.child; scrn = value->value.child;
} }
@ -674,7 +671,7 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
"Illegal screen value %d ignored\n", rtrn.ival); "Illegal screen value %d ignored\n", rtrn.ival);
return false; return false;
} }
if (value->op == OpNegate) if (value->op == EXPR_NEGATE)
act->screen = -rtrn.ival; act->screen = -rtrn.ival;
else else
act->screen = rtrn.ival; act->screen = rtrn.ival;
@ -1077,7 +1074,7 @@ HandleActionDef(ExprDef * def,
if (!actionsInitialized) if (!actionsInitialized)
ActionsInit(keymap->ctx); ActionsInit(keymap->ctx);
if (def->op != ExprActionDecl) { if (def->op != EXPR_ACTION_DECL) {
log_err(keymap->ctx, "Expected an action definition, found %s\n", log_err(keymap->ctx, "Expected an action definition, found %s\n",
exprOpText(def->op)); exprOpText(def->op));
return false; return false;
@ -1114,12 +1111,12 @@ HandleActionDef(ExprDef * def,
ExprResult elemRtrn, fieldRtrn; ExprResult elemRtrn, fieldRtrn;
unsigned fieldNdx; unsigned fieldNdx;
if (arg->op == OpAssign) { if (arg->op == EXPR_ASSIGN) {
field = arg->value.binary.left; field = arg->value.binary.left;
value = arg->value.binary.right; value = arg->value.binary.right;
} }
else { else {
if ((arg->op == OpNot) || (arg->op == OpInvert)) { if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) {
field = arg->value.child; field = arg->value.child;
constFalse.value.str = xkb_atom_intern(keymap->ctx, "false"); constFalse.value.str = xkb_atom_intern(keymap->ctx, "false");
value = &constFalse; value = &constFalse;
@ -1209,15 +1206,15 @@ ActionsInit(struct xkb_context *ctx)
if (!actionsInitialized) { if (!actionsInitialized) {
memset(&constTrue, 0, sizeof(constTrue)); memset(&constTrue, 0, sizeof(constTrue));
memset(&constFalse, 0, sizeof(constFalse)); memset(&constFalse, 0, sizeof(constFalse));
constTrue.common.stmtType = StmtExpr; constTrue.common.type = STMT_EXPR;
constTrue.common.next = NULL; constTrue.common.next = NULL;
constTrue.op = ExprIdent; constTrue.op = EXPR_IDENT;
constTrue.type = TypeBoolean; constTrue.value_type = EXPR_TYPE_BOOLEAN;
constTrue.value.str = xkb_atom_intern(ctx, "true"); constTrue.value.str = xkb_atom_intern(ctx, "true");
constFalse.common.stmtType = StmtExpr; constFalse.common.type = STMT_EXPR;
constFalse.common.next = NULL; constFalse.common.next = NULL;
constFalse.op = ExprIdent; constFalse.op = EXPR_IDENT;
constFalse.type = TypeBoolean; constFalse.value_type = EXPR_TYPE_BOOLEAN;
constFalse.value.str = xkb_atom_intern(ctx, "false"); constFalse.value.str = xkb_atom_intern(ctx, "false");
actionsInitialized = 1; actionsInitialized = 1;
} }

View File

@ -377,7 +377,7 @@ ResolveStateAndPredicate(ExprDef * expr,
} }
*pred_rtrn = XkbSI_Exactly; *pred_rtrn = XkbSI_Exactly;
if (expr->op == ExprActionDecl) { if (expr->op == EXPR_ACTION_DECL) {
const char *pred_txt = xkb_atom_text(info->keymap->ctx, const char *pred_txt = xkb_atom_text(info->keymap->ctx,
expr->value.action.name); expr->value.action.name);
if (istreq(pred_txt, "noneof")) if (istreq(pred_txt, "noneof"))
@ -397,7 +397,7 @@ ResolveStateAndPredicate(ExprDef * expr,
} }
expr = expr->value.action.args; expr = expr->value.action.args;
} }
else if (expr->op == ExprIdent) { else if (expr->op == EXPR_IDENT) {
const char *pred_txt = xkb_atom_text(info->keymap->ctx, const char *pred_txt = xkb_atom_text(info->keymap->ctx,
expr->value.str); expr->value.str);
if (pred_txt && istreq(pred_txt, "any")) { if (pred_txt && istreq(pred_txt, "any")) {
@ -595,7 +595,7 @@ HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
stmt->stmt = NULL; stmt->stmt = NULL;
} }
for (; stmt; stmt = stmt->next) { for (; stmt; stmt = stmt->next_incl) {
if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT, if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
&rtrn, &merge)) { &rtrn, &merge)) {
info->errorCount += 10; info->errorCount += 10;
@ -899,7 +899,7 @@ HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
ExprDef *arrayNdx; ExprDef *arrayNdx;
for (; def != NULL; def = (VarDef *) def->common.next) { for (; def != NULL; def = (VarDef *) def->common.next) {
if ((def->name) && (def->name->op == ExprFieldRef)) { if (def->name && def->name->op == EXPR_FIELD_REF) {
ok = HandleInterpVar(info, def); ok = HandleInterpVar(info, def);
continue; continue;
} }
@ -1036,33 +1036,33 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
stmt = file->defs; stmt = file->defs;
while (stmt) while (stmt)
{ {
switch (stmt->stmtType) { switch (stmt->type) {
case StmtInclude: case STMT_INCLUDE:
if (!HandleIncludeCompatMap(info, (IncludeStmt *) stmt)) if (!HandleIncludeCompatMap(info, (IncludeStmt *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtInterpDef: case STMT_INTERP:
if (!HandleInterpDef(info, (InterpDef *) stmt, merge)) if (!HandleInterpDef(info, (InterpDef *) stmt, merge))
info->errorCount++; info->errorCount++;
break; break;
case StmtGroupCompatDef: case STMT_GROUP_COMPAT:
if (!HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge)) if (!HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge))
info->errorCount++; info->errorCount++;
break; break;
case StmtIndicatorMapDef: case STMT_INDICATOR_MAP:
if (!HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge)) if (!HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge))
info->errorCount++; info->errorCount++;
break; break;
case StmtVarDef: case STMT_VAR:
if (!HandleInterpVar(info, (VarDef *) stmt)) if (!HandleInterpVar(info, (VarDef *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtVModDef: case STMT_VMOD:
if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods)) &info->vmods))
info->errorCount++; info->errorCount++;
break; break;
case StmtKeycodeDef: case STMT_KEYCODE:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Interpretation files may not include other types; " "Interpretation files may not include other types; "
"Ignoring definition of key name\n"); "Ignoring definition of key name\n");
@ -1071,7 +1071,7 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
default: default:
log_wsgo(info->keymap->ctx, log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleCompatMapFile\n", "Unexpected statement type %d in HandleCompatMapFile\n",
stmt->stmtType); stmt->type);
break; break;
} }
stmt = stmt->next; stmt = stmt->next;

View File

@ -27,92 +27,92 @@
#include "expr.h" #include "expr.h"
typedef bool (*IdentLookupFunc)(struct xkb_context *ctx, const void *priv, typedef bool (*IdentLookupFunc)(struct xkb_context *ctx, const void *priv,
xkb_atom_t field, unsigned type, xkb_atom_t field, enum expr_value_type type,
ExprResult *val_rtrn); ExprResult *val_rtrn);
const char * const char *
exprOpText(unsigned type) exprOpText(enum expr_op_type op)
{ {
static char buf[32]; static char buf[32];
switch (type) { switch (op) {
case ExprValue: case EXPR_VALUE:
strcpy(buf, "literal"); strcpy(buf, "literal");
break; break;
case ExprIdent: case EXPR_IDENT:
strcpy(buf, "identifier"); strcpy(buf, "identifier");
break; break;
case ExprActionDecl: case EXPR_ACTION_DECL:
strcpy(buf, "action declaration"); strcpy(buf, "action declaration");
break; break;
case ExprFieldRef: case EXPR_FIELD_REF:
strcpy(buf, "field reference"); strcpy(buf, "field reference");
break; break;
case ExprArrayRef: case EXPR_ARRAY_REF:
strcpy(buf, "array reference"); strcpy(buf, "array reference");
break; break;
case ExprKeysymList: case EXPR_KEYSYM_LIST:
strcpy(buf, "list of keysyms"); strcpy(buf, "list of keysyms");
break; break;
case ExprActionList: case EXPR_ACTION_LIST:
strcpy(buf, "list of actions"); strcpy(buf, "list of actions");
break; break;
case OpAdd: case EXPR_ADD:
strcpy(buf, "addition"); strcpy(buf, "addition");
break; break;
case OpSubtract: case EXPR_SUBTRACT:
strcpy(buf, "subtraction"); strcpy(buf, "subtraction");
break; break;
case OpMultiply: case EXPR_MULTIPLY:
strcpy(buf, "multiplication"); strcpy(buf, "multiplication");
break; break;
case OpDivide: case EXPR_DIVIDE:
strcpy(buf, "division"); strcpy(buf, "division");
break; break;
case OpAssign: case EXPR_ASSIGN:
strcpy(buf, "assignment"); strcpy(buf, "assignment");
break; break;
case OpNot: case EXPR_NOT:
strcpy(buf, "logical not"); strcpy(buf, "logical not");
break; break;
case OpNegate: case EXPR_NEGATE:
strcpy(buf, "arithmetic negation"); strcpy(buf, "arithmetic negation");
break; break;
case OpInvert: case EXPR_INVERT:
strcpy(buf, "bitwise inversion"); strcpy(buf, "bitwise inversion");
break; break;
case OpUnaryPlus: case EXPR_UNARY_PLUS:
strcpy(buf, "unary plus"); strcpy(buf, "unary plus");
break; break;
default: default:
snprintf(buf, sizeof(buf), "illegal(%d)", type); snprintf(buf, sizeof(buf), "illegal(%d)", op);
break; break;
} }
return buf; return buf;
} }
static const char * static const char *
exprTypeText(unsigned type) exprValueTypeText(enum expr_value_type type)
{ {
static char buf[20]; static char buf[20];
switch (type) { switch (type) {
case TypeUnknown: case EXPR_TYPE_UNKNOWN:
strcpy(buf, "unknown"); strcpy(buf, "unknown");
break; break;
case TypeBoolean: case EXPR_TYPE_BOOLEAN:
strcpy(buf, "boolean"); strcpy(buf, "boolean");
break; break;
case TypeInt: case EXPR_TYPE_INT:
strcpy(buf, "int"); strcpy(buf, "int");
break; break;
case TypeString: case EXPR_TYPE_STRING:
strcpy(buf, "string"); strcpy(buf, "string");
break; break;
case TypeAction: case EXPR_TYPE_ACTION:
strcpy(buf, "action"); strcpy(buf, "action");
break; break;
case TypeKeyName: case EXPR_TYPE_KEYNAME:
strcpy(buf, "keyname"); strcpy(buf, "keyname");
break; break;
default: default:
@ -130,21 +130,23 @@ ExprResolveLhs(struct xkb_keymap *keymap, ExprDef *expr,
struct xkb_context *ctx = keymap->ctx; struct xkb_context *ctx = keymap->ctx;
switch (expr->op) { switch (expr->op) {
case ExprIdent: case EXPR_IDENT:
elem_rtrn->str = NULL; elem_rtrn->str = NULL;
field_rtrn->str = xkb_atom_text(ctx, expr->value.str); field_rtrn->str = xkb_atom_text(ctx, expr->value.str);
*index_rtrn = NULL; *index_rtrn = NULL;
return true; return true;
case ExprFieldRef: case EXPR_FIELD_REF:
elem_rtrn->str = xkb_atom_text(ctx, expr->value.field.element); elem_rtrn->str = xkb_atom_text(ctx, expr->value.field.element);
field_rtrn->str = xkb_atom_text(ctx, expr->value.field.field); field_rtrn->str = xkb_atom_text(ctx, expr->value.field.field);
*index_rtrn = NULL; *index_rtrn = NULL;
return true; return true;
case ExprArrayRef: case EXPR_ARRAY_REF:
elem_rtrn->str = xkb_atom_text(ctx, expr->value.array.element); elem_rtrn->str = xkb_atom_text(ctx, expr->value.array.element);
field_rtrn->str = xkb_atom_text(ctx, expr->value.array.field); field_rtrn->str = xkb_atom_text(ctx, expr->value.array.field);
*index_rtrn = expr->value.array.entry; *index_rtrn = expr->value.array.entry;
return true; return true;
default:
break;
} }
log_wsgo(keymap->ctx, "Unexpected operator %d in ResolveLhs\n", expr->op); log_wsgo(keymap->ctx, "Unexpected operator %d in ResolveLhs\n", expr->op);
return false; return false;
@ -152,16 +154,17 @@ ExprResolveLhs(struct xkb_keymap *keymap, ExprDef *expr,
static bool static bool
SimpleLookup(struct xkb_context *ctx, const void *priv, SimpleLookup(struct xkb_context *ctx, const void *priv,
xkb_atom_t field, unsigned type, ExprResult *val_rtrn) xkb_atom_t field, enum expr_value_type type,
ExprResult *val_rtrn)
{ {
const LookupEntry *entry; const LookupEntry *entry;
const char *str; const char *str;
if ((priv == NULL) || (field == XKB_ATOM_NONE) || (type != TypeInt)) if (!priv || field == XKB_ATOM_NONE || type != EXPR_TYPE_INT)
return false; return false;
str = xkb_atom_text(ctx, field); str = xkb_atom_text(ctx, field);
for (entry = priv; (entry != NULL) && (entry->name != NULL); entry++) { for (entry = priv; entry && entry->name; entry++) {
if (istreq(str, entry->name)) { if (istreq(str, entry->name)) {
val_rtrn->uval = entry->result; val_rtrn->uval = entry->result;
return true; return true;
@ -186,19 +189,19 @@ static const LookupEntry modIndexNames[] = {
bool bool
LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field, LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
unsigned type, ExprResult *val_rtrn) enum expr_value_type type, ExprResult *val_rtrn)
{ {
return SimpleLookup(ctx, modIndexNames, field, type, val_rtrn); return SimpleLookup(ctx, modIndexNames, field, type, val_rtrn);
} }
bool bool
LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
unsigned type, ExprResult *val_rtrn) enum expr_value_type type, ExprResult *val_rtrn)
{ {
const char *str; const char *str;
bool ret = true; bool ret = true;
if (type != TypeInt) if (type != EXPR_TYPE_INT)
return false; return false;
str = xkb_atom_text(ctx, field); str = xkb_atom_text(ctx, field);
if (str == NULL) if (str == NULL)
@ -222,17 +225,17 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr,
const char *ident; const char *ident;
switch (expr->op) { switch (expr->op) {
case ExprValue: case EXPR_VALUE:
if (expr->type != TypeBoolean) { if (expr->value_type != EXPR_TYPE_BOOLEAN) {
log_err(ctx, log_err(ctx,
"Found constant of type %s where boolean was expected\n", "Found constant of type %s where boolean was expected\n",
exprTypeText(expr->type)); exprValueTypeText(expr->value_type));
return false; return false;
} }
val_rtrn->ival = expr->value.ival; val_rtrn->ival = expr->value.ival;
return true; return true;
case ExprIdent: case EXPR_IDENT:
ident = xkb_atom_text(ctx, expr->value.str); ident = xkb_atom_text(ctx, expr->value.str);
if (ident) { if (ident) {
if (istreq(ident, "true") || if (istreq(ident, "true") ||
@ -252,25 +255,25 @@ ExprResolveBoolean(struct xkb_context *ctx, ExprDef *expr,
xkb_atom_text(ctx, expr->value.str)); xkb_atom_text(ctx, expr->value.str));
return false; return false;
case ExprFieldRef: case EXPR_FIELD_REF:
log_err(ctx, "Default \"%s.%s\" of type boolean is unknown\n", log_err(ctx, "Default \"%s.%s\" of type boolean is unknown\n",
xkb_atom_text(ctx, expr->value.field.element), xkb_atom_text(ctx, expr->value.field.element),
xkb_atom_text(ctx, expr->value.field.field)); xkb_atom_text(ctx, expr->value.field.field));
return false; return false;
case OpInvert: case EXPR_INVERT:
case OpNot: case EXPR_NOT:
ok = ExprResolveBoolean(ctx, expr, val_rtrn); ok = ExprResolveBoolean(ctx, expr, val_rtrn);
if (ok) if (ok)
val_rtrn->uval = !val_rtrn->uval; val_rtrn->uval = !val_rtrn->uval;
return ok; return ok;
case OpAdd: case EXPR_ADD:
case OpSubtract: case EXPR_SUBTRACT:
case OpMultiply: case EXPR_MULTIPLY:
case OpDivide: case EXPR_DIVIDE:
case OpAssign: case EXPR_ASSIGN:
case OpNegate: case EXPR_NEGATE:
case OpUnaryPlus: case EXPR_UNARY_PLUS:
log_err(ctx, "%s of boolean values not permitted\n", log_err(ctx, "%s of boolean values not permitted\n",
exprOpText(expr->op)); exprOpText(expr->op));
break; break;
@ -290,35 +293,37 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
ExprDef *left, *right; ExprDef *left, *right;
switch (expr->op) { switch (expr->op) {
case ExprValue: case EXPR_VALUE:
if (expr->type != TypeInt) { if (expr->value_type != EXPR_TYPE_INT) {
log_err(ctx, log_err(ctx,
"Found constant of type %s where an int was expected\n", "Found constant of type %s where an int was expected\n",
exprTypeText(expr->type)); exprValueTypeText(expr->value_type));
return false; return false;
} }
val_rtrn->uval = expr->value.uval; val_rtrn->uval = expr->value.uval;
return true; return true;
case OpAdd: case EXPR_ADD:
case OpSubtract: case EXPR_SUBTRACT:
case OpMultiply: case EXPR_MULTIPLY:
case OpDivide: case EXPR_DIVIDE:
left = expr->value.binary.left; left = expr->value.binary.left;
right = expr->value.binary.right; right = expr->value.binary.right;
if (ExprResolveKeyCode(ctx, left, &leftRtrn) && if (!ExprResolveKeyCode(ctx, left, &leftRtrn) ||
ExprResolveKeyCode(ctx, right, &rightRtrn)) { !ExprResolveKeyCode(ctx, right, &rightRtrn))
return false;
switch (expr->op) { switch (expr->op) {
case OpAdd: case EXPR_ADD:
val_rtrn->uval = leftRtrn.uval + rightRtrn.uval; val_rtrn->uval = leftRtrn.uval + rightRtrn.uval;
break; break;
case OpSubtract: case EXPR_SUBTRACT:
val_rtrn->uval = leftRtrn.uval - rightRtrn.uval; val_rtrn->uval = leftRtrn.uval - rightRtrn.uval;
break; break;
case OpMultiply: case EXPR_MULTIPLY:
val_rtrn->uval = leftRtrn.uval * rightRtrn.uval; val_rtrn->uval = leftRtrn.uval * rightRtrn.uval;
break; break;
case OpDivide: case EXPR_DIVIDE:
if (rightRtrn.uval == 0) { if (rightRtrn.uval == 0) {
log_err(ctx, "Cannot divide by zero: %d / %d\n", log_err(ctx, "Cannot divide by zero: %d / %d\n",
leftRtrn.uval, rightRtrn.uval); leftRtrn.uval, rightRtrn.uval);
@ -326,12 +331,13 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
} }
val_rtrn->uval = leftRtrn.uval / rightRtrn.uval; val_rtrn->uval = leftRtrn.uval / rightRtrn.uval;
break; break;
default:
break;
} }
return true;
}
return false;
case OpNegate: return true;
case EXPR_NEGATE:
left = expr->value.child; left = expr->value.child;
if (ExprResolveKeyCode(ctx, left, &leftRtrn)) { if (ExprResolveKeyCode(ctx, left, &leftRtrn)) {
val_rtrn->uval = ~leftRtrn.uval; val_rtrn->uval = ~leftRtrn.uval;
@ -339,7 +345,7 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr,
} }
return false; return false;
case OpUnaryPlus: case EXPR_UNARY_PLUS:
left = expr->value.child; left = expr->value.child;
return ExprResolveKeyCode(ctx, left, val_rtrn); return ExprResolveKeyCode(ctx, left, val_rtrn);
@ -374,8 +380,8 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
ExprDef *left, *right; ExprDef *left, *right;
switch (expr->op) { switch (expr->op) {
case ExprValue: case EXPR_VALUE:
if (expr->type == TypeString) { if (expr->value_type == EXPR_TYPE_STRING) {
const char *str; const char *str;
str = xkb_atom_text(ctx, expr->value.str); str = xkb_atom_text(ctx, expr->value.str);
if (str != NULL) if (str != NULL)
@ -390,34 +396,34 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
break; break;
} }
} }
if (expr->type != TypeInt) { if (expr->value_type != EXPR_TYPE_INT) {
log_err(ctx, log_err(ctx,
"Found constant of type %s where an int was expected\n", "Found constant of type %s where an int was expected\n",
exprTypeText(expr->type)); exprValueTypeText(expr->value_type));
return false; return false;
} }
val_rtrn->ival = expr->value.ival; val_rtrn->ival = expr->value.ival;
return true; return true;
case ExprIdent: case EXPR_IDENT:
if (lookup) if (lookup)
ok = lookup(ctx, lookupPriv, expr->value.str, ok = lookup(ctx, lookupPriv, expr->value.str,
TypeInt, val_rtrn); EXPR_TYPE_INT, val_rtrn);
if (!ok) if (!ok)
log_err(ctx, "Identifier \"%s\" of type int is unknown\n", log_err(ctx, "Identifier \"%s\" of type int is unknown\n",
xkb_atom_text(ctx, expr->value.str)); xkb_atom_text(ctx, expr->value.str));
return ok; return ok;
case ExprFieldRef: case EXPR_FIELD_REF:
log_err(ctx, "Default \"%s.%s\" of type int is unknown\n", log_err(ctx, "Default \"%s.%s\" of type int is unknown\n",
xkb_atom_text(ctx, expr->value.field.element), xkb_atom_text(ctx, expr->value.field.element),
xkb_atom_text(ctx, expr->value.field.field)); xkb_atom_text(ctx, expr->value.field.field));
return false; return false;
case OpAdd: case EXPR_ADD:
case OpSubtract: case EXPR_SUBTRACT:
case OpMultiply: case EXPR_MULTIPLY:
case OpDivide: case EXPR_DIVIDE:
left = expr->value.binary.left; left = expr->value.binary.left;
right = expr->value.binary.right; right = expr->value.binary.right;
if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup, if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
@ -425,16 +431,16 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
ExprResolveIntegerLookup(ctx, right, &rightRtrn, lookup, ExprResolveIntegerLookup(ctx, right, &rightRtrn, lookup,
lookupPriv)) { lookupPriv)) {
switch (expr->op) { switch (expr->op) {
case OpAdd: case EXPR_ADD:
val_rtrn->ival = leftRtrn.ival + rightRtrn.ival; val_rtrn->ival = leftRtrn.ival + rightRtrn.ival;
break; break;
case OpSubtract: case EXPR_SUBTRACT:
val_rtrn->ival = leftRtrn.ival - rightRtrn.ival; val_rtrn->ival = leftRtrn.ival - rightRtrn.ival;
break; break;
case OpMultiply: case EXPR_MULTIPLY:
val_rtrn->ival = leftRtrn.ival * rightRtrn.ival; val_rtrn->ival = leftRtrn.ival * rightRtrn.ival;
break; break;
case OpDivide: case EXPR_DIVIDE:
if (rightRtrn.ival == 0) { if (rightRtrn.ival == 0) {
log_err(ctx, "Cannot divide by zero: %d / %d\n", log_err(ctx, "Cannot divide by zero: %d / %d\n",
leftRtrn.ival, rightRtrn.ival); leftRtrn.ival, rightRtrn.ival);
@ -442,25 +448,27 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
} }
val_rtrn->ival = leftRtrn.ival / rightRtrn.ival; val_rtrn->ival = leftRtrn.ival / rightRtrn.ival;
break; break;
default:
break;
} }
return true; return true;
} }
return false; return false;
case OpAssign: case EXPR_ASSIGN:
log_wsgo(ctx, "Assignment operator not implemented yet\n"); log_wsgo(ctx, "Assignment operator not implemented yet\n");
break; break;
case OpNot: case EXPR_NOT:
log_err(ctx, "The ! operator cannot be applied to an integer\n"); log_err(ctx, "The ! operator cannot be applied to an integer\n");
return false; return false;
case OpInvert: case EXPR_INVERT:
case OpNegate: case EXPR_NEGATE:
left = expr->value.child; left = expr->value.child;
if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup, if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
lookupPriv)) { lookupPriv)) {
if (expr->op == OpNegate) if (expr->op == EXPR_NEGATE)
val_rtrn->ival = -leftRtrn.ival; val_rtrn->ival = -leftRtrn.ival;
else else
val_rtrn->ival = ~leftRtrn.ival; val_rtrn->ival = ~leftRtrn.ival;
@ -468,7 +476,7 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
} }
return false; return false;
case OpUnaryPlus: case EXPR_UNARY_PLUS:
left = expr->value.child; left = expr->value.child;
return ExprResolveIntegerLookup(ctx, left, val_rtrn, lookup, return ExprResolveIntegerLookup(ctx, left, val_rtrn, lookup,
lookupPriv); lookupPriv);
@ -572,35 +580,35 @@ ExprResolveString(struct xkb_context *ctx, ExprDef *expr,
ExprResult *val_rtrn) ExprResult *val_rtrn)
{ {
switch (expr->op) { switch (expr->op) {
case ExprValue: case EXPR_VALUE:
if (expr->type != TypeString) { if (expr->value_type != EXPR_TYPE_STRING) {
log_err(ctx, "Found constant of type %s, expected a string\n", log_err(ctx, "Found constant of type %s, expected a string\n",
exprTypeText(expr->type)); exprValueTypeText(expr->value_type));
return false; return false;
} }
val_rtrn->str = xkb_atom_text(ctx, expr->value.str); val_rtrn->str = xkb_atom_text(ctx, expr->value.str);
return true; return true;
case ExprIdent: case EXPR_IDENT:
log_err(ctx, "Identifier \"%s\" of type string not found\n", log_err(ctx, "Identifier \"%s\" of type string not found\n",
xkb_atom_text(ctx, expr->value.str)); xkb_atom_text(ctx, expr->value.str));
return false; return false;
case ExprFieldRef: case EXPR_FIELD_REF:
log_err(ctx, "Default \"%s.%s\" of type string not found\n", log_err(ctx, "Default \"%s.%s\" of type string not found\n",
xkb_atom_text(ctx, expr->value.field.element), xkb_atom_text(ctx, expr->value.field.element),
xkb_atom_text(ctx, expr->value.field.field)); xkb_atom_text(ctx, expr->value.field.field));
return false; return false;
case OpAdd: case EXPR_ADD:
case OpSubtract: case EXPR_SUBTRACT:
case OpMultiply: case EXPR_MULTIPLY:
case OpDivide: case EXPR_DIVIDE:
case OpAssign: case EXPR_ASSIGN:
case OpNegate: case EXPR_NEGATE:
case OpInvert: case EXPR_INVERT:
case OpNot: case EXPR_NOT:
case OpUnaryPlus: case EXPR_UNARY_PLUS:
log_err(ctx, "%s of strings not permitted\n", exprOpText(expr->op)); log_err(ctx, "%s of strings not permitted\n", exprOpText(expr->op));
return false; return false;
@ -616,35 +624,35 @@ ExprResolveKeyName(struct xkb_context *ctx, ExprDef *expr,
ExprResult *val_rtrn) ExprResult *val_rtrn)
{ {
switch (expr->op) { switch (expr->op) {
case ExprValue: case EXPR_VALUE:
if (expr->type != TypeKeyName) { if (expr->value_type != EXPR_TYPE_KEYNAME) {
log_err(ctx, "Found constant of type %s, expected a key name\n", log_err(ctx, "Found constant of type %s, expected a key name\n",
exprTypeText(expr->type)); exprValueTypeText(expr->value_type));
return false; return false;
} }
memcpy(val_rtrn->name, expr->value.keyName, XkbKeyNameLength); memcpy(val_rtrn->name, expr->value.keyName, XkbKeyNameLength);
return true; return true;
case ExprIdent: case EXPR_IDENT:
log_err(ctx, "Identifier \"%s\" of type string not found\n", log_err(ctx, "Identifier \"%s\" of type string not found\n",
xkb_atom_text(ctx, expr->value.str)); xkb_atom_text(ctx, expr->value.str));
return false; return false;
case ExprFieldRef: case EXPR_FIELD_REF:
log_err(ctx, "Default \"%s.%s\" of type key name not found\n", log_err(ctx, "Default \"%s.%s\" of type key name not found\n",
xkb_atom_text(ctx, expr->value.field.element), xkb_atom_text(ctx, expr->value.field.element),
xkb_atom_text(ctx, expr->value.field.field)); xkb_atom_text(ctx, expr->value.field.field));
return false; return false;
case OpAdd: case EXPR_ADD:
case OpSubtract: case EXPR_SUBTRACT:
case OpMultiply: case EXPR_MULTIPLY:
case OpDivide: case EXPR_DIVIDE:
case OpAssign: case EXPR_ASSIGN:
case OpNegate: case EXPR_NEGATE:
case OpInvert: case EXPR_INVERT:
case OpNot: case EXPR_NOT:
case OpUnaryPlus: case EXPR_UNARY_PLUS:
log_err(ctx, "%s of key name values not permitted\n", log_err(ctx, "%s of key name values not permitted\n",
exprOpText(expr->op)); exprOpText(expr->op));
return false; return false;
@ -662,12 +670,13 @@ int
ExprResolveEnum(struct xkb_context *ctx, ExprDef *expr, ExprResolveEnum(struct xkb_context *ctx, ExprDef *expr,
ExprResult *val_rtrn, const LookupEntry *values) ExprResult *val_rtrn, const LookupEntry *values)
{ {
if (expr->op != ExprIdent) { if (expr->op != EXPR_IDENT) {
log_err(ctx, "Found a %s where an enumerated value was expected\n", log_err(ctx, "Found a %s where an enumerated value was expected\n",
exprOpText(expr->op)); exprOpText(expr->op));
return false; return false;
} }
if (!SimpleLookup(ctx, values, expr->value.str, TypeInt, val_rtrn)) { if (!SimpleLookup(ctx, values, expr->value.str, EXPR_TYPE_INT,
val_rtrn)) {
int nOut = 0; int nOut = 0;
log_err(ctx, "Illegal identifier %s (expected one of: ", log_err(ctx, "Illegal identifier %s (expected one of: ",
xkb_atom_text(ctx, expr->value.str)); xkb_atom_text(ctx, expr->value.str));
@ -697,33 +706,33 @@ ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
const char *bogus = NULL; const char *bogus = NULL;
switch (expr->op) { switch (expr->op) {
case ExprValue: case EXPR_VALUE:
if (expr->type != TypeInt) { if (expr->value_type != EXPR_TYPE_INT) {
log_err(ctx, log_err(ctx,
"Found constant of type %s where a mask was expected\n", "Found constant of type %s where a mask was expected\n",
exprTypeText(expr->type)); exprValueTypeText(expr->value_type));
return false; return false;
} }
val_rtrn->ival = expr->value.ival; val_rtrn->ival = expr->value.ival;
return true; return true;
case ExprIdent: case EXPR_IDENT:
ok = lookup(ctx, lookupPriv, expr->value.str, TypeInt, val_rtrn); ok = lookup(ctx, lookupPriv, expr->value.str, EXPR_TYPE_INT, val_rtrn);
if (!ok) if (!ok)
log_err(ctx, "Identifier \"%s\" of type int is unknown\n", log_err(ctx, "Identifier \"%s\" of type int is unknown\n",
xkb_atom_text(ctx, expr->value.str)); xkb_atom_text(ctx, expr->value.str));
return ok; return ok;
case ExprFieldRef: case EXPR_FIELD_REF:
log_err(ctx, "Default \"%s.%s\" of type int is unknown\n", log_err(ctx, "Default \"%s.%s\" of type int is unknown\n",
xkb_atom_text(ctx, expr->value.field.element), xkb_atom_text(ctx, expr->value.field.element),
xkb_atom_text(ctx, expr->value.field.field)); xkb_atom_text(ctx, expr->value.field.field));
return false; return false;
case ExprArrayRef: case EXPR_ARRAY_REF:
bogus = "array reference"; bogus = "array reference";
case ExprActionDecl: case EXPR_ACTION_DECL:
if (bogus == NULL) if (bogus == NULL)
bogus = "function use"; bogus = "function use";
log_err(ctx, log_err(ctx,
@ -731,10 +740,10 @@ ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
bogus); bogus);
return false; return false;
case OpAdd: case EXPR_ADD:
case OpSubtract: case EXPR_SUBTRACT:
case OpMultiply: case EXPR_MULTIPLY:
case OpDivide: case EXPR_DIVIDE:
left = expr->value.binary.left; left = expr->value.binary.left;
right = expr->value.binary.right; right = expr->value.binary.right;
if (ExprResolveMaskLookup(ctx, left, &leftRtrn, lookup, if (ExprResolveMaskLookup(ctx, left, &leftRtrn, lookup,
@ -742,27 +751,29 @@ ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
ExprResolveMaskLookup(ctx, right, &rightRtrn, lookup, ExprResolveMaskLookup(ctx, right, &rightRtrn, lookup,
lookupPriv)) { lookupPriv)) {
switch (expr->op) { switch (expr->op) {
case OpAdd: case EXPR_ADD:
val_rtrn->ival = leftRtrn.ival | rightRtrn.ival; val_rtrn->ival = leftRtrn.ival | rightRtrn.ival;
break; break;
case OpSubtract: case EXPR_SUBTRACT:
val_rtrn->ival = leftRtrn.ival & (~rightRtrn.ival); val_rtrn->ival = leftRtrn.ival & (~rightRtrn.ival);
break; break;
case OpMultiply: case EXPR_MULTIPLY:
case OpDivide: case EXPR_DIVIDE:
log_err(ctx, "Cannot %s masks; Illegal operation ignored\n", log_err(ctx, "Cannot %s masks; Illegal operation ignored\n",
(expr->op == OpDivide ? "divide" : "multiply")); (expr->op == EXPR_DIVIDE ? "divide" : "multiply"));
return false; return false;
default:
break;
} }
return true; return true;
} }
return false; return false;
case OpAssign: case EXPR_ASSIGN:
log_wsgo(ctx, "Assignment operator not implemented yet\n"); log_wsgo(ctx, "Assignment operator not implemented yet\n");
break; break;
case OpInvert: case EXPR_INVERT:
left = expr->value.child; left = expr->value.child;
if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup, if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
lookupPriv)) { lookupPriv)) {
@ -771,14 +782,14 @@ ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
} }
return false; return false;
case OpUnaryPlus: case EXPR_UNARY_PLUS:
case OpNegate: case EXPR_NEGATE:
case OpNot: case EXPR_NOT:
left = expr->value.child; left = expr->value.child;
if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup, if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
lookupPriv)) { lookupPriv)) {
log_err(ctx, "The %s operator cannot be used with a mask\n", log_err(ctx, "The %s operator cannot be used with a mask\n",
(expr->op == OpNegate ? "-" : "!")); (expr->op == EXPR_NEGATE ? "-" : "!"));
} }
return false; return false;
@ -818,7 +829,7 @@ ExprResolveKeySym(struct xkb_context *ctx, ExprDef *expr,
int ok = 0; int ok = 0;
xkb_keysym_t sym; xkb_keysym_t sym;
if (expr->op == ExprIdent) { if (expr->op == EXPR_IDENT) {
const char *str; const char *str;
str = xkb_atom_text(ctx, expr->value.str); str = xkb_atom_text(ctx, expr->value.str);
if (str) { if (str) {

View File

@ -47,22 +47,19 @@ typedef struct _LookupEntry {
} LookupEntry; } LookupEntry;
extern const char * extern const char *
exprOpText(unsigned type); exprOpText(enum expr_op_type op);
extern bool extern bool
LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
unsigned type, enum expr_value_type type, ExprResult *val_rtrn);
ExprResult *val_rtrn);
extern bool extern bool
LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
unsigned type, enum expr_value_type type, ExprResult *val_rtrn);
ExprResult *val_rtrn);
extern bool extern bool
LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field, LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
unsigned type, enum expr_value_type type, ExprResult *val_rtrn);
ExprResult *val_rtrn);
extern int extern int
ExprResolveModMask(struct xkb_context *ctx, ExprDef *expr, ExprResolveModMask(struct xkb_context *ctx, ExprDef *expr,

View File

@ -477,7 +477,7 @@ HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *stmt)
stmt->stmt = NULL; stmt->stmt = NULL;
} }
for (; stmt; stmt = stmt->next) { for (; stmt; stmt = stmt->next_incl) {
if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_KEYCODES, if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_KEYCODES,
&rtrn, &merge)) { &rtrn, &merge)) {
info->errorCount += 10; info->errorCount += 10;
@ -749,42 +749,42 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
stmt = file->defs; stmt = file->defs;
while (stmt) while (stmt)
{ {
switch (stmt->stmtType) { switch (stmt->type) {
case StmtInclude: /* e.g. include "evdev+aliases(qwerty)" */ case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */
if (!HandleIncludeKeycodes(info, (IncludeStmt *) stmt)) if (!HandleIncludeKeycodes(info, (IncludeStmt *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtKeycodeDef: /* e.g. <ESC> = 9; */ case STMT_KEYCODE: /* e.g. <ESC> = 9; */
if (!HandleKeycodeDef(info, (KeycodeDef *) stmt, merge)) if (!HandleKeycodeDef(info, (KeycodeDef *) stmt, merge))
info->errorCount++; info->errorCount++;
break; break;
case StmtKeyAliasDef: /* e.g. alias <MENU> = <COMP>; */ case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */
if (!HandleAliasDef(info, (KeyAliasDef *) stmt, merge, if (!HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
info->file_id)) info->file_id))
info->errorCount++; info->errorCount++;
break; break;
case StmtVarDef: /* e.g. minimum, maximum */ case STMT_VAR: /* e.g. minimum, maximum */
if (!HandleKeyNameVar(info, (VarDef *) stmt)) if (!HandleKeyNameVar(info, (VarDef *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtIndicatorNameDef: /* e.g. indicator 1 = "Caps Lock"; */ case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */
if (!HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt, if (!HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
merge)) merge))
info->errorCount++; info->errorCount++;
break; break;
case StmtInterpDef: case STMT_INTERP:
case StmtVModDef: case STMT_VMOD:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Keycode files may define key and indicator names only; " "Keycode files may define key and indicator names only; "
"Ignoring definition of %s\n", "Ignoring definition of %s\n",
(stmt->stmtType == StmtInterpDef ? (stmt->type == STMT_INTERP ?
"a symbol interpretation" : "virtual modifiers")); "a symbol interpretation" : "virtual modifiers"));
info->errorCount++; info->errorCount++;
break; break;
default: default:
log_wsgo(info->keymap->ctx, log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleKeycodesFile\n", "Unexpected statement type %d in HandleKeycodesFile\n",
stmt->stmtType); stmt->type);
break; break;
} }
stmt = stmt->next; stmt = stmt->next;

View File

@ -361,7 +361,7 @@ HandleIncludeKeyTypes(KeyTypesInfo *info, IncludeStmt *stmt)
stmt->stmt = NULL; stmt->stmt = NULL;
} }
for (; stmt; stmt = stmt->next) { for (; stmt; stmt = stmt->next_incl) {
if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_TYPES, if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_TYPES,
&rtrn, &merge)) { &rtrn, &merge)) {
info->errorCount += 10; info->errorCount += 10;
@ -781,8 +781,8 @@ HandleKeyTypeBody(KeyTypesInfo *info, VarDef *def, KeyTypeInfo *type)
ExprResult tmp, field; ExprResult tmp, field;
ExprDef *arrayNdx; ExprDef *arrayNdx;
for (; def != NULL; def = (VarDef *) def->common.next) { for (; def; def = (VarDef *) def->common.next) {
if ((def->name) && (def->name->op == ExprFieldRef)) { if (def->name && def->name->op == EXPR_FIELD_REF) {
ok = HandleKeyTypeVar(info, def); ok = HandleKeyTypeVar(info, def);
continue; continue;
} }
@ -874,37 +874,37 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
stmt = file->defs; stmt = file->defs;
while (stmt) while (stmt)
{ {
switch (stmt->stmtType) { switch (stmt->type) {
case StmtInclude: case STMT_INCLUDE:
if (!HandleIncludeKeyTypes(info, (IncludeStmt *) stmt)) if (!HandleIncludeKeyTypes(info, (IncludeStmt *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtKeyTypeDef: /* e.g. type "ONE_LEVEL" */ case STMT_TYPE: /* e.g. type "ONE_LEVEL" */
if (!HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge)) if (!HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge))
info->errorCount++; info->errorCount++;
break; break;
case StmtVarDef: case STMT_VAR:
if (!HandleKeyTypeVar(info, (VarDef *) stmt)) if (!HandleKeyTypeVar(info, (VarDef *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtVModDef: /* virtual_modifiers NumLock, ... */ case STMT_VMOD: /* virtual_modifiers NumLock, ... */
if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods)) &info->vmods))
info->errorCount++; info->errorCount++;
break; break;
case StmtKeyAliasDef: case STMT_ALIAS:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Key type files may not include other declarations; " "Key type files may not include other declarations; "
"Ignoring definition of key alias\n"); "Ignoring definition of key alias\n");
info->errorCount++; info->errorCount++;
break; break;
case StmtKeycodeDef: case STMT_KEYCODE:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Key type files may not include other declarations; " "Key type files may not include other declarations; "
"Ignoring definition of key name\n"); "Ignoring definition of key name\n");
info->errorCount++; info->errorCount++;
break; break;
case StmtInterpDef: case STMT_INTERP:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Key type files may not include other declarations; " "Key type files may not include other declarations; "
"Ignoring definition of symbol interpretation\n"); "Ignoring definition of symbol interpretation\n");
@ -913,7 +913,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
default: default:
log_wsgo(info->keymap->ctx, log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleKeyTypesFile\n", "Unexpected statement type %d in HandleKeyTypesFile\n",
stmt->stmtType); stmt->type);
break; break;
} }
stmt = stmt->next; stmt = stmt->next;

View File

@ -71,7 +71,7 @@ ProcessIncludeFile(struct xkb_context *ctx,
next = (XkbFile *) mapToUse->common.next; next = (XkbFile *) mapToUse->common.next;
mapToUse->common.next = NULL; mapToUse->common.next = NULL;
if (streq(mapToUse->name, stmt->map) && if (streq(mapToUse->name, stmt->map) &&
mapToUse->type == file_type) { mapToUse->file_type == file_type) {
FreeXKBFile(next); FreeXKBFile(next);
break; break;
} }
@ -92,11 +92,11 @@ ProcessIncludeFile(struct xkb_context *ctx,
"Using first defined map, \"%s\"\n", "Using first defined map, \"%s\"\n",
stmt->file, rtrn->name); stmt->file, rtrn->name);
} }
if (mapToUse->type != file_type) { if (mapToUse->file_type != file_type) {
log_err(ctx, log_err(ctx,
"Include file wrong type (expected %s, got %s); " "Include file wrong type (expected %s, got %s); "
"Include file \"%s\" ignored\n", "Include file \"%s\" ignored\n",
FileTypeText(file_type), FileTypeText(mapToUse->type), FileTypeText(file_type), FileTypeText(mapToUse->file_type),
stmt->file); stmt->file);
return false; return false;
} }

View File

@ -435,7 +435,7 @@ SymbolsVarDecl : Lhs EQUALS Expr
ArrayInit : OBRACKET OptKeySymList CBRACKET ArrayInit : OBRACKET OptKeySymList CBRACKET
{ $$= $2; } { $$= $2; }
| OBRACKET ActionList CBRACKET | OBRACKET ActionList CBRACKET
{ $$= ExprCreateUnary(ExprActionList,TypeAction,$2); } { $$= ExprCreateUnary(EXPR_ACTION_LIST, EXPR_TYPE_ACTION, $2); }
; ;
GroupCompatDecl : GROUP Integer EQUALS Expr SEMI GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
@ -613,27 +613,27 @@ ExprList : ExprList COMMA Expr
; ;
Expr : Expr DIVIDE Expr Expr : Expr DIVIDE Expr
{ $$= ExprCreateBinary(OpDivide,$1,$3); } { $$= ExprCreateBinary(EXPR_DIVIDE,$1,$3); }
| Expr PLUS Expr | Expr PLUS Expr
{ $$= ExprCreateBinary(OpAdd,$1,$3); } { $$= ExprCreateBinary(EXPR_ADD,$1,$3); }
| Expr MINUS Expr | Expr MINUS Expr
{ $$= ExprCreateBinary(OpSubtract,$1,$3); } { $$= ExprCreateBinary(EXPR_SUBTRACT,$1,$3); }
| Expr TIMES Expr | Expr TIMES Expr
{ $$= ExprCreateBinary(OpMultiply,$1,$3); } { $$= ExprCreateBinary(EXPR_MULTIPLY,$1,$3); }
| Lhs EQUALS Expr | Lhs EQUALS Expr
{ $$= ExprCreateBinary(OpAssign,$1,$3); } { $$= ExprCreateBinary(EXPR_ASSIGN,$1,$3); }
| Term | Term
{ $$= $1; } { $$= $1; }
; ;
Term : MINUS Term Term : MINUS Term
{ $$= ExprCreateUnary(OpNegate,$2->type,$2); } { $$= ExprCreateUnary(EXPR_NEGATE,$2->value_type,$2); }
| PLUS Term | PLUS Term
{ $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); } { $$= ExprCreateUnary(EXPR_UNARY_PLUS,$2->value_type,$2); }
| EXCLAM Term | EXCLAM Term
{ $$= ExprCreateUnary(OpNot,TypeBoolean,$2); } { $$= ExprCreateUnary(EXPR_NOT,EXPR_TYPE_BOOLEAN,$2); }
| INVERT Term | INVERT Term
{ $$= ExprCreateUnary(OpInvert,$2->type,$2); } { $$= ExprCreateUnary(EXPR_INVERT,$2->value_type,$2); }
| Lhs | Lhs
{ $$= $1; } { $$= $1; }
| FieldSpec OPAREN OptExprList CPAREN %prec OPAREN | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
@ -657,14 +657,14 @@ Action : FieldSpec OPAREN OptExprList CPAREN
Lhs : FieldSpec Lhs : FieldSpec
{ {
ExprDef *expr; ExprDef *expr;
expr= ExprCreate(ExprIdent,TypeUnknown); expr= ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
expr->value.str= $1; expr->value.str= $1;
$$= expr; $$= expr;
} }
| FieldSpec DOT FieldSpec | FieldSpec DOT FieldSpec
{ {
ExprDef *expr; ExprDef *expr;
expr= ExprCreate(ExprFieldRef,TypeUnknown); expr= ExprCreate(EXPR_FIELD_REF,EXPR_TYPE_UNKNOWN);
expr->value.field.element= $1; expr->value.field.element= $1;
expr->value.field.field= $3; expr->value.field.field= $3;
$$= expr; $$= expr;
@ -672,7 +672,7 @@ Lhs : FieldSpec
| FieldSpec OBRACKET Expr CBRACKET | FieldSpec OBRACKET Expr CBRACKET
{ {
ExprDef *expr; ExprDef *expr;
expr= ExprCreate(ExprArrayRef,TypeUnknown); expr= ExprCreate(EXPR_ARRAY_REF,EXPR_TYPE_UNKNOWN);
expr->value.array.element= XKB_ATOM_NONE; expr->value.array.element= XKB_ATOM_NONE;
expr->value.array.field= $1; expr->value.array.field= $1;
expr->value.array.entry= $3; expr->value.array.entry= $3;
@ -681,7 +681,7 @@ Lhs : FieldSpec
| FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
{ {
ExprDef *expr; ExprDef *expr;
expr= ExprCreate(ExprArrayRef,TypeUnknown); expr= ExprCreate(EXPR_ARRAY_REF,EXPR_TYPE_UNKNOWN);
expr->value.array.element= $1; expr->value.array.element= $1;
expr->value.array.field= $3; expr->value.array.field= $3;
expr->value.array.entry= $5; expr->value.array.entry= $5;
@ -692,14 +692,14 @@ Lhs : FieldSpec
Terminal : String Terminal : String
{ {
ExprDef *expr; ExprDef *expr;
expr= ExprCreate(ExprValue,TypeString); expr= ExprCreate(EXPR_VALUE,EXPR_TYPE_STRING);
expr->value.str= $1; expr->value.str= $1;
$$= expr; $$= expr;
} }
| Integer | Integer
{ {
ExprDef *expr; ExprDef *expr;
expr= ExprCreate(ExprValue,TypeInt); expr= ExprCreate(EXPR_VALUE,EXPR_TYPE_INT);
expr->value.ival= $1; expr->value.ival= $1;
$$= expr; $$= expr;
} }
@ -710,7 +710,7 @@ Terminal : String
| KeyName | KeyName
{ {
ExprDef *expr; ExprDef *expr;
expr= ExprCreate(ExprValue,TypeKeyName); expr= ExprCreate(EXPR_VALUE,EXPR_TYPE_KEYNAME);
strncpy(expr->value.keyName,$1,4); strncpy(expr->value.keyName,$1,4);
$$= expr; $$= expr;
} }

View File

@ -57,49 +57,51 @@ AppendStmt(ParseCommon * to, ParseCommon * append)
} }
ExprDef * ExprDef *
ExprCreate(unsigned op, unsigned type) ExprCreate(enum expr_op_type op, enum expr_value_type type)
{ {
ExprDef *expr; ExprDef *expr;
expr = malloc_or_die(sizeof(*expr)); expr = malloc_or_die(sizeof(*expr));
expr->common.stmtType = StmtExpr; expr->common.type = STMT_EXPR;
expr->common.next = NULL; expr->common.next = NULL;
expr->op = op; expr->op = op;
expr->type = type; expr->value_type = type;
return expr; return expr;
} }
ExprDef * ExprDef *
ExprCreateUnary(unsigned op, unsigned type, ExprDef * child) ExprCreateUnary(enum expr_op_type op, enum expr_value_type type,
ExprDef *child)
{ {
ExprDef *expr; ExprDef *expr;
expr = malloc_or_die(sizeof(*expr)); expr = malloc_or_die(sizeof(*expr));
expr->common.stmtType = StmtExpr; expr->common.type = STMT_EXPR;
expr->common.next = NULL; expr->common.next = NULL;
expr->op = op; expr->op = op;
expr->type = type; expr->value_type = type;
expr->value.child = child; expr->value.child = child;
return expr; return expr;
} }
ExprDef * ExprDef *
ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right) ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right)
{ {
ExprDef *expr; ExprDef *expr;
expr = malloc_or_die(sizeof(*expr)); expr = malloc_or_die(sizeof(*expr));
expr->common.stmtType = StmtExpr; expr->common.type = STMT_EXPR;
expr->common.next = NULL; expr->common.next = NULL;
expr->op = op; expr->op = op;
if ((op == OpAssign) || (left->type == TypeUnknown)) if (op == EXPR_ASSIGN || left->value_type == EXPR_TYPE_UNKNOWN)
expr->type = right->type; expr->value_type = right->value_type;
else if ((left->type == right->type) || (right->type == TypeUnknown)) else if (left->value_type == right->value_type ||
expr->type = left->type; right->value_type == EXPR_TYPE_UNKNOWN)
expr->value_type = left->value_type;
else else
expr->type = TypeUnknown; expr->value_type = EXPR_TYPE_UNKNOWN;
expr->value.binary.left = left; expr->value.binary.left = left;
expr->value.binary.right = right; expr->value.binary.right = right;
return expr; return expr;
@ -112,7 +114,7 @@ KeycodeCreate(char keyName[XkbKeyNameLength], unsigned long value)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtKeycodeDef; def->common.type = STMT_KEYCODE;
def->common.next = NULL; def->common.next = NULL;
strncpy(def->name, keyName, XkbKeyNameLength); strncpy(def->name, keyName, XkbKeyNameLength);
def->name[XkbKeyNameLength] = '\0'; def->name[XkbKeyNameLength] = '\0';
@ -127,7 +129,7 @@ KeyAliasCreate(char alias[XkbKeyNameLength], char real[XkbKeyNameLength])
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtKeyAliasDef; def->common.type = STMT_ALIAS;
def->common.next = NULL; def->common.next = NULL;
strncpy(def->alias, alias, XkbKeyNameLength); strncpy(def->alias, alias, XkbKeyNameLength);
def->alias[XkbKeyNameLength] = '\0'; def->alias[XkbKeyNameLength] = '\0';
@ -143,7 +145,7 @@ VModCreate(xkb_atom_t name, ExprDef * value)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtVModDef; def->common.type = STMT_VMOD;
def->common.next = NULL; def->common.next = NULL;
def->name = name; def->name = name;
def->value = value; def->value = value;
@ -156,7 +158,7 @@ VarCreate(ExprDef * name, ExprDef * value)
VarDef *def; VarDef *def;
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtVarDef; def->common.type = STMT_VAR;
def->common.next = NULL; def->common.next = NULL;
def->name = name; def->name = name;
def->value = value; def->value = value;
@ -168,9 +170,9 @@ BoolVarCreate(xkb_atom_t nameToken, unsigned set)
{ {
ExprDef *name, *value; ExprDef *name, *value;
name = ExprCreate(ExprIdent, TypeUnknown); name = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN);
name->value.str = nameToken; name->value.str = nameToken;
value = ExprCreate(ExprValue, TypeBoolean); value = ExprCreate(EXPR_VALUE, EXPR_TYPE_BOOLEAN);
value->value.uval = set; value->value.uval = set;
return VarCreate(name, value); return VarCreate(name, value);
} }
@ -182,7 +184,7 @@ InterpCreate(char *sym, ExprDef * match)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtInterpDef; def->common.type = STMT_INTERP;
def->common.next = NULL; def->common.next = NULL;
def->sym = sym; def->sym = sym;
def->match = match; def->match = match;
@ -196,7 +198,7 @@ KeyTypeCreate(xkb_atom_t name, VarDef * body)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtKeyTypeDef; def->common.type = STMT_TYPE;
def->common.next = NULL; def->common.next = NULL;
def->merge = MERGE_DEFAULT; def->merge = MERGE_DEFAULT;
def->name = name; def->name = name;
@ -211,7 +213,7 @@ SymbolsCreate(char keyName[XkbKeyNameLength], ExprDef *symbols)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtSymbolsDef; def->common.type = STMT_SYMBOLS;
def->common.next = NULL; def->common.next = NULL;
def->merge = MERGE_DEFAULT; def->merge = MERGE_DEFAULT;
strncpy(def->keyName, keyName, XkbKeyNameLength); strncpy(def->keyName, keyName, XkbKeyNameLength);
@ -226,7 +228,7 @@ GroupCompatCreate(int group, ExprDef * val)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtGroupCompatDef; def->common.type = STMT_GROUP_COMPAT;
def->common.next = NULL; def->common.next = NULL;
def->merge = MERGE_DEFAULT; def->merge = MERGE_DEFAULT;
def->group = group; def->group = group;
@ -241,7 +243,7 @@ ModMapCreate(uint32_t modifier, ExprDef * keys)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtModMapDef; def->common.type = STMT_MODMAP;
def->common.next = NULL; def->common.next = NULL;
def->merge = MERGE_DEFAULT; def->merge = MERGE_DEFAULT;
def->modifier = modifier; def->modifier = modifier;
@ -256,7 +258,7 @@ IndicatorMapCreate(xkb_atom_t name, VarDef * body)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtIndicatorMapDef; def->common.type = STMT_INDICATOR_MAP;
def->common.next = NULL; def->common.next = NULL;
def->merge = MERGE_DEFAULT; def->merge = MERGE_DEFAULT;
def->name = name; def->name = name;
@ -271,7 +273,7 @@ IndicatorNameCreate(int ndx, ExprDef * name, bool virtual)
def = malloc_or_die(sizeof(*def)); def = malloc_or_die(sizeof(*def));
def->common.stmtType = StmtIndicatorNameDef; def->common.type = STMT_INDICATOR_NAME;
def->common.next = NULL; def->common.next = NULL;
def->merge = MERGE_DEFAULT; def->merge = MERGE_DEFAULT;
def->ndx = ndx; def->ndx = ndx;
@ -287,9 +289,9 @@ ActionCreate(xkb_atom_t name, ExprDef * args)
act = malloc_or_die(sizeof(*act)); act = malloc_or_die(sizeof(*act));
act->common.stmtType = StmtExpr; act->common.type = STMT_EXPR;
act->common.next = NULL; act->common.next = NULL;
act->op = ExprActionDecl; act->op = EXPR_ACTION_DECL;
act->value.action.name = name; act->value.action.name = name;
act->value.action.args = args; act->value.action.args = args;
return act; return act;
@ -300,7 +302,7 @@ CreateKeysymList(char *sym)
{ {
ExprDef *def; ExprDef *def;
def = ExprCreate(ExprKeysymList, TypeSymbols); def = ExprCreate(EXPR_KEYSYM_LIST, EXPR_TYPE_SYMBOLS);
darray_init(def->value.list.syms); darray_init(def->value.list.syms);
darray_init(def->value.list.symsMapIndex); darray_init(def->value.list.symsMapIndex);
@ -402,8 +404,8 @@ IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge)
if (first == NULL) { if (first == NULL) {
first = incl = malloc(sizeof(*first)); first = incl = malloc(sizeof(*first));
} else { } else {
incl->next = malloc(sizeof(*first)); incl->next_incl = malloc(sizeof(*first));
incl = incl->next; incl = incl->next_incl;
} }
if (!incl) { if (!incl) {
@ -413,7 +415,7 @@ IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge)
break; break;
} }
incl->common.stmtType = StmtInclude; incl->common.type = STMT_INCLUDE;
incl->common.next = NULL; incl->common.next = NULL;
incl->merge = merge; incl->merge = merge;
incl->stmt = NULL; incl->stmt = NULL;
@ -421,7 +423,7 @@ IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge)
incl->map = map; incl->map = map;
incl->modifier = extra_data; incl->modifier = extra_data;
incl->path = NULL; incl->path = NULL;
incl->next = NULL; incl->next_incl = NULL;
if (nextop == '|') if (nextop == '|')
merge = MERGE_AUGMENT; merge = MERGE_AUGMENT;
@ -502,7 +504,7 @@ CreateXKBFile(struct xkb_context *ctx, enum xkb_file_type type, char *name,
return NULL; return NULL;
EnsureSafeMapName(name); EnsureSafeMapName(name);
file->type = type; file->file_type = type;
file->topName = strdup_safe(name); file->topName = strdup_safe(name);
file->name = name; file->name = name;
file->defs = defs; file->defs = defs;
@ -520,32 +522,32 @@ FreeExpr(ExprDef *expr)
return; return;
switch (expr->op) { switch (expr->op) {
case ExprActionList: case EXPR_ACTION_LIST:
case OpNegate: case EXPR_NEGATE:
case OpUnaryPlus: case EXPR_UNARY_PLUS:
case OpNot: case EXPR_NOT:
case OpInvert: case EXPR_INVERT:
FreeStmt(&expr->value.child->common); FreeStmt(&expr->value.child->common);
break; break;
case OpDivide: case EXPR_DIVIDE:
case OpAdd: case EXPR_ADD:
case OpSubtract: case EXPR_SUBTRACT:
case OpMultiply: case EXPR_MULTIPLY:
case OpAssign: case EXPR_ASSIGN:
FreeStmt(&expr->value.binary.left->common); FreeStmt(&expr->value.binary.left->common);
FreeStmt(&expr->value.binary.right->common); FreeStmt(&expr->value.binary.right->common);
break; break;
case ExprActionDecl: case EXPR_ACTION_DECL:
FreeStmt(&expr->value.action.args->common); FreeStmt(&expr->value.action.args->common);
break; break;
case ExprArrayRef: case EXPR_ARRAY_REF:
FreeStmt(&expr->value.array.entry->common); FreeStmt(&expr->value.array.entry->common);
break; break;
case ExprKeysymList: case EXPR_KEYSYM_LIST:
darray_foreach(sym, expr->value.list.syms) darray_foreach(sym, expr->value.list.syms)
free(*sym); free(*sym);
darray_free(expr->value.list.syms); darray_free(expr->value.list.syms);
@ -565,7 +567,7 @@ FreeInclude(IncludeStmt *incl)
while (incl) while (incl)
{ {
next = incl->next; next = incl->next_incl;
free(incl->file); free(incl->file);
free(incl->map); free(incl->map);
@ -589,43 +591,43 @@ FreeStmt(ParseCommon *stmt)
next = stmt->next; next = stmt->next;
u.any = stmt; u.any = stmt;
switch (stmt->stmtType) { switch (stmt->type) {
case StmtInclude: case STMT_INCLUDE:
FreeInclude((IncludeStmt *) stmt); FreeInclude((IncludeStmt *) stmt);
/* stmt is already free'd here. */ /* stmt is already free'd here. */
stmt = NULL; stmt = NULL;
break; break;
case StmtExpr: case STMT_EXPR:
FreeExpr(u.expr); FreeExpr(u.expr);
break; break;
case StmtVarDef: case STMT_VAR:
FreeStmt(&u.var->name->common); FreeStmt(&u.var->name->common);
FreeStmt(&u.var->value->common); FreeStmt(&u.var->value->common);
break; break;
case StmtKeyTypeDef: case STMT_TYPE:
FreeStmt(&u.keyType->body->common); FreeStmt(&u.keyType->body->common);
break; break;
case StmtInterpDef: case STMT_INTERP:
free(u.interp->sym); free(u.interp->sym);
FreeStmt(&u.interp->match->common); FreeStmt(&u.interp->match->common);
FreeStmt(&u.interp->def->common); FreeStmt(&u.interp->def->common);
break; break;
case StmtVModDef: case STMT_VMOD:
FreeStmt(&u.vmod->value->common); FreeStmt(&u.vmod->value->common);
break; break;
case StmtSymbolsDef: case STMT_SYMBOLS:
FreeStmt(&u.syms->symbols->common); FreeStmt(&u.syms->symbols->common);
break; break;
case StmtModMapDef: case STMT_MODMAP:
FreeStmt(&u.modMask->keys->common); FreeStmt(&u.modMask->keys->common);
break; break;
case StmtGroupCompatDef: case STMT_GROUP_COMPAT:
FreeStmt(&u.groupCompat->def->common); FreeStmt(&u.groupCompat->def->common);
break; break;
case StmtIndicatorMapDef: case STMT_INDICATOR_MAP:
FreeStmt(&u.ledMap->body->common); FreeStmt(&u.ledMap->body->common);
break; break;
case StmtIndicatorNameDef: case STMT_INDICATOR_NAME:
FreeStmt(&u.ledName->name->common); FreeStmt(&u.ledName->name->common);
break; break;
default: default:
@ -646,7 +648,7 @@ FreeXKBFile(XkbFile *file)
{ {
next = (XkbFile *) file->common.next; next = (XkbFile *) file->common.next;
switch (file->type) { switch (file->file_type) {
case FILE_TYPE_KEYMAP: case FILE_TYPE_KEYMAP:
FreeXKBFile((XkbFile *) file->defs); FreeXKBFile((XkbFile *) file->defs);
break; break;

View File

@ -50,13 +50,14 @@ extern ParseCommon *
AppendStmt(ParseCommon *to, ParseCommon *append); AppendStmt(ParseCommon *to, ParseCommon *append);
extern ExprDef * extern ExprDef *
ExprCreate(unsigned op, unsigned type); ExprCreate(enum expr_op_type op, enum expr_value_type type);
extern ExprDef * extern ExprDef *
ExprCreateUnary(unsigned op, unsigned type, ExprDef *child); ExprCreateUnary(enum expr_op_type op, enum expr_value_type type,
ExprDef *child);
extern ExprDef * extern ExprDef *
ExprCreateBinary(unsigned op, ExprDef *left, ExprDef *right); ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right);
KeycodeDef * KeycodeDef *
KeycodeCreate(char keyName[XkbKeyNameLength], unsigned long value); KeycodeCreate(char keyName[XkbKeyNameLength], unsigned long value);

View File

@ -167,8 +167,8 @@ XkbDirectoryForInclude(enum xkb_file_type type)
* pathRtrn is undefined. * pathRtrn is undefined.
*/ */
FILE * FILE *
XkbFindFileInPath(struct xkb_context *ctx, XkbFindFileInPath(struct xkb_context *ctx, const char *name,
const char *name, enum xkb_file_type type, char **pathRtrn) enum xkb_file_type type, char **pathRtrn)
{ {
size_t i; size_t i;
int ret; int ret;

View File

@ -37,10 +37,10 @@ XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
char **extra_data); char **extra_data);
const char * const char *
XkbDirectoryForInclude(unsigned type); XkbDirectoryForInclude(enum xkb_file_type type);
FILE * FILE *
XkbFindFileInPath(struct xkb_context *ctx, const char *name, unsigned type, XkbFindFileInPath(struct xkb_context *ctx, const char *name,
char **pathRtrn); enum xkb_file_type type, char **pathRtrn);
#endif /* XKBCOMP_PATH_H */ #endif /* XKBCOMP_PATH_H */

View File

@ -766,7 +766,7 @@ HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
stmt->stmt = NULL; stmt->stmt = NULL;
} }
for (; stmt; stmt = stmt->next) { for (; stmt; stmt = stmt->next_incl) {
if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS, if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
&rtrn, &merge)) { &rtrn, &merge)) {
info->errorCount += 10; info->errorCount += 10;
@ -856,7 +856,7 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
keyi->symsDefined |= (1 << ndx); keyi->symsDefined |= (1 << ndx);
return true; return true;
} }
if (value->op != ExprKeysymList) { if (value->op != EXPR_KEYSYM_LIST) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Expected a list of symbols, found %s; " "Expected a list of symbols, found %s; "
"Ignoring symbols for group %u of %s\n", "Ignoring symbols for group %u of %s\n",
@ -946,7 +946,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
return true; return true;
} }
if (value->op != ExprActionList) { if (value->op != EXPR_ACTION_LIST) {
log_wsgo(info->keymap->ctx, log_wsgo(info->keymap->ctx,
"Bad expression type (%d) for action list value; " "Bad expression type (%d) for action list value; "
"Ignoring actions for group %u of %s\n", "Ignoring actions for group %u of %s\n",
@ -1247,14 +1247,14 @@ HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
ExprResult tmp, field; ExprResult tmp, field;
ExprDef *arrayNdx; ExprDef *arrayNdx;
for (; def != NULL; def = (VarDef *) def->common.next) { for (; def; def = (VarDef *) def->common.next) {
if ((def->name) && (def->name->type == ExprFieldRef)) { if (def->name && def->name->op == EXPR_FIELD_REF) {
ok = HandleSymbolsVar(info, def); ok = HandleSymbolsVar(info, def);
continue; continue;
} }
if (!def->name) { if (!def->name) {
if (!def->value || (def->value->op == ExprKeysymList)) if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
field.str = "symbols"; field.str = "symbols";
else else
field.str = "actions"; field.str = "actions";
@ -1349,7 +1349,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
bool ok; bool ok;
struct xkb_context *ctx = info->keymap->ctx; struct xkb_context *ctx = info->keymap->ctx;
if (!LookupModIndex(ctx, NULL, def->modifier, TypeInt, &rtrn)) { if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &rtrn)) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Illegal modifier map definition; " "Illegal modifier map definition; "
"Ignoring map for non-modifier \"%s\"\n", "Ignoring map for non-modifier \"%s\"\n",
@ -1359,7 +1359,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
ok = true; ok = true;
tmp.modifier = rtrn.uval; tmp.modifier = rtrn.uval;
for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) { for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
if ((key->op == ExprValue) && (key->type == TypeKeyName)) { if (key->op == EXPR_VALUE && key->value_type == EXPR_TYPE_KEYNAME) {
tmp.haveSymbol = false; tmp.haveSymbol = false;
tmp.u.keyName = KeyNameToLong(key->value.keyName); tmp.u.keyName = KeyNameToLong(key->value.keyName);
} }
@ -1390,44 +1390,44 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
stmt = file->defs; stmt = file->defs;
while (stmt) while (stmt)
{ {
switch (stmt->stmtType) { switch (stmt->type) {
case StmtInclude: case STMT_INCLUDE:
if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt)) if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtSymbolsDef: case STMT_SYMBOLS:
if (!HandleSymbolsDef(info, (SymbolsDef *) stmt)) if (!HandleSymbolsDef(info, (SymbolsDef *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtVarDef: case STMT_VAR:
if (!HandleSymbolsVar(info, (VarDef *) stmt)) if (!HandleSymbolsVar(info, (VarDef *) stmt))
info->errorCount++; info->errorCount++;
break; break;
case StmtVModDef: case STMT_VMOD:
if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods)) &info->vmods))
info->errorCount++; info->errorCount++;
break; break;
case StmtInterpDef: case STMT_INTERP:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Interpretation files may not include other types; " "Interpretation files may not include other types; "
"Ignoring definition of symbol interpretation\n"); "Ignoring definition of symbol interpretation\n");
info->errorCount++; info->errorCount++;
break; break;
case StmtKeycodeDef: case STMT_KEYCODE:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Interpretation files may not include other types; " "Interpretation files may not include other types; "
"Ignoring definition of key name\n"); "Ignoring definition of key name\n");
info->errorCount++; info->errorCount++;
break; break;
case StmtModMapDef: case STMT_MODMAP:
if (!HandleModMapDef(info, (ModMapDef *) stmt)) if (!HandleModMapDef(info, (ModMapDef *) stmt))
info->errorCount++; info->errorCount++;
break; break;
default: default:
log_wsgo(info->keymap->ctx, log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleSymbolsFile\n", "Unexpected statement type %d in HandleSymbolsFile\n",
stmt->stmtType); stmt->type);
break; break;
} }
stmt = stmt->next; stmt = stmt->next;

View File

@ -149,7 +149,7 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
* *
* @param keymap Pointer to the xkb data structure. * @param keymap Pointer to the xkb data structure.
* @param field The Atom of the modifier's name (e.g. Atom for LAlt) * @param field The Atom of the modifier's name (e.g. Atom for LAlt)
* @param type Must be TypeInt, otherwise return false. * @param type Must be EXPR_TYPE_INT, otherwise return false.
* @param val_rtrn Set to the index of the modifier that matches. * @param val_rtrn Set to the index of the modifier that matches.
* *
* @return true on success, false otherwise. If false is returned, val_rtrn is * @return true on success, false otherwise. If false is returned, val_rtrn is
@ -157,12 +157,12 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
*/ */
static int static int
LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field, LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
unsigned type, ExprResult * val_rtrn) enum expr_value_type type, ExprResult * val_rtrn)
{ {
xkb_mod_index_t i; xkb_mod_index_t i;
const char *name = xkb_atom_text(keymap->ctx, field); const char *name = xkb_atom_text(keymap->ctx, field);
if (type != TypeInt) if (type != EXPR_TYPE_INT)
return false; return false;
/* For each named modifier, get the name and compare it to the one passed /* For each named modifier, get the name and compare it to the one passed
@ -192,7 +192,7 @@ LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
*/ */
bool bool
LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
unsigned type, ExprResult *val_rtrn) enum expr_value_type type, ExprResult *val_rtrn)
{ {
if (LookupModMask(ctx, NULL, field, type, val_rtrn)) { if (LookupModMask(ctx, NULL, field, type, val_rtrn)) {
return true; return true;
@ -212,7 +212,7 @@ FindKeypadVMod(struct xkb_keymap *keymap)
ExprResult rtrn; ExprResult rtrn;
name = xkb_atom_intern(keymap->ctx, "NumLock"); name = xkb_atom_intern(keymap->ctx, "NumLock");
if ((keymap) && LookupVModIndex(keymap, name, TypeInt, &rtrn)) { if ((keymap) && LookupVModIndex(keymap, name, EXPR_TYPE_INT, &rtrn)) {
return rtrn.ival; return rtrn.ival;
} }
return -1; return -1;
@ -222,7 +222,7 @@ bool
ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap, ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
ExprResult *val_rtrn, VModInfo *info) ExprResult *val_rtrn, VModInfo *info)
{ {
if (def->op == ExprIdent) { if (def->op == EXPR_IDENT) {
xkb_mod_index_t i; xkb_mod_index_t i;
xkb_mod_mask_t bit; xkb_mod_mask_t bit;
const char *name = xkb_atom_text(keymap->ctx, def->value.str); const char *name = xkb_atom_text(keymap->ctx, def->value.str);

View File

@ -102,24 +102,24 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
* Other aggregate file types are converted to FILE_TYPE_KEYMAP * Other aggregate file types are converted to FILE_TYPE_KEYMAP
* in the parser. * in the parser.
*/ */
if (file->type != FILE_TYPE_KEYMAP) { if (file->file_type != FILE_TYPE_KEYMAP) {
log_err(ctx, "Cannot compile a %s file alone into a keymap\n", log_err(ctx, "Cannot compile a %s file alone into a keymap\n",
FileTypeText(file->type)); FileTypeText(file->file_type));
goto err; goto err;
} }
/* Check for duplicate entries in the input file */ /* Check for duplicate entries in the input file */
for (file = (XkbFile *) file->defs; file; for (file = (XkbFile *) file->defs; file;
file = (XkbFile *) file->common.next) { file = (XkbFile *) file->common.next) {
if (have & file->type) { if (have & file->file_type) {
log_err(ctx, log_err(ctx,
"More than one %s section in a keymap file; " "More than one %s section in a keymap file; "
"All sections after the first ignored\n", "All sections after the first ignored\n",
FileTypeText(file->type)); FileTypeText(file->file_type));
continue; continue;
} }
switch (file->type) { switch (file->file_type) {
case FILE_TYPE_KEYCODES: case FILE_TYPE_KEYCODES:
keycodes = file; keycodes = file;
break; break;
@ -138,7 +138,7 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
default: default:
log_err(ctx, "Cannot define %s in a keymap file\n", log_err(ctx, "Cannot define %s in a keymap file\n",
FileTypeText(file->type)); FileTypeText(file->file_type));
continue; continue;
} }
@ -147,7 +147,7 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
file->topName = strdup(main_name); file->topName = strdup(main_name);
} }
have |= file->type; have |= file->file_type;
} }
if (REQUIRED_FILE_TYPES & (~have)) { if (REQUIRED_FILE_TYPES & (~have)) {

View File

@ -29,51 +29,51 @@
#include "xkb-priv.h" #include "xkb-priv.h"
#define TypeUnknown 0 enum stmt_type {
#define TypeBoolean 1 STMT_UNKNOWN = 0,
#define TypeInt 2 STMT_INCLUDE,
#define TypeString 4 STMT_KEYCODE,
#define TypeAction 5 STMT_ALIAS,
#define TypeKeyName 6 STMT_EXPR,
#define TypeSymbols 7 STMT_VAR,
STMT_TYPE,
STMT_INTERP,
STMT_VMOD,
STMT_SYMBOLS,
STMT_MODMAP,
STMT_GROUP_COMPAT,
STMT_INDICATOR_MAP,
STMT_INDICATOR_NAME,
};
#define StmtUnknown 0 enum expr_value_type {
#define StmtInclude 1 EXPR_TYPE_UNKNOWN = 0,
#define StmtKeycodeDef 2 EXPR_TYPE_BOOLEAN,
#define StmtKeyAliasDef 3 EXPR_TYPE_INT,
#define StmtExpr 4 EXPR_TYPE_STRING,
#define StmtVarDef 5 EXPR_TYPE_ACTION,
#define StmtKeyTypeDef 6 EXPR_TYPE_KEYNAME,
#define StmtInterpDef 7 EXPR_TYPE_SYMBOLS,
#define StmtVModDef 8 };
#define StmtSymbolsDef 9
#define StmtModMapDef 10
#define StmtGroupCompatDef 11
#define StmtIndicatorMapDef 12
#define StmtIndicatorNameDef 13
typedef struct _ParseCommon { enum expr_op_type {
unsigned stmtType; EXPR_VALUE = 0,
struct _ParseCommon *next; EXPR_IDENT,
} ParseCommon; EXPR_ACTION_DECL,
EXPR_FIELD_REF,
#define ExprValue 0 EXPR_ARRAY_REF,
#define ExprIdent 1 EXPR_KEYSYM_LIST,
#define ExprActionDecl 2 EXPR_ACTION_LIST,
#define ExprFieldRef 3 EXPR_ADD,
#define ExprArrayRef 4 EXPR_SUBTRACT,
#define ExprKeysymList 5 EXPR_MULTIPLY,
#define ExprActionList 6 EXPR_DIVIDE,
EXPR_ASSIGN,
#define OpAdd 20 EXPR_NOT,
#define OpSubtract 21 EXPR_NEGATE,
#define OpMultiply 22 EXPR_INVERT,
#define OpDivide 23 EXPR_UNARY_PLUS,
#define OpAssign 24 };
#define OpNot 25
#define OpNegate 26
#define OpInvert 27
#define OpUnaryPlus 28
enum merge_mode { enum merge_mode {
MERGE_DEFAULT, MERGE_DEFAULT,
@ -82,8 +82,10 @@ enum merge_mode {
MERGE_REPLACE, MERGE_REPLACE,
}; };
#define AutoKeyNames (1L << 0) typedef struct _ParseCommon {
#define CreateKeyNames(x) ((x)->flags & AutoKeyNames) enum stmt_type type;
struct _ParseCommon *next;
} ParseCommon;
typedef struct _IncludeStmt { typedef struct _IncludeStmt {
ParseCommon common; ParseCommon common;
@ -93,13 +95,13 @@ typedef struct _IncludeStmt {
char *map; char *map;
char *modifier; char *modifier;
char *path; char *path;
struct _IncludeStmt *next; struct _IncludeStmt *next_incl;
} IncludeStmt; } IncludeStmt;
typedef struct _Expr { typedef struct _Expr {
ParseCommon common; ParseCommon common;
unsigned op; enum expr_op_type op;
unsigned type; enum expr_value_type value_type;
union { union {
struct { struct {
struct _Expr *left; struct _Expr *left;
@ -206,14 +208,13 @@ typedef struct _IndicatorNameDef {
typedef struct _IndicatorMapDef { typedef struct _IndicatorMapDef {
ParseCommon common; ParseCommon common;
enum merge_mode merge; enum merge_mode merge;
unsigned type;
xkb_atom_t name; xkb_atom_t name;
VarDef *body; VarDef *body;
} IndicatorMapDef; } IndicatorMapDef;
typedef struct _XkbFile { typedef struct _XkbFile {
ParseCommon common; ParseCommon common;
enum xkb_file_type type; enum xkb_file_type file_type;
char *topName; char *topName;
char *name; char *name;
ParseCommon *defs; ParseCommon *defs;
@ -237,4 +238,7 @@ extern bool
CompileSymbols(XkbFile *file, struct xkb_keymap *keymap, CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
enum merge_mode merge); enum merge_mode merge);
#define AutoKeyNames (1L << 0)
#define CreateKeyNames(x) ((x)->flags & AutoKeyNames)
#endif /* XKBCOMP_H */ #endif /* XKBCOMP_H */