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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Routines used to traverse tdesc trees, invoking user-supplied callbacks
30 * as the tree is traversed.
40 int (*tddescenders
[])();
43 int tdtraverse(tdesc_t
*, tdesc_t
**, tdtrav_data_t
*);
46 tdtrav_init(tdtrav_data_t
*tdtd
, int *vgenp
, tdtrav_cb_f
*firstops
,
47 tdtrav_cb_f
*preops
, tdtrav_cb_f
*postops
, void *private)
49 tdtd
->vgen
= ++(*vgenp
);
50 tdtd
->firstops
= firstops
? firstops
: tdnops
;
51 tdtd
->preops
= preops
? preops
: tdnops
;
52 tdtd
->postops
= postops
? postops
: tdnops
;
53 tdtd
->private = private;
57 tdtrav_plain(tdesc_t
*this, tdtrav_data_t
*tdtd
)
59 return (tdtraverse(this->t_tdesc
, &this->t_tdesc
, tdtd
));
63 tdtrav_func(tdesc_t
*this, tdtrav_data_t
*tdtd
)
65 fndef_t
*fn
= this->t_fndef
;
68 if ((rc
= tdtraverse(fn
->fn_ret
, &fn
->fn_ret
, tdtd
)) < 0)
71 for (i
= 0; i
< fn
->fn_nargs
; i
++) {
72 if ((rc
= tdtraverse(fn
->fn_args
[i
], &fn
->fn_args
[i
],
81 tdtrav_array(tdesc_t
*this, tdtrav_data_t
*tdtd
)
83 ardef_t
*ardef
= this->t_ardef
;
86 if ((rc
= tdtraverse(ardef
->ad_contents
, &ardef
->ad_contents
,
90 return (tdtraverse(ardef
->ad_idxtype
, &ardef
->ad_idxtype
, tdtd
));
94 tdtrav_su(tdesc_t
*this, tdtrav_data_t
*tdtd
)
99 for (ml
= this->t_members
; ml
; ml
= ml
->ml_next
) {
100 if ((rc
= tdtraverse(ml
->ml_type
, &ml
->ml_type
, tdtd
)) < 0)
109 tdtrav_assert(tdesc_t
*node
, tdesc_t
**nodep
, void *private)
116 tdtrav_cb_f tdnops
[] = {
118 NULL
, /* intrinsic */
127 NULL
, /* typedef_unres */
133 int (*tddescenders
[])(tdesc_t
*, tdtrav_data_t
*) = {
135 NULL
, /* intrinsic */
136 tdtrav_plain
, /* pointer */
137 tdtrav_array
, /* array */
138 tdtrav_func
, /* function */
139 tdtrav_su
, /* struct */
140 tdtrav_su
, /* union */
143 tdtrav_plain
, /* typedef */
144 NULL
, /* typedef_unres */
145 tdtrav_plain
, /* volatile */
146 tdtrav_plain
, /* const */
147 tdtrav_plain
/* restrict */
151 tdtraverse(tdesc_t
*this, tdesc_t
**thisp
, tdtrav_data_t
*tdtd
)
158 if ((travcb
= tdtd
->firstops
[this->t_type
]) != NULL
) {
159 if ((rc
= travcb(this, thisp
, tdtd
->private)) < 0)
165 if (this->t_vgen
== tdtd
->vgen
)
167 this->t_vgen
= tdtd
->vgen
;
169 if (descend
&& (travcb
= tdtd
->preops
[this->t_type
]) != NULL
) {
170 if ((rc
= travcb(this, thisp
, tdtd
->private)) < 0)
177 if ((descender
= tddescenders
[this->t_type
]) != NULL
&&
178 (rc
= descender(this, tdtd
)) < 0)
181 if ((travcb
= tdtd
->postops
[this->t_type
]) != NULL
&&
182 (rc
= travcb(this, thisp
, tdtd
->private)) < 0)
190 iitraverse_td(iidesc_t
*ii
, tdtrav_data_t
*tdtd
)
194 if ((rc
= tdtraverse(ii
->ii_dtype
, &ii
->ii_dtype
, tdtd
)) < 0)
197 for (i
= 0; i
< ii
->ii_nargs
; i
++) {
198 if ((rc
= tdtraverse(ii
->ii_args
[i
], &ii
->ii_args
[i
],
207 iitraverse(iidesc_t
*ii
, int *vgenp
, tdtrav_cb_f
*firstops
, tdtrav_cb_f
*preops
,
208 tdtrav_cb_f
*postops
, void *private)
212 tdtrav_init(&tdtd
, vgenp
, firstops
, preops
, postops
, private);
214 return (iitraverse_td(ii
, &tdtd
));
218 iitraverse_hash(hash_t
*iihash
, int *vgenp
, tdtrav_cb_f
*firstops
,
219 tdtrav_cb_f
*preops
, tdtrav_cb_f
*postops
, void *private)
223 tdtrav_init(&tdtd
, vgenp
, firstops
, preops
, postops
, private);
225 return (hash_iter(iihash
, (int (*)())iitraverse_td
, &tdtd
));