Print this page
4474 DTrace Userland CTF Support
4475 DTrace userland Keyword
4476 DTrace tests should be better citizens
4479 pid provider types
4480 dof emulation missing checks
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libdtrace/common/dt_grammar.y
+++ new/usr/src/lib/libdtrace/common/dt_grammar.y
1 1 %{
2 2 /*
3 3 * CDDL HEADER START
4 4 *
5 5 * The contents of this file are subject to the terms of the
6 6 * Common Development and Distribution License, Version 1.0 only
7 7 * (the "License"). You may not use this file except in compliance
8 8 * with the License.
9 9 *
10 10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 11 * or http://www.opensolaris.org/os/licensing.
12 12 * See the License for the specific language governing permissions
13 13 * and limitations under the License.
14 14 *
15 15 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 17 * If applicable, add the following below this CDDL HEADER, with the
18 18 * fields enclosed by brackets "[]" replaced with your own identifying
19 19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 20 *
21 21 * CDDL HEADER END
22 22 *
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 -
27 -#pragma ident "%Z%%M% %I% %E% SMI"
26 +/*
27 + * Copyright (c) 2013 by Delphix. All rights reserved.
28 + * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 + */
28 30
29 31 #include <dt_impl.h>
30 32
31 33 #define OP1(op, c) dt_node_op1(op, c)
32 34 #define OP2(op, l, r) dt_node_op2(op, l, r)
33 35 #define OP3(x, y, z) dt_node_op3(x, y, z)
34 36 #define LINK(l, r) dt_node_link(l, r)
35 37 #define DUP(s) strdup(s)
36 38
37 39 %}
38 40
39 41 %union {
40 42 dt_node_t *l_node;
41 43 dt_decl_t *l_decl;
42 44 char *l_str;
43 45 uintmax_t l_int;
44 46 int l_tok;
45 47 }
46 48
47 49 %token DT_TOK_COMMA DT_TOK_ELLIPSIS
48 50 %token DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ
49 51 %token DT_TOK_DIV_EQ DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ
50 52 %token DT_TOK_LSH_EQ DT_TOK_RSH_EQ DT_TOK_QUESTION DT_TOK_COLON
51 53 %token DT_TOK_LOR DT_TOK_LXOR DT_TOK_LAND
52 54 %token DT_TOK_BOR DT_TOK_XOR DT_TOK_BAND DT_TOK_EQU DT_TOK_NEQ
53 55 %token DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE DT_TOK_LSH DT_TOK_RSH
54 56 %token DT_TOK_ADD DT_TOK_SUB DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD
55 57 %token DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB
56 58 %token DT_TOK_PREINC DT_TOK_POSTINC DT_TOK_PREDEC DT_TOK_POSTDEC
57 59 %token DT_TOK_IPOS DT_TOK_INEG DT_TOK_DEREF DT_TOK_ADDROF
58 60 %token DT_TOK_OFFSETOF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE
59 61 %token DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT
60 62
61 63 %token <l_str> DT_TOK_STRING
62 64 %token <l_str> DT_TOK_IDENT
63 65 %token <l_str> DT_TOK_PSPEC
64 66 %token <l_str> DT_TOK_AGG
65 67 %token <l_str> DT_TOK_TNAME
66 68 %token <l_int> DT_TOK_INT
67 69
68 70 %token DT_KEY_AUTO
69 71 %token DT_KEY_BREAK
70 72 %token DT_KEY_CASE
71 73 %token DT_KEY_CHAR
72 74 %token DT_KEY_CONST
73 75 %token DT_KEY_CONTINUE
74 76 %token DT_KEY_COUNTER
75 77 %token DT_KEY_DEFAULT
76 78 %token DT_KEY_DO
77 79 %token DT_KEY_DOUBLE
78 80 %token DT_KEY_ELSE
79 81 %token DT_KEY_ENUM
80 82 %token DT_KEY_EXTERN
81 83 %token DT_KEY_FLOAT
82 84 %token DT_KEY_FOR
83 85 %token DT_KEY_GOTO
84 86 %token DT_KEY_IF
85 87 %token DT_KEY_IMPORT
86 88 %token DT_KEY_INLINE
87 89 %token DT_KEY_INT
88 90 %token DT_KEY_LONG
89 91 %token DT_KEY_PROBE
90 92 %token DT_KEY_PROVIDER
91 93 %token DT_KEY_REGISTER
92 94 %token DT_KEY_RESTRICT
93 95 %token DT_KEY_RETURN
94 96 %token DT_KEY_SELF
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
95 97 %token DT_KEY_SHORT
96 98 %token DT_KEY_SIGNED
97 99 %token DT_KEY_STATIC
98 100 %token DT_KEY_STRING
99 101 %token DT_KEY_STRUCT
100 102 %token DT_KEY_SWITCH
101 103 %token DT_KEY_THIS
102 104 %token DT_KEY_TYPEDEF
103 105 %token DT_KEY_UNION
104 106 %token DT_KEY_UNSIGNED
107 +%token DT_KEY_USERLAND
105 108 %token DT_KEY_VOID
106 109 %token DT_KEY_VOLATILE
107 110 %token DT_KEY_WHILE
108 111 %token DT_KEY_XLATOR
109 112
110 113 %token DT_TOK_EPRED
111 114 %token DT_CTX_DEXPR
112 115 %token DT_CTX_DPROG
113 116 %token DT_CTX_DTYPE
114 117 %token DT_TOK_EOF 0
115 118
116 119 %left DT_TOK_COMMA
117 120 %right DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ DT_TOK_DIV_EQ
118 121 DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ DT_TOK_LSH_EQ
119 122 DT_TOK_RSH_EQ
120 123 %left DT_TOK_QUESTION DT_TOK_COLON
121 124 %left DT_TOK_LOR
122 125 %left DT_TOK_LXOR
123 126 %left DT_TOK_LAND
124 127 %left DT_TOK_BOR
125 128 %left DT_TOK_XOR
126 129 %left DT_TOK_BAND
127 130 %left DT_TOK_EQU DT_TOK_NEQ
128 131 %left DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE
129 132 %left DT_TOK_LSH DT_TOK_RSH
130 133 %left DT_TOK_ADD DT_TOK_SUB
131 134 %left DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD
132 135 %right DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB
133 136 DT_TOK_IPOS DT_TOK_INEG
134 137 %right DT_TOK_DEREF DT_TOK_ADDROF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE
135 138 %left DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT
136 139
137 140 %type <l_node> d_expression
138 141 %type <l_node> d_program
139 142 %type <l_node> d_type
140 143
141 144 %type <l_node> translation_unit
142 145 %type <l_node> external_declaration
143 146 %type <l_node> inline_definition
144 147 %type <l_node> translator_definition
145 148 %type <l_node> translator_member_list
146 149 %type <l_node> translator_member
147 150 %type <l_node> provider_definition
148 151 %type <l_node> provider_probe_list
149 152 %type <l_node> provider_probe
150 153 %type <l_node> probe_definition
151 154 %type <l_node> probe_specifiers
152 155 %type <l_node> probe_specifier_list
153 156 %type <l_node> probe_specifier
154 157 %type <l_node> statement_list
155 158 %type <l_node> statement
156 159 %type <l_node> declaration
157 160 %type <l_node> init_declarator_list
158 161 %type <l_node> init_declarator
159 162
160 163 %type <l_decl> type_specifier
161 164 %type <l_decl> type_qualifier
162 165 %type <l_decl> struct_or_union_specifier
163 166 %type <l_decl> specifier_qualifier_list
164 167 %type <l_decl> enum_specifier
165 168 %type <l_decl> declarator
166 169 %type <l_decl> direct_declarator
167 170 %type <l_decl> pointer
168 171 %type <l_decl> type_qualifier_list
169 172 %type <l_decl> type_name
170 173 %type <l_decl> abstract_declarator
171 174 %type <l_decl> direct_abstract_declarator
172 175
173 176 %type <l_node> parameter_type_list
174 177 %type <l_node> parameter_list
175 178 %type <l_node> parameter_declaration
176 179
177 180 %type <l_node> array
178 181 %type <l_node> array_parameters
179 182 %type <l_node> function
180 183 %type <l_node> function_parameters
181 184
182 185 %type <l_node> expression
183 186 %type <l_node> assignment_expression
184 187 %type <l_node> conditional_expression
185 188 %type <l_node> constant_expression
186 189 %type <l_node> logical_or_expression
187 190 %type <l_node> logical_xor_expression
188 191 %type <l_node> logical_and_expression
189 192 %type <l_node> inclusive_or_expression
190 193 %type <l_node> exclusive_or_expression
191 194 %type <l_node> and_expression
192 195 %type <l_node> equality_expression
193 196 %type <l_node> relational_expression
194 197 %type <l_node> shift_expression
195 198 %type <l_node> additive_expression
196 199 %type <l_node> multiplicative_expression
197 200 %type <l_node> cast_expression
198 201 %type <l_node> unary_expression
199 202 %type <l_node> postfix_expression
200 203 %type <l_node> primary_expression
201 204 %type <l_node> argument_expression_list
202 205
203 206 %type <l_tok> assignment_operator
204 207 %type <l_tok> unary_operator
205 208 %type <l_tok> struct_or_union
206 209
207 210 %%
208 211
209 212 dtrace_program: d_expression DT_TOK_EOF { return (dt_node_root($1)); }
210 213 | d_program DT_TOK_EOF { return (dt_node_root($1)); }
211 214 | d_type DT_TOK_EOF { return (dt_node_root($1)); }
212 215 ;
213 216
214 217 d_expression: DT_CTX_DEXPR { $$ = NULL; }
215 218 | DT_CTX_DEXPR expression { $$ = $2; }
216 219 ;
217 220
218 221 d_program: DT_CTX_DPROG { $$ = dt_node_program(NULL); }
219 222 | DT_CTX_DPROG translation_unit { $$ = dt_node_program($2); }
220 223 ;
221 224
222 225 d_type: DT_CTX_DTYPE { $$ = NULL; }
223 226 | DT_CTX_DTYPE type_name { $$ = (dt_node_t *)$2; }
224 227 ;
225 228
226 229 translation_unit:
227 230 external_declaration
228 231 | translation_unit external_declaration { $$ = LINK($1, $2); }
229 232 ;
230 233
231 234 external_declaration:
232 235 inline_definition
233 236 | translator_definition
234 237 | provider_definition
235 238 | probe_definition
236 239 | declaration
237 240 ;
238 241
239 242 inline_definition:
240 243 DT_KEY_INLINE declaration_specifiers declarator
241 244 { dt_scope_push(NULL, CTF_ERR); } DT_TOK_ASGN
242 245 assignment_expression ';' {
243 246 /*
244 247 * We push a new declaration scope before shifting the
245 248 * assignment_expression in order to preserve ds_class
246 249 * and ds_ident for use in dt_node_inline(). Once the
247 250 * entire inline_definition rule is matched, pop the
248 251 * scope and construct the inline using the saved decl.
249 252 */
250 253 dt_scope_pop();
251 254 $$ = dt_node_inline($6);
252 255 }
253 256 ;
254 257
255 258 translator_definition:
256 259 DT_KEY_XLATOR type_name DT_TOK_LT type_name
257 260 DT_TOK_IDENT DT_TOK_GT '{' translator_member_list '}' ';' {
258 261 $$ = dt_node_xlator($2, $4, $5, $8);
259 262 }
260 263 | DT_KEY_XLATOR type_name DT_TOK_LT type_name
261 264 DT_TOK_IDENT DT_TOK_GT '{' '}' ';' {
262 265 $$ = dt_node_xlator($2, $4, $5, NULL);
263 266 }
264 267 ;
265 268
266 269 translator_member_list:
267 270 translator_member
268 271 | translator_member_list translator_member { $$ = LINK($1,$2); }
269 272 ;
270 273
271 274 translator_member:
272 275 DT_TOK_IDENT DT_TOK_ASGN assignment_expression ';' {
273 276 $$ = dt_node_member(NULL, $1, $3);
274 277 }
275 278 ;
276 279
277 280 provider_definition:
278 281 DT_KEY_PROVIDER DT_TOK_IDENT '{' provider_probe_list '}' ';' {
279 282 $$ = dt_node_provider($2, $4);
280 283 }
281 284 | DT_KEY_PROVIDER DT_TOK_IDENT '{' '}' ';' {
282 285 $$ = dt_node_provider($2, NULL);
283 286 }
284 287 ;
285 288
286 289 provider_probe_list:
287 290 provider_probe
288 291 | provider_probe_list provider_probe { $$ = LINK($1, $2); }
289 292 ;
290 293
291 294 provider_probe:
292 295 DT_KEY_PROBE DT_TOK_IDENT function DT_TOK_COLON function ';' {
293 296 $$ = dt_node_probe($2, 2, $3, $5);
294 297 }
295 298 | DT_KEY_PROBE DT_TOK_IDENT function ';' {
296 299 $$ = dt_node_probe($2, 1, $3, NULL);
297 300 }
298 301 ;
299 302
300 303
301 304 probe_definition:
302 305 probe_specifiers {
303 306 /*
304 307 * If the input stream is a file, do not permit a probe
305 308 * specification without / <pred> / or { <act> } after
306 309 * it. This can only occur if the next token is EOF or
307 310 * an ambiguous predicate was slurped up as a comment.
308 311 * We cannot perform this check if input() is a string
309 312 * because dtrace(1M) [-fmnP] also use the compiler and
310 313 * things like dtrace -n BEGIN have to be accepted.
311 314 */
312 315 if (yypcb->pcb_fileptr != NULL) {
313 316 dnerror($1, D_SYNTAX, "expected predicate and/"
314 317 "or actions following probe description\n");
315 318 }
316 319 $$ = dt_node_clause($1, NULL, NULL);
317 320 }
318 321 | probe_specifiers '{' statement_list '}' {
319 322 $$ = dt_node_clause($1, NULL, $3);
320 323 }
321 324 | probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED {
322 325 dnerror($3, D_SYNTAX, "expected actions { } following "
323 326 "probe description and predicate\n");
324 327 }
325 328 | probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED
326 329 '{' statement_list '}' {
327 330 $$ = dt_node_clause($1, $3, $6);
328 331 }
329 332 ;
330 333
331 334 probe_specifiers:
332 335 probe_specifier_list { yybegin(YYS_EXPR); $$ = $1; }
333 336 ;
334 337
335 338 probe_specifier_list:
336 339 probe_specifier
337 340 | probe_specifier_list DT_TOK_COMMA probe_specifier {
338 341 $$ = LINK($1, $3);
339 342 }
340 343 ;
341 344
342 345 probe_specifier:
343 346 DT_TOK_PSPEC { $$ = dt_node_pdesc_by_name($1); }
344 347 | DT_TOK_INT { $$ = dt_node_pdesc_by_id($1); }
345 348 ;
346 349
347 350 statement_list: statement { $$ = $1; }
348 351 | statement_list ';' statement { $$ = LINK($1, $3); }
349 352 ;
350 353
351 354 statement: /* empty */ { $$ = NULL; }
352 355 | expression { $$ = dt_node_statement($1); }
353 356 ;
354 357
355 358 argument_expression_list:
356 359 assignment_expression
357 360 | argument_expression_list DT_TOK_COMMA assignment_expression {
358 361 $$ = LINK($1, $3);
359 362 }
360 363 ;
361 364
362 365 primary_expression:
363 366 DT_TOK_IDENT { $$ = dt_node_ident($1); }
364 367 | DT_TOK_AGG { $$ = dt_node_ident($1); }
365 368 | DT_TOK_INT { $$ = dt_node_int($1); }
366 369 | DT_TOK_STRING { $$ = dt_node_string($1); }
367 370 | DT_KEY_SELF { $$ = dt_node_ident(DUP("self")); }
368 371 | DT_KEY_THIS { $$ = dt_node_ident(DUP("this")); }
369 372 | DT_TOK_LPAR expression DT_TOK_RPAR { $$ = $2; }
370 373 ;
371 374
372 375 postfix_expression:
373 376 primary_expression
374 377 | postfix_expression
375 378 DT_TOK_LBRAC argument_expression_list DT_TOK_RBRAC {
376 379 $$ = OP2(DT_TOK_LBRAC, $1, $3);
377 380 }
378 381 | postfix_expression DT_TOK_LPAR DT_TOK_RPAR {
379 382 $$ = dt_node_func($1, NULL);
380 383 }
381 384 | postfix_expression
382 385 DT_TOK_LPAR argument_expression_list DT_TOK_RPAR {
383 386 $$ = dt_node_func($1, $3);
384 387 }
385 388 | postfix_expression DT_TOK_DOT DT_TOK_IDENT {
386 389 $$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
387 390 }
388 391 | postfix_expression DT_TOK_DOT DT_TOK_TNAME {
389 392 $$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
390 393 }
391 394 | postfix_expression DT_TOK_PTR DT_TOK_IDENT {
392 395 $$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
393 396 }
394 397 | postfix_expression DT_TOK_PTR DT_TOK_TNAME {
395 398 $$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
396 399 }
397 400 | postfix_expression DT_TOK_ADDADD {
398 401 $$ = OP1(DT_TOK_POSTINC, $1);
399 402 }
400 403 | postfix_expression DT_TOK_SUBSUB {
401 404 $$ = OP1(DT_TOK_POSTDEC, $1);
402 405 }
403 406 | DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
404 407 DT_TOK_IDENT DT_TOK_RPAR {
405 408 $$ = dt_node_offsetof($3, $5);
406 409 }
407 410 | DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
408 411 DT_TOK_TNAME DT_TOK_RPAR {
409 412 $$ = dt_node_offsetof($3, $5);
410 413 }
411 414 | DT_TOK_XLATE DT_TOK_LT type_name DT_TOK_GT
412 415 DT_TOK_LPAR expression DT_TOK_RPAR {
413 416 $$ = OP2(DT_TOK_XLATE, dt_node_type($3), $6);
414 417 }
415 418 ;
416 419
417 420 unary_expression:
418 421 postfix_expression
419 422 | DT_TOK_ADDADD unary_expression { $$ = OP1(DT_TOK_PREINC, $2); }
420 423 | DT_TOK_SUBSUB unary_expression { $$ = OP1(DT_TOK_PREDEC, $2); }
421 424 | unary_operator cast_expression { $$ = OP1($1, $2); }
422 425 | DT_TOK_SIZEOF unary_expression { $$ = OP1(DT_TOK_SIZEOF, $2); }
423 426 | DT_TOK_SIZEOF DT_TOK_LPAR type_name DT_TOK_RPAR {
424 427 $$ = OP1(DT_TOK_SIZEOF, dt_node_type($3));
425 428 }
426 429 | DT_TOK_STRINGOF unary_expression {
427 430 $$ = OP1(DT_TOK_STRINGOF, $2);
428 431 }
429 432 ;
430 433
431 434 unary_operator: DT_TOK_BAND { $$ = DT_TOK_ADDROF; }
432 435 | DT_TOK_MUL { $$ = DT_TOK_DEREF; }
433 436 | DT_TOK_ADD { $$ = DT_TOK_IPOS; }
434 437 | DT_TOK_SUB { $$ = DT_TOK_INEG; }
435 438 | DT_TOK_BNEG { $$ = DT_TOK_BNEG; }
436 439 | DT_TOK_LNEG { $$ = DT_TOK_LNEG; }
437 440 ;
438 441
439 442 cast_expression:
440 443 unary_expression
441 444 | DT_TOK_LPAR type_name DT_TOK_RPAR cast_expression {
442 445 $$ = OP2(DT_TOK_LPAR, dt_node_type($2), $4);
443 446 }
444 447 ;
445 448
446 449 multiplicative_expression:
447 450 cast_expression
448 451 | multiplicative_expression DT_TOK_MUL cast_expression {
449 452 $$ = OP2(DT_TOK_MUL, $1, $3);
450 453 }
451 454 | multiplicative_expression DT_TOK_DIV cast_expression {
452 455 $$ = OP2(DT_TOK_DIV, $1, $3);
453 456 }
454 457 | multiplicative_expression DT_TOK_MOD cast_expression {
455 458 $$ = OP2(DT_TOK_MOD, $1, $3);
456 459 }
457 460 ;
458 461
459 462 additive_expression:
460 463 multiplicative_expression
461 464 | additive_expression DT_TOK_ADD multiplicative_expression {
462 465 $$ = OP2(DT_TOK_ADD, $1, $3);
463 466 }
464 467 | additive_expression DT_TOK_SUB multiplicative_expression {
465 468 $$ = OP2(DT_TOK_SUB, $1, $3);
466 469 }
467 470 ;
468 471
469 472 shift_expression:
470 473 additive_expression
471 474 | shift_expression DT_TOK_LSH additive_expression {
472 475 $$ = OP2(DT_TOK_LSH, $1, $3);
473 476 }
474 477 | shift_expression DT_TOK_RSH additive_expression {
475 478 $$ = OP2(DT_TOK_RSH, $1, $3);
476 479 }
477 480 ;
478 481
479 482 relational_expression:
480 483 shift_expression
481 484 | relational_expression DT_TOK_LT shift_expression {
482 485 $$ = OP2(DT_TOK_LT, $1, $3);
483 486 }
484 487 | relational_expression DT_TOK_GT shift_expression {
485 488 $$ = OP2(DT_TOK_GT, $1, $3);
486 489 }
487 490 | relational_expression DT_TOK_LE shift_expression {
488 491 $$ = OP2(DT_TOK_LE, $1, $3);
489 492 }
490 493 | relational_expression DT_TOK_GE shift_expression {
491 494 $$ = OP2(DT_TOK_GE, $1, $3);
492 495 }
493 496 ;
494 497
495 498 equality_expression:
496 499 relational_expression
497 500 | equality_expression DT_TOK_EQU relational_expression {
498 501 $$ = OP2(DT_TOK_EQU, $1, $3);
499 502 }
500 503 | equality_expression DT_TOK_NEQ relational_expression {
501 504 $$ = OP2(DT_TOK_NEQ, $1, $3);
502 505 }
503 506 ;
504 507
505 508 and_expression:
506 509 equality_expression
507 510 | and_expression DT_TOK_BAND equality_expression {
508 511 $$ = OP2(DT_TOK_BAND, $1, $3);
509 512 }
510 513 ;
511 514
512 515 exclusive_or_expression:
513 516 and_expression
514 517 | exclusive_or_expression DT_TOK_XOR and_expression {
515 518 $$ = OP2(DT_TOK_XOR, $1, $3);
516 519 }
517 520 ;
518 521
519 522 inclusive_or_expression:
520 523 exclusive_or_expression
521 524 | inclusive_or_expression DT_TOK_BOR exclusive_or_expression {
522 525 $$ = OP2(DT_TOK_BOR, $1, $3);
523 526 }
524 527 ;
525 528
526 529 logical_and_expression:
527 530 inclusive_or_expression
528 531 | logical_and_expression DT_TOK_LAND inclusive_or_expression {
529 532 $$ = OP2(DT_TOK_LAND, $1, $3);
530 533 }
531 534 ;
532 535
533 536 logical_xor_expression:
534 537 logical_and_expression
535 538 | logical_xor_expression DT_TOK_LXOR logical_and_expression {
536 539 $$ = OP2(DT_TOK_LXOR, $1, $3);
537 540 }
538 541 ;
539 542
540 543 logical_or_expression:
541 544 logical_xor_expression
542 545 | logical_or_expression DT_TOK_LOR logical_xor_expression {
543 546 $$ = OP2(DT_TOK_LOR, $1, $3);
544 547 }
545 548 ;
546 549
547 550 constant_expression: conditional_expression
548 551 ;
549 552
550 553 conditional_expression:
551 554 logical_or_expression
552 555 | logical_or_expression DT_TOK_QUESTION expression DT_TOK_COLON
553 556 conditional_expression { $$ = OP3($1, $3, $5); }
554 557 ;
555 558
556 559 assignment_expression:
557 560 conditional_expression
558 561 | unary_expression assignment_operator assignment_expression {
559 562 $$ = OP2($2, $1, $3);
560 563 }
561 564 ;
562 565
563 566 assignment_operator:
564 567 DT_TOK_ASGN { $$ = DT_TOK_ASGN; }
565 568 | DT_TOK_MUL_EQ { $$ = DT_TOK_MUL_EQ; }
566 569 | DT_TOK_DIV_EQ { $$ = DT_TOK_DIV_EQ; }
567 570 | DT_TOK_MOD_EQ { $$ = DT_TOK_MOD_EQ; }
568 571 | DT_TOK_ADD_EQ { $$ = DT_TOK_ADD_EQ; }
569 572 | DT_TOK_SUB_EQ { $$ = DT_TOK_SUB_EQ; }
570 573 | DT_TOK_LSH_EQ { $$ = DT_TOK_LSH_EQ; }
571 574 | DT_TOK_RSH_EQ { $$ = DT_TOK_RSH_EQ; }
572 575 | DT_TOK_AND_EQ { $$ = DT_TOK_AND_EQ; }
573 576 | DT_TOK_XOR_EQ { $$ = DT_TOK_XOR_EQ; }
574 577 | DT_TOK_OR_EQ { $$ = DT_TOK_OR_EQ; }
575 578 ;
576 579
577 580 expression: assignment_expression
578 581 | expression DT_TOK_COMMA assignment_expression {
579 582 $$ = OP2(DT_TOK_COMMA, $1, $3);
580 583 }
581 584 ;
582 585
583 586 declaration: declaration_specifiers ';' {
584 587 $$ = dt_node_decl();
585 588 dt_decl_free(dt_decl_pop());
586 589 yybegin(YYS_CLAUSE);
587 590 }
588 591 | declaration_specifiers init_declarator_list ';' {
589 592 $$ = $2;
590 593 dt_decl_free(dt_decl_pop());
591 594 yybegin(YYS_CLAUSE);
592 595 }
593 596 ;
594 597
595 598 declaration_specifiers:
596 599 d_storage_class_specifier
597 600 | d_storage_class_specifier declaration_specifiers
598 601 | type_specifier
599 602 | type_specifier declaration_specifiers
600 603 | type_qualifier
601 604 | type_qualifier declaration_specifiers
602 605 ;
603 606
604 607 parameter_declaration_specifiers:
605 608 storage_class_specifier
606 609 | storage_class_specifier declaration_specifiers
607 610 | type_specifier
608 611 | type_specifier declaration_specifiers
609 612 | type_qualifier
610 613 | type_qualifier declaration_specifiers
611 614 ;
612 615
613 616 storage_class_specifier:
614 617 DT_KEY_AUTO { dt_decl_class(DT_DC_AUTO); }
615 618 | DT_KEY_REGISTER { dt_decl_class(DT_DC_REGISTER); }
616 619 | DT_KEY_STATIC { dt_decl_class(DT_DC_STATIC); }
617 620 | DT_KEY_EXTERN { dt_decl_class(DT_DC_EXTERN); }
618 621 | DT_KEY_TYPEDEF { dt_decl_class(DT_DC_TYPEDEF); }
619 622 ;
620 623
621 624 d_storage_class_specifier:
622 625 storage_class_specifier
623 626 | DT_KEY_SELF { dt_decl_class(DT_DC_SELF); }
624 627 | DT_KEY_THIS { dt_decl_class(DT_DC_THIS); }
625 628 ;
↓ open down ↓ |
511 lines elided |
↑ open up ↑ |
626 629
627 630 type_specifier: DT_KEY_VOID { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("void")); }
628 631 | DT_KEY_CHAR { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("char")); }
629 632 | DT_KEY_SHORT { $$ = dt_decl_attr(DT_DA_SHORT); }
630 633 | DT_KEY_INT { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("int")); }
631 634 | DT_KEY_LONG { $$ = dt_decl_attr(DT_DA_LONG); }
632 635 | DT_KEY_FLOAT { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("float")); }
633 636 | DT_KEY_DOUBLE { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("double")); }
634 637 | DT_KEY_SIGNED { $$ = dt_decl_attr(DT_DA_SIGNED); }
635 638 | DT_KEY_UNSIGNED { $$ = dt_decl_attr(DT_DA_UNSIGNED); }
639 + | DT_KEY_USERLAND { $$ = dt_decl_attr(DT_DA_USER); }
636 640 | DT_KEY_STRING {
637 641 $$ = dt_decl_spec(CTF_K_TYPEDEF, DUP("string"));
638 642 }
639 643 | DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_TYPEDEF, $1); }
640 644 | struct_or_union_specifier
641 645 | enum_specifier
642 646 ;
643 647
644 648 type_qualifier: DT_KEY_CONST { $$ = dt_decl_attr(DT_DA_CONST); }
645 649 | DT_KEY_RESTRICT { $$ = dt_decl_attr(DT_DA_RESTRICT); }
646 650 | DT_KEY_VOLATILE { $$ = dt_decl_attr(DT_DA_VOLATILE); }
647 651 ;
648 652
649 653 struct_or_union_specifier:
650 654 struct_or_union_definition struct_declaration_list '}' {
651 655 $$ = dt_scope_pop();
652 656 }
653 657 | struct_or_union DT_TOK_IDENT { $$ = dt_decl_spec($1, $2); }
654 658 | struct_or_union DT_TOK_TNAME { $$ = dt_decl_spec($1, $2); }
655 659 ;
656 660
657 661 struct_or_union_definition:
658 662 struct_or_union '{' { dt_decl_sou($1, NULL); }
659 663 | struct_or_union DT_TOK_IDENT '{' { dt_decl_sou($1, $2); }
660 664 | struct_or_union DT_TOK_TNAME '{' { dt_decl_sou($1, $2); }
661 665 ;
662 666
663 667 struct_or_union:
664 668 DT_KEY_STRUCT { $$ = CTF_K_STRUCT; }
665 669 | DT_KEY_UNION { $$ = CTF_K_UNION; }
666 670 ;
667 671
668 672 struct_declaration_list:
669 673 struct_declaration
670 674 | struct_declaration_list struct_declaration
671 675 ;
672 676
673 677 init_declarator_list:
674 678 init_declarator
675 679 | init_declarator_list DT_TOK_COMMA init_declarator {
676 680 $$ = LINK($1, $3);
677 681 }
678 682 ;
679 683
680 684 init_declarator:
681 685 declarator {
682 686 $$ = dt_node_decl();
683 687 dt_decl_reset();
684 688 }
685 689 ;
686 690
687 691 struct_declaration:
688 692 specifier_qualifier_list struct_declarator_list ';' {
689 693 dt_decl_free(dt_decl_pop());
690 694 }
691 695 ;
692 696
693 697 specifier_qualifier_list:
694 698 type_specifier
695 699 | type_specifier specifier_qualifier_list { $$ = $2; }
696 700 | type_qualifier
697 701 | type_qualifier specifier_qualifier_list { $$ = $2; }
698 702 ;
699 703
700 704 struct_declarator_list:
701 705 struct_declarator
702 706 | struct_declarator_list DT_TOK_COMMA struct_declarator
703 707 ;
704 708
705 709 struct_declarator:
706 710 declarator { dt_decl_member(NULL); }
707 711 | DT_TOK_COLON constant_expression { dt_decl_member($2); }
708 712 | declarator DT_TOK_COLON constant_expression {
709 713 dt_decl_member($3);
710 714 }
711 715 ;
712 716
713 717 enum_specifier:
714 718 enum_definition enumerator_list '}' { $$ = dt_scope_pop(); }
715 719 | DT_KEY_ENUM DT_TOK_IDENT { $$ = dt_decl_spec(CTF_K_ENUM, $2); }
716 720 | DT_KEY_ENUM DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_ENUM, $2); }
717 721 ;
718 722
719 723 enum_definition:
720 724 DT_KEY_ENUM '{' { dt_decl_enum(NULL); }
721 725 | DT_KEY_ENUM DT_TOK_IDENT '{' { dt_decl_enum($2); }
722 726 | DT_KEY_ENUM DT_TOK_TNAME '{' { dt_decl_enum($2); }
723 727 ;
724 728
725 729 enumerator_list:
726 730 enumerator
727 731 | enumerator_list DT_TOK_COMMA enumerator
728 732 ;
729 733
730 734 enumerator: DT_TOK_IDENT { dt_decl_enumerator($1, NULL); }
731 735 | DT_TOK_IDENT DT_TOK_ASGN expression {
732 736 dt_decl_enumerator($1, $3);
733 737 }
734 738 ;
735 739
736 740 declarator: direct_declarator
737 741 | pointer direct_declarator
738 742 ;
739 743
740 744 direct_declarator:
741 745 DT_TOK_IDENT { $$ = dt_decl_ident($1); }
742 746 | lparen declarator DT_TOK_RPAR { $$ = $2; }
743 747 | direct_declarator array { dt_decl_array($2); }
744 748 | direct_declarator function { dt_decl_func($1, $2); }
745 749 ;
746 750
747 751 lparen: DT_TOK_LPAR { dt_decl_top()->dd_attr |= DT_DA_PAREN; }
748 752 ;
749 753
750 754 pointer: DT_TOK_MUL { $$ = dt_decl_ptr(); }
751 755 | DT_TOK_MUL type_qualifier_list { $$ = dt_decl_ptr(); }
752 756 | DT_TOK_MUL pointer { $$ = dt_decl_ptr(); }
753 757 | DT_TOK_MUL type_qualifier_list pointer { $$ = dt_decl_ptr(); }
754 758 ;
755 759
756 760 type_qualifier_list:
757 761 type_qualifier
758 762 | type_qualifier_list type_qualifier { $$ = $2; }
759 763 ;
760 764
761 765 parameter_type_list:
762 766 parameter_list
763 767 | DT_TOK_ELLIPSIS { $$ = dt_node_vatype(); }
764 768 | parameter_list DT_TOK_COMMA DT_TOK_ELLIPSIS {
765 769 $$ = LINK($1, dt_node_vatype());
766 770 }
767 771 ;
768 772
769 773 parameter_list: parameter_declaration
770 774 | parameter_list DT_TOK_COMMA parameter_declaration {
771 775 $$ = LINK($1, $3);
772 776 }
773 777 ;
774 778
775 779 parameter_declaration:
776 780 parameter_declaration_specifiers {
777 781 $$ = dt_node_type(NULL);
778 782 }
779 783 | parameter_declaration_specifiers declarator {
780 784 $$ = dt_node_type(NULL);
781 785 }
782 786 | parameter_declaration_specifiers abstract_declarator {
783 787 $$ = dt_node_type(NULL);
784 788 }
785 789 ;
786 790
787 791 type_name: specifier_qualifier_list {
788 792 $$ = dt_decl_pop();
789 793 }
790 794 | specifier_qualifier_list abstract_declarator {
791 795 $$ = dt_decl_pop();
792 796 }
793 797 ;
794 798
795 799 abstract_declarator:
796 800 pointer
797 801 | direct_abstract_declarator
798 802 | pointer direct_abstract_declarator
799 803 ;
800 804
801 805 direct_abstract_declarator:
802 806 lparen abstract_declarator DT_TOK_RPAR { $$ = $2; }
803 807 | direct_abstract_declarator array { dt_decl_array($2); }
804 808 | array { dt_decl_array($1); $$ = NULL; }
805 809 | direct_abstract_declarator function { dt_decl_func($1, $2); }
806 810 | function { dt_decl_func(NULL, $1); }
807 811 ;
808 812
809 813 array: DT_TOK_LBRAC { dt_scope_push(NULL, CTF_ERR); }
810 814 array_parameters DT_TOK_RBRAC {
811 815 dt_scope_pop();
812 816 $$ = $3;
813 817 }
814 818 ;
815 819
816 820 array_parameters:
817 821 /* empty */ { $$ = NULL; }
818 822 | constant_expression { $$ = $1; }
819 823 | parameter_type_list { $$ = $1; }
820 824 ;
821 825
822 826 function: DT_TOK_LPAR { dt_scope_push(NULL, CTF_ERR); }
823 827 function_parameters DT_TOK_RPAR {
824 828 dt_scope_pop();
825 829 $$ = $3;
826 830 }
827 831 ;
828 832
829 833 function_parameters:
830 834 /* empty */ { $$ = NULL; }
831 835 | parameter_type_list { $$ = $1; }
832 836 ;
833 837
834 838 %%
↓ open down ↓ |
189 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX