Copyright updates
[platform/upstream/libxkbcommon.git] / src / xkbcomp / ast.h
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_INDICATOR_MAP,
89     STMT_INDICATOR_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     enum stmt_type type;
148     struct _ParseCommon *next;
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 _Expr {
162     ParseCommon common;
163     enum expr_op_type op;
164     enum expr_value_type value_type;
165     union {
166         struct {
167             struct _Expr *left;
168             struct _Expr *right;
169         } binary;
170         struct {
171             xkb_atom_t element;
172             xkb_atom_t field;
173         } field;
174         struct {
175             xkb_atom_t element;
176             xkb_atom_t field;
177             struct _Expr *entry;
178         } array;
179         struct {
180             xkb_atom_t name;
181             struct _Expr *args;
182         } action;
183         struct {
184             darray(char *) syms;
185             darray(int) symsMapIndex;
186             darray(unsigned int) symsNumEntries;
187         } list;
188         struct _Expr *child;
189         xkb_atom_t str;
190         unsigned uval;
191         int ival;
192         char keyName[XKB_KEY_NAME_LENGTH];
193     } value;
194 } ExprDef;
195
196 typedef struct _VarDef {
197     ParseCommon common;
198     enum merge_mode merge;
199     ExprDef *name;
200     ExprDef *value;
201 } VarDef;
202
203 typedef struct _VModDef {
204     ParseCommon common;
205     enum merge_mode merge;
206     xkb_atom_t name;
207     ExprDef *value;
208 } VModDef;
209
210 typedef struct _KeycodeDef {
211     ParseCommon common;
212     enum merge_mode merge;
213     char name[XKB_KEY_NAME_LENGTH];
214     unsigned long value;
215 } KeycodeDef;
216
217 typedef struct _KeyAliasDef {
218     ParseCommon common;
219     enum merge_mode merge;
220     char alias[XKB_KEY_NAME_LENGTH];
221     char real[XKB_KEY_NAME_LENGTH];
222 } KeyAliasDef;
223
224 typedef struct _KeyTypeDef {
225     ParseCommon common;
226     enum merge_mode merge;
227     xkb_atom_t name;
228     VarDef *body;
229 } KeyTypeDef;
230
231 typedef struct _SymbolsDef {
232     ParseCommon common;
233     enum merge_mode merge;
234     char keyName[XKB_KEY_NAME_LENGTH];
235     ExprDef *symbols;
236 } SymbolsDef;
237
238 typedef struct _ModMapDef {
239     ParseCommon common;
240     enum merge_mode merge;
241     xkb_atom_t modifier;
242     ExprDef *keys;
243 } ModMapDef;
244
245 typedef struct _GroupCompatDef {
246     ParseCommon common;
247     enum merge_mode merge;
248     int group;
249     ExprDef *def;
250 } GroupCompatDef;
251
252 typedef struct _InterpDef {
253     ParseCommon common;
254     enum merge_mode merge;
255     char *sym;
256     ExprDef *match;
257     VarDef *def;
258 } InterpDef;
259
260 typedef struct _IndicatorNameDef {
261     ParseCommon common;
262     enum merge_mode merge;
263     int ndx;
264     ExprDef *name;
265     bool virtual;
266 } IndicatorNameDef;
267
268 typedef struct _IndicatorMapDef {
269     ParseCommon common;
270     enum merge_mode merge;
271     xkb_atom_t name;
272     VarDef *body;
273 } IndicatorMapDef;
274
275 enum xkb_map_flags {
276     MAP_IS_DEFAULT = (1 << 0),
277     MAP_IS_PARTIAL = (1 << 1),
278     MAP_IS_HIDDEN = (1 << 2),
279     MAP_HAS_ALPHANUMERIC = (1 << 3),
280     MAP_HAS_MODIFIER = (1 << 4),
281     MAP_HAS_KEYPAD = (1 << 5),
282     MAP_HAS_FN = (1 << 6),
283     MAP_IS_ALTGR = (1 << 7),
284 };
285
286 typedef struct _XkbFile {
287     ParseCommon common;
288     enum xkb_file_type file_type;
289     char *topName;
290     char *name;
291     ParseCommon *defs;
292     int id;
293     enum xkb_map_flags flags;
294 } XkbFile;
295
296 #endif