Resolve keysyms early in parser Instead of having the parser passing strings to the AST, and symbols/compat etc. resolving them themselves. This simplifies the code a bit, and makes it possible to print where exactly in the file the bad keysym originates from. The previous lazy approach had an advantage of not needlessly resolving keysyms from unrelated maps. However, I think reporting these errors in *any* map is better, and the parser is also a bit smarter then old xkbcomp and doesn't parse many useless maps. So there's no discernible speed/memory difference with this change. 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
diff --git a/src/xkbcomp/ast-build.c b/src/xkbcomp/ast-build.c
index 4a36802..25172ee 100644
--- a/src/xkbcomp/ast-build.c
+++ b/src/xkbcomp/ast-build.c
@@ -201,7 +201,7 @@ BoolVarCreate(xkb_atom_t nameToken, unsigned set)
}
InterpDef *
-InterpCreate(char *sym, ExprDef *match)
+InterpCreate(xkb_keysym_t sym, ExprDef *match)
{
InterpDef *def = malloc(sizeof(*def));
if (!def)
@@ -329,7 +329,7 @@ ActionCreate(xkb_atom_t name, ExprDef *args)
}
ExprDef *
-CreateKeysymList(char *sym)
+CreateKeysymList(xkb_keysym_t sym)
{
ExprDef *def;
@@ -360,7 +360,7 @@ CreateMultiKeysymList(ExprDef *list)
}
ExprDef *
-AppendKeysymList(ExprDef *list, char *sym)
+AppendKeysymList(ExprDef *list, xkb_keysym_t sym)
{
size_t nSyms = darray_size(list->value.list.syms);
@@ -549,8 +549,6 @@ err:
static void
FreeExpr(ExprDef *expr)
{
- char **sym;
-
if (!expr)
return;
@@ -581,8 +579,6 @@ FreeExpr(ExprDef *expr)
break;
case EXPR_KEYSYM_LIST:
- darray_foreach(sym, expr->value.list.syms)
- free(*sym);
darray_free(expr->value.list.syms);
darray_free(expr->value.list.symsMapIndex);
darray_free(expr->value.list.symsNumEntries);
@@ -640,7 +636,6 @@ FreeStmt(ParseCommon *stmt)
FreeStmt(&u.keyType->body->common);
break;
case STMT_INTERP:
- free(u.interp->sym);
FreeStmt(&u.interp->match->common);
FreeStmt(&u.interp->def->common);
break;
diff --git a/src/xkbcomp/ast-build.h b/src/xkbcomp/ast-build.h
index 4340c8c..4413f88 100644
--- a/src/xkbcomp/ast-build.h
+++ b/src/xkbcomp/ast-build.h
@@ -56,7 +56,7 @@ VarDef *
BoolVarCreate(xkb_atom_t nameToken, unsigned set);
InterpDef *
-InterpCreate(char *sym, ExprDef *match);
+InterpCreate(xkb_keysym_t sym, ExprDef *match);
KeyTypeDef *
KeyTypeCreate(xkb_atom_t name, VarDef *body);
@@ -83,13 +83,13 @@ ExprDef *
CreateMultiKeysymList(ExprDef *list);
ExprDef *
-CreateKeysymList(char *sym);
+CreateKeysymList(xkb_keysym_t sym);
ExprDef *
AppendMultiKeysymList(ExprDef *list, ExprDef *append);
ExprDef *
-AppendKeysymList(ExprDef *list, char *sym);
+AppendKeysymList(ExprDef *list, xkb_keysym_t sym);
IncludeStmt *
IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge);
diff --git a/src/xkbcomp/ast.h b/src/xkbcomp/ast.h
index c430a77..ed8831b 100644
--- a/src/xkbcomp/ast.h
+++ b/src/xkbcomp/ast.h
@@ -181,7 +181,7 @@ typedef struct _Expr {
struct _Expr *args;
} action;
struct {
- darray(char *) syms;
+ darray(xkb_keysym_t) syms;
darray(int) symsMapIndex;
darray(unsigned int) symsNumEntries;
} list;
@@ -252,7 +252,7 @@ typedef struct {
typedef struct {
ParseCommon common;
enum merge_mode merge;
- char *sym;
+ xkb_keysym_t sym;
ExprDef *match;
VarDef *def;
} InterpDef;
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index e58f61c..9e17cbb 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -840,15 +840,7 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
si = info->default_interp;
si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
-
- if (!LookupKeysym(def->sym, &si.interp.sym)) {
- log_err(info->keymap->ctx,
- "Could not resolve keysym %s; "
- "Symbol interpretation ignored\n",
- def->sym);
- return false;
- }
-
+ si.interp.sym = def->sym;
si.interp.match = pred;
si.interp.mods = mods;
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 001ea67..01421fc 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -43,11 +43,47 @@ struct parser_param {
};
static void
-_xkbcommon_error(struct parser_param *param, const char *msg)
+parser_error(struct parser_param *param, const char *msg)
{
scanner_error(param->scanner, msg);
}
+static void
+parser_warn(struct parser_param *param, const char *msg)
+{
+ scanner_warn(param->scanner, msg);
+}
+
+static void
+_xkbcommon_error(struct parser_param *param, const char *msg)
+{
+ parser_error(param, msg);
+}
+
+static bool
+resolve_keysym(const char *str, xkb_keysym_t *sym_rtrn)
+{
+ xkb_keysym_t sym;
+
+ if (!str || istreq(str, "any") || istreq(str, "nosymbol")) {
+ *sym_rtrn = XKB_KEY_NoSymbol;
+ return true;
+ }
+
+ if (istreq(str, "none") || istreq(str, "voidsymbol")) {
+ *sym_rtrn = XKB_KEY_VoidSymbol;
+ return true;
+ }
+
+ sym = xkb_keysym_from_name(str, XKB_KEYSYM_NO_FLAGS);
+ if (sym != XKB_KEY_NoSymbol) {
+ *sym_rtrn = sym;
+ return true;
+ }
+
+ return false;
+}
+
#define scanner param->scanner
%}
@@ -137,6 +173,7 @@ _xkbcommon_error(struct parser_param *param, const char *msg)
xkb_atom_t sval;
enum merge_mode merge;
enum xkb_map_flags mapFlags;
+ xkb_keysym_t keysym;
ParseCommon *any;
ExprDef *expr;
VarDef *var;
@@ -163,8 +200,9 @@ _xkbcommon_error(struct parser_param *param, const char *msg)
%type <file_type> XkbCompositeType FileType
%type <uval> DoodadType
%type <mapFlags> Flag Flags OptFlags
-%type <str> MapName OptMapName KeySym
+%type <str> MapName OptMapName
%type <sval> FieldSpec Ident Element String
+%type <keysym> KeySym
%type <any> DeclList Decl
%type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
%type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
@@ -707,18 +745,23 @@ KeySyms : OBRACE KeySymList CBRACE
{ $$ = $2; }
;
-KeySym : IDENT { $$ = $1; }
- | SECTION { $$ = strdup("section"); }
+KeySym : IDENT
+ {
+ if (!resolve_keysym($1, &$$))
+ parser_warn(param, "unrecognized keysym");
+ free($1);
+ }
+ | SECTION { $$ = XKB_KEY_section; }
| Integer
{
- if ($1 < 10) { /* XK_0 .. XK_9 */
- $$ = malloc(2);
- $$[0] = $1 + '0';
- $$[1] = '\0';
+ if ($1 < 10) { /* XKB_KEY_0 .. XKB_KEY_9 */
+ $$ = XKB_KEY_0 + $1;
}
else {
- $$ = malloc(17);
- snprintf($$, 17, "0x%x", $1);
+ char buf[17];
+ snprintf(buf, sizeof(buf), "0x%x", $1);
+ if (!resolve_keysym(buf, &$$))
+ parser_warn(param, "unrecognized keysym");
}
}
;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index fdc961b..e719da9 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -626,30 +626,6 @@ GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
return true;
}
-bool
-LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn)
-{
- xkb_keysym_t sym;
-
- if (!str || istreq(str, "any") || istreq(str, "nosymbol")) {
- *sym_rtrn = XKB_KEY_NoSymbol;
- return true;
- }
-
- if (istreq(str, "none") || istreq(str, "voidsymbol")) {
- *sym_rtrn = XKB_KEY_VoidSymbol;
- return true;
- }
-
- sym = xkb_keysym_from_name(str, XKB_KEYSYM_NO_FLAGS);
- if (sym != XKB_KEY_NoSymbol) {
- *sym_rtrn = sym;
- return true;
- }
-
- return false;
-}
-
static bool
AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
ExprDef *value)
@@ -703,28 +679,8 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
leveli->u.syms = calloc(leveli->num_syms, sizeof(*leveli->u.syms));
for (j = 0; j < leveli->num_syms; j++) {
- char *sym_name = darray_item(value->value.list.syms,
- sym_index + j);
- xkb_keysym_t keysym;
-
- if (!LookupKeysym(sym_name, &keysym)) {
- const char *group_name = "unnamed";
-
- if (ndx < darray_size(info->group_names) &&
- darray_item(info->group_names, ndx))
- group_name = xkb_atom_text(info->keymap->ctx,
- darray_item(info->group_names,
- ndx));
-
- log_warn(info->keymap->ctx,
- "Could not resolve keysym %s for key %s, group %u (%s), level %u\n",
- sym_name, KeyInfoText(info, keyi), ndx + 1,
- group_name, i);
-
- ClearLevelInfo(leveli);
- leveli->num_syms = 0;
- break;
- }
+ xkb_keysym_t keysym = darray_item(value->value.list.syms,
+ sym_index + j);
if (leveli->num_syms == 1) {
if (keysym == XKB_KEY_NoSymbol)
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index a5d4a1e..7e21d53 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -79,9 +79,6 @@ bool
CompileKeymap(XkbFile *file, struct xkb_keymap *keymap,
enum merge_mode merge);
-bool
-LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn);
-
/***====================================================================***/
static inline bool