• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     ExprCommon expr;
247     ExprIdent ident;
248     ExprString string;
249     ExprBoolean boolean;
250     ExprInteger integer;
251     ExprKeyName key_name;
252     ExprBinary binary;
253     ExprUnary unary;
254     ExprFieldRef field_ref;
255     ExprArrayRef array_ref;
256     ExprAction action;
257     ExprActionList actions;
258     ExprKeysymList keysym_list;
259 };
260 
261 typedef struct {
262     ParseCommon common;
263     enum merge_mode merge;
264     ExprDef *name;
265     ExprDef *value;
266 } VarDef;
267 
268 typedef struct {
269     ParseCommon common;
270     enum merge_mode merge;
271     xkb_atom_t name;
272     ExprDef *value;
273 } VModDef;
274 
275 typedef struct {
276     ParseCommon common;
277     enum merge_mode merge;
278     xkb_atom_t name;
279     int64_t value;
280 } KeycodeDef;
281 
282 typedef struct {
283     ParseCommon common;
284     enum merge_mode merge;
285     xkb_atom_t alias;
286     xkb_atom_t real;
287 } KeyAliasDef;
288 
289 typedef struct {
290     ParseCommon common;
291     enum merge_mode merge;
292     xkb_atom_t name;
293     VarDef *body;
294 } KeyTypeDef;
295 
296 typedef struct {
297     ParseCommon common;
298     enum merge_mode merge;
299     xkb_atom_t keyName;
300     VarDef *symbols;
301 } SymbolsDef;
302 
303 typedef struct {
304     ParseCommon common;
305     enum merge_mode merge;
306     xkb_atom_t modifier;
307     ExprDef *keys;
308 } ModMapDef;
309 
310 typedef struct {
311     ParseCommon common;
312     enum merge_mode merge;
313     unsigned group;
314     ExprDef *def;
315 } GroupCompatDef;
316 
317 typedef struct {
318     ParseCommon common;
319     enum merge_mode merge;
320     xkb_keysym_t sym;
321     ExprDef *match;
322     VarDef *def;
323 } InterpDef;
324 
325 typedef struct {
326     ParseCommon common;
327     enum merge_mode merge;
328     unsigned ndx;
329     ExprDef *name;
330     bool virtual;
331 } LedNameDef;
332 
333 typedef struct {
334     ParseCommon common;
335     enum merge_mode merge;
336     xkb_atom_t name;
337     VarDef *body;
338 } LedMapDef;
339 
340 enum xkb_map_flags {
341     MAP_IS_DEFAULT = (1 << 0),
342     MAP_IS_PARTIAL = (1 << 1),
343     MAP_IS_HIDDEN = (1 << 2),
344     MAP_HAS_ALPHANUMERIC = (1 << 3),
345     MAP_HAS_MODIFIER = (1 << 4),
346     MAP_HAS_KEYPAD = (1 << 5),
347     MAP_HAS_FN = (1 << 6),
348     MAP_IS_ALTGR = (1 << 7),
349 };
350 
351 typedef struct {
352     ParseCommon common;
353     enum xkb_file_type file_type;
354     char *name;
355     ParseCommon *defs;
356     enum xkb_map_flags flags;
357 } XkbFile;
358 
359 #endif
360