Allocate xkb_component_names on stack
[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 #ifndef XKBCOMP_AST_H
28 #define XKBCOMP_AST_H
29
30 enum stmt_type {
31     STMT_UNKNOWN = 0,
32     STMT_INCLUDE,
33     STMT_KEYCODE,
34     STMT_ALIAS,
35     STMT_EXPR,
36     STMT_VAR,
37     STMT_TYPE,
38     STMT_INTERP,
39     STMT_VMOD,
40     STMT_SYMBOLS,
41     STMT_MODMAP,
42     STMT_GROUP_COMPAT,
43     STMT_INDICATOR_MAP,
44     STMT_INDICATOR_NAME,
45     _STMT_NUM_VALUES
46 };
47
48 enum expr_value_type {
49     EXPR_TYPE_UNKNOWN = 0,
50     EXPR_TYPE_BOOLEAN,
51     EXPR_TYPE_INT,
52     EXPR_TYPE_STRING,
53     EXPR_TYPE_ACTION,
54     EXPR_TYPE_KEYNAME,
55     EXPR_TYPE_SYMBOLS,
56 };
57
58 enum expr_op_type {
59     EXPR_VALUE = 0,
60     EXPR_IDENT,
61     EXPR_ACTION_DECL,
62     EXPR_FIELD_REF,
63     EXPR_ARRAY_REF,
64     EXPR_KEYSYM_LIST,
65     EXPR_ACTION_LIST,
66     EXPR_ADD,
67     EXPR_SUBTRACT,
68     EXPR_MULTIPLY,
69     EXPR_DIVIDE,
70     EXPR_ASSIGN,
71     EXPR_NOT,
72     EXPR_NEGATE,
73     EXPR_INVERT,
74     EXPR_UNARY_PLUS,
75 };
76
77 enum merge_mode {
78     MERGE_DEFAULT,
79     MERGE_AUGMENT,
80     MERGE_OVERRIDE,
81     MERGE_REPLACE,
82 };
83
84 typedef struct _ParseCommon {
85     enum stmt_type type;
86     struct _ParseCommon *next;
87 } ParseCommon;
88
89 typedef struct _IncludeStmt {
90     ParseCommon common;
91     enum merge_mode merge;
92     char *stmt;
93     char *file;
94     char *map;
95     char *modifier;
96     struct _IncludeStmt *next_incl;
97 } IncludeStmt;
98
99 typedef struct _Expr {
100     ParseCommon common;
101     enum expr_op_type op;
102     enum expr_value_type value_type;
103     union {
104         struct {
105             struct _Expr *left;
106             struct _Expr *right;
107         } binary;
108         struct {
109             xkb_atom_t element;
110             xkb_atom_t field;
111         } field;
112         struct {
113             xkb_atom_t element;
114             xkb_atom_t field;
115             struct _Expr *entry;
116         } array;
117         struct {
118             xkb_atom_t name;
119             struct _Expr *args;
120         } action;
121         struct {
122             darray(char *) syms;
123             darray(int) symsMapIndex;
124             darray(unsigned int) symsNumEntries;
125         } list;
126         struct _Expr *child;
127         xkb_atom_t str;
128         unsigned uval;
129         int ival;
130         char keyName[XkbKeyNameLength];
131     } value;
132 } ExprDef;
133
134 typedef struct _VarDef {
135     ParseCommon common;
136     enum merge_mode merge;
137     ExprDef *name;
138     ExprDef *value;
139 } VarDef;
140
141 typedef struct _VModDef {
142     ParseCommon common;
143     enum merge_mode merge;
144     xkb_atom_t name;
145     ExprDef *value;
146 } VModDef;
147
148 typedef struct _KeycodeDef {
149     ParseCommon common;
150     enum merge_mode merge;
151     char name[XkbKeyNameLength];
152     unsigned long value;
153 } KeycodeDef;
154
155 typedef struct _KeyAliasDef {
156     ParseCommon common;
157     enum merge_mode merge;
158     char alias[XkbKeyNameLength];
159     char real[XkbKeyNameLength];
160 } KeyAliasDef;
161
162 typedef struct _KeyTypeDef {
163     ParseCommon common;
164     enum merge_mode merge;
165     xkb_atom_t name;
166     VarDef *body;
167 } KeyTypeDef;
168
169 typedef struct _SymbolsDef {
170     ParseCommon common;
171     enum merge_mode merge;
172     char keyName[XkbKeyNameLength];
173     ExprDef *symbols;
174 } SymbolsDef;
175
176 typedef struct _ModMapDef {
177     ParseCommon common;
178     enum merge_mode merge;
179     xkb_atom_t modifier;
180     ExprDef *keys;
181 } ModMapDef;
182
183 typedef struct _GroupCompatDef {
184     ParseCommon common;
185     enum merge_mode merge;
186     int group;
187     ExprDef *def;
188 } GroupCompatDef;
189
190 typedef struct _InterpDef {
191     ParseCommon common;
192     enum merge_mode merge;
193     char *sym;
194     ExprDef *match;
195     VarDef *def;
196 } InterpDef;
197
198 typedef struct _IndicatorNameDef {
199     ParseCommon common;
200     enum merge_mode merge;
201     int ndx;
202     ExprDef *name;
203     bool virtual;
204 } IndicatorNameDef;
205
206 typedef struct _IndicatorMapDef {
207     ParseCommon common;
208     enum merge_mode merge;
209     xkb_atom_t name;
210     VarDef *body;
211 } IndicatorMapDef;
212
213 typedef struct _XkbFile {
214     ParseCommon common;
215     enum xkb_file_type file_type;
216     char *topName;
217     char *name;
218     ParseCommon *defs;
219     int id;
220     unsigned flags;
221 } XkbFile;
222
223 #endif