Remove VModInfo for now
authorRan Benita <ran234@gmail.com>
Fri, 5 Oct 2012 19:06:34 +0000 (21:06 +0200)
committerRan Benita <ran234@gmail.com>
Sat, 6 Oct 2012 19:41:59 +0000 (21:41 +0200)
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>
src/xkbcomp/compat.c
src/xkbcomp/expr.c
src/xkbcomp/expr.h
src/xkbcomp/symbols.c
src/xkbcomp/types.c
src/xkbcomp/vmod.c
src/xkbcomp/vmod.h

index d883ab3..0c94346 100644 (file)
@@ -195,7 +195,6 @@ typedef struct {
     darray(SymInterpInfo) interps;
     LEDInfo ledDflt;
     darray(LEDInfo) leds;
-    VModInfo vmods;
     ActionsInfo *actions;
     struct xkb_keymap *keymap;
 } CompatInfo;
@@ -260,7 +259,6 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id,
     info->dflt.interp.virtual_mod = XKB_MOD_INVALID;
     info->ledDflt.file_id = file_id;
     info->ledDflt.merge = MERGE_OVERRIDE;
-    InitVModInfo(&info->vmods, keymap);
 }
 
 static void
@@ -584,7 +582,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
         if (arrayNdx)
             return ReportSINotArray(info, si, field);
 
-        if (!ResolveVirtualModifier(value, keymap, &ndx, &info->vmods))
+        if (!ExprResolveVMod(keymap, value, &ndx))
             return ReportSIBadType(info, si, field, "virtual modifier");
 
         si->interp.virtual_mod = ndx;
@@ -898,7 +896,7 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
             ok = HandleGlobalVar(info, (VarDef *) stmt);
             break;
         case STMT_VMOD:
-            ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods);
+            ok = HandleVModDef(info->keymap, (VModDef *) stmt);
             break;
         default:
             log_err(info->keymap->ctx,
index cf6ff40..c8197d1 100644 (file)
@@ -90,7 +90,7 @@ LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
     return (*val_rtrn != XKB_MOD_INVALID);
 }
 
-bool
+static bool
 LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
               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);
 }
 
+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
 ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr,
                     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';
     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;
+}
index 21d9c5d..a5abce1 100644 (file)
@@ -33,14 +33,6 @@ ExprResolveLhs(struct xkb_context *ctx, const ExprDef *expr,
                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
 LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
                enum expr_value_type type, xkb_mod_index_t *val_rtrn);
 
@@ -53,6 +45,10 @@ ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr,
                     xkb_mod_mask_t *mask_rtrn);
 
 bool
+ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
+                xkb_mod_index_t *ndx_rtrn);
+
+bool
 ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr,
                    bool *set_rtrn);
 
index bb6ccc6..06661ae 100644 (file)
@@ -179,7 +179,6 @@ typedef struct {
     xkb_layout_index_t explicit_group;
     darray(KeyInfo) keys;
     KeyInfo dflt;
-    VModInfo vmods;
     ActionsInfo *actions;
     darray_xkb_atom_t group_names;
     darray(ModMapEntry) modMaps;
@@ -196,7 +195,6 @@ InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap,
     info->file_id = file_id;
     info->merge = MERGE_OVERRIDE;
     InitKeyInfo(keymap->ctx, &info->dflt, file_id);
-    InitVModInfo(&info->vmods, keymap);
     info->actions = actions;
     info->explicit_group = XKB_LAYOUT_INVALID;
 }
@@ -1268,7 +1266,7 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
             ok = HandleGlobalVar(info, (VarDef *) stmt);
             break;
         case STMT_VMOD:
-            ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods);
+            ok = HandleVModDef(info->keymap, (VModDef *) stmt);
             break;
         case STMT_MODMAP:
             ok = HandleModMapDef(info, (ModMapDef *) stmt);
index 73c1427..5eff5f4 100644 (file)
@@ -160,7 +160,6 @@ typedef struct {
     unsigned file_id;
 
     darray(KeyTypeInfo) types;
-    VModInfo vmods;
     struct xkb_keymap *keymap;
 } KeyTypesInfo;
 
@@ -219,7 +218,6 @@ InitKeyTypesInfo(KeyTypesInfo *info, struct xkb_keymap *keymap,
     memset(info, 0, sizeof(*info));
     info->keymap = keymap;
     info->file_id = file_id;
-    InitVModInfo(&info->vmods, keymap);
 }
 
 static void
@@ -761,7 +759,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
             ok = true;
             break;
         case STMT_VMOD: /* virtual_modifiers NumLock, ... */
-            ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods);
+            ok = HandleVModDef(info->keymap, (VModDef *) stmt);
             break;
         default:
             log_err(info->keymap->ctx,
index 51269be..5e8a6c5 100644 (file)
 #include "expr.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
-HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info)
+HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt)
 {
     xkb_mod_index_t i;
     const char *name;
@@ -61,12 +51,9 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info)
         return false;
     }
 
-    darray_enumerate(i, vmod, keymap->vmods) {
-        if (vmod->name == stmt->name) {
-            info->available |= 1 << i;
+    darray_enumerate(i, vmod, keymap->vmods)
+        if (vmod->name == stmt->name)
             return true;
-        }
-    }
 
     if (darray_size(keymap->vmods) >= XKB_MAX_VIRTUAL_MODS) {
         log_err(keymap->ctx,
@@ -78,73 +65,5 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info)
     new.name = stmt->name;
     new.mapping = 0;
     darray_append(keymap->vmods, new);
-    info->available |= (1 << (darray_size(keymap->vmods) - 1));
     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;
-}
index 6fdd891..9915507 100644 (file)
 #ifndef 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
-HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info);
-
 bool
-ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
-                       xkb_mod_index_t *ndx_rtrn, VModInfo *info);
+HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt);
 
 #endif