Remove VModInfo for now

VModInfo currently is only used to track which virtual modifiers were
declared in the file which owns the VModInfo. This, in turn, is only
used in ResolveVirtualModifier, which in turn is only used to resolve
the virtualModifier field in an interpret statement (compat.c). In other
words, it is used to ensure that interprets can only use a vmod which
was declared in the same map.

We remove this now, because it doesn't do much and distracts from other
changes; we will later re-add it properly. Specificly, we will make it
so that virtual modifiers are not the exception in that they modify the
keymap directly, instead of keeping the changes in some *Info struct and
commiting them to the keymap at the end of the compilation. (This is bad
because if a vmod is added to the keymap, and then the compilation of
this specific file fails, the change sticks around nonetheless).

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-10-05 21:06:34 +02:00
parent 9a2ce2a5ad
commit aed3140e8d
7 changed files with 81 additions and 116 deletions

View File

@ -195,7 +195,6 @@ typedef struct {
darray(SymInterpInfo) interps; darray(SymInterpInfo) interps;
LEDInfo ledDflt; LEDInfo ledDflt;
darray(LEDInfo) leds; darray(LEDInfo) leds;
VModInfo vmods;
ActionsInfo *actions; ActionsInfo *actions;
struct xkb_keymap *keymap; struct xkb_keymap *keymap;
} CompatInfo; } CompatInfo;
@ -260,7 +259,6 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id,
info->dflt.interp.virtual_mod = XKB_MOD_INVALID; info->dflt.interp.virtual_mod = XKB_MOD_INVALID;
info->ledDflt.file_id = file_id; info->ledDflt.file_id = file_id;
info->ledDflt.merge = MERGE_OVERRIDE; info->ledDflt.merge = MERGE_OVERRIDE;
InitVModInfo(&info->vmods, keymap);
} }
static void static void
@ -584,7 +582,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
if (arrayNdx) if (arrayNdx)
return ReportSINotArray(info, si, field); return ReportSINotArray(info, si, field);
if (!ResolveVirtualModifier(value, keymap, &ndx, &info->vmods)) if (!ExprResolveVMod(keymap, value, &ndx))
return ReportSIBadType(info, si, field, "virtual modifier"); return ReportSIBadType(info, si, field, "virtual modifier");
si->interp.virtual_mod = ndx; si->interp.virtual_mod = ndx;
@ -898,7 +896,7 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
ok = HandleGlobalVar(info, (VarDef *) stmt); ok = HandleGlobalVar(info, (VarDef *) stmt);
break; break;
case STMT_VMOD: case STMT_VMOD:
ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods); ok = HandleVModDef(info->keymap, (VModDef *) stmt);
break; break;
default: default:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,

View File

@ -90,7 +90,7 @@ LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
return (*val_rtrn != XKB_MOD_INVALID); return (*val_rtrn != XKB_MOD_INVALID);
} }
bool static 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,
enum expr_value_type type, xkb_mod_mask_t *val_rtrn) enum expr_value_type type, xkb_mod_mask_t *val_rtrn)
{ {
@ -624,6 +624,44 @@ ExprResolveModMask(struct xkb_context *ctx, const ExprDef *expr,
return ExprResolveMaskLookup(ctx, expr, mask_rtrn, LookupModMask, NULL); return ExprResolveMaskLookup(ctx, expr, mask_rtrn, LookupModMask, NULL);
} }
static bool
LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
enum expr_value_type type, xkb_mod_index_t *val_rtrn)
{
const struct xkb_vmod *vmod;
xkb_mod_index_t i;
if (type != EXPR_TYPE_INT)
return false;
darray_enumerate(i, vmod, keymap->vmods) {
if (vmod->name == field) {
*val_rtrn = i;
return true;
}
}
return false;
}
static bool
LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
enum expr_value_type type, xkb_mod_mask_t *val_rtrn)
{
xkb_mod_index_t ndx;
if (LookupModMask(ctx, NULL, field, type, val_rtrn)) {
return true;
}
else if (LookupVModIndex(priv, field, type, &ndx)) {
*val_rtrn = (1 << (XKB_NUM_CORE_MODS + ndx));
return true;
}
return false;
}
bool bool
ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr, ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr,
xkb_mod_mask_t *mask_rtrn) xkb_mod_mask_t *mask_rtrn)
@ -655,3 +693,33 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
*sym_rtrn = ((xkb_keysym_t) val) + '0'; *sym_rtrn = ((xkb_keysym_t) val) + '0';
return true; return true;
} }
bool
ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
xkb_mod_index_t *ndx_rtrn)
{
const struct xkb_vmod *vmod;
xkb_mod_index_t i;
xkb_atom_t name = def->value.str;
if (def->op != EXPR_IDENT) {
log_err(keymap->ctx,
"Cannot resolve virtual modifier: "
"found %s where a virtual modifier name was expected\n",
expr_op_type_to_string(def->op));
return false;
}
darray_enumerate(i, vmod, keymap->vmods) {
if (vmod->name == name) {
*ndx_rtrn = i;
return true;
}
}
log_err(keymap->ctx,
"Cannot resolve virtual modifier: "
"\"%s\" was not previously declared\n",
xkb_atom_text(keymap->ctx, name));
return false;
}

View File

@ -32,14 +32,6 @@ ExprResolveLhs(struct xkb_context *ctx, const ExprDef *expr,
const char **elem_rtrn, const char **field_rtrn, const char **elem_rtrn, const char **field_rtrn,
ExprDef **index_rtrn); ExprDef **index_rtrn);
bool
LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
enum expr_value_type type, xkb_mod_mask_t *val_rtrn);
bool
LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
enum expr_value_type type, xkb_mod_mask_t *val_rtrn);
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,
enum expr_value_type type, xkb_mod_index_t *val_rtrn); enum expr_value_type type, xkb_mod_index_t *val_rtrn);
@ -52,6 +44,10 @@ bool
ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr, ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr,
xkb_mod_mask_t *mask_rtrn); xkb_mod_mask_t *mask_rtrn);
bool
ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
xkb_mod_index_t *ndx_rtrn);
bool bool
ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr, ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr,
bool *set_rtrn); bool *set_rtrn);

View File

@ -179,7 +179,6 @@ typedef struct {
xkb_layout_index_t explicit_group; xkb_layout_index_t explicit_group;
darray(KeyInfo) keys; darray(KeyInfo) keys;
KeyInfo dflt; KeyInfo dflt;
VModInfo vmods;
ActionsInfo *actions; ActionsInfo *actions;
darray_xkb_atom_t group_names; darray_xkb_atom_t group_names;
darray(ModMapEntry) modMaps; darray(ModMapEntry) modMaps;
@ -196,7 +195,6 @@ InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap,
info->file_id = file_id; info->file_id = file_id;
info->merge = MERGE_OVERRIDE; info->merge = MERGE_OVERRIDE;
InitKeyInfo(keymap->ctx, &info->dflt, file_id); InitKeyInfo(keymap->ctx, &info->dflt, file_id);
InitVModInfo(&info->vmods, keymap);
info->actions = actions; info->actions = actions;
info->explicit_group = XKB_LAYOUT_INVALID; info->explicit_group = XKB_LAYOUT_INVALID;
} }
@ -1268,7 +1266,7 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
ok = HandleGlobalVar(info, (VarDef *) stmt); ok = HandleGlobalVar(info, (VarDef *) stmt);
break; break;
case STMT_VMOD: case STMT_VMOD:
ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods); ok = HandleVModDef(info->keymap, (VModDef *) stmt);
break; break;
case STMT_MODMAP: case STMT_MODMAP:
ok = HandleModMapDef(info, (ModMapDef *) stmt); ok = HandleModMapDef(info, (ModMapDef *) stmt);

View File

@ -160,7 +160,6 @@ typedef struct {
unsigned file_id; unsigned file_id;
darray(KeyTypeInfo) types; darray(KeyTypeInfo) types;
VModInfo vmods;
struct xkb_keymap *keymap; struct xkb_keymap *keymap;
} KeyTypesInfo; } KeyTypesInfo;
@ -219,7 +218,6 @@ InitKeyTypesInfo(KeyTypesInfo *info, struct xkb_keymap *keymap,
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->keymap = keymap; info->keymap = keymap;
info->file_id = file_id; info->file_id = file_id;
InitVModInfo(&info->vmods, keymap);
} }
static void static void
@ -761,7 +759,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
ok = true; ok = true;
break; break;
case STMT_VMOD: /* virtual_modifiers NumLock, ... */ case STMT_VMOD: /* virtual_modifiers NumLock, ... */
ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods); ok = HandleVModDef(info->keymap, (VModDef *) stmt);
break; break;
default: default:
log_err(info->keymap->ctx, log_err(info->keymap->ctx,

View File

@ -29,18 +29,8 @@
#include "expr.h" #include "expr.h"
#include "vmod.h" #include "vmod.h"
void
InitVModInfo(VModInfo *info, struct xkb_keymap *keymap)
{
xkb_mod_index_t i;
memset(info, 0, sizeof(*info));
for (i = 0; i < darray_size(keymap->vmods); i++)
info->defined |= (1 << i);
}
bool bool
HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info) HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt)
{ {
xkb_mod_index_t i; xkb_mod_index_t i;
const char *name; const char *name;
@ -61,12 +51,9 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info)
return false; return false;
} }
darray_enumerate(i, vmod, keymap->vmods) { darray_enumerate(i, vmod, keymap->vmods)
if (vmod->name == stmt->name) { if (vmod->name == stmt->name)
info->available |= 1 << i;
return true; return true;
}
}
if (darray_size(keymap->vmods) >= XKB_MAX_VIRTUAL_MODS) { if (darray_size(keymap->vmods) >= XKB_MAX_VIRTUAL_MODS) {
log_err(keymap->ctx, log_err(keymap->ctx,
@ -78,73 +65,5 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info)
new.name = stmt->name; new.name = stmt->name;
new.mapping = 0; new.mapping = 0;
darray_append(keymap->vmods, new); darray_append(keymap->vmods, new);
info->available |= (1 << (darray_size(keymap->vmods) - 1));
return true; return true;
} }
static bool
LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
enum expr_value_type type, xkb_mod_index_t *val_rtrn)
{
const struct xkb_vmod *vmod;
xkb_mod_index_t i;
if (type != EXPR_TYPE_INT)
return false;
darray_enumerate(i, vmod, keymap->vmods) {
if (vmod->name == field) {
*val_rtrn = i;
return true;
}
}
return false;
}
bool
LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
enum expr_value_type type, xkb_mod_mask_t *val_rtrn)
{
xkb_mod_index_t ndx;
if (LookupModMask(ctx, NULL, field, type, val_rtrn)) {
return true;
}
else if (LookupVModIndex(priv, field, type, &ndx)) {
*val_rtrn = (1 << (XKB_NUM_CORE_MODS + ndx));
return true;
}
return false;
}
bool
ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
xkb_mod_index_t *ndx_rtrn, VModInfo *info)
{
const struct xkb_vmod *vmod;
xkb_mod_index_t i;
xkb_atom_t name = def->value.str;
if (def->op != EXPR_IDENT) {
log_err(keymap->ctx,
"Cannot resolve virtual modifier: "
"found %s where a virtual modifier name was expected\n",
expr_op_type_to_string(def->op));
return false;
}
darray_enumerate(i, vmod, keymap->vmods) {
if ((info->available & (1 << i)) && vmod->name == name) {
*ndx_rtrn = i;
return true;
}
}
log_err(keymap->ctx,
"Cannot resolve virtual modifier: "
"\"%s\" was not previously declared\n",
xkb_atom_text(keymap->ctx, name));
return false;
}

View File

@ -27,19 +27,7 @@
#ifndef XKBCOMP_VMOD_H #ifndef XKBCOMP_VMOD_H
#define XKBCOMP_VMOD_H #define XKBCOMP_VMOD_H
typedef struct {
xkb_mod_mask_t defined;
xkb_mod_mask_t available;
} VModInfo;
void
InitVModInfo(VModInfo *info, struct xkb_keymap *keymap);
bool bool
HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info); HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt);
bool
ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
xkb_mod_index_t *ndx_rtrn, VModInfo *info);
#endif #endif