xref: /onnv-gate/usr/src/cmd/fm/eversholt/common/tree.c (revision 854:c80cbb3274d6)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*854Srw145199  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  *
260Sstevel@tonic-gate  * tree.c -- routines for manipulating the prop tree
270Sstevel@tonic-gate  *
280Sstevel@tonic-gate  * the actions in escparse.y call these routines to construct
290Sstevel@tonic-gate  * the parse tree.  these routines, in turn, call the check_X()
300Sstevel@tonic-gate  * routines for semantic checking.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <stdio.h>
360Sstevel@tonic-gate #include <stdlib.h>
370Sstevel@tonic-gate #include <ctype.h>
380Sstevel@tonic-gate #include <strings.h>
390Sstevel@tonic-gate #include <alloca.h>
400Sstevel@tonic-gate #include "alloc.h"
410Sstevel@tonic-gate #include "out.h"
420Sstevel@tonic-gate #include "stats.h"
430Sstevel@tonic-gate #include "stable.h"
440Sstevel@tonic-gate #include "literals.h"
450Sstevel@tonic-gate #include "lut.h"
460Sstevel@tonic-gate #include "esclex.h"
470Sstevel@tonic-gate #include "tree.h"
480Sstevel@tonic-gate #include "check.h"
490Sstevel@tonic-gate #include "ptree.h"
500Sstevel@tonic-gate 
510Sstevel@tonic-gate static struct node *Root;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate static char *Newname;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate static struct stats *Faultcount;
560Sstevel@tonic-gate static struct stats *Upsetcount;
570Sstevel@tonic-gate static struct stats *Defectcount;
580Sstevel@tonic-gate static struct stats *Errorcount;
590Sstevel@tonic-gate static struct stats *Ereportcount;
600Sstevel@tonic-gate static struct stats *SERDcount;
610Sstevel@tonic-gate static struct stats *ASRUcount;
620Sstevel@tonic-gate static struct stats *FRUcount;
630Sstevel@tonic-gate static struct stats *Configcount;
640Sstevel@tonic-gate static struct stats *Propcount;
650Sstevel@tonic-gate static struct stats *Maskcount;
660Sstevel@tonic-gate static struct stats *Nodecount;
670Sstevel@tonic-gate static struct stats *Namecount;
680Sstevel@tonic-gate static struct stats *Nodesize;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate void
710Sstevel@tonic-gate tree_init(void)
720Sstevel@tonic-gate {
730Sstevel@tonic-gate 	Faultcount = stats_new_counter("parser.fault", "fault decls", 1);
740Sstevel@tonic-gate 	Upsetcount = stats_new_counter("parser.upset", "upset decls", 1);
750Sstevel@tonic-gate 	Defectcount = stats_new_counter("parser.defect", "defect decls", 1);
760Sstevel@tonic-gate 	Errorcount = stats_new_counter("parser.error", "error decls", 1);
770Sstevel@tonic-gate 	Ereportcount = stats_new_counter("parser.ereport", "ereport decls", 1);
780Sstevel@tonic-gate 	SERDcount = stats_new_counter("parser.SERD", "SERD engine decls", 1);
790Sstevel@tonic-gate 	ASRUcount = stats_new_counter("parser.ASRU", "ASRU decls", 1);
800Sstevel@tonic-gate 	FRUcount = stats_new_counter("parser.FRU", "FRU decls", 1);
810Sstevel@tonic-gate 	Configcount = stats_new_counter("parser.config", "config stmts", 1);
820Sstevel@tonic-gate 	Propcount = stats_new_counter("parser.prop", "prop stmts", 1);
830Sstevel@tonic-gate 	Maskcount = stats_new_counter("parser.mask", "mask stmts", 1);
840Sstevel@tonic-gate 	Nodecount = stats_new_counter("parser.node", "nodes created", 1);
850Sstevel@tonic-gate 	Namecount = stats_new_counter("parser.name", "names created", 1);
860Sstevel@tonic-gate 	Nodesize =
870Sstevel@tonic-gate 	    stats_new_counter("parser.nodesize", "sizeof(struct node)", 1);
880Sstevel@tonic-gate 	stats_counter_add(Nodesize, sizeof (struct node));
890Sstevel@tonic-gate }
900Sstevel@tonic-gate 
910Sstevel@tonic-gate void
920Sstevel@tonic-gate tree_fini(void)
930Sstevel@tonic-gate {
940Sstevel@tonic-gate 	stats_delete(Faultcount);
950Sstevel@tonic-gate 	stats_delete(Upsetcount);
960Sstevel@tonic-gate 	stats_delete(Defectcount);
970Sstevel@tonic-gate 	stats_delete(Errorcount);
980Sstevel@tonic-gate 	stats_delete(Ereportcount);
990Sstevel@tonic-gate 	stats_delete(SERDcount);
1000Sstevel@tonic-gate 	stats_delete(ASRUcount);
1010Sstevel@tonic-gate 	stats_delete(FRUcount);
1020Sstevel@tonic-gate 	stats_delete(Configcount);
1030Sstevel@tonic-gate 	stats_delete(Propcount);
1040Sstevel@tonic-gate 	stats_delete(Maskcount);
1050Sstevel@tonic-gate 	stats_delete(Nodecount);
1060Sstevel@tonic-gate 	stats_delete(Namecount);
1070Sstevel@tonic-gate 	stats_delete(Nodesize);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	/* free entire parse tree */
1100Sstevel@tonic-gate 	tree_free(Root);
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	/* free up the luts we keep for decls */
1130Sstevel@tonic-gate 	lut_free(Faults, NULL, NULL);
1140Sstevel@tonic-gate 	Faults = NULL;
1150Sstevel@tonic-gate 	lut_free(Upsets, NULL, NULL);
1160Sstevel@tonic-gate 	Upsets = NULL;
1170Sstevel@tonic-gate 	lut_free(Defects, NULL, NULL);
1180Sstevel@tonic-gate 	Defects = NULL;
1190Sstevel@tonic-gate 	lut_free(Errors, NULL, NULL);
1200Sstevel@tonic-gate 	Errors = NULL;
1210Sstevel@tonic-gate 	lut_free(Ereports, NULL, NULL);
1220Sstevel@tonic-gate 	Ereports = NULL;
1230Sstevel@tonic-gate 	lut_free(Ereportenames, NULL, NULL);
1240Sstevel@tonic-gate 	Ereportenames = NULL;
1250Sstevel@tonic-gate 	lut_free(SERDs, NULL, NULL);
1260Sstevel@tonic-gate 	SERDs = NULL;
1270Sstevel@tonic-gate 	lut_free(ASRUs, NULL, NULL);
1280Sstevel@tonic-gate 	ASRUs = NULL;
1290Sstevel@tonic-gate 	lut_free(FRUs, NULL, NULL);
1300Sstevel@tonic-gate 	FRUs = NULL;
1310Sstevel@tonic-gate 	lut_free(Configs, NULL, NULL);
1320Sstevel@tonic-gate 	Configs = NULL;
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	Props = Lastprops = NULL;
1350Sstevel@tonic-gate 	Masks = Lastmasks = NULL;
1360Sstevel@tonic-gate 	Problems = Lastproblems = NULL;
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	if (Newname != NULL) {
1390Sstevel@tonic-gate 		FREE(Newname);
1400Sstevel@tonic-gate 		Newname = NULL;
1410Sstevel@tonic-gate 	}
1420Sstevel@tonic-gate }
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate struct node *
1450Sstevel@tonic-gate newnode(enum nodetype t, const char *file, int line)
1460Sstevel@tonic-gate {
1470Sstevel@tonic-gate 	struct node *ret = MALLOC(sizeof (*ret));
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	stats_counter_bump(Nodecount);
1500Sstevel@tonic-gate 	bzero(ret, sizeof (*ret));
1510Sstevel@tonic-gate 	ret->t = t;
1520Sstevel@tonic-gate 	ret->file = (file == NULL) ? "<nofile>" : file;
1530Sstevel@tonic-gate 	ret->line = line;
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	return (ret);
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /*ARGSUSED*/
1590Sstevel@tonic-gate void
1600Sstevel@tonic-gate tree_free(struct node *root)
1610Sstevel@tonic-gate {
1620Sstevel@tonic-gate 	if (root == NULL)
1630Sstevel@tonic-gate 		return;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	switch (root->t) {
1660Sstevel@tonic-gate 	case T_NAME:
1670Sstevel@tonic-gate 		tree_free(root->u.name.child);
1680Sstevel@tonic-gate 		tree_free(root->u.name.next);
1690Sstevel@tonic-gate 		break;
1700Sstevel@tonic-gate 	case T_FUNC:
1710Sstevel@tonic-gate 		tree_free(root->u.func.arglist);
1720Sstevel@tonic-gate 		if (root->u.func.cachedval != NULL)
1730Sstevel@tonic-gate 			FREE(root->u.func.cachedval);
1740Sstevel@tonic-gate 		break;
1750Sstevel@tonic-gate 	case T_AND:
1760Sstevel@tonic-gate 	case T_OR:
1770Sstevel@tonic-gate 	case T_EQ:
1780Sstevel@tonic-gate 	case T_NE:
1790Sstevel@tonic-gate 	case T_ADD:
1800Sstevel@tonic-gate 	case T_DIV:
1810Sstevel@tonic-gate 	case T_MOD:
1820Sstevel@tonic-gate 	case T_MUL:
1830Sstevel@tonic-gate 	case T_SUB:
1840Sstevel@tonic-gate 	case T_LT:
1850Sstevel@tonic-gate 	case T_LE:
1860Sstevel@tonic-gate 	case T_GT:
1870Sstevel@tonic-gate 	case T_GE:
1880Sstevel@tonic-gate 	case T_BITAND:
1890Sstevel@tonic-gate 	case T_BITOR:
1900Sstevel@tonic-gate 	case T_BITXOR:
1910Sstevel@tonic-gate 	case T_BITNOT:
1920Sstevel@tonic-gate 	case T_LSHIFT:
1930Sstevel@tonic-gate 	case T_RSHIFT:
1940Sstevel@tonic-gate 	case T_NVPAIR:
1950Sstevel@tonic-gate 	case T_ASSIGN:
1960Sstevel@tonic-gate 	case T_CONDIF:
1970Sstevel@tonic-gate 	case T_CONDELSE:
1980Sstevel@tonic-gate 	case T_LIST:
1990Sstevel@tonic-gate 		tree_free(root->u.expr.left);
2000Sstevel@tonic-gate 		tree_free(root->u.expr.right);
2010Sstevel@tonic-gate 		break;
2020Sstevel@tonic-gate 	case T_EVENT:
2030Sstevel@tonic-gate 		tree_free(root->u.event.ename);
2040Sstevel@tonic-gate 		tree_free(root->u.event.epname);
2050Sstevel@tonic-gate 		tree_free(root->u.event.eexprlist);
2060Sstevel@tonic-gate 		break;
2070Sstevel@tonic-gate 	case T_NOT:
2080Sstevel@tonic-gate 		tree_free(root->u.expr.left);
2090Sstevel@tonic-gate 		break;
2100Sstevel@tonic-gate 	case T_ARROW:
2110Sstevel@tonic-gate 		tree_free(root->u.arrow.lhs);
2120Sstevel@tonic-gate 		tree_free(root->u.arrow.nnp);
2130Sstevel@tonic-gate 		tree_free(root->u.arrow.knp);
2140Sstevel@tonic-gate 		tree_free(root->u.arrow.rhs);
2150Sstevel@tonic-gate 		break;
2160Sstevel@tonic-gate 	case T_PROP:
2170Sstevel@tonic-gate 	case T_MASK:
2180Sstevel@tonic-gate 		tree_free(root->u.stmt.np);
2190Sstevel@tonic-gate 		break;
2200Sstevel@tonic-gate 	case T_FAULT:
2210Sstevel@tonic-gate 	case T_UPSET:
2220Sstevel@tonic-gate 	case T_DEFECT:
2230Sstevel@tonic-gate 	case T_ERROR:
2240Sstevel@tonic-gate 	case T_EREPORT:
2250Sstevel@tonic-gate 	case T_ASRU:
2260Sstevel@tonic-gate 	case T_FRU:
2270Sstevel@tonic-gate 	case T_SERD:
2280Sstevel@tonic-gate 	case T_CONFIG:
2290Sstevel@tonic-gate 		tree_free(root->u.stmt.np);
2300Sstevel@tonic-gate 		if (root->u.stmt.nvpairs)
2310Sstevel@tonic-gate 			tree_free(root->u.stmt.nvpairs);
2320Sstevel@tonic-gate 		if (root->u.stmt.lutp)
2330Sstevel@tonic-gate 			lut_free(root->u.stmt.lutp, NULL, NULL);
2340Sstevel@tonic-gate 		break;
2350Sstevel@tonic-gate 	case T_TIMEVAL:
2360Sstevel@tonic-gate 	case T_NUM:
2370Sstevel@tonic-gate 	case T_QUOTE:
2380Sstevel@tonic-gate 	case T_GLOBID:
2390Sstevel@tonic-gate 	case T_NOTHING:
2400Sstevel@tonic-gate 		break;
2410Sstevel@tonic-gate 	default:
2420Sstevel@tonic-gate 		out(O_DIE,
2430Sstevel@tonic-gate 		    "internal error: tree_free unexpected nodetype: %d",
2440Sstevel@tonic-gate 		    root->t);
2450Sstevel@tonic-gate 		/*NOTREACHED*/
2460Sstevel@tonic-gate 	}
2470Sstevel@tonic-gate 	bzero(root, sizeof (*root));
2480Sstevel@tonic-gate 	FREE(root);
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate static int
2520Sstevel@tonic-gate tree_treecmp(struct node *np1, struct node *np2, enum nodetype t,
2530Sstevel@tonic-gate 	    lut_cmp cmp_func)
2540Sstevel@tonic-gate {
2550Sstevel@tonic-gate 	if (np1 == NULL || np2 == NULL)
2560Sstevel@tonic-gate 		return (0);
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 	if (np1->t != np2->t)
2590Sstevel@tonic-gate 		return (1);
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 	ASSERT(cmp_func != NULL);
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	if (np1->t == t)
2640Sstevel@tonic-gate 		return ((*cmp_func)(np1, np2));
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate 	switch (np1->t) {
2670Sstevel@tonic-gate 	case T_NAME:
2680Sstevel@tonic-gate 		if (tree_treecmp(np1->u.name.child, np2->u.name.child, t,
2690Sstevel@tonic-gate 				cmp_func))
2700Sstevel@tonic-gate 			return (1);
2710Sstevel@tonic-gate 		return (tree_treecmp(np1->u.name.next, np2->u.name.next, t,
2720Sstevel@tonic-gate 				    cmp_func));
2730Sstevel@tonic-gate 		/*NOTREACHED*/
2740Sstevel@tonic-gate 		break;
2750Sstevel@tonic-gate 	case T_FUNC:
2760Sstevel@tonic-gate 		return (tree_treecmp(np1->u.func.arglist, np2->u.func.arglist,
2770Sstevel@tonic-gate 				    t, cmp_func));
2780Sstevel@tonic-gate 		/*NOTREACHED*/
2790Sstevel@tonic-gate 		break;
2800Sstevel@tonic-gate 	case T_AND:
2810Sstevel@tonic-gate 	case T_OR:
2820Sstevel@tonic-gate 	case T_EQ:
2830Sstevel@tonic-gate 	case T_NE:
2840Sstevel@tonic-gate 	case T_ADD:
2850Sstevel@tonic-gate 	case T_DIV:
2860Sstevel@tonic-gate 	case T_MOD:
2870Sstevel@tonic-gate 	case T_MUL:
2880Sstevel@tonic-gate 	case T_SUB:
2890Sstevel@tonic-gate 	case T_LT:
2900Sstevel@tonic-gate 	case T_LE:
2910Sstevel@tonic-gate 	case T_GT:
2920Sstevel@tonic-gate 	case T_GE:
2930Sstevel@tonic-gate 	case T_BITAND:
2940Sstevel@tonic-gate 	case T_BITOR:
2950Sstevel@tonic-gate 	case T_BITXOR:
2960Sstevel@tonic-gate 	case T_BITNOT:
2970Sstevel@tonic-gate 	case T_LSHIFT:
2980Sstevel@tonic-gate 	case T_RSHIFT:
2990Sstevel@tonic-gate 	case T_NVPAIR:
3000Sstevel@tonic-gate 	case T_ASSIGN:
3010Sstevel@tonic-gate 	case T_CONDIF:
3020Sstevel@tonic-gate 	case T_CONDELSE:
3030Sstevel@tonic-gate 	case T_LIST:
3040Sstevel@tonic-gate 		if (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t,
3050Sstevel@tonic-gate 				cmp_func))
3060Sstevel@tonic-gate 			return (1);
3070Sstevel@tonic-gate 		return (tree_treecmp(np1->u.expr.right, np2->u.expr.right, t,
3080Sstevel@tonic-gate 				    cmp_func));
3090Sstevel@tonic-gate 		/*NOTREACHED*/
3100Sstevel@tonic-gate 		break;
3110Sstevel@tonic-gate 	case T_EVENT:
3120Sstevel@tonic-gate 		if (tree_treecmp(np1->u.event.ename, np2->u.event.ename, t,
3130Sstevel@tonic-gate 				cmp_func))
3140Sstevel@tonic-gate 			return (1);
3150Sstevel@tonic-gate 		if (tree_treecmp(np1->u.event.epname, np2->u.event.epname, t,
3160Sstevel@tonic-gate 				cmp_func))
3170Sstevel@tonic-gate 			return (1);
3180Sstevel@tonic-gate 		return (tree_treecmp(np1->u.event.eexprlist,
3190Sstevel@tonic-gate 				    np2->u.event.eexprlist, t, cmp_func));
3200Sstevel@tonic-gate 		/*NOTREACHED*/
3210Sstevel@tonic-gate 		break;
3220Sstevel@tonic-gate 	case T_NOT:
3230Sstevel@tonic-gate 		return (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t,
3240Sstevel@tonic-gate 				    cmp_func));
3250Sstevel@tonic-gate 		/*NOTREACHED*/
3260Sstevel@tonic-gate 		break;
3270Sstevel@tonic-gate 	case T_ARROW:
3280Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.lhs, np2->u.arrow.lhs, t,
3290Sstevel@tonic-gate 				cmp_func))
3300Sstevel@tonic-gate 			return (1);
3310Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.nnp, np2->u.arrow.nnp, t,
3320Sstevel@tonic-gate 				cmp_func))
3330Sstevel@tonic-gate 			return (1);
3340Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.knp, np2->u.arrow.knp, t,
3350Sstevel@tonic-gate 				cmp_func))
3360Sstevel@tonic-gate 			return (1);
3370Sstevel@tonic-gate 		return (tree_treecmp(np1->u.arrow.rhs, np2->u.arrow.rhs, t,
3380Sstevel@tonic-gate 				    cmp_func));
3390Sstevel@tonic-gate 		/*NOTREACHED*/
3400Sstevel@tonic-gate 		break;
3410Sstevel@tonic-gate 	case T_PROP:
3420Sstevel@tonic-gate 	case T_MASK:
3430Sstevel@tonic-gate 		return (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t,
3440Sstevel@tonic-gate 				    cmp_func));
3450Sstevel@tonic-gate 		/*NOTREACHED*/
3460Sstevel@tonic-gate 		break;
3470Sstevel@tonic-gate 	case T_FAULT:
3480Sstevel@tonic-gate 	case T_UPSET:
3490Sstevel@tonic-gate 	case T_DEFECT:
3500Sstevel@tonic-gate 	case T_ERROR:
3510Sstevel@tonic-gate 	case T_EREPORT:
3520Sstevel@tonic-gate 	case T_ASRU:
3530Sstevel@tonic-gate 	case T_FRU:
3540Sstevel@tonic-gate 	case T_SERD:
3550Sstevel@tonic-gate 		if (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t, cmp_func))
3560Sstevel@tonic-gate 			return (1);
3570Sstevel@tonic-gate 		return (tree_treecmp(np1->u.stmt.nvpairs, np2->u.stmt.nvpairs,
3580Sstevel@tonic-gate 				    t, cmp_func));
3590Sstevel@tonic-gate 		/*NOTREACHED*/
3600Sstevel@tonic-gate 		break;
3610Sstevel@tonic-gate 	case T_TIMEVAL:
3620Sstevel@tonic-gate 	case T_NUM:
3630Sstevel@tonic-gate 	case T_QUOTE:
3640Sstevel@tonic-gate 	case T_GLOBID:
3650Sstevel@tonic-gate 	case T_NOTHING:
3660Sstevel@tonic-gate 		break;
3670Sstevel@tonic-gate 	default:
3680Sstevel@tonic-gate 		out(O_DIE,
3690Sstevel@tonic-gate 		    "internal error: tree_treecmp unexpected nodetype: %d",
3700Sstevel@tonic-gate 		    np1->t);
3710Sstevel@tonic-gate 		/*NOTREACHED*/
3720Sstevel@tonic-gate 		break;
3730Sstevel@tonic-gate 	}
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate 	return (0);
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate struct node *
3790Sstevel@tonic-gate tree_root(struct node *np)
3800Sstevel@tonic-gate {
3810Sstevel@tonic-gate 	if (np)
3820Sstevel@tonic-gate 		Root = np;
3830Sstevel@tonic-gate 	return (Root);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate struct node *
3870Sstevel@tonic-gate tree_nothing(void)
3880Sstevel@tonic-gate {
3890Sstevel@tonic-gate 	return (newnode(T_NOTHING, L_nofile, 0));
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate struct node *
3930Sstevel@tonic-gate tree_expr(enum nodetype t, struct node *left, struct node *right)
3940Sstevel@tonic-gate {
3950Sstevel@tonic-gate 	struct node *ret;
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate 	ASSERTinfo(left != NULL || right != NULL, ptree_nodetype2str(t));
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate 	ret = newnode(t,
4000Sstevel@tonic-gate 	    (left) ? left->file : right->file,
4010Sstevel@tonic-gate 	    (left) ? left->line : right->line);
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate 	ret->u.expr.left = left;
4040Sstevel@tonic-gate 	ret->u.expr.right = right;
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate 	check_expr(ret);
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate 	return (ret);
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate /*
4120Sstevel@tonic-gate  * ename_compress -- convert event class name in to more space-efficient form
4130Sstevel@tonic-gate  *
4140Sstevel@tonic-gate  * this routine is called after the parser has completed an "ename", which
4150Sstevel@tonic-gate  * is that part of an event that contains the class name (like ereport.x.y.z).
4160Sstevel@tonic-gate  * after this routine gets done with the ename, two things are true:
4170Sstevel@tonic-gate  *   1. the ename uses only a single struct node
4180Sstevel@tonic-gate  *   2. ename->u.name.s contains the *complete* class name, dots and all,
4190Sstevel@tonic-gate  *      entered into the string table.
4200Sstevel@tonic-gate  *
4210Sstevel@tonic-gate  * so in addition to saving space by using fewer struct nodes, this routine
4220Sstevel@tonic-gate  * allows consumers of the fault tree to assume the ename is a single
4230Sstevel@tonic-gate  * string, rather than a linked list of strings.
4240Sstevel@tonic-gate  */
4250Sstevel@tonic-gate static struct node *
4260Sstevel@tonic-gate ename_compress(struct node *ename)
4270Sstevel@tonic-gate {
4280Sstevel@tonic-gate 	char *buf;
4290Sstevel@tonic-gate 	char *cp;
4300Sstevel@tonic-gate 	int len = 0;
4310Sstevel@tonic-gate 	struct node *np;
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate 	if (ename == NULL)
4340Sstevel@tonic-gate 		return (ename);
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate 	ASSERT(ename->t == T_NAME);
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate 	if (ename->u.name.next == NULL)
4390Sstevel@tonic-gate 		return (ename);	/* no compression to be applied here */
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 	for (np = ename; np != NULL; np = np->u.name.next) {
4420Sstevel@tonic-gate 		ASSERT(np->t == T_NAME);
4430Sstevel@tonic-gate 		len++;	/* room for '.' and final '\0' */
4440Sstevel@tonic-gate 		len += strlen(np->u.name.s);
4450Sstevel@tonic-gate 	}
4460Sstevel@tonic-gate 	cp = buf = alloca(len);
4470Sstevel@tonic-gate 	for (np = ename; np != NULL; np = np->u.name.next) {
4480Sstevel@tonic-gate 		ASSERT(np->t == T_NAME);
4490Sstevel@tonic-gate 		if (np != ename)
4500Sstevel@tonic-gate 			*cp++ = '.';
4510Sstevel@tonic-gate 		(void) strcpy(cp, np->u.name.s);
4520Sstevel@tonic-gate 		cp += strlen(cp);
4530Sstevel@tonic-gate 	}
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate 	ename->u.name.s = stable(buf);
4560Sstevel@tonic-gate 	tree_free(ename->u.name.next);
4570Sstevel@tonic-gate 	ename->u.name.next = NULL;
4580Sstevel@tonic-gate 	ename->u.name.last = ename;
4590Sstevel@tonic-gate 	return (ename);
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate struct node *
4630Sstevel@tonic-gate tree_event(struct node *ename, struct node *epname, struct node *eexprlist)
4640Sstevel@tonic-gate {
4650Sstevel@tonic-gate 	struct node *ret;
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 	ASSERT(ename != NULL);
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate 	ret = newnode(T_EVENT, ename->file, ename->line);
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate 	ret->u.event.ename = ename_compress(ename);
4720Sstevel@tonic-gate 	ret->u.event.epname = epname;
4730Sstevel@tonic-gate 	ret->u.event.eexprlist = eexprlist;
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate 	check_event(ret);
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate 	return (ret);
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate struct node *
4810Sstevel@tonic-gate tree_name(const char *s, enum itertype it, const char *file, int line)
4820Sstevel@tonic-gate {
4830Sstevel@tonic-gate 	struct node *ret = newnode(T_NAME, file, line);
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 	ASSERT(s != NULL);
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate 	stats_counter_bump(Namecount);
4880Sstevel@tonic-gate 	ret->u.name.t = N_UNSPEC;
4890Sstevel@tonic-gate 	ret->u.name.s = stable(s);
4900Sstevel@tonic-gate 	ret->u.name.it = it;
4910Sstevel@tonic-gate 	ret->u.name.last = ret;
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate 	if (it == IT_ENAME) {
4940Sstevel@tonic-gate 		/* PHASE2, possible optimization: convert to table driven */
4950Sstevel@tonic-gate 		if (s == L_fault)
4960Sstevel@tonic-gate 			ret->u.name.t = N_FAULT;
4970Sstevel@tonic-gate 		else if (s == L_upset)
4980Sstevel@tonic-gate 			ret->u.name.t = N_UPSET;
4990Sstevel@tonic-gate 		else if (s == L_defect)
5000Sstevel@tonic-gate 			ret->u.name.t = N_DEFECT;
5010Sstevel@tonic-gate 		else if (s == L_error)
5020Sstevel@tonic-gate 			ret->u.name.t = N_ERROR;
5030Sstevel@tonic-gate 		else if (s == L_ereport)
5040Sstevel@tonic-gate 			ret->u.name.t = N_EREPORT;
5050Sstevel@tonic-gate 		else if (s == L_serd)
5060Sstevel@tonic-gate 			ret->u.name.t = N_SERD;
5070Sstevel@tonic-gate 		else
5080Sstevel@tonic-gate 			outfl(O_ERR, file, line, "unknown class: %s", s);
5090Sstevel@tonic-gate 	}
5100Sstevel@tonic-gate 	return (ret);
5110Sstevel@tonic-gate }
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate struct node *
5140Sstevel@tonic-gate tree_iname(const char *s, const char *file, int line)
5150Sstevel@tonic-gate {
5160Sstevel@tonic-gate 	struct node *ret;
5170Sstevel@tonic-gate 	char *ss;
5180Sstevel@tonic-gate 	char *ptr;
5190Sstevel@tonic-gate 
5200Sstevel@tonic-gate 	ASSERT(s != NULL && *s != '\0');
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate 	ss = STRDUP(s);
5230Sstevel@tonic-gate 
5240Sstevel@tonic-gate 	ptr = &ss[strlen(ss) - 1];
5250Sstevel@tonic-gate 	if (!isdigit(*ptr)) {
5260Sstevel@tonic-gate 		outfl(O_ERR, file, line,
5270Sstevel@tonic-gate 		    "instanced name expected (i.e. \"x0/y1\")");
5280Sstevel@tonic-gate 		FREE(ss);
5290Sstevel@tonic-gate 		return (tree_name(s, IT_NONE, file, line));
5300Sstevel@tonic-gate 	}
5310Sstevel@tonic-gate 	while (ptr > ss && isdigit(*(ptr - 1)))
5320Sstevel@tonic-gate 		ptr--;
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 	ret = newnode(T_NAME, file, line);
5350Sstevel@tonic-gate 	stats_counter_bump(Namecount);
5360Sstevel@tonic-gate 	ret->u.name.child = tree_num(ptr, file, line);
5370Sstevel@tonic-gate 	*ptr = '\0';
5380Sstevel@tonic-gate 	ret->u.name.t = N_UNSPEC;
5390Sstevel@tonic-gate 	ret->u.name.s = stable(ss);
5400Sstevel@tonic-gate 	ret->u.name.it = IT_NONE;
5410Sstevel@tonic-gate 	ret->u.name.last = ret;
5420Sstevel@tonic-gate 	FREE(ss);
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate 	return (ret);
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate struct node *
5480Sstevel@tonic-gate tree_globid(const char *s, const char *file, int line)
5490Sstevel@tonic-gate {
5500Sstevel@tonic-gate 	struct node *ret = newnode(T_GLOBID, file, line);
5510Sstevel@tonic-gate 
5520Sstevel@tonic-gate 	ASSERT(s != NULL);
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate 	ret->u.globid.s = stable(s);
5550Sstevel@tonic-gate 
5560Sstevel@tonic-gate 	return (ret);
5570Sstevel@tonic-gate }
5580Sstevel@tonic-gate 
5590Sstevel@tonic-gate struct node *
5600Sstevel@tonic-gate tree_name_append(struct node *np1, struct node *np2)
5610Sstevel@tonic-gate {
5620Sstevel@tonic-gate 	ASSERT(np1 != NULL && np2 != NULL);
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 	if (np1->t != T_NAME)
5650Sstevel@tonic-gate 		outfl(O_DIE, np1->file, np1->line,
5660Sstevel@tonic-gate 		    "tree_name_append: internal error (np1 type %d)", np1->t);
5670Sstevel@tonic-gate 	if (np2->t != T_NAME)
5680Sstevel@tonic-gate 		outfl(O_DIE, np2->file, np2->line,
5690Sstevel@tonic-gate 		    "tree_name_append: internal error (np2 type %d)", np2->t);
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate 	ASSERT(np1->u.name.last != NULL);
5720Sstevel@tonic-gate 
5730Sstevel@tonic-gate 	np1->u.name.last->u.name.next = np2;
5740Sstevel@tonic-gate 	np1->u.name.last = np2;
5750Sstevel@tonic-gate 	return (np1);
5760Sstevel@tonic-gate }
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate /*
5790Sstevel@tonic-gate  * tree_name_repairdash -- repair a class name that contained a dash
5800Sstevel@tonic-gate  *
5810Sstevel@tonic-gate  * this routine is called by the parser when a dash is encountered
5820Sstevel@tonic-gate  * in a class name.  the event protocol allows the dashes but our
5830Sstevel@tonic-gate  * lexer considers them a separate token (arithmetic minus).  an extra
5840Sstevel@tonic-gate  * rule in the parser catches this case and calls this routine to fixup
5850Sstevel@tonic-gate  * the last component of the class name (so far) by constructing the
5860Sstevel@tonic-gate  * new stable entry for a name including the dash.
5870Sstevel@tonic-gate  */
5880Sstevel@tonic-gate struct node *
5890Sstevel@tonic-gate tree_name_repairdash(struct node *np, const char *s)
5900Sstevel@tonic-gate {
5910Sstevel@tonic-gate 	int len;
5920Sstevel@tonic-gate 	char *buf;
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate 	ASSERT(np != NULL && s != NULL);
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate 	if (np->t != T_NAME)
5970Sstevel@tonic-gate 		outfl(O_DIE, np->file, np->line,
5980Sstevel@tonic-gate 		    "tree_name_repairdash: internal error (np type %d)",
5990Sstevel@tonic-gate 		    np->t);
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate 	ASSERT(np->u.name.last != NULL);
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate 	len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1;
6040Sstevel@tonic-gate 	buf = MALLOC(len);
6050Sstevel@tonic-gate 	(void) snprintf(buf, len, "%s-%s", np->u.name.last->u.name.s, s);
6060Sstevel@tonic-gate 	np->u.name.last->u.name.s = stable(buf);
6070Sstevel@tonic-gate 	FREE(buf);
6080Sstevel@tonic-gate 	return (np);
6090Sstevel@tonic-gate }
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate struct node *
6120Sstevel@tonic-gate tree_name_iterator(struct node *np1, struct node *np2)
6130Sstevel@tonic-gate {
6140Sstevel@tonic-gate 	ASSERT(np1 != NULL);
6150Sstevel@tonic-gate 	ASSERT(np2 != NULL);
6160Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t));
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate 	np1->u.name.child = np2;
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate 	check_name_iterator(np1);
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate 	return (np1);
6230Sstevel@tonic-gate }
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate struct node *
6260Sstevel@tonic-gate tree_timeval(const char *s, const char *suffix, const char *file, int line)
6270Sstevel@tonic-gate {
6280Sstevel@tonic-gate 	struct node *ret = newnode(T_TIMEVAL, file, line);
6290Sstevel@tonic-gate 	const unsigned long long *ullp;
6300Sstevel@tonic-gate 
6310Sstevel@tonic-gate 	ASSERT(s != NULL);
6320Sstevel@tonic-gate 	ASSERT(suffix != NULL);
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate 	if ((ullp = lex_s2ullp_lut_lookup(Timesuffixlut, suffix)) == NULL) {
6350Sstevel@tonic-gate 		outfl(O_ERR, file, line,
6360Sstevel@tonic-gate 		    "unrecognized number suffix: %s", suffix);
6370Sstevel@tonic-gate 		/* still construct a valid timeval node so parsing continues */
6380Sstevel@tonic-gate 		ret->u.ull = 1;
6390Sstevel@tonic-gate 	} else {
6400Sstevel@tonic-gate 		ret->u.ull = (unsigned long long)strtoul(s, NULL, 0) * *ullp;
6410Sstevel@tonic-gate 	}
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 	return (ret);
6440Sstevel@tonic-gate }
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate struct node *
6470Sstevel@tonic-gate tree_num(const char *s, const char *file, int line)
6480Sstevel@tonic-gate {
6490Sstevel@tonic-gate 	struct node *ret = newnode(T_NUM, file, line);
6500Sstevel@tonic-gate 
6510Sstevel@tonic-gate 	ret->u.ull = (unsigned long long)strtoul(s, NULL, 0);
6520Sstevel@tonic-gate 	return (ret);
6530Sstevel@tonic-gate }
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate struct node *
6560Sstevel@tonic-gate tree_quote(const char *s, const char *file, int line)
6570Sstevel@tonic-gate {
6580Sstevel@tonic-gate 	struct node *ret = newnode(T_QUOTE, file, line);
6590Sstevel@tonic-gate 
6600Sstevel@tonic-gate 	ret->u.quote.s = stable(s);
6610Sstevel@tonic-gate 	return (ret);
6620Sstevel@tonic-gate }
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate struct node *
6650Sstevel@tonic-gate tree_func(const char *s, struct node *np, const char *file, int line)
6660Sstevel@tonic-gate {
6670Sstevel@tonic-gate 	struct node *ret = newnode(T_FUNC, file, line);
6680Sstevel@tonic-gate 
6690Sstevel@tonic-gate 	ret->u.func.s = s;
6700Sstevel@tonic-gate 	ret->u.func.arglist = np;
6710Sstevel@tonic-gate 
6720Sstevel@tonic-gate 	check_func(ret);
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate 	return (ret);
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate 
6770Sstevel@tonic-gate /*
6780Sstevel@tonic-gate  * given a list from a prop or mask statement or a function argument,
6790Sstevel@tonic-gate  * convert all iterators to explicit iterators by inventing appropriate
6800Sstevel@tonic-gate  * iterator names.
6810Sstevel@tonic-gate  */
6820Sstevel@tonic-gate static void
6830Sstevel@tonic-gate make_explicit(struct node *np)
6840Sstevel@tonic-gate {
6850Sstevel@tonic-gate 	struct node *pnp;	/* component of pathname */
6860Sstevel@tonic-gate 	struct node *pnp2;
6870Sstevel@tonic-gate 	int count;
6880Sstevel@tonic-gate 	static size_t namesz;
6890Sstevel@tonic-gate 
6900Sstevel@tonic-gate 	if (Newname == NULL) {
6910Sstevel@tonic-gate 		namesz = 200;
6920Sstevel@tonic-gate 		Newname = MALLOC(namesz);
6930Sstevel@tonic-gate 	}
6940Sstevel@tonic-gate 
6950Sstevel@tonic-gate 	if (np == NULL)
6960Sstevel@tonic-gate 		return;		/* all done */
6970Sstevel@tonic-gate 
6980Sstevel@tonic-gate 	switch (np->t) {
6990Sstevel@tonic-gate 		case T_ARROW:
7000Sstevel@tonic-gate 			/* cascaded arrow, already done */
7010Sstevel@tonic-gate 			break;
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate 		case T_LIST:
7040Sstevel@tonic-gate 			make_explicit(np->u.expr.left);
7050Sstevel@tonic-gate 			make_explicit(np->u.expr.right);
7060Sstevel@tonic-gate 			break;
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 		case T_EVENT:
7090Sstevel@tonic-gate 			make_explicit(np->u.event.epname);
7100Sstevel@tonic-gate 			break;
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate 		case T_NAME:
7130Sstevel@tonic-gate 			for (pnp = np; pnp != NULL; pnp = pnp->u.name.next)
7140Sstevel@tonic-gate 				if (pnp->u.name.child == NULL) {
7150Sstevel@tonic-gate 					/*
7160Sstevel@tonic-gate 					 * found implicit iterator.  convert
7170Sstevel@tonic-gate 					 * it to an explicit iterator by
7180Sstevel@tonic-gate 					 * using the name of the component
7190Sstevel@tonic-gate 					 * appended with '#' and the number
7200Sstevel@tonic-gate 					 * of times we've seen this same
7210Sstevel@tonic-gate 					 * component name in this path so far.
7220Sstevel@tonic-gate 					 */
7230Sstevel@tonic-gate 					count = 0;
7240Sstevel@tonic-gate 					for (pnp2 = np; pnp2 != NULL;
7250Sstevel@tonic-gate 					    pnp2 = pnp2->u.name.next)
7260Sstevel@tonic-gate 						if (pnp2 == pnp)
7270Sstevel@tonic-gate 							break;
7280Sstevel@tonic-gate 						else if (pnp2->u.name.s ==
7290Sstevel@tonic-gate 						    pnp->u.name.s)
7300Sstevel@tonic-gate 							count++;
7310Sstevel@tonic-gate 
7320Sstevel@tonic-gate 					if (namesz < strlen(pnp->u.name.s) +
7330Sstevel@tonic-gate 					    100) {
7340Sstevel@tonic-gate 						namesz = strlen(pnp->u.name.s) +
7350Sstevel@tonic-gate 						    100;
7360Sstevel@tonic-gate 						FREE(Newname);
7370Sstevel@tonic-gate 						Newname = MALLOC(namesz);
7380Sstevel@tonic-gate 					}
7390Sstevel@tonic-gate 					/*
7400Sstevel@tonic-gate 					 * made up interator name is:
7410Sstevel@tonic-gate 					 *	name#ordinal
7420Sstevel@tonic-gate 					 * or
7430Sstevel@tonic-gate 					 *	name##ordinal
7440Sstevel@tonic-gate 					 * the first one is used for vertical
7450Sstevel@tonic-gate 					 * expansion, the second for horizontal.
7460Sstevel@tonic-gate 					 * either way, the '#' embedded in
7470Sstevel@tonic-gate 					 * the name makes it impossible to
7480Sstevel@tonic-gate 					 * collide with an actual iterator
7490Sstevel@tonic-gate 					 * given to us in the eversholt file.
7500Sstevel@tonic-gate 					 */
7510Sstevel@tonic-gate 					(void) snprintf(Newname, namesz,
7520Sstevel@tonic-gate 					    "%s#%s%d", pnp->u.name.s,
7530Sstevel@tonic-gate 					    (pnp->u.name.it == IT_HORIZONTAL) ?
7540Sstevel@tonic-gate 					    "#" : "", count);
7550Sstevel@tonic-gate 
7560Sstevel@tonic-gate 					pnp->u.name.child = tree_name(Newname,
7570Sstevel@tonic-gate 					    IT_NONE, pnp->file, pnp->line);
7580Sstevel@tonic-gate 					pnp->u.name.childgen = 1;
7590Sstevel@tonic-gate 				}
7600Sstevel@tonic-gate 			break;
7610Sstevel@tonic-gate 
7620Sstevel@tonic-gate 		default:
7630Sstevel@tonic-gate 			outfl(O_DIE, np->file, np->line,
7640Sstevel@tonic-gate 			    "internal error: make_explicit: "
7650Sstevel@tonic-gate 			    "unexpected type: %s",
7660Sstevel@tonic-gate 			    ptree_nodetype2str(np->t));
7670Sstevel@tonic-gate 	}
7680Sstevel@tonic-gate }
7690Sstevel@tonic-gate 
7700Sstevel@tonic-gate struct node *
7710Sstevel@tonic-gate tree_pname(struct node *np)
7720Sstevel@tonic-gate {
7730Sstevel@tonic-gate 	make_explicit(np);
7740Sstevel@tonic-gate 	return (np);
7750Sstevel@tonic-gate }
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate struct node *
7780Sstevel@tonic-gate tree_arrow(struct node *lhs, struct node *nnp, struct node *knp,
7790Sstevel@tonic-gate     struct node *rhs)
7800Sstevel@tonic-gate {
7810Sstevel@tonic-gate 	struct node *ret;
7820Sstevel@tonic-gate 
7830Sstevel@tonic-gate 	ASSERT(lhs != NULL || rhs != NULL);
7840Sstevel@tonic-gate 
7850Sstevel@tonic-gate 	ret = newnode(T_ARROW,
7860Sstevel@tonic-gate 	    (lhs) ? lhs->file : rhs->file,
7870Sstevel@tonic-gate 	    (lhs) ? lhs->line : rhs->line);
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 	ret->u.arrow.lhs = lhs;
7900Sstevel@tonic-gate 	ret->u.arrow.nnp = nnp;
7910Sstevel@tonic-gate 	ret->u.arrow.knp = knp;
7920Sstevel@tonic-gate 	ret->u.arrow.rhs = rhs;
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate 	make_explicit(lhs);
7950Sstevel@tonic-gate 	make_explicit(rhs);
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate 	check_arrow(ret);
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 	return (ret);
8000Sstevel@tonic-gate }
8010Sstevel@tonic-gate 
8020Sstevel@tonic-gate static struct lut *
8030Sstevel@tonic-gate nvpair2lut(struct node *np, struct lut *lutp, enum nodetype t)
8040Sstevel@tonic-gate {
8050Sstevel@tonic-gate 	if (np) {
8060Sstevel@tonic-gate 		if (np->t == T_NVPAIR) {
8070Sstevel@tonic-gate 			ASSERTeq(np->u.expr.left->t, T_NAME,
8080Sstevel@tonic-gate 			    ptree_nodetype2str);
8090Sstevel@tonic-gate 			check_stmt_allowed_properties(t, np, lutp);
8100Sstevel@tonic-gate 			lutp = tree_s2np_lut_add(lutp,
8110Sstevel@tonic-gate 			    np->u.expr.left->u.name.s, np->u.expr.right);
8120Sstevel@tonic-gate 		} else if (np->t == T_LIST) {
8130Sstevel@tonic-gate 			lutp = nvpair2lut(np->u.expr.left, lutp, t);
8140Sstevel@tonic-gate 			lutp = nvpair2lut(np->u.expr.right, lutp, t);
8150Sstevel@tonic-gate 		} else
8160Sstevel@tonic-gate 			outfl(O_DIE, np->file, np->line,
8170Sstevel@tonic-gate 			    "internal error: nvpair2lut type %s",
8180Sstevel@tonic-gate 			    ptree_nodetype2str(np->t));
8190Sstevel@tonic-gate 	}
8200Sstevel@tonic-gate 
8210Sstevel@tonic-gate 	return (lutp);
8220Sstevel@tonic-gate }
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate struct lut *
8250Sstevel@tonic-gate tree_s2np_lut_add(struct lut *root, const char *s, struct node *np)
8260Sstevel@tonic-gate {
8270Sstevel@tonic-gate 	return (lut_add(root, (void *)s, (void *)np, NULL));
8280Sstevel@tonic-gate }
8290Sstevel@tonic-gate 
8300Sstevel@tonic-gate struct node *
8310Sstevel@tonic-gate tree_s2np_lut_lookup(struct lut *root, const char *s)
8320Sstevel@tonic-gate {
8330Sstevel@tonic-gate 	return (struct node *)lut_lookup(root, (void *)s, NULL);
8340Sstevel@tonic-gate }
8350Sstevel@tonic-gate 
8360Sstevel@tonic-gate struct lut *
8370Sstevel@tonic-gate tree_name2np_lut_add(struct lut *root, struct node *namep, struct node *np)
8380Sstevel@tonic-gate {
8390Sstevel@tonic-gate 	return (lut_add(root, (void *)namep, (void *)np,
8400Sstevel@tonic-gate 	    (lut_cmp)tree_namecmp));
8410Sstevel@tonic-gate }
8420Sstevel@tonic-gate 
8430Sstevel@tonic-gate struct node *
8440Sstevel@tonic-gate tree_name2np_lut_lookup(struct lut *root, struct node *namep)
8450Sstevel@tonic-gate {
8460Sstevel@tonic-gate 	return (struct node *)
8470Sstevel@tonic-gate 	    lut_lookup(root, (void *)namep, (lut_cmp)tree_namecmp);
8480Sstevel@tonic-gate }
8490Sstevel@tonic-gate 
8500Sstevel@tonic-gate struct node *
8510Sstevel@tonic-gate tree_name2np_lut_lookup_name(struct lut *root, struct node *namep)
8520Sstevel@tonic-gate {
8530Sstevel@tonic-gate 	return (struct node *)
8540Sstevel@tonic-gate 	    lut_lookup_lhs(root, (void *)namep, (lut_cmp)tree_namecmp);
8550Sstevel@tonic-gate }
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate struct lut *
8580Sstevel@tonic-gate tree_event2np_lut_add(struct lut *root, struct node *enp, struct node *np)
8590Sstevel@tonic-gate {
8600Sstevel@tonic-gate 	return (lut_add(root, (void *)enp, (void *)np, (lut_cmp)tree_eventcmp));
8610Sstevel@tonic-gate }
8620Sstevel@tonic-gate 
8630Sstevel@tonic-gate struct node *
8640Sstevel@tonic-gate tree_event2np_lut_lookup(struct lut *root, struct node *enp)
8650Sstevel@tonic-gate {
8660Sstevel@tonic-gate 	return ((struct node *)
8670Sstevel@tonic-gate 	    lut_lookup(root, (void *)enp, (lut_cmp)tree_eventcmp));
8680Sstevel@tonic-gate }
8690Sstevel@tonic-gate 
8700Sstevel@tonic-gate struct node *
8710Sstevel@tonic-gate tree_event2np_lut_lookup_event(struct lut *root, struct node *enp)
8720Sstevel@tonic-gate {
8730Sstevel@tonic-gate 	return ((struct node *)
8740Sstevel@tonic-gate 	    lut_lookup_lhs(root, (void *)enp, (lut_cmp)tree_eventcmp));
8750Sstevel@tonic-gate }
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate static struct node *
8780Sstevel@tonic-gate dodecl(enum nodetype t, const char *file, int line,
8790Sstevel@tonic-gate     struct node *np, struct node *nvpairs, struct lut **lutpp,
8800Sstevel@tonic-gate     struct stats *countp, int justpath)
8810Sstevel@tonic-gate {
8820Sstevel@tonic-gate 	struct node *ret;
8830Sstevel@tonic-gate 	struct node *decl;
8840Sstevel@tonic-gate 
8850Sstevel@tonic-gate 	/* allocate parse tree node */
8860Sstevel@tonic-gate 	ret = newnode(t, file, line);
8870Sstevel@tonic-gate 	ret->u.stmt.np = np;
8880Sstevel@tonic-gate 	ret->u.stmt.nvpairs = nvpairs;
8890Sstevel@tonic-gate 
8900Sstevel@tonic-gate 	/*
8910Sstevel@tonic-gate 	 * the global lut pointed to by lutpp (Faults, Defects, Upsets,
8920Sstevel@tonic-gate 	 * Errors, Ereports, Serds, FRUs, or ASRUs) keeps the first decl.
8930Sstevel@tonic-gate 	 * if this isn't the first declr, we merge the
8940Sstevel@tonic-gate 	 * nvpairs into the first decl so we have a
8950Sstevel@tonic-gate 	 * merged table to look up properties from.
8960Sstevel@tonic-gate 	 * if this is the first time we've seen this fault,
8970Sstevel@tonic-gate 	 * we add it to the global lut and start lutp
8980Sstevel@tonic-gate 	 * off with any nvpairs from this declaration statement.
8990Sstevel@tonic-gate 	 */
9000Sstevel@tonic-gate 	if (justpath && (decl = tree_name2np_lut_lookup(*lutpp, np)) == NULL) {
9010Sstevel@tonic-gate 		/* this is the first time name is declared */
9020Sstevel@tonic-gate 		stats_counter_bump(countp);
9030Sstevel@tonic-gate 		*lutpp = tree_name2np_lut_add(*lutpp, np, ret);
9040Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t);
9050Sstevel@tonic-gate 	} else if (!justpath &&
9060Sstevel@tonic-gate 	    (decl = tree_event2np_lut_lookup(*lutpp, np)) == NULL) {
9070Sstevel@tonic-gate 		/* this is the first time event is declared */
9080Sstevel@tonic-gate 		stats_counter_bump(countp);
9090Sstevel@tonic-gate 		*lutpp = tree_event2np_lut_add(*lutpp, np, ret);
9100Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t);
9110Sstevel@tonic-gate 	} else {
9120Sstevel@tonic-gate 		/* was declared before, just add new nvpairs to its lutp */
9130Sstevel@tonic-gate 		decl->u.stmt.lutp = nvpair2lut(nvpairs, decl->u.stmt.lutp, t);
9140Sstevel@tonic-gate 	}
9150Sstevel@tonic-gate 
9160Sstevel@tonic-gate 	return (ret);
9170Sstevel@tonic-gate }
9180Sstevel@tonic-gate 
9190Sstevel@tonic-gate /*ARGSUSED*/
9200Sstevel@tonic-gate static void
9210Sstevel@tonic-gate update_serd_refstmt(void *lhs, void *rhs, void *arg)
9220Sstevel@tonic-gate {
9230Sstevel@tonic-gate 	struct node *serd;
9240Sstevel@tonic-gate 
9250Sstevel@tonic-gate 	ASSERT(rhs != NULL);
9260Sstevel@tonic-gate 
9270Sstevel@tonic-gate 	serd = tree_s2np_lut_lookup(((struct node *)rhs)->u.stmt.lutp,
9280Sstevel@tonic-gate 				    L_engine);
9290Sstevel@tonic-gate 	if (serd == NULL)
9300Sstevel@tonic-gate 		return;
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate 	ASSERT(serd->t == T_EVENT);
9330Sstevel@tonic-gate 	if (arg != NULL && tree_eventcmp(serd, (struct node *)arg) != 0)
9340Sstevel@tonic-gate 		return;
9350Sstevel@tonic-gate 
9360Sstevel@tonic-gate 	serd = tree_event2np_lut_lookup(SERDs, serd);
9370Sstevel@tonic-gate 	if (serd != NULL)
9380Sstevel@tonic-gate 		serd->u.stmt.flags |= STMT_REF;
9390Sstevel@tonic-gate }
9400Sstevel@tonic-gate 
9410Sstevel@tonic-gate struct node *
9420Sstevel@tonic-gate tree_decl(enum nodetype t, struct node *np, struct node *nvpairs,
9430Sstevel@tonic-gate     const char *file, int line)
9440Sstevel@tonic-gate {
9450Sstevel@tonic-gate 	struct node *decl;
9460Sstevel@tonic-gate 	struct node *ret;
9470Sstevel@tonic-gate 
9480Sstevel@tonic-gate 	ASSERT(np != NULL);
9490Sstevel@tonic-gate 
9500Sstevel@tonic-gate 	check_type_iterator(np);
9510Sstevel@tonic-gate 
9520Sstevel@tonic-gate 	switch (t) {
9530Sstevel@tonic-gate 	case T_EVENT:
9540Sstevel@tonic-gate 		/* determine the type of event being declared */
9550Sstevel@tonic-gate 		ASSERT(np->u.event.ename->t == T_NAME);
9560Sstevel@tonic-gate 		switch (np->u.event.ename->u.name.t) {
9570Sstevel@tonic-gate 		case N_FAULT:
9580Sstevel@tonic-gate 			ret = dodecl(T_FAULT, file, line, np, nvpairs,
9590Sstevel@tonic-gate 			    &Faults, Faultcount, 0);
9600Sstevel@tonic-gate 			break;
9610Sstevel@tonic-gate 
9620Sstevel@tonic-gate 		case N_UPSET:
9630Sstevel@tonic-gate 			ret = dodecl(T_UPSET, file, line, np, nvpairs,
9640Sstevel@tonic-gate 			    &Upsets, Upsetcount, 0);
9650Sstevel@tonic-gate 
9660Sstevel@tonic-gate 			/* increment serd statement reference */
9670Sstevel@tonic-gate 			decl = tree_event2np_lut_lookup(Upsets, np);
9680Sstevel@tonic-gate 			update_serd_refstmt(NULL, decl, NULL);
9690Sstevel@tonic-gate 			break;
9700Sstevel@tonic-gate 
9710Sstevel@tonic-gate 		case N_DEFECT:
9720Sstevel@tonic-gate 			ret = dodecl(T_DEFECT, file, line, np, nvpairs,
9730Sstevel@tonic-gate 			    &Defects, Defectcount, 0);
9740Sstevel@tonic-gate 			break;
9750Sstevel@tonic-gate 
9760Sstevel@tonic-gate 		case N_ERROR:
9770Sstevel@tonic-gate 			ret = dodecl(T_ERROR, file, line, np, nvpairs,
9780Sstevel@tonic-gate 			    &Errors, Errorcount, 0);
9790Sstevel@tonic-gate 			break;
9800Sstevel@tonic-gate 
9810Sstevel@tonic-gate 		case N_EREPORT:
9820Sstevel@tonic-gate 			ret = dodecl(T_EREPORT, file, line, np, nvpairs,
9830Sstevel@tonic-gate 			    &Ereports, Ereportcount, 0);
9840Sstevel@tonic-gate 			/*
9850Sstevel@tonic-gate 			 * keep a lut of just the enames, so that the DE
9860Sstevel@tonic-gate 			 * can subscribe to a uniqified list of event
9870Sstevel@tonic-gate 			 * classes.
9880Sstevel@tonic-gate 			 */
9890Sstevel@tonic-gate 			Ereportenames =
9900Sstevel@tonic-gate 			    tree_name2np_lut_add(Ereportenames,
9910Sstevel@tonic-gate 			    np->u.event.ename, np);
9920Sstevel@tonic-gate 			break;
9930Sstevel@tonic-gate 
9940Sstevel@tonic-gate 		default:
9950Sstevel@tonic-gate 			outfl(O_ERR, file, line,
9960Sstevel@tonic-gate 			    "tree_decl: internal error, event name type %s",
9970Sstevel@tonic-gate 			    ptree_nametype2str(np->u.event.ename->u.name.t));
9980Sstevel@tonic-gate 		}
9990Sstevel@tonic-gate 		break;
10000Sstevel@tonic-gate 
10010Sstevel@tonic-gate 	case T_ENGINE:
10020Sstevel@tonic-gate 		/* determine the type of engine being declared */
10030Sstevel@tonic-gate 		ASSERT(np->u.event.ename->t == T_NAME);
10040Sstevel@tonic-gate 		switch (np->u.event.ename->u.name.t) {
10050Sstevel@tonic-gate 		case N_SERD:
10060Sstevel@tonic-gate 			ret = dodecl(T_SERD, file, line, np, nvpairs,
10070Sstevel@tonic-gate 			    &SERDs, SERDcount, 0);
10080Sstevel@tonic-gate 			lut_walk(Upsets, update_serd_refstmt, np);
10090Sstevel@tonic-gate 			break;
10100Sstevel@tonic-gate 
10110Sstevel@tonic-gate 		default:
10120Sstevel@tonic-gate 			outfl(O_ERR, file, line,
10130Sstevel@tonic-gate 			    "tree_decl: internal error, engine name type %s",
10140Sstevel@tonic-gate 			    ptree_nametype2str(np->u.event.ename->u.name.t));
10150Sstevel@tonic-gate 		}
10160Sstevel@tonic-gate 		break;
10170Sstevel@tonic-gate 	case T_ASRU:
10180Sstevel@tonic-gate 		ret = dodecl(T_ASRU, file, line, np, nvpairs,
10190Sstevel@tonic-gate 		    &ASRUs, ASRUcount, 1);
10200Sstevel@tonic-gate 		break;
10210Sstevel@tonic-gate 
10220Sstevel@tonic-gate 	case T_FRU:
10230Sstevel@tonic-gate 		ret = dodecl(T_FRU, file, line, np, nvpairs,
10240Sstevel@tonic-gate 		    &FRUs, FRUcount, 1);
10250Sstevel@tonic-gate 		break;
10260Sstevel@tonic-gate 
10270Sstevel@tonic-gate 	case T_CONFIG:
10280Sstevel@tonic-gate 		/*
10290Sstevel@tonic-gate 		 * config statements are different from above: they
10300Sstevel@tonic-gate 		 * are not merged at all (until the configuration cache
10310Sstevel@tonic-gate 		 * code does its own style of merging.  and the properties
10320Sstevel@tonic-gate 		 * are a free-for-all -- we don't check for allowed or
10330Sstevel@tonic-gate 		 * required config properties.
10340Sstevel@tonic-gate 		 */
10350Sstevel@tonic-gate 		ret = newnode(T_CONFIG, file, line);
10360Sstevel@tonic-gate 		ret->u.stmt.np = np;
10370Sstevel@tonic-gate 		ret->u.stmt.nvpairs = nvpairs;
10380Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, T_CONFIG);
10390Sstevel@tonic-gate 
10400Sstevel@tonic-gate 		if (lut_lookup(Configs, np, (lut_cmp)tree_namecmp) == NULL)
10410Sstevel@tonic-gate 			stats_counter_bump(Configcount);
10420Sstevel@tonic-gate 
10430Sstevel@tonic-gate 		Configs = lut_add(Configs, (void *)np, (void *)ret, NULL);
10440Sstevel@tonic-gate 		break;
10450Sstevel@tonic-gate 
10460Sstevel@tonic-gate 	default:
10470Sstevel@tonic-gate 		out(O_DIE, "tree_decl: internal error, type %s",
10480Sstevel@tonic-gate 		    ptree_nodetype2str(t));
10490Sstevel@tonic-gate 	}
10500Sstevel@tonic-gate 
10510Sstevel@tonic-gate 	return (ret);
10520Sstevel@tonic-gate }
10530Sstevel@tonic-gate 
10540Sstevel@tonic-gate /* keep backpointers in arrows to the prop they belong to (used for scoping) */
10550Sstevel@tonic-gate static void
10560Sstevel@tonic-gate set_arrow_prop(struct node *prop, struct node *np)
10570Sstevel@tonic-gate {
10580Sstevel@tonic-gate 	if (np == NULL)
10590Sstevel@tonic-gate 		return;
10600Sstevel@tonic-gate 
10610Sstevel@tonic-gate 	if (np->t == T_ARROW) {
10620Sstevel@tonic-gate 		np->u.arrow.prop = prop;
10630Sstevel@tonic-gate 		set_arrow_prop(prop, np->u.arrow.lhs);
10640Sstevel@tonic-gate 		/*
10650Sstevel@tonic-gate 		 * no need to recurse right or handle T_LIST since
10660Sstevel@tonic-gate 		 * T_ARROWs always cascade left and are at the top
10670Sstevel@tonic-gate 		 * of the parse tree.  (you can see this in the rule
10680Sstevel@tonic-gate 		 * for "propbody" in escparse.y.)
10690Sstevel@tonic-gate 		 */
10700Sstevel@tonic-gate 	}
10710Sstevel@tonic-gate }
10720Sstevel@tonic-gate 
10730Sstevel@tonic-gate struct node *
10740Sstevel@tonic-gate tree_stmt(enum nodetype t, struct node *np, const char *file, int line)
10750Sstevel@tonic-gate {
10760Sstevel@tonic-gate 	struct node *ret = newnode(t, file, line);
10770Sstevel@tonic-gate 	struct node *pp;
10780Sstevel@tonic-gate 	int inlist = 0;
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate 	ret->u.stmt.np = np;
10810Sstevel@tonic-gate 
10820Sstevel@tonic-gate 	switch (t) {
10830Sstevel@tonic-gate 	case T_PROP:
1084*854Srw145199 		check_proplists(t, np);
10850Sstevel@tonic-gate 		check_propnames(t, np, 0, 0);
10860Sstevel@tonic-gate 		check_propscope(np);
10870Sstevel@tonic-gate 		set_arrow_prop(ret, np);
10880Sstevel@tonic-gate 
10890Sstevel@tonic-gate 		for (pp = Props; pp; pp = pp->u.stmt.next) {
10900Sstevel@tonic-gate 			if (tree_treecmp(pp, ret, T_NAME,
10910Sstevel@tonic-gate 					(lut_cmp)tree_namecmp) == 0) {
10920Sstevel@tonic-gate 				inlist = 1;
10930Sstevel@tonic-gate 				break;
10940Sstevel@tonic-gate 			}
10950Sstevel@tonic-gate 		}
10960Sstevel@tonic-gate 		if (inlist == 0)
10970Sstevel@tonic-gate 			stats_counter_bump(Propcount);
10980Sstevel@tonic-gate 
10990Sstevel@tonic-gate 		/* "Props" is a linked list of all prop statements */
11000Sstevel@tonic-gate 		if (Lastprops)
11010Sstevel@tonic-gate 			Lastprops->u.stmt.next = ret;
11020Sstevel@tonic-gate 		else
11030Sstevel@tonic-gate 			Props = ret;
11040Sstevel@tonic-gate 		Lastprops = ret;
11050Sstevel@tonic-gate 		break;
11060Sstevel@tonic-gate 
11070Sstevel@tonic-gate 	case T_MASK:
1108*854Srw145199 		check_proplists(t, np);
11090Sstevel@tonic-gate 		check_propnames(t, np, 0, 0);
11100Sstevel@tonic-gate 		check_propscope(np);
11110Sstevel@tonic-gate 		set_arrow_prop(ret, np);
11120Sstevel@tonic-gate 
11130Sstevel@tonic-gate 		for (pp = Masks; pp; pp = pp->u.stmt.next) {
11140Sstevel@tonic-gate 			if (tree_treecmp(pp, ret, T_NAME,
11150Sstevel@tonic-gate 					(lut_cmp)tree_namecmp) == 0) {
11160Sstevel@tonic-gate 				inlist = 1;
11170Sstevel@tonic-gate 				break;
11180Sstevel@tonic-gate 			}
11190Sstevel@tonic-gate 		}
11200Sstevel@tonic-gate 		if (inlist == 0)
11210Sstevel@tonic-gate 			stats_counter_bump(Maskcount);
11220Sstevel@tonic-gate 
11230Sstevel@tonic-gate 		/* "Masks" is a linked list of all mask statements */
11240Sstevel@tonic-gate 		if (Lastmasks)
11250Sstevel@tonic-gate 			Lastmasks->u.stmt.next = ret;
11260Sstevel@tonic-gate 		else
11270Sstevel@tonic-gate 			Masks = ret;
11280Sstevel@tonic-gate 		Lastmasks = ret;
11290Sstevel@tonic-gate 		stats_counter_bump(Maskcount);
11300Sstevel@tonic-gate 		break;
11310Sstevel@tonic-gate 
11320Sstevel@tonic-gate 	default:
11330Sstevel@tonic-gate 		outfl(O_DIE, np->file, np->line,
11340Sstevel@tonic-gate 		    "tree_stmt: internal error (t %d)", t);
11350Sstevel@tonic-gate 	}
11360Sstevel@tonic-gate 
11370Sstevel@tonic-gate 	return (ret);
11380Sstevel@tonic-gate }
11390Sstevel@tonic-gate 
11400Sstevel@tonic-gate void
11410Sstevel@tonic-gate tree_report()
11420Sstevel@tonic-gate {
11430Sstevel@tonic-gate 	/*
11440Sstevel@tonic-gate 	 * The only declarations with required properties
11450Sstevel@tonic-gate 	 * currently are faults and serds. Make sure the
11460Sstevel@tonic-gate 	 * the declarations have the required properties.
11470Sstevel@tonic-gate 	 */
11480Sstevel@tonic-gate 	lut_walk(Faults, (lut_cb)check_required_props, (void *)T_FAULT);
11490Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_required_props, (void *)T_UPSET);
11500Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_required_props, (void *)T_ERROR);
11510Sstevel@tonic-gate 	lut_walk(Ereports, (lut_cb)check_required_props, (void *)T_EREPORT);
11520Sstevel@tonic-gate 	lut_walk(SERDs, (lut_cb)check_required_props, (void *)T_SERD);
11530Sstevel@tonic-gate 
11540Sstevel@tonic-gate 	/*
11550Sstevel@tonic-gate 	 * we do this now rather than while building the parse
11560Sstevel@tonic-gate 	 * tree because it is inconvenient for the user if we
11570Sstevel@tonic-gate 	 * require SERD engines to be declared before used in
11580Sstevel@tonic-gate 	 * an upset "engine" property.
11590Sstevel@tonic-gate 	 */
11600Sstevel@tonic-gate 	lut_walk(Faults, (lut_cb)check_refcount, (void *)T_FAULT);
11610Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_upset_engine, (void *)T_UPSET);
11620Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_refcount, (void *)T_UPSET);
11630Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_refcount, (void *)T_ERROR);
11640Sstevel@tonic-gate 	lut_walk(Ereports, (lut_cb)check_refcount, (void *)T_EREPORT);
11650Sstevel@tonic-gate 	lut_walk(SERDs, (lut_cb)check_refcount, (void *)T_SERD);
11660Sstevel@tonic-gate 
11670Sstevel@tonic-gate 	/* check for cycles */
11680Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_cycle, (void *)0);
11690Sstevel@tonic-gate }
11700Sstevel@tonic-gate 
11710Sstevel@tonic-gate /* compare two T_NAMES by only looking at components, not iterators */
11720Sstevel@tonic-gate int
11730Sstevel@tonic-gate tree_namecmp(struct node *np1, struct node *np2)
11740Sstevel@tonic-gate {
11750Sstevel@tonic-gate 	ASSERT(np1 != NULL);
11760Sstevel@tonic-gate 	ASSERT(np2 != NULL);
11770Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t));
11780Sstevel@tonic-gate 	ASSERTinfo(np2->t == T_NAME, ptree_nodetype2str(np1->t));
11790Sstevel@tonic-gate 
11800Sstevel@tonic-gate 	while (np1 && np2 && np1->u.name.s == np2->u.name.s) {
11810Sstevel@tonic-gate 		np1 = np1->u.name.next;
11820Sstevel@tonic-gate 		np2 = np2->u.name.next;
11830Sstevel@tonic-gate 	}
11840Sstevel@tonic-gate 	if (np1 == NULL)
11850Sstevel@tonic-gate 		if (np2 == NULL)
11860Sstevel@tonic-gate 			return (0);
11870Sstevel@tonic-gate 		else
11880Sstevel@tonic-gate 			return (-1);
11890Sstevel@tonic-gate 	else if (np2 == NULL)
11900Sstevel@tonic-gate 		return (1);
11910Sstevel@tonic-gate 	else
11920Sstevel@tonic-gate 		return (np2->u.name.s - np1->u.name.s);
11930Sstevel@tonic-gate }
11940Sstevel@tonic-gate 
11950Sstevel@tonic-gate int
11960Sstevel@tonic-gate tree_eventcmp(struct node *np1, struct node *np2)
11970Sstevel@tonic-gate {
11980Sstevel@tonic-gate 	int ret;
11990Sstevel@tonic-gate 
12000Sstevel@tonic-gate 	ASSERT(np1 != NULL);
12010Sstevel@tonic-gate 	ASSERT(np2 != NULL);
12020Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_EVENT, ptree_nodetype2str(np1->t));
12030Sstevel@tonic-gate 	ASSERTinfo(np2->t == T_EVENT, ptree_nodetype2str(np2->t));
12040Sstevel@tonic-gate 
12050Sstevel@tonic-gate 	if ((ret = tree_namecmp(np1->u.event.ename,
12060Sstevel@tonic-gate 		np2->u.event.ename)) == 0) {
12070Sstevel@tonic-gate 			if (np1->u.event.epname == NULL &&
12080Sstevel@tonic-gate 				np2->u.event.epname == NULL)
12090Sstevel@tonic-gate 				return (0);
12100Sstevel@tonic-gate 			else if (np1->u.event.epname == NULL)
12110Sstevel@tonic-gate 				return (-1);
12120Sstevel@tonic-gate 			else if (np2->u.event.epname == NULL)
12130Sstevel@tonic-gate 				return (1);
12140Sstevel@tonic-gate 			else
12150Sstevel@tonic-gate 				return tree_namecmp(np1->u.event.epname,
12160Sstevel@tonic-gate 					np2->u.event.epname);
12170Sstevel@tonic-gate 	} else
12180Sstevel@tonic-gate 	return (ret);
12190Sstevel@tonic-gate }
1220