Home | History | Annotate | Download | only in xkbcomp
      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 (at) 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_STRING,
     99     EXPR_TYPE_ACTION,
    100     EXPR_TYPE_KEYNAME,
    101     EXPR_TYPE_SYMBOLS,
    102 
    103     _EXPR_TYPE_NUM_VALUES
    104 };
    105 
    106 enum expr_op_type {
    107     EXPR_VALUE,
    108     EXPR_IDENT,
    109     EXPR_ACTION_DECL,
    110     EXPR_FIELD_REF,
    111     EXPR_ARRAY_REF,
    112     EXPR_KEYSYM_LIST,
    113     EXPR_ACTION_LIST,
    114     EXPR_ADD,
    115     EXPR_SUBTRACT,
    116     EXPR_MULTIPLY,
    117     EXPR_DIVIDE,
    118     EXPR_ASSIGN,
    119     EXPR_NOT,
    120     EXPR_NEGATE,
    121     EXPR_INVERT,
    122     EXPR_UNARY_PLUS,
    123 
    124     _EXPR_NUM_VALUES
    125 };
    126 
    127 enum merge_mode {
    128     MERGE_DEFAULT,
    129     MERGE_AUGMENT,
    130     MERGE_OVERRIDE,
    131     MERGE_REPLACE,
    132 };
    133 
    134 const char *
    135 xkb_file_type_to_string(enum xkb_file_type type);
    136 
    137 const char *
    138 stmt_type_to_string(enum stmt_type type);
    139 
    140 const char *
    141 expr_op_type_to_string(enum expr_op_type type);
    142 
    143 const char *
    144 expr_value_type_to_string(enum expr_value_type type);
    145 
    146 typedef struct _ParseCommon  {
    147     struct _ParseCommon *next;
    148     enum stmt_type type;
    149 } ParseCommon;
    150 
    151 typedef struct _IncludeStmt {
    152     ParseCommon common;
    153     enum merge_mode merge;
    154     char *stmt;
    155     char *file;
    156     char *map;
    157     char *modifier;
    158     struct _IncludeStmt *next_incl;
    159 } IncludeStmt;
    160 
    161 typedef struct {
    162     ParseCommon common;
    163     enum expr_op_type op;
    164     enum expr_value_type value_type;
    165 } ExprCommon;
    166 
    167 typedef union ExprDef ExprDef;
    168 
    169 typedef struct {
    170     ExprCommon expr;
    171     xkb_atom_t ident;
    172 } ExprIdent;
    173 
    174 typedef struct {
    175     ExprCommon expr;
    176     xkb_atom_t str;
    177 } ExprString;
    178 
    179 typedef struct {
    180     ExprCommon expr;
    181     bool set;
    182 } ExprBoolean;
    183 
    184 typedef struct {
    185     ExprCommon expr;
    186     int ival;
    187 } ExprInteger;
    188 
    189 typedef struct {
    190     ExprCommon expr;
    191     xkb_atom_t key_name;
    192 } ExprKeyName;
    193 
    194 typedef struct {
    195     ExprCommon expr;
    196     ExprDef *left;
    197     ExprDef *right;
    198 } ExprBinary;
    199 
    200 typedef struct {
    201     ExprCommon expr;
    202     ExprDef *child;
    203 } ExprUnary;
    204 
    205 typedef struct {
    206     ExprCommon expr;
    207     xkb_atom_t element;
    208     xkb_atom_t field;
    209 } ExprFieldRef;
    210 
    211 typedef struct {
    212     ExprCommon expr;
    213     xkb_atom_t element;
    214     xkb_atom_t field;
    215     ExprDef *entry;
    216 } ExprArrayRef;
    217 
    218 typedef struct {
    219     ExprCommon expr;
    220     xkb_atom_t name;
    221     ExprDef *args;
    222 } ExprAction;
    223 
    224 typedef struct {
    225     ExprCommon expr;
    226     darray(xkb_keysym_t) syms;
    227     darray(unsigned int) symsMapIndex;
    228     darray(unsigned int) symsNumEntries;
    229 } ExprKeysymList;
    230 
    231 union ExprDef {
    232     ParseCommon common;
    233     /* Maybe someday we can use C11 anonymous struct for ExprCommon here. */
    234     ExprCommon expr;
    235     ExprIdent ident;
    236     ExprString string;
    237     ExprBoolean boolean;
    238     ExprInteger integer;
    239     ExprKeyName key_name;
    240     ExprBinary binary;
    241     ExprUnary unary;
    242     ExprFieldRef field_ref;
    243     ExprArrayRef array_ref;
    244     ExprAction action;
    245     ExprKeysymList keysym_list;
    246 };
    247 
    248 typedef struct {
    249     ParseCommon common;
    250     enum merge_mode merge;
    251     ExprDef *name;
    252     ExprDef *value;
    253 } VarDef;
    254 
    255 typedef struct {
    256     ParseCommon common;
    257     enum merge_mode merge;
    258     xkb_atom_t name;
    259     ExprDef *value;
    260 } VModDef;
    261 
    262 typedef struct {
    263     ParseCommon common;
    264     enum merge_mode merge;
    265     xkb_atom_t name;
    266     int64_t value;
    267 } KeycodeDef;
    268 
    269 typedef struct {
    270     ParseCommon common;
    271     enum merge_mode merge;
    272     xkb_atom_t alias;
    273     xkb_atom_t real;
    274 } KeyAliasDef;
    275 
    276 typedef struct {
    277     ParseCommon common;
    278     enum merge_mode merge;
    279     xkb_atom_t name;
    280     VarDef *body;
    281 } KeyTypeDef;
    282 
    283 typedef struct {
    284     ParseCommon common;
    285     enum merge_mode merge;
    286     xkb_atom_t keyName;
    287     VarDef *symbols;
    288 } SymbolsDef;
    289 
    290 typedef struct {
    291     ParseCommon common;
    292     enum merge_mode merge;
    293     xkb_atom_t modifier;
    294     ExprDef *keys;
    295 } ModMapDef;
    296 
    297 typedef struct {
    298     ParseCommon common;
    299     enum merge_mode merge;
    300     unsigned group;
    301     ExprDef *def;
    302 } GroupCompatDef;
    303 
    304 typedef struct {
    305     ParseCommon common;
    306     enum merge_mode merge;
    307     xkb_keysym_t sym;
    308     ExprDef *match;
    309     VarDef *def;
    310 } InterpDef;
    311 
    312 typedef struct {
    313     ParseCommon common;
    314     enum merge_mode merge;
    315     unsigned ndx;
    316     ExprDef *name;
    317     bool virtual;
    318 } LedNameDef;
    319 
    320 typedef struct {
    321     ParseCommon common;
    322     enum merge_mode merge;
    323     xkb_atom_t name;
    324     VarDef *body;
    325 } LedMapDef;
    326 
    327 enum xkb_map_flags {
    328     MAP_IS_DEFAULT = (1 << 0),
    329     MAP_IS_PARTIAL = (1 << 1),
    330     MAP_IS_HIDDEN = (1 << 2),
    331     MAP_HAS_ALPHANUMERIC = (1 << 3),
    332     MAP_HAS_MODIFIER = (1 << 4),
    333     MAP_HAS_KEYPAD = (1 << 5),
    334     MAP_HAS_FN = (1 << 6),
    335     MAP_IS_ALTGR = (1 << 7),
    336 };
    337 
    338 typedef struct {
    339     ParseCommon common;
    340     enum xkb_file_type file_type;
    341     char *topName;
    342     char *name;
    343     ParseCommon *defs;
    344     enum xkb_map_flags flags;
    345 } XkbFile;
    346 
    347 #endif
    348