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