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[])(tdesc_t *, tdtrav_data_t *);
44 tdtrav_init(tdtrav_data_t *tdtd, int *vgenp, tdtrav_cb_f *firstops,
45 tdtrav_cb_f *preops, tdtrav_cb_f *postops, void *private)
47 tdtd->vgen = ++(*vgenp);
48 tdtd->firstops = firstops ? firstops : tdnops;
49 tdtd->preops = preops ? preops : tdnops;
50 tdtd->postops = postops ? postops : tdnops;
51 tdtd->private = private;
55 tdtrav_plain(tdesc_t *this, tdtrav_data_t *tdtd)
57 return (tdtraverse(this->t_tdesc, &this->t_tdesc, tdtd));
61 tdtrav_func(tdesc_t *this, tdtrav_data_t *tdtd)
63 fndef_t *fn = this->t_fndef;
66 if ((rc = tdtraverse(fn->fn_ret, &fn->fn_ret, tdtd)) < 0)
69 for (i = 0; i < (int) fn->fn_nargs; i++) {
70 if ((rc = tdtraverse(fn->fn_args[i], &fn->fn_args[i],
79 tdtrav_array(tdesc_t *this, tdtrav_data_t *tdtd)
81 ardef_t *ardef = this->t_ardef;
84 if ((rc = tdtraverse(ardef->ad_contents, &ardef->ad_contents,
88 return (tdtraverse(ardef->ad_idxtype, &ardef->ad_idxtype, tdtd));
92 tdtrav_su(tdesc_t *this, tdtrav_data_t *tdtd)
97 for (ml = this->t_members; ml; ml = ml->ml_next) {
98 if ((rc = tdtraverse(ml->ml_type, &ml->ml_type, tdtd)) < 0)
107 tdtrav_assert(tdesc_t *node __unused, tdesc_t **nodep __unused, void *private __unused)
114 tdtrav_cb_f tdnops[] = {
116 NULL, /* intrinsic */
125 NULL, /* typedef_unres */
131 int (*tddescenders[])(tdesc_t *, tdtrav_data_t *) = {
133 NULL, /* intrinsic */
134 tdtrav_plain, /* pointer */
135 tdtrav_array, /* array */
136 tdtrav_func, /* function */
137 tdtrav_su, /* struct */
138 tdtrav_su, /* union */
141 tdtrav_plain, /* typedef */
142 NULL, /* typedef_unres */
143 tdtrav_plain, /* volatile */
144 tdtrav_plain, /* const */
145 tdtrav_plain /* restrict */
149 tdtraverse(tdesc_t *this, tdesc_t **thisp, tdtrav_data_t *tdtd)
152 int (*descender)(tdesc_t *, tdtrav_data_t *);
156 if ((travcb = tdtd->firstops[this->t_type]) != NULL) {
157 if ((rc = travcb(this, thisp, tdtd->private)) < 0)
163 if (this->t_vgen == tdtd->vgen)
165 this->t_vgen = tdtd->vgen;
167 if (descend && (travcb = tdtd->preops[this->t_type]) != NULL) {
168 if ((rc = travcb(this, thisp, tdtd->private)) < 0)
175 if ((descender = tddescenders[this->t_type]) != NULL &&
176 (rc = descender(this, tdtd)) < 0)
179 if ((travcb = tdtd->postops[this->t_type]) != NULL &&
180 (rc = travcb(this, thisp, tdtd->private)) < 0)
188 iitraverse_td(void *arg1, void *arg2)
191 tdtrav_data_t *tdtd = arg2;
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, iitraverse_td, &tdtd));