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 52869Sgavinm * Common Development and Distribution License (the "License"). 62869Sgavinm * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 225947Sstephh * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate * 250Sstevel@tonic-gate * tree.c -- routines for manipulating the prop tree 260Sstevel@tonic-gate * 270Sstevel@tonic-gate * the actions in escparse.y call these routines to construct 280Sstevel@tonic-gate * the parse tree. these routines, in turn, call the check_X() 290Sstevel@tonic-gate * routines for semantic checking. 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include <stdio.h> 350Sstevel@tonic-gate #include <stdlib.h> 360Sstevel@tonic-gate #include <ctype.h> 370Sstevel@tonic-gate #include <strings.h> 380Sstevel@tonic-gate #include <alloca.h> 390Sstevel@tonic-gate #include "alloc.h" 400Sstevel@tonic-gate #include "out.h" 410Sstevel@tonic-gate #include "stats.h" 420Sstevel@tonic-gate #include "stable.h" 430Sstevel@tonic-gate #include "literals.h" 440Sstevel@tonic-gate #include "lut.h" 450Sstevel@tonic-gate #include "esclex.h" 460Sstevel@tonic-gate #include "tree.h" 470Sstevel@tonic-gate #include "check.h" 480Sstevel@tonic-gate #include "ptree.h" 490Sstevel@tonic-gate 500Sstevel@tonic-gate static struct node *Root; 510Sstevel@tonic-gate 520Sstevel@tonic-gate static char *Newname; 530Sstevel@tonic-gate 540Sstevel@tonic-gate static struct stats *Faultcount; 550Sstevel@tonic-gate static struct stats *Upsetcount; 560Sstevel@tonic-gate static struct stats *Defectcount; 570Sstevel@tonic-gate static struct stats *Errorcount; 580Sstevel@tonic-gate static struct stats *Ereportcount; 590Sstevel@tonic-gate static struct stats *SERDcount; 601414Scindi static struct stats *STATcount; 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 704436Sstephh struct lut *Usedprops; 714436Sstephh 720Sstevel@tonic-gate void 730Sstevel@tonic-gate tree_init(void) 740Sstevel@tonic-gate { 750Sstevel@tonic-gate Faultcount = stats_new_counter("parser.fault", "fault decls", 1); 760Sstevel@tonic-gate Upsetcount = stats_new_counter("parser.upset", "upset decls", 1); 770Sstevel@tonic-gate Defectcount = stats_new_counter("parser.defect", "defect decls", 1); 780Sstevel@tonic-gate Errorcount = stats_new_counter("parser.error", "error decls", 1); 790Sstevel@tonic-gate Ereportcount = stats_new_counter("parser.ereport", "ereport decls", 1); 800Sstevel@tonic-gate SERDcount = stats_new_counter("parser.SERD", "SERD engine decls", 1); 811414Scindi STATcount = stats_new_counter("parser.STAT", "STAT engine decls", 1); 820Sstevel@tonic-gate ASRUcount = stats_new_counter("parser.ASRU", "ASRU decls", 1); 830Sstevel@tonic-gate FRUcount = stats_new_counter("parser.FRU", "FRU decls", 1); 840Sstevel@tonic-gate Configcount = stats_new_counter("parser.config", "config stmts", 1); 850Sstevel@tonic-gate Propcount = stats_new_counter("parser.prop", "prop stmts", 1); 860Sstevel@tonic-gate Maskcount = stats_new_counter("parser.mask", "mask stmts", 1); 870Sstevel@tonic-gate Nodecount = stats_new_counter("parser.node", "nodes created", 1); 880Sstevel@tonic-gate Namecount = stats_new_counter("parser.name", "names created", 1); 890Sstevel@tonic-gate Nodesize = 900Sstevel@tonic-gate stats_new_counter("parser.nodesize", "sizeof(struct node)", 1); 910Sstevel@tonic-gate stats_counter_add(Nodesize, sizeof (struct node)); 920Sstevel@tonic-gate } 930Sstevel@tonic-gate 940Sstevel@tonic-gate void 950Sstevel@tonic-gate tree_fini(void) 960Sstevel@tonic-gate { 970Sstevel@tonic-gate stats_delete(Faultcount); 980Sstevel@tonic-gate stats_delete(Upsetcount); 990Sstevel@tonic-gate stats_delete(Defectcount); 1000Sstevel@tonic-gate stats_delete(Errorcount); 1010Sstevel@tonic-gate stats_delete(Ereportcount); 1020Sstevel@tonic-gate stats_delete(SERDcount); 1031414Scindi stats_delete(STATcount); 1040Sstevel@tonic-gate stats_delete(ASRUcount); 1050Sstevel@tonic-gate stats_delete(FRUcount); 1060Sstevel@tonic-gate stats_delete(Configcount); 1070Sstevel@tonic-gate stats_delete(Propcount); 1080Sstevel@tonic-gate stats_delete(Maskcount); 1090Sstevel@tonic-gate stats_delete(Nodecount); 1100Sstevel@tonic-gate stats_delete(Namecount); 1110Sstevel@tonic-gate stats_delete(Nodesize); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* free entire parse tree */ 1140Sstevel@tonic-gate tree_free(Root); 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* free up the luts we keep for decls */ 1170Sstevel@tonic-gate lut_free(Faults, NULL, NULL); 1180Sstevel@tonic-gate Faults = NULL; 1190Sstevel@tonic-gate lut_free(Upsets, NULL, NULL); 1200Sstevel@tonic-gate Upsets = NULL; 1210Sstevel@tonic-gate lut_free(Defects, NULL, NULL); 1220Sstevel@tonic-gate Defects = NULL; 1230Sstevel@tonic-gate lut_free(Errors, NULL, NULL); 1240Sstevel@tonic-gate Errors = NULL; 1250Sstevel@tonic-gate lut_free(Ereports, NULL, NULL); 1260Sstevel@tonic-gate Ereports = NULL; 1270Sstevel@tonic-gate lut_free(Ereportenames, NULL, NULL); 1280Sstevel@tonic-gate Ereportenames = NULL; 129*6640Scth lut_free(Ereportenames_discard, NULL, NULL); 130*6640Scth Ereportenames_discard = NULL; 1310Sstevel@tonic-gate lut_free(SERDs, NULL, NULL); 1320Sstevel@tonic-gate SERDs = NULL; 1331414Scindi lut_free(STATs, NULL, NULL); 1341414Scindi STATs = NULL; 1350Sstevel@tonic-gate lut_free(ASRUs, NULL, NULL); 1360Sstevel@tonic-gate ASRUs = NULL; 1370Sstevel@tonic-gate lut_free(FRUs, NULL, NULL); 1380Sstevel@tonic-gate FRUs = NULL; 1390Sstevel@tonic-gate lut_free(Configs, NULL, NULL); 1400Sstevel@tonic-gate Configs = NULL; 1415947Sstephh lut_free(Usedprops, NULL, NULL); 1425947Sstephh Usedprops = NULL; 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate Props = Lastprops = NULL; 1450Sstevel@tonic-gate Masks = Lastmasks = NULL; 1460Sstevel@tonic-gate Problems = Lastproblems = NULL; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate if (Newname != NULL) { 1490Sstevel@tonic-gate FREE(Newname); 1500Sstevel@tonic-gate Newname = NULL; 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate 1544436Sstephh /*ARGSUSED*/ 1554436Sstephh static int 1564436Sstephh nodesize(enum nodetype t, struct node *ret) 1574436Sstephh { 1584436Sstephh int size = sizeof (struct node); 1594436Sstephh 1604436Sstephh switch (t) { 1614436Sstephh case T_NAME: 1624436Sstephh size += sizeof (ret->u.name) - sizeof (ret->u); 1634436Sstephh break; 1644436Sstephh 1654436Sstephh case T_GLOBID: 1664436Sstephh size += sizeof (ret->u.globid) - sizeof (ret->u); 1674436Sstephh break; 1684436Sstephh 1694436Sstephh case T_TIMEVAL: 1704436Sstephh case T_NUM: 1714436Sstephh size += sizeof (ret->u.ull) - sizeof (ret->u); 1724436Sstephh break; 1734436Sstephh 1744436Sstephh case T_QUOTE: 1754436Sstephh size += sizeof (ret->u.quote) - sizeof (ret->u); 1764436Sstephh break; 1774436Sstephh 1784436Sstephh case T_FUNC: 1794436Sstephh size += sizeof (ret->u.func) - sizeof (ret->u); 1804436Sstephh break; 1814436Sstephh 1824436Sstephh case T_FAULT: 1834436Sstephh case T_UPSET: 1844436Sstephh case T_DEFECT: 1854436Sstephh case T_ERROR: 1864436Sstephh case T_EREPORT: 1874436Sstephh case T_ASRU: 1884436Sstephh case T_FRU: 1894436Sstephh case T_SERD: 1904436Sstephh case T_STAT: 1914436Sstephh case T_CONFIG: 1924436Sstephh case T_PROP: 1934436Sstephh case T_MASK: 1944436Sstephh size += sizeof (ret->u.stmt) - sizeof (ret->u); 1954436Sstephh break; 1964436Sstephh 1974436Sstephh case T_EVENT: 1984436Sstephh size += sizeof (ret->u.event) - sizeof (ret->u); 1994436Sstephh break; 2004436Sstephh 2014436Sstephh case T_ARROW: 2024436Sstephh size += sizeof (ret->u.arrow) - sizeof (ret->u); 2034436Sstephh break; 2044436Sstephh 2054436Sstephh default: 2064436Sstephh size += sizeof (ret->u.expr) - sizeof (ret->u); 2074436Sstephh break; 2084436Sstephh } 2094436Sstephh return (size); 2104436Sstephh } 2114436Sstephh 2120Sstevel@tonic-gate struct node * 2130Sstevel@tonic-gate newnode(enum nodetype t, const char *file, int line) 2140Sstevel@tonic-gate { 2154436Sstephh struct node *ret = NULL; 2164436Sstephh int size = nodesize(t, ret); 2170Sstevel@tonic-gate 2184436Sstephh ret = alloc_xmalloc(size); 2190Sstevel@tonic-gate stats_counter_bump(Nodecount); 2204436Sstephh bzero(ret, size); 2210Sstevel@tonic-gate ret->t = t; 2220Sstevel@tonic-gate ret->file = (file == NULL) ? "<nofile>" : file; 2230Sstevel@tonic-gate ret->line = line; 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate return (ret); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /*ARGSUSED*/ 2290Sstevel@tonic-gate void 2300Sstevel@tonic-gate tree_free(struct node *root) 2310Sstevel@tonic-gate { 2320Sstevel@tonic-gate if (root == NULL) 2330Sstevel@tonic-gate return; 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate switch (root->t) { 2360Sstevel@tonic-gate case T_NAME: 2370Sstevel@tonic-gate tree_free(root->u.name.child); 2380Sstevel@tonic-gate tree_free(root->u.name.next); 2390Sstevel@tonic-gate break; 2400Sstevel@tonic-gate case T_FUNC: 2410Sstevel@tonic-gate tree_free(root->u.func.arglist); 2420Sstevel@tonic-gate break; 2430Sstevel@tonic-gate case T_AND: 2440Sstevel@tonic-gate case T_OR: 2450Sstevel@tonic-gate case T_EQ: 2460Sstevel@tonic-gate case T_NE: 2470Sstevel@tonic-gate case T_ADD: 2480Sstevel@tonic-gate case T_DIV: 2490Sstevel@tonic-gate case T_MOD: 2500Sstevel@tonic-gate case T_MUL: 2510Sstevel@tonic-gate case T_SUB: 2520Sstevel@tonic-gate case T_LT: 2530Sstevel@tonic-gate case T_LE: 2540Sstevel@tonic-gate case T_GT: 2550Sstevel@tonic-gate case T_GE: 2560Sstevel@tonic-gate case T_BITAND: 2570Sstevel@tonic-gate case T_BITOR: 2580Sstevel@tonic-gate case T_BITXOR: 2590Sstevel@tonic-gate case T_BITNOT: 2600Sstevel@tonic-gate case T_LSHIFT: 2610Sstevel@tonic-gate case T_RSHIFT: 2620Sstevel@tonic-gate case T_NVPAIR: 2630Sstevel@tonic-gate case T_ASSIGN: 2640Sstevel@tonic-gate case T_CONDIF: 2650Sstevel@tonic-gate case T_CONDELSE: 2660Sstevel@tonic-gate case T_LIST: 2670Sstevel@tonic-gate tree_free(root->u.expr.left); 2680Sstevel@tonic-gate tree_free(root->u.expr.right); 2690Sstevel@tonic-gate break; 2700Sstevel@tonic-gate case T_EVENT: 2710Sstevel@tonic-gate tree_free(root->u.event.ename); 2720Sstevel@tonic-gate tree_free(root->u.event.epname); 2730Sstevel@tonic-gate tree_free(root->u.event.eexprlist); 2740Sstevel@tonic-gate break; 2750Sstevel@tonic-gate case T_NOT: 2760Sstevel@tonic-gate tree_free(root->u.expr.left); 2770Sstevel@tonic-gate break; 2780Sstevel@tonic-gate case T_ARROW: 2790Sstevel@tonic-gate tree_free(root->u.arrow.lhs); 2800Sstevel@tonic-gate tree_free(root->u.arrow.nnp); 2810Sstevel@tonic-gate tree_free(root->u.arrow.knp); 2820Sstevel@tonic-gate tree_free(root->u.arrow.rhs); 2830Sstevel@tonic-gate break; 2840Sstevel@tonic-gate case T_PROP: 2850Sstevel@tonic-gate case T_MASK: 2860Sstevel@tonic-gate tree_free(root->u.stmt.np); 2870Sstevel@tonic-gate break; 2880Sstevel@tonic-gate case T_FAULT: 2890Sstevel@tonic-gate case T_UPSET: 2900Sstevel@tonic-gate case T_DEFECT: 2910Sstevel@tonic-gate case T_ERROR: 2920Sstevel@tonic-gate case T_EREPORT: 2930Sstevel@tonic-gate case T_ASRU: 2940Sstevel@tonic-gate case T_FRU: 2950Sstevel@tonic-gate case T_SERD: 2961414Scindi case T_STAT: 2970Sstevel@tonic-gate case T_CONFIG: 2980Sstevel@tonic-gate tree_free(root->u.stmt.np); 2990Sstevel@tonic-gate if (root->u.stmt.nvpairs) 3000Sstevel@tonic-gate tree_free(root->u.stmt.nvpairs); 3010Sstevel@tonic-gate if (root->u.stmt.lutp) 3020Sstevel@tonic-gate lut_free(root->u.stmt.lutp, NULL, NULL); 3030Sstevel@tonic-gate break; 3040Sstevel@tonic-gate case T_TIMEVAL: 3050Sstevel@tonic-gate case T_NUM: 3060Sstevel@tonic-gate case T_QUOTE: 3070Sstevel@tonic-gate case T_GLOBID: 3080Sstevel@tonic-gate case T_NOTHING: 3090Sstevel@tonic-gate break; 3100Sstevel@tonic-gate default: 3110Sstevel@tonic-gate out(O_DIE, 3120Sstevel@tonic-gate "internal error: tree_free unexpected nodetype: %d", 3130Sstevel@tonic-gate root->t); 3140Sstevel@tonic-gate /*NOTREACHED*/ 3150Sstevel@tonic-gate } 3164436Sstephh alloc_xfree((char *)root, nodesize(root->t, root)); 3170Sstevel@tonic-gate } 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate static int 3200Sstevel@tonic-gate tree_treecmp(struct node *np1, struct node *np2, enum nodetype t, 3210Sstevel@tonic-gate lut_cmp cmp_func) 3220Sstevel@tonic-gate { 3230Sstevel@tonic-gate if (np1 == NULL || np2 == NULL) 3240Sstevel@tonic-gate return (0); 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate if (np1->t != np2->t) 3270Sstevel@tonic-gate return (1); 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate ASSERT(cmp_func != NULL); 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate if (np1->t == t) 3320Sstevel@tonic-gate return ((*cmp_func)(np1, np2)); 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate switch (np1->t) { 3350Sstevel@tonic-gate case T_NAME: 3360Sstevel@tonic-gate if (tree_treecmp(np1->u.name.child, np2->u.name.child, t, 3374436Sstephh cmp_func)) 3380Sstevel@tonic-gate return (1); 3390Sstevel@tonic-gate return (tree_treecmp(np1->u.name.next, np2->u.name.next, t, 3404436Sstephh cmp_func)); 3410Sstevel@tonic-gate /*NOTREACHED*/ 3420Sstevel@tonic-gate break; 3430Sstevel@tonic-gate case T_FUNC: 3440Sstevel@tonic-gate return (tree_treecmp(np1->u.func.arglist, np2->u.func.arglist, 3454436Sstephh t, cmp_func)); 3460Sstevel@tonic-gate /*NOTREACHED*/ 3470Sstevel@tonic-gate break; 3480Sstevel@tonic-gate case T_AND: 3490Sstevel@tonic-gate case T_OR: 3500Sstevel@tonic-gate case T_EQ: 3510Sstevel@tonic-gate case T_NE: 3520Sstevel@tonic-gate case T_ADD: 3530Sstevel@tonic-gate case T_DIV: 3540Sstevel@tonic-gate case T_MOD: 3550Sstevel@tonic-gate case T_MUL: 3560Sstevel@tonic-gate case T_SUB: 3570Sstevel@tonic-gate case T_LT: 3580Sstevel@tonic-gate case T_LE: 3590Sstevel@tonic-gate case T_GT: 3600Sstevel@tonic-gate case T_GE: 3610Sstevel@tonic-gate case T_BITAND: 3620Sstevel@tonic-gate case T_BITOR: 3630Sstevel@tonic-gate case T_BITXOR: 3640Sstevel@tonic-gate case T_BITNOT: 3650Sstevel@tonic-gate case T_LSHIFT: 3660Sstevel@tonic-gate case T_RSHIFT: 3670Sstevel@tonic-gate case T_NVPAIR: 3680Sstevel@tonic-gate case T_ASSIGN: 3690Sstevel@tonic-gate case T_CONDIF: 3700Sstevel@tonic-gate case T_CONDELSE: 3710Sstevel@tonic-gate case T_LIST: 3720Sstevel@tonic-gate if (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t, 3734436Sstephh cmp_func)) 3740Sstevel@tonic-gate return (1); 3750Sstevel@tonic-gate return (tree_treecmp(np1->u.expr.right, np2->u.expr.right, t, 3764436Sstephh cmp_func)); 3770Sstevel@tonic-gate /*NOTREACHED*/ 3780Sstevel@tonic-gate break; 3790Sstevel@tonic-gate case T_EVENT: 3800Sstevel@tonic-gate if (tree_treecmp(np1->u.event.ename, np2->u.event.ename, t, 3814436Sstephh cmp_func)) 3820Sstevel@tonic-gate return (1); 3830Sstevel@tonic-gate if (tree_treecmp(np1->u.event.epname, np2->u.event.epname, t, 3844436Sstephh cmp_func)) 3850Sstevel@tonic-gate return (1); 3860Sstevel@tonic-gate return (tree_treecmp(np1->u.event.eexprlist, 3874436Sstephh np2->u.event.eexprlist, t, cmp_func)); 3880Sstevel@tonic-gate /*NOTREACHED*/ 3890Sstevel@tonic-gate break; 3900Sstevel@tonic-gate case T_NOT: 3910Sstevel@tonic-gate return (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t, 3924436Sstephh cmp_func)); 3930Sstevel@tonic-gate /*NOTREACHED*/ 3940Sstevel@tonic-gate break; 3950Sstevel@tonic-gate case T_ARROW: 3960Sstevel@tonic-gate if (tree_treecmp(np1->u.arrow.lhs, np2->u.arrow.lhs, t, 3974436Sstephh cmp_func)) 3980Sstevel@tonic-gate return (1); 3990Sstevel@tonic-gate if (tree_treecmp(np1->u.arrow.nnp, np2->u.arrow.nnp, t, 4004436Sstephh cmp_func)) 4010Sstevel@tonic-gate return (1); 4020Sstevel@tonic-gate if (tree_treecmp(np1->u.arrow.knp, np2->u.arrow.knp, t, 4034436Sstephh cmp_func)) 4040Sstevel@tonic-gate return (1); 4050Sstevel@tonic-gate return (tree_treecmp(np1->u.arrow.rhs, np2->u.arrow.rhs, t, 4064436Sstephh cmp_func)); 4070Sstevel@tonic-gate /*NOTREACHED*/ 4080Sstevel@tonic-gate break; 4090Sstevel@tonic-gate case T_PROP: 4100Sstevel@tonic-gate case T_MASK: 4110Sstevel@tonic-gate return (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t, 4124436Sstephh cmp_func)); 4130Sstevel@tonic-gate /*NOTREACHED*/ 4140Sstevel@tonic-gate break; 4150Sstevel@tonic-gate case T_FAULT: 4160Sstevel@tonic-gate case T_UPSET: 4170Sstevel@tonic-gate case T_DEFECT: 4180Sstevel@tonic-gate case T_ERROR: 4190Sstevel@tonic-gate case T_EREPORT: 4200Sstevel@tonic-gate case T_ASRU: 4210Sstevel@tonic-gate case T_FRU: 4220Sstevel@tonic-gate case T_SERD: 4231414Scindi case T_STAT: 4240Sstevel@tonic-gate if (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t, cmp_func)) 4250Sstevel@tonic-gate return (1); 4260Sstevel@tonic-gate return (tree_treecmp(np1->u.stmt.nvpairs, np2->u.stmt.nvpairs, 4274436Sstephh t, cmp_func)); 4280Sstevel@tonic-gate /*NOTREACHED*/ 4290Sstevel@tonic-gate break; 4300Sstevel@tonic-gate case T_TIMEVAL: 4310Sstevel@tonic-gate case T_NUM: 4320Sstevel@tonic-gate case T_QUOTE: 4330Sstevel@tonic-gate case T_GLOBID: 4340Sstevel@tonic-gate case T_NOTHING: 4350Sstevel@tonic-gate break; 4360Sstevel@tonic-gate default: 4370Sstevel@tonic-gate out(O_DIE, 4380Sstevel@tonic-gate "internal error: tree_treecmp unexpected nodetype: %d", 4390Sstevel@tonic-gate np1->t); 4400Sstevel@tonic-gate /*NOTREACHED*/ 4410Sstevel@tonic-gate break; 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate return (0); 4450Sstevel@tonic-gate } 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate struct node * 4480Sstevel@tonic-gate tree_root(struct node *np) 4490Sstevel@tonic-gate { 4500Sstevel@tonic-gate if (np) 4510Sstevel@tonic-gate Root = np; 4520Sstevel@tonic-gate return (Root); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate struct node * 4560Sstevel@tonic-gate tree_nothing(void) 4570Sstevel@tonic-gate { 4580Sstevel@tonic-gate return (newnode(T_NOTHING, L_nofile, 0)); 4590Sstevel@tonic-gate } 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate struct node * 4620Sstevel@tonic-gate tree_expr(enum nodetype t, struct node *left, struct node *right) 4630Sstevel@tonic-gate { 4640Sstevel@tonic-gate struct node *ret; 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate ASSERTinfo(left != NULL || right != NULL, ptree_nodetype2str(t)); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate ret = newnode(t, 4690Sstevel@tonic-gate (left) ? left->file : right->file, 4700Sstevel@tonic-gate (left) ? left->line : right->line); 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate ret->u.expr.left = left; 4730Sstevel@tonic-gate ret->u.expr.right = right; 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate check_expr(ret); 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate return (ret); 4780Sstevel@tonic-gate } 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate /* 4810Sstevel@tonic-gate * ename_compress -- convert event class name in to more space-efficient form 4820Sstevel@tonic-gate * 4830Sstevel@tonic-gate * this routine is called after the parser has completed an "ename", which 4840Sstevel@tonic-gate * is that part of an event that contains the class name (like ereport.x.y.z). 4850Sstevel@tonic-gate * after this routine gets done with the ename, two things are true: 4860Sstevel@tonic-gate * 1. the ename uses only a single struct node 4870Sstevel@tonic-gate * 2. ename->u.name.s contains the *complete* class name, dots and all, 4880Sstevel@tonic-gate * entered into the string table. 4890Sstevel@tonic-gate * 4900Sstevel@tonic-gate * so in addition to saving space by using fewer struct nodes, this routine 4910Sstevel@tonic-gate * allows consumers of the fault tree to assume the ename is a single 4920Sstevel@tonic-gate * string, rather than a linked list of strings. 4930Sstevel@tonic-gate */ 4940Sstevel@tonic-gate static struct node * 4950Sstevel@tonic-gate ename_compress(struct node *ename) 4960Sstevel@tonic-gate { 4970Sstevel@tonic-gate char *buf; 4980Sstevel@tonic-gate char *cp; 4990Sstevel@tonic-gate int len = 0; 5000Sstevel@tonic-gate struct node *np; 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate if (ename == NULL) 5030Sstevel@tonic-gate return (ename); 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate ASSERT(ename->t == T_NAME); 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate if (ename->u.name.next == NULL) 5080Sstevel@tonic-gate return (ename); /* no compression to be applied here */ 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate for (np = ename; np != NULL; np = np->u.name.next) { 5110Sstevel@tonic-gate ASSERT(np->t == T_NAME); 5120Sstevel@tonic-gate len++; /* room for '.' and final '\0' */ 5130Sstevel@tonic-gate len += strlen(np->u.name.s); 5140Sstevel@tonic-gate } 5150Sstevel@tonic-gate cp = buf = alloca(len); 5160Sstevel@tonic-gate for (np = ename; np != NULL; np = np->u.name.next) { 5170Sstevel@tonic-gate ASSERT(np->t == T_NAME); 5180Sstevel@tonic-gate if (np != ename) 5190Sstevel@tonic-gate *cp++ = '.'; 5200Sstevel@tonic-gate (void) strcpy(cp, np->u.name.s); 5210Sstevel@tonic-gate cp += strlen(cp); 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate ename->u.name.s = stable(buf); 5250Sstevel@tonic-gate tree_free(ename->u.name.next); 5260Sstevel@tonic-gate ename->u.name.next = NULL; 5270Sstevel@tonic-gate ename->u.name.last = ename; 5280Sstevel@tonic-gate return (ename); 5290Sstevel@tonic-gate } 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate struct node * 5320Sstevel@tonic-gate tree_event(struct node *ename, struct node *epname, struct node *eexprlist) 5330Sstevel@tonic-gate { 5340Sstevel@tonic-gate struct node *ret; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate ASSERT(ename != NULL); 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate ret = newnode(T_EVENT, ename->file, ename->line); 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate ret->u.event.ename = ename_compress(ename); 5410Sstevel@tonic-gate ret->u.event.epname = epname; 5420Sstevel@tonic-gate ret->u.event.eexprlist = eexprlist; 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate check_event(ret); 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate return (ret); 5470Sstevel@tonic-gate } 5480Sstevel@tonic-gate 5490Sstevel@tonic-gate struct node * 5500Sstevel@tonic-gate tree_name(const char *s, enum itertype it, const char *file, int line) 5510Sstevel@tonic-gate { 5520Sstevel@tonic-gate struct node *ret = newnode(T_NAME, file, line); 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate ASSERT(s != NULL); 5550Sstevel@tonic-gate 5560Sstevel@tonic-gate stats_counter_bump(Namecount); 5570Sstevel@tonic-gate ret->u.name.t = N_UNSPEC; 5580Sstevel@tonic-gate ret->u.name.s = stable(s); 5590Sstevel@tonic-gate ret->u.name.it = it; 5600Sstevel@tonic-gate ret->u.name.last = ret; 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate if (it == IT_ENAME) { 5630Sstevel@tonic-gate /* PHASE2, possible optimization: convert to table driven */ 5640Sstevel@tonic-gate if (s == L_fault) 5650Sstevel@tonic-gate ret->u.name.t = N_FAULT; 5660Sstevel@tonic-gate else if (s == L_upset) 5670Sstevel@tonic-gate ret->u.name.t = N_UPSET; 5680Sstevel@tonic-gate else if (s == L_defect) 5690Sstevel@tonic-gate ret->u.name.t = N_DEFECT; 5700Sstevel@tonic-gate else if (s == L_error) 5710Sstevel@tonic-gate ret->u.name.t = N_ERROR; 5720Sstevel@tonic-gate else if (s == L_ereport) 5730Sstevel@tonic-gate ret->u.name.t = N_EREPORT; 5740Sstevel@tonic-gate else if (s == L_serd) 5750Sstevel@tonic-gate ret->u.name.t = N_SERD; 5761414Scindi else if (s == L_stat) 5771414Scindi ret->u.name.t = N_STAT; 5780Sstevel@tonic-gate else 5790Sstevel@tonic-gate outfl(O_ERR, file, line, "unknown class: %s", s); 5800Sstevel@tonic-gate } 5810Sstevel@tonic-gate return (ret); 5820Sstevel@tonic-gate } 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate struct node * 5850Sstevel@tonic-gate tree_iname(const char *s, const char *file, int line) 5860Sstevel@tonic-gate { 5870Sstevel@tonic-gate struct node *ret; 5880Sstevel@tonic-gate char *ss; 5890Sstevel@tonic-gate char *ptr; 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate ASSERT(s != NULL && *s != '\0'); 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate ss = STRDUP(s); 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate ptr = &ss[strlen(ss) - 1]; 5960Sstevel@tonic-gate if (!isdigit(*ptr)) { 5970Sstevel@tonic-gate outfl(O_ERR, file, line, 5980Sstevel@tonic-gate "instanced name expected (i.e. \"x0/y1\")"); 5990Sstevel@tonic-gate FREE(ss); 6000Sstevel@tonic-gate return (tree_name(s, IT_NONE, file, line)); 6010Sstevel@tonic-gate } 6020Sstevel@tonic-gate while (ptr > ss && isdigit(*(ptr - 1))) 6030Sstevel@tonic-gate ptr--; 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate ret = newnode(T_NAME, file, line); 6060Sstevel@tonic-gate stats_counter_bump(Namecount); 6070Sstevel@tonic-gate ret->u.name.child = tree_num(ptr, file, line); 6080Sstevel@tonic-gate *ptr = '\0'; 6090Sstevel@tonic-gate ret->u.name.t = N_UNSPEC; 6100Sstevel@tonic-gate ret->u.name.s = stable(ss); 6110Sstevel@tonic-gate ret->u.name.it = IT_NONE; 6120Sstevel@tonic-gate ret->u.name.last = ret; 6130Sstevel@tonic-gate FREE(ss); 6140Sstevel@tonic-gate 6150Sstevel@tonic-gate return (ret); 6160Sstevel@tonic-gate } 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate struct node * 6190Sstevel@tonic-gate tree_globid(const char *s, const char *file, int line) 6200Sstevel@tonic-gate { 6210Sstevel@tonic-gate struct node *ret = newnode(T_GLOBID, file, line); 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate ASSERT(s != NULL); 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate ret->u.globid.s = stable(s); 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate return (ret); 6280Sstevel@tonic-gate } 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate struct node * 6310Sstevel@tonic-gate tree_name_append(struct node *np1, struct node *np2) 6320Sstevel@tonic-gate { 6330Sstevel@tonic-gate ASSERT(np1 != NULL && np2 != NULL); 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate if (np1->t != T_NAME) 6360Sstevel@tonic-gate outfl(O_DIE, np1->file, np1->line, 6370Sstevel@tonic-gate "tree_name_append: internal error (np1 type %d)", np1->t); 6380Sstevel@tonic-gate if (np2->t != T_NAME) 6390Sstevel@tonic-gate outfl(O_DIE, np2->file, np2->line, 6400Sstevel@tonic-gate "tree_name_append: internal error (np2 type %d)", np2->t); 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate ASSERT(np1->u.name.last != NULL); 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate np1->u.name.last->u.name.next = np2; 6450Sstevel@tonic-gate np1->u.name.last = np2; 6460Sstevel@tonic-gate return (np1); 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate /* 6500Sstevel@tonic-gate * tree_name_repairdash -- repair a class name that contained a dash 6510Sstevel@tonic-gate * 6520Sstevel@tonic-gate * this routine is called by the parser when a dash is encountered 6530Sstevel@tonic-gate * in a class name. the event protocol allows the dashes but our 6540Sstevel@tonic-gate * lexer considers them a separate token (arithmetic minus). an extra 6550Sstevel@tonic-gate * rule in the parser catches this case and calls this routine to fixup 6560Sstevel@tonic-gate * the last component of the class name (so far) by constructing the 6570Sstevel@tonic-gate * new stable entry for a name including the dash. 6580Sstevel@tonic-gate */ 6590Sstevel@tonic-gate struct node * 6600Sstevel@tonic-gate tree_name_repairdash(struct node *np, const char *s) 6610Sstevel@tonic-gate { 6620Sstevel@tonic-gate int len; 6630Sstevel@tonic-gate char *buf; 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate ASSERT(np != NULL && s != NULL); 6660Sstevel@tonic-gate 6670Sstevel@tonic-gate if (np->t != T_NAME) 6680Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 6690Sstevel@tonic-gate "tree_name_repairdash: internal error (np type %d)", 6700Sstevel@tonic-gate np->t); 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate ASSERT(np->u.name.last != NULL); 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1; 6750Sstevel@tonic-gate buf = MALLOC(len); 6760Sstevel@tonic-gate (void) snprintf(buf, len, "%s-%s", np->u.name.last->u.name.s, s); 6770Sstevel@tonic-gate np->u.name.last->u.name.s = stable(buf); 6780Sstevel@tonic-gate FREE(buf); 6790Sstevel@tonic-gate return (np); 6800Sstevel@tonic-gate } 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate struct node * 6832869Sgavinm tree_name_repairdash2(const char *s, struct node *np) 6842869Sgavinm { 6852869Sgavinm int len; 6862869Sgavinm char *buf; 6872869Sgavinm 6882869Sgavinm ASSERT(np != NULL && s != NULL); 6892869Sgavinm 6902869Sgavinm if (np->t != T_NAME) 6912869Sgavinm outfl(O_DIE, np->file, np->line, 6922869Sgavinm "tree_name_repairdash: internal error (np type %d)", 6932869Sgavinm np->t); 6942869Sgavinm 6952869Sgavinm ASSERT(np->u.name.last != NULL); 6962869Sgavinm 6972869Sgavinm len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1; 6982869Sgavinm buf = MALLOC(len); 6992869Sgavinm (void) snprintf(buf, len, "%s-%s", s, np->u.name.last->u.name.s); 7002869Sgavinm np->u.name.last->u.name.s = stable(buf); 7012869Sgavinm FREE(buf); 7022869Sgavinm return (np); 7032869Sgavinm } 7042869Sgavinm 7052869Sgavinm struct node * 7060Sstevel@tonic-gate tree_name_iterator(struct node *np1, struct node *np2) 7070Sstevel@tonic-gate { 7080Sstevel@tonic-gate ASSERT(np1 != NULL); 7090Sstevel@tonic-gate ASSERT(np2 != NULL); 7100Sstevel@tonic-gate ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t)); 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate np1->u.name.child = np2; 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate check_name_iterator(np1); 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate return (np1); 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate struct node * 7200Sstevel@tonic-gate tree_timeval(const char *s, const char *suffix, const char *file, int line) 7210Sstevel@tonic-gate { 7220Sstevel@tonic-gate struct node *ret = newnode(T_TIMEVAL, file, line); 7230Sstevel@tonic-gate const unsigned long long *ullp; 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate ASSERT(s != NULL); 7260Sstevel@tonic-gate ASSERT(suffix != NULL); 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate if ((ullp = lex_s2ullp_lut_lookup(Timesuffixlut, suffix)) == NULL) { 7290Sstevel@tonic-gate outfl(O_ERR, file, line, 7300Sstevel@tonic-gate "unrecognized number suffix: %s", suffix); 7310Sstevel@tonic-gate /* still construct a valid timeval node so parsing continues */ 7320Sstevel@tonic-gate ret->u.ull = 1; 7330Sstevel@tonic-gate } else { 7340Sstevel@tonic-gate ret->u.ull = (unsigned long long)strtoul(s, NULL, 0) * *ullp; 7350Sstevel@tonic-gate } 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate return (ret); 7380Sstevel@tonic-gate } 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate struct node * 7410Sstevel@tonic-gate tree_num(const char *s, const char *file, int line) 7420Sstevel@tonic-gate { 7430Sstevel@tonic-gate struct node *ret = newnode(T_NUM, file, line); 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate ret->u.ull = (unsigned long long)strtoul(s, NULL, 0); 7460Sstevel@tonic-gate return (ret); 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate struct node * 7500Sstevel@tonic-gate tree_quote(const char *s, const char *file, int line) 7510Sstevel@tonic-gate { 7520Sstevel@tonic-gate struct node *ret = newnode(T_QUOTE, file, line); 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate ret->u.quote.s = stable(s); 7550Sstevel@tonic-gate return (ret); 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate struct node * 7590Sstevel@tonic-gate tree_func(const char *s, struct node *np, const char *file, int line) 7600Sstevel@tonic-gate { 7610Sstevel@tonic-gate struct node *ret = newnode(T_FUNC, file, line); 7624436Sstephh const char *ptr; 7630Sstevel@tonic-gate 7640Sstevel@tonic-gate ret->u.func.s = s; 7650Sstevel@tonic-gate ret->u.func.arglist = np; 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate check_func(ret); 7680Sstevel@tonic-gate 7694436Sstephh /* 7704436Sstephh * keep track of the properties we're interested in so we can ignore the 7714436Sstephh * rest 7724436Sstephh */ 7734436Sstephh if (strcmp(s, L_confprop) == 0 || strcmp(s, L_confprop_defined) == 0) { 7744436Sstephh ptr = stable(np->u.expr.right->u.quote.s); 7754436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7764436Sstephh } else if (strcmp(s, L_is_connected) == 0) { 7774436Sstephh ptr = stable("connected"); 7784436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7794436Sstephh ptr = stable("CONNECTED"); 7804436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7814436Sstephh } else if (strcmp(s, L_is_type) == 0) { 7824436Sstephh ptr = stable("type"); 7834436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7844436Sstephh ptr = stable("TYPE"); 7854436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7864436Sstephh } else if (strcmp(s, L_is_on) == 0) { 7874436Sstephh ptr = stable("on"); 7884436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7894436Sstephh ptr = stable("ON"); 7904436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7914436Sstephh } 7924436Sstephh 7930Sstevel@tonic-gate return (ret); 7940Sstevel@tonic-gate } 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate /* 7970Sstevel@tonic-gate * given a list from a prop or mask statement or a function argument, 7980Sstevel@tonic-gate * convert all iterators to explicit iterators by inventing appropriate 7990Sstevel@tonic-gate * iterator names. 8000Sstevel@tonic-gate */ 8010Sstevel@tonic-gate static void 8021414Scindi make_explicit(struct node *np, int eventonly) 8030Sstevel@tonic-gate { 8040Sstevel@tonic-gate struct node *pnp; /* component of pathname */ 8050Sstevel@tonic-gate struct node *pnp2; 8060Sstevel@tonic-gate int count; 8070Sstevel@tonic-gate static size_t namesz; 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate if (Newname == NULL) { 8100Sstevel@tonic-gate namesz = 200; 8110Sstevel@tonic-gate Newname = MALLOC(namesz); 8120Sstevel@tonic-gate } 8130Sstevel@tonic-gate 8140Sstevel@tonic-gate if (np == NULL) 8150Sstevel@tonic-gate return; /* all done */ 8160Sstevel@tonic-gate 8170Sstevel@tonic-gate switch (np->t) { 8181414Scindi case T_ASSIGN: 8191414Scindi case T_CONDIF: 8201414Scindi case T_CONDELSE: 8211414Scindi case T_NE: 8221414Scindi case T_EQ: 8231414Scindi case T_LT: 8241414Scindi case T_LE: 8251414Scindi case T_GT: 8261414Scindi case T_GE: 8271414Scindi case T_BITAND: 8281414Scindi case T_BITOR: 8291414Scindi case T_BITXOR: 8301414Scindi case T_BITNOT: 8311414Scindi case T_LSHIFT: 8321414Scindi case T_RSHIFT: 8330Sstevel@tonic-gate case T_LIST: 8341414Scindi case T_AND: 8351414Scindi case T_OR: 8361414Scindi case T_NOT: 8371414Scindi case T_ADD: 8381414Scindi case T_SUB: 8391414Scindi case T_MUL: 8401414Scindi case T_DIV: 8411414Scindi case T_MOD: 8421414Scindi make_explicit(np->u.expr.left, eventonly); 8431414Scindi make_explicit(np->u.expr.right, eventonly); 8440Sstevel@tonic-gate break; 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate case T_EVENT: 8471414Scindi make_explicit(np->u.event.epname, 0); 8481414Scindi make_explicit(np->u.event.eexprlist, 1); 8491414Scindi break; 8501414Scindi 8511414Scindi case T_FUNC: 8521414Scindi make_explicit(np->u.func.arglist, eventonly); 8530Sstevel@tonic-gate break; 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate case T_NAME: 8561414Scindi if (eventonly) 8571414Scindi return; 8580Sstevel@tonic-gate for (pnp = np; pnp != NULL; pnp = pnp->u.name.next) 8590Sstevel@tonic-gate if (pnp->u.name.child == NULL) { 8600Sstevel@tonic-gate /* 8610Sstevel@tonic-gate * found implicit iterator. convert 8620Sstevel@tonic-gate * it to an explicit iterator by 8630Sstevel@tonic-gate * using the name of the component 8640Sstevel@tonic-gate * appended with '#' and the number 8650Sstevel@tonic-gate * of times we've seen this same 8660Sstevel@tonic-gate * component name in this path so far. 8670Sstevel@tonic-gate */ 8680Sstevel@tonic-gate count = 0; 8690Sstevel@tonic-gate for (pnp2 = np; pnp2 != NULL; 8700Sstevel@tonic-gate pnp2 = pnp2->u.name.next) 8710Sstevel@tonic-gate if (pnp2 == pnp) 8720Sstevel@tonic-gate break; 8730Sstevel@tonic-gate else if (pnp2->u.name.s == 8740Sstevel@tonic-gate pnp->u.name.s) 8750Sstevel@tonic-gate count++; 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate if (namesz < strlen(pnp->u.name.s) + 8780Sstevel@tonic-gate 100) { 8790Sstevel@tonic-gate namesz = strlen(pnp->u.name.s) + 8800Sstevel@tonic-gate 100; 8810Sstevel@tonic-gate FREE(Newname); 8820Sstevel@tonic-gate Newname = MALLOC(namesz); 8830Sstevel@tonic-gate } 8840Sstevel@tonic-gate /* 8850Sstevel@tonic-gate * made up interator name is: 8860Sstevel@tonic-gate * name#ordinal 8870Sstevel@tonic-gate * or 8880Sstevel@tonic-gate * name##ordinal 8890Sstevel@tonic-gate * the first one is used for vertical 8900Sstevel@tonic-gate * expansion, the second for horizontal. 8910Sstevel@tonic-gate * either way, the '#' embedded in 8920Sstevel@tonic-gate * the name makes it impossible to 8930Sstevel@tonic-gate * collide with an actual iterator 8940Sstevel@tonic-gate * given to us in the eversholt file. 8950Sstevel@tonic-gate */ 8960Sstevel@tonic-gate (void) snprintf(Newname, namesz, 8970Sstevel@tonic-gate "%s#%s%d", pnp->u.name.s, 8980Sstevel@tonic-gate (pnp->u.name.it == IT_HORIZONTAL) ? 8990Sstevel@tonic-gate "#" : "", count); 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate pnp->u.name.child = tree_name(Newname, 9020Sstevel@tonic-gate IT_NONE, pnp->file, pnp->line); 9030Sstevel@tonic-gate pnp->u.name.childgen = 1; 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate break; 9060Sstevel@tonic-gate } 9070Sstevel@tonic-gate } 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate struct node * 9100Sstevel@tonic-gate tree_pname(struct node *np) 9110Sstevel@tonic-gate { 9121414Scindi make_explicit(np, 0); 9130Sstevel@tonic-gate return (np); 9140Sstevel@tonic-gate } 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate struct node * 9170Sstevel@tonic-gate tree_arrow(struct node *lhs, struct node *nnp, struct node *knp, 9180Sstevel@tonic-gate struct node *rhs) 9190Sstevel@tonic-gate { 9200Sstevel@tonic-gate struct node *ret; 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate ASSERT(lhs != NULL || rhs != NULL); 9230Sstevel@tonic-gate 9240Sstevel@tonic-gate ret = newnode(T_ARROW, 9250Sstevel@tonic-gate (lhs) ? lhs->file : rhs->file, 9260Sstevel@tonic-gate (lhs) ? lhs->line : rhs->line); 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate ret->u.arrow.lhs = lhs; 9290Sstevel@tonic-gate ret->u.arrow.nnp = nnp; 9300Sstevel@tonic-gate ret->u.arrow.knp = knp; 9310Sstevel@tonic-gate ret->u.arrow.rhs = rhs; 9320Sstevel@tonic-gate 9331414Scindi make_explicit(lhs, 0); 9341414Scindi make_explicit(rhs, 0); 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate check_arrow(ret); 9370Sstevel@tonic-gate 9380Sstevel@tonic-gate return (ret); 9390Sstevel@tonic-gate } 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate static struct lut * 9420Sstevel@tonic-gate nvpair2lut(struct node *np, struct lut *lutp, enum nodetype t) 9430Sstevel@tonic-gate { 9440Sstevel@tonic-gate if (np) { 9450Sstevel@tonic-gate if (np->t == T_NVPAIR) { 9460Sstevel@tonic-gate ASSERTeq(np->u.expr.left->t, T_NAME, 9470Sstevel@tonic-gate ptree_nodetype2str); 9480Sstevel@tonic-gate check_stmt_allowed_properties(t, np, lutp); 9490Sstevel@tonic-gate lutp = tree_s2np_lut_add(lutp, 9500Sstevel@tonic-gate np->u.expr.left->u.name.s, np->u.expr.right); 9510Sstevel@tonic-gate } else if (np->t == T_LIST) { 9520Sstevel@tonic-gate lutp = nvpair2lut(np->u.expr.left, lutp, t); 9530Sstevel@tonic-gate lutp = nvpair2lut(np->u.expr.right, lutp, t); 9540Sstevel@tonic-gate } else 9550Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 9560Sstevel@tonic-gate "internal error: nvpair2lut type %s", 9570Sstevel@tonic-gate ptree_nodetype2str(np->t)); 9580Sstevel@tonic-gate } 9590Sstevel@tonic-gate 9600Sstevel@tonic-gate return (lutp); 9610Sstevel@tonic-gate } 9620Sstevel@tonic-gate 9630Sstevel@tonic-gate struct lut * 9640Sstevel@tonic-gate tree_s2np_lut_add(struct lut *root, const char *s, struct node *np) 9650Sstevel@tonic-gate { 9660Sstevel@tonic-gate return (lut_add(root, (void *)s, (void *)np, NULL)); 9670Sstevel@tonic-gate } 9680Sstevel@tonic-gate 9690Sstevel@tonic-gate struct node * 9700Sstevel@tonic-gate tree_s2np_lut_lookup(struct lut *root, const char *s) 9710Sstevel@tonic-gate { 9720Sstevel@tonic-gate return (struct node *)lut_lookup(root, (void *)s, NULL); 9730Sstevel@tonic-gate } 9740Sstevel@tonic-gate 9750Sstevel@tonic-gate struct lut * 9760Sstevel@tonic-gate tree_name2np_lut_add(struct lut *root, struct node *namep, struct node *np) 9770Sstevel@tonic-gate { 9780Sstevel@tonic-gate return (lut_add(root, (void *)namep, (void *)np, 9790Sstevel@tonic-gate (lut_cmp)tree_namecmp)); 9800Sstevel@tonic-gate } 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate struct node * 9830Sstevel@tonic-gate tree_name2np_lut_lookup(struct lut *root, struct node *namep) 9840Sstevel@tonic-gate { 9850Sstevel@tonic-gate return (struct node *) 9860Sstevel@tonic-gate lut_lookup(root, (void *)namep, (lut_cmp)tree_namecmp); 9870Sstevel@tonic-gate } 9880Sstevel@tonic-gate 9890Sstevel@tonic-gate struct node * 9900Sstevel@tonic-gate tree_name2np_lut_lookup_name(struct lut *root, struct node *namep) 9910Sstevel@tonic-gate { 9920Sstevel@tonic-gate return (struct node *) 9930Sstevel@tonic-gate lut_lookup_lhs(root, (void *)namep, (lut_cmp)tree_namecmp); 9940Sstevel@tonic-gate } 9950Sstevel@tonic-gate 9960Sstevel@tonic-gate struct lut * 9970Sstevel@tonic-gate tree_event2np_lut_add(struct lut *root, struct node *enp, struct node *np) 9980Sstevel@tonic-gate { 9990Sstevel@tonic-gate return (lut_add(root, (void *)enp, (void *)np, (lut_cmp)tree_eventcmp)); 10000Sstevel@tonic-gate } 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate struct node * 10030Sstevel@tonic-gate tree_event2np_lut_lookup(struct lut *root, struct node *enp) 10040Sstevel@tonic-gate { 10050Sstevel@tonic-gate return ((struct node *) 10060Sstevel@tonic-gate lut_lookup(root, (void *)enp, (lut_cmp)tree_eventcmp)); 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate struct node * 10100Sstevel@tonic-gate tree_event2np_lut_lookup_event(struct lut *root, struct node *enp) 10110Sstevel@tonic-gate { 10120Sstevel@tonic-gate return ((struct node *) 10130Sstevel@tonic-gate lut_lookup_lhs(root, (void *)enp, (lut_cmp)tree_eventcmp)); 10140Sstevel@tonic-gate } 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate static struct node * 10170Sstevel@tonic-gate dodecl(enum nodetype t, const char *file, int line, 10180Sstevel@tonic-gate struct node *np, struct node *nvpairs, struct lut **lutpp, 10190Sstevel@tonic-gate struct stats *countp, int justpath) 10200Sstevel@tonic-gate { 10210Sstevel@tonic-gate struct node *ret; 10220Sstevel@tonic-gate struct node *decl; 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate /* allocate parse tree node */ 10250Sstevel@tonic-gate ret = newnode(t, file, line); 10260Sstevel@tonic-gate ret->u.stmt.np = np; 10270Sstevel@tonic-gate ret->u.stmt.nvpairs = nvpairs; 10280Sstevel@tonic-gate 10290Sstevel@tonic-gate /* 10300Sstevel@tonic-gate * the global lut pointed to by lutpp (Faults, Defects, Upsets, 10310Sstevel@tonic-gate * Errors, Ereports, Serds, FRUs, or ASRUs) keeps the first decl. 10320Sstevel@tonic-gate * if this isn't the first declr, we merge the 10330Sstevel@tonic-gate * nvpairs into the first decl so we have a 10340Sstevel@tonic-gate * merged table to look up properties from. 10350Sstevel@tonic-gate * if this is the first time we've seen this fault, 10360Sstevel@tonic-gate * we add it to the global lut and start lutp 10370Sstevel@tonic-gate * off with any nvpairs from this declaration statement. 10380Sstevel@tonic-gate */ 10390Sstevel@tonic-gate if (justpath && (decl = tree_name2np_lut_lookup(*lutpp, np)) == NULL) { 10400Sstevel@tonic-gate /* this is the first time name is declared */ 10410Sstevel@tonic-gate stats_counter_bump(countp); 10420Sstevel@tonic-gate *lutpp = tree_name2np_lut_add(*lutpp, np, ret); 10430Sstevel@tonic-gate ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t); 10440Sstevel@tonic-gate } else if (!justpath && 10450Sstevel@tonic-gate (decl = tree_event2np_lut_lookup(*lutpp, np)) == NULL) { 10460Sstevel@tonic-gate /* this is the first time event is declared */ 10470Sstevel@tonic-gate stats_counter_bump(countp); 10480Sstevel@tonic-gate *lutpp = tree_event2np_lut_add(*lutpp, np, ret); 10490Sstevel@tonic-gate ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t); 10500Sstevel@tonic-gate } else { 10510Sstevel@tonic-gate /* was declared before, just add new nvpairs to its lutp */ 10520Sstevel@tonic-gate decl->u.stmt.lutp = nvpair2lut(nvpairs, decl->u.stmt.lutp, t); 10530Sstevel@tonic-gate } 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate return (ret); 10560Sstevel@tonic-gate } 10570Sstevel@tonic-gate 10580Sstevel@tonic-gate /*ARGSUSED*/ 10590Sstevel@tonic-gate static void 10600Sstevel@tonic-gate update_serd_refstmt(void *lhs, void *rhs, void *arg) 10610Sstevel@tonic-gate { 10620Sstevel@tonic-gate struct node *serd; 10630Sstevel@tonic-gate 10640Sstevel@tonic-gate ASSERT(rhs != NULL); 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate serd = tree_s2np_lut_lookup(((struct node *)rhs)->u.stmt.lutp, 10674436Sstephh L_engine); 10680Sstevel@tonic-gate if (serd == NULL) 10690Sstevel@tonic-gate return; 10700Sstevel@tonic-gate 10710Sstevel@tonic-gate ASSERT(serd->t == T_EVENT); 10720Sstevel@tonic-gate if (arg != NULL && tree_eventcmp(serd, (struct node *)arg) != 0) 10730Sstevel@tonic-gate return; 10740Sstevel@tonic-gate 10750Sstevel@tonic-gate serd = tree_event2np_lut_lookup(SERDs, serd); 10760Sstevel@tonic-gate if (serd != NULL) 10770Sstevel@tonic-gate serd->u.stmt.flags |= STMT_REF; 10780Sstevel@tonic-gate } 10790Sstevel@tonic-gate 10800Sstevel@tonic-gate struct node * 10810Sstevel@tonic-gate tree_decl(enum nodetype t, struct node *np, struct node *nvpairs, 10820Sstevel@tonic-gate const char *file, int line) 10830Sstevel@tonic-gate { 10840Sstevel@tonic-gate struct node *decl; 10850Sstevel@tonic-gate struct node *ret; 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate ASSERT(np != NULL); 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate check_type_iterator(np); 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate switch (t) { 10920Sstevel@tonic-gate case T_EVENT: 10930Sstevel@tonic-gate /* determine the type of event being declared */ 10940Sstevel@tonic-gate ASSERT(np->u.event.ename->t == T_NAME); 10950Sstevel@tonic-gate switch (np->u.event.ename->u.name.t) { 10960Sstevel@tonic-gate case N_FAULT: 10970Sstevel@tonic-gate ret = dodecl(T_FAULT, file, line, np, nvpairs, 10980Sstevel@tonic-gate &Faults, Faultcount, 0); 10990Sstevel@tonic-gate break; 11000Sstevel@tonic-gate 11010Sstevel@tonic-gate case N_UPSET: 11020Sstevel@tonic-gate ret = dodecl(T_UPSET, file, line, np, nvpairs, 11030Sstevel@tonic-gate &Upsets, Upsetcount, 0); 11040Sstevel@tonic-gate 11050Sstevel@tonic-gate /* increment serd statement reference */ 11060Sstevel@tonic-gate decl = tree_event2np_lut_lookup(Upsets, np); 11070Sstevel@tonic-gate update_serd_refstmt(NULL, decl, NULL); 11080Sstevel@tonic-gate break; 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate case N_DEFECT: 11110Sstevel@tonic-gate ret = dodecl(T_DEFECT, file, line, np, nvpairs, 11120Sstevel@tonic-gate &Defects, Defectcount, 0); 11130Sstevel@tonic-gate break; 11140Sstevel@tonic-gate 11150Sstevel@tonic-gate case N_ERROR: 11160Sstevel@tonic-gate ret = dodecl(T_ERROR, file, line, np, nvpairs, 11170Sstevel@tonic-gate &Errors, Errorcount, 0); 11180Sstevel@tonic-gate break; 11190Sstevel@tonic-gate 11200Sstevel@tonic-gate case N_EREPORT: 11210Sstevel@tonic-gate ret = dodecl(T_EREPORT, file, line, np, nvpairs, 11220Sstevel@tonic-gate &Ereports, Ereportcount, 0); 11230Sstevel@tonic-gate /* 1124*6640Scth * Keep a lut of just the enames, so that the DE 11250Sstevel@tonic-gate * can subscribe to a uniqified list of event 11260Sstevel@tonic-gate * classes. 11270Sstevel@tonic-gate */ 11280Sstevel@tonic-gate Ereportenames = 11290Sstevel@tonic-gate tree_name2np_lut_add(Ereportenames, 11300Sstevel@tonic-gate np->u.event.ename, np); 1131*6640Scth 1132*6640Scth /* 1133*6640Scth * Keep a lut of the enames (event classes) to 1134*6640Scth * silently discard if we can't find a matching 1135*6640Scth * configuration node when an ereport of of a given 1136*6640Scth * class is received. Such events are declaired 1137*6640Scth * with 'discard_if_config_unknown=1'. 1138*6640Scth */ 1139*6640Scth if (tree_s2np_lut_lookup(ret->u.stmt.lutp, 1140*6640Scth L_discard_if_config_unknown)) { 1141*6640Scth Ereportenames_discard = lut_add( 1142*6640Scth Ereportenames_discard, 1143*6640Scth (void *)np->u.event.ename->u.name.s, 1144*6640Scth (void *)np->u.event.ename->u.name.s, NULL); 1145*6640Scth } 11460Sstevel@tonic-gate break; 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate default: 11490Sstevel@tonic-gate outfl(O_ERR, file, line, 11500Sstevel@tonic-gate "tree_decl: internal error, event name type %s", 11510Sstevel@tonic-gate ptree_nametype2str(np->u.event.ename->u.name.t)); 11520Sstevel@tonic-gate } 11530Sstevel@tonic-gate break; 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate case T_ENGINE: 11560Sstevel@tonic-gate /* determine the type of engine being declared */ 11570Sstevel@tonic-gate ASSERT(np->u.event.ename->t == T_NAME); 11580Sstevel@tonic-gate switch (np->u.event.ename->u.name.t) { 11590Sstevel@tonic-gate case N_SERD: 11600Sstevel@tonic-gate ret = dodecl(T_SERD, file, line, np, nvpairs, 11610Sstevel@tonic-gate &SERDs, SERDcount, 0); 11620Sstevel@tonic-gate lut_walk(Upsets, update_serd_refstmt, np); 11630Sstevel@tonic-gate break; 11640Sstevel@tonic-gate 11651414Scindi case N_STAT: 11661414Scindi ret = dodecl(T_STAT, file, line, np, nvpairs, 11671414Scindi &STATs, STATcount, 0); 11681414Scindi break; 11691414Scindi 11700Sstevel@tonic-gate default: 11710Sstevel@tonic-gate outfl(O_ERR, file, line, 11720Sstevel@tonic-gate "tree_decl: internal error, engine name type %s", 11730Sstevel@tonic-gate ptree_nametype2str(np->u.event.ename->u.name.t)); 11740Sstevel@tonic-gate } 11750Sstevel@tonic-gate break; 11760Sstevel@tonic-gate case T_ASRU: 11770Sstevel@tonic-gate ret = dodecl(T_ASRU, file, line, np, nvpairs, 11780Sstevel@tonic-gate &ASRUs, ASRUcount, 1); 11790Sstevel@tonic-gate break; 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate case T_FRU: 11820Sstevel@tonic-gate ret = dodecl(T_FRU, file, line, np, nvpairs, 11830Sstevel@tonic-gate &FRUs, FRUcount, 1); 11840Sstevel@tonic-gate break; 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate case T_CONFIG: 11870Sstevel@tonic-gate /* 11880Sstevel@tonic-gate * config statements are different from above: they 11890Sstevel@tonic-gate * are not merged at all (until the configuration cache 11900Sstevel@tonic-gate * code does its own style of merging. and the properties 11910Sstevel@tonic-gate * are a free-for-all -- we don't check for allowed or 11920Sstevel@tonic-gate * required config properties. 11930Sstevel@tonic-gate */ 11940Sstevel@tonic-gate ret = newnode(T_CONFIG, file, line); 11950Sstevel@tonic-gate ret->u.stmt.np = np; 11960Sstevel@tonic-gate ret->u.stmt.nvpairs = nvpairs; 11970Sstevel@tonic-gate ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, T_CONFIG); 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate if (lut_lookup(Configs, np, (lut_cmp)tree_namecmp) == NULL) 12000Sstevel@tonic-gate stats_counter_bump(Configcount); 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate Configs = lut_add(Configs, (void *)np, (void *)ret, NULL); 12030Sstevel@tonic-gate break; 12040Sstevel@tonic-gate 12050Sstevel@tonic-gate default: 12060Sstevel@tonic-gate out(O_DIE, "tree_decl: internal error, type %s", 12070Sstevel@tonic-gate ptree_nodetype2str(t)); 12080Sstevel@tonic-gate } 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate return (ret); 12110Sstevel@tonic-gate } 12120Sstevel@tonic-gate 12130Sstevel@tonic-gate /* keep backpointers in arrows to the prop they belong to (used for scoping) */ 12140Sstevel@tonic-gate static void 12150Sstevel@tonic-gate set_arrow_prop(struct node *prop, struct node *np) 12160Sstevel@tonic-gate { 12170Sstevel@tonic-gate if (np == NULL) 12180Sstevel@tonic-gate return; 12190Sstevel@tonic-gate 12200Sstevel@tonic-gate if (np->t == T_ARROW) { 12210Sstevel@tonic-gate np->u.arrow.prop = prop; 12220Sstevel@tonic-gate set_arrow_prop(prop, np->u.arrow.lhs); 12230Sstevel@tonic-gate /* 12240Sstevel@tonic-gate * no need to recurse right or handle T_LIST since 12250Sstevel@tonic-gate * T_ARROWs always cascade left and are at the top 12260Sstevel@tonic-gate * of the parse tree. (you can see this in the rule 12270Sstevel@tonic-gate * for "propbody" in escparse.y.) 12280Sstevel@tonic-gate */ 12290Sstevel@tonic-gate } 12300Sstevel@tonic-gate } 12310Sstevel@tonic-gate 12320Sstevel@tonic-gate struct node * 12330Sstevel@tonic-gate tree_stmt(enum nodetype t, struct node *np, const char *file, int line) 12340Sstevel@tonic-gate { 12350Sstevel@tonic-gate struct node *ret = newnode(t, file, line); 12360Sstevel@tonic-gate struct node *pp; 12370Sstevel@tonic-gate int inlist = 0; 12380Sstevel@tonic-gate 12390Sstevel@tonic-gate ret->u.stmt.np = np; 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate switch (t) { 12420Sstevel@tonic-gate case T_PROP: 1243854Srw145199 check_proplists(t, np); 12440Sstevel@tonic-gate check_propnames(t, np, 0, 0); 12450Sstevel@tonic-gate check_propscope(np); 12460Sstevel@tonic-gate set_arrow_prop(ret, np); 12470Sstevel@tonic-gate 12480Sstevel@tonic-gate for (pp = Props; pp; pp = pp->u.stmt.next) { 12490Sstevel@tonic-gate if (tree_treecmp(pp, ret, T_NAME, 12504436Sstephh (lut_cmp)tree_namecmp) == 0) { 12510Sstevel@tonic-gate inlist = 1; 12520Sstevel@tonic-gate break; 12530Sstevel@tonic-gate } 12540Sstevel@tonic-gate } 12550Sstevel@tonic-gate if (inlist == 0) 12560Sstevel@tonic-gate stats_counter_bump(Propcount); 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate /* "Props" is a linked list of all prop statements */ 12590Sstevel@tonic-gate if (Lastprops) 12600Sstevel@tonic-gate Lastprops->u.stmt.next = ret; 12610Sstevel@tonic-gate else 12620Sstevel@tonic-gate Props = ret; 12630Sstevel@tonic-gate Lastprops = ret; 12640Sstevel@tonic-gate break; 12650Sstevel@tonic-gate 12660Sstevel@tonic-gate case T_MASK: 1267854Srw145199 check_proplists(t, np); 12680Sstevel@tonic-gate check_propnames(t, np, 0, 0); 12690Sstevel@tonic-gate check_propscope(np); 12700Sstevel@tonic-gate set_arrow_prop(ret, np); 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate for (pp = Masks; pp; pp = pp->u.stmt.next) { 12730Sstevel@tonic-gate if (tree_treecmp(pp, ret, T_NAME, 12744436Sstephh (lut_cmp)tree_namecmp) == 0) { 12750Sstevel@tonic-gate inlist = 1; 12760Sstevel@tonic-gate break; 12770Sstevel@tonic-gate } 12780Sstevel@tonic-gate } 12790Sstevel@tonic-gate if (inlist == 0) 12800Sstevel@tonic-gate stats_counter_bump(Maskcount); 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate /* "Masks" is a linked list of all mask statements */ 12830Sstevel@tonic-gate if (Lastmasks) 12840Sstevel@tonic-gate Lastmasks->u.stmt.next = ret; 12850Sstevel@tonic-gate else 12860Sstevel@tonic-gate Masks = ret; 12870Sstevel@tonic-gate Lastmasks = ret; 12880Sstevel@tonic-gate stats_counter_bump(Maskcount); 12890Sstevel@tonic-gate break; 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate default: 12920Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 12930Sstevel@tonic-gate "tree_stmt: internal error (t %d)", t); 12940Sstevel@tonic-gate } 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate return (ret); 12970Sstevel@tonic-gate } 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate void 13000Sstevel@tonic-gate tree_report() 13010Sstevel@tonic-gate { 13020Sstevel@tonic-gate /* 13030Sstevel@tonic-gate * The only declarations with required properties 13040Sstevel@tonic-gate * currently are faults and serds. Make sure the 13050Sstevel@tonic-gate * the declarations have the required properties. 13060Sstevel@tonic-gate */ 13070Sstevel@tonic-gate lut_walk(Faults, (lut_cb)check_required_props, (void *)T_FAULT); 13080Sstevel@tonic-gate lut_walk(Upsets, (lut_cb)check_required_props, (void *)T_UPSET); 13090Sstevel@tonic-gate lut_walk(Errors, (lut_cb)check_required_props, (void *)T_ERROR); 13100Sstevel@tonic-gate lut_walk(Ereports, (lut_cb)check_required_props, (void *)T_EREPORT); 13110Sstevel@tonic-gate lut_walk(SERDs, (lut_cb)check_required_props, (void *)T_SERD); 13121414Scindi lut_walk(STATs, (lut_cb)check_required_props, (void *)T_STAT); 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate /* 13150Sstevel@tonic-gate * we do this now rather than while building the parse 13160Sstevel@tonic-gate * tree because it is inconvenient for the user if we 13170Sstevel@tonic-gate * require SERD engines to be declared before used in 13180Sstevel@tonic-gate * an upset "engine" property. 13190Sstevel@tonic-gate */ 13200Sstevel@tonic-gate lut_walk(Faults, (lut_cb)check_refcount, (void *)T_FAULT); 13210Sstevel@tonic-gate lut_walk(Upsets, (lut_cb)check_upset_engine, (void *)T_UPSET); 13220Sstevel@tonic-gate lut_walk(Upsets, (lut_cb)check_refcount, (void *)T_UPSET); 13230Sstevel@tonic-gate lut_walk(Errors, (lut_cb)check_refcount, (void *)T_ERROR); 13240Sstevel@tonic-gate lut_walk(Ereports, (lut_cb)check_refcount, (void *)T_EREPORT); 13250Sstevel@tonic-gate lut_walk(SERDs, (lut_cb)check_refcount, (void *)T_SERD); 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate /* check for cycles */ 13280Sstevel@tonic-gate lut_walk(Errors, (lut_cb)check_cycle, (void *)0); 13290Sstevel@tonic-gate } 13300Sstevel@tonic-gate 13310Sstevel@tonic-gate /* compare two T_NAMES by only looking at components, not iterators */ 13320Sstevel@tonic-gate int 13330Sstevel@tonic-gate tree_namecmp(struct node *np1, struct node *np2) 13340Sstevel@tonic-gate { 13350Sstevel@tonic-gate ASSERT(np1 != NULL); 13360Sstevel@tonic-gate ASSERT(np2 != NULL); 13370Sstevel@tonic-gate ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t)); 13380Sstevel@tonic-gate ASSERTinfo(np2->t == T_NAME, ptree_nodetype2str(np1->t)); 13390Sstevel@tonic-gate 13400Sstevel@tonic-gate while (np1 && np2 && np1->u.name.s == np2->u.name.s) { 13410Sstevel@tonic-gate np1 = np1->u.name.next; 13420Sstevel@tonic-gate np2 = np2->u.name.next; 13430Sstevel@tonic-gate } 13440Sstevel@tonic-gate if (np1 == NULL) 13450Sstevel@tonic-gate if (np2 == NULL) 13460Sstevel@tonic-gate return (0); 13470Sstevel@tonic-gate else 13480Sstevel@tonic-gate return (-1); 13490Sstevel@tonic-gate else if (np2 == NULL) 13500Sstevel@tonic-gate return (1); 13510Sstevel@tonic-gate else 13520Sstevel@tonic-gate return (np2->u.name.s - np1->u.name.s); 13530Sstevel@tonic-gate } 13540Sstevel@tonic-gate 13550Sstevel@tonic-gate int 13560Sstevel@tonic-gate tree_eventcmp(struct node *np1, struct node *np2) 13570Sstevel@tonic-gate { 13580Sstevel@tonic-gate int ret; 13590Sstevel@tonic-gate 13600Sstevel@tonic-gate ASSERT(np1 != NULL); 13610Sstevel@tonic-gate ASSERT(np2 != NULL); 13620Sstevel@tonic-gate ASSERTinfo(np1->t == T_EVENT, ptree_nodetype2str(np1->t)); 13630Sstevel@tonic-gate ASSERTinfo(np2->t == T_EVENT, ptree_nodetype2str(np2->t)); 13640Sstevel@tonic-gate 13650Sstevel@tonic-gate if ((ret = tree_namecmp(np1->u.event.ename, 13664436Sstephh np2->u.event.ename)) == 0) { 13670Sstevel@tonic-gate if (np1->u.event.epname == NULL && 13684436Sstephh np2->u.event.epname == NULL) 13690Sstevel@tonic-gate return (0); 13700Sstevel@tonic-gate else if (np1->u.event.epname == NULL) 13710Sstevel@tonic-gate return (-1); 13720Sstevel@tonic-gate else if (np2->u.event.epname == NULL) 13730Sstevel@tonic-gate return (1); 13740Sstevel@tonic-gate else 13750Sstevel@tonic-gate return tree_namecmp(np1->u.event.epname, 13764436Sstephh np2->u.event.epname); 13770Sstevel@tonic-gate } else 13780Sstevel@tonic-gate return (ret); 13790Sstevel@tonic-gate } 1380