1 /************************************************************ 2 * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc. 3 * 4 * Permission to use, copy, modify, and distribute this 5 * software and its documentation for any purpose and without 6 * fee is hereby granted, provided that the above copyright 7 * notice appear in all copies and that both that copyright 8 * notice and this permission notice appear in supporting 9 * documentation, and that the name of Silicon Graphics not be 10 * used in advertising or publicity pertaining to distribution 11 * of the software without specific prior written permission. 12 * Silicon Graphics makes no representation about the suitability 13 * of this software for any purpose. It is provided "as is" 14 * without any express or implied warranty. 15 * 16 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 18 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 19 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 22 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 23 * THE USE OR PERFORMANCE OF THIS SOFTWARE. 24 * 25 ********************************************************/ 26 27 /* 28 * Copyright © 2012 Ran Benita <ran234@gmail.com> 29 * 30 * Permission is hereby granted, free of charge, to any person obtaining a 31 * copy of this software and associated documentation files (the "Software"), 32 * to deal in the Software without restriction, including without limitation 33 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 34 * and/or sell copies of the Software, and to permit persons to whom the 35 * Software is furnished to do so, subject to the following conditions: 36 * 37 * The above copyright notice and this permission notice (including the next 38 * paragraph) shall be included in all copies or substantial portions of the 39 * Software. 40 * 41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 44 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 46 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 47 * DEALINGS IN THE SOFTWARE. 48 */ 49 50 #ifndef XKBCOMP_AST_H 51 #define XKBCOMP_AST_H 52 53 enum xkb_file_type { 54 /* Component files, by order of compilation. */ 55 FILE_TYPE_KEYCODES = 0, 56 FILE_TYPE_TYPES = 1, 57 FILE_TYPE_COMPAT = 2, 58 FILE_TYPE_SYMBOLS = 3, 59 /* Geometry is not compiled any more. */ 60 FILE_TYPE_GEOMETRY = 4, 61 62 /* A top level file which includes the above files. */ 63 FILE_TYPE_KEYMAP, 64 65 /* File types which must be found in a keymap file. */ 66 #define FIRST_KEYMAP_FILE_TYPE FILE_TYPE_KEYCODES 67 #define LAST_KEYMAP_FILE_TYPE FILE_TYPE_SYMBOLS 68 69 /* This one doesn't mix with the others, but useful here as well. */ 70 FILE_TYPE_RULES, 71 72 _FILE_TYPE_NUM_ENTRIES 73 }; 74 75 enum stmt_type { 76 STMT_UNKNOWN = 0, 77 STMT_INCLUDE, 78 STMT_KEYCODE, 79 STMT_ALIAS, 80 STMT_EXPR, 81 STMT_VAR, 82 STMT_TYPE, 83 STMT_INTERP, 84 STMT_VMOD, 85 STMT_SYMBOLS, 86 STMT_MODMAP, 87 STMT_GROUP_COMPAT, 88 STMT_LED_MAP, 89 STMT_LED_NAME, 90 91 _STMT_NUM_VALUES 92 }; 93 94 enum expr_value_type { 95 EXPR_TYPE_UNKNOWN = 0, 96 EXPR_TYPE_BOOLEAN, 97 EXPR_TYPE_INT, 98 EXPR_TYPE_FLOAT, 99 EXPR_TYPE_STRING, 100 EXPR_TYPE_ACTION, 101 EXPR_TYPE_ACTIONS, 102 EXPR_TYPE_KEYNAME, 103 EXPR_TYPE_SYMBOLS, 104 105 _EXPR_TYPE_NUM_VALUES 106 }; 107 108 enum expr_op_type { 109 EXPR_VALUE, 110 EXPR_IDENT, 111 EXPR_ACTION_DECL, 112 EXPR_FIELD_REF, 113 EXPR_ARRAY_REF, 114 EXPR_KEYSYM_LIST, 115 EXPR_ACTION_LIST, 116 EXPR_ADD, 117 EXPR_SUBTRACT, 118 EXPR_MULTIPLY, 119 EXPR_DIVIDE, 120 EXPR_ASSIGN, 121 EXPR_NOT, 122 EXPR_NEGATE, 123 EXPR_INVERT, 124 EXPR_UNARY_PLUS, 125 126 _EXPR_NUM_VALUES 127 }; 128 129 enum merge_mode { 130 MERGE_DEFAULT, 131 MERGE_AUGMENT, 132 MERGE_OVERRIDE, 133 MERGE_REPLACE, 134 }; 135 136 const char * 137 xkb_file_type_to_string(enum xkb_file_type type); 138 139 const char * 140 stmt_type_to_string(enum stmt_type type); 141 142 const char * 143 expr_op_type_to_string(enum expr_op_type type); 144 145 const char * 146 expr_value_type_to_string(enum expr_value_type type); 147 148 typedef struct _ParseCommon { 149 struct _ParseCommon *next; 150 enum stmt_type type; 151 } ParseCommon; 152 153 typedef struct _IncludeStmt { 154 ParseCommon common; 155 enum merge_mode merge; 156 char *stmt; 157 char *file; 158 char *map; 159 char *modifier; 160 struct _IncludeStmt *next_incl; 161 } IncludeStmt; 162 163 typedef struct { 164 ParseCommon common; 165 enum expr_op_type op; 166 enum expr_value_type value_type; 167 } ExprCommon; 168 169 typedef union ExprDef ExprDef; 170 171 typedef struct { 172 ExprCommon expr; 173 xkb_atom_t ident; 174 } ExprIdent; 175 176 typedef struct { 177 ExprCommon expr; 178 xkb_atom_t str; 179 } ExprString; 180 181 typedef struct { 182 ExprCommon expr; 183 bool set; 184 } ExprBoolean; 185 186 typedef struct { 187 ExprCommon expr; 188 int ival; 189 } ExprInteger; 190 191 typedef struct { 192 ExprCommon expr; 193 /* We don't support floats, but we still represnt them in the AST, in 194 * order to provide proper error messages. */ 195 } ExprFloat; 196 197 typedef struct { 198 ExprCommon expr; 199 xkb_atom_t key_name; 200 } ExprKeyName; 201 202 typedef struct { 203 ExprCommon expr; 204 ExprDef *left; 205 ExprDef *right; 206 } ExprBinary; 207 208 typedef struct { 209 ExprCommon expr; 210 ExprDef *child; 211 } ExprUnary; 212 213 typedef struct { 214 ExprCommon expr; 215 xkb_atom_t element; 216 xkb_atom_t field; 217 } ExprFieldRef; 218 219 typedef struct { 220 ExprCommon expr; 221 xkb_atom_t element; 222 xkb_atom_t field; 223 ExprDef *entry; 224 } ExprArrayRef; 225 226 typedef struct { 227 ExprCommon expr; 228 xkb_atom_t name; 229 ExprDef *args; 230 } ExprAction; 231 232 typedef struct { 233 ExprCommon expr; 234 ExprDef *actions; 235 } ExprActionList; 236 237 typedef struct { 238 ExprCommon expr; 239 darray(xkb_keysym_t) syms; 240 darray(unsigned int) symsMapIndex; 241 darray(unsigned int) symsNumEntries; 242 } ExprKeysymList; 243 244 union ExprDef { 245 ParseCommon common; 246 /* Maybe someday we can use C11 anonymous struct for ExprCommon here. */ 247 ExprCommon expr; 248 ExprIdent ident; 249 ExprString string; 250 ExprBoolean boolean; 251 ExprInteger integer; 252 ExprKeyName key_name; 253 ExprBinary binary; 254 ExprUnary unary; 255 ExprFieldRef field_ref; 256 ExprArrayRef array_ref; 257 ExprAction action; 258 ExprActionList actions; 259 ExprKeysymList keysym_list; 260 }; 261 262 typedef struct { 263 ParseCommon common; 264 enum merge_mode merge; 265 ExprDef *name; 266 ExprDef *value; 267 } VarDef; 268 269 typedef struct { 270 ParseCommon common; 271 enum merge_mode merge; 272 xkb_atom_t name; 273 ExprDef *value; 274 } VModDef; 275 276 typedef struct { 277 ParseCommon common; 278 enum merge_mode merge; 279 xkb_atom_t name; 280 int64_t value; 281 } KeycodeDef; 282 283 typedef struct { 284 ParseCommon common; 285 enum merge_mode merge; 286 xkb_atom_t alias; 287 xkb_atom_t real; 288 } KeyAliasDef; 289 290 typedef struct { 291 ParseCommon common; 292 enum merge_mode merge; 293 xkb_atom_t name; 294 VarDef *body; 295 } KeyTypeDef; 296 297 typedef struct { 298 ParseCommon common; 299 enum merge_mode merge; 300 xkb_atom_t keyName; 301 VarDef *symbols; 302 } SymbolsDef; 303 304 typedef struct { 305 ParseCommon common; 306 enum merge_mode merge; 307 xkb_atom_t modifier; 308 ExprDef *keys; 309 } ModMapDef; 310 311 typedef struct { 312 ParseCommon common; 313 enum merge_mode merge; 314 unsigned group; 315 ExprDef *def; 316 } GroupCompatDef; 317 318 typedef struct { 319 ParseCommon common; 320 enum merge_mode merge; 321 xkb_keysym_t sym; 322 ExprDef *match; 323 VarDef *def; 324 } InterpDef; 325 326 typedef struct { 327 ParseCommon common; 328 enum merge_mode merge; 329 unsigned ndx; 330 ExprDef *name; 331 bool virtual; 332 } LedNameDef; 333 334 typedef struct { 335 ParseCommon common; 336 enum merge_mode merge; 337 xkb_atom_t name; 338 VarDef *body; 339 } LedMapDef; 340 341 enum xkb_map_flags { 342 MAP_IS_DEFAULT = (1 << 0), 343 MAP_IS_PARTIAL = (1 << 1), 344 MAP_IS_HIDDEN = (1 << 2), 345 MAP_HAS_ALPHANUMERIC = (1 << 3), 346 MAP_HAS_MODIFIER = (1 << 4), 347 MAP_HAS_KEYPAD = (1 << 5), 348 MAP_HAS_FN = (1 << 6), 349 MAP_IS_ALTGR = (1 << 7), 350 }; 351 352 typedef struct { 353 ParseCommon common; 354 enum xkb_file_type file_type; 355 char *name; 356 ParseCommon *defs; 357 enum xkb_map_flags flags; 358 } XkbFile; 359 360 #endif 361