xref: /illumos-gate/usr/src/cmd/fm/eversholt/common/tree.c (revision cfc9ef1d)
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 #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <ctype.h>
357c478bd9Sstevel@tonic-gate #include <strings.h>
367c478bd9Sstevel@tonic-gate #include <alloca.h>
377c478bd9Sstevel@tonic-gate #include "alloc.h"
387c478bd9Sstevel@tonic-gate #include "out.h"
397c478bd9Sstevel@tonic-gate #include "stats.h"
407c478bd9Sstevel@tonic-gate #include "stable.h"
417c478bd9Sstevel@tonic-gate #include "literals.h"
427c478bd9Sstevel@tonic-gate #include "lut.h"
437c478bd9Sstevel@tonic-gate #include "esclex.h"
447c478bd9Sstevel@tonic-gate #include "tree.h"
457c478bd9Sstevel@tonic-gate #include "check.h"
467c478bd9Sstevel@tonic-gate #include "ptree.h"
477c478bd9Sstevel@tonic-gate 
48*cfc9ef1dSToomas Soome struct lut *Faults;
49*cfc9ef1dSToomas Soome struct lut *Upsets;
50*cfc9ef1dSToomas Soome struct lut *Defects;
51*cfc9ef1dSToomas Soome struct lut *Errors;
52*cfc9ef1dSToomas Soome struct lut *Ereports;
53*cfc9ef1dSToomas Soome struct lut *Ereportenames;
54*cfc9ef1dSToomas Soome struct lut *Ereportenames_discard;
55*cfc9ef1dSToomas Soome struct lut *SERDs;
56*cfc9ef1dSToomas Soome struct lut *STATs;
57*cfc9ef1dSToomas Soome struct lut *ASRUs;
58*cfc9ef1dSToomas Soome struct lut *FRUs;
59*cfc9ef1dSToomas Soome struct lut *Configs;
60*cfc9ef1dSToomas Soome struct node *Props;
61*cfc9ef1dSToomas Soome struct node *Lastprops;
62*cfc9ef1dSToomas Soome struct node *Masks;
63*cfc9ef1dSToomas Soome struct node *Lastmasks;
64*cfc9ef1dSToomas Soome struct node *Problems;
65*cfc9ef1dSToomas Soome struct node *Lastproblems;
667c478bd9Sstevel@tonic-gate 
67*cfc9ef1dSToomas Soome static struct node *Root;
687c478bd9Sstevel@tonic-gate static char *Newname;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate static struct stats *Faultcount;
717c478bd9Sstevel@tonic-gate static struct stats *Upsetcount;
727c478bd9Sstevel@tonic-gate static struct stats *Defectcount;
737c478bd9Sstevel@tonic-gate static struct stats *Errorcount;
747c478bd9Sstevel@tonic-gate static struct stats *Ereportcount;
757c478bd9Sstevel@tonic-gate static struct stats *SERDcount;
767aec1d6eScindi static struct stats *STATcount;
777c478bd9Sstevel@tonic-gate static struct stats *ASRUcount;
787c478bd9Sstevel@tonic-gate static struct stats *FRUcount;
797c478bd9Sstevel@tonic-gate static struct stats *Configcount;
807c478bd9Sstevel@tonic-gate static struct stats *Propcount;
817c478bd9Sstevel@tonic-gate static struct stats *Maskcount;
827c478bd9Sstevel@tonic-gate static struct stats *Nodecount;
837c478bd9Sstevel@tonic-gate static struct stats *Namecount;
847c478bd9Sstevel@tonic-gate static struct stats *Nodesize;
857c478bd9Sstevel@tonic-gate 
86b5016cbbSstephh struct lut *Usedprops;
87b5016cbbSstephh 
887c478bd9Sstevel@tonic-gate void
tree_init(void)897c478bd9Sstevel@tonic-gate tree_init(void)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate 	Faultcount = stats_new_counter("parser.fault", "fault decls", 1);
927c478bd9Sstevel@tonic-gate 	Upsetcount = stats_new_counter("parser.upset", "upset decls", 1);
937c478bd9Sstevel@tonic-gate 	Defectcount = stats_new_counter("parser.defect", "defect decls", 1);
947c478bd9Sstevel@tonic-gate 	Errorcount = stats_new_counter("parser.error", "error decls", 1);
957c478bd9Sstevel@tonic-gate 	Ereportcount = stats_new_counter("parser.ereport", "ereport decls", 1);
967c478bd9Sstevel@tonic-gate 	SERDcount = stats_new_counter("parser.SERD", "SERD engine decls", 1);
977aec1d6eScindi 	STATcount = stats_new_counter("parser.STAT", "STAT engine decls", 1);
987c478bd9Sstevel@tonic-gate 	ASRUcount = stats_new_counter("parser.ASRU", "ASRU decls", 1);
997c478bd9Sstevel@tonic-gate 	FRUcount = stats_new_counter("parser.FRU", "FRU decls", 1);
1007c478bd9Sstevel@tonic-gate 	Configcount = stats_new_counter("parser.config", "config stmts", 1);
1017c478bd9Sstevel@tonic-gate 	Propcount = stats_new_counter("parser.prop", "prop stmts", 1);
1027c478bd9Sstevel@tonic-gate 	Maskcount = stats_new_counter("parser.mask", "mask stmts", 1);
1037c478bd9Sstevel@tonic-gate 	Nodecount = stats_new_counter("parser.node", "nodes created", 1);
1047c478bd9Sstevel@tonic-gate 	Namecount = stats_new_counter("parser.name", "names created", 1);
1057c478bd9Sstevel@tonic-gate 	Nodesize =
1067c478bd9Sstevel@tonic-gate 	    stats_new_counter("parser.nodesize", "sizeof(struct node)", 1);
1077c478bd9Sstevel@tonic-gate 	stats_counter_add(Nodesize, sizeof (struct node));
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate void
tree_fini(void)1117c478bd9Sstevel@tonic-gate tree_fini(void)
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate 	stats_delete(Faultcount);
1147c478bd9Sstevel@tonic-gate 	stats_delete(Upsetcount);
1157c478bd9Sstevel@tonic-gate 	stats_delete(Defectcount);
1167c478bd9Sstevel@tonic-gate 	stats_delete(Errorcount);
1177c478bd9Sstevel@tonic-gate 	stats_delete(Ereportcount);
1187c478bd9Sstevel@tonic-gate 	stats_delete(SERDcount);
1197aec1d6eScindi 	stats_delete(STATcount);
1207c478bd9Sstevel@tonic-gate 	stats_delete(ASRUcount);
1217c478bd9Sstevel@tonic-gate 	stats_delete(FRUcount);
1227c478bd9Sstevel@tonic-gate 	stats_delete(Configcount);
1237c478bd9Sstevel@tonic-gate 	stats_delete(Propcount);
1247c478bd9Sstevel@tonic-gate 	stats_delete(Maskcount);
1257c478bd9Sstevel@tonic-gate 	stats_delete(Nodecount);
1267c478bd9Sstevel@tonic-gate 	stats_delete(Namecount);
1277c478bd9Sstevel@tonic-gate 	stats_delete(Nodesize);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	/* free entire parse tree */
1307c478bd9Sstevel@tonic-gate 	tree_free(Root);
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	/* free up the luts we keep for decls */
1337c478bd9Sstevel@tonic-gate 	lut_free(Faults, NULL, NULL);
1347c478bd9Sstevel@tonic-gate 	Faults = NULL;
1357c478bd9Sstevel@tonic-gate 	lut_free(Upsets, NULL, NULL);
1367c478bd9Sstevel@tonic-gate 	Upsets = NULL;
1377c478bd9Sstevel@tonic-gate 	lut_free(Defects, NULL, NULL);
1387c478bd9Sstevel@tonic-gate 	Defects = NULL;
1397c478bd9Sstevel@tonic-gate 	lut_free(Errors, NULL, NULL);
1407c478bd9Sstevel@tonic-gate 	Errors = NULL;
1417c478bd9Sstevel@tonic-gate 	lut_free(Ereports, NULL, NULL);
1427c478bd9Sstevel@tonic-gate 	Ereports = NULL;
1437c478bd9Sstevel@tonic-gate 	lut_free(Ereportenames, NULL, NULL);
1447c478bd9Sstevel@tonic-gate 	Ereportenames = NULL;
145602ca9eaScth 	lut_free(Ereportenames_discard, NULL, NULL);
146602ca9eaScth 	Ereportenames_discard = NULL;
1477c478bd9Sstevel@tonic-gate 	lut_free(SERDs, NULL, NULL);
1487c478bd9Sstevel@tonic-gate 	SERDs = NULL;
1497aec1d6eScindi 	lut_free(STATs, NULL, NULL);
1507aec1d6eScindi 	STATs = NULL;
1517c478bd9Sstevel@tonic-gate 	lut_free(ASRUs, NULL, NULL);
1527c478bd9Sstevel@tonic-gate 	ASRUs = NULL;
1537c478bd9Sstevel@tonic-gate 	lut_free(FRUs, NULL, NULL);
1547c478bd9Sstevel@tonic-gate 	FRUs = NULL;
1557c478bd9Sstevel@tonic-gate 	lut_free(Configs, NULL, NULL);
1567c478bd9Sstevel@tonic-gate 	Configs = NULL;
15727134bdaSstephh 	lut_free(Usedprops, NULL, NULL);
15827134bdaSstephh 	Usedprops = NULL;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	Props = Lastprops = NULL;
1617c478bd9Sstevel@tonic-gate 	Masks = Lastmasks = NULL;
1627c478bd9Sstevel@tonic-gate 	Problems = Lastproblems = NULL;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	if (Newname != NULL) {
1657c478bd9Sstevel@tonic-gate 		FREE(Newname);
1667c478bd9Sstevel@tonic-gate 		Newname = NULL;
1677c478bd9Sstevel@tonic-gate 	}
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate 
170b5016cbbSstephh /*ARGSUSED*/
171b5016cbbSstephh static int
nodesize(enum nodetype t,struct node * ret)172b5016cbbSstephh nodesize(enum nodetype t, struct node *ret)
173b5016cbbSstephh {
174b5016cbbSstephh 	int size = sizeof (struct node);
175b5016cbbSstephh 
176b5016cbbSstephh 	switch (t) {
177b5016cbbSstephh 	case T_NAME:
178b5016cbbSstephh 		size += sizeof (ret->u.name) - sizeof (ret->u);
179b5016cbbSstephh 		break;
180b5016cbbSstephh 
181b5016cbbSstephh 	case T_GLOBID:
182b5016cbbSstephh 		size += sizeof (ret->u.globid) - sizeof (ret->u);
183b5016cbbSstephh 		break;
184b5016cbbSstephh 
185b5016cbbSstephh 	case T_TIMEVAL:
186b5016cbbSstephh 	case T_NUM:
187b5016cbbSstephh 		size += sizeof (ret->u.ull) - sizeof (ret->u);
188b5016cbbSstephh 		break;
189b5016cbbSstephh 
190b5016cbbSstephh 	case T_QUOTE:
191b5016cbbSstephh 		size += sizeof (ret->u.quote) - sizeof (ret->u);
192b5016cbbSstephh 		break;
193b5016cbbSstephh 
194b5016cbbSstephh 	case T_FUNC:
195b5016cbbSstephh 		size += sizeof (ret->u.func) - sizeof (ret->u);
196b5016cbbSstephh 		break;
197b5016cbbSstephh 
198b5016cbbSstephh 	case T_FAULT:
199b5016cbbSstephh 	case T_UPSET:
200b5016cbbSstephh 	case T_DEFECT:
201b5016cbbSstephh 	case T_ERROR:
202b5016cbbSstephh 	case T_EREPORT:
203b5016cbbSstephh 	case T_ASRU:
204b5016cbbSstephh 	case T_FRU:
205b5016cbbSstephh 	case T_SERD:
206b5016cbbSstephh 	case T_STAT:
207b5016cbbSstephh 	case T_CONFIG:
208b5016cbbSstephh 	case T_PROP:
209b5016cbbSstephh 	case T_MASK:
210b5016cbbSstephh 		size += sizeof (ret->u.stmt) - sizeof (ret->u);
211b5016cbbSstephh 		break;
212b5016cbbSstephh 
213b5016cbbSstephh 	case T_EVENT:
214b5016cbbSstephh 		size += sizeof (ret->u.event) - sizeof (ret->u);
215b5016cbbSstephh 		break;
216b5016cbbSstephh 
217b5016cbbSstephh 	case T_ARROW:
218b5016cbbSstephh 		size += sizeof (ret->u.arrow) - sizeof (ret->u);
219b5016cbbSstephh 		break;
220b5016cbbSstephh 
221b5016cbbSstephh 	default:
222b5016cbbSstephh 		size += sizeof (ret->u.expr) - sizeof (ret->u);
223b5016cbbSstephh 		break;
224b5016cbbSstephh 	}
225b5016cbbSstephh 	return (size);
226b5016cbbSstephh }
227b5016cbbSstephh 
2287c478bd9Sstevel@tonic-gate struct node *
newnode(enum nodetype t,const char * file,int line)2297c478bd9Sstevel@tonic-gate newnode(enum nodetype t, const char *file, int line)
2307c478bd9Sstevel@tonic-gate {
231b5016cbbSstephh 	struct node *ret = NULL;
232b5016cbbSstephh 	int size = nodesize(t, ret);
2337c478bd9Sstevel@tonic-gate 
234b5016cbbSstephh 	ret = alloc_xmalloc(size);
2357c478bd9Sstevel@tonic-gate 	stats_counter_bump(Nodecount);
236b5016cbbSstephh 	bzero(ret, size);
2377c478bd9Sstevel@tonic-gate 	ret->t = t;
2387c478bd9Sstevel@tonic-gate 	ret->file = (file == NULL) ? "<nofile>" : file;
2397c478bd9Sstevel@tonic-gate 	ret->line = line;
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	return (ret);
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2457c478bd9Sstevel@tonic-gate void
tree_free(struct node * root)2467c478bd9Sstevel@tonic-gate tree_free(struct node *root)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate 	if (root == NULL)
2497c478bd9Sstevel@tonic-gate 		return;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	switch (root->t) {
2527c478bd9Sstevel@tonic-gate 	case T_NAME:
2537c478bd9Sstevel@tonic-gate 		tree_free(root->u.name.child);
2547c478bd9Sstevel@tonic-gate 		tree_free(root->u.name.next);
2557c478bd9Sstevel@tonic-gate 		break;
2567c478bd9Sstevel@tonic-gate 	case T_FUNC:
2577c478bd9Sstevel@tonic-gate 		tree_free(root->u.func.arglist);
2587c478bd9Sstevel@tonic-gate 		break;
2597c478bd9Sstevel@tonic-gate 	case T_AND:
2607c478bd9Sstevel@tonic-gate 	case T_OR:
2617c478bd9Sstevel@tonic-gate 	case T_EQ:
2627c478bd9Sstevel@tonic-gate 	case T_NE:
2637c478bd9Sstevel@tonic-gate 	case T_ADD:
2647c478bd9Sstevel@tonic-gate 	case T_DIV:
2657c478bd9Sstevel@tonic-gate 	case T_MOD:
2667c478bd9Sstevel@tonic-gate 	case T_MUL:
2677c478bd9Sstevel@tonic-gate 	case T_SUB:
2687c478bd9Sstevel@tonic-gate 	case T_LT:
2697c478bd9Sstevel@tonic-gate 	case T_LE:
2707c478bd9Sstevel@tonic-gate 	case T_GT:
2717c478bd9Sstevel@tonic-gate 	case T_GE:
2727c478bd9Sstevel@tonic-gate 	case T_BITAND:
2737c478bd9Sstevel@tonic-gate 	case T_BITOR:
2747c478bd9Sstevel@tonic-gate 	case T_BITXOR:
2757c478bd9Sstevel@tonic-gate 	case T_BITNOT:
2767c478bd9Sstevel@tonic-gate 	case T_LSHIFT:
2777c478bd9Sstevel@tonic-gate 	case T_RSHIFT:
2787c478bd9Sstevel@tonic-gate 	case T_NVPAIR:
2797c478bd9Sstevel@tonic-gate 	case T_ASSIGN:
2807c478bd9Sstevel@tonic-gate 	case T_CONDIF:
2817c478bd9Sstevel@tonic-gate 	case T_CONDELSE:
2827c478bd9Sstevel@tonic-gate 	case T_LIST:
2837c478bd9Sstevel@tonic-gate 		tree_free(root->u.expr.left);
2847c478bd9Sstevel@tonic-gate 		tree_free(root->u.expr.right);
2857c478bd9Sstevel@tonic-gate 		break;
2867c478bd9Sstevel@tonic-gate 	case T_EVENT:
2877c478bd9Sstevel@tonic-gate 		tree_free(root->u.event.ename);
2887c478bd9Sstevel@tonic-gate 		tree_free(root->u.event.epname);
2897c478bd9Sstevel@tonic-gate 		tree_free(root->u.event.eexprlist);
2907c478bd9Sstevel@tonic-gate 		break;
2917c478bd9Sstevel@tonic-gate 	case T_NOT:
2927c478bd9Sstevel@tonic-gate 		tree_free(root->u.expr.left);
2937c478bd9Sstevel@tonic-gate 		break;
2947c478bd9Sstevel@tonic-gate 	case T_ARROW:
2957c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.lhs);
2967c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.nnp);
2977c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.knp);
2987c478bd9Sstevel@tonic-gate 		tree_free(root->u.arrow.rhs);
2997c478bd9Sstevel@tonic-gate 		break;
3007c478bd9Sstevel@tonic-gate 	case T_PROP:
3017c478bd9Sstevel@tonic-gate 	case T_MASK:
3027c478bd9Sstevel@tonic-gate 		tree_free(root->u.stmt.np);
3037c478bd9Sstevel@tonic-gate 		break;
3047c478bd9Sstevel@tonic-gate 	case T_FAULT:
3057c478bd9Sstevel@tonic-gate 	case T_UPSET:
3067c478bd9Sstevel@tonic-gate 	case T_DEFECT:
3077c478bd9Sstevel@tonic-gate 	case T_ERROR:
3087c478bd9Sstevel@tonic-gate 	case T_EREPORT:
3097c478bd9Sstevel@tonic-gate 	case T_ASRU:
3107c478bd9Sstevel@tonic-gate 	case T_FRU:
3117c478bd9Sstevel@tonic-gate 	case T_SERD:
3127aec1d6eScindi 	case T_STAT:
3137c478bd9Sstevel@tonic-gate 	case T_CONFIG:
3147c478bd9Sstevel@tonic-gate 		tree_free(root->u.stmt.np);
3157c478bd9Sstevel@tonic-gate 		if (root->u.stmt.nvpairs)
3167c478bd9Sstevel@tonic-gate 			tree_free(root->u.stmt.nvpairs);
3177c478bd9Sstevel@tonic-gate 		if (root->u.stmt.lutp)
3187c478bd9Sstevel@tonic-gate 			lut_free(root->u.stmt.lutp, NULL, NULL);
3197c478bd9Sstevel@tonic-gate 		break;
3207c478bd9Sstevel@tonic-gate 	case T_TIMEVAL:
3217c478bd9Sstevel@tonic-gate 	case T_NUM:
3227c478bd9Sstevel@tonic-gate 	case T_QUOTE:
3237c478bd9Sstevel@tonic-gate 	case T_GLOBID:
3247c478bd9Sstevel@tonic-gate 	case T_NOTHING:
3257c478bd9Sstevel@tonic-gate 		break;
3267c478bd9Sstevel@tonic-gate 	default:
3277c478bd9Sstevel@tonic-gate 		out(O_DIE,
3287c478bd9Sstevel@tonic-gate 		    "internal error: tree_free unexpected nodetype: %d",
3297c478bd9Sstevel@tonic-gate 		    root->t);
3307c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3317c478bd9Sstevel@tonic-gate 	}
332b5016cbbSstephh 	alloc_xfree((char *)root, nodesize(root->t, root));
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate static int
tree_treecmp(struct node * np1,struct node * np2,enum nodetype t,lut_cmp cmp_func)3367c478bd9Sstevel@tonic-gate tree_treecmp(struct node *np1, struct node *np2, enum nodetype t,
337*cfc9ef1dSToomas Soome     lut_cmp cmp_func)
3387c478bd9Sstevel@tonic-gate {
3397c478bd9Sstevel@tonic-gate 	if (np1 == NULL || np2 == NULL)
3407c478bd9Sstevel@tonic-gate 		return (0);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	if (np1->t != np2->t)
3437c478bd9Sstevel@tonic-gate 		return (1);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	ASSERT(cmp_func != NULL);
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	if (np1->t == t)
3487c478bd9Sstevel@tonic-gate 		return ((*cmp_func)(np1, np2));
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	switch (np1->t) {
3517c478bd9Sstevel@tonic-gate 	case T_NAME:
3527c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.name.child, np2->u.name.child, t,
353b5016cbbSstephh 		    cmp_func))
3547c478bd9Sstevel@tonic-gate 			return (1);
3557c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.name.next, np2->u.name.next, t,
356b5016cbbSstephh 		    cmp_func));
3577c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3587c478bd9Sstevel@tonic-gate 		break;
3597c478bd9Sstevel@tonic-gate 	case T_FUNC:
3607c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.func.arglist, np2->u.func.arglist,
361b5016cbbSstephh 		    t, cmp_func));
3627c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3637c478bd9Sstevel@tonic-gate 		break;
3647c478bd9Sstevel@tonic-gate 	case T_AND:
3657c478bd9Sstevel@tonic-gate 	case T_OR:
3667c478bd9Sstevel@tonic-gate 	case T_EQ:
3677c478bd9Sstevel@tonic-gate 	case T_NE:
3687c478bd9Sstevel@tonic-gate 	case T_ADD:
3697c478bd9Sstevel@tonic-gate 	case T_DIV:
3707c478bd9Sstevel@tonic-gate 	case T_MOD:
3717c478bd9Sstevel@tonic-gate 	case T_MUL:
3727c478bd9Sstevel@tonic-gate 	case T_SUB:
3737c478bd9Sstevel@tonic-gate 	case T_LT:
3747c478bd9Sstevel@tonic-gate 	case T_LE:
3757c478bd9Sstevel@tonic-gate 	case T_GT:
3767c478bd9Sstevel@tonic-gate 	case T_GE:
3777c478bd9Sstevel@tonic-gate 	case T_BITAND:
3787c478bd9Sstevel@tonic-gate 	case T_BITOR:
3797c478bd9Sstevel@tonic-gate 	case T_BITXOR:
3807c478bd9Sstevel@tonic-gate 	case T_BITNOT:
3817c478bd9Sstevel@tonic-gate 	case T_LSHIFT:
3827c478bd9Sstevel@tonic-gate 	case T_RSHIFT:
3837c478bd9Sstevel@tonic-gate 	case T_NVPAIR:
3847c478bd9Sstevel@tonic-gate 	case T_ASSIGN:
3857c478bd9Sstevel@tonic-gate 	case T_CONDIF:
3867c478bd9Sstevel@tonic-gate 	case T_CONDELSE:
3877c478bd9Sstevel@tonic-gate 	case T_LIST:
3887c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t,
389b5016cbbSstephh 		    cmp_func))
3907c478bd9Sstevel@tonic-gate 			return (1);
3917c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.expr.right, np2->u.expr.right, t,
392b5016cbbSstephh 		    cmp_func));
3937c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3947c478bd9Sstevel@tonic-gate 		break;
3957c478bd9Sstevel@tonic-gate 	case T_EVENT:
3967c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.event.ename, np2->u.event.ename, t,
397b5016cbbSstephh 		    cmp_func))
3987c478bd9Sstevel@tonic-gate 			return (1);
3997c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.event.epname, np2->u.event.epname, t,
400b5016cbbSstephh 		    cmp_func))
4017c478bd9Sstevel@tonic-gate 			return (1);
4027c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.event.eexprlist,
403b5016cbbSstephh 		    np2->u.event.eexprlist, t, cmp_func));
4047c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4057c478bd9Sstevel@tonic-gate 		break;
4067c478bd9Sstevel@tonic-gate 	case T_NOT:
4077c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t,
408b5016cbbSstephh 		    cmp_func));
4097c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4107c478bd9Sstevel@tonic-gate 		break;
4117c478bd9Sstevel@tonic-gate 	case T_ARROW:
4127c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.lhs, np2->u.arrow.lhs, t,
413b5016cbbSstephh 		    cmp_func))
4147c478bd9Sstevel@tonic-gate 			return (1);
4157c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.nnp, np2->u.arrow.nnp, t,
416b5016cbbSstephh 		    cmp_func))
4177c478bd9Sstevel@tonic-gate 			return (1);
4187c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.arrow.knp, np2->u.arrow.knp, t,
419b5016cbbSstephh 		    cmp_func))
4207c478bd9Sstevel@tonic-gate 			return (1);
4217c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.arrow.rhs, np2->u.arrow.rhs, t,
422b5016cbbSstephh 		    cmp_func));
4237c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4247c478bd9Sstevel@tonic-gate 		break;
4257c478bd9Sstevel@tonic-gate 	case T_PROP:
4267c478bd9Sstevel@tonic-gate 	case T_MASK:
4277c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t,
428b5016cbbSstephh 		    cmp_func));
4297c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4307c478bd9Sstevel@tonic-gate 		break;
4317c478bd9Sstevel@tonic-gate 	case T_FAULT:
4327c478bd9Sstevel@tonic-gate 	case T_UPSET:
4337c478bd9Sstevel@tonic-gate 	case T_DEFECT:
4347c478bd9Sstevel@tonic-gate 	case T_ERROR:
4357c478bd9Sstevel@tonic-gate 	case T_EREPORT:
4367c478bd9Sstevel@tonic-gate 	case T_ASRU:
4377c478bd9Sstevel@tonic-gate 	case T_FRU:
4387c478bd9Sstevel@tonic-gate 	case T_SERD:
4397aec1d6eScindi 	case T_STAT:
4407c478bd9Sstevel@tonic-gate 		if (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t, cmp_func))
4417c478bd9Sstevel@tonic-gate 			return (1);
4427c478bd9Sstevel@tonic-gate 		return (tree_treecmp(np1->u.stmt.nvpairs, np2->u.stmt.nvpairs,
443b5016cbbSstephh 		    t, cmp_func));
4447c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4457c478bd9Sstevel@tonic-gate 		break;
4467c478bd9Sstevel@tonic-gate 	case T_TIMEVAL:
4477c478bd9Sstevel@tonic-gate 	case T_NUM:
4487c478bd9Sstevel@tonic-gate 	case T_QUOTE:
4497c478bd9Sstevel@tonic-gate 	case T_GLOBID:
4507c478bd9Sstevel@tonic-gate 	case T_NOTHING:
4517c478bd9Sstevel@tonic-gate 		break;
4527c478bd9Sstevel@tonic-gate 	default:
4537c478bd9Sstevel@tonic-gate 		out(O_DIE,
4547c478bd9Sstevel@tonic-gate 		    "internal error: tree_treecmp unexpected nodetype: %d",
4557c478bd9Sstevel@tonic-gate 		    np1->t);
4567c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4577c478bd9Sstevel@tonic-gate 		break;
4587c478bd9Sstevel@tonic-gate 	}
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 	return (0);
4617c478bd9Sstevel@tonic-gate }
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate struct node *
tree_root(struct node * np)4647c478bd9Sstevel@tonic-gate tree_root(struct node *np)
4657c478bd9Sstevel@tonic-gate {
4667c478bd9Sstevel@tonic-gate 	if (np)
4677c478bd9Sstevel@tonic-gate 		Root = np;
4687c478bd9Sstevel@tonic-gate 	return (Root);
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate struct node *
tree_nothing(void)4727c478bd9Sstevel@tonic-gate tree_nothing(void)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate 	return (newnode(T_NOTHING, L_nofile, 0));
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate struct node *
tree_expr(enum nodetype t,struct node * left,struct node * right)4787c478bd9Sstevel@tonic-gate tree_expr(enum nodetype t, struct node *left, struct node *right)
4797c478bd9Sstevel@tonic-gate {
4807c478bd9Sstevel@tonic-gate 	struct node *ret;
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 	ASSERTinfo(left != NULL || right != NULL, ptree_nodetype2str(t));
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 	ret = newnode(t,
4857c478bd9Sstevel@tonic-gate 	    (left) ? left->file : right->file,
4867c478bd9Sstevel@tonic-gate 	    (left) ? left->line : right->line);
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	ret->u.expr.left = left;
4897c478bd9Sstevel@tonic-gate 	ret->u.expr.right = right;
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	check_expr(ret);
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	return (ret);
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate /*
4977c478bd9Sstevel@tonic-gate  * ename_compress -- convert event class name in to more space-efficient form
4987c478bd9Sstevel@tonic-gate  *
4997c478bd9Sstevel@tonic-gate  * this routine is called after the parser has completed an "ename", which
5007c478bd9Sstevel@tonic-gate  * is that part of an event that contains the class name (like ereport.x.y.z).
5017c478bd9Sstevel@tonic-gate  * after this routine gets done with the ename, two things are true:
5027c478bd9Sstevel@tonic-gate  *   1. the ename uses only a single struct node
5037c478bd9Sstevel@tonic-gate  *   2. ename->u.name.s contains the *complete* class name, dots and all,
5047c478bd9Sstevel@tonic-gate  *      entered into the string table.
5057c478bd9Sstevel@tonic-gate  *
5067c478bd9Sstevel@tonic-gate  * so in addition to saving space by using fewer struct nodes, this routine
5077c478bd9Sstevel@tonic-gate  * allows consumers of the fault tree to assume the ename is a single
5087c478bd9Sstevel@tonic-gate  * string, rather than a linked list of strings.
5097c478bd9Sstevel@tonic-gate  */
5107c478bd9Sstevel@tonic-gate static struct node *
ename_compress(struct node * ename)5117c478bd9Sstevel@tonic-gate ename_compress(struct node *ename)
5127c478bd9Sstevel@tonic-gate {
5137c478bd9Sstevel@tonic-gate 	char *buf;
5147c478bd9Sstevel@tonic-gate 	char *cp;
5157c478bd9Sstevel@tonic-gate 	int len = 0;
5167c478bd9Sstevel@tonic-gate 	struct node *np;
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 	if (ename == NULL)
5197c478bd9Sstevel@tonic-gate 		return (ename);
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	ASSERT(ename->t == T_NAME);
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	if (ename->u.name.next == NULL)
5247c478bd9Sstevel@tonic-gate 		return (ename);	/* no compression to be applied here */
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	for (np = ename; np != NULL; np = np->u.name.next) {
5277c478bd9Sstevel@tonic-gate 		ASSERT(np->t == T_NAME);
5287c478bd9Sstevel@tonic-gate 		len++;	/* room for '.' and final '\0' */
5297c478bd9Sstevel@tonic-gate 		len += strlen(np->u.name.s);
5307c478bd9Sstevel@tonic-gate 	}
5317c478bd9Sstevel@tonic-gate 	cp = buf = alloca(len);
5327c478bd9Sstevel@tonic-gate 	for (np = ename; np != NULL; np = np->u.name.next) {
5337c478bd9Sstevel@tonic-gate 		ASSERT(np->t == T_NAME);
5347c478bd9Sstevel@tonic-gate 		if (np != ename)
5357c478bd9Sstevel@tonic-gate 			*cp++ = '.';
5367c478bd9Sstevel@tonic-gate 		(void) strcpy(cp, np->u.name.s);
5377c478bd9Sstevel@tonic-gate 		cp += strlen(cp);
5387c478bd9Sstevel@tonic-gate 	}
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 	ename->u.name.s = stable(buf);
5417c478bd9Sstevel@tonic-gate 	tree_free(ename->u.name.next);
5427c478bd9Sstevel@tonic-gate 	ename->u.name.next = NULL;
5437c478bd9Sstevel@tonic-gate 	ename->u.name.last = ename;
5447c478bd9Sstevel@tonic-gate 	return (ename);
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate struct node *
tree_event(struct node * ename,struct node * epname,struct node * eexprlist)5487c478bd9Sstevel@tonic-gate tree_event(struct node *ename, struct node *epname, struct node *eexprlist)
5497c478bd9Sstevel@tonic-gate {
5507c478bd9Sstevel@tonic-gate 	struct node *ret;
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	ASSERT(ename != NULL);
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	ret = newnode(T_EVENT, ename->file, ename->line);
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	ret->u.event.ename = ename_compress(ename);
5577c478bd9Sstevel@tonic-gate 	ret->u.event.epname = epname;
5587c478bd9Sstevel@tonic-gate 	ret->u.event.eexprlist = eexprlist;
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate 	check_event(ret);
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	return (ret);
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate struct node *
tree_name(const char * s,enum itertype it,const char * file,int line)5667c478bd9Sstevel@tonic-gate tree_name(const char *s, enum itertype it, const char *file, int line)
5677c478bd9Sstevel@tonic-gate {
5687c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_NAME, file, line);
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL);
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate 	stats_counter_bump(Namecount);
5737c478bd9Sstevel@tonic-gate 	ret->u.name.t = N_UNSPEC;
5747c478bd9Sstevel@tonic-gate 	ret->u.name.s = stable(s);
5757c478bd9Sstevel@tonic-gate 	ret->u.name.it = it;
5767c478bd9Sstevel@tonic-gate 	ret->u.name.last = ret;
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate 	if (it == IT_ENAME) {
5797c478bd9Sstevel@tonic-gate 		/* PHASE2, possible optimization: convert to table driven */
5807c478bd9Sstevel@tonic-gate 		if (s == L_fault)
5817c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_FAULT;
5827c478bd9Sstevel@tonic-gate 		else if (s == L_upset)
5837c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_UPSET;
5847c478bd9Sstevel@tonic-gate 		else if (s == L_defect)
5857c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_DEFECT;
5867c478bd9Sstevel@tonic-gate 		else if (s == L_error)
5877c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_ERROR;
5887c478bd9Sstevel@tonic-gate 		else if (s == L_ereport)
5897c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_EREPORT;
5907c478bd9Sstevel@tonic-gate 		else if (s == L_serd)
5917c478bd9Sstevel@tonic-gate 			ret->u.name.t = N_SERD;
5927aec1d6eScindi 		else if (s == L_stat)
5937aec1d6eScindi 			ret->u.name.t = N_STAT;
5947c478bd9Sstevel@tonic-gate 		else
5957c478bd9Sstevel@tonic-gate 			outfl(O_ERR, file, line, "unknown class: %s", s);
5967c478bd9Sstevel@tonic-gate 	}
5977c478bd9Sstevel@tonic-gate 	return (ret);
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate struct node *
tree_iname(const char * s,const char * file,int line)6017c478bd9Sstevel@tonic-gate tree_iname(const char *s, const char *file, int line)
6027c478bd9Sstevel@tonic-gate {
6037c478bd9Sstevel@tonic-gate 	struct node *ret;
6047c478bd9Sstevel@tonic-gate 	char *ss;
6057c478bd9Sstevel@tonic-gate 	char *ptr;
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL && *s != '\0');
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	ss = STRDUP(s);
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	ptr = &ss[strlen(ss) - 1];
6127c478bd9Sstevel@tonic-gate 	if (!isdigit(*ptr)) {
6137c478bd9Sstevel@tonic-gate 		outfl(O_ERR, file, line,
6147c478bd9Sstevel@tonic-gate 		    "instanced name expected (i.e. \"x0/y1\")");
6157c478bd9Sstevel@tonic-gate 		FREE(ss);
6167c478bd9Sstevel@tonic-gate 		return (tree_name(s, IT_NONE, file, line));
6177c478bd9Sstevel@tonic-gate 	}
6187c478bd9Sstevel@tonic-gate 	while (ptr > ss && isdigit(*(ptr - 1)))
6197c478bd9Sstevel@tonic-gate 		ptr--;
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	ret = newnode(T_NAME, file, line);
6227c478bd9Sstevel@tonic-gate 	stats_counter_bump(Namecount);
6237c478bd9Sstevel@tonic-gate 	ret->u.name.child = tree_num(ptr, file, line);
6247c478bd9Sstevel@tonic-gate 	*ptr = '\0';
6257c478bd9Sstevel@tonic-gate 	ret->u.name.t = N_UNSPEC;
6267c478bd9Sstevel@tonic-gate 	ret->u.name.s = stable(ss);
6277c478bd9Sstevel@tonic-gate 	ret->u.name.it = IT_NONE;
6287c478bd9Sstevel@tonic-gate 	ret->u.name.last = ret;
6297c478bd9Sstevel@tonic-gate 	FREE(ss);
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate 	return (ret);
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate struct node *
tree_globid(const char * s,const char * file,int line)6357c478bd9Sstevel@tonic-gate tree_globid(const char *s, const char *file, int line)
6367c478bd9Sstevel@tonic-gate {
6377c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_GLOBID, file, line);
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL);
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 	ret->u.globid.s = stable(s);
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	return (ret);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate struct node *
tree_name_append(struct node * np1,struct node * np2)6477c478bd9Sstevel@tonic-gate tree_name_append(struct node *np1, struct node *np2)
6487c478bd9Sstevel@tonic-gate {
6497c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL && np2 != NULL);
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	if (np1->t != T_NAME)
6527c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np1->file, np1->line,
6537c478bd9Sstevel@tonic-gate 		    "tree_name_append: internal error (np1 type %d)", np1->t);
6547c478bd9Sstevel@tonic-gate 	if (np2->t != T_NAME)
6557c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np2->file, np2->line,
6567c478bd9Sstevel@tonic-gate 		    "tree_name_append: internal error (np2 type %d)", np2->t);
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	ASSERT(np1->u.name.last != NULL);
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	np1->u.name.last->u.name.next = np2;
6617c478bd9Sstevel@tonic-gate 	np1->u.name.last = np2;
6627c478bd9Sstevel@tonic-gate 	return (np1);
6637c478bd9Sstevel@tonic-gate }
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate /*
6667c478bd9Sstevel@tonic-gate  * tree_name_repairdash -- repair a class name that contained a dash
6677c478bd9Sstevel@tonic-gate  *
6687c478bd9Sstevel@tonic-gate  * this routine is called by the parser when a dash is encountered
6697c478bd9Sstevel@tonic-gate  * in a class name.  the event protocol allows the dashes but our
6707c478bd9Sstevel@tonic-gate  * lexer considers them a separate token (arithmetic minus).  an extra
6717c478bd9Sstevel@tonic-gate  * rule in the parser catches this case and calls this routine to fixup
6727c478bd9Sstevel@tonic-gate  * the last component of the class name (so far) by constructing the
6737c478bd9Sstevel@tonic-gate  * new stable entry for a name including the dash.
6747c478bd9Sstevel@tonic-gate  */
6757c478bd9Sstevel@tonic-gate struct node *
tree_name_repairdash(struct node * np,const char * s)6767c478bd9Sstevel@tonic-gate tree_name_repairdash(struct node *np, const char *s)
6777c478bd9Sstevel@tonic-gate {
6787c478bd9Sstevel@tonic-gate 	int len;
6797c478bd9Sstevel@tonic-gate 	char *buf;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	ASSERT(np != NULL && s != NULL);
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	if (np->t != T_NAME)
6847c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np->file, np->line,
6857c478bd9Sstevel@tonic-gate 		    "tree_name_repairdash: internal error (np type %d)",
6867c478bd9Sstevel@tonic-gate 		    np->t);
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 	ASSERT(np->u.name.last != NULL);
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 	len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1;
6917c478bd9Sstevel@tonic-gate 	buf = MALLOC(len);
6927c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, len, "%s-%s", np->u.name.last->u.name.s, s);
6937c478bd9Sstevel@tonic-gate 	np->u.name.last->u.name.s = stable(buf);
6947c478bd9Sstevel@tonic-gate 	FREE(buf);
6957c478bd9Sstevel@tonic-gate 	return (np);
6967c478bd9Sstevel@tonic-gate }
6977c478bd9Sstevel@tonic-gate 
6988a40a695Sgavinm struct node *
tree_name_repairdash2(const char * s,struct node * np)6998a40a695Sgavinm tree_name_repairdash2(const char *s, struct node *np)
7008a40a695Sgavinm {
7018a40a695Sgavinm 	int len;
7028a40a695Sgavinm 	char *buf;
7038a40a695Sgavinm 
7048a40a695Sgavinm 	ASSERT(np != NULL && s != NULL);
7058a40a695Sgavinm 
7068a40a695Sgavinm 	if (np->t != T_NAME)
7078a40a695Sgavinm 		outfl(O_DIE, np->file, np->line,
7088a40a695Sgavinm 		    "tree_name_repairdash: internal error (np type %d)",
7098a40a695Sgavinm 		    np->t);
7108a40a695Sgavinm 
7118a40a695Sgavinm 	ASSERT(np->u.name.last != NULL);
7128a40a695Sgavinm 
7138a40a695Sgavinm 	len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1;
7148a40a695Sgavinm 	buf = MALLOC(len);
7158a40a695Sgavinm 	(void) snprintf(buf, len, "%s-%s", s, np->u.name.last->u.name.s);
7168a40a695Sgavinm 	np->u.name.last->u.name.s = stable(buf);
7178a40a695Sgavinm 	FREE(buf);
7188a40a695Sgavinm 	return (np);
7198a40a695Sgavinm }
7208a40a695Sgavinm 
7217c478bd9Sstevel@tonic-gate struct node *
tree_name_iterator(struct node * np1,struct node * np2)7227c478bd9Sstevel@tonic-gate tree_name_iterator(struct node *np1, struct node *np2)
7237c478bd9Sstevel@tonic-gate {
7247c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL);
7257c478bd9Sstevel@tonic-gate 	ASSERT(np2 != NULL);
7267c478bd9Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t));
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate 	np1->u.name.child = np2;
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate 	check_name_iterator(np1);
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 	return (np1);
7337c478bd9Sstevel@tonic-gate }
7347c478bd9Sstevel@tonic-gate 
7357c478bd9Sstevel@tonic-gate struct node *
tree_timeval(const char * s,const char * suffix,const char * file,int line)7367c478bd9Sstevel@tonic-gate tree_timeval(const char *s, const char *suffix, const char *file, int line)
7377c478bd9Sstevel@tonic-gate {
7387c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_TIMEVAL, file, line);
7397c478bd9Sstevel@tonic-gate 	const unsigned long long *ullp;
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate 	ASSERT(s != NULL);
7427c478bd9Sstevel@tonic-gate 	ASSERT(suffix != NULL);
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 	if ((ullp = lex_s2ullp_lut_lookup(Timesuffixlut, suffix)) == NULL) {
7457c478bd9Sstevel@tonic-gate 		outfl(O_ERR, file, line,
7467c478bd9Sstevel@tonic-gate 		    "unrecognized number suffix: %s", suffix);
7477c478bd9Sstevel@tonic-gate 		/* still construct a valid timeval node so parsing continues */
7487c478bd9Sstevel@tonic-gate 		ret->u.ull = 1;
7497c478bd9Sstevel@tonic-gate 	} else {
7507c478bd9Sstevel@tonic-gate 		ret->u.ull = (unsigned long long)strtoul(s, NULL, 0) * *ullp;
7517c478bd9Sstevel@tonic-gate 	}
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 	return (ret);
7547c478bd9Sstevel@tonic-gate }
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate struct node *
tree_num(const char * s,const char * file,int line)7577c478bd9Sstevel@tonic-gate tree_num(const char *s, const char *file, int line)
7587c478bd9Sstevel@tonic-gate {
7597c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_NUM, file, line);
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 	ret->u.ull = (unsigned long long)strtoul(s, NULL, 0);
7627c478bd9Sstevel@tonic-gate 	return (ret);
7637c478bd9Sstevel@tonic-gate }
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate struct node *
tree_quote(const char * s,const char * file,int line)7667c478bd9Sstevel@tonic-gate tree_quote(const char *s, const char *file, int line)
7677c478bd9Sstevel@tonic-gate {
7687c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_QUOTE, file, line);
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 	ret->u.quote.s = stable(s);
7717c478bd9Sstevel@tonic-gate 	return (ret);
7727c478bd9Sstevel@tonic-gate }
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate struct node *
tree_func(const char * s,struct node * np,const char * file,int line)7757c478bd9Sstevel@tonic-gate tree_func(const char *s, struct node *np, const char *file, int line)
7767c478bd9Sstevel@tonic-gate {
7777c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(T_FUNC, file, line);
778b5016cbbSstephh 	const char *ptr;
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate 	ret->u.func.s = s;
7817c478bd9Sstevel@tonic-gate 	ret->u.func.arglist = np;
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate 	check_func(ret);
7847c478bd9Sstevel@tonic-gate 
785b5016cbbSstephh 	/*
786b5016cbbSstephh 	 * keep track of the properties we're interested in so we can ignore the
787b5016cbbSstephh 	 * rest
788b5016cbbSstephh 	 */
789b5016cbbSstephh 	if (strcmp(s, L_confprop) == 0 || strcmp(s, L_confprop_defined) == 0) {
790b5016cbbSstephh 		ptr = stable(np->u.expr.right->u.quote.s);
791b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
792b5016cbbSstephh 	} else if (strcmp(s, L_is_connected) == 0) {
793b5016cbbSstephh 		ptr = stable("connected");
794b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
795b5016cbbSstephh 		ptr = stable("CONNECTED");
796b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
797b5016cbbSstephh 	} else if (strcmp(s, L_is_type) == 0) {
798b5016cbbSstephh 		ptr = stable("type");
799b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
800b5016cbbSstephh 		ptr = stable("TYPE");
801b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
802b5016cbbSstephh 	} else if (strcmp(s, L_is_on) == 0) {
803b5016cbbSstephh 		ptr = stable("on");
804b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
805b5016cbbSstephh 		ptr = stable("ON");
806b5016cbbSstephh 		Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL);
807b5016cbbSstephh 	}
808b5016cbbSstephh 
8097c478bd9Sstevel@tonic-gate 	return (ret);
8107c478bd9Sstevel@tonic-gate }
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate /*
8137c478bd9Sstevel@tonic-gate  * given a list from a prop or mask statement or a function argument,
8147c478bd9Sstevel@tonic-gate  * convert all iterators to explicit iterators by inventing appropriate
8157c478bd9Sstevel@tonic-gate  * iterator names.
8167c478bd9Sstevel@tonic-gate  */
8177c478bd9Sstevel@tonic-gate static void
make_explicit(struct node * np,int eventonly)8187aec1d6eScindi make_explicit(struct node *np, int eventonly)
8197c478bd9Sstevel@tonic-gate {
8207c478bd9Sstevel@tonic-gate 	struct node *pnp;	/* component of pathname */
8217c478bd9Sstevel@tonic-gate 	struct node *pnp2;
8227c478bd9Sstevel@tonic-gate 	int count;
8237c478bd9Sstevel@tonic-gate 	static size_t namesz;
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 	if (Newname == NULL) {
8267c478bd9Sstevel@tonic-gate 		namesz = 200;
8277c478bd9Sstevel@tonic-gate 		Newname = MALLOC(namesz);
8287c478bd9Sstevel@tonic-gate 	}
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	if (np == NULL)
8317c478bd9Sstevel@tonic-gate 		return;		/* all done */
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 	switch (np->t) {
8347aec1d6eScindi 		case T_ASSIGN:
8357aec1d6eScindi 		case T_CONDIF:
8367aec1d6eScindi 		case T_CONDELSE:
8377aec1d6eScindi 		case T_NE:
8387aec1d6eScindi 		case T_EQ:
8397aec1d6eScindi 		case T_LT:
8407aec1d6eScindi 		case T_LE:
8417aec1d6eScindi 		case T_GT:
8427aec1d6eScindi 		case T_GE:
8437aec1d6eScindi 		case T_BITAND:
8447aec1d6eScindi 		case T_BITOR:
8457aec1d6eScindi 		case T_BITXOR:
8467aec1d6eScindi 		case T_BITNOT:
8477aec1d6eScindi 		case T_LSHIFT:
8487aec1d6eScindi 		case T_RSHIFT:
8497c478bd9Sstevel@tonic-gate 		case T_LIST:
8507aec1d6eScindi 		case T_AND:
8517aec1d6eScindi 		case T_OR:
8527aec1d6eScindi 		case T_NOT:
8537aec1d6eScindi 		case T_ADD:
8547aec1d6eScindi 		case T_SUB:
8557aec1d6eScindi 		case T_MUL:
8567aec1d6eScindi 		case T_DIV:
8577aec1d6eScindi 		case T_MOD:
8587aec1d6eScindi 			make_explicit(np->u.expr.left, eventonly);
8597aec1d6eScindi 			make_explicit(np->u.expr.right, eventonly);
8607c478bd9Sstevel@tonic-gate 			break;
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 		case T_EVENT:
8637aec1d6eScindi 			make_explicit(np->u.event.epname, 0);
8647aec1d6eScindi 			make_explicit(np->u.event.eexprlist, 1);
8657aec1d6eScindi 			break;
8667aec1d6eScindi 
8677aec1d6eScindi 		case T_FUNC:
8687aec1d6eScindi 			make_explicit(np->u.func.arglist, eventonly);
8697c478bd9Sstevel@tonic-gate 			break;
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate 		case T_NAME:
8727aec1d6eScindi 			if (eventonly)
8737aec1d6eScindi 				return;
8747c478bd9Sstevel@tonic-gate 			for (pnp = np; pnp != NULL; pnp = pnp->u.name.next)
8757c478bd9Sstevel@tonic-gate 				if (pnp->u.name.child == NULL) {
8767c478bd9Sstevel@tonic-gate 					/*
8777c478bd9Sstevel@tonic-gate 					 * found implicit iterator.  convert
8787c478bd9Sstevel@tonic-gate 					 * it to an explicit iterator by
8797c478bd9Sstevel@tonic-gate 					 * using the name of the component
8807c478bd9Sstevel@tonic-gate 					 * appended with '#' and the number
8817c478bd9Sstevel@tonic-gate 					 * of times we've seen this same
8827c478bd9Sstevel@tonic-gate 					 * component name in this path so far.
8837c478bd9Sstevel@tonic-gate 					 */
8847c478bd9Sstevel@tonic-gate 					count = 0;
8857c478bd9Sstevel@tonic-gate 					for (pnp2 = np; pnp2 != NULL;
8867c478bd9Sstevel@tonic-gate 					    pnp2 = pnp2->u.name.next)
8877c478bd9Sstevel@tonic-gate 						if (pnp2 == pnp)
8887c478bd9Sstevel@tonic-gate 							break;
8897c478bd9Sstevel@tonic-gate 						else if (pnp2->u.name.s ==
8907c478bd9Sstevel@tonic-gate 						    pnp->u.name.s)
8917c478bd9Sstevel@tonic-gate 							count++;
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 					if (namesz < strlen(pnp->u.name.s) +
8947c478bd9Sstevel@tonic-gate 					    100) {
8957c478bd9Sstevel@tonic-gate 						namesz = strlen(pnp->u.name.s) +
8967c478bd9Sstevel@tonic-gate 						    100;
8977c478bd9Sstevel@tonic-gate 						FREE(Newname);
8987c478bd9Sstevel@tonic-gate 						Newname = MALLOC(namesz);
8997c478bd9Sstevel@tonic-gate 					}
9007c478bd9Sstevel@tonic-gate 					/*
9017c478bd9Sstevel@tonic-gate 					 * made up interator name is:
9027c478bd9Sstevel@tonic-gate 					 *	name#ordinal
9037c478bd9Sstevel@tonic-gate 					 * or
9047c478bd9Sstevel@tonic-gate 					 *	name##ordinal
9057c478bd9Sstevel@tonic-gate 					 * the first one is used for vertical
9067c478bd9Sstevel@tonic-gate 					 * expansion, the second for horizontal.
9077c478bd9Sstevel@tonic-gate 					 * either way, the '#' embedded in
9087c478bd9Sstevel@tonic-gate 					 * the name makes it impossible to
9097c478bd9Sstevel@tonic-gate 					 * collide with an actual iterator
9107c478bd9Sstevel@tonic-gate 					 * given to us in the eversholt file.
9117c478bd9Sstevel@tonic-gate 					 */
9127c478bd9Sstevel@tonic-gate 					(void) snprintf(Newname, namesz,
9137c478bd9Sstevel@tonic-gate 					    "%s#%s%d", pnp->u.name.s,
9147c478bd9Sstevel@tonic-gate 					    (pnp->u.name.it == IT_HORIZONTAL) ?
9157c478bd9Sstevel@tonic-gate 					    "#" : "", count);
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate 					pnp->u.name.child = tree_name(Newname,
9187c478bd9Sstevel@tonic-gate 					    IT_NONE, pnp->file, pnp->line);
9197c478bd9Sstevel@tonic-gate 					pnp->u.name.childgen = 1;
9207c478bd9Sstevel@tonic-gate 				}
9217c478bd9Sstevel@tonic-gate 			break;
9227c478bd9Sstevel@tonic-gate 	}
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate 
9257c478bd9Sstevel@tonic-gate struct node *
tree_pname(struct node * np)9267c478bd9Sstevel@tonic-gate tree_pname(struct node *np)
9277c478bd9Sstevel@tonic-gate {
9287aec1d6eScindi 	make_explicit(np, 0);
9297c478bd9Sstevel@tonic-gate 	return (np);
9307c478bd9Sstevel@tonic-gate }
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate struct node *
tree_arrow(struct node * lhs,struct node * nnp,struct node * knp,struct node * rhs)9337c478bd9Sstevel@tonic-gate tree_arrow(struct node *lhs, struct node *nnp, struct node *knp,
9347c478bd9Sstevel@tonic-gate     struct node *rhs)
9357c478bd9Sstevel@tonic-gate {
9367c478bd9Sstevel@tonic-gate 	struct node *ret;
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 	ASSERT(lhs != NULL || rhs != NULL);
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	ret = newnode(T_ARROW,
9417c478bd9Sstevel@tonic-gate 	    (lhs) ? lhs->file : rhs->file,
9427c478bd9Sstevel@tonic-gate 	    (lhs) ? lhs->line : rhs->line);
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate 	ret->u.arrow.lhs = lhs;
9457c478bd9Sstevel@tonic-gate 	ret->u.arrow.nnp = nnp;
9467c478bd9Sstevel@tonic-gate 	ret->u.arrow.knp = knp;
9477c478bd9Sstevel@tonic-gate 	ret->u.arrow.rhs = rhs;
9487c478bd9Sstevel@tonic-gate 
9497aec1d6eScindi 	make_explicit(lhs, 0);
9507aec1d6eScindi 	make_explicit(rhs, 0);
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate 	check_arrow(ret);
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate 	return (ret);
9557c478bd9Sstevel@tonic-gate }
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate static struct lut *
nvpair2lut(struct node * np,struct lut * lutp,enum nodetype t)9587c478bd9Sstevel@tonic-gate nvpair2lut(struct node *np, struct lut *lutp, enum nodetype t)
9597c478bd9Sstevel@tonic-gate {
9607c478bd9Sstevel@tonic-gate 	if (np) {
9617c478bd9Sstevel@tonic-gate 		if (np->t == T_NVPAIR) {
9627c478bd9Sstevel@tonic-gate 			ASSERTeq(np->u.expr.left->t, T_NAME,
9637c478bd9Sstevel@tonic-gate 			    ptree_nodetype2str);
9647c478bd9Sstevel@tonic-gate 			check_stmt_allowed_properties(t, np, lutp);
9657c478bd9Sstevel@tonic-gate 			lutp = tree_s2np_lut_add(lutp,
9667c478bd9Sstevel@tonic-gate 			    np->u.expr.left->u.name.s, np->u.expr.right);
9677c478bd9Sstevel@tonic-gate 		} else if (np->t == T_LIST) {
9687c478bd9Sstevel@tonic-gate 			lutp = nvpair2lut(np->u.expr.left, lutp, t);
9697c478bd9Sstevel@tonic-gate 			lutp = nvpair2lut(np->u.expr.right, lutp, t);
9707c478bd9Sstevel@tonic-gate 		} else
9717c478bd9Sstevel@tonic-gate 			outfl(O_DIE, np->file, np->line,
9727c478bd9Sstevel@tonic-gate 			    "internal error: nvpair2lut type %s",
9737c478bd9Sstevel@tonic-gate 			    ptree_nodetype2str(np->t));
9747c478bd9Sstevel@tonic-gate 	}
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	return (lutp);
9777c478bd9Sstevel@tonic-gate }
9787c478bd9Sstevel@tonic-gate 
9797c478bd9Sstevel@tonic-gate struct lut *
tree_s2np_lut_add(struct lut * root,const char * s,struct node * np)9807c478bd9Sstevel@tonic-gate tree_s2np_lut_add(struct lut *root, const char *s, struct node *np)
9817c478bd9Sstevel@tonic-gate {
9827c478bd9Sstevel@tonic-gate 	return (lut_add(root, (void *)s, (void *)np, NULL));
9837c478bd9Sstevel@tonic-gate }
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate struct node *
tree_s2np_lut_lookup(struct lut * root,const char * s)9867c478bd9Sstevel@tonic-gate tree_s2np_lut_lookup(struct lut *root, const char *s)
9877c478bd9Sstevel@tonic-gate {
9887c478bd9Sstevel@tonic-gate 	return (struct node *)lut_lookup(root, (void *)s, NULL);
9897c478bd9Sstevel@tonic-gate }
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate struct lut *
tree_name2np_lut_add(struct lut * root,struct node * namep,struct node * np)9927c478bd9Sstevel@tonic-gate tree_name2np_lut_add(struct lut *root, struct node *namep, struct node *np)
9937c478bd9Sstevel@tonic-gate {
9947c478bd9Sstevel@tonic-gate 	return (lut_add(root, (void *)namep, (void *)np,
9957c478bd9Sstevel@tonic-gate 	    (lut_cmp)tree_namecmp));
9967c478bd9Sstevel@tonic-gate }
9977c478bd9Sstevel@tonic-gate 
9987c478bd9Sstevel@tonic-gate struct node *
tree_name2np_lut_lookup(struct lut * root,struct node * namep)9997c478bd9Sstevel@tonic-gate tree_name2np_lut_lookup(struct lut *root, struct node *namep)
10007c478bd9Sstevel@tonic-gate {
10017c478bd9Sstevel@tonic-gate 	return (struct node *)
10027c478bd9Sstevel@tonic-gate 	    lut_lookup(root, (void *)namep, (lut_cmp)tree_namecmp);
10037c478bd9Sstevel@tonic-gate }
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate struct node *
tree_name2np_lut_lookup_name(struct lut * root,struct node * namep)10067c478bd9Sstevel@tonic-gate tree_name2np_lut_lookup_name(struct lut *root, struct node *namep)
10077c478bd9Sstevel@tonic-gate {
10087c478bd9Sstevel@tonic-gate 	return (struct node *)
10097c478bd9Sstevel@tonic-gate 	    lut_lookup_lhs(root, (void *)namep, (lut_cmp)tree_namecmp);
10107c478bd9Sstevel@tonic-gate }
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate struct lut *
tree_event2np_lut_add(struct lut * root,struct node * enp,struct node * np)10137c478bd9Sstevel@tonic-gate tree_event2np_lut_add(struct lut *root, struct node *enp, struct node *np)
10147c478bd9Sstevel@tonic-gate {
10157c478bd9Sstevel@tonic-gate 	return (lut_add(root, (void *)enp, (void *)np, (lut_cmp)tree_eventcmp));
10167c478bd9Sstevel@tonic-gate }
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate struct node *
tree_event2np_lut_lookup(struct lut * root,struct node * enp)10197c478bd9Sstevel@tonic-gate tree_event2np_lut_lookup(struct lut *root, struct node *enp)
10207c478bd9Sstevel@tonic-gate {
10217c478bd9Sstevel@tonic-gate 	return ((struct node *)
10227c478bd9Sstevel@tonic-gate 	    lut_lookup(root, (void *)enp, (lut_cmp)tree_eventcmp));
10237c478bd9Sstevel@tonic-gate }
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate struct node *
tree_event2np_lut_lookup_event(struct lut * root,struct node * enp)10267c478bd9Sstevel@tonic-gate tree_event2np_lut_lookup_event(struct lut *root, struct node *enp)
10277c478bd9Sstevel@tonic-gate {
10287c478bd9Sstevel@tonic-gate 	return ((struct node *)
10297c478bd9Sstevel@tonic-gate 	    lut_lookup_lhs(root, (void *)enp, (lut_cmp)tree_eventcmp));
10307c478bd9Sstevel@tonic-gate }
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate static struct node *
dodecl(enum nodetype t,const char * file,int line,struct node * np,struct node * nvpairs,struct lut ** lutpp,struct stats * countp,int justpath)10337c478bd9Sstevel@tonic-gate dodecl(enum nodetype t, const char *file, int line,
10347c478bd9Sstevel@tonic-gate     struct node *np, struct node *nvpairs, struct lut **lutpp,
10357c478bd9Sstevel@tonic-gate     struct stats *countp, int justpath)
10367c478bd9Sstevel@tonic-gate {
10377c478bd9Sstevel@tonic-gate 	struct node *ret;
10387c478bd9Sstevel@tonic-gate 	struct node *decl;
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate 	/* allocate parse tree node */
10417c478bd9Sstevel@tonic-gate 	ret = newnode(t, file, line);
10427c478bd9Sstevel@tonic-gate 	ret->u.stmt.np = np;
10437c478bd9Sstevel@tonic-gate 	ret->u.stmt.nvpairs = nvpairs;
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 	/*
10467c478bd9Sstevel@tonic-gate 	 * the global lut pointed to by lutpp (Faults, Defects, Upsets,
10477c478bd9Sstevel@tonic-gate 	 * Errors, Ereports, Serds, FRUs, or ASRUs) keeps the first decl.
10487c478bd9Sstevel@tonic-gate 	 * if this isn't the first declr, we merge the
10497c478bd9Sstevel@tonic-gate 	 * nvpairs into the first decl so we have a
10507c478bd9Sstevel@tonic-gate 	 * merged table to look up properties from.
10517c478bd9Sstevel@tonic-gate 	 * if this is the first time we've seen this fault,
10527c478bd9Sstevel@tonic-gate 	 * we add it to the global lut and start lutp
10537c478bd9Sstevel@tonic-gate 	 * off with any nvpairs from this declaration statement.
10547c478bd9Sstevel@tonic-gate 	 */
10557c478bd9Sstevel@tonic-gate 	if (justpath && (decl = tree_name2np_lut_lookup(*lutpp, np)) == NULL) {
10567c478bd9Sstevel@tonic-gate 		/* this is the first time name is declared */
10577c478bd9Sstevel@tonic-gate 		stats_counter_bump(countp);
10587c478bd9Sstevel@tonic-gate 		*lutpp = tree_name2np_lut_add(*lutpp, np, ret);
10597c478bd9Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t);
10607c478bd9Sstevel@tonic-gate 	} else if (!justpath &&
10617c478bd9Sstevel@tonic-gate 	    (decl = tree_event2np_lut_lookup(*lutpp, np)) == NULL) {
10627c478bd9Sstevel@tonic-gate 		/* this is the first time event is declared */
10637c478bd9Sstevel@tonic-gate 		stats_counter_bump(countp);
10647c478bd9Sstevel@tonic-gate 		*lutpp = tree_event2np_lut_add(*lutpp, np, ret);
10657c478bd9Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t);
10667c478bd9Sstevel@tonic-gate 	} else {
10677c478bd9Sstevel@tonic-gate 		/* was declared before, just add new nvpairs to its lutp */
10687c478bd9Sstevel@tonic-gate 		decl->u.stmt.lutp = nvpair2lut(nvpairs, decl->u.stmt.lutp, t);
10697c478bd9Sstevel@tonic-gate 	}
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate 	return (ret);
10727c478bd9Sstevel@tonic-gate }
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10757c478bd9Sstevel@tonic-gate static void
update_serd_refstmt(void * lhs,void * rhs,void * arg)10767c478bd9Sstevel@tonic-gate update_serd_refstmt(void *lhs, void *rhs, void *arg)
10777c478bd9Sstevel@tonic-gate {
10787c478bd9Sstevel@tonic-gate 	struct node *serd;
10797c478bd9Sstevel@tonic-gate 
10807c478bd9Sstevel@tonic-gate 	ASSERT(rhs != NULL);
10817c478bd9Sstevel@tonic-gate 
10827c478bd9Sstevel@tonic-gate 	serd = tree_s2np_lut_lookup(((struct node *)rhs)->u.stmt.lutp,
1083b5016cbbSstephh 	    L_engine);
10847c478bd9Sstevel@tonic-gate 	if (serd == NULL)
10857c478bd9Sstevel@tonic-gate 		return;
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 	ASSERT(serd->t == T_EVENT);
10887c478bd9Sstevel@tonic-gate 	if (arg != NULL && tree_eventcmp(serd, (struct node *)arg) != 0)
10897c478bd9Sstevel@tonic-gate 		return;
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	serd = tree_event2np_lut_lookup(SERDs, serd);
10927c478bd9Sstevel@tonic-gate 	if (serd != NULL)
10937c478bd9Sstevel@tonic-gate 		serd->u.stmt.flags |= STMT_REF;
10947c478bd9Sstevel@tonic-gate }
10957c478bd9Sstevel@tonic-gate 
10967c478bd9Sstevel@tonic-gate struct node *
tree_decl(enum nodetype t,struct node * np,struct node * nvpairs,const char * file,int line)10977c478bd9Sstevel@tonic-gate tree_decl(enum nodetype t, struct node *np, struct node *nvpairs,
10987c478bd9Sstevel@tonic-gate     const char *file, int line)
10997c478bd9Sstevel@tonic-gate {
11007c478bd9Sstevel@tonic-gate 	struct node *decl;
11017c478bd9Sstevel@tonic-gate 	struct node *ret;
11027c478bd9Sstevel@tonic-gate 
11037c478bd9Sstevel@tonic-gate 	ASSERT(np != NULL);
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 	check_type_iterator(np);
11067c478bd9Sstevel@tonic-gate 
11077c478bd9Sstevel@tonic-gate 	switch (t) {
11087c478bd9Sstevel@tonic-gate 	case T_EVENT:
11097c478bd9Sstevel@tonic-gate 		/* determine the type of event being declared */
11107c478bd9Sstevel@tonic-gate 		ASSERT(np->u.event.ename->t == T_NAME);
11117c478bd9Sstevel@tonic-gate 		switch (np->u.event.ename->u.name.t) {
11127c478bd9Sstevel@tonic-gate 		case N_FAULT:
11137c478bd9Sstevel@tonic-gate 			ret = dodecl(T_FAULT, file, line, np, nvpairs,
11147c478bd9Sstevel@tonic-gate 			    &Faults, Faultcount, 0);
1115b7d3956bSstephh 
1116b7d3956bSstephh 			/* increment serd statement reference */
1117b7d3956bSstephh 			decl = tree_event2np_lut_lookup(Faults, np);
1118b7d3956bSstephh 			update_serd_refstmt(NULL, decl, NULL);
11197c478bd9Sstevel@tonic-gate 			break;
11207c478bd9Sstevel@tonic-gate 
11217c478bd9Sstevel@tonic-gate 		case N_UPSET:
11227c478bd9Sstevel@tonic-gate 			ret = dodecl(T_UPSET, file, line, np, nvpairs,
11237c478bd9Sstevel@tonic-gate 			    &Upsets, Upsetcount, 0);
11247c478bd9Sstevel@tonic-gate 
11257c478bd9Sstevel@tonic-gate 			/* increment serd statement reference */
11267c478bd9Sstevel@tonic-gate 			decl = tree_event2np_lut_lookup(Upsets, np);
11277c478bd9Sstevel@tonic-gate 			update_serd_refstmt(NULL, decl, NULL);
11287c478bd9Sstevel@tonic-gate 			break;
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate 		case N_DEFECT:
11317c478bd9Sstevel@tonic-gate 			ret = dodecl(T_DEFECT, file, line, np, nvpairs,
11327c478bd9Sstevel@tonic-gate 			    &Defects, Defectcount, 0);
1133b7d3956bSstephh 
1134b7d3956bSstephh 			/* increment serd statement reference */
1135b7d3956bSstephh 			decl = tree_event2np_lut_lookup(Defects, np);
1136b7d3956bSstephh 			update_serd_refstmt(NULL, decl, NULL);
11377c478bd9Sstevel@tonic-gate 			break;
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate 		case N_ERROR:
11407c478bd9Sstevel@tonic-gate 			ret = dodecl(T_ERROR, file, line, np, nvpairs,
11417c478bd9Sstevel@tonic-gate 			    &Errors, Errorcount, 0);
11427c478bd9Sstevel@tonic-gate 			break;
11437c478bd9Sstevel@tonic-gate 
11447c478bd9Sstevel@tonic-gate 		case N_EREPORT:
11457c478bd9Sstevel@tonic-gate 			ret = dodecl(T_EREPORT, file, line, np, nvpairs,
11467c478bd9Sstevel@tonic-gate 			    &Ereports, Ereportcount, 0);
11477c478bd9Sstevel@tonic-gate 			/*
1148602ca9eaScth 			 * Keep a lut of just the enames, so that the DE
11497c478bd9Sstevel@tonic-gate 			 * can subscribe to a uniqified list of event
11507c478bd9Sstevel@tonic-gate 			 * classes.
11517c478bd9Sstevel@tonic-gate 			 */
11527c478bd9Sstevel@tonic-gate 			Ereportenames =
11537c478bd9Sstevel@tonic-gate 			    tree_name2np_lut_add(Ereportenames,
11547c478bd9Sstevel@tonic-gate 			    np->u.event.ename, np);
1155602ca9eaScth 
1156602ca9eaScth 			/*
1157602ca9eaScth 			 * Keep a lut of the enames (event classes) to
1158602ca9eaScth 			 * silently discard if we can't find a matching
1159602ca9eaScth 			 * configuration node when an ereport of of a given
1160602ca9eaScth 			 * class is received.  Such events are declaired
1161602ca9eaScth 			 * with 'discard_if_config_unknown=1'.
1162602ca9eaScth 			 */
1163602ca9eaScth 			if (tree_s2np_lut_lookup(ret->u.stmt.lutp,
1164602ca9eaScth 			    L_discard_if_config_unknown)) {
1165602ca9eaScth 				Ereportenames_discard = lut_add(
1166602ca9eaScth 				    Ereportenames_discard,
1167602ca9eaScth 				    (void *)np->u.event.ename->u.name.s,
1168602ca9eaScth 				    (void *)np->u.event.ename->u.name.s, NULL);
1169602ca9eaScth 			}
11707c478bd9Sstevel@tonic-gate 			break;
11717c478bd9Sstevel@tonic-gate 
11727c478bd9Sstevel@tonic-gate 		default:
11737c478bd9Sstevel@tonic-gate 			outfl(O_ERR, file, line,
11747c478bd9Sstevel@tonic-gate 			    "tree_decl: internal error, event name type %s",
11757c478bd9Sstevel@tonic-gate 			    ptree_nametype2str(np->u.event.ename->u.name.t));
11767c478bd9Sstevel@tonic-gate 		}
11777c478bd9Sstevel@tonic-gate 		break;
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 	case T_ENGINE:
11807c478bd9Sstevel@tonic-gate 		/* determine the type of engine being declared */
11817c478bd9Sstevel@tonic-gate 		ASSERT(np->u.event.ename->t == T_NAME);
11827c478bd9Sstevel@tonic-gate 		switch (np->u.event.ename->u.name.t) {
11837c478bd9Sstevel@tonic-gate 		case N_SERD:
11847c478bd9Sstevel@tonic-gate 			ret = dodecl(T_SERD, file, line, np, nvpairs,
11857c478bd9Sstevel@tonic-gate 			    &SERDs, SERDcount, 0);
11867c478bd9Sstevel@tonic-gate 			lut_walk(Upsets, update_serd_refstmt, np);
11877c478bd9Sstevel@tonic-gate 			break;
11887c478bd9Sstevel@tonic-gate 
11897aec1d6eScindi 		case N_STAT:
11907aec1d6eScindi 			ret = dodecl(T_STAT, file, line, np, nvpairs,
11917aec1d6eScindi 			    &STATs, STATcount, 0);
11927aec1d6eScindi 			break;
11937aec1d6eScindi 
11947c478bd9Sstevel@tonic-gate 		default:
11957c478bd9Sstevel@tonic-gate 			outfl(O_ERR, file, line,
11967c478bd9Sstevel@tonic-gate 			    "tree_decl: internal error, engine name type %s",
11977c478bd9Sstevel@tonic-gate 			    ptree_nametype2str(np->u.event.ename->u.name.t));
11987c478bd9Sstevel@tonic-gate 		}
11997c478bd9Sstevel@tonic-gate 		break;
12007c478bd9Sstevel@tonic-gate 	case T_ASRU:
12017c478bd9Sstevel@tonic-gate 		ret = dodecl(T_ASRU, file, line, np, nvpairs,
12027c478bd9Sstevel@tonic-gate 		    &ASRUs, ASRUcount, 1);
12037c478bd9Sstevel@tonic-gate 		break;
12047c478bd9Sstevel@tonic-gate 
12057c478bd9Sstevel@tonic-gate 	case T_FRU:
12067c478bd9Sstevel@tonic-gate 		ret = dodecl(T_FRU, file, line, np, nvpairs,
12077c478bd9Sstevel@tonic-gate 		    &FRUs, FRUcount, 1);
12087c478bd9Sstevel@tonic-gate 		break;
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate 	case T_CONFIG:
12117c478bd9Sstevel@tonic-gate 		/*
12127c478bd9Sstevel@tonic-gate 		 * config statements are different from above: they
12137c478bd9Sstevel@tonic-gate 		 * are not merged at all (until the configuration cache
12147c478bd9Sstevel@tonic-gate 		 * code does its own style of merging.  and the properties
12157c478bd9Sstevel@tonic-gate 		 * are a free-for-all -- we don't check for allowed or
12167c478bd9Sstevel@tonic-gate 		 * required config properties.
12177c478bd9Sstevel@tonic-gate 		 */
12187c478bd9Sstevel@tonic-gate 		ret = newnode(T_CONFIG, file, line);
12197c478bd9Sstevel@tonic-gate 		ret->u.stmt.np = np;
12207c478bd9Sstevel@tonic-gate 		ret->u.stmt.nvpairs = nvpairs;
12217c478bd9Sstevel@tonic-gate 		ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, T_CONFIG);
12227c478bd9Sstevel@tonic-gate 
12237c478bd9Sstevel@tonic-gate 		if (lut_lookup(Configs, np, (lut_cmp)tree_namecmp) == NULL)
12247c478bd9Sstevel@tonic-gate 			stats_counter_bump(Configcount);
12257c478bd9Sstevel@tonic-gate 
12267c478bd9Sstevel@tonic-gate 		Configs = lut_add(Configs, (void *)np, (void *)ret, NULL);
12277c478bd9Sstevel@tonic-gate 		break;
12287c478bd9Sstevel@tonic-gate 
12297c478bd9Sstevel@tonic-gate 	default:
12307c478bd9Sstevel@tonic-gate 		out(O_DIE, "tree_decl: internal error, type %s",
12317c478bd9Sstevel@tonic-gate 		    ptree_nodetype2str(t));
12327c478bd9Sstevel@tonic-gate 	}
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate 	return (ret);
12357c478bd9Sstevel@tonic-gate }
12367c478bd9Sstevel@tonic-gate 
12377c478bd9Sstevel@tonic-gate /* keep backpointers in arrows to the prop they belong to (used for scoping) */
12387c478bd9Sstevel@tonic-gate static void
set_arrow_prop(struct node * prop,struct node * np)12397c478bd9Sstevel@tonic-gate set_arrow_prop(struct node *prop, struct node *np)
12407c478bd9Sstevel@tonic-gate {
12417c478bd9Sstevel@tonic-gate 	if (np == NULL)
12427c478bd9Sstevel@tonic-gate 		return;
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate 	if (np->t == T_ARROW) {
12457c478bd9Sstevel@tonic-gate 		np->u.arrow.prop = prop;
12467c478bd9Sstevel@tonic-gate 		set_arrow_prop(prop, np->u.arrow.lhs);
12477c478bd9Sstevel@tonic-gate 		/*
12487c478bd9Sstevel@tonic-gate 		 * no need to recurse right or handle T_LIST since
12497c478bd9Sstevel@tonic-gate 		 * T_ARROWs always cascade left and are at the top
12507c478bd9Sstevel@tonic-gate 		 * of the parse tree.  (you can see this in the rule
12517c478bd9Sstevel@tonic-gate 		 * for "propbody" in escparse.y.)
12527c478bd9Sstevel@tonic-gate 		 */
12537c478bd9Sstevel@tonic-gate 	}
12547c478bd9Sstevel@tonic-gate }
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate struct node *
tree_stmt(enum nodetype t,struct node * np,const char * file,int line)12577c478bd9Sstevel@tonic-gate tree_stmt(enum nodetype t, struct node *np, const char *file, int line)
12587c478bd9Sstevel@tonic-gate {
12597c478bd9Sstevel@tonic-gate 	struct node *ret = newnode(t, file, line);
12607c478bd9Sstevel@tonic-gate 	struct node *pp;
12617c478bd9Sstevel@tonic-gate 	int inlist = 0;
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate 	ret->u.stmt.np = np;
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate 	switch (t) {
12667c478bd9Sstevel@tonic-gate 	case T_PROP:
1267f358d892Srw 		check_proplists(t, np);
12687c478bd9Sstevel@tonic-gate 		check_propnames(t, np, 0, 0);
12697c478bd9Sstevel@tonic-gate 		check_propscope(np);
12707c478bd9Sstevel@tonic-gate 		set_arrow_prop(ret, np);
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate 		for (pp = Props; pp; pp = pp->u.stmt.next) {
12737c478bd9Sstevel@tonic-gate 			if (tree_treecmp(pp, ret, T_NAME,
1274b5016cbbSstephh 			    (lut_cmp)tree_namecmp) == 0) {
12757c478bd9Sstevel@tonic-gate 				inlist = 1;
12767c478bd9Sstevel@tonic-gate 				break;
12777c478bd9Sstevel@tonic-gate 			}
12787c478bd9Sstevel@tonic-gate 		}
12797c478bd9Sstevel@tonic-gate 		if (inlist == 0)
12807c478bd9Sstevel@tonic-gate 			stats_counter_bump(Propcount);
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate 		/* "Props" is a linked list of all prop statements */
12837c478bd9Sstevel@tonic-gate 		if (Lastprops)
12847c478bd9Sstevel@tonic-gate 			Lastprops->u.stmt.next = ret;
12857c478bd9Sstevel@tonic-gate 		else
12867c478bd9Sstevel@tonic-gate 			Props = ret;
12877c478bd9Sstevel@tonic-gate 		Lastprops = ret;
12887c478bd9Sstevel@tonic-gate 		break;
12897c478bd9Sstevel@tonic-gate 
12907c478bd9Sstevel@tonic-gate 	case T_MASK:
1291f358d892Srw 		check_proplists(t, np);
12927c478bd9Sstevel@tonic-gate 		check_propnames(t, np, 0, 0);
12937c478bd9Sstevel@tonic-gate 		check_propscope(np);
12947c478bd9Sstevel@tonic-gate 		set_arrow_prop(ret, np);
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate 		for (pp = Masks; pp; pp = pp->u.stmt.next) {
12977c478bd9Sstevel@tonic-gate 			if (tree_treecmp(pp, ret, T_NAME,
1298b5016cbbSstephh 			    (lut_cmp)tree_namecmp) == 0) {
12997c478bd9Sstevel@tonic-gate 				inlist = 1;
13007c478bd9Sstevel@tonic-gate 				break;
13017c478bd9Sstevel@tonic-gate 			}
13027c478bd9Sstevel@tonic-gate 		}
13037c478bd9Sstevel@tonic-gate 		if (inlist == 0)
13047c478bd9Sstevel@tonic-gate 			stats_counter_bump(Maskcount);
13057c478bd9Sstevel@tonic-gate 
13067c478bd9Sstevel@tonic-gate 		/* "Masks" is a linked list of all mask statements */
13077c478bd9Sstevel@tonic-gate 		if (Lastmasks)
13087c478bd9Sstevel@tonic-gate 			Lastmasks->u.stmt.next = ret;
13097c478bd9Sstevel@tonic-gate 		else
13107c478bd9Sstevel@tonic-gate 			Masks = ret;
13117c478bd9Sstevel@tonic-gate 		Lastmasks = ret;
13127c478bd9Sstevel@tonic-gate 		stats_counter_bump(Maskcount);
13137c478bd9Sstevel@tonic-gate 		break;
13147c478bd9Sstevel@tonic-gate 
13157c478bd9Sstevel@tonic-gate 	default:
13167c478bd9Sstevel@tonic-gate 		outfl(O_DIE, np->file, np->line,
13177c478bd9Sstevel@tonic-gate 		    "tree_stmt: internal error (t %d)", t);
13187c478bd9Sstevel@tonic-gate 	}
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate 	return (ret);
13217c478bd9Sstevel@tonic-gate }
13227c478bd9Sstevel@tonic-gate 
13237c478bd9Sstevel@tonic-gate void
tree_report()13247c478bd9Sstevel@tonic-gate tree_report()
13257c478bd9Sstevel@tonic-gate {
13267c478bd9Sstevel@tonic-gate 	/*
13277c478bd9Sstevel@tonic-gate 	 * The only declarations with required properties
13287c478bd9Sstevel@tonic-gate 	 * currently are faults and serds. Make sure the
13297c478bd9Sstevel@tonic-gate 	 * the declarations have the required properties.
13307c478bd9Sstevel@tonic-gate 	 */
13317c478bd9Sstevel@tonic-gate 	lut_walk(Faults, (lut_cb)check_required_props, (void *)T_FAULT);
13327c478bd9Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_required_props, (void *)T_UPSET);
13337c478bd9Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_required_props, (void *)T_ERROR);
13347c478bd9Sstevel@tonic-gate 	lut_walk(Ereports, (lut_cb)check_required_props, (void *)T_EREPORT);
13357c478bd9Sstevel@tonic-gate 	lut_walk(SERDs, (lut_cb)check_required_props, (void *)T_SERD);
13367aec1d6eScindi 	lut_walk(STATs, (lut_cb)check_required_props, (void *)T_STAT);
13377c478bd9Sstevel@tonic-gate 
13387c478bd9Sstevel@tonic-gate 	/*
13397c478bd9Sstevel@tonic-gate 	 * we do this now rather than while building the parse
13407c478bd9Sstevel@tonic-gate 	 * tree because it is inconvenient for the user if we
13417c478bd9Sstevel@tonic-gate 	 * require SERD engines to be declared before used in
13427c478bd9Sstevel@tonic-gate 	 * an upset "engine" property.
13437c478bd9Sstevel@tonic-gate 	 */
13447c478bd9Sstevel@tonic-gate 	lut_walk(Faults, (lut_cb)check_refcount, (void *)T_FAULT);
1345b7d3956bSstephh 	lut_walk(Faults, (lut_cb)check_upset_engine, (void *)T_FAULT);
1346b7d3956bSstephh 	lut_walk(Defects, (lut_cb)check_upset_engine, (void *)T_DEFECT);
13477c478bd9Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_upset_engine, (void *)T_UPSET);
13487c478bd9Sstevel@tonic-gate 	lut_walk(Upsets, (lut_cb)check_refcount, (void *)T_UPSET);
13497c478bd9Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_refcount, (void *)T_ERROR);
13507c478bd9Sstevel@tonic-gate 	lut_walk(Ereports, (lut_cb)check_refcount, (void *)T_EREPORT);
13517c478bd9Sstevel@tonic-gate 	lut_walk(SERDs, (lut_cb)check_refcount, (void *)T_SERD);
13527c478bd9Sstevel@tonic-gate 
13537c478bd9Sstevel@tonic-gate 	/* check for cycles */
13547c478bd9Sstevel@tonic-gate 	lut_walk(Errors, (lut_cb)check_cycle, (void *)0);
13557c478bd9Sstevel@tonic-gate }
13567c478bd9Sstevel@tonic-gate 
13577c478bd9Sstevel@tonic-gate /* compare two T_NAMES by only looking at components, not iterators */
13587c478bd9Sstevel@tonic-gate int
tree_namecmp(struct node * np1,struct node * np2)13597c478bd9Sstevel@tonic-gate tree_namecmp(struct node *np1, struct node *np2)
13607c478bd9Sstevel@tonic-gate {
13617c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL);
13627c478bd9Sstevel@tonic-gate 	ASSERT(np2 != NULL);
13637c478bd9Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t));
13647c478bd9Sstevel@tonic-gate 	ASSERTinfo(np2->t == T_NAME, ptree_nodetype2str(np1->t));
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate 	while (np1 && np2 && np1->u.name.s == np2->u.name.s) {
13677c478bd9Sstevel@tonic-gate 		np1 = np1->u.name.next;
13687c478bd9Sstevel@tonic-gate 		np2 = np2->u.name.next;
13697c478bd9Sstevel@tonic-gate 	}
13707c478bd9Sstevel@tonic-gate 	if (np1 == NULL)
13717c478bd9Sstevel@tonic-gate 		if (np2 == NULL)
13727c478bd9Sstevel@tonic-gate 			return (0);
13737c478bd9Sstevel@tonic-gate 		else
13747c478bd9Sstevel@tonic-gate 			return (-1);
13757c478bd9Sstevel@tonic-gate 	else if (np2 == NULL)
13767c478bd9Sstevel@tonic-gate 		return (1);
13777c478bd9Sstevel@tonic-gate 	else
13787c478bd9Sstevel@tonic-gate 		return (np2->u.name.s - np1->u.name.s);
13797c478bd9Sstevel@tonic-gate }
13807c478bd9Sstevel@tonic-gate 
13817c478bd9Sstevel@tonic-gate int
tree_eventcmp(struct node * np1,struct node * np2)13827c478bd9Sstevel@tonic-gate tree_eventcmp(struct node *np1, struct node *np2)
13837c478bd9Sstevel@tonic-gate {
13847c478bd9Sstevel@tonic-gate 	int ret;
13857c478bd9Sstevel@tonic-gate 
13867c478bd9Sstevel@tonic-gate 	ASSERT(np1 != NULL);
13877c478bd9Sstevel@tonic-gate 	ASSERT(np2 != NULL);
13887c478bd9Sstevel@tonic-gate 	ASSERTinfo(np1->t == T_EVENT, ptree_nodetype2str(np1->t));
13897c478bd9Sstevel@tonic-gate 	ASSERTinfo(np2->t == T_EVENT, ptree_nodetype2str(np2->t));
13907c478bd9Sstevel@tonic-gate 
13917c478bd9Sstevel@tonic-gate 	if ((ret = tree_namecmp(np1->u.event.ename,
1392b5016cbbSstephh 	    np2->u.event.ename)) == 0) {
13937c478bd9Sstevel@tonic-gate 			if (np1->u.event.epname == NULL &&
1394b5016cbbSstephh 			    np2->u.event.epname == NULL)
13957c478bd9Sstevel@tonic-gate 				return (0);
13967c478bd9Sstevel@tonic-gate 			else if (np1->u.event.epname == NULL)
13977c478bd9Sstevel@tonic-gate 				return (-1);
13987c478bd9Sstevel@tonic-gate 			else if (np2->u.event.epname == NULL)
13997c478bd9Sstevel@tonic-gate 				return (1);
14007c478bd9Sstevel@tonic-gate 			else
14017c478bd9Sstevel@tonic-gate 				return tree_namecmp(np1->u.event.epname,
1402b5016cbbSstephh 				    np2->u.event.epname);
14037c478bd9Sstevel@tonic-gate 	} else
14047c478bd9Sstevel@tonic-gate 	return (ret);
14057c478bd9Sstevel@tonic-gate }
1406