Commit 41d9afc5560e8770f19d009eb76854b0345e580b

Ran Benita 2012-07-27T15:31:03

Remove ExprResult Convert the IdentLookup typedef away from ExprResult, which drags along everything else. This should also make all of the conversions explicit. Signed-off-by: Ran Benita <ran234@gmail.com>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index bdfbbb1..602f833 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -116,16 +116,16 @@ static const LookupEntry fieldStrings[] = {
 
 static bool
 stringToValue(const LookupEntry tab[], const char *string,
-              unsigned *value_rtrn)
+              unsigned int *value_rtrn)
 {
     const LookupEntry *entry;
 
     if (!string)
         return false;
 
-    for (entry = tab; entry->name != NULL; entry++) {
+    for (entry = tab; entry->name; entry++) {
         if (istreq(entry->name, string)) {
-            *value_rtrn = entry->result;
+            *value_rtrn = entry->value;
             return true;
         }
     }
@@ -134,12 +134,12 @@ stringToValue(const LookupEntry tab[], const char *string,
 }
 
 static const char *
-valueToString(const LookupEntry tab[], unsigned value)
+valueToString(const LookupEntry tab[], unsigned int value)
 {
     const LookupEntry *entry;
 
-    for (entry = tab; entry->name != NULL; entry++)
-        if (entry->result == value)
+    for (entry = tab; entry->name; entry++)
+        if (entry->value == value)
             return entry->name;
 
     return "unknown";
@@ -483,7 +483,6 @@ static bool
 HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
              unsigned field, ExprDef *array_ndx, ExprDef *value)
 {
-    ExprResult rtrn;
     struct xkb_pointer_button_action *act;
 
     act = (struct xkb_pointer_button_action *) action;
@@ -534,7 +533,7 @@ HandlePtrBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
         if (btn < 0 || btn > 255) {
             log_err(keymap->ctx,
                     "The count field must have a value in the range 0..255; "
-                    "Illegal count %d ignored\n", rtrn.ival);
+                    "Illegal count %d ignored\n", btn);
             return false;
         }
 
@@ -555,7 +554,6 @@ static bool
 HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
                  unsigned field, ExprDef *array_ndx, ExprDef *value)
 {
-    ExprResult rtrn;
     struct xkb_pointer_default_action *act;
 
     act = (struct xkb_pointer_default_action *) action;
@@ -594,7 +592,7 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, struct xkb_any_action *action,
         if (btn < 0 || btn > 5) {
             log_err(keymap->ctx,
                     "New default button value must be in the range 1..5; "
-                    "Illegal default button value %d ignored\n", rtrn.ival);
+                    "Illegal default button value %d ignored\n", btn);
             return false;
         }
         if (btn == 0) {
@@ -683,7 +681,6 @@ static bool
 HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
                    unsigned field, ExprDef *array_ndx, ExprDef *value)
 {
-    ExprResult rtrn;
     struct xkb_switch_screen_action *act;
 
     act = (struct xkb_switch_screen_action *) action;
@@ -710,7 +707,7 @@ HandleSwitchScreen(struct xkb_keymap *keymap, struct xkb_any_action *action,
         if (val < 0 || val > 255) {
             log_err(keymap->ctx,
                     "Screen index must be in the range 1..255; "
-                    "Illegal screen value %d ignored\n", rtrn.ival);
+                    "Illegal screen value %d ignored\n", val);
             return false;
         }
 
@@ -938,7 +935,6 @@ static bool
 HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
                 unsigned field, ExprDef *array_ndx, ExprDef *value)
 {
-    ExprResult rtrn;
     struct xkb_device_button_action *act;
 
     act = (struct xkb_device_button_action *) action;
@@ -989,7 +985,7 @@ HandleDeviceBtn(struct xkb_keymap *keymap, struct xkb_any_action *action,
         if (btn < 0 || btn > 255) {
             log_err(keymap->ctx,
                     "The count field must have a value in the range 0..255; "
-                    "Illegal count %d ignored\n", rtrn.ival);
+                    "Illegal count %d ignored\n", btn);
             return false;
         }
 
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index f299f39..501a816 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -635,7 +635,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
                ExprDef *arrayNdx, ExprDef *value)
 {
     struct xkb_keymap *keymap = info->keymap;
-    ExprResult tmp;
+    xkb_mod_index_t ndx;
 
     if (istreq(field, "action")) {
         if (arrayNdx)
@@ -651,10 +651,10 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
         if (arrayNdx)
             return ReportSINotArray(info, si, field);
 
-        if (!ResolveVirtualModifier(value, keymap, &tmp, &info->vmods))
+        if (!ResolveVirtualModifier(value, keymap, &ndx, &info->vmods))
             return ReportSIBadType(info, si, field, "virtual modifier");
 
-        si->interp.virtual_mod = tmp.uval;
+        si->interp.virtual_mod = ndx;
         si->defined |= _SI_VirtualMod;
     }
     else if (istreq(field, "repeat")) {
@@ -752,7 +752,6 @@ static int
 SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
                      const char *field, ExprDef *arrayNdx, ExprDef *value)
 {
-    ExprResult rtrn;
     bool ok = true;
     struct xkb_keymap *keymap = info->keymap;
 
@@ -870,7 +869,7 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
             log_err(info->keymap->ctx,
                     "Illegal indicator index %d (range 1..%d); "
                     "Index definition for %s indicator ignored\n",
-                    rtrn.uval, XkbNumIndicators,
+                    ndx, XkbNumIndicators,
                     xkb_atom_text(keymap->ctx, led->name));
             return false;
         }
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index d82aad8..6a02c2a 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -28,7 +28,7 @@
 
 typedef bool (*IdentLookupFunc)(struct xkb_context *ctx, const void *priv,
                                 xkb_atom_t field, enum expr_value_type type,
-                                ExprResult *val_rtrn);
+                                unsigned int *val_rtrn);
 
 const char *
 exprOpText(enum expr_op_type op)
@@ -150,9 +150,8 @@ ExprResolveLhs(struct xkb_context *ctx, ExprDef *expr, const char **elem_rtrn,
 }
 
 static bool
-SimpleLookup(struct xkb_context *ctx, const void *priv,
-             xkb_atom_t field, enum expr_value_type type,
-             ExprResult *val_rtrn)
+SimpleLookup(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
+             enum expr_value_type type, unsigned int *val_rtrn)
 {
     const LookupEntry *entry;
     const char *str;
@@ -163,7 +162,7 @@ SimpleLookup(struct xkb_context *ctx, const void *priv,
     str = xkb_atom_text(ctx, field);
     for (entry = priv; entry && entry->name; entry++) {
         if (istreq(str, entry->name)) {
-            val_rtrn->uval = entry->result;
+            *val_rtrn = entry->value;
             return true;
         }
     }
@@ -186,32 +185,33 @@ static const LookupEntry modIndexNames[] = {
 
 bool
 LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
-               enum expr_value_type type, ExprResult *val_rtrn)
+               enum expr_value_type type, xkb_mod_index_t *val_rtrn)
 {
     return SimpleLookup(ctx, modIndexNames, field, type, val_rtrn);
 }
 
 bool
 LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
-              enum expr_value_type type, ExprResult *val_rtrn)
+              enum expr_value_type type, xkb_mod_mask_t *val_rtrn)
 {
     const char *str;
-    bool ret = true;
+    xkb_mod_index_t ndx;
 
     if (type != EXPR_TYPE_INT)
         return false;
+
     str = xkb_atom_text(ctx, field);
-    if (str == NULL)
-        return false;
+
     if (istreq(str, "all"))
-        val_rtrn->uval = 0xff;
+        *val_rtrn  = 0xff;
     else if (istreq(str, "none"))
-        val_rtrn->uval = 0;
-    else if (LookupModIndex(ctx, priv, field, type, val_rtrn))
-        val_rtrn->uval = (1 << val_rtrn->uval);
+        *val_rtrn = 0;
+    else if (LookupModIndex(ctx, priv, field, type, &ndx))
+        *val_rtrn = (1 << ndx);
     else
-        ret = false;
-    return ret;
+        return false;
+
+    return true;
 }
 
 bool
@@ -366,13 +366,14 @@ ExprResolveKeyCode(struct xkb_context *ctx, ExprDef *expr, xkb_keycode_t *kc)
  *
  * Cool.
  */
-static int
+static bool
 ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
-                         ExprResult *val_rtrn, IdentLookupFunc lookup,
+                         int *val_rtrn, IdentLookupFunc lookup,
                          const void *lookupPriv)
 {
-    int ok = 0;
-    ExprResult leftRtrn, rightRtrn;
+    bool ok = false;
+    int l, r;
+    unsigned u;
     ExprDef *left, *right;
 
     switch (expr->op) {
@@ -383,16 +384,20 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
                     exprValueTypeText(expr->value_type));
             return false;
         }
-        val_rtrn->ival = expr->value.ival;
+
+        *val_rtrn = expr->value.ival;
         return true;
 
     case EXPR_IDENT:
         if (lookup)
-            ok = lookup(ctx, lookupPriv, expr->value.str,
-                        EXPR_TYPE_INT, val_rtrn);
+            ok = lookup(ctx, lookupPriv, expr->value.str, EXPR_TYPE_INT, &u);
+
         if (!ok)
             log_err(ctx, "Identifier \"%s\" of type int is unknown\n",
                     xkb_atom_text(ctx, expr->value.str));
+        else
+            *val_rtrn = (int) u;
+
         return ok;
 
     case EXPR_FIELD_REF:
@@ -407,34 +412,32 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
     case EXPR_DIVIDE:
         left = expr->value.binary.left;
         right = expr->value.binary.right;
-        if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
-                                     lookupPriv) &&
-            ExprResolveIntegerLookup(ctx, right, &rightRtrn, lookup,
-                                     lookupPriv)) {
-            switch (expr->op) {
-            case EXPR_ADD:
-                val_rtrn->ival = leftRtrn.ival + rightRtrn.ival;
-                break;
-            case EXPR_SUBTRACT:
-                val_rtrn->ival = leftRtrn.ival - rightRtrn.ival;
-                break;
-            case EXPR_MULTIPLY:
-                val_rtrn->ival = leftRtrn.ival * rightRtrn.ival;
-                break;
-            case EXPR_DIVIDE:
-                if (rightRtrn.ival == 0) {
-                    log_err(ctx, "Cannot divide by zero: %d / %d\n",
-                            leftRtrn.ival, rightRtrn.ival);
-                    return false;
-                }
-                val_rtrn->ival = leftRtrn.ival / rightRtrn.ival;
-                break;
-            default:
-                break;
+        if (!ExprResolveIntegerLookup(ctx, left, &l, lookup, lookupPriv) ||
+            !ExprResolveIntegerLookup(ctx, right, &r, lookup, lookupPriv))
+            return false;
+
+        switch (expr->op) {
+        case EXPR_ADD:
+            *val_rtrn = l + r;
+            break;
+        case EXPR_SUBTRACT:
+            *val_rtrn = l - r;
+            break;
+        case EXPR_MULTIPLY:
+            *val_rtrn = l * r;
+            break;
+        case EXPR_DIVIDE:
+            if (r == 0) {
+                log_err(ctx, "Cannot divide by zero: %d / %d\n", l, r);
+                return false;
             }
-            return true;
+            *val_rtrn = l / r;
+            break;
+        default:
+            break;
         }
-        return false;
+
+        return true;
 
     case EXPR_ASSIGN:
         log_wsgo(ctx, "Assignment operator not implemented yet\n");
@@ -447,15 +450,11 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
     case EXPR_INVERT:
     case EXPR_NEGATE:
         left = expr->value.child;
-        if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
-                                     lookupPriv)) {
-            if (expr->op == EXPR_NEGATE)
-                val_rtrn->ival = -leftRtrn.ival;
-            else
-                val_rtrn->ival = ~leftRtrn.ival;
-            return true;
-        }
-        return false;
+        if (!ExprResolveIntegerLookup(ctx, left, &l, lookup, lookupPriv))
+            return false;
+
+        *val_rtrn = (expr->op == EXPR_NEGATE ? -l : ~l);
+        return true;
 
     case EXPR_UNARY_PLUS:
         left = expr->value.child;
@@ -466,18 +465,14 @@ ExprResolveIntegerLookup(struct xkb_context *ctx, ExprDef *expr,
         log_wsgo(ctx, "Unknown operator %d in ResolveInteger\n", expr->op);
         break;
     }
+
     return false;
 }
 
 bool
 ExprResolveInteger(struct xkb_context *ctx, ExprDef *expr, int *val_rtrn)
 {
-    ExprResult result;
-    bool ok;
-    ok = ExprResolveIntegerLookup(ctx, expr, &result, NULL, NULL);
-    if (ok)
-        *val_rtrn = result.ival;
-    return ok;
+    return ExprResolveIntegerLookup(ctx, expr, val_rtrn, NULL, NULL);
 }
 
 bool
@@ -485,7 +480,7 @@ ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,
                  xkb_group_index_t *group_rtrn)
 {
     bool ok;
-    ExprResult result;
+    int result;
     static const LookupEntry group_names[] = {
         { "group1", 1 },
         { "group2", 2 },
@@ -503,13 +498,13 @@ ExprResolveGroup(struct xkb_context *ctx, ExprDef *expr,
     if (!ok)
         return false;
 
-    if (result.uval == 0 || result.uval > XkbNumKbdGroups) {
+    if (result <= 0 || result > XkbNumKbdGroups) {
         log_err(ctx, "Group index %u is out of range (1..%d)\n",
-                result.uval, XkbNumKbdGroups);
+                result, XkbNumKbdGroups);
         return false;
     }
 
-    *group_rtrn = result.uval;
+    *group_rtrn = (xkb_group_index_t) result;
     return true;
 }
 
@@ -518,7 +513,7 @@ ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
                  unsigned int *level_rtrn)
 {
     bool ok;
-    ExprResult result;
+    int result;
     static const LookupEntry level_names[] = {
         { "level1", 1 },
         { "level2", 2 },
@@ -536,21 +531,20 @@ ExprResolveLevel(struct xkb_context *ctx, ExprDef *expr,
     if (!ok)
         return false;
 
-    if (result.uval < 1 || result.uval > XkbMaxShiftLevel) {
+    if (result < 1 || result > XkbMaxShiftLevel) {
         log_err(ctx, "Shift level %d is out of range (1..%d)\n",
-                result.uval, XkbMaxShiftLevel);
+                result, XkbMaxShiftLevel);
         return false;
     }
 
-    *level_rtrn = result.uval;
+    *level_rtrn = (unsigned int) result;
     return true;
 }
 
 bool
 ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, int *btn_rtrn)
 {
-    bool ok;
-    ExprResult result;
+    int result;
     static const LookupEntry button_names[] = {
         { "button1", 1 },
         { "button2", 2 },
@@ -561,11 +555,12 @@ ExprResolveButton(struct xkb_context *ctx, ExprDef *expr, int *btn_rtrn)
         { NULL, 0 }
     };
 
-    ok = ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup,
-                                  button_names);
-    if (ok)
-        *btn_rtrn = result.ival;
-    return ok;
+    if (!ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup,
+                                  button_names))
+        return false;
+
+    *btn_rtrn = result;
+    return true;
 }
 
 bool
@@ -662,42 +657,35 @@ bool
 ExprResolveEnum(struct xkb_context *ctx, ExprDef *expr,
                 unsigned int *val_rtrn, const LookupEntry *values)
 {
-    ExprResult result;
-
     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, EXPR_TYPE_INT, &result)) {
-        int nOut = 0;
-        log_err(ctx, "Illegal identifier %s (expected one of: ",
+    if (!SimpleLookup(ctx, values, expr->value.str, EXPR_TYPE_INT,
+                      val_rtrn)) {
+        log_err(ctx, "Illegal identifier %s; expected one of:\n",
                 xkb_atom_text(ctx, expr->value.str));
         while (values && values->name)
         {
-            if (nOut != 0)
-                log_info(ctx, ", %s", values->name);
-            else
-                log_info(ctx, "%s", values->name);
+            log_err(ctx, "\t%s\n", values->name);
             values++;
-            nOut++;
         }
-        log_info(ctx, ")\n");
         return false;
     }
 
-    *val_rtrn = result.uval;
     return true;
 }
 
-static int
+static bool
 ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
-                      ExprResult *val_rtrn, IdentLookupFunc lookup,
+                      unsigned int *val_rtrn, IdentLookupFunc lookup,
                       const void *lookupPriv)
 {
-    int ok = 0;
-    ExprResult leftRtrn, rightRtrn;
+    bool ok = 0;
+    unsigned int l, r;
+    int v;
     ExprDef *left, *right;
     const char *bogus = NULL;
 
@@ -709,11 +697,12 @@ ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
                     exprValueTypeText(expr->value_type));
             return false;
         }
-        val_rtrn->ival = expr->value.ival;
+        *val_rtrn = (unsigned int) expr->value.ival;
         return true;
 
     case EXPR_IDENT:
-        ok = lookup(ctx, lookupPriv, expr->value.str, EXPR_TYPE_INT, val_rtrn);
+        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));
@@ -742,28 +731,27 @@ ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
     case EXPR_DIVIDE:
         left = expr->value.binary.left;
         right = expr->value.binary.right;
-        if (ExprResolveMaskLookup(ctx, left, &leftRtrn, lookup,
-                                  lookupPriv) &&
-            ExprResolveMaskLookup(ctx, right, &rightRtrn, lookup,
-                                  lookupPriv)) {
-            switch (expr->op) {
-            case EXPR_ADD:
-                val_rtrn->ival = leftRtrn.ival | rightRtrn.ival;
-                break;
-            case EXPR_SUBTRACT:
-                val_rtrn->ival = leftRtrn.ival & (~rightRtrn.ival);
-                break;
-            case EXPR_MULTIPLY:
-            case EXPR_DIVIDE:
-                log_err(ctx, "Cannot %s masks; Illegal operation ignored\n",
-                        (expr->op == EXPR_DIVIDE ? "divide" : "multiply"));
-                return false;
-            default:
-                break;
-            }
-            return true;
+        if (!ExprResolveMaskLookup(ctx, left, &l, lookup, lookupPriv) ||
+            !ExprResolveMaskLookup(ctx, right, &r, lookup, lookupPriv))
+            return false;
+
+        switch (expr->op) {
+        case EXPR_ADD:
+            *val_rtrn = l | r;
+            break;
+        case EXPR_SUBTRACT:
+            *val_rtrn = l & (~r);
+            break;
+        case EXPR_MULTIPLY:
+        case EXPR_DIVIDE:
+            log_err(ctx, "Cannot %s masks; Illegal operation ignored\n",
+                    (expr->op == EXPR_DIVIDE ? "divide" : "multiply"));
+            return false;
+        default:
+            break;
         }
-        return false;
+
+        return true;
 
     case EXPR_ASSIGN:
         log_wsgo(ctx, "Assignment operator not implemented yet\n");
@@ -771,28 +759,26 @@ ExprResolveMaskLookup(struct xkb_context *ctx, ExprDef *expr,
 
     case EXPR_INVERT:
         left = expr->value.child;
-        if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
-                                     lookupPriv)) {
-            val_rtrn->ival = ~leftRtrn.ival;
-            return true;
-        }
-        return false;
+        if (!ExprResolveIntegerLookup(ctx, left, &v, lookup, lookupPriv))
+            return false;
+
+        *val_rtrn = ~v;
+        return true;
 
     case EXPR_UNARY_PLUS:
     case EXPR_NEGATE:
     case EXPR_NOT:
         left = expr->value.child;
-        if (ExprResolveIntegerLookup(ctx, left, &leftRtrn, lookup,
-                                     lookupPriv)) {
+        if (!ExprResolveIntegerLookup(ctx, left, &v, lookup, lookupPriv))
             log_err(ctx, "The %s operator cannot be used with a mask\n",
                     (expr->op == EXPR_NEGATE ? "-" : "!"));
-        }
         return false;
 
     default:
         log_wsgo(ctx, "Unknown operator %d in ResolveMask\n", expr->op);
         break;
     }
+
     return false;
 }
 
@@ -800,40 +786,22 @@ bool
 ExprResolveMask(struct xkb_context *ctx, ExprDef *expr,
                 unsigned int *mask_rtrn, const LookupEntry *values)
 {
-    ExprResult result;
-    bool ok;
-
-    ok = ExprResolveMaskLookup(ctx, expr, &result, SimpleLookup, values);
-    if (ok)
-        *mask_rtrn = (unsigned int) result.ival;
-    return ok;
+    return ExprResolveMaskLookup(ctx, expr, mask_rtrn, SimpleLookup, values);
 }
 
 bool
 ExprResolveModMask(struct xkb_context *ctx, ExprDef *expr,
                    xkb_mod_mask_t *mask_rtrn)
 {
-    ExprResult result;
-    bool ok;
-
-    ok = ExprResolveMaskLookup(ctx, expr, &result, LookupModMask, NULL);
-    if (ok)
-        *mask_rtrn = (xkb_mod_mask_t) result.ival;
-    return ok;
+    return ExprResolveMaskLookup(ctx, expr, mask_rtrn, LookupModMask, NULL);
 }
 
 bool
 ExprResolveVModMask(struct xkb_keymap *keymap, ExprDef *expr,
                     xkb_mod_mask_t *mask_rtrn)
 {
-    ExprResult result;
-    bool ok;
-
-    ok = ExprResolveMaskLookup(keymap->ctx, expr, &result, LookupVModMask,
-                               keymap);
-    if (ok)
-        *mask_rtrn = (xkb_mod_mask_t) result.ival;
-    return ok;
+    return ExprResolveMaskLookup(keymap->ctx, expr, mask_rtrn, LookupVModMask,
+                                 keymap);
 }
 
 bool
diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h
index 194b668..75bcb82 100644
--- a/src/xkbcomp/expr.h
+++ b/src/xkbcomp/expr.h
@@ -29,14 +29,9 @@
 
 #include "xkbcomp-priv.h"
 
-typedef union _ExprResult {
-    int ival;
-    unsigned uval;
-} ExprResult;
-
 typedef struct _LookupEntry {
     const char *name;
-    unsigned result;
+    unsigned int value;
 } LookupEntry;
 
 extern const char *
@@ -46,17 +41,17 @@ bool
 ExprResolveLhs(struct xkb_context *ctx, ExprDef *expr, const char **elem_rtrn,
                const char **field_rtrn, ExprDef **index_rtrn);
 
-extern bool
+bool
 LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
-              enum expr_value_type type, ExprResult *val_rtrn);
+              enum expr_value_type type, xkb_mod_mask_t *val_rtrn);
 
-extern bool
+bool
 LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
-               enum expr_value_type type, ExprResult *val_rtrn);
+               enum expr_value_type type, xkb_mod_mask_t *val_rtrn);
 
-extern bool
+bool
 LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
-               enum expr_value_type type, ExprResult *val_rtrn);
+               enum expr_value_type type, xkb_mod_index_t *val_rtrn);
 
 bool
 ExprResolveModMask(struct xkb_context *ctx, ExprDef *expr,
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index fcb679f..4529958 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1367,19 +1367,21 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
 {
     ExprDef *key;
     ModMapEntry tmp;
-    ExprResult rtrn;
+    xkb_mod_index_t ndx;
     bool ok;
     struct xkb_context *ctx = info->keymap->ctx;
 
-    if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &rtrn)) {
+    if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &ndx)) {
         log_err(info->keymap->ctx,
                 "Illegal modifier map definition; "
                 "Ignoring map for non-modifier \"%s\"\n",
                 xkb_atom_text(ctx, def->modifier));
         return false;
     }
+
     ok = true;
-    tmp.modifier = rtrn.uval;
+    tmp.modifier = ndx;
+
     for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
         xkb_keysym_t sym;
 
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 5ce1f94..593cd13 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -155,9 +155,9 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
  * @return true on success, false otherwise. If false is returned, val_rtrn is
  * undefined.
  */
-static int
+static bool
 LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
-                enum expr_value_type type, ExprResult * val_rtrn)
+                enum expr_value_type type, xkb_mod_index_t *val_rtrn)
 {
     xkb_mod_index_t i;
     const char *name = xkb_atom_text(keymap->ctx, field);
@@ -172,7 +172,7 @@ LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
      */
     for (i = 0; i < XkbNumVirtualMods; i++) {
         if (keymap->vmod_names[i] && streq(keymap->vmod_names[i], name)) {
-            val_rtrn->uval = i;
+            *val_rtrn = i;
             return true;
         }
     }
@@ -192,35 +192,37 @@ LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
  */
 bool
 LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
-               enum expr_value_type type, ExprResult *val_rtrn)
+               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, val_rtrn)) {
-        unsigned ndx = val_rtrn->uval;
-        val_rtrn->uval = (1 << (XkbNumModifiers + ndx));
+    else if (LookupVModIndex(priv, field, type, &ndx)) {
+        *val_rtrn = (1 << (XkbNumModifiers + ndx));
         return true;
     }
+
     return false;
 }
 
-int
+xkb_mod_index_t
 FindKeypadVMod(struct xkb_keymap *keymap)
 {
     xkb_atom_t name;
-    ExprResult rtrn;
+    xkb_mod_index_t ndx;
 
     name = xkb_atom_intern(keymap->ctx, "NumLock");
-    if ((keymap) && LookupVModIndex(keymap, name, EXPR_TYPE_INT, &rtrn)) {
-        return rtrn.ival;
-    }
+    if (LookupVModIndex(keymap, name, EXPR_TYPE_INT, &ndx))
+        return ndx;
+
     return -1;
 }
 
 bool
 ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
-                       ExprResult *val_rtrn, VModInfo *info)
+                       xkb_mod_index_t *ndx_rtrn, VModInfo *info)
 {
     int val;
 
@@ -232,7 +234,7 @@ ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
         for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
             if ((info->available & bit) && keymap->vmod_names[i] &&
                 streq(keymap->vmod_names[i], name)) {
-                val_rtrn->uval = i;
+                *ndx_rtrn = i;
                 return true;
             }
         }
@@ -248,6 +250,6 @@ ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
         return false;
     }
 
-    val_rtrn->uval = (unsigned int) val;
+    *ndx_rtrn = (xkb_mod_index_t) val;
     return true;
 }
diff --git a/src/xkbcomp/vmod.h b/src/xkbcomp/vmod.h
index 30df71a..cdbb624 100644
--- a/src/xkbcomp/vmod.h
+++ b/src/xkbcomp/vmod.h
@@ -51,12 +51,11 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap,
 extern bool
 ApplyVModDefs(VModInfo *info, struct xkb_keymap *keymap);
 
-extern int
+xkb_mod_index_t
 FindKeypadVMod(struct xkb_keymap *keymap);
 
-extern bool
+bool
 ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
-                       ExprResult *value_rtrn,
-                       VModInfo *info);
+                       xkb_mod_index_t *ndx_rtrn, VModInfo *info);
 
 #endif /* VMOD_H */