1178479Sjb%{
2178479Sjb/*
3178479Sjb * CDDL HEADER START
4178479Sjb *
5178479Sjb * The contents of this file are subject to the terms of the
6178479Sjb * Common Development and Distribution License, Version 1.0 only
7178479Sjb * (the "License").  You may not use this file except in compliance
8178479Sjb * with the License.
9178479Sjb *
10178479Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11178479Sjb * or http://www.opensolaris.org/os/licensing.
12178479Sjb * See the License for the specific language governing permissions
13178479Sjb * and limitations under the License.
14178479Sjb *
15178479Sjb * When distributing Covered Code, include this CDDL HEADER in each
16178479Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17178479Sjb * If applicable, add the following below this CDDL HEADER, with the
18178479Sjb * fields enclosed by brackets "[]" replaced with your own identifying
19178479Sjb * information: Portions Copyright [yyyy] [name of copyright owner]
20178479Sjb *
21178479Sjb * CDDL HEADER END
22178479Sjb *
23178479Sjb * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24178479Sjb * Use is subject to license terms.
25178479Sjb */
26268578Srpaulo/*
27268578Srpaulo * Copyright (c) 2013 by Delphix. All rights reserved.
28268578Srpaulo * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29268578Srpaulo */
30178479Sjb
31178479Sjb#include <dt_impl.h>
32178479Sjb
33178479Sjb#define	OP1(op, c)	dt_node_op1(op, c)
34178479Sjb#define	OP2(op, l, r)	dt_node_op2(op, l, r)
35178479Sjb#define	OP3(x, y, z)	dt_node_op3(x, y, z)
36178479Sjb#define	LINK(l, r)	dt_node_link(l, r)
37178479Sjb#define	DUP(s)		strdup(s)
38178479Sjb
39178479Sjb%}
40178479Sjb
41178479Sjb%union {
42178479Sjb	dt_node_t *l_node;
43178479Sjb	dt_decl_t *l_decl;
44178479Sjb	char *l_str;
45178479Sjb	uintmax_t l_int;
46178479Sjb	int l_tok;
47178479Sjb}
48178479Sjb
49178479Sjb%token	DT_TOK_COMMA DT_TOK_ELLIPSIS
50178479Sjb%token	DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ
51178479Sjb%token	DT_TOK_DIV_EQ DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ
52178479Sjb%token	DT_TOK_LSH_EQ DT_TOK_RSH_EQ DT_TOK_QUESTION DT_TOK_COLON
53178479Sjb%token	DT_TOK_LOR DT_TOK_LXOR DT_TOK_LAND
54178479Sjb%token	DT_TOK_BOR DT_TOK_XOR DT_TOK_BAND DT_TOK_EQU DT_TOK_NEQ
55178479Sjb%token	DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE DT_TOK_LSH DT_TOK_RSH
56178479Sjb%token	DT_TOK_ADD DT_TOK_SUB DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD
57178479Sjb%token	DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB
58178479Sjb%token	DT_TOK_PREINC DT_TOK_POSTINC DT_TOK_PREDEC DT_TOK_POSTDEC
59178479Sjb%token	DT_TOK_IPOS DT_TOK_INEG DT_TOK_DEREF DT_TOK_ADDROF
60178479Sjb%token	DT_TOK_OFFSETOF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE
61178479Sjb%token	DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT
62178479Sjb
63178479Sjb%token <l_str>	DT_TOK_STRING
64178479Sjb%token <l_str>	DT_TOK_IDENT
65178479Sjb%token <l_str>	DT_TOK_PSPEC
66178479Sjb%token <l_str>	DT_TOK_AGG
67178479Sjb%token <l_str>	DT_TOK_TNAME
68178479Sjb%token <l_int>	DT_TOK_INT
69178479Sjb
70178479Sjb%token	DT_KEY_AUTO
71178479Sjb%token	DT_KEY_BREAK
72178479Sjb%token	DT_KEY_CASE
73178479Sjb%token	DT_KEY_CHAR
74178479Sjb%token	DT_KEY_CONST
75178479Sjb%token	DT_KEY_CONTINUE
76178479Sjb%token	DT_KEY_COUNTER
77178479Sjb%token	DT_KEY_DEFAULT
78178479Sjb%token	DT_KEY_DO
79178479Sjb%token	DT_KEY_DOUBLE
80178479Sjb%token	DT_KEY_ELSE
81178479Sjb%token	DT_KEY_ENUM
82178479Sjb%token	DT_KEY_EXTERN
83178479Sjb%token	DT_KEY_FLOAT
84178479Sjb%token	DT_KEY_FOR
85178479Sjb%token	DT_KEY_GOTO
86178479Sjb%token	DT_KEY_IF
87178479Sjb%token	DT_KEY_IMPORT
88178479Sjb%token	DT_KEY_INLINE
89178479Sjb%token	DT_KEY_INT
90178479Sjb%token	DT_KEY_LONG
91178479Sjb%token	DT_KEY_PROBE
92178479Sjb%token	DT_KEY_PROVIDER
93178479Sjb%token	DT_KEY_REGISTER
94178479Sjb%token	DT_KEY_RESTRICT
95178479Sjb%token	DT_KEY_RETURN
96178479Sjb%token	DT_KEY_SELF
97178479Sjb%token	DT_KEY_SHORT
98178479Sjb%token	DT_KEY_SIGNED
99178479Sjb%token	DT_KEY_STATIC
100178479Sjb%token	DT_KEY_STRING
101178479Sjb%token	DT_KEY_STRUCT
102178479Sjb%token	DT_KEY_SWITCH
103178479Sjb%token	DT_KEY_THIS
104178479Sjb%token	DT_KEY_TYPEDEF
105178479Sjb%token	DT_KEY_UNION
106178479Sjb%token	DT_KEY_UNSIGNED
107268578Srpaulo%token	DT_KEY_USERLAND
108178479Sjb%token	DT_KEY_VOID
109178479Sjb%token	DT_KEY_VOLATILE
110178479Sjb%token	DT_KEY_WHILE
111178479Sjb%token	DT_KEY_XLATOR
112178479Sjb
113178479Sjb%token	DT_TOK_EPRED
114178479Sjb%token	DT_CTX_DEXPR
115178479Sjb%token	DT_CTX_DPROG
116178479Sjb%token	DT_CTX_DTYPE
117178479Sjb%token	DT_TOK_EOF	0
118178479Sjb
119178479Sjb%left	DT_TOK_COMMA
120178479Sjb%right	DT_TOK_ASGN DT_TOK_ADD_EQ DT_TOK_SUB_EQ DT_TOK_MUL_EQ DT_TOK_DIV_EQ
121178479Sjb	DT_TOK_MOD_EQ DT_TOK_AND_EQ DT_TOK_XOR_EQ DT_TOK_OR_EQ DT_TOK_LSH_EQ
122178479Sjb	DT_TOK_RSH_EQ
123178479Sjb%left	DT_TOK_QUESTION DT_TOK_COLON
124178479Sjb%left	DT_TOK_LOR
125178479Sjb%left	DT_TOK_LXOR
126178479Sjb%left	DT_TOK_LAND
127178479Sjb%left	DT_TOK_BOR
128178479Sjb%left	DT_TOK_XOR
129178479Sjb%left	DT_TOK_BAND
130178479Sjb%left	DT_TOK_EQU DT_TOK_NEQ
131178479Sjb%left	DT_TOK_LT DT_TOK_LE DT_TOK_GT DT_TOK_GE
132178479Sjb%left	DT_TOK_LSH DT_TOK_RSH
133178479Sjb%left	DT_TOK_ADD DT_TOK_SUB
134178479Sjb%left	DT_TOK_MUL DT_TOK_DIV DT_TOK_MOD
135178479Sjb%right	DT_TOK_LNEG DT_TOK_BNEG DT_TOK_ADDADD DT_TOK_SUBSUB
136178479Sjb	DT_TOK_IPOS DT_TOK_INEG
137178479Sjb%right	DT_TOK_DEREF DT_TOK_ADDROF DT_TOK_SIZEOF DT_TOK_STRINGOF DT_TOK_XLATE
138178479Sjb%left	DT_TOK_LPAR DT_TOK_RPAR DT_TOK_LBRAC DT_TOK_RBRAC DT_TOK_PTR DT_TOK_DOT
139178479Sjb
140178479Sjb%type	<l_node>	d_expression
141178479Sjb%type	<l_node>	d_program
142178479Sjb%type	<l_node>	d_type
143178479Sjb
144178479Sjb%type	<l_node>	translation_unit
145178479Sjb%type	<l_node>	external_declaration
146178479Sjb%type	<l_node>	inline_definition
147178479Sjb%type	<l_node>	translator_definition
148178479Sjb%type	<l_node>	translator_member_list
149178479Sjb%type	<l_node>	translator_member
150178479Sjb%type	<l_node>	provider_definition
151178479Sjb%type	<l_node>	provider_probe_list
152178479Sjb%type	<l_node>	provider_probe
153178479Sjb%type	<l_node>	probe_definition
154178479Sjb%type	<l_node>	probe_specifiers
155178479Sjb%type	<l_node>	probe_specifier_list
156178479Sjb%type	<l_node>	probe_specifier
157178479Sjb%type	<l_node>	statement_list
158178479Sjb%type	<l_node>	statement
159178479Sjb%type	<l_node>	declaration
160178479Sjb%type	<l_node>	init_declarator_list
161178479Sjb%type	<l_node>	init_declarator
162178479Sjb
163178479Sjb%type	<l_decl>	type_specifier
164178479Sjb%type	<l_decl>	type_qualifier
165178479Sjb%type	<l_decl>	struct_or_union_specifier
166178479Sjb%type	<l_decl>	specifier_qualifier_list
167178479Sjb%type	<l_decl>	enum_specifier
168178479Sjb%type	<l_decl>	declarator
169178479Sjb%type	<l_decl>	direct_declarator
170178479Sjb%type	<l_decl>	pointer
171178479Sjb%type	<l_decl>	type_qualifier_list
172178479Sjb%type	<l_decl>	type_name
173178479Sjb%type	<l_decl>	abstract_declarator
174178479Sjb%type	<l_decl>	direct_abstract_declarator
175178479Sjb
176178479Sjb%type	<l_node>	parameter_type_list
177178479Sjb%type	<l_node>	parameter_list
178178479Sjb%type	<l_node>	parameter_declaration
179178479Sjb
180178479Sjb%type	<l_node>	array
181178479Sjb%type	<l_node>	array_parameters
182178479Sjb%type	<l_node>	function
183178479Sjb%type	<l_node>	function_parameters
184178479Sjb
185178479Sjb%type	<l_node>	expression
186178479Sjb%type	<l_node>	assignment_expression
187178479Sjb%type	<l_node>	conditional_expression
188178479Sjb%type	<l_node>	constant_expression
189178479Sjb%type	<l_node>	logical_or_expression
190178479Sjb%type	<l_node>	logical_xor_expression
191178479Sjb%type	<l_node>	logical_and_expression
192178479Sjb%type	<l_node>	inclusive_or_expression
193178479Sjb%type	<l_node>	exclusive_or_expression
194178479Sjb%type	<l_node>	and_expression
195178479Sjb%type	<l_node>	equality_expression
196178479Sjb%type	<l_node>	relational_expression
197178479Sjb%type	<l_node>	shift_expression
198178479Sjb%type	<l_node>	additive_expression
199178479Sjb%type	<l_node>	multiplicative_expression
200178479Sjb%type	<l_node>	cast_expression
201178479Sjb%type	<l_node>	unary_expression
202178479Sjb%type	<l_node>	postfix_expression
203178479Sjb%type	<l_node>	primary_expression
204178479Sjb%type	<l_node>	argument_expression_list
205178479Sjb
206178479Sjb%type	<l_tok>		assignment_operator
207178479Sjb%type	<l_tok>		unary_operator
208178479Sjb%type	<l_tok>		struct_or_union
209178479Sjb
210276267Smarkj%type	<l_str>		dtrace_keyword_ident
211276267Smarkj
212178479Sjb%%
213178479Sjb
214178479Sjbdtrace_program: d_expression DT_TOK_EOF { return (dt_node_root($1)); }
215178479Sjb	|	d_program DT_TOK_EOF { return (dt_node_root($1)); }
216178479Sjb	|	d_type DT_TOK_EOF { return (dt_node_root($1)); }
217178479Sjb	;
218178479Sjb
219178479Sjbd_expression:	DT_CTX_DEXPR { $$ = NULL; }
220178479Sjb	|	DT_CTX_DEXPR expression { $$ = $2; }
221178479Sjb	;
222178479Sjb
223178479Sjbd_program:	DT_CTX_DPROG { $$ = dt_node_program(NULL); }
224178479Sjb	|	DT_CTX_DPROG translation_unit { $$ = dt_node_program($2); }
225178479Sjb	;
226178479Sjb
227178479Sjbd_type:		DT_CTX_DTYPE { $$ = NULL; }
228178479Sjb	|	DT_CTX_DTYPE type_name { $$ = (dt_node_t *)$2; }
229178479Sjb	;
230178479Sjb
231178479Sjbtranslation_unit:
232178479Sjb		external_declaration
233178479Sjb	|	translation_unit external_declaration { $$ = LINK($1, $2); }
234178479Sjb	;
235178479Sjb
236178479Sjbexternal_declaration:
237178479Sjb		inline_definition
238178479Sjb	|	translator_definition
239178479Sjb	|	provider_definition
240178479Sjb	|	probe_definition
241178479Sjb	|	declaration
242178479Sjb	;
243178479Sjb
244178479Sjbinline_definition:
245178479Sjb		DT_KEY_INLINE declaration_specifiers declarator
246178479Sjb		    { dt_scope_push(NULL, CTF_ERR); } DT_TOK_ASGN
247178479Sjb		    assignment_expression ';' {
248178479Sjb			/*
249178479Sjb			 * We push a new declaration scope before shifting the
250178479Sjb			 * assignment_expression in order to preserve ds_class
251178479Sjb			 * and ds_ident for use in dt_node_inline().  Once the
252178479Sjb			 * entire inline_definition rule is matched, pop the
253178479Sjb			 * scope and construct the inline using the saved decl.
254178479Sjb			 */
255178479Sjb			dt_scope_pop();
256178479Sjb			$$ = dt_node_inline($6);
257178479Sjb		}
258178479Sjb	;
259178479Sjb
260178479Sjbtranslator_definition:
261178479Sjb		DT_KEY_XLATOR type_name DT_TOK_LT type_name
262178479Sjb		    DT_TOK_IDENT DT_TOK_GT '{' translator_member_list '}' ';' {
263178479Sjb			$$ = dt_node_xlator($2, $4, $5, $8);
264178479Sjb		}
265178479Sjb	|	DT_KEY_XLATOR type_name DT_TOK_LT type_name
266178479Sjb		    DT_TOK_IDENT DT_TOK_GT '{' '}' ';' {
267178479Sjb			$$ = dt_node_xlator($2, $4, $5, NULL);
268178479Sjb		}
269178479Sjb	;
270178479Sjb
271178479Sjbtranslator_member_list:
272178479Sjb		translator_member
273178479Sjb	|	translator_member_list translator_member { $$ = LINK($1,$2); }
274178479Sjb	;
275178479Sjb
276178479Sjbtranslator_member:
277178479Sjb		DT_TOK_IDENT DT_TOK_ASGN assignment_expression ';' {
278178479Sjb			$$ = dt_node_member(NULL, $1, $3);
279178479Sjb		}
280178479Sjb	;
281178479Sjb
282178479Sjbprovider_definition:
283178479Sjb		DT_KEY_PROVIDER DT_TOK_IDENT '{' provider_probe_list '}' ';' {
284178479Sjb			$$ = dt_node_provider($2, $4);
285178479Sjb		}
286178479Sjb	|	DT_KEY_PROVIDER DT_TOK_IDENT '{' '}' ';' {
287178479Sjb			$$ = dt_node_provider($2, NULL);
288178479Sjb		}
289178479Sjb	;
290178479Sjb
291178479Sjbprovider_probe_list:
292178479Sjb		provider_probe
293178479Sjb	|	provider_probe_list provider_probe { $$ = LINK($1, $2); }
294178479Sjb	;
295178479Sjb
296178479Sjbprovider_probe:
297178479Sjb		DT_KEY_PROBE DT_TOK_IDENT function DT_TOK_COLON function ';' {
298178479Sjb			$$ = dt_node_probe($2, 2, $3, $5);
299178479Sjb		}
300178479Sjb	|	DT_KEY_PROBE DT_TOK_IDENT function ';' {
301178479Sjb			$$ = dt_node_probe($2, 1, $3, NULL);
302178479Sjb		}
303178479Sjb	;
304178479Sjb
305178479Sjb
306178479Sjbprobe_definition:
307178479Sjb		probe_specifiers {
308178479Sjb			/*
309178479Sjb			 * If the input stream is a file, do not permit a probe
310178479Sjb			 * specification without / <pred> / or { <act> } after
311178479Sjb			 * it.  This can only occur if the next token is EOF or
312178479Sjb			 * an ambiguous predicate was slurped up as a comment.
313178479Sjb			 * We cannot perform this check if input() is a string
314178479Sjb			 * because dtrace(1M) [-fmnP] also use the compiler and
315178479Sjb			 * things like dtrace -n BEGIN have to be accepted.
316178479Sjb			 */
317178479Sjb			if (yypcb->pcb_fileptr != NULL) {
318178479Sjb				dnerror($1, D_SYNTAX, "expected predicate and/"
319178479Sjb				    "or actions following probe description\n");
320178479Sjb			}
321178479Sjb			$$ = dt_node_clause($1, NULL, NULL);
322178479Sjb		}
323178479Sjb	|	probe_specifiers '{' statement_list '}' {
324178479Sjb			$$ = dt_node_clause($1, NULL, $3);
325178479Sjb		}
326178479Sjb	|	probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED {
327178479Sjb			dnerror($3, D_SYNTAX, "expected actions { } following "
328178479Sjb			    "probe description and predicate\n");
329178479Sjb		}
330178479Sjb	|	probe_specifiers DT_TOK_DIV expression DT_TOK_EPRED
331178479Sjb		    '{' statement_list '}' {
332178479Sjb			$$ = dt_node_clause($1, $3, $6);
333178479Sjb		}
334178479Sjb	;
335178479Sjb
336178479Sjbprobe_specifiers:
337178479Sjb		probe_specifier_list { yybegin(YYS_EXPR); $$ = $1; }
338178479Sjb	;
339178479Sjb
340178479Sjbprobe_specifier_list:
341178479Sjb		probe_specifier
342178479Sjb	|	probe_specifier_list DT_TOK_COMMA probe_specifier {
343178479Sjb			$$ = LINK($1, $3);
344178479Sjb		}
345178479Sjb	;
346178479Sjb
347178479Sjbprobe_specifier:
348178479Sjb		DT_TOK_PSPEC { $$ = dt_node_pdesc_by_name($1); }
349178479Sjb	|	DT_TOK_INT   { $$ = dt_node_pdesc_by_id($1); }
350178479Sjb	;
351178479Sjb
352178479Sjbstatement_list:	statement { $$ = $1; }
353178479Sjb	|	statement_list ';' statement { $$ = LINK($1, $3); }
354178479Sjb	;
355178479Sjb
356178479Sjbstatement:	/* empty */ { $$ = NULL; }
357178479Sjb	|	expression { $$ = dt_node_statement($1); }
358178479Sjb	;
359178479Sjb
360178479Sjbargument_expression_list:
361178479Sjb		assignment_expression
362178479Sjb	|	argument_expression_list DT_TOK_COMMA assignment_expression {
363178479Sjb			$$ = LINK($1, $3);
364178479Sjb		}
365178479Sjb	;
366178479Sjb
367178479Sjbprimary_expression:
368178479Sjb		DT_TOK_IDENT { $$ = dt_node_ident($1); }
369178479Sjb	|	DT_TOK_AGG { $$ = dt_node_ident($1); }
370178479Sjb	|	DT_TOK_INT { $$ = dt_node_int($1); }
371178479Sjb	|	DT_TOK_STRING { $$ = dt_node_string($1); }
372178479Sjb	|	DT_KEY_SELF { $$ = dt_node_ident(DUP("self")); }
373178479Sjb	|	DT_KEY_THIS { $$ = dt_node_ident(DUP("this")); }
374178479Sjb	|	DT_TOK_LPAR expression DT_TOK_RPAR { $$ = $2; }
375178479Sjb	;
376178479Sjb
377178479Sjbpostfix_expression:
378178479Sjb		primary_expression
379178479Sjb	|	postfix_expression
380178479Sjb		    DT_TOK_LBRAC argument_expression_list DT_TOK_RBRAC {
381178479Sjb			$$ = OP2(DT_TOK_LBRAC, $1, $3);
382178479Sjb		}
383178479Sjb	|	postfix_expression DT_TOK_LPAR DT_TOK_RPAR {
384178479Sjb			$$ = dt_node_func($1, NULL);
385178479Sjb		}
386178479Sjb	|	postfix_expression
387178479Sjb		    DT_TOK_LPAR argument_expression_list DT_TOK_RPAR {
388178479Sjb			$$ = dt_node_func($1, $3);
389178479Sjb		}
390178479Sjb	|	postfix_expression DT_TOK_DOT DT_TOK_IDENT {
391178479Sjb			$$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
392178479Sjb		}
393178479Sjb	|	postfix_expression DT_TOK_DOT DT_TOK_TNAME {
394178479Sjb			$$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
395178479Sjb		}
396276267Smarkj	|	postfix_expression DT_TOK_DOT dtrace_keyword_ident {
397276267Smarkj			$$ = OP2(DT_TOK_DOT, $1, dt_node_ident($3));
398276267Smarkj		}
399178479Sjb	|	postfix_expression DT_TOK_PTR DT_TOK_IDENT {
400178479Sjb			$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
401178479Sjb		}
402178479Sjb	|	postfix_expression DT_TOK_PTR DT_TOK_TNAME {
403178479Sjb			$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
404178479Sjb		}
405276267Smarkj	|	postfix_expression DT_TOK_PTR dtrace_keyword_ident {
406276267Smarkj			$$ = OP2(DT_TOK_PTR, $1, dt_node_ident($3));
407276267Smarkj		}
408178479Sjb	|	postfix_expression DT_TOK_ADDADD {
409178479Sjb			$$ = OP1(DT_TOK_POSTINC, $1);
410178479Sjb		}
411178479Sjb	|	postfix_expression DT_TOK_SUBSUB {
412178479Sjb			$$ = OP1(DT_TOK_POSTDEC, $1);
413178479Sjb		}
414178479Sjb	|	DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
415178479Sjb		    DT_TOK_IDENT DT_TOK_RPAR {
416178479Sjb			$$ = dt_node_offsetof($3, $5);
417178479Sjb		}
418178479Sjb	|	DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
419178479Sjb		    DT_TOK_TNAME DT_TOK_RPAR {
420178479Sjb			$$ = dt_node_offsetof($3, $5);
421178479Sjb		}
422276267Smarkj	|	DT_TOK_OFFSETOF DT_TOK_LPAR type_name DT_TOK_COMMA
423276267Smarkj		    dtrace_keyword_ident DT_TOK_RPAR {
424276267Smarkj			$$ = dt_node_offsetof($3, $5);
425276267Smarkj		}
426178479Sjb	|	DT_TOK_XLATE DT_TOK_LT type_name DT_TOK_GT
427178479Sjb		    DT_TOK_LPAR expression DT_TOK_RPAR {
428178479Sjb			$$ = OP2(DT_TOK_XLATE, dt_node_type($3), $6);
429178479Sjb		}
430178479Sjb	;
431178479Sjb
432178479Sjbunary_expression:
433178479Sjb		postfix_expression
434178479Sjb	|	DT_TOK_ADDADD unary_expression { $$ = OP1(DT_TOK_PREINC, $2); }
435178479Sjb	|	DT_TOK_SUBSUB unary_expression { $$ = OP1(DT_TOK_PREDEC, $2); }
436178479Sjb	|	unary_operator cast_expression { $$ = OP1($1, $2); }
437178479Sjb	|	DT_TOK_SIZEOF unary_expression { $$ = OP1(DT_TOK_SIZEOF, $2); }
438178479Sjb	|	DT_TOK_SIZEOF DT_TOK_LPAR type_name DT_TOK_RPAR {
439178479Sjb			$$ = OP1(DT_TOK_SIZEOF, dt_node_type($3));
440178479Sjb		}
441178479Sjb	|	DT_TOK_STRINGOF unary_expression {
442178479Sjb			$$ = OP1(DT_TOK_STRINGOF, $2);
443178479Sjb		}
444178479Sjb	;
445178479Sjb
446178479Sjbunary_operator:	DT_TOK_BAND { $$ = DT_TOK_ADDROF; }
447178479Sjb	|	DT_TOK_MUL { $$ = DT_TOK_DEREF; }
448178479Sjb	|	DT_TOK_ADD { $$ = DT_TOK_IPOS; }
449178479Sjb	|	DT_TOK_SUB { $$ = DT_TOK_INEG; }
450178479Sjb	|	DT_TOK_BNEG { $$ = DT_TOK_BNEG; }
451178479Sjb	|	DT_TOK_LNEG { $$ = DT_TOK_LNEG; }
452178479Sjb	;
453178479Sjb
454178479Sjbcast_expression:
455178479Sjb		unary_expression
456178479Sjb	|	DT_TOK_LPAR type_name DT_TOK_RPAR cast_expression {
457178479Sjb			$$ = OP2(DT_TOK_LPAR, dt_node_type($2), $4);
458178479Sjb		}
459178479Sjb	;
460178479Sjb
461178479Sjbmultiplicative_expression:
462178479Sjb		cast_expression
463178479Sjb	|	multiplicative_expression DT_TOK_MUL cast_expression {
464178479Sjb			$$ = OP2(DT_TOK_MUL, $1, $3);
465178479Sjb		}
466178479Sjb	|	multiplicative_expression DT_TOK_DIV cast_expression {
467178479Sjb			$$ = OP2(DT_TOK_DIV, $1, $3);
468178479Sjb		}
469178479Sjb	|	multiplicative_expression DT_TOK_MOD cast_expression {
470178479Sjb			$$ = OP2(DT_TOK_MOD, $1, $3);
471178479Sjb		}
472178479Sjb	;
473178479Sjb
474178479Sjbadditive_expression:
475178479Sjb		multiplicative_expression
476178479Sjb	|	additive_expression DT_TOK_ADD multiplicative_expression {
477178479Sjb			$$ = OP2(DT_TOK_ADD, $1, $3);
478178479Sjb		}
479178479Sjb	|	additive_expression DT_TOK_SUB multiplicative_expression {
480178479Sjb			$$ = OP2(DT_TOK_SUB, $1, $3);
481178479Sjb		}
482178479Sjb	;
483178479Sjb
484178479Sjbshift_expression:
485178479Sjb		additive_expression
486178479Sjb	|	shift_expression DT_TOK_LSH additive_expression {
487178479Sjb			$$ = OP2(DT_TOK_LSH, $1, $3);
488178479Sjb		}
489178479Sjb	|	shift_expression DT_TOK_RSH additive_expression {
490178479Sjb			$$ = OP2(DT_TOK_RSH, $1, $3);
491178479Sjb		}
492178479Sjb	;
493178479Sjb
494178479Sjbrelational_expression:
495178479Sjb		shift_expression
496178479Sjb	|	relational_expression DT_TOK_LT shift_expression {
497178479Sjb			$$ = OP2(DT_TOK_LT, $1, $3);
498178479Sjb		}
499178479Sjb	|	relational_expression DT_TOK_GT shift_expression {
500178479Sjb			$$ = OP2(DT_TOK_GT, $1, $3);
501178479Sjb		}
502178479Sjb	|	relational_expression DT_TOK_LE shift_expression {
503178479Sjb			$$ = OP2(DT_TOK_LE, $1, $3);
504178479Sjb		}
505178479Sjb	|	relational_expression DT_TOK_GE shift_expression {
506178479Sjb			$$ = OP2(DT_TOK_GE, $1, $3);
507178479Sjb		}
508178479Sjb	;
509178479Sjb
510178479Sjbequality_expression:
511178479Sjb		relational_expression
512178479Sjb	|	equality_expression DT_TOK_EQU relational_expression {
513178479Sjb			$$ = OP2(DT_TOK_EQU, $1, $3);
514178479Sjb		}
515178479Sjb	|	equality_expression DT_TOK_NEQ relational_expression {
516178479Sjb			$$ = OP2(DT_TOK_NEQ, $1, $3);
517178479Sjb		}
518178479Sjb	;
519178479Sjb
520178479Sjband_expression:
521178479Sjb		equality_expression
522178479Sjb	|	and_expression DT_TOK_BAND equality_expression {
523178479Sjb			$$ = OP2(DT_TOK_BAND, $1, $3);
524178479Sjb		}
525178479Sjb	;
526178479Sjb
527178479Sjbexclusive_or_expression:
528178479Sjb		and_expression
529178479Sjb	|	exclusive_or_expression DT_TOK_XOR and_expression {
530178479Sjb			$$ = OP2(DT_TOK_XOR, $1, $3);
531178479Sjb		}
532178479Sjb	;
533178479Sjb
534178479Sjbinclusive_or_expression:
535178479Sjb		exclusive_or_expression
536178479Sjb	|	inclusive_or_expression DT_TOK_BOR exclusive_or_expression {
537178479Sjb			$$ = OP2(DT_TOK_BOR, $1, $3);
538178479Sjb		}
539178479Sjb	;
540178479Sjb
541178479Sjblogical_and_expression:
542178479Sjb		inclusive_or_expression
543178479Sjb	|	logical_and_expression DT_TOK_LAND inclusive_or_expression {
544178479Sjb			$$ = OP2(DT_TOK_LAND, $1, $3);
545178479Sjb		}
546178479Sjb	;
547178479Sjb
548178479Sjblogical_xor_expression:
549178479Sjb		logical_and_expression
550178479Sjb	|	logical_xor_expression DT_TOK_LXOR logical_and_expression {
551178479Sjb			$$ = OP2(DT_TOK_LXOR, $1, $3);
552178479Sjb		}
553178479Sjb	;
554178479Sjb
555178479Sjblogical_or_expression:
556178479Sjb		logical_xor_expression
557178479Sjb	|	logical_or_expression DT_TOK_LOR logical_xor_expression {
558178479Sjb			$$ = OP2(DT_TOK_LOR, $1, $3);
559178479Sjb		}
560178479Sjb	;
561178479Sjb
562178479Sjbconstant_expression: conditional_expression
563178479Sjb	;
564178479Sjb
565178479Sjbconditional_expression:
566178479Sjb		logical_or_expression
567178479Sjb	|	logical_or_expression DT_TOK_QUESTION expression DT_TOK_COLON
568178479Sjb		    conditional_expression { $$ = OP3($1, $3, $5); }
569178479Sjb	;
570178479Sjb
571178479Sjbassignment_expression:
572178479Sjb		conditional_expression
573178479Sjb	|	unary_expression assignment_operator assignment_expression {
574178479Sjb			$$ = OP2($2, $1, $3);
575178479Sjb		}
576178479Sjb	;
577178479Sjb
578178479Sjbassignment_operator:
579178479Sjb		DT_TOK_ASGN   { $$ = DT_TOK_ASGN; }
580178479Sjb	|	DT_TOK_MUL_EQ { $$ = DT_TOK_MUL_EQ; }
581178479Sjb	|	DT_TOK_DIV_EQ { $$ = DT_TOK_DIV_EQ; }
582178479Sjb	|	DT_TOK_MOD_EQ { $$ = DT_TOK_MOD_EQ; }
583178479Sjb	|	DT_TOK_ADD_EQ { $$ = DT_TOK_ADD_EQ; }
584178479Sjb	|	DT_TOK_SUB_EQ { $$ = DT_TOK_SUB_EQ; }
585178479Sjb	|	DT_TOK_LSH_EQ { $$ = DT_TOK_LSH_EQ; }
586178479Sjb	|	DT_TOK_RSH_EQ { $$ = DT_TOK_RSH_EQ; }
587178479Sjb	|	DT_TOK_AND_EQ { $$ = DT_TOK_AND_EQ; }
588178479Sjb	|	DT_TOK_XOR_EQ { $$ = DT_TOK_XOR_EQ; }
589178479Sjb	|	DT_TOK_OR_EQ  { $$ = DT_TOK_OR_EQ; }
590178479Sjb	;
591178479Sjb
592178479Sjbexpression:	assignment_expression
593178479Sjb	|	expression DT_TOK_COMMA assignment_expression {
594178479Sjb			$$ = OP2(DT_TOK_COMMA, $1, $3);
595178479Sjb		}
596178479Sjb	;
597178479Sjb
598178479Sjbdeclaration:	declaration_specifiers ';' {
599178479Sjb			$$ = dt_node_decl();
600178479Sjb			dt_decl_free(dt_decl_pop());
601178479Sjb			yybegin(YYS_CLAUSE);
602178479Sjb		}
603178479Sjb	|	declaration_specifiers init_declarator_list ';' {
604178479Sjb			$$ = $2;
605178479Sjb			dt_decl_free(dt_decl_pop());
606178479Sjb			yybegin(YYS_CLAUSE);
607178479Sjb		}
608178479Sjb	;
609178479Sjb
610178479Sjbdeclaration_specifiers:
611178479Sjb		d_storage_class_specifier
612178479Sjb	|	d_storage_class_specifier declaration_specifiers
613178479Sjb	|	type_specifier
614178479Sjb	|	type_specifier declaration_specifiers
615178479Sjb	|	type_qualifier
616178479Sjb	|	type_qualifier declaration_specifiers
617178479Sjb	;
618178479Sjb
619178479Sjbparameter_declaration_specifiers:
620178479Sjb		storage_class_specifier
621178479Sjb	|	storage_class_specifier declaration_specifiers
622178479Sjb	|	type_specifier
623178479Sjb	|	type_specifier declaration_specifiers
624178479Sjb	|	type_qualifier
625178479Sjb	|	type_qualifier declaration_specifiers
626178479Sjb	;
627178479Sjb
628178479Sjbstorage_class_specifier:
629178479Sjb		DT_KEY_AUTO { dt_decl_class(DT_DC_AUTO); }
630178479Sjb	|	DT_KEY_REGISTER { dt_decl_class(DT_DC_REGISTER); }
631178479Sjb	|	DT_KEY_STATIC { dt_decl_class(DT_DC_STATIC); }
632178479Sjb	|	DT_KEY_EXTERN { dt_decl_class(DT_DC_EXTERN); }
633178479Sjb	|	DT_KEY_TYPEDEF { dt_decl_class(DT_DC_TYPEDEF); }
634178479Sjb	;
635178479Sjb
636178479Sjbd_storage_class_specifier:
637178479Sjb		storage_class_specifier
638178479Sjb	|	DT_KEY_SELF { dt_decl_class(DT_DC_SELF); }
639178479Sjb	|	DT_KEY_THIS { dt_decl_class(DT_DC_THIS); }
640178479Sjb	;
641178479Sjb
642178479Sjbtype_specifier:	DT_KEY_VOID { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("void")); }
643178479Sjb	|	DT_KEY_CHAR { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("char")); }
644178479Sjb	|	DT_KEY_SHORT { $$ = dt_decl_attr(DT_DA_SHORT); }
645178479Sjb	|	DT_KEY_INT { $$ = dt_decl_spec(CTF_K_INTEGER, DUP("int")); }
646178479Sjb	|	DT_KEY_LONG { $$ = dt_decl_attr(DT_DA_LONG); }
647178479Sjb	|	DT_KEY_FLOAT { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("float")); }
648178479Sjb	|	DT_KEY_DOUBLE { $$ = dt_decl_spec(CTF_K_FLOAT, DUP("double")); }
649178479Sjb	|	DT_KEY_SIGNED { $$ = dt_decl_attr(DT_DA_SIGNED); }
650178479Sjb	|	DT_KEY_UNSIGNED { $$ = dt_decl_attr(DT_DA_UNSIGNED); }
651268578Srpaulo	|	DT_KEY_USERLAND { $$ = dt_decl_attr(DT_DA_USER); }
652178479Sjb	|	DT_KEY_STRING {
653178479Sjb			$$ = dt_decl_spec(CTF_K_TYPEDEF, DUP("string"));
654178479Sjb		}
655178479Sjb	|	DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_TYPEDEF, $1); }
656178479Sjb	|	struct_or_union_specifier
657178479Sjb	|	enum_specifier
658178479Sjb	;
659178479Sjb
660178479Sjbtype_qualifier:	DT_KEY_CONST { $$ = dt_decl_attr(DT_DA_CONST); }
661178479Sjb	|	DT_KEY_RESTRICT { $$ = dt_decl_attr(DT_DA_RESTRICT); }
662178479Sjb	|	DT_KEY_VOLATILE { $$ = dt_decl_attr(DT_DA_VOLATILE); }
663178479Sjb	;
664178479Sjb
665178479Sjbstruct_or_union_specifier:
666178479Sjb		struct_or_union_definition struct_declaration_list '}' {
667178479Sjb			$$ = dt_scope_pop();
668178479Sjb		}
669178479Sjb	|	struct_or_union DT_TOK_IDENT { $$ = dt_decl_spec($1, $2); }
670178479Sjb	|	struct_or_union DT_TOK_TNAME { $$ = dt_decl_spec($1, $2); }
671178479Sjb	;
672178479Sjb
673178479Sjbstruct_or_union_definition:
674178479Sjb		struct_or_union '{' { dt_decl_sou($1, NULL); }
675178479Sjb	|	struct_or_union DT_TOK_IDENT '{' { dt_decl_sou($1, $2); }
676178479Sjb	|	struct_or_union DT_TOK_TNAME '{' { dt_decl_sou($1, $2); }
677178479Sjb	;
678178479Sjb
679178479Sjbstruct_or_union:
680178479Sjb		DT_KEY_STRUCT { $$ = CTF_K_STRUCT; }
681178479Sjb	|	DT_KEY_UNION { $$ = CTF_K_UNION; }
682178479Sjb	;
683178479Sjb
684178479Sjbstruct_declaration_list:
685178479Sjb		struct_declaration
686178479Sjb	|	struct_declaration_list struct_declaration
687178479Sjb	;
688178479Sjb
689178479Sjbinit_declarator_list:
690178479Sjb		init_declarator
691178479Sjb	|	init_declarator_list DT_TOK_COMMA init_declarator {
692178479Sjb			$$ = LINK($1, $3);
693178479Sjb		}
694178479Sjb	;
695178479Sjb
696178479Sjbinit_declarator:
697178479Sjb		declarator {
698178479Sjb			$$ = dt_node_decl();
699178479Sjb			dt_decl_reset();
700178479Sjb		}
701178479Sjb	;
702178479Sjb
703178479Sjbstruct_declaration:
704178479Sjb		specifier_qualifier_list struct_declarator_list ';' {
705178479Sjb			dt_decl_free(dt_decl_pop());
706178479Sjb		}
707178479Sjb	;
708178479Sjb
709178479Sjbspecifier_qualifier_list:
710178479Sjb		type_specifier
711178479Sjb	|	type_specifier specifier_qualifier_list { $$ = $2; }
712178479Sjb	|	type_qualifier
713178479Sjb	|	type_qualifier specifier_qualifier_list { $$ = $2; }
714178479Sjb	;
715178479Sjb
716178479Sjbstruct_declarator_list:
717178479Sjb		struct_declarator
718178479Sjb	|	struct_declarator_list DT_TOK_COMMA struct_declarator
719178479Sjb	;
720178479Sjb
721178479Sjbstruct_declarator:
722178479Sjb		declarator { dt_decl_member(NULL); }
723178479Sjb	|	DT_TOK_COLON constant_expression { dt_decl_member($2); }
724178479Sjb	|	declarator DT_TOK_COLON constant_expression {
725178479Sjb			dt_decl_member($3);
726178479Sjb		}
727178479Sjb	;
728178479Sjb
729178479Sjbenum_specifier:
730178479Sjb		enum_definition enumerator_list '}' { $$ = dt_scope_pop(); }
731178479Sjb	|	DT_KEY_ENUM DT_TOK_IDENT { $$ = dt_decl_spec(CTF_K_ENUM, $2); }
732178479Sjb	|	DT_KEY_ENUM DT_TOK_TNAME { $$ = dt_decl_spec(CTF_K_ENUM, $2); }
733178479Sjb	;
734178479Sjb
735178479Sjbenum_definition:
736178479Sjb		DT_KEY_ENUM '{' { dt_decl_enum(NULL); }
737178479Sjb	|	DT_KEY_ENUM DT_TOK_IDENT '{' { dt_decl_enum($2); }
738178479Sjb	|	DT_KEY_ENUM DT_TOK_TNAME '{' { dt_decl_enum($2); }
739178479Sjb	;
740178479Sjb
741178479Sjbenumerator_list:
742178479Sjb		enumerator
743178479Sjb	|	enumerator_list DT_TOK_COMMA enumerator
744178479Sjb	;
745178479Sjb
746178479Sjbenumerator:	DT_TOK_IDENT { dt_decl_enumerator($1, NULL); }
747178479Sjb	|	DT_TOK_IDENT DT_TOK_ASGN expression {
748178479Sjb			dt_decl_enumerator($1, $3);
749178479Sjb		}
750178479Sjb	;
751178479Sjb
752178479Sjbdeclarator:	direct_declarator
753178479Sjb	|	pointer direct_declarator
754178479Sjb	;
755178479Sjb
756178479Sjbdirect_declarator:
757178479Sjb		DT_TOK_IDENT { $$ = dt_decl_ident($1); }
758178479Sjb	|	lparen declarator DT_TOK_RPAR { $$ = $2; }
759178479Sjb	|	direct_declarator array { dt_decl_array($2); }
760178479Sjb	|	direct_declarator function { dt_decl_func($1, $2); }
761178479Sjb	;
762178479Sjb
763178479Sjblparen:		DT_TOK_LPAR { dt_decl_top()->dd_attr |= DT_DA_PAREN; }
764178479Sjb	;
765178479Sjb
766178479Sjbpointer:	DT_TOK_MUL { $$ = dt_decl_ptr(); }
767178479Sjb	|	DT_TOK_MUL type_qualifier_list { $$ = dt_decl_ptr(); }
768178479Sjb	|	DT_TOK_MUL pointer { $$ = dt_decl_ptr(); }
769178479Sjb	|	DT_TOK_MUL type_qualifier_list pointer { $$ = dt_decl_ptr(); }
770178479Sjb	;
771178479Sjb
772178479Sjbtype_qualifier_list:
773178479Sjb		type_qualifier
774178479Sjb	|	type_qualifier_list type_qualifier { $$ = $2; }
775178479Sjb	;
776178479Sjb
777178479Sjbparameter_type_list:
778178479Sjb		parameter_list
779178479Sjb	|	DT_TOK_ELLIPSIS { $$ = dt_node_vatype(); }
780178479Sjb	|	parameter_list DT_TOK_COMMA DT_TOK_ELLIPSIS {
781178479Sjb			$$ = LINK($1, dt_node_vatype());
782178479Sjb		}
783178479Sjb	;
784178479Sjb
785178479Sjbparameter_list:	parameter_declaration
786178479Sjb	|	parameter_list DT_TOK_COMMA parameter_declaration {
787178479Sjb			$$ = LINK($1, $3);
788178479Sjb		}
789178479Sjb	;
790178479Sjb
791178479Sjbparameter_declaration:
792178479Sjb		parameter_declaration_specifiers {
793178479Sjb			$$ = dt_node_type(NULL);
794178479Sjb		}
795178479Sjb	|	parameter_declaration_specifiers declarator {
796178479Sjb			$$ = dt_node_type(NULL);
797178479Sjb		}
798178479Sjb	|	parameter_declaration_specifiers abstract_declarator {
799178479Sjb			$$ = dt_node_type(NULL);
800178479Sjb		}
801178479Sjb	;
802178479Sjb
803178479Sjbtype_name:	specifier_qualifier_list {
804178479Sjb			$$ = dt_decl_pop();
805178479Sjb		}
806178479Sjb	|	specifier_qualifier_list abstract_declarator {
807178479Sjb			$$ = dt_decl_pop();
808178479Sjb		}
809178479Sjb	;
810178479Sjb
811178479Sjbabstract_declarator:
812178479Sjb		pointer
813178479Sjb	|	direct_abstract_declarator
814178479Sjb	|	pointer direct_abstract_declarator
815178479Sjb	;
816178479Sjb
817178479Sjbdirect_abstract_declarator:
818178479Sjb		lparen abstract_declarator DT_TOK_RPAR { $$ = $2; }
819178479Sjb	|	direct_abstract_declarator array { dt_decl_array($2); }
820178479Sjb	|	array { dt_decl_array($1); $$ = NULL; }
821178479Sjb	|	direct_abstract_declarator function { dt_decl_func($1, $2); }
822178479Sjb	|	function { dt_decl_func(NULL, $1); }
823178479Sjb	;
824178479Sjb
825178479Sjbarray:		DT_TOK_LBRAC { dt_scope_push(NULL, CTF_ERR); }
826178479Sjb		    array_parameters DT_TOK_RBRAC {
827178479Sjb			dt_scope_pop();
828178479Sjb			$$ = $3;
829178479Sjb		}
830178479Sjb	;
831178479Sjb
832178479Sjbarray_parameters:
833178479Sjb		/* empty */ 		{ $$ = NULL; }
834178479Sjb	|	constant_expression	{ $$ = $1; }
835178479Sjb	|	parameter_type_list	{ $$ = $1; }
836178479Sjb	;
837178479Sjb
838178479Sjbfunction:	DT_TOK_LPAR { dt_scope_push(NULL, CTF_ERR); }
839178479Sjb		    function_parameters DT_TOK_RPAR {
840178479Sjb			dt_scope_pop();
841178479Sjb			$$ = $3;
842178479Sjb		}
843178479Sjb	;
844178479Sjb
845178479Sjbfunction_parameters:
846178479Sjb		/* empty */ 		{ $$ = NULL; }
847178479Sjb	|	parameter_type_list	{ $$ = $1; }
848178479Sjb	;
849178479Sjb
850276267Smarkjdtrace_keyword_ident:
851276267Smarkj	  DT_KEY_PROBE { $$ = DUP("probe"); }
852276267Smarkj	| DT_KEY_PROVIDER { $$ = DUP("provider"); }
853276267Smarkj	| DT_KEY_SELF { $$ = DUP("self"); }
854276267Smarkj	| DT_KEY_STRING { $$ = DUP("string"); }
855276267Smarkj	| DT_TOK_STRINGOF { $$ = DUP("stringof"); }
856276267Smarkj	| DT_KEY_USERLAND { $$ = DUP("userland"); }
857276267Smarkj	| DT_TOK_XLATE { $$ = DUP("xlate"); }
858276267Smarkj	| DT_KEY_XLATOR { $$ = DUP("translator"); }
859276267Smarkj	;
860276267Smarkj
861178479Sjb%%
862