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

View File

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

View File

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

View File

@ -47,22 +47,19 @@ typedef struct _LookupEntry {
} LookupEntry;
extern const char *
exprOpText(unsigned type);
exprOpText(enum expr_op_type op);
extern bool
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);
extern bool
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);
extern bool
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);
extern int
ExprResolveModMask(struct xkb_context *ctx, ExprDef *expr,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -766,7 +766,7 @@ HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
stmt->stmt = NULL;
}
for (; stmt; stmt = stmt->next) {
for (; stmt; stmt = stmt->next_incl) {
if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
&rtrn, &merge)) {
info->errorCount += 10;
@ -856,7 +856,7 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
keyi->symsDefined |= (1 << ndx);
return true;
}
if (value->op != ExprKeysymList) {
if (value->op != EXPR_KEYSYM_LIST) {
log_err(info->keymap->ctx,
"Expected a list of symbols, found %s; "
"Ignoring symbols for group %u of %s\n",
@ -946,7 +946,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
return true;
}
if (value->op != ExprActionList) {
if (value->op != EXPR_ACTION_LIST) {
log_wsgo(info->keymap->ctx,
"Bad expression type (%d) for action list value; "
"Ignoring actions for group %u of %s\n",
@ -1247,14 +1247,14 @@ HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
ExprResult tmp, field;
ExprDef *arrayNdx;
for (; def != NULL; def = (VarDef *) def->common.next) {
if ((def->name) && (def->name->type == ExprFieldRef)) {
for (; def; def = (VarDef *) def->common.next) {
if (def->name && def->name->op == EXPR_FIELD_REF) {
ok = HandleSymbolsVar(info, def);
continue;
}
if (!def->name) {
if (!def->value || (def->value->op == ExprKeysymList))
if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
field.str = "symbols";
else
field.str = "actions";
@ -1349,7 +1349,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
bool ok;
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,
"Illegal modifier map definition; "
"Ignoring map for non-modifier \"%s\"\n",
@ -1359,7 +1359,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
ok = true;
tmp.modifier = rtrn.uval;
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.u.keyName = KeyNameToLong(key->value.keyName);
}
@ -1390,44 +1390,44 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
stmt = file->defs;
while (stmt)
{
switch (stmt->stmtType) {
case StmtInclude:
switch (stmt->type) {
case STMT_INCLUDE:
if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt))
info->errorCount++;
break;
case StmtSymbolsDef:
case STMT_SYMBOLS:
if (!HandleSymbolsDef(info, (SymbolsDef *) stmt))
info->errorCount++;
break;
case StmtVarDef:
case STMT_VAR:
if (!HandleSymbolsVar(info, (VarDef *) stmt))
info->errorCount++;
break;
case StmtVModDef:
case STMT_VMOD:
if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods))
info->errorCount++;
break;
case StmtInterpDef:
case STMT_INTERP:
log_err(info->keymap->ctx,
"Interpretation files may not include other types; "
"Ignoring definition of symbol interpretation\n");
info->errorCount++;
break;
case StmtKeycodeDef:
case STMT_KEYCODE:
log_err(info->keymap->ctx,
"Interpretation files may not include other types; "
"Ignoring definition of key name\n");
info->errorCount++;
break;
case StmtModMapDef:
case STMT_MODMAP:
if (!HandleModMapDef(info, (ModMapDef *) stmt))
info->errorCount++;
break;
default:
log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleSymbolsFile\n",
stmt->stmtType);
stmt->type);
break;
}
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 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.
*
* @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
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;
const char *name = xkb_atom_text(keymap->ctx, field);
if (type != TypeInt)
if (type != EXPR_TYPE_INT)
return false;
/* 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
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)) {
return true;
@ -212,7 +212,7 @@ FindKeypadVMod(struct xkb_keymap *keymap)
ExprResult rtrn;
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 -1;
@ -222,7 +222,7 @@ bool
ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
ExprResult *val_rtrn, VModInfo *info)
{
if (def->op == ExprIdent) {
if (def->op == EXPR_IDENT) {
xkb_mod_index_t i;
xkb_mod_mask_t bit;
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
* 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",
FileTypeText(file->type));
FileTypeText(file->file_type));
goto err;
}
/* Check for duplicate entries in the input file */
for (file = (XkbFile *) file->defs; file;
file = (XkbFile *) file->common.next) {
if (have & file->type) {
if (have & file->file_type) {
log_err(ctx,
"More than one %s section in a keymap file; "
"All sections after the first ignored\n",
FileTypeText(file->type));
FileTypeText(file->file_type));
continue;
}
switch (file->type) {
switch (file->file_type) {
case FILE_TYPE_KEYCODES:
keycodes = file;
break;
@ -138,7 +138,7 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
default:
log_err(ctx, "Cannot define %s in a keymap file\n",
FileTypeText(file->type));
FileTypeText(file->file_type));
continue;
}
@ -147,7 +147,7 @@ compile_keymap(struct xkb_context *ctx, XkbFile *file)
file->topName = strdup(main_name);
}
have |= file->type;
have |= file->file_type;
}
if (REQUIRED_FILE_TYPES & (~have)) {

View File

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