4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
31 static void print_declaration(ndr_node_t
*);
32 static void print_advice_list(ndr_node_t
*);
33 static void print_node_list(ndr_node_t
*);
39 print_node_list(construct_list
);
43 print_node(ndr_node_t
*np
)
48 (void) printf("<null>");
53 case ALIGN_KW
: nm
= "align"; break;
54 case STRUCT_KW
: nm
= "struct"; break;
55 case UNION_KW
: nm
= "union"; break;
56 case TYPEDEF_KW
: nm
= "typedef"; break;
57 case INTERFACE_KW
: nm
= "interface"; break;
58 case IN_KW
: nm
= "in"; break;
59 case OUT_KW
: nm
= "out"; break;
60 case SIZE_IS_KW
: nm
= "size_is"; break;
61 case LENGTH_IS_KW
: nm
= "length_is"; break;
62 case STRING_KW
: nm
= "string"; break;
63 case TRANSMIT_AS_KW
: nm
= "transmit_as"; break;
64 case OPERATION_KW
: nm
= "operation"; break;
65 case UUID_KW
: nm
= "uuid"; break;
66 case _NO_REORDER_KW
: nm
= "_no_reorder"; break;
67 case EXTERN_KW
: nm
= "extern"; break;
68 case ARG_IS_KW
: nm
= "arg_is"; break;
69 case CASE_KW
: nm
= "case"; break;
70 case DEFAULT_KW
: nm
= "default"; break;
71 case BASIC_TYPE
: nm
= "<btype>"; break;
72 case TYPENAME
: nm
= "<tname>"; break;
73 case IDENTIFIER
: nm
= "<ident>"; break;
74 case INTEGER
: nm
= "<intg>"; break;
75 case STRING
: nm
= "<string>"; break;
76 case STAR
: nm
= "<*>"; break;
77 case LB
: nm
= "<[>"; break;
78 case LP
: nm
= "<(>"; break;
79 case L_MEMBER
: nm
= "<member>"; break;
81 (void) printf("<<lab=%d>>", np
->label
);
91 print_advice_list(np
->n_c_advice
);
94 (void) printf("%s ", nm
);
95 print_node(np
->n_c_typename
);
96 (void) printf(" {\n");
97 print_node_list(np
->n_c_members
);
98 (void) printf("};\n");
107 (void) printf("%s", nm
);
112 * Don't output anything for default alignment.
114 if ((np
->n_a_arg
== NULL
) || (np
->n_a_arg
->n_int
== 0))
116 (void) printf("%s(", nm
);
117 print_node(np
->n_a_arg
);
123 (void) printf("%s(", nm
);
124 print_field_attr(np
);
134 (void) printf("%s(", nm
);
135 print_node(np
->n_a_arg
);
142 (void) printf("%s", np
->n_sym
->name
);
146 (void) printf("%ld", np
->n_int
);
150 (void) printf("\"%s\"", np
->n_str
);
155 print_node(np
->n_d_descend
);
159 print_node(np
->n_d_descend
);
162 print_node(np
->n_d_dim
);
168 print_node(np
->n_d_descend
);
173 if (np
->n_m_advice
) {
175 print_advice_list(np
->n_m_advice
);
179 print_declaration(np
);
180 (void) printf(";\n");
189 * Field attributes are used to specify the size of an array, or the portion
190 * of the array, that contains valid data, which is done by associating
191 * another parameter with the array that contains the sizing information.
193 * Supports formats such as size_is(x) or size_is(x / 2). The supported
199 print_field_attr(ndr_node_t
*np
)
201 static char *valid
= "*/%+-&|^";
208 if (arg
->label
!= IDENTIFIER
)
209 fatal_error("invalid label %d", arg
->label
);
210 if ((name
= arg
->n_sym
->name
) == NULL
)
211 fatal_error("missing symbol name");
215 if (arg
->label
== IDENTIFIER
) {
216 operator = arg
->n_sym
->name
;
218 if (operator != NULL
) {
220 * The lexer sets the name and operator to
221 * the same value if there is no operator.
223 if (strcmp(name
, operator) == 0)
225 else if (strchr(valid
, *operator) == NULL
)
226 compile_error("invalid operator: %s", operator);
231 if (arg
->label
== INTEGER
) {
234 if ((value
== 0) && strcmp(operator, "/") == 0)
235 compile_error("divide by zero");
239 (void) printf("%s %s %ldUL", name
, operator, value
);
241 (void) printf("%s", name
);
245 print_declaration(ndr_node_t
*np
)
247 ndr_node_t
*dnp
= np
->n_m_decl
;
252 (np
->n_m_type
->label
== IDENTIFIER
||
253 np
->n_m_type
->label
== TYPENAME
)) {
254 (void) snprintf(buf
, NDLBUFSZ
, "%s", np
->n_m_type
->n_sym
->name
);
259 if (dnp
&& dnp
->label
== STAR
) {
261 while (dnp
&& dnp
->label
== STAR
) {
263 dnp
= dnp
->n_d_descend
;
267 (void) printf("%-23s ", buf
);
269 print_node(np
->n_m_type
);
277 print_advice_list(ndr_node_t
*np
)
283 for (; np
; np
= np
->n_next
) {
292 print_node_list(ndr_node_t
*np
)
294 for (; np
; np
= np
->n_next
) {