1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
%{
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2020 Tintri by DDN, Inc. All rights reserved.
*/
#include "ndrgen.h"
typedef struct node *node_ptr;
#define YYSTYPE node_ptr
%}
/* keywords */
%token STRUCT_KW UNION_KW TYPEDEF_KW
/* advice keywords */
%token ALIGN_KW OPERATION_KW IN_KW OUT_KW
%token INTERFACE_KW UUID_KW _NO_REORDER_KW EXTERN_KW
%token SIZE_IS_KW LENGTH_IS_KW STRING_KW REFERENCE_KW
%token CASE_KW DEFAULT_KW SWITCH_IS_KW
%token TRANSMIT_AS_KW ARG_IS_KW FAKE_KW
/* composite keywords */
%token BASIC_TYPE TYPENAME
/* symbols and punctuation */
%token IDENTIFIER INTEGER STRING
%token LC RC SEMI STAR DIV MOD PLUS MINUS AND OR XOR LB RB LP RP
%token L_MEMBER
%%
defn : /* empty */
| construct_list ={ construct_list = (struct node *)$1; }
;
construct_list: construct
| construct_list construct ={ n_splice ($1,$2); }
;
construct: struct
| union
| typedef
;
struct : advice STRUCT_KW typename LC members RC SEMI
={ $$ = n_cons (STRUCT_KW, $1, $3, $5);
construct_fixup ($$);
}
;
union : advice UNION_KW typename LC members RC SEMI
={ $$ = n_cons (UNION_KW, $1, $3, $5);
construct_fixup ($$);
}
;
typedef : TYPEDEF_KW member
={ $$ = n_cons (TYPEDEF_KW, 0, $2->n_m_name, $2);
construct_fixup ($$);
}
;
members : member
| members member ={ n_splice ($1,$2); }
;
member : advice type declarator SEMI
={ $$ = n_cons (L_MEMBER, $1, $2, $3);
member_fixup ($$);
}
;
advice : /* empty */ ={ $$ = 0; }
| adv_list
;
adv_list: LB adv_attrs RB ={ $$ = $2; }
| adv_list LB adv_attrs RB ={ n_splice ($1,$3); }
;
adv_attrs: adv_attr
| adv_attr adv_attr ={ n_splice ($1,$2); }
;
adv_attr: IN_KW ={ $$ = n_cons (IN_KW); }
| OUT_KW ={ $$ = n_cons (OUT_KW); }
| OPERATION_KW LP arg RP ={ $$ = n_cons (OPERATION_KW, $3); }
| ALIGN_KW LP arg RP ={ $$ = n_cons (ALIGN_KW, $3); }
| STRING_KW ={ $$ = n_cons (STRING_KW); }
| FAKE_KW ={ $$ = n_cons (FAKE_KW); }
| SIZE_IS_KW LP arg RP
={ $$ = n_cons (SIZE_IS_KW, $3, $3, $3); }
| SIZE_IS_KW LP arg operator INTEGER RP
={ $$ = n_cons (SIZE_IS_KW, $3, $4, $5); }
| LENGTH_IS_KW LP arg RP
={ $$ = n_cons (LENGTH_IS_KW, $3, $3, $3); }
| LENGTH_IS_KW LP arg operator INTEGER RP
={ $$ = n_cons (LENGTH_IS_KW, $3, $4, $5); }
| SWITCH_IS_KW LP arg RP
={ $$ = n_cons (SWITCH_IS_KW, $3, $3, $3); }
| SWITCH_IS_KW LP arg operator INTEGER RP
={ $$ = n_cons (SWITCH_IS_KW, $3, $4, $5); }
| CASE_KW LP arg RP ={ $$ = n_cons (CASE_KW, $3); }
| DEFAULT_KW ={ $$ = n_cons (DEFAULT_KW); }
| ARG_IS_KW LP arg RP ={ $$ = n_cons (ARG_IS_KW, $3); }
| TRANSMIT_AS_KW LP BASIC_TYPE RP
={ $$ = n_cons (TRANSMIT_AS_KW, $3); }
| INTERFACE_KW LP arg RP ={ $$ = n_cons (INTERFACE_KW, $3); }
| UUID_KW LP arg RP ={ $$ = n_cons (UUID_KW, $3); }
| _NO_REORDER_KW ={ $$ = n_cons (_NO_REORDER_KW); }
| EXTERN_KW ={ $$ = n_cons (EXTERN_KW); }
| REFERENCE_KW ={ $$ = n_cons (REFERENCE_KW); }
;
arg : IDENTIFIER
| INTEGER
| STRING
;
type : BASIC_TYPE
| typename
| STRUCT_KW typename ={ $$ = $2; }
| UNION_KW typename ={ $$ = $2; }
;
typename: TYPENAME
| IDENTIFIER
;
operator: STAR
| DIV
| MOD
| PLUS
| MINUS
| AND
| OR
| XOR
;
declarator: decl1
;
decl1 : decl2
| STAR decl1 ={ $$ = n_cons (STAR, $2); }
;
decl2 : decl3
| decl3 LB RB ={ $$ = n_cons (LB, $1, 0); }
| decl3 LB STAR RB ={ $$ = n_cons (LB, $1, 0); }
| decl3 LB INTEGER RB ={ $$ = n_cons (LB, $1, $3); }
;
decl3 : IDENTIFIER
| LP decl1 RP ={ $$ = n_cons (LP, $2); }
;
%%
|