xref: /titanic_51/usr/src/cmd/fm/eversholt/common/tree.c (revision b7d3956b92a285d8dac2c7f5f7e28d2ef5347ef8)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
58a40a695Sgavinm  * Common Development and Distribution License (the "License").
68a40a695Sgavinm  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2227134bdaSstephh  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  *
257c478bd9Sstevel@tonic-gate  * tree.c -- routines for manipulating the prop tree
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  * the actions in escparse.y call these routines to construct
287c478bd9Sstevel@tonic-gate  * the parse tree.  these routines, in turn, call the check_X()
297c478bd9Sstevel@tonic-gate  * routines for semantic checking.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <ctype.h>
377c478bd9Sstevel@tonic-gate #include <strings.h>
387c478bd9Sstevel@tonic-gate #include <alloca.h>
397c478bd9Sstevel@tonic-gate #include "alloc.h"
407c478bd9Sstevel@tonic-gate #include "out.h"
417c478bd9Sstevel@tonic-gate #include "stats.h"
427c478bd9Sstevel@tonic-gate #include "stable.h"
437c478bd9Sstevel@tonic-gate #include "literals.h"
447c478bd9Sstevel@tonic-gate #include "lut.h"
457c478bd9Sstevel@tonic-gate #include "esclex.h"
467c478bd9Sstevel@tonic-gate #include "tree.h"
477c478bd9Sstevel@tonic-gate #include "check.h"
487c478bd9Sstevel@tonic-gate #include "ptree.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static struct node *Root;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static char *Newname;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate static struct stats *Faultcount;
557c478bd9Sstevel@tonic-gate static struct stats *Upsetcount;
567c478bd9Sstevel@tonic-gate static struct stats *Defectcount;
577c478bd9Sstevel@tonic-gate static struct stats *Errorcount;
587c478bd9Sstevel@tonic-gate static struct stats *Ereportcount;
597c478bd9Sstevel@tonic-gate static struct stats *SERDcount;
607aec1d6eScindi static struct stats *STATcount;
617c478bd9Sstevel@tonic-gate static struct stats *ASRUcount;
627c478bd9Sstevel@tonic-gate static struct stats *FRUcount;
637c478bd9Sstevel@tonic-gate static struct stats *Configcount;
647c478bd9Sstevel@tonic-gate static struct stats *Propcount;
657c478bd9Sstevel@tonic-gate static struct stats *Maskcount;
667c478bd9Sstevel@tonic-gate static struct stats *Nodecount;
677c478bd9Sstevel@tonic-gate static struct stats *Namecount;
687c478bd9Sstevel@tonic-gate static struct stats *Nodesize;
697c478bd9Sstevel@tonic-gate 
70b5016cbbSstephh struct lut *Usedprops;
71b5016cbbSstephh 
727c478bd9Sstevel@tonic-gate void
737c478bd9Sstevel@tonic-gate tree_init(void)
747c478bd9Sstevel@tonic-gate {
757c478bd9Sstevel@tonic-gate 	Faultcount = stats_new_counter("parser.fault", "fault decls", 1);
767c478bd9Sstevel@tonic-gate 	Upsetcount = stats_new_counter("parser.upset", "upset decls", 1);
777c478bd9Sstevel@tonic-gate 	Defectcount = stats_new_counter("parser.defect", "defect decls", 1);
787c478bd9Sstevel@tonic-gate 	Errorcount = stats_new_counter("parser.error", "error decls", 1);
797c478bd9Sstevel@tonic-gate 	Ereportcount = stats_new_counter("parser.ereport", "ereport decls", 1);
807c478bd9Sstevel@tonic-gate 	SERDcount = stats_new_counter("parser.SERD", "SERD engine decls", 1);
817aec1d6eScindi 	STATcount = stats_new_counter("parser.STAT", "STAT engine decls", 1);
827c478bd9Sstevel@tonic-gate 	ASRUcount = stats_new_counter("parser.ASRU", "ASRU decls", 1);
837c478bd9Sstevel@tonic-gate 	FRUcount = stats_new_counter("parser.FRU", "FRU decls", 1);
847c478bd9Sstevel@tonic-gate 	Configcount = stats_new_counter("parser.config", "config stmts", 1);
857c478bd9Sstevel@tonic-gate 	Propcount = stats_new_counter("parser.prop", "prop stmts", 1);
867c478bd9Sstevel@tonic-gate 	Maskcount = stats_new_counter("parser.mask", "mask stmts", 1);
877c478bd9Sstevel@tonic-gate 	Nodecount = stats_new_counter("parser.node", "nodes created", 1);
887c478bd9Sstevel@tonic-gate 	Namecount = stats_new_counter("parser.name", "names created", 1);
897c478bd9Sstevel@tonic-gate 	Nodesize =
907c478bd9Sstevel@tonic-gate 	    stats_new_counter("parser.nodesize", "sizeof(struct node)", 1);
917c478bd9Sstevel@tonic-gate 	stats_counter_add(Nodesize, sizeof (struct node));
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate void
957c478bd9Sstevel@tonic-gate tree_fini(void)
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate 	stats_delete(Faultcount);
987c478bd9Sstevel@tonic-gate 	stats_delete(Upsetcount);
997c478bd9Sstevel@tonic-gate 	stats_delete(Defectcount);
1007c478bd9Sstevel@tonic-gate 	stats_delete(Errorcount);
1017c478bd9Sstevel@tonic-gate 	stats_delete(Ereportcount);
1027c478bd9Sstevel@tonic-gate 	stats_delete(SERDcount);
1037aec1d6eScindi 	stats_delete(STATcount);
1047c478bd9Sstevel@tonic-gate 	stats_delete(ASRUcount);
1057c478bd9Sstevel@tonic-gate 	stats_delete(FRUcount);
1067c478bd9Sstevel@tonic-gate 	stats_delete(Configcount);
1077c478bd9Sstevel@tonic-gate 	stats_delete(Propcount);
1087c478bd9Sstevel@tonic-gate 	stats_delete(Maskcount);
1097c478bd9Sstevel@tonic-gate 	stats_delete(Nodecount);
1107c478bd9Sstevel@tonic-gate 	stats_delete(Namecount);
1117c478bd9Sstevel@tonic-gate 	stats_delete(Nodesize);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	/* free entire parse tree */
1147c478bd9Sstevel@tonic-gate 	tree_free(Root);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	/* free up the luts we keep for decls */
1177c478bd9Sstevel@tonic-gate 	lut_free(Faults, NULL, NULL);
1187c478bd9Sstevel@tonic-gate 	Faults = NULL;
1197c478bd9Sstevel@tonic-gate 	lut_free(Upsets, NULL, NULL);
1207c478bd9Sstevel@tonic-gate 	Upsets = NULL;
1217c478bd9Sstevel@tonic-gate 	lut_free(Defects, NULL, NULL);
1227c478bd9Sstevel@tonic-gate 	Defects = NULL;
1237c478bd9Sstevel@tonic-gate 	lut_free(Errors, NULL, NULL);
1247c478bd9Sstevel@tonic-gate 	Errors = NULL;
1257c478bd9Sstevel@tonic-gate 	lut_free(Ereports, NULL, NULL);
1267c478bd9Sstevel@tonic-gate 	Ereports = NULL;
1277c478bd9Sstevel@tonic-gate 	lut_free(Ereportenames, NULL, NULL);
1287c478bd9Sstevel@tonic-gate 	Ereportenames = NULL;
129602ca9eaScth 	lut_free(Ereportenames_discard, NULL, NULL);
130602ca9eaScth 	Ereportenames_discard = NULL;
1317c478bd9Sstevel@tonic-gate 	lut_free(SERDs, NULL, NULL);
1327c478bd9Sstevel@tonic-gate 	SERDs = NULL;
1337aec1d6eScindi 	lut_free(STATs, NULL, NULL);
1347aec1d6eScindi 	STATs = NULL;
1357c478bd9Sstevel@tonic-gate 	lut_free(ASRUs, NULL, NULL);
1367c478bd9Sstevel@tonic-gate 	ASRUs = NULL;
1377c478bd9Sstevel@tonic-gate 	lut_free(FRUs, NULL, NULL);
1387c478bd9Sstevel@tonic-gate 	FRUs = NULL;
1397c478bd9Sstevel@tonic-gate 	lut_free(Configs, NULL, NULL);
1407c478bd9Sstevel@tonic-gate 	Configs = NULL;
14127134bdaSstephh 	lut_free(Usedprops, NULL, NULL);
14227134bdaSstephh 	Usedprops = NULL;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	Props = Lastprops = NULL;
1457c478bd9Sstevel@tonic-gate 	Masks = Lastmasks = NULL;
1467c478bd9Sstevel@tonic-gate 	Problems = Lastproblems = NULL;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	if (Newname != NULL) {
1497c478bd9Sstevel@tonic-gate 		FREE(Newname);
1507c478bd9Sstevel@tonic-gate 		Newname = NULL;
1517c478bd9Sstevel@tonic-gate 	}
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
154b5016cbbSstephh /*ARGSUSED*/
155b5016cbbSstephh static int
156b5016cbbSstephh nodesize(enum nodetype t, struct node *ret)
157b5016cbbSstephh {
158b5016cbbSstephh 	int size = sizeof (struct node);
159b5016cbbSstephh 
160b5016cbbSstephh 	switch (t) {
161b5016cbbSstephh 	case T_NAME:
162b5016cbbSstephh 		size += sizeof (ret->u.name) - sizeof (ret->u);
163b5016cbbSstephh 		break;
164b5016cbbSstephh 
165b5016cbbSstephh 	case T_GLOBID:
166b5016cbbSstephh 		size += sizeof (ret->u.globid) - sizeof (ret->u);
167b5016cbbSstephh 		break;
168b5016cbbSstephh 
169b5016cbbSstephh 	case T_TIMEVAL:
170b5016cbbSstephh 	case T_NUM:
171b5016cbbSstephh 		size += sizeof (ret->u.ull) - sizeof (ret->u);
172b5016cbbSstephh 		break;
173b5016cbbSstephh 
174b5016cbbSstephh 	case T_QUOTE:
175b5016cbbSstephh 		size += sizeof (ret->u.quote) - sizeof (ret->u);
176b5016cbbSstephh 		break;
177b5016cbbSstephh 
178b5016cbbSstephh 	case T_FUNC:
179b5016cbbSstephh 		size += sizeof (ret->u.func) - sizeof (ret->u);
180b5016cbbSstephh 		break;
181b5016cbbSstephh 
182b5016cbbSstephh 	case T_FAULT:
183b5016cbbSstephh 	case T_UPSET:
184b5016cbbSstephh 	case T_DEFECT:
185b5016cbbSstephh 	case T_ERROR:
186b5016cbbSstephh 	case T_EREPORT:
187b5016cbbSstephh 	case T_ASRU:
188b5016cbbSstephh 	case T_FRU:
189b5016cbbSstephh 	case T_SERD:
190b5016cbbSstephh 	case T_STAT:
191b5016cbbSstephh 	case T_CONFIG:
192b5016cbbSstephh 	case T_PROP:
193b5016cbbSstephh 	case T_MASK:
194b5016cbbSstephh 		size += sizeof (ret->u.stmt) - sizeof (ret->u);
195b5016cbbSstephh 		break;
196b5016cbbSstephh 
197b5016cbbSstephh 	case T_EVENT:
198b5016cbbSstephh 		size += sizeof (ret->u.event) - sizeof (ret->u);
199b5016cbbSstephh 		break;
200b5016cbbSstephh 
201b5016cbbSstephh 	case T_ARROW:
202b5016cbbSstephh 		size += sizeof (ret->u.arrow) - sizeof (ret->u);
203b5016cbbSstephh 		break;
204b5016cbbSstephh 
205b5016cbbSstephh 	default:
206b5016cbbSstephh 		size += sizeof (ret->u.expr) - sizeof (ret->u);
207b5016cbbSstephh 		break;
208b5016cbbSstephh 	}
209b5016cbbSstephh 	return (size);
210b5016cbbSstephh }
211b5016cbbSstephh 
2127c478bd9Sstevel@tonic-gate struct node *
2137c478bd9Sstevel@tonic-gate newnode(enum nodetype t, const char *file, int line)
2147c478bd9Sstevel@tonic-gate {
215b5016cbbSstephh 	struct node *ret = NULL;
216b5016cbbSstephh 	int size = nodesize(t, ret);
2177c478bd9Sstevel@tonic-gate 
218b5016cbbSstephh 	ret = alloc_xmalloc(size);
2197c478bd9Sstevel@tonic-gate 	stats_counter_bump(Nodecount);
220b5016cbbSstephh 	bzero(ret, size);
2217c478bd9Sstevel@tonic-gate 	ret->t = t;
2227c478bd9Sstevel@tonic-gate 	ret->file = (file == NULL) ? "<nofile>" : file;
2237c478bd9Sstevel@tonic-gate 	ret->line = line;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	return (ret);
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2297c478bd9Sstevel@tonic-gate void
2307c478bd9Sstevel@tonic-gate tree_free(struct node *root)
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	if (root == NULL)
2337c478bd9Sstevel@tonic-gate 		return;
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	switch (root->t) {
2367c478bd9Sstevel@tonic-gate 	case T_NAME:
2377c478bd9Sstevel@tonic-gate 		tree_free(root->u.name.child);
2387c478bd9Sstevel@tonic-gate 		tree_free(root->u.name.next);
2397c478bd9Sstevel@tonic-gate 		break;
2407c478bd9Sstevel@tonic-gate 	case T_FUNC:
2417c478bd9Sstevel@tonic-gate 		tree_free(root->u.func.arglist);
2427c478bd9Sstevel@tonic-gate 		break;
2437c478bd9Sstevel@tonic-gate 	case T_AND:
2447c478bd9Sstevel@tonic-gate 	case T_OR:
2457c478bd9Sstevel@tonic-gate 	case T_EQ:
2467c478bd9Sstevel@tonic-gate 	case T_NE:
2477c478bd9Sstevel@tonic-gate 	case T_ADD:
2487c478bd9Sstevel@tonic-gate 	case T_DIV:
2497c478bd9Sstevel@tonic-gate 	case T_MOD:
2507c478bd9Sstevel@tonic-gate 	case T_MUL:
2517c478bd9Sstevel@tonic-gate 	case T_SUB:
2527c478bd9Sstevel@tonic-gate 	case T_LT:
2537c478bd9Sstevel@tonic-gate 	case T_LE:
2547c478bd9Sstevel@tonic-gate 	case T_GT:
2557c478bd9Sstevel@tonic-gate 	case T_GE:
2567c478bd9Sstevel@tonic-gate 	case T_BITAND:
2577c478bd9Sstevel@tonic-gate 	case T_BITOR:
2587c478bd9Sstevel@tonic-gate 	case T_BITXOR:
2597c478bd9Sstevel@tonic-gate 	case T_BITNOT:
2607c478bd9Sstevel@tonic-gate 	case T_LSHIFT:
2617c478bd9Sstevel@tonic-gate 	case T_RSHIFT:
2627c478bd9Sstevel@tonic-gate 	case T_NVPAIR:
2637c478bd9Sstevel@tonic-gate 	case T_ASSIGN:
2647c478bd9Sstevel@tonic-gate 	case T_CONDIF:
2657c478bd9Sstevel@tonic-gate 	case T_CONDELSE:
2667c478bd9Sstevel@tonic-gate 	case T_LIST:
2677c478bd9Sstevel@tonic-gate 		tree_free(root->u.expr.left);
2687c478bd9Sstevel@tonic-gate 		tree_free(root->u.expr.right);
2697c478bd9Sstevel@tonic-gate 		break;
2707c478bd9Sstevel@tonic-gate 	case T_EVENT:
2717c478bd9Sstevel@tonic-gate 		tree_free(root->u.event.ename);
2727c478bd9Sstevel@tonic-gate 		tree_free(root->u.event.epname);
2737c478bd9Sstevel@tonic-gate 		tree_free(root->u.event.eexprlist);
2747c478bd9Sstevel@tonic-gate 		break;
2757c478bd9Sstevel@tonic-gate 	case T_NOT:
2767c478bd9Sstevel@tonic-gate 		tree_free(root->u.expr.left);
2777c478bd9Sstevel@tonic-gate 		break;
2787c478bd9Sstevel@tonic-gate 	case T_ARROW:
2797c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.lhs);
2807c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.nnp);
2817c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.knp);
2827c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.rhs);
2837c478bd9Sstevel@tonic-gate 		break;
2847c478bd9Sstevel@tonic-gate 	case T_PROP:
2857c478bd9Sstevel@tonic-gate 	case T_MASK:
2867c478bd9Sstevel@tonic-gate 		tree_free(root->u.stmt.np);
2877c478bd9Sstevel@tonic-gate 		break;
2887c478bd9Sstevel@tonic-gate 	case T_FAULT:
2897c478bd9Sstevel@tonic-gate 	case T_UPSET:
2907c478bd9Sstevel@tonic-gate 	case T_DEFECT:
2917c478bd9Sstevel@tonic-gate 	case T_ERROR:
2927c478bd9Sstevel@tonic-gate 	case T_EREPORT:
2937c478bd9Sstevel@tonic-gate 	case T_ASRU:
2947c478bd9Sstevel@tonic-gate 	case T_FRU:
2957c478bd9Sstevel@tonic-gate 	case T_SERD:
2967aec1d6eScindi 	case T_STAT:
2977c478bd9Sstevel@tonic-gate 	case T_CONFIG:
2987c478bd9Sstevel@tonic-gate 		tree_free(root->u.stmt.np);
2997c478bd9Sstevel@tonic-gate 		if (root->u.stmt.nvpairs)
3007c478bd9Sstevel@tonic-gate 			tree_free(root->u.stmt.nvpairs);
3017c478bd9Sstevel@tonic-gate 		if (root->u.stmt.lutp)
3027c478bd9Sstevel@tonic-gate 			lut_free(root->u.stmt.lutp, NULL, NULL);
3037c478bd9Sstevel@tonic-gate 		break;
3047c478bd9Sstevel@tonic-gate 	case T_TIMEVAL:
3057c478bd9Sstevel@tonic-gate 	case T_NUM:
3067c478bd9Sstevel@tonic-gate 	case T_QUOTE:
3077c478bd9Sstevel@tonic-gate 	case T_GLOBID:
3087c478bd9Sstevel@tonic-gate 	case T_NOTHING:
3097c478bd9Sstevel@tonic-gate 		break;
3107c478bd9Sstevel@tonic-gate 	default:
3117c478bd9Sstevel@tonic-gate 		out(O_DIE,
3127c478bd9Sstevel@tonic-gate 		    "internal error: tree_free unexpected nodetype: %d",
3137c478bd9Sstevel@tonic-gate 		    root->t);
3147c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3157c478bd9Sstevel@tonic-gate 	}
316b5016cbbSstephh 	alloc_xfree((char *)root, nodesize(root->t, root));
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate static int
3207c478bd9Sstevel@tonic-gate tree_treecmp(struct node *np1, struct node *np2, enum nodetype t,
3217c478bd9Sstevel@tonic-gate 	    lut_cmp cmp_func)
3227c478bd9Sstevel@tonic-gate {
3237c478bd9Sstevel@tonic-gate 	if (np1 == NULL || np2 == NULL)
3247c478bd9Sstevel@tonic-gate 		return (0);
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	if (np1->t != np2->t)
3277c478bd9Sstevel@tonic-gate 		return (1);
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	ASSERT(cmp_func != NULL);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	if (np1->t == t)
3327c478bd9Sstevel@tonic-gate 		return ((*cmp_func)(np1, np2));
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	switch (np1->t) {
3357c478bd9Sstevel@tonic-gate 	case T_NAME:
3367c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.name.child, np2->u.name.child, t,
3377c478bd9Sstevel@tonic-gate 		    cmp_func))
3387c478bd9Sstevel@tonic-gate 			return (1);
3397c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.name.next, np2->u.name.next, t,
3407c478bd9Sstevel@tonic-gate 		    cmp_func));
3417c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3427c478bd9Sstevel@tonic-gate 		break;
3437c478bd9Sstevel@tonic-gate 	case T_FUNC:
3447c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.func.arglist, np2->u.func.arglist,
3457c478bd9Sstevel@tonic-gate 		    t, cmp_func));
3467c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3477c478bd9Sstevel@tonic-gate 		break;
3487c478bd9Sstevel@tonic-gate 	case T_AND:
3497c478bd9Sstevel@tonic-gate 	case T_OR:
3507c478bd9Sstevel@tonic-gate 	case T_EQ:
3517c478bd9Sstevel@tonic-gate 	case T_NE:
3527c478bd9Sstevel@tonic-gate 	case T_ADD:
3537c478bd9Sstevel@tonic-gate 	case T_DIV:
3547c478bd9Sstevel@tonic-gate 	case T_MOD:
3557c478bd9Sstevel@tonic-gate 	case T_MUL:
3567c478bd9Sstevel@tonic-gate 	case T_SUB:
3577c478bd9Sstevel@tonic-gate 	case T_LT:
3587c478bd9Sstevel@tonic-gate 	case T_LE:
3597c478bd9Sstevel@tonic-gate 	case T_GT:
3607c478bd9Sstevel@tonic-gate 	case T_GE:
3617c478bd9Sstevel@tonic-gate 	case T_BITAND:
3627c478bd9Sstevel@tonic-gate 	case T_BITOR:
3637c478bd9Sstevel@tonic-gate 	case T_BITXOR:
3647c478bd9Sstevel@tonic-gate 	case T_BITNOT:
3657c478bd9Sstevel@tonic-gate 	case T_LSHIFT:
3667c478bd9Sstevel@tonic-gate 	case T_RSHIFT:
3677c478bd9Sstevel@tonic-gate 	case T_NVPAIR:
3687c478bd9Sstevel@tonic-gate 	case T_ASSIGN:
3697c478bd9Sstevel@tonic-gate 	case T_CONDIF:
3707c478bd9Sstevel@tonic-gate 	case T_CONDELSE:
3717c478bd9Sstevel@tonic-gate 	case T_LIST:
3727c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t,
3737c478bd9Sstevel@tonic-gate 		    cmp_func))
3747c478bd9Sstevel@tonic-gate 			return (1);
3757c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.expr.right, np2->u.expr.right, t,
3767c478bd9Sstevel@tonic-gate 		    cmp_func));
3777c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3787c478bd9Sstevel@tonic-gate 		break;
3797c478bd9Sstevel@tonic-gate 	case T_EVENT:
3807c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.event.ename, np2->u.event.ename, t,
3817c478bd9Sstevel@tonic-gate 		    cmp_func))
3827c478bd9Sstevel@tonic-gate 			return (1);
3837c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.event.epname, np2->u.event.epname, t,
3847c478bd9Sstevel@tonic-gate 		    cmp_func))
3857c478bd9Sstevel@tonic-gate 			return (1);
3867c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.event.eexprlist,
3877c478bd9Sstevel@tonic-gate 		    np2->u.event.eexprlist, t, cmp_func));
3887c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3897c478bd9Sstevel@tonic-gate 		break;
3907c478bd9Sstevel@tonic-gate 	case T_NOT:
3917c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t,
3927c478bd9Sstevel@tonic-gate 		    cmp_func));
3937c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3947c478bd9Sstevel@tonic-gate 		break;
3957c478bd9Sstevel@tonic-gate 	case T_ARROW:
3967c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.lhs, np2->u.arrow.lhs, t,
3977c478bd9Sstevel@tonic-gate 		    cmp_func))
3987c478bd9Sstevel@tonic-gate 			return (1);
3997c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.nnp, np2->u.arrow.nnp, t,
4007c478bd9Sstevel@tonic-gate 		    cmp_func))
4017c478bd9Sstevel@tonic-gate 			return (1);
4027c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.knp, np2->u.arrow.knp, t,
4037c478bd9Sstevel@tonic-gate 		    cmp_func))
4047c478bd9Sstevel@tonic-gate 			return (1);
4057c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.arrow.rhs, np2->u.arrow.rhs, t,
4067c478bd9Sstevel@tonic-gate 		    cmp_func));
4077c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4087c478bd9Sstevel@tonic-gate 		break;
4097c478bd9Sstevel@tonic-gate 	case T_PROP:
4107c478bd9Sstevel@tonic-gate 	case T_MASK:
4117c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t,
4127c478bd9Sstevel@tonic-gate 		    cmp_func));
4137c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4147c478bd9Sstevel@tonic-gate 		break;
4157c478bd9Sstevel@tonic-gate 	case T_FAULT:
4167c478bd9Sstevel@tonic-gate 	case T_UPSET:
4177c478bd9Sstevel@tonic-gate 	case T_DEFECT:
4187c478bd9Sstevel@tonic-gate 	case T_ERROR:
4197c478bd9Sstevel@tonic-gate 	case T_EREPORT:
4207c478bd9Sstevel@tonic-gate 	case T_ASRU:
4217c478bd9Sstevel@tonic-gate 	case T_FRU:
4227c478bd9Sstevel@tonic-gate 	case T_SERD:
4237aec1d6eScindi 	case T_STAT:
4247c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t, cmp_func))
4257c478bd9Sstevel@tonic-gate 			return (1);
4267c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.stmt.nvpairs, np2->u.stmt.nvpairs,
4277c478bd9Sstevel@tonic-gate 		    t, cmp_func));
4287c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4297c478bd9Sstevel@tonic-gate 		break;
4307c478bd9Sstevel@tonic-gate 	case T_TIMEVAL:
4317c478bd9Sstevel@tonic-gate 	case T_NUM:
4327c478bd9Sstevel@tonic-gate 	case T_QUOTE:
4337c478bd9Sstevel@tonic-gate 	case T_GLOBID:
4347c478bd9Sstevel@tonic-gate 	case T_NOTHING:
4357c478bd9Sstevel@tonic-gate 		break;
4367c478bd9Sstevel@tonic-gate 	default:
4377c478bd9Sstevel@tonic-gate 		out(O_DIE,
4387c478bd9Sstevel@tonic-gate 		    "internal error: tree_treecmp unexpected nodetype: %d",
4397c478bd9Sstevel@tonic-gate 		    np1->t);
4407c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4417c478bd9Sstevel@tonic-gate 		break;
4427c478bd9Sstevel@tonic-gate 	}
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	return (0);
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate struct node *
4487c478bd9Sstevel@tonic-gate tree_root(struct node *np)
4497c478bd9Sstevel@tonic-gate {
4507c478bd9Sstevel@tonic-gate 	if (np)
4517c478bd9Sstevel@tonic-gate 		Root = np;
4527c478bd9Sstevel@tonic-gate 	return (Root);
4537c478bd9Sstevel@tonic-gate }
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate struct node *
4567c478bd9Sstevel@tonic-gate tree_nothing(void)
4577c478bd9Sstevel@tonic-gate {
4587c478bd9Sstevel@tonic-gate 	return (newnode(T_NOTHING, L_nofile, 0));
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate struct node *
4627c478bd9Sstevel@tonic-gate tree_expr(enum nodetype t, struct node *left, struct node *right)
4637c478bd9Sstevel@tonic-gate {
4647c478bd9Sstevel@tonic-gate 	struct node *ret;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	ASSERTinfo(left != NULL || right != NULL, ptree_nodetype2str(t));
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 	ret = newnode(t,
4697c478bd9Sstevel@tonic-gate 	    (left) ? left->file : right->file,
4707c478bd9Sstevel@tonic-gate 	    (left) ? left->line : right->line);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	ret->u.expr.left = left;
4737c478bd9Sstevel@tonic-gate 	ret->u.expr.right = right;
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 	check_expr(ret);
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	return (ret);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate /*
4817c478bd9Sstevel@tonic-gate  * ename_compress -- convert event class name in to more space-efficient form
4827c478bd9Sstevel@tonic-gate  *
4837c478bd9Sstevel@tonic-gate  * this routine is called after the parser has completed an "ename", which
4847c478bd9Sstevel@tonic-gate  * is that part of an event that contains the class name (like ereport.x.y.z).
4857c478bd9Sstevel@tonic-gate  * after this routine gets done with the ename, two things are true:
4867c478bd9Sstevel@tonic-gate  *   1. the ename uses only a single struct node
4877c478bd9Sstevel@tonic-gate  *   2. ename->u.name.s contains the *complete* class name, dots and all,
4887c478bd9Sstevel@tonic-gate  *      entered into the string table.
4897c478bd9Sstevel@tonic-gate  *
4907c478bd9Sstevel@tonic-gate  * so in addition to saving space by using fewer struct nodes, this routine
4917c478bd9Sstevel@tonic-gate  * allows consumers of the fault tree to assume the ename is a single
4927c478bd9Sstevel@tonic-gate  * string, rather than a linked list of strings.
4937c478bd9Sstevel@tonic-gate  */
4947c478bd9Sstevel@tonic-gate static struct node *
4957c478bd9Sstevel@tonic-gate ename_compress(struct node *ename)
4967c478bd9Sstevel@tonic-gate {
4977c478bd9Sstevel@tonic-gate 	char *buf;
4987c478bd9Sstevel@tonic-gate 	char *cp;
4997c478bd9Sstevel@tonic-gate 	int len = 0;
5007c478bd9Sstevel@tonic-gate 	struct node *np;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	if (ename == NULL)
5037c478bd9Sstevel@tonic-gate 		return (ename);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	ASSERT(ename->t == T_NAME);
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	if (ename->u.name.next == NULL)
5087c478bd9Sstevel@tonic-gate 		return (ename);	/* no compression to be applied here */
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 	for (np = ename; np != NULL; np = np->u.name.next) {
5117c478bd9Sstevel@tonic-gate 		ASSERT(np->t == T_NAME);
5127c478bd9Sstevel@tonic-gate 		len++;	/* room for '.' and final '\0' */
5137c478bd9Sstevel@tonic-gate 		len += strlen(np->u.name.s);
5147c478bd9Sstevel@tonic-gate 	}
5157c478bd9Sstevel@tonic-gate 	cp = buf = alloca(len);
5167c478bd9Sstevel@tonic-gate 	for (np = ename; np != NULL; np = np->u.name.next) {
5177c478bd9Sstevel@tonic-gate 		ASSERT(np->t == T_NAME);
5187c478bd9Sstevel@tonic-gate 		if (np != ename)
5197c478bd9Sstevel@tonic-gate 			*cp++ = '.';
5207c478bd9Sstevel@tonic-gate 		(void) strcpy(cp, np->u.name.s);
5217c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
5227c478bd9Sstevel@tonic-gate 	}
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate 	ename->u.name.s = stable(buf);
5257c478bd9Sstevel@tonic-gate 	tree_free(ename->u.name.next);
5267c478bd9Sstevel@tonic-gate 	ename->u.name.next = NULL;
5277c478bd9Sstevel@tonic-gate 	ename->u.name.last = ename;
5287c478bd9Sstevel@tonic-gate 	return (ename);
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate struct node *
5327c478bd9Sstevel@tonic-gate tree_event(struct node *ename, struct node *epname, struct node *eexprlist)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate 	struct node *ret;
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 	ASSERT(ename != NULL);
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 	ret = newnode(T_EVENT, ename->file, ename->line);
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	ret->u.event.ename = ename_compress(ename);
5417c478bd9Sstevel@tonic-gate 	ret->u.event.epname = epname;
5427c478bd9Sstevel@tonic-gate 	ret->u.event.eexprlist = eexprlist;
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 	check_event(ret);
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	return (ret);
5477c478bd9Sstevel@tonic-gate }
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate struct node *
5507c478bd9Sstevel@tonic-gate tree_name(const char *s, enum itertype it, const char *file, int line)
5517c478bd9Sstevel@tonic-gate {
5527c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_NAME, file, line);
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL);
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	stats_counter_bump(Namecount);
5577c478bd9Sstevel@tonic-gate 	ret->u.name.t = N_UNSPEC;
5587c478bd9Sstevel@tonic-gate 	ret->u.name.s = stable(s);
5597c478bd9Sstevel@tonic-gate 	ret->u.name.it = it;
5607c478bd9Sstevel@tonic-gate 	ret->u.name.last = ret;
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	if (it == IT_ENAME) {
5637c478bd9Sstevel@tonic-gate 		/* PHASE2, possible optimization: convert to table driven */
5647c478bd9Sstevel@tonic-gate 		if (s == L_fault)
5657c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_FAULT;
5667c478bd9Sstevel@tonic-gate 		else if (s == L_upset)
5677c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_UPSET;
5687c478bd9Sstevel@tonic-gate 		else if (s == L_defect)
5697c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_DEFECT;
5707c478bd9Sstevel@tonic-gate 		else if (s == L_error)
5717c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_ERROR;
5727c478bd9Sstevel@tonic-gate 		else if (s == L_ereport)
5737c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_EREPORT;
5747c478bd9Sstevel@tonic-gate 		else if (s == L_serd)
5757c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_SERD;
5767aec1d6eScindi 		else if (s == L_stat)
5777aec1d6eScindi 			ret->u.name.t = N_STAT;
5787c478bd9Sstevel@tonic-gate 		else
5797c478bd9Sstevel@tonic-gate 			outfl(O_ERR, file, line, "unknown class: %s", s);
5807c478bd9Sstevel@tonic-gate 	}
5817c478bd9Sstevel@tonic-gate 	return (ret);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate struct node *
5857c478bd9Sstevel@tonic-gate tree_iname(const char *s, const char *file, int line)
5867c478bd9Sstevel@tonic-gate {
5877c478bd9Sstevel@tonic-gate 	struct node *ret;
5887c478bd9Sstevel@tonic-gate 	char *ss;
5897c478bd9Sstevel@tonic-gate 	char *ptr;
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL && *s != '\0');
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	ss = STRDUP(s);
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	ptr = &ss[strlen(ss) - 1];
5967c478bd9Sstevel@tonic-gate 	if (!isdigit(*ptr)) {
5977c478bd9Sstevel@tonic-gate 		outfl(O_ERR, file, line,
5987c478bd9Sstevel@tonic-gate 		    "instanced name expected (i.e. \"x0/y1\")");
5997c478bd9Sstevel@tonic-gate 		FREE(ss);
6007c478bd9Sstevel@tonic-gate 		return (tree_name(s, IT_NONE, file, line));
6017c478bd9Sstevel@tonic-gate 	}
6027c478bd9Sstevel@tonic-gate 	while (ptr > ss && isdigit(*(ptr - 1)))
6037c478bd9Sstevel@tonic-gate 		ptr--;
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 	ret = newnode(T_NAME, file, line);
6067c478bd9Sstevel@tonic-gate 	stats_counter_bump(Namecount);
6077c478bd9Sstevel@tonic-gate 	ret->u.name.child = tree_num(ptr, file, line);
6087c478bd9Sstevel@tonic-gate 	*ptr = '\0';
6097c478bd9Sstevel@tonic-gate 	ret->u.name.t = N_UNSPEC;
6107c478bd9Sstevel@tonic-gate 	ret->u.name.s = stable(ss);
6117c478bd9Sstevel@tonic-gate 	ret->u.name.it = IT_NONE;
6127c478bd9Sstevel@tonic-gate 	ret->u.name.last = ret;
6137c478bd9Sstevel@tonic-gate 	FREE(ss);
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	return (ret);
6167c478bd9Sstevel@tonic-gate }
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate struct node *
6197c478bd9Sstevel@tonic-gate tree_globid(const char *s, const char *file, int line)
6207c478bd9Sstevel@tonic-gate {
6217c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_GLOBID, file, line);
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL);
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	ret->u.globid.s = stable(s);
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 	return (ret);
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate struct node *
6317c478bd9Sstevel@tonic-gate tree_name_append(struct node *np1, struct node *np2)
6327c478bd9Sstevel@tonic-gate {
6337c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL && np2 != NULL);
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 	if (np1->t != T_NAME)
6367c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np1->file, np1->line,
6377c478bd9Sstevel@tonic-gate 		    "tree_name_append: internal error (np1 type %d)", np1->t);
6387c478bd9Sstevel@tonic-gate 	if (np2->t != T_NAME)
6397c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np2->file, np2->line,
6407c478bd9Sstevel@tonic-gate 		    "tree_name_append: internal error (np2 type %d)", np2->t);
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 	ASSERT(np1->u.name.last != NULL);
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	np1->u.name.last->u.name.next = np2;
6457c478bd9Sstevel@tonic-gate 	np1->u.name.last = np2;
6467c478bd9Sstevel@tonic-gate 	return (np1);
6477c478bd9Sstevel@tonic-gate }
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate /*
6507c478bd9Sstevel@tonic-gate  * tree_name_repairdash -- repair a class name that contained a dash
6517c478bd9Sstevel@tonic-gate  *
6527c478bd9Sstevel@tonic-gate  * this routine is called by the parser when a dash is encountered
6537c478bd9Sstevel@tonic-gate  * in a class name.  the event protocol allows the dashes but our
6547c478bd9Sstevel@tonic-gate  * lexer considers them a separate token (arithmetic minus).  an extra
6557c478bd9Sstevel@tonic-gate  * rule in the parser catches this case and calls this routine to fixup
6567c478bd9Sstevel@tonic-gate  * the last component of the class name (so far) by constructing the
6577c478bd9Sstevel@tonic-gate  * new stable entry for a name including the dash.
6587c478bd9Sstevel@tonic-gate  */
6597c478bd9Sstevel@tonic-gate struct node *
6607c478bd9Sstevel@tonic-gate tree_name_repairdash(struct node *np, const char *s)
6617c478bd9Sstevel@tonic-gate {
6627c478bd9Sstevel@tonic-gate 	int len;
6637c478bd9Sstevel@tonic-gate 	char *buf;
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	ASSERT(np != NULL && s != NULL);
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 	if (np->t != T_NAME)
6687c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np->file, np->line,
6697c478bd9Sstevel@tonic-gate 		    "tree_name_repairdash: internal error (np type %d)",
6707c478bd9Sstevel@tonic-gate 		    np->t);
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate 	ASSERT(np->u.name.last != NULL);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1;
6757c478bd9Sstevel@tonic-gate 	buf = MALLOC(len);
6767c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, len, "%s-%s", np->u.name.last->u.name.s, s);
6777c478bd9Sstevel@tonic-gate 	np->u.name.last->u.name.s = stable(buf);
6787c478bd9Sstevel@tonic-gate 	FREE(buf);
6797c478bd9Sstevel@tonic-gate 	return (np);
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate struct node *
6838a40a695Sgavinm tree_name_repairdash2(const char *s, struct node *np)
6848a40a695Sgavinm {
6858a40a695Sgavinm 	int len;
6868a40a695Sgavinm 	char *buf;
6878a40a695Sgavinm 
6888a40a695Sgavinm 	ASSERT(np != NULL && s != NULL);
6898a40a695Sgavinm 
6908a40a695Sgavinm 	if (np->t != T_NAME)
6918a40a695Sgavinm 		outfl(O_DIE, np->file, np->line,
6928a40a695Sgavinm 		    "tree_name_repairdash: internal error (np type %d)",
6938a40a695Sgavinm 		    np->t);
6948a40a695Sgavinm 
6958a40a695Sgavinm 	ASSERT(np->u.name.last != NULL);
6968a40a695Sgavinm 
6978a40a695Sgavinm 	len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1;
6988a40a695Sgavinm 	buf = MALLOC(len);
6998a40a695Sgavinm 	(void) snprintf(buf, len, "%s-%s", s, np->u.name.last->u.name.s);
7008a40a695Sgavinm 	np->u.name.last->u.name.s = stable(buf);
7018a40a695Sgavinm 	FREE(buf);
7028a40a695Sgavinm 	return (np);
7038a40a695Sgavinm }
7048a40a695Sgavinm 
7058a40a695Sgavinm struct node *
7067c478bd9Sstevel@tonic-gate tree_name_iterator(struct node *np1, struct node *np2)
7077c478bd9Sstevel@tonic-gate {
7087c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL);
7097c478bd9Sstevel@tonic-gate 	ASSERT(np2 != NULL);
7107c478bd9Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t));
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 	np1->u.name.child = np2;
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate 	check_name_iterator(np1);
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 	return (np1);
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate struct node *
7207c478bd9Sstevel@tonic-gate tree_timeval(const char *s, const char *suffix, const char *file, int line)
7217c478bd9Sstevel@tonic-gate {
7227c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_TIMEVAL, file, line);
7237c478bd9Sstevel@tonic-gate 	const unsigned long long *ullp;
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL);
7267c478bd9Sstevel@tonic-gate 	ASSERT(suffix != NULL);
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 	if ((ullp = lex_s2ullp_lut_lookup(Timesuffixlut, suffix)) == NULL) {
7297c478bd9Sstevel@tonic-gate 		outfl(O_ERR, file, line,
7307c478bd9Sstevel@tonic-gate 		    "unrecognized number suffix: %s", suffix);
7317c478bd9Sstevel@tonic-gate 		/* still construct a valid timeval node so parsing continues */
7327c478bd9Sstevel@tonic-gate 		ret->u.ull = 1;
7337c478bd9Sstevel@tonic-gate 	} else {
7347c478bd9Sstevel@tonic-gate 		ret->u.ull = (unsigned long long)strtoul(s, NULL, 0) * *ullp;
7357c478bd9Sstevel@tonic-gate 	}
7367c478bd9Sstevel@tonic-gate 
7377c478bd9Sstevel@tonic-gate 	return (ret);
7387c478bd9Sstevel@tonic-gate }
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate struct node *
7417c478bd9Sstevel@tonic-gate tree_num(const char *s, const char *file, int line)
7427c478bd9Sstevel@tonic-gate {
7437c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_NUM, file, line);
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 	ret->u.ull = (unsigned long long)strtoul(s, NULL, 0);
7467c478bd9Sstevel@tonic-gate 	return (ret);
7477c478bd9Sstevel@tonic-gate }
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate struct node *
7507c478bd9Sstevel@tonic-gate tree_quote(const char *s, const char *file, int line)
7517c478bd9Sstevel@tonic-gate {
7527c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_QUOTE, file, line);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate 	ret->u.quote.s = stable(s);
7557c478bd9Sstevel@tonic-gate 	return (ret);
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate 
7587c478bd9Sstevel@tonic-gate struct node *
7597c478bd9Sstevel@tonic-gate tree_func(const char *s, struct node *np, const char *file, int line)
7607c478bd9Sstevel@tonic-gate {
7617c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_FUNC, file, line);
762b5016cbbSstephh 	const char *ptr;
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 	ret->u.func.s = s;
7657c478bd9Sstevel@tonic-gate 	ret->u.func.arglist = np;
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 	check_func(ret);
7687c478bd9Sstevel@tonic-gate 
769b5016cbbSstephh 	/*
770b5016cbbSstephh 	 * keep track of the properties we're interested in so we can ignore the
771b5016cbbSstephh 	 * rest
772b5016cbbSstephh 	 */
773b5016cbbSstephh 	if (strcmp(s, L_confprop) == 0 || strcmp(s, L_confprop_defined) == 0) {
774b5016cbbSstephh 		ptr = stable(np->u.expr.right->u.quote.s);
775b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
776b5016cbbSstephh 	} else if (strcmp(s, L_is_connected) == 0) {
777b5016cbbSstephh 		ptr = stable("connected");
778b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
779b5016cbbSstephh 		ptr = stable("CONNECTED");
780b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
781b5016cbbSstephh 	} else if (strcmp(s, L_is_type) == 0) {
782b5016cbbSstephh 		ptr = stable("type");
783b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
784b5016cbbSstephh 		ptr = stable("TYPE");
785b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
786b5016cbbSstephh 	} else if (strcmp(s, L_is_on) == 0) {
787b5016cbbSstephh 		ptr = stable("on");
788b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
789b5016cbbSstephh 		ptr = stable("ON");
790b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
791b5016cbbSstephh 	}
792b5016cbbSstephh 
7937c478bd9Sstevel@tonic-gate 	return (ret);
7947c478bd9Sstevel@tonic-gate }
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate /*
7977c478bd9Sstevel@tonic-gate  * given a list from a prop or mask statement or a function argument,
7987c478bd9Sstevel@tonic-gate  * convert all iterators to explicit iterators by inventing appropriate
7997c478bd9Sstevel@tonic-gate  * iterator names.
8007c478bd9Sstevel@tonic-gate  */
8017c478bd9Sstevel@tonic-gate static void
8027aec1d6eScindi make_explicit(struct node *np, int eventonly)
8037c478bd9Sstevel@tonic-gate {
8047c478bd9Sstevel@tonic-gate 	struct node *pnp;	/* component of pathname */
8057c478bd9Sstevel@tonic-gate 	struct node *pnp2;
8067c478bd9Sstevel@tonic-gate 	int count;
8077c478bd9Sstevel@tonic-gate 	static size_t namesz;
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate 	if (Newname == NULL) {
8107c478bd9Sstevel@tonic-gate 		namesz = 200;
8117c478bd9Sstevel@tonic-gate 		Newname = MALLOC(namesz);
8127c478bd9Sstevel@tonic-gate 	}
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate 	if (np == NULL)
8157c478bd9Sstevel@tonic-gate 		return;		/* all done */
8167c478bd9Sstevel@tonic-gate 
8177c478bd9Sstevel@tonic-gate 	switch (np->t) {
8187aec1d6eScindi 		case T_ASSIGN:
8197aec1d6eScindi 		case T_CONDIF:
8207aec1d6eScindi 		case T_CONDELSE:
8217aec1d6eScindi 		case T_NE:
8227aec1d6eScindi 		case T_EQ:
8237aec1d6eScindi 		case T_LT:
8247aec1d6eScindi 		case T_LE:
8257aec1d6eScindi 		case T_GT:
8267aec1d6eScindi 		case T_GE:
8277aec1d6eScindi 		case T_BITAND:
8287aec1d6eScindi 		case T_BITOR:
8297aec1d6eScindi 		case T_BITXOR:
8307aec1d6eScindi 		case T_BITNOT:
8317aec1d6eScindi 		case T_LSHIFT:
8327aec1d6eScindi 		case T_RSHIFT:
8337c478bd9Sstevel@tonic-gate 		case T_LIST:
8347aec1d6eScindi 		case T_AND:
8357aec1d6eScindi 		case T_OR:
8367aec1d6eScindi 		case T_NOT:
8377aec1d6eScindi 		case T_ADD:
8387aec1d6eScindi 		case T_SUB:
8397aec1d6eScindi 		case T_MUL:
8407aec1d6eScindi 		case T_DIV:
8417aec1d6eScindi 		case T_MOD:
8427aec1d6eScindi 			make_explicit(np->u.expr.left, eventonly);
8437aec1d6eScindi 			make_explicit(np->u.expr.right, eventonly);
8447c478bd9Sstevel@tonic-gate 			break;
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate 		case T_EVENT:
8477aec1d6eScindi 			make_explicit(np->u.event.epname, 0);
8487aec1d6eScindi 			make_explicit(np->u.event.eexprlist, 1);
8497aec1d6eScindi 			break;
8507aec1d6eScindi 
8517aec1d6eScindi 		case T_FUNC:
8527aec1d6eScindi 			make_explicit(np->u.func.arglist, eventonly);
8537c478bd9Sstevel@tonic-gate 			break;
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 		case T_NAME:
8567aec1d6eScindi 			if (eventonly)
8577aec1d6eScindi 				return;
8587c478bd9Sstevel@tonic-gate 			for (pnp = np; pnp != NULL; pnp = pnp->u.name.next)
8597c478bd9Sstevel@tonic-gate 				if (pnp->u.name.child == NULL) {
8607c478bd9Sstevel@tonic-gate 					/*
8617c478bd9Sstevel@tonic-gate 					 * found implicit iterator.  convert
8627c478bd9Sstevel@tonic-gate 					 * it to an explicit iterator by
8637c478bd9Sstevel@tonic-gate 					 * using the name of the component
8647c478bd9Sstevel@tonic-gate 					 * appended with '#' and the number
8657c478bd9Sstevel@tonic-gate 					 * of times we've seen this same
8667c478bd9Sstevel@tonic-gate 					 * component name in this path so far.
8677c478bd9Sstevel@tonic-gate 					 */
8687c478bd9Sstevel@tonic-gate 					count = 0;
8697c478bd9Sstevel@tonic-gate 					for (pnp2 = np; pnp2 != NULL;
8707c478bd9Sstevel@tonic-gate 					    pnp2 = pnp2->u.name.next)
8717c478bd9Sstevel@tonic-gate 						if (pnp2 == pnp)
8727c478bd9Sstevel@tonic-gate 							break;
8737c478bd9Sstevel@tonic-gate 						else if (pnp2->u.name.s ==
8747c478bd9Sstevel@tonic-gate 						    pnp->u.name.s)
8757c478bd9Sstevel@tonic-gate 							count++;
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 					if (namesz < strlen(pnp->u.name.s) +
8787c478bd9Sstevel@tonic-gate 					    100) {
8797c478bd9Sstevel@tonic-gate 						namesz = strlen(pnp->u.name.s) +
8807c478bd9Sstevel@tonic-gate 						    100;
8817c478bd9Sstevel@tonic-gate 						FREE(Newname);
8827c478bd9Sstevel@tonic-gate 						Newname = MALLOC(namesz);
8837c478bd9Sstevel@tonic-gate 					}
8847c478bd9Sstevel@tonic-gate 					/*
8857c478bd9Sstevel@tonic-gate 					 * made up interator name is:
8867c478bd9Sstevel@tonic-gate 					 *	name#ordinal
8877c478bd9Sstevel@tonic-gate 					 * or
8887c478bd9Sstevel@tonic-gate 					 *	name##ordinal
8897c478bd9Sstevel@tonic-gate 					 * the first one is used for vertical
8907c478bd9Sstevel@tonic-gate 					 * expansion, the second for horizontal.
8917c478bd9Sstevel@tonic-gate 					 * either way, the '#' embedded in
8927c478bd9Sstevel@tonic-gate 					 * the name makes it impossible to
8937c478bd9Sstevel@tonic-gate 					 * collide with an actual iterator
8947c478bd9Sstevel@tonic-gate 					 * given to us in the eversholt file.
8957c478bd9Sstevel@tonic-gate 					 */
8967c478bd9Sstevel@tonic-gate 					(void) snprintf(Newname, namesz,
8977c478bd9Sstevel@tonic-gate 					    "%s#%s%d", pnp->u.name.s,
8987c478bd9Sstevel@tonic-gate 					    (pnp->u.name.it == IT_HORIZONTAL) ?
8997c478bd9Sstevel@tonic-gate 					    "#" : "", count);
9007c478bd9Sstevel@tonic-gate 
9017c478bd9Sstevel@tonic-gate 					pnp->u.name.child = tree_name(Newname,
9027c478bd9Sstevel@tonic-gate 					    IT_NONE, pnp->file, pnp->line);
9037c478bd9Sstevel@tonic-gate 					pnp->u.name.childgen = 1;
9047c478bd9Sstevel@tonic-gate 				}
9057c478bd9Sstevel@tonic-gate 			break;
9067c478bd9Sstevel@tonic-gate 	}
9077c478bd9Sstevel@tonic-gate }
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate struct node *
9107c478bd9Sstevel@tonic-gate tree_pname(struct node *np)
9117c478bd9Sstevel@tonic-gate {
9127aec1d6eScindi 	make_explicit(np, 0);
9137c478bd9Sstevel@tonic-gate 	return (np);
9147c478bd9Sstevel@tonic-gate }
9157c478bd9Sstevel@tonic-gate 
9167c478bd9Sstevel@tonic-gate struct node *
9177c478bd9Sstevel@tonic-gate tree_arrow(struct node *lhs, struct node *nnp, struct node *knp,
9187c478bd9Sstevel@tonic-gate     struct node *rhs)
9197c478bd9Sstevel@tonic-gate {
9207c478bd9Sstevel@tonic-gate 	struct node *ret;
9217c478bd9Sstevel@tonic-gate 
9227c478bd9Sstevel@tonic-gate 	ASSERT(lhs != NULL || rhs != NULL);
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate 	ret = newnode(T_ARROW,
9257c478bd9Sstevel@tonic-gate 	    (lhs) ? lhs->file : rhs->file,
9267c478bd9Sstevel@tonic-gate 	    (lhs) ? lhs->line : rhs->line);
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate 	ret->u.arrow.lhs = lhs;
9297c478bd9Sstevel@tonic-gate 	ret->u.arrow.nnp = nnp;
9307c478bd9Sstevel@tonic-gate 	ret->u.arrow.knp = knp;
9317c478bd9Sstevel@tonic-gate 	ret->u.arrow.rhs = rhs;
9327c478bd9Sstevel@tonic-gate 
9337aec1d6eScindi 	make_explicit(lhs, 0);
9347aec1d6eScindi 	make_explicit(rhs, 0);
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate 	check_arrow(ret);
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 	return (ret);
9397c478bd9Sstevel@tonic-gate }
9407c478bd9Sstevel@tonic-gate 
9417c478bd9Sstevel@tonic-gate static struct lut *
9427c478bd9Sstevel@tonic-gate nvpair2lut(struct node *np, struct lut *lutp, enum nodetype t)
9437c478bd9Sstevel@tonic-gate {
9447c478bd9Sstevel@tonic-gate 	if (np) {
9457c478bd9Sstevel@tonic-gate 		if (np->t == T_NVPAIR) {
9467c478bd9Sstevel@tonic-gate 			ASSERTeq(np->u.expr.left->t, T_NAME,
9477c478bd9Sstevel@tonic-gate 			    ptree_nodetype2str);
9487c478bd9Sstevel@tonic-gate 			check_stmt_allowed_properties(t, np, lutp);
9497c478bd9Sstevel@tonic-gate 			lutp = tree_s2np_lut_add(lutp,
9507c478bd9Sstevel@tonic-gate 			    np->u.expr.left->u.name.s, np->u.expr.right);
9517c478bd9Sstevel@tonic-gate 		} else if (np->t == T_LIST) {
9527c478bd9Sstevel@tonic-gate 			lutp = nvpair2lut(np->u.expr.left, lutp, t);
9537c478bd9Sstevel@tonic-gate 			lutp = nvpair2lut(np->u.expr.right, lutp, t);
9547c478bd9Sstevel@tonic-gate 		} else
9557c478bd9Sstevel@tonic-gate 			outfl(O_DIE, np->file, np->line,
9567c478bd9Sstevel@tonic-gate 			    "internal error: nvpair2lut type %s",
9577c478bd9Sstevel@tonic-gate 			    ptree_nodetype2str(np->t));
9587c478bd9Sstevel@tonic-gate 	}
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate 	return (lutp);
9617c478bd9Sstevel@tonic-gate }
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate struct lut *
9647c478bd9Sstevel@tonic-gate tree_s2np_lut_add(struct lut *root, const char *s, struct node *np)
9657c478bd9Sstevel@tonic-gate {
9667c478bd9Sstevel@tonic-gate 	return (lut_add(root, (void *)s, (void *)np, NULL));
9677c478bd9Sstevel@tonic-gate }
9687c478bd9Sstevel@tonic-gate 
9697c478bd9Sstevel@tonic-gate struct node *
9707c478bd9Sstevel@tonic-gate tree_s2np_lut_lookup(struct lut *root, const char *s)
9717c478bd9Sstevel@tonic-gate {
9727c478bd9Sstevel@tonic-gate 	return (struct node *)lut_lookup(root, (void *)s, NULL);
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate struct lut *
9767c478bd9Sstevel@tonic-gate tree_name2np_lut_add(struct lut *root, struct node *namep, struct node *np)
9777c478bd9Sstevel@tonic-gate {
9787c478bd9Sstevel@tonic-gate 	return (lut_add(root, (void *)namep, (void *)np,
9797c478bd9Sstevel@tonic-gate 	    (lut_cmp)tree_namecmp));
9807c478bd9Sstevel@tonic-gate }
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate struct node *
9837c478bd9Sstevel@tonic-gate tree_name2np_lut_lookup(struct lut *root, struct node *namep)
9847c478bd9Sstevel@tonic-gate {
9857c478bd9Sstevel@tonic-gate 	return (struct node *)
9867c478bd9Sstevel@tonic-gate 	    lut_lookup(root, (void *)namep, (lut_cmp)tree_namecmp);
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate struct node *
9907c478bd9Sstevel@tonic-gate tree_name2np_lut_lookup_name(struct lut *root, struct node *namep)
9917c478bd9Sstevel@tonic-gate {
9927c478bd9Sstevel@tonic-gate 	return (struct node *)
9937c478bd9Sstevel@tonic-gate 	    lut_lookup_lhs(root, (void *)namep, (lut_cmp)tree_namecmp);
9947c478bd9Sstevel@tonic-gate }
9957c478bd9Sstevel@tonic-gate 
9967c478bd9Sstevel@tonic-gate struct lut *
9977c478bd9Sstevel@tonic-gate tree_event2np_lut_add(struct lut *root, struct node *enp, struct node *np)
9987c478bd9Sstevel@tonic-gate {
9997c478bd9Sstevel@tonic-gate 	return (lut_add(root, (void *)enp, (void *)np, (lut_cmp)tree_eventcmp));
10007c478bd9Sstevel@tonic-gate }
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate struct node *
10037c478bd9Sstevel@tonic-gate tree_event2np_lut_lookup(struct lut *root, struct node *enp)
10047c478bd9Sstevel@tonic-gate {
10057c478bd9Sstevel@tonic-gate 	return ((struct node *)
10067c478bd9Sstevel@tonic-gate 	    lut_lookup(root, (void *)enp, (lut_cmp)tree_eventcmp));
10077c478bd9Sstevel@tonic-gate }
10087c478bd9Sstevel@tonic-gate 
10097c478bd9Sstevel@tonic-gate struct node *
10107c478bd9Sstevel@tonic-gate tree_event2np_lut_lookup_event(struct lut *root, struct node *enp)
10117c478bd9Sstevel@tonic-gate {
10127c478bd9Sstevel@tonic-gate 	return ((struct node *)
10137c478bd9Sstevel@tonic-gate 	    lut_lookup_lhs(root, (void *)enp, (lut_cmp)tree_eventcmp));
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate static struct node *
10177c478bd9Sstevel@tonic-gate dodecl(enum nodetype t, const char *file, int line,
10187c478bd9Sstevel@tonic-gate     struct node *np, struct node *nvpairs, struct lut **lutpp,
10197c478bd9Sstevel@tonic-gate     struct stats *countp, int justpath)
10207c478bd9Sstevel@tonic-gate {
10217c478bd9Sstevel@tonic-gate 	struct node *ret;
10227c478bd9Sstevel@tonic-gate 	struct node *decl;
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate 	/* allocate parse tree node */
10257c478bd9Sstevel@tonic-gate 	ret = newnode(t, file, line);
10267c478bd9Sstevel@tonic-gate 	ret->u.stmt.np = np;
10277c478bd9Sstevel@tonic-gate 	ret->u.stmt.nvpairs = nvpairs;
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate 	/*
10307c478bd9Sstevel@tonic-gate 	 * the global lut pointed to by lutpp (Faults, Defects, Upsets,
10317c478bd9Sstevel@tonic-gate 	 * Errors, Ereports, Serds, FRUs, or ASRUs) keeps the first decl.
10327c478bd9Sstevel@tonic-gate 	 * if this isn't the first declr, we merge the
10337c478bd9Sstevel@tonic-gate 	 * nvpairs into the first decl so we have a
10347c478bd9Sstevel@tonic-gate 	 * merged table to look up properties from.
10357c478bd9Sstevel@tonic-gate 	 * if this is the first time we've seen this fault,
10367c478bd9Sstevel@tonic-gate 	 * we add it to the global lut and start lutp
10377c478bd9Sstevel@tonic-gate 	 * off with any nvpairs from this declaration statement.
10387c478bd9Sstevel@tonic-gate 	 */
10397c478bd9Sstevel@tonic-gate 	if (justpath && (decl = tree_name2np_lut_lookup(*lutpp, np)) == NULL) {
10407c478bd9Sstevel@tonic-gate 		/* this is the first time name is declared */
10417c478bd9Sstevel@tonic-gate 		stats_counter_bump(countp);
10427c478bd9Sstevel@tonic-gate 		*lutpp = tree_name2np_lut_add(*lutpp, np, ret);
10437c478bd9Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t);
10447c478bd9Sstevel@tonic-gate 	} else if (!justpath &&
10457c478bd9Sstevel@tonic-gate 	    (decl = tree_event2np_lut_lookup(*lutpp, np)) == NULL) {
10467c478bd9Sstevel@tonic-gate 		/* this is the first time event is declared */
10477c478bd9Sstevel@tonic-gate 		stats_counter_bump(countp);
10487c478bd9Sstevel@tonic-gate 		*lutpp = tree_event2np_lut_add(*lutpp, np, ret);
10497c478bd9Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t);
10507c478bd9Sstevel@tonic-gate 	} else {
10517c478bd9Sstevel@tonic-gate 		/* was declared before, just add new nvpairs to its lutp */
10527c478bd9Sstevel@tonic-gate 		decl->u.stmt.lutp = nvpair2lut(nvpairs, decl->u.stmt.lutp, t);
10537c478bd9Sstevel@tonic-gate 	}
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 	return (ret);
10567c478bd9Sstevel@tonic-gate }
10577c478bd9Sstevel@tonic-gate 
10587c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10597c478bd9Sstevel@tonic-gate static void
10607c478bd9Sstevel@tonic-gate update_serd_refstmt(void *lhs, void *rhs, void *arg)
10617c478bd9Sstevel@tonic-gate {
10627c478bd9Sstevel@tonic-gate 	struct node *serd;
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate 	ASSERT(rhs != NULL);
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 	serd = tree_s2np_lut_lookup(((struct node *)rhs)->u.stmt.lutp,
10677c478bd9Sstevel@tonic-gate 	    L_engine);
10687c478bd9Sstevel@tonic-gate 	if (serd == NULL)
10697c478bd9Sstevel@tonic-gate 		return;
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate 	ASSERT(serd->t == T_EVENT);
10727c478bd9Sstevel@tonic-gate 	if (arg != NULL && tree_eventcmp(serd, (struct node *)arg) != 0)
10737c478bd9Sstevel@tonic-gate 		return;
10747c478bd9Sstevel@tonic-gate 
10757c478bd9Sstevel@tonic-gate 	serd = tree_event2np_lut_lookup(SERDs, serd);
10767c478bd9Sstevel@tonic-gate 	if (serd != NULL)
10777c478bd9Sstevel@tonic-gate 		serd->u.stmt.flags |= STMT_REF;
10787c478bd9Sstevel@tonic-gate }
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate struct node *
10817c478bd9Sstevel@tonic-gate tree_decl(enum nodetype t, struct node *np, struct node *nvpairs,
10827c478bd9Sstevel@tonic-gate     const char *file, int line)
10837c478bd9Sstevel@tonic-gate {
10847c478bd9Sstevel@tonic-gate 	struct node *decl;
10857c478bd9Sstevel@tonic-gate 	struct node *ret;
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 	ASSERT(np != NULL);
10887c478bd9Sstevel@tonic-gate 
10897c478bd9Sstevel@tonic-gate 	check_type_iterator(np);
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	switch (t) {
10927c478bd9Sstevel@tonic-gate 	case T_EVENT:
10937c478bd9Sstevel@tonic-gate 		/* determine the type of event being declared */
10947c478bd9Sstevel@tonic-gate 		ASSERT(np->u.event.ename->t == T_NAME);
10957c478bd9Sstevel@tonic-gate 		switch (np->u.event.ename->u.name.t) {
10967c478bd9Sstevel@tonic-gate 		case N_FAULT:
10977c478bd9Sstevel@tonic-gate 			ret = dodecl(T_FAULT, file, line, np, nvpairs,
10987c478bd9Sstevel@tonic-gate 			    &Faults, Faultcount, 0);
1099*b7d3956bSstephh 
1100*b7d3956bSstephh 			/* increment serd statement reference */
1101*b7d3956bSstephh 			decl = tree_event2np_lut_lookup(Faults, np);
1102*b7d3956bSstephh 			update_serd_refstmt(NULL, decl, NULL);
11037c478bd9Sstevel@tonic-gate 			break;
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 		case N_UPSET:
11067c478bd9Sstevel@tonic-gate 			ret = dodecl(T_UPSET, file, line, np, nvpairs,
11077c478bd9Sstevel@tonic-gate 			    &Upsets, Upsetcount, 0);
11087c478bd9Sstevel@tonic-gate 
11097c478bd9Sstevel@tonic-gate 			/* increment serd statement reference */
11107c478bd9Sstevel@tonic-gate 			decl = tree_event2np_lut_lookup(Upsets, np);
11117c478bd9Sstevel@tonic-gate 			update_serd_refstmt(NULL, decl, NULL);
11127c478bd9Sstevel@tonic-gate 			break;
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate 		case N_DEFECT:
11157c478bd9Sstevel@tonic-gate 			ret = dodecl(T_DEFECT, file, line, np, nvpairs,
11167c478bd9Sstevel@tonic-gate 			    &Defects, Defectcount, 0);
1117*b7d3956bSstephh 
1118*b7d3956bSstephh 			/* increment serd statement reference */
1119*b7d3956bSstephh 			decl = tree_event2np_lut_lookup(Defects, np);
1120*b7d3956bSstephh 			update_serd_refstmt(NULL, decl, NULL);
11217c478bd9Sstevel@tonic-gate 			break;
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 		case N_ERROR:
11247c478bd9Sstevel@tonic-gate 			ret = dodecl(T_ERROR, file, line, np, nvpairs,
11257c478bd9Sstevel@tonic-gate 			    &Errors, Errorcount, 0);
11267c478bd9Sstevel@tonic-gate 			break;
11277c478bd9Sstevel@tonic-gate 
11287c478bd9Sstevel@tonic-gate 		case N_EREPORT:
11297c478bd9Sstevel@tonic-gate 			ret = dodecl(T_EREPORT, file, line, np, nvpairs,
11307c478bd9Sstevel@tonic-gate 			    &Ereports, Ereportcount, 0);
11317c478bd9Sstevel@tonic-gate 			/*
1132602ca9eaScth 			 * Keep a lut of just the enames, so that the DE
11337c478bd9Sstevel@tonic-gate 			 * can subscribe to a uniqified list of event
11347c478bd9Sstevel@tonic-gate 			 * classes.
11357c478bd9Sstevel@tonic-gate 			 */
11367c478bd9Sstevel@tonic-gate 			Ereportenames =
11377c478bd9Sstevel@tonic-gate 			    tree_name2np_lut_add(Ereportenames,
11387c478bd9Sstevel@tonic-gate 			    np->u.event.ename, np);
1139602ca9eaScth 
1140602ca9eaScth 			/*
1141602ca9eaScth 			 * Keep a lut of the enames (event classes) to
1142602ca9eaScth 			 * silently discard if we can't find a matching
1143602ca9eaScth 			 * configuration node when an ereport of of a given
1144602ca9eaScth 			 * class is received.  Such events are declaired
1145602ca9eaScth 			 * with 'discard_if_config_unknown=1'.
1146602ca9eaScth 			 */
1147602ca9eaScth 			if (tree_s2np_lut_lookup(ret->u.stmt.lutp,
1148602ca9eaScth 			    L_discard_if_config_unknown)) {
1149602ca9eaScth 				Ereportenames_discard = lut_add(
1150602ca9eaScth 				    Ereportenames_discard,
1151602ca9eaScth 				    (void *)np->u.event.ename->u.name.s,
1152602ca9eaScth 				    (void *)np->u.event.ename->u.name.s, NULL);
1153602ca9eaScth 			}
11547c478bd9Sstevel@tonic-gate 			break;
11557c478bd9Sstevel@tonic-gate 
11567c478bd9Sstevel@tonic-gate 		default:
11577c478bd9Sstevel@tonic-gate 			outfl(O_ERR, file, line,
11587c478bd9Sstevel@tonic-gate 			    "tree_decl: internal error, event name type %s",
11597c478bd9Sstevel@tonic-gate 			    ptree_nametype2str(np->u.event.ename->u.name.t));
11607c478bd9Sstevel@tonic-gate 		}
11617c478bd9Sstevel@tonic-gate 		break;
11627c478bd9Sstevel@tonic-gate 
11637c478bd9Sstevel@tonic-gate 	case T_ENGINE:
11647c478bd9Sstevel@tonic-gate 		/* determine the type of engine being declared */
11657c478bd9Sstevel@tonic-gate 		ASSERT(np->u.event.ename->t == T_NAME);
11667c478bd9Sstevel@tonic-gate 		switch (np->u.event.ename->u.name.t) {
11677c478bd9Sstevel@tonic-gate 		case N_SERD:
11687c478bd9Sstevel@tonic-gate 			ret = dodecl(T_SERD, file, line, np, nvpairs,
11697c478bd9Sstevel@tonic-gate 			    &SERDs, SERDcount, 0);
11707c478bd9Sstevel@tonic-gate 			lut_walk(Upsets, update_serd_refstmt, np);
11717c478bd9Sstevel@tonic-gate 			break;
11727c478bd9Sstevel@tonic-gate 
11737aec1d6eScindi 		case N_STAT:
11747aec1d6eScindi 			ret = dodecl(T_STAT, file, line, np, nvpairs,
11757aec1d6eScindi 			    &STATs, STATcount, 0);
11767aec1d6eScindi 			break;
11777aec1d6eScindi 
11787c478bd9Sstevel@tonic-gate 		default:
11797c478bd9Sstevel@tonic-gate 			outfl(O_ERR, file, line,
11807c478bd9Sstevel@tonic-gate 			    "tree_decl: internal error, engine name type %s",
11817c478bd9Sstevel@tonic-gate 			    ptree_nametype2str(np->u.event.ename->u.name.t));
11827c478bd9Sstevel@tonic-gate 		}
11837c478bd9Sstevel@tonic-gate 		break;
11847c478bd9Sstevel@tonic-gate 	case T_ASRU:
11857c478bd9Sstevel@tonic-gate 		ret = dodecl(T_ASRU, file, line, np, nvpairs,
11867c478bd9Sstevel@tonic-gate 		    &ASRUs, ASRUcount, 1);
11877c478bd9Sstevel@tonic-gate 		break;
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 	case T_FRU:
11907c478bd9Sstevel@tonic-gate 		ret = dodecl(T_FRU, file, line, np, nvpairs,
11917c478bd9Sstevel@tonic-gate 		    &FRUs, FRUcount, 1);
11927c478bd9Sstevel@tonic-gate 		break;
11937c478bd9Sstevel@tonic-gate 
11947c478bd9Sstevel@tonic-gate 	case T_CONFIG:
11957c478bd9Sstevel@tonic-gate 		/*
11967c478bd9Sstevel@tonic-gate 		 * config statements are different from above: they
11977c478bd9Sstevel@tonic-gate 		 * are not merged at all (until the configuration cache
11987c478bd9Sstevel@tonic-gate 		 * code does its own style of merging.  and the properties
11997c478bd9Sstevel@tonic-gate 		 * are a free-for-all -- we don't check for allowed or
12007c478bd9Sstevel@tonic-gate 		 * required config properties.
12017c478bd9Sstevel@tonic-gate 		 */
12027c478bd9Sstevel@tonic-gate 		ret = newnode(T_CONFIG, file, line);
12037c478bd9Sstevel@tonic-gate 		ret->u.stmt.np = np;
12047c478bd9Sstevel@tonic-gate 		ret->u.stmt.nvpairs = nvpairs;
12057c478bd9Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, T_CONFIG);
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate 		if (lut_lookup(Configs, np, (lut_cmp)tree_namecmp) == NULL)
12087c478bd9Sstevel@tonic-gate 			stats_counter_bump(Configcount);
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate 		Configs = lut_add(Configs, (void *)np, (void *)ret, NULL);
12117c478bd9Sstevel@tonic-gate 		break;
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate 	default:
12147c478bd9Sstevel@tonic-gate 		out(O_DIE, "tree_decl: internal error, type %s",
12157c478bd9Sstevel@tonic-gate 		    ptree_nodetype2str(t));
12167c478bd9Sstevel@tonic-gate 	}
12177c478bd9Sstevel@tonic-gate 
12187c478bd9Sstevel@tonic-gate 	return (ret);
12197c478bd9Sstevel@tonic-gate }
12207c478bd9Sstevel@tonic-gate 
12217c478bd9Sstevel@tonic-gate /* keep backpointers in arrows to the prop they belong to (used for scoping) */
12227c478bd9Sstevel@tonic-gate static void
12237c478bd9Sstevel@tonic-gate set_arrow_prop(struct node *prop, struct node *np)
12247c478bd9Sstevel@tonic-gate {
12257c478bd9Sstevel@tonic-gate 	if (np == NULL)
12267c478bd9Sstevel@tonic-gate 		return;
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate 	if (np->t == T_ARROW) {
12297c478bd9Sstevel@tonic-gate 		np->u.arrow.prop = prop;
12307c478bd9Sstevel@tonic-gate 		set_arrow_prop(prop, np->u.arrow.lhs);
12317c478bd9Sstevel@tonic-gate 		/*
12327c478bd9Sstevel@tonic-gate 		 * no need to recurse right or handle T_LIST since
12337c478bd9Sstevel@tonic-gate 		 * T_ARROWs always cascade left and are at the top
12347c478bd9Sstevel@tonic-gate 		 * of the parse tree.  (you can see this in the rule
12357c478bd9Sstevel@tonic-gate 		 * for "propbody" in escparse.y.)
12367c478bd9Sstevel@tonic-gate 		 */
12377c478bd9Sstevel@tonic-gate 	}
12387c478bd9Sstevel@tonic-gate }
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate struct node *
12417c478bd9Sstevel@tonic-gate tree_stmt(enum nodetype t, struct node *np, const char *file, int line)
12427c478bd9Sstevel@tonic-gate {
12437c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(t, file, line);
12447c478bd9Sstevel@tonic-gate 	struct node *pp;
12457c478bd9Sstevel@tonic-gate 	int inlist = 0;
12467c478bd9Sstevel@tonic-gate 
12477c478bd9Sstevel@tonic-gate 	ret->u.stmt.np = np;
12487c478bd9Sstevel@tonic-gate 
12497c478bd9Sstevel@tonic-gate 	switch (t) {
12507c478bd9Sstevel@tonic-gate 	case T_PROP:
1251f358d892Srw145199 		check_proplists(t, np);
12527c478bd9Sstevel@tonic-gate 		check_propnames(t, np, 0, 0);
12537c478bd9Sstevel@tonic-gate 		check_propscope(np);
12547c478bd9Sstevel@tonic-gate 		set_arrow_prop(ret, np);
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate 		for (pp = Props; pp; pp = pp->u.stmt.next) {
12577c478bd9Sstevel@tonic-gate 			if (tree_treecmp(pp, ret, T_NAME,
12587c478bd9Sstevel@tonic-gate 			    (lut_cmp)tree_namecmp) == 0) {
12597c478bd9Sstevel@tonic-gate 				inlist = 1;
12607c478bd9Sstevel@tonic-gate 				break;
12617c478bd9Sstevel@tonic-gate 			}
12627c478bd9Sstevel@tonic-gate 		}
12637c478bd9Sstevel@tonic-gate 		if (inlist == 0)
12647c478bd9Sstevel@tonic-gate 			stats_counter_bump(Propcount);
12657c478bd9Sstevel@tonic-gate 
12667c478bd9Sstevel@tonic-gate 		/* "Props" is a linked list of all prop statements */
12677c478bd9Sstevel@tonic-gate 		if (Lastprops)
12687c478bd9Sstevel@tonic-gate 			Lastprops->u.stmt.next = ret;
12697c478bd9Sstevel@tonic-gate 		else
12707c478bd9Sstevel@tonic-gate 			Props = ret;
12717c478bd9Sstevel@tonic-gate 		Lastprops = ret;
12727c478bd9Sstevel@tonic-gate 		break;
12737c478bd9Sstevel@tonic-gate 
12747c478bd9Sstevel@tonic-gate 	case T_MASK:
1275f358d892Srw145199 		check_proplists(t, np);
12767c478bd9Sstevel@tonic-gate 		check_propnames(t, np, 0, 0);
12777c478bd9Sstevel@tonic-gate 		check_propscope(np);
12787c478bd9Sstevel@tonic-gate 		set_arrow_prop(ret, np);
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 		for (pp = Masks; pp; pp = pp->u.stmt.next) {
12817c478bd9Sstevel@tonic-gate 			if (tree_treecmp(pp, ret, T_NAME,
12827c478bd9Sstevel@tonic-gate 			    (lut_cmp)tree_namecmp) == 0) {
12837c478bd9Sstevel@tonic-gate 				inlist = 1;
12847c478bd9Sstevel@tonic-gate 				break;
12857c478bd9Sstevel@tonic-gate 			}
12867c478bd9Sstevel@tonic-gate 		}
12877c478bd9Sstevel@tonic-gate 		if (inlist == 0)
12887c478bd9Sstevel@tonic-gate 			stats_counter_bump(Maskcount);
12897c478bd9Sstevel@tonic-gate 
12907c478bd9Sstevel@tonic-gate 		/* "Masks" is a linked list of all mask statements */
12917c478bd9Sstevel@tonic-gate 		if (Lastmasks)
12927c478bd9Sstevel@tonic-gate 			Lastmasks->u.stmt.next = ret;
12937c478bd9Sstevel@tonic-gate 		else
12947c478bd9Sstevel@tonic-gate 			Masks = ret;
12957c478bd9Sstevel@tonic-gate 		Lastmasks = ret;
12967c478bd9Sstevel@tonic-gate 		stats_counter_bump(Maskcount);
12977c478bd9Sstevel@tonic-gate 		break;
12987c478bd9Sstevel@tonic-gate 
12997c478bd9Sstevel@tonic-gate 	default:
13007c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np->file, np->line,
13017c478bd9Sstevel@tonic-gate 		    "tree_stmt: internal error (t %d)", t);
13027c478bd9Sstevel@tonic-gate 	}
13037c478bd9Sstevel@tonic-gate 
13047c478bd9Sstevel@tonic-gate 	return (ret);
13057c478bd9Sstevel@tonic-gate }
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate void
13087c478bd9Sstevel@tonic-gate tree_report()
13097c478bd9Sstevel@tonic-gate {
13107c478bd9Sstevel@tonic-gate 	/*
13117c478bd9Sstevel@tonic-gate 	 * The only declarations with required properties
13127c478bd9Sstevel@tonic-gate 	 * currently are faults and serds. Make sure the
13137c478bd9Sstevel@tonic-gate 	 * the declarations have the required properties.
13147c478bd9Sstevel@tonic-gate 	 */
13157c478bd9Sstevel@tonic-gate 	lut_walk(Faults, (lut_cb)check_required_props, (void *)T_FAULT);
13167c478bd9Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_required_props, (void *)T_UPSET);
13177c478bd9Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_required_props, (void *)T_ERROR);
13187c478bd9Sstevel@tonic-gate 	lut_walk(Ereports, (lut_cb)check_required_props, (void *)T_EREPORT);
13197c478bd9Sstevel@tonic-gate 	lut_walk(SERDs, (lut_cb)check_required_props, (void *)T_SERD);
13207aec1d6eScindi 	lut_walk(STATs, (lut_cb)check_required_props, (void *)T_STAT);
13217c478bd9Sstevel@tonic-gate 
13227c478bd9Sstevel@tonic-gate 	/*
13237c478bd9Sstevel@tonic-gate 	 * we do this now rather than while building the parse
13247c478bd9Sstevel@tonic-gate 	 * tree because it is inconvenient for the user if we
13257c478bd9Sstevel@tonic-gate 	 * require SERD engines to be declared before used in
13267c478bd9Sstevel@tonic-gate 	 * an upset "engine" property.
13277c478bd9Sstevel@tonic-gate 	 */
13287c478bd9Sstevel@tonic-gate 	lut_walk(Faults, (lut_cb)check_refcount, (void *)T_FAULT);
1329*b7d3956bSstephh 	lut_walk(Faults, (lut_cb)check_upset_engine, (void *)T_FAULT);
1330*b7d3956bSstephh 	lut_walk(Defects, (lut_cb)check_upset_engine, (void *)T_DEFECT);
13317c478bd9Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_upset_engine, (void *)T_UPSET);
13327c478bd9Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_refcount, (void *)T_UPSET);
13337c478bd9Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_refcount, (void *)T_ERROR);
13347c478bd9Sstevel@tonic-gate 	lut_walk(Ereports, (lut_cb)check_refcount, (void *)T_EREPORT);
13357c478bd9Sstevel@tonic-gate 	lut_walk(SERDs, (lut_cb)check_refcount, (void *)T_SERD);
13367c478bd9Sstevel@tonic-gate 
13377c478bd9Sstevel@tonic-gate 	/* check for cycles */
13387c478bd9Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_cycle, (void *)0);
13397c478bd9Sstevel@tonic-gate }
13407c478bd9Sstevel@tonic-gate 
13417c478bd9Sstevel@tonic-gate /* compare two T_NAMES by only looking at components, not iterators */
13427c478bd9Sstevel@tonic-gate int
13437c478bd9Sstevel@tonic-gate tree_namecmp(struct node *np1, struct node *np2)
13447c478bd9Sstevel@tonic-gate {
13457c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL);
13467c478bd9Sstevel@tonic-gate 	ASSERT(np2 != NULL);
13477c478bd9Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t));
13487c478bd9Sstevel@tonic-gate 	ASSERTinfo(np2->t == T_NAME, ptree_nodetype2str(np1->t));
13497c478bd9Sstevel@tonic-gate 
13507c478bd9Sstevel@tonic-gate 	while (np1 && np2 && np1->u.name.s == np2->u.name.s) {
13517c478bd9Sstevel@tonic-gate 		np1 = np1->u.name.next;
13527c478bd9Sstevel@tonic-gate 		np2 = np2->u.name.next;
13537c478bd9Sstevel@tonic-gate 	}
13547c478bd9Sstevel@tonic-gate 	if (np1 == NULL)
13557c478bd9Sstevel@tonic-gate 		if (np2 == NULL)
13567c478bd9Sstevel@tonic-gate 			return (0);
13577c478bd9Sstevel@tonic-gate 		else
13587c478bd9Sstevel@tonic-gate 			return (-1);
13597c478bd9Sstevel@tonic-gate 	else if (np2 == NULL)
13607c478bd9Sstevel@tonic-gate 		return (1);
13617c478bd9Sstevel@tonic-gate 	else
13627c478bd9Sstevel@tonic-gate 		return (np2->u.name.s - np1->u.name.s);
13637c478bd9Sstevel@tonic-gate }
13647c478bd9Sstevel@tonic-gate 
13657c478bd9Sstevel@tonic-gate int
13667c478bd9Sstevel@tonic-gate tree_eventcmp(struct node *np1, struct node *np2)
13677c478bd9Sstevel@tonic-gate {
13687c478bd9Sstevel@tonic-gate 	int ret;
13697c478bd9Sstevel@tonic-gate 
13707c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL);
13717c478bd9Sstevel@tonic-gate 	ASSERT(np2 != NULL);
13727c478bd9Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_EVENT, ptree_nodetype2str(np1->t));
13737c478bd9Sstevel@tonic-gate 	ASSERTinfo(np2->t == T_EVENT, ptree_nodetype2str(np2->t));
13747c478bd9Sstevel@tonic-gate 
13757c478bd9Sstevel@tonic-gate 	if ((ret = tree_namecmp(np1->u.event.ename,
13767c478bd9Sstevel@tonic-gate 	    np2->u.event.ename)) == 0) {
13777c478bd9Sstevel@tonic-gate 			if (np1->u.event.epname == NULL &&
13787c478bd9Sstevel@tonic-gate 			    np2->u.event.epname == NULL)
13797c478bd9Sstevel@tonic-gate 				return (0);
13807c478bd9Sstevel@tonic-gate 			else if (np1->u.event.epname == NULL)
13817c478bd9Sstevel@tonic-gate 				return (-1);
13827c478bd9Sstevel@tonic-gate 			else if (np2->u.event.epname == NULL)
13837c478bd9Sstevel@tonic-gate 				return (1);
13847c478bd9Sstevel@tonic-gate 			else
13857c478bd9Sstevel@tonic-gate 				return tree_namecmp(np1->u.event.epname,
13867c478bd9Sstevel@tonic-gate 				    np2->u.event.epname);
13877c478bd9Sstevel@tonic-gate 	} else
13887c478bd9Sstevel@tonic-gate 	return (ret);
13897c478bd9Sstevel@tonic-gate }
1390