Commit dfa0929c6d0199b93907b4927f3dd82d9bc30df7

Ran Benita 2012-07-16T22:15:43

Convert macros to inline functions 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
diff --git a/Makefile.am b/Makefile.am
index db17832..5ca617b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -48,7 +48,6 @@ libxkbcommon_la_SOURCES = \
 	src/xkbcomp/indicators.c \
 	src/xkbcomp/indicators.h \
 	src/xkbcomp/keycodes.c \
-	src/xkbcomp/keycodes.h \
 	src/xkbcomp/keytypes.c \
 	src/xkbcomp/misc.c \
 	src/xkbcomp/parser.y \
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index 4f0a6e9..07e881e 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -25,7 +25,6 @@
  ********************************************************/
 
 #include "action.h"
-#include "keycodes.h"
 
 static bool actionsInitialized;
 static ExprDef constTrue;
@@ -166,7 +165,7 @@ fieldText(unsigned field)
 
 /***====================================================================***/
 
-static bool
+static inline bool
 ReportMismatch(unsigned action, unsigned field, const char *type)
 {
     ERROR("Value of %s field must be of type %s\n", fieldText(field), type);
@@ -174,7 +173,7 @@ ReportMismatch(unsigned action, unsigned field, const char *type)
     return false;
 }
 
-static bool
+static inline bool
 ReportIllegal(unsigned action, unsigned field)
 {
     ERROR("Field %s is not defined for an action of type %s\n",
@@ -183,7 +182,7 @@ ReportIllegal(unsigned action, unsigned field)
     return false;
 }
 
-static bool
+static inline bool
 ReportActionNotArray(unsigned action, unsigned field)
 {
     ERROR("The %s field in the %s action is not an array\n",
@@ -192,7 +191,7 @@ ReportActionNotArray(unsigned action, unsigned field)
     return false;
 }
 
-static bool
+static inline bool
 ReportNotFound(unsigned action, unsigned field, const char *what,
                const char *bad)
 {
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 8d492db..2c40dc2 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -64,15 +64,6 @@ typedef struct _CompatInfo {
     struct xkb_keymap *keymap;
 } CompatInfo;
 
-/***====================================================================***/
-
-#define ReportSINotArray(si, f, i) \
-    ReportNotArray("symbol interpretation", (f), siText((si), (i)))
-#define ReportSIBadType(si, f, w, i) \
-    ReportBadType("symbol interpretation", (f), siText((si), (i)), (w))
-
-/***====================================================================***/
-
 static const char *
 siText(SymInterpInfo * si, CompatInfo * info)
 {
@@ -90,6 +81,20 @@ siText(SymInterpInfo * si, CompatInfo * info)
     return buf;
 }
 
+static inline bool
+ReportSINotArray(SymInterpInfo *si, const char *field, CompatInfo *info)
+{
+    return ReportNotArray("symbol interpretation", field, siText(si, info));
+}
+
+static inline bool
+ReportSIBadType(SymInterpInfo *si, const char *field, const char *wanted,
+                CompatInfo *info)
+{
+    return ReportBadType("symbol interpretation", field, siText(si, info),
+                         wanted);
+}
+
 static void
 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
 {
diff --git a/src/xkbcomp/indicators.c b/src/xkbcomp/indicators.c
index c7f0958..09ef851 100644
--- a/src/xkbcomp/indicators.c
+++ b/src/xkbcomp/indicators.c
@@ -30,12 +30,21 @@
 
 /***====================================================================***/
 
-#define ReportIndicatorBadType(keymap, l, f, w)                            \
-    ReportBadType("indicator map", (f),                                 \
-                  xkb_atom_text((keymap)->ctx, (l)->name), (w))
-#define ReportIndicatorNotArray(keymap, l, f)                              \
-    ReportNotArray("indicator map", (f),                                \
-                   xkb_atom_text((keymap)->ctx, (l)->name))
+static inline bool
+ReportIndicatorBadType(struct xkb_keymap *keymap, LEDInfo *led,
+                       const char *field, const char *wanted)
+{
+    return ReportBadType("indicator map", field,
+                         xkb_atom_text(keymap->ctx, led->name), wanted);
+}
+
+static inline bool
+ReportIndicatorNotArray(struct xkb_keymap *keymap, LEDInfo *led,
+                        const char *field)
+{
+    return ReportNotArray("indicator map", field,
+                          xkb_atom_text(keymap->ctx, led->name));
+}
 
 /***====================================================================***/
 
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index ccd0553..bd7bba9 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -24,32 +24,10 @@
  *
  ********************************************************/
 
-#include "keycodes.h"
+#include "xkbcomp-priv.h"
 #include "expr.h"
 #include "parseutils.h"
 
-const char *
-longText(unsigned long val)
-{
-    char buf[4];
-
-    LongToKeyName(val, buf);
-    return XkbcKeyNameText(buf);
-}
-
-/***====================================================================***/
-
-void
-LongToKeyName(unsigned long val, char *name)
-{
-    name[0] = ((val >> 24) & 0xff);
-    name[1] = ((val >> 16) & 0xff);
-    name[2] = ((val >> 8) & 0xff);
-    name[3] = (val & 0xff);
-}
-
-/***====================================================================***/
-
 typedef struct _AliasInfo {
     enum merge_mode merge;
     unsigned file_id;
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 91bab7c..e7da50f 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -73,23 +73,49 @@ static xkb_atom_t tok_KEYPAD;
 
 /***====================================================================***/
 
-#define ReportTypeShouldBeArray(keymap, t, f) \
-    ReportShouldBeArray("key type", (f), TypeTxt((keymap), (t)))
-#define ReportTypeBadType(keymap, t, f, w) \
-    ReportBadType("key type", (f), TypeTxt((keymap), (t)), (w))
+static inline const char *
+MapEntryTxt(struct xkb_keymap *keymap, struct xkb_kt_map_entry *entry)
+{
+    return XkbcVModMaskText(keymap, entry->mods.real_mods, entry->mods.vmods);
+}
 
-/***====================================================================***/
+static inline const char *
+PreserveIndexTxt(struct xkb_keymap *keymap, PreserveInfo *pi)
+{
+    return XkbcVModMaskText(keymap, pi->indexMods, pi->indexVMods);
+}
 
-#define MapEntryTxt(x, e) \
-    XkbcVModMaskText((x), (e)->mods.real_mods, (e)->mods.vmods)
-#define PreserveIndexTxt(x, p) \
-    XkbcVModMaskText((x), (p)->indexMods, (p)->indexVMods)
-#define PreserveTxt(x, p) \
-    XkbcVModMaskText((x), (p)->preMods, (p)->preVMods)
-#define TypeTxt(keymap, t) \
-    xkb_atom_text((keymap)->ctx, (t)->name)
-#define TypeMaskTxt(t, x) \
-    XkbcVModMaskText((x), (t)->mask, (t)->vmask)
+static inline const char *
+PreserveTxt(struct xkb_keymap *keymap, PreserveInfo *pi)
+{
+    return XkbcVModMaskText(keymap, pi->preMods, pi->preVMods);
+}
+
+static inline const char *
+TypeTxt(struct xkb_keymap *keymap, KeyTypeInfo *type)
+{
+    return xkb_atom_text(keymap->ctx, type->name);
+}
+
+static inline const char *
+TypeMaskTxt(struct xkb_keymap *keymap, KeyTypeInfo *type)
+{
+    return XkbcVModMaskText(keymap, type->mask, type->vmask);
+}
+
+static inline bool
+ReportTypeShouldBeArray(struct xkb_keymap *keymap, KeyTypeInfo *type,
+                        const char *field)
+{
+    return ReportShouldBeArray("key type", field, TypeTxt(keymap, type));
+}
+
+static inline bool
+ReportTypeBadType(struct xkb_keymap *keymap, KeyTypeInfo *type,
+                  const char *field, const char *wanted)
+{
+    return ReportBadType("key type", field, TypeTxt(keymap, type), wanted);
+}
 
 /***====================================================================***/
 
@@ -707,7 +733,7 @@ SetKeyTypeField(KeyTypeInfo *type, struct xkb_keymap *keymap,
         if (type->defs.defined & _KT_Mask) {
             WARN("Multiple modifier mask definitions for key type %s\n",
                  xkb_atom_text(keymap->ctx, type->name));
-            ACTION("Using %s, ", TypeMaskTxt(type, keymap));
+            ACTION("Using %s, ", TypeMaskTxt(keymap, type));
             INFO("ignoring %s\n", XkbcVModMaskText(keymap, mods, vmods));
             return false;
         }
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 7d1d380..55c77e6 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -27,7 +27,6 @@
 #include "xkbcomp-priv.h"
 #include "path.h"
 #include "parseutils.h"
-#include "keycodes.h"
 
 /***====================================================================***/
 
@@ -107,43 +106,6 @@ ProcessIncludeFile(struct xkb_context *ctx,
     return true;
 }
 
-/***====================================================================***/
-
-int
-ReportNotArray(const char *type, const char *field, const char *name)
-{
-    ERROR("The %s %s field is not an array\n", type, field);
-    ACTION("Ignoring illegal assignment in %s\n", name);
-    return false;
-}
-
-int
-ReportShouldBeArray(const char *type, const char *field, const char *name)
-{
-    ERROR("Missing subscript for %s %s\n", type, field);
-    ACTION("Ignoring illegal assignment in %s\n", name);
-    return false;
-}
-
-int
-ReportBadType(const char *type, const char *field,
-              const char *name, const char *wanted)
-{
-    ERROR("The %s %s field must be a %s\n", type, field, wanted);
-    ACTION("Ignoring illegal assignment in %s\n", name);
-    return false;
-}
-
-int
-ReportBadField(const char *type, const char *field, const char *name)
-{
-    ERROR("Unknown %s field %s in %s\n", type, field, name);
-    ACTION("Ignoring assignment to unknown field in %s\n", name);
-    return false;
-}
-
-/***====================================================================***/
-
 bool
 UseNewField(unsigned field,
             CommonInfo * oldDefs, CommonInfo * newDefs, unsigned *pCollide)
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 81689fd..67e6a57 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -29,14 +29,13 @@
 #include "xkbcomp-priv.h"
 #include "parseutils.h"
 #include "action.h"
-#include "keycodes.h"
 #include "vmod.h"
 
 /***====================================================================***/
 
 /* Needed to work with the typechecker. */
-typedef darray (xkb_keysym_t) darray_xkb_keysym_t;
-typedef darray (union xkb_action) darray_xkb_action;
+typedef darray(xkb_keysym_t) darray_xkb_keysym_t;
+typedef darray(union xkb_action) darray_xkb_action;
 
 #define RepeatYes       1
 #define RepeatNo        0
@@ -51,6 +50,15 @@ typedef darray (union xkb_action) darray_xkb_action;
 #define _Key_GroupInfo  (1 << 6)
 #define _Key_VModMap    (1 << 7)
 
+static inline const char *
+longText(unsigned long val)
+{
+    char buf[4];
+
+    LongToKeyName(val, buf);
+    return XkbcKeyNameText(buf);
+}
+
 typedef struct _KeyInfo {
     unsigned short defined;
     unsigned file_id;
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 8322fdf..3b03709 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -49,19 +49,6 @@ ClearCommonInfo(CommonInfo *cmn);
 extern void *
 AddCommonInfo(CommonInfo * old, CommonInfo * new);
 
-extern int
-ReportNotArray(const char *type, const char *field, const char *name);
-
-extern int
-ReportShouldBeArray(const char *type, const char *field, const char *name);
-
-extern int
-ReportBadType(const char *type, const char *field, const char *name,
-              const char *wanted);
-
-extern int
-ReportBadField(const char *type, const char *field, const char *name);
-
 extern bool
 ProcessIncludeFile(struct xkb_context *ctx, IncludeStmt *stmt,
                    enum xkb_file_type file_type, XkbFile **file_rtrn,
@@ -81,4 +68,56 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap);
 uint32_t
 VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask);
 
+static inline unsigned long
+KeyNameToLong(const char *name)
+{
+    return
+        (((unsigned long)name[0]) << 24) |
+        (((unsigned long)name[1]) << 16) |
+        (((unsigned long)name[2]) << 8)  |
+        (((unsigned long)name[3]) << 0);
+}
+
+static inline void
+LongToKeyName(unsigned long val, char *name)
+{
+    name[0] = ((val >> 24) & 0xff);
+    name[1] = ((val >> 16) & 0xff);
+    name[2] = ((val >> 8) & 0xff);
+    name[3] = ((val >> 0) & 0xff);
+}
+
+static inline bool
+ReportNotArray(const char *type, const char *field, const char *name)
+{
+    ERROR("The %s %s field is not an array\n", type, field);
+    ACTION("Ignoring illegal assignment in %s\n", name);
+    return false;
+}
+
+static inline bool
+ReportShouldBeArray(const char *type, const char *field, const char *name)
+{
+    ERROR("Missing subscript for %s %s\n", type, field);
+    ACTION("Ignoring illegal assignment in %s\n", name);
+    return false;
+}
+
+static inline bool
+ReportBadType(const char *type, const char *field,
+              const char *name, const char *wanted)
+{
+    ERROR("The %s %s field must be a %s\n", type, field, wanted);
+    ACTION("Ignoring illegal assignment in %s\n", name);
+    return false;
+}
+
+static inline bool
+ReportBadField(const char *type, const char *field, const char *name)
+{
+    ERROR("Unknown %s field %s in %s\n", type, field, name);
+    ACTION("Ignoring assignment to unknown field in %s\n", name);
+    return false;
+}
+
 #endif /* XKBCOMP_PRIV_H */