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 /* 22*5947Sstephh * 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; 1290Sstevel@tonic-gate lut_free(SERDs, NULL, NULL); 1300Sstevel@tonic-gate SERDs = NULL; 1311414Scindi lut_free(STATs, NULL, NULL); 1321414Scindi STATs = NULL; 1330Sstevel@tonic-gate lut_free(ASRUs, NULL, NULL); 1340Sstevel@tonic-gate ASRUs = NULL; 1350Sstevel@tonic-gate lut_free(FRUs, NULL, NULL); 1360Sstevel@tonic-gate FRUs = NULL; 1370Sstevel@tonic-gate lut_free(Configs, NULL, NULL); 1380Sstevel@tonic-gate Configs = NULL; 139*5947Sstephh lut_free(Usedprops, NULL, NULL); 140*5947Sstephh Usedprops = NULL; 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate Props = Lastprops = NULL; 1430Sstevel@tonic-gate Masks = Lastmasks = NULL; 1440Sstevel@tonic-gate Problems = Lastproblems = NULL; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate if (Newname != NULL) { 1470Sstevel@tonic-gate FREE(Newname); 1480Sstevel@tonic-gate Newname = NULL; 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate 1524436Sstephh /*ARGSUSED*/ 1534436Sstephh static int 1544436Sstephh nodesize(enum nodetype t, struct node *ret) 1554436Sstephh { 1564436Sstephh int size = sizeof (struct node); 1574436Sstephh 1584436Sstephh switch (t) { 1594436Sstephh case T_NAME: 1604436Sstephh size += sizeof (ret->u.name) - sizeof (ret->u); 1614436Sstephh break; 1624436Sstephh 1634436Sstephh case T_GLOBID: 1644436Sstephh size += sizeof (ret->u.globid) - sizeof (ret->u); 1654436Sstephh break; 1664436Sstephh 1674436Sstephh case T_TIMEVAL: 1684436Sstephh case T_NUM: 1694436Sstephh size += sizeof (ret->u.ull) - sizeof (ret->u); 1704436Sstephh break; 1714436Sstephh 1724436Sstephh case T_QUOTE: 1734436Sstephh size += sizeof (ret->u.quote) - sizeof (ret->u); 1744436Sstephh break; 1754436Sstephh 1764436Sstephh case T_FUNC: 1774436Sstephh size += sizeof (ret->u.func) - sizeof (ret->u); 1784436Sstephh break; 1794436Sstephh 1804436Sstephh case T_FAULT: 1814436Sstephh case T_UPSET: 1824436Sstephh case T_DEFECT: 1834436Sstephh case T_ERROR: 1844436Sstephh case T_EREPORT: 1854436Sstephh case T_ASRU: 1864436Sstephh case T_FRU: 1874436Sstephh case T_SERD: 1884436Sstephh case T_STAT: 1894436Sstephh case T_CONFIG: 1904436Sstephh case T_PROP: 1914436Sstephh case T_MASK: 1924436Sstephh size += sizeof (ret->u.stmt) - sizeof (ret->u); 1934436Sstephh break; 1944436Sstephh 1954436Sstephh case T_EVENT: 1964436Sstephh size += sizeof (ret->u.event) - sizeof (ret->u); 1974436Sstephh break; 1984436Sstephh 1994436Sstephh case T_ARROW: 2004436Sstephh size += sizeof (ret->u.arrow) - sizeof (ret->u); 2014436Sstephh break; 2024436Sstephh 2034436Sstephh default: 2044436Sstephh size += sizeof (ret->u.expr) - sizeof (ret->u); 2054436Sstephh break; 2064436Sstephh } 2074436Sstephh return (size); 2084436Sstephh } 2094436Sstephh 2100Sstevel@tonic-gate struct node * 2110Sstevel@tonic-gate newnode(enum nodetype t, const char *file, int line) 2120Sstevel@tonic-gate { 2134436Sstephh struct node *ret = NULL; 2144436Sstephh int size = nodesize(t, ret); 2150Sstevel@tonic-gate 2164436Sstephh ret = alloc_xmalloc(size); 2170Sstevel@tonic-gate stats_counter_bump(Nodecount); 2184436Sstephh bzero(ret, size); 2190Sstevel@tonic-gate ret->t = t; 2200Sstevel@tonic-gate ret->file = (file == NULL) ? "<nofile>" : file; 2210Sstevel@tonic-gate ret->line = line; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate return (ret); 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate /*ARGSUSED*/ 2270Sstevel@tonic-gate void 2280Sstevel@tonic-gate tree_free(struct node *root) 2290Sstevel@tonic-gate { 2300Sstevel@tonic-gate if (root == NULL) 2310Sstevel@tonic-gate return; 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate switch (root->t) { 2340Sstevel@tonic-gate case T_NAME: 2350Sstevel@tonic-gate tree_free(root->u.name.child); 2360Sstevel@tonic-gate tree_free(root->u.name.next); 2370Sstevel@tonic-gate break; 2380Sstevel@tonic-gate case T_FUNC: 2390Sstevel@tonic-gate tree_free(root->u.func.arglist); 2400Sstevel@tonic-gate break; 2410Sstevel@tonic-gate case T_AND: 2420Sstevel@tonic-gate case T_OR: 2430Sstevel@tonic-gate case T_EQ: 2440Sstevel@tonic-gate case T_NE: 2450Sstevel@tonic-gate case T_ADD: 2460Sstevel@tonic-gate case T_DIV: 2470Sstevel@tonic-gate case T_MOD: 2480Sstevel@tonic-gate case T_MUL: 2490Sstevel@tonic-gate case T_SUB: 2500Sstevel@tonic-gate case T_LT: 2510Sstevel@tonic-gate case T_LE: 2520Sstevel@tonic-gate case T_GT: 2530Sstevel@tonic-gate case T_GE: 2540Sstevel@tonic-gate case T_BITAND: 2550Sstevel@tonic-gate case T_BITOR: 2560Sstevel@tonic-gate case T_BITXOR: 2570Sstevel@tonic-gate case T_BITNOT: 2580Sstevel@tonic-gate case T_LSHIFT: 2590Sstevel@tonic-gate case T_RSHIFT: 2600Sstevel@tonic-gate case T_NVPAIR: 2610Sstevel@tonic-gate case T_ASSIGN: 2620Sstevel@tonic-gate case T_CONDIF: 2630Sstevel@tonic-gate case T_CONDELSE: 2640Sstevel@tonic-gate case T_LIST: 2650Sstevel@tonic-gate tree_free(root->u.expr.left); 2660Sstevel@tonic-gate tree_free(root->u.expr.right); 2670Sstevel@tonic-gate break; 2680Sstevel@tonic-gate case T_EVENT: 2690Sstevel@tonic-gate tree_free(root->u.event.ename); 2700Sstevel@tonic-gate tree_free(root->u.event.epname); 2710Sstevel@tonic-gate tree_free(root->u.event.eexprlist); 2720Sstevel@tonic-gate break; 2730Sstevel@tonic-gate case T_NOT: 2740Sstevel@tonic-gate tree_free(root->u.expr.left); 2750Sstevel@tonic-gate break; 2760Sstevel@tonic-gate case T_ARROW: 2770Sstevel@tonic-gate tree_free(root->u.arrow.lhs); 2780Sstevel@tonic-gate tree_free(root->u.arrow.nnp); 2790Sstevel@tonic-gate tree_free(root->u.arrow.knp); 2800Sstevel@tonic-gate tree_free(root->u.arrow.rhs); 2810Sstevel@tonic-gate break; 2820Sstevel@tonic-gate case T_PROP: 2830Sstevel@tonic-gate case T_MASK: 2840Sstevel@tonic-gate tree_free(root->u.stmt.np); 2850Sstevel@tonic-gate break; 2860Sstevel@tonic-gate case T_FAULT: 2870Sstevel@tonic-gate case T_UPSET: 2880Sstevel@tonic-gate case T_DEFECT: 2890Sstevel@tonic-gate case T_ERROR: 2900Sstevel@tonic-gate case T_EREPORT: 2910Sstevel@tonic-gate case T_ASRU: 2920Sstevel@tonic-gate case T_FRU: 2930Sstevel@tonic-gate case T_SERD: 2941414Scindi case T_STAT: 2950Sstevel@tonic-gate case T_CONFIG: 2960Sstevel@tonic-gate tree_free(root->u.stmt.np); 2970Sstevel@tonic-gate if (root->u.stmt.nvpairs) 2980Sstevel@tonic-gate tree_free(root->u.stmt.nvpairs); 2990Sstevel@tonic-gate if (root->u.stmt.lutp) 3000Sstevel@tonic-gate lut_free(root->u.stmt.lutp, NULL, NULL); 3010Sstevel@tonic-gate break; 3020Sstevel@tonic-gate case T_TIMEVAL: 3030Sstevel@tonic-gate case T_NUM: 3040Sstevel@tonic-gate case T_QUOTE: 3050Sstevel@tonic-gate case T_GLOBID: 3060Sstevel@tonic-gate case T_NOTHING: 3070Sstevel@tonic-gate break; 3080Sstevel@tonic-gate default: 3090Sstevel@tonic-gate out(O_DIE, 3100Sstevel@tonic-gate "internal error: tree_free unexpected nodetype: %d", 3110Sstevel@tonic-gate root->t); 3120Sstevel@tonic-gate /*NOTREACHED*/ 3130Sstevel@tonic-gate } 3144436Sstephh alloc_xfree((char *)root, nodesize(root->t, root)); 3150Sstevel@tonic-gate } 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate static int 3180Sstevel@tonic-gate tree_treecmp(struct node *np1, struct node *np2, enum nodetype t, 3190Sstevel@tonic-gate lut_cmp cmp_func) 3200Sstevel@tonic-gate { 3210Sstevel@tonic-gate if (np1 == NULL || np2 == NULL) 3220Sstevel@tonic-gate return (0); 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate if (np1->t != np2->t) 3250Sstevel@tonic-gate return (1); 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate ASSERT(cmp_func != NULL); 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate if (np1->t == t) 3300Sstevel@tonic-gate return ((*cmp_func)(np1, np2)); 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate switch (np1->t) { 3330Sstevel@tonic-gate case T_NAME: 3340Sstevel@tonic-gate if (tree_treecmp(np1->u.name.child, np2->u.name.child, t, 3354436Sstephh cmp_func)) 3360Sstevel@tonic-gate return (1); 3370Sstevel@tonic-gate return (tree_treecmp(np1->u.name.next, np2->u.name.next, t, 3384436Sstephh cmp_func)); 3390Sstevel@tonic-gate /*NOTREACHED*/ 3400Sstevel@tonic-gate break; 3410Sstevel@tonic-gate case T_FUNC: 3420Sstevel@tonic-gate return (tree_treecmp(np1->u.func.arglist, np2->u.func.arglist, 3434436Sstephh t, cmp_func)); 3440Sstevel@tonic-gate /*NOTREACHED*/ 3450Sstevel@tonic-gate break; 3460Sstevel@tonic-gate case T_AND: 3470Sstevel@tonic-gate case T_OR: 3480Sstevel@tonic-gate case T_EQ: 3490Sstevel@tonic-gate case T_NE: 3500Sstevel@tonic-gate case T_ADD: 3510Sstevel@tonic-gate case T_DIV: 3520Sstevel@tonic-gate case T_MOD: 3530Sstevel@tonic-gate case T_MUL: 3540Sstevel@tonic-gate case T_SUB: 3550Sstevel@tonic-gate case T_LT: 3560Sstevel@tonic-gate case T_LE: 3570Sstevel@tonic-gate case T_GT: 3580Sstevel@tonic-gate case T_GE: 3590Sstevel@tonic-gate case T_BITAND: 3600Sstevel@tonic-gate case T_BITOR: 3610Sstevel@tonic-gate case T_BITXOR: 3620Sstevel@tonic-gate case T_BITNOT: 3630Sstevel@tonic-gate case T_LSHIFT: 3640Sstevel@tonic-gate case T_RSHIFT: 3650Sstevel@tonic-gate case T_NVPAIR: 3660Sstevel@tonic-gate case T_ASSIGN: 3670Sstevel@tonic-gate case T_CONDIF: 3680Sstevel@tonic-gate case T_CONDELSE: 3690Sstevel@tonic-gate case T_LIST: 3700Sstevel@tonic-gate if (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t, 3714436Sstephh cmp_func)) 3720Sstevel@tonic-gate return (1); 3730Sstevel@tonic-gate return (tree_treecmp(np1->u.expr.right, np2->u.expr.right, t, 3744436Sstephh cmp_func)); 3750Sstevel@tonic-gate /*NOTREACHED*/ 3760Sstevel@tonic-gate break; 3770Sstevel@tonic-gate case T_EVENT: 3780Sstevel@tonic-gate if (tree_treecmp(np1->u.event.ename, np2->u.event.ename, t, 3794436Sstephh cmp_func)) 3800Sstevel@tonic-gate return (1); 3810Sstevel@tonic-gate if (tree_treecmp(np1->u.event.epname, np2->u.event.epname, t, 3824436Sstephh cmp_func)) 3830Sstevel@tonic-gate return (1); 3840Sstevel@tonic-gate return (tree_treecmp(np1->u.event.eexprlist, 3854436Sstephh np2->u.event.eexprlist, t, cmp_func)); 3860Sstevel@tonic-gate /*NOTREACHED*/ 3870Sstevel@tonic-gate break; 3880Sstevel@tonic-gate case T_NOT: 3890Sstevel@tonic-gate return (tree_treecmp(np1->u.expr.left, np2->u.expr.left, t, 3904436Sstephh cmp_func)); 3910Sstevel@tonic-gate /*NOTREACHED*/ 3920Sstevel@tonic-gate break; 3930Sstevel@tonic-gate case T_ARROW: 3940Sstevel@tonic-gate if (tree_treecmp(np1->u.arrow.lhs, np2->u.arrow.lhs, t, 3954436Sstephh cmp_func)) 3960Sstevel@tonic-gate return (1); 3970Sstevel@tonic-gate if (tree_treecmp(np1->u.arrow.nnp, np2->u.arrow.nnp, t, 3984436Sstephh cmp_func)) 3990Sstevel@tonic-gate return (1); 4000Sstevel@tonic-gate if (tree_treecmp(np1->u.arrow.knp, np2->u.arrow.knp, t, 4014436Sstephh cmp_func)) 4020Sstevel@tonic-gate return (1); 4030Sstevel@tonic-gate return (tree_treecmp(np1->u.arrow.rhs, np2->u.arrow.rhs, t, 4044436Sstephh cmp_func)); 4050Sstevel@tonic-gate /*NOTREACHED*/ 4060Sstevel@tonic-gate break; 4070Sstevel@tonic-gate case T_PROP: 4080Sstevel@tonic-gate case T_MASK: 4090Sstevel@tonic-gate return (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t, 4104436Sstephh cmp_func)); 4110Sstevel@tonic-gate /*NOTREACHED*/ 4120Sstevel@tonic-gate break; 4130Sstevel@tonic-gate case T_FAULT: 4140Sstevel@tonic-gate case T_UPSET: 4150Sstevel@tonic-gate case T_DEFECT: 4160Sstevel@tonic-gate case T_ERROR: 4170Sstevel@tonic-gate case T_EREPORT: 4180Sstevel@tonic-gate case T_ASRU: 4190Sstevel@tonic-gate case T_FRU: 4200Sstevel@tonic-gate case T_SERD: 4211414Scindi case T_STAT: 4220Sstevel@tonic-gate if (tree_treecmp(np1->u.stmt.np, np2->u.stmt.np, t, cmp_func)) 4230Sstevel@tonic-gate return (1); 4240Sstevel@tonic-gate return (tree_treecmp(np1->u.stmt.nvpairs, np2->u.stmt.nvpairs, 4254436Sstephh t, cmp_func)); 4260Sstevel@tonic-gate /*NOTREACHED*/ 4270Sstevel@tonic-gate break; 4280Sstevel@tonic-gate case T_TIMEVAL: 4290Sstevel@tonic-gate case T_NUM: 4300Sstevel@tonic-gate case T_QUOTE: 4310Sstevel@tonic-gate case T_GLOBID: 4320Sstevel@tonic-gate case T_NOTHING: 4330Sstevel@tonic-gate break; 4340Sstevel@tonic-gate default: 4350Sstevel@tonic-gate out(O_DIE, 4360Sstevel@tonic-gate "internal error: tree_treecmp unexpected nodetype: %d", 4370Sstevel@tonic-gate np1->t); 4380Sstevel@tonic-gate /*NOTREACHED*/ 4390Sstevel@tonic-gate break; 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate return (0); 4430Sstevel@tonic-gate } 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate struct node * 4460Sstevel@tonic-gate tree_root(struct node *np) 4470Sstevel@tonic-gate { 4480Sstevel@tonic-gate if (np) 4490Sstevel@tonic-gate Root = np; 4500Sstevel@tonic-gate return (Root); 4510Sstevel@tonic-gate } 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate struct node * 4540Sstevel@tonic-gate tree_nothing(void) 4550Sstevel@tonic-gate { 4560Sstevel@tonic-gate return (newnode(T_NOTHING, L_nofile, 0)); 4570Sstevel@tonic-gate } 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate struct node * 4600Sstevel@tonic-gate tree_expr(enum nodetype t, struct node *left, struct node *right) 4610Sstevel@tonic-gate { 4620Sstevel@tonic-gate struct node *ret; 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate ASSERTinfo(left != NULL || right != NULL, ptree_nodetype2str(t)); 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate ret = newnode(t, 4670Sstevel@tonic-gate (left) ? left->file : right->file, 4680Sstevel@tonic-gate (left) ? left->line : right->line); 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate ret->u.expr.left = left; 4710Sstevel@tonic-gate ret->u.expr.right = right; 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate check_expr(ret); 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate return (ret); 4760Sstevel@tonic-gate } 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate /* 4790Sstevel@tonic-gate * ename_compress -- convert event class name in to more space-efficient form 4800Sstevel@tonic-gate * 4810Sstevel@tonic-gate * this routine is called after the parser has completed an "ename", which 4820Sstevel@tonic-gate * is that part of an event that contains the class name (like ereport.x.y.z). 4830Sstevel@tonic-gate * after this routine gets done with the ename, two things are true: 4840Sstevel@tonic-gate * 1. the ename uses only a single struct node 4850Sstevel@tonic-gate * 2. ename->u.name.s contains the *complete* class name, dots and all, 4860Sstevel@tonic-gate * entered into the string table. 4870Sstevel@tonic-gate * 4880Sstevel@tonic-gate * so in addition to saving space by using fewer struct nodes, this routine 4890Sstevel@tonic-gate * allows consumers of the fault tree to assume the ename is a single 4900Sstevel@tonic-gate * string, rather than a linked list of strings. 4910Sstevel@tonic-gate */ 4920Sstevel@tonic-gate static struct node * 4930Sstevel@tonic-gate ename_compress(struct node *ename) 4940Sstevel@tonic-gate { 4950Sstevel@tonic-gate char *buf; 4960Sstevel@tonic-gate char *cp; 4970Sstevel@tonic-gate int len = 0; 4980Sstevel@tonic-gate struct node *np; 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate if (ename == NULL) 5010Sstevel@tonic-gate return (ename); 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate ASSERT(ename->t == T_NAME); 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate if (ename->u.name.next == NULL) 5060Sstevel@tonic-gate return (ename); /* no compression to be applied here */ 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate for (np = ename; np != NULL; np = np->u.name.next) { 5090Sstevel@tonic-gate ASSERT(np->t == T_NAME); 5100Sstevel@tonic-gate len++; /* room for '.' and final '\0' */ 5110Sstevel@tonic-gate len += strlen(np->u.name.s); 5120Sstevel@tonic-gate } 5130Sstevel@tonic-gate cp = buf = alloca(len); 5140Sstevel@tonic-gate for (np = ename; np != NULL; np = np->u.name.next) { 5150Sstevel@tonic-gate ASSERT(np->t == T_NAME); 5160Sstevel@tonic-gate if (np != ename) 5170Sstevel@tonic-gate *cp++ = '.'; 5180Sstevel@tonic-gate (void) strcpy(cp, np->u.name.s); 5190Sstevel@tonic-gate cp += strlen(cp); 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate ename->u.name.s = stable(buf); 5230Sstevel@tonic-gate tree_free(ename->u.name.next); 5240Sstevel@tonic-gate ename->u.name.next = NULL; 5250Sstevel@tonic-gate ename->u.name.last = ename; 5260Sstevel@tonic-gate return (ename); 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate struct node * 5300Sstevel@tonic-gate tree_event(struct node *ename, struct node *epname, struct node *eexprlist) 5310Sstevel@tonic-gate { 5320Sstevel@tonic-gate struct node *ret; 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate ASSERT(ename != NULL); 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate ret = newnode(T_EVENT, ename->file, ename->line); 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate ret->u.event.ename = ename_compress(ename); 5390Sstevel@tonic-gate ret->u.event.epname = epname; 5400Sstevel@tonic-gate ret->u.event.eexprlist = eexprlist; 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate check_event(ret); 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate return (ret); 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate struct node * 5480Sstevel@tonic-gate tree_name(const char *s, enum itertype it, const char *file, int line) 5490Sstevel@tonic-gate { 5500Sstevel@tonic-gate struct node *ret = newnode(T_NAME, file, line); 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate ASSERT(s != NULL); 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate stats_counter_bump(Namecount); 5550Sstevel@tonic-gate ret->u.name.t = N_UNSPEC; 5560Sstevel@tonic-gate ret->u.name.s = stable(s); 5570Sstevel@tonic-gate ret->u.name.it = it; 5580Sstevel@tonic-gate ret->u.name.last = ret; 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate if (it == IT_ENAME) { 5610Sstevel@tonic-gate /* PHASE2, possible optimization: convert to table driven */ 5620Sstevel@tonic-gate if (s == L_fault) 5630Sstevel@tonic-gate ret->u.name.t = N_FAULT; 5640Sstevel@tonic-gate else if (s == L_upset) 5650Sstevel@tonic-gate ret->u.name.t = N_UPSET; 5660Sstevel@tonic-gate else if (s == L_defect) 5670Sstevel@tonic-gate ret->u.name.t = N_DEFECT; 5680Sstevel@tonic-gate else if (s == L_error) 5690Sstevel@tonic-gate ret->u.name.t = N_ERROR; 5700Sstevel@tonic-gate else if (s == L_ereport) 5710Sstevel@tonic-gate ret->u.name.t = N_EREPORT; 5720Sstevel@tonic-gate else if (s == L_serd) 5730Sstevel@tonic-gate ret->u.name.t = N_SERD; 5741414Scindi else if (s == L_stat) 5751414Scindi ret->u.name.t = N_STAT; 5760Sstevel@tonic-gate else 5770Sstevel@tonic-gate outfl(O_ERR, file, line, "unknown class: %s", s); 5780Sstevel@tonic-gate } 5790Sstevel@tonic-gate return (ret); 5800Sstevel@tonic-gate } 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate struct node * 5830Sstevel@tonic-gate tree_iname(const char *s, const char *file, int line) 5840Sstevel@tonic-gate { 5850Sstevel@tonic-gate struct node *ret; 5860Sstevel@tonic-gate char *ss; 5870Sstevel@tonic-gate char *ptr; 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate ASSERT(s != NULL && *s != '\0'); 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate ss = STRDUP(s); 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate ptr = &ss[strlen(ss) - 1]; 5940Sstevel@tonic-gate if (!isdigit(*ptr)) { 5950Sstevel@tonic-gate outfl(O_ERR, file, line, 5960Sstevel@tonic-gate "instanced name expected (i.e. \"x0/y1\")"); 5970Sstevel@tonic-gate FREE(ss); 5980Sstevel@tonic-gate return (tree_name(s, IT_NONE, file, line)); 5990Sstevel@tonic-gate } 6000Sstevel@tonic-gate while (ptr > ss && isdigit(*(ptr - 1))) 6010Sstevel@tonic-gate ptr--; 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate ret = newnode(T_NAME, file, line); 6040Sstevel@tonic-gate stats_counter_bump(Namecount); 6050Sstevel@tonic-gate ret->u.name.child = tree_num(ptr, file, line); 6060Sstevel@tonic-gate *ptr = '\0'; 6070Sstevel@tonic-gate ret->u.name.t = N_UNSPEC; 6080Sstevel@tonic-gate ret->u.name.s = stable(ss); 6090Sstevel@tonic-gate ret->u.name.it = IT_NONE; 6100Sstevel@tonic-gate ret->u.name.last = ret; 6110Sstevel@tonic-gate FREE(ss); 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate return (ret); 6140Sstevel@tonic-gate } 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate struct node * 6170Sstevel@tonic-gate tree_globid(const char *s, const char *file, int line) 6180Sstevel@tonic-gate { 6190Sstevel@tonic-gate struct node *ret = newnode(T_GLOBID, file, line); 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate ASSERT(s != NULL); 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate ret->u.globid.s = stable(s); 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate return (ret); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate struct node * 6290Sstevel@tonic-gate tree_name_append(struct node *np1, struct node *np2) 6300Sstevel@tonic-gate { 6310Sstevel@tonic-gate ASSERT(np1 != NULL && np2 != NULL); 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate if (np1->t != T_NAME) 6340Sstevel@tonic-gate outfl(O_DIE, np1->file, np1->line, 6350Sstevel@tonic-gate "tree_name_append: internal error (np1 type %d)", np1->t); 6360Sstevel@tonic-gate if (np2->t != T_NAME) 6370Sstevel@tonic-gate outfl(O_DIE, np2->file, np2->line, 6380Sstevel@tonic-gate "tree_name_append: internal error (np2 type %d)", np2->t); 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate ASSERT(np1->u.name.last != NULL); 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate np1->u.name.last->u.name.next = np2; 6430Sstevel@tonic-gate np1->u.name.last = np2; 6440Sstevel@tonic-gate return (np1); 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate /* 6480Sstevel@tonic-gate * tree_name_repairdash -- repair a class name that contained a dash 6490Sstevel@tonic-gate * 6500Sstevel@tonic-gate * this routine is called by the parser when a dash is encountered 6510Sstevel@tonic-gate * in a class name. the event protocol allows the dashes but our 6520Sstevel@tonic-gate * lexer considers them a separate token (arithmetic minus). an extra 6530Sstevel@tonic-gate * rule in the parser catches this case and calls this routine to fixup 6540Sstevel@tonic-gate * the last component of the class name (so far) by constructing the 6550Sstevel@tonic-gate * new stable entry for a name including the dash. 6560Sstevel@tonic-gate */ 6570Sstevel@tonic-gate struct node * 6580Sstevel@tonic-gate tree_name_repairdash(struct node *np, const char *s) 6590Sstevel@tonic-gate { 6600Sstevel@tonic-gate int len; 6610Sstevel@tonic-gate char *buf; 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate ASSERT(np != NULL && s != NULL); 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate if (np->t != T_NAME) 6660Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 6670Sstevel@tonic-gate "tree_name_repairdash: internal error (np type %d)", 6680Sstevel@tonic-gate np->t); 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate ASSERT(np->u.name.last != NULL); 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1; 6730Sstevel@tonic-gate buf = MALLOC(len); 6740Sstevel@tonic-gate (void) snprintf(buf, len, "%s-%s", np->u.name.last->u.name.s, s); 6750Sstevel@tonic-gate np->u.name.last->u.name.s = stable(buf); 6760Sstevel@tonic-gate FREE(buf); 6770Sstevel@tonic-gate return (np); 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate struct node * 6812869Sgavinm tree_name_repairdash2(const char *s, struct node *np) 6822869Sgavinm { 6832869Sgavinm int len; 6842869Sgavinm char *buf; 6852869Sgavinm 6862869Sgavinm ASSERT(np != NULL && s != NULL); 6872869Sgavinm 6882869Sgavinm if (np->t != T_NAME) 6892869Sgavinm outfl(O_DIE, np->file, np->line, 6902869Sgavinm "tree_name_repairdash: internal error (np type %d)", 6912869Sgavinm np->t); 6922869Sgavinm 6932869Sgavinm ASSERT(np->u.name.last != NULL); 6942869Sgavinm 6952869Sgavinm len = strlen(np->u.name.last->u.name.s) + 1 + strlen(s) + 1; 6962869Sgavinm buf = MALLOC(len); 6972869Sgavinm (void) snprintf(buf, len, "%s-%s", s, np->u.name.last->u.name.s); 6982869Sgavinm np->u.name.last->u.name.s = stable(buf); 6992869Sgavinm FREE(buf); 7002869Sgavinm return (np); 7012869Sgavinm } 7022869Sgavinm 7032869Sgavinm struct node * 7040Sstevel@tonic-gate tree_name_iterator(struct node *np1, struct node *np2) 7050Sstevel@tonic-gate { 7060Sstevel@tonic-gate ASSERT(np1 != NULL); 7070Sstevel@tonic-gate ASSERT(np2 != NULL); 7080Sstevel@tonic-gate ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t)); 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate np1->u.name.child = np2; 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate check_name_iterator(np1); 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate return (np1); 7150Sstevel@tonic-gate } 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate struct node * 7180Sstevel@tonic-gate tree_timeval(const char *s, const char *suffix, const char *file, int line) 7190Sstevel@tonic-gate { 7200Sstevel@tonic-gate struct node *ret = newnode(T_TIMEVAL, file, line); 7210Sstevel@tonic-gate const unsigned long long *ullp; 7220Sstevel@tonic-gate 7230Sstevel@tonic-gate ASSERT(s != NULL); 7240Sstevel@tonic-gate ASSERT(suffix != NULL); 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate if ((ullp = lex_s2ullp_lut_lookup(Timesuffixlut, suffix)) == NULL) { 7270Sstevel@tonic-gate outfl(O_ERR, file, line, 7280Sstevel@tonic-gate "unrecognized number suffix: %s", suffix); 7290Sstevel@tonic-gate /* still construct a valid timeval node so parsing continues */ 7300Sstevel@tonic-gate ret->u.ull = 1; 7310Sstevel@tonic-gate } else { 7320Sstevel@tonic-gate ret->u.ull = (unsigned long long)strtoul(s, NULL, 0) * *ullp; 7330Sstevel@tonic-gate } 7340Sstevel@tonic-gate 7350Sstevel@tonic-gate return (ret); 7360Sstevel@tonic-gate } 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate struct node * 7390Sstevel@tonic-gate tree_num(const char *s, const char *file, int line) 7400Sstevel@tonic-gate { 7410Sstevel@tonic-gate struct node *ret = newnode(T_NUM, file, line); 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate ret->u.ull = (unsigned long long)strtoul(s, NULL, 0); 7440Sstevel@tonic-gate return (ret); 7450Sstevel@tonic-gate } 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate struct node * 7480Sstevel@tonic-gate tree_quote(const char *s, const char *file, int line) 7490Sstevel@tonic-gate { 7500Sstevel@tonic-gate struct node *ret = newnode(T_QUOTE, file, line); 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate ret->u.quote.s = stable(s); 7530Sstevel@tonic-gate return (ret); 7540Sstevel@tonic-gate } 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate struct node * 7570Sstevel@tonic-gate tree_func(const char *s, struct node *np, const char *file, int line) 7580Sstevel@tonic-gate { 7590Sstevel@tonic-gate struct node *ret = newnode(T_FUNC, file, line); 7604436Sstephh const char *ptr; 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate ret->u.func.s = s; 7630Sstevel@tonic-gate ret->u.func.arglist = np; 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate check_func(ret); 7660Sstevel@tonic-gate 7674436Sstephh /* 7684436Sstephh * keep track of the properties we're interested in so we can ignore the 7694436Sstephh * rest 7704436Sstephh */ 7714436Sstephh if (strcmp(s, L_confprop) == 0 || strcmp(s, L_confprop_defined) == 0) { 7724436Sstephh ptr = stable(np->u.expr.right->u.quote.s); 7734436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7744436Sstephh } else if (strcmp(s, L_is_connected) == 0) { 7754436Sstephh ptr = stable("connected"); 7764436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7774436Sstephh ptr = stable("CONNECTED"); 7784436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7794436Sstephh } else if (strcmp(s, L_is_type) == 0) { 7804436Sstephh ptr = stable("type"); 7814436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7824436Sstephh ptr = stable("TYPE"); 7834436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7844436Sstephh } else if (strcmp(s, L_is_on) == 0) { 7854436Sstephh ptr = stable("on"); 7864436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7874436Sstephh ptr = stable("ON"); 7884436Sstephh Usedprops = lut_add(Usedprops, (void *)ptr, (void *)ptr, NULL); 7894436Sstephh } 7904436Sstephh 7910Sstevel@tonic-gate return (ret); 7920Sstevel@tonic-gate } 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* 7950Sstevel@tonic-gate * given a list from a prop or mask statement or a function argument, 7960Sstevel@tonic-gate * convert all iterators to explicit iterators by inventing appropriate 7970Sstevel@tonic-gate * iterator names. 7980Sstevel@tonic-gate */ 7990Sstevel@tonic-gate static void 8001414Scindi make_explicit(struct node *np, int eventonly) 8010Sstevel@tonic-gate { 8020Sstevel@tonic-gate struct node *pnp; /* component of pathname */ 8030Sstevel@tonic-gate struct node *pnp2; 8040Sstevel@tonic-gate int count; 8050Sstevel@tonic-gate static size_t namesz; 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate if (Newname == NULL) { 8080Sstevel@tonic-gate namesz = 200; 8090Sstevel@tonic-gate Newname = MALLOC(namesz); 8100Sstevel@tonic-gate } 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate if (np == NULL) 8130Sstevel@tonic-gate return; /* all done */ 8140Sstevel@tonic-gate 8150Sstevel@tonic-gate switch (np->t) { 8161414Scindi case T_ASSIGN: 8171414Scindi case T_CONDIF: 8181414Scindi case T_CONDELSE: 8191414Scindi case T_NE: 8201414Scindi case T_EQ: 8211414Scindi case T_LT: 8221414Scindi case T_LE: 8231414Scindi case T_GT: 8241414Scindi case T_GE: 8251414Scindi case T_BITAND: 8261414Scindi case T_BITOR: 8271414Scindi case T_BITXOR: 8281414Scindi case T_BITNOT: 8291414Scindi case T_LSHIFT: 8301414Scindi case T_RSHIFT: 8310Sstevel@tonic-gate case T_LIST: 8321414Scindi case T_AND: 8331414Scindi case T_OR: 8341414Scindi case T_NOT: 8351414Scindi case T_ADD: 8361414Scindi case T_SUB: 8371414Scindi case T_MUL: 8381414Scindi case T_DIV: 8391414Scindi case T_MOD: 8401414Scindi make_explicit(np->u.expr.left, eventonly); 8411414Scindi make_explicit(np->u.expr.right, eventonly); 8420Sstevel@tonic-gate break; 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate case T_EVENT: 8451414Scindi make_explicit(np->u.event.epname, 0); 8461414Scindi make_explicit(np->u.event.eexprlist, 1); 8471414Scindi break; 8481414Scindi 8491414Scindi case T_FUNC: 8501414Scindi make_explicit(np->u.func.arglist, eventonly); 8510Sstevel@tonic-gate break; 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate case T_NAME: 8541414Scindi if (eventonly) 8551414Scindi return; 8560Sstevel@tonic-gate for (pnp = np; pnp != NULL; pnp = pnp->u.name.next) 8570Sstevel@tonic-gate if (pnp->u.name.child == NULL) { 8580Sstevel@tonic-gate /* 8590Sstevel@tonic-gate * found implicit iterator. convert 8600Sstevel@tonic-gate * it to an explicit iterator by 8610Sstevel@tonic-gate * using the name of the component 8620Sstevel@tonic-gate * appended with '#' and the number 8630Sstevel@tonic-gate * of times we've seen this same 8640Sstevel@tonic-gate * component name in this path so far. 8650Sstevel@tonic-gate */ 8660Sstevel@tonic-gate count = 0; 8670Sstevel@tonic-gate for (pnp2 = np; pnp2 != NULL; 8680Sstevel@tonic-gate pnp2 = pnp2->u.name.next) 8690Sstevel@tonic-gate if (pnp2 == pnp) 8700Sstevel@tonic-gate break; 8710Sstevel@tonic-gate else if (pnp2->u.name.s == 8720Sstevel@tonic-gate pnp->u.name.s) 8730Sstevel@tonic-gate count++; 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate if (namesz < strlen(pnp->u.name.s) + 8760Sstevel@tonic-gate 100) { 8770Sstevel@tonic-gate namesz = strlen(pnp->u.name.s) + 8780Sstevel@tonic-gate 100; 8790Sstevel@tonic-gate FREE(Newname); 8800Sstevel@tonic-gate Newname = MALLOC(namesz); 8810Sstevel@tonic-gate } 8820Sstevel@tonic-gate /* 8830Sstevel@tonic-gate * made up interator name is: 8840Sstevel@tonic-gate * name#ordinal 8850Sstevel@tonic-gate * or 8860Sstevel@tonic-gate * name##ordinal 8870Sstevel@tonic-gate * the first one is used for vertical 8880Sstevel@tonic-gate * expansion, the second for horizontal. 8890Sstevel@tonic-gate * either way, the '#' embedded in 8900Sstevel@tonic-gate * the name makes it impossible to 8910Sstevel@tonic-gate * collide with an actual iterator 8920Sstevel@tonic-gate * given to us in the eversholt file. 8930Sstevel@tonic-gate */ 8940Sstevel@tonic-gate (void) snprintf(Newname, namesz, 8950Sstevel@tonic-gate "%s#%s%d", pnp->u.name.s, 8960Sstevel@tonic-gate (pnp->u.name.it == IT_HORIZONTAL) ? 8970Sstevel@tonic-gate "#" : "", count); 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate pnp->u.name.child = tree_name(Newname, 9000Sstevel@tonic-gate IT_NONE, pnp->file, pnp->line); 9010Sstevel@tonic-gate pnp->u.name.childgen = 1; 9020Sstevel@tonic-gate } 9030Sstevel@tonic-gate break; 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate } 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate struct node * 9080Sstevel@tonic-gate tree_pname(struct node *np) 9090Sstevel@tonic-gate { 9101414Scindi make_explicit(np, 0); 9110Sstevel@tonic-gate return (np); 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate struct node * 9150Sstevel@tonic-gate tree_arrow(struct node *lhs, struct node *nnp, struct node *knp, 9160Sstevel@tonic-gate struct node *rhs) 9170Sstevel@tonic-gate { 9180Sstevel@tonic-gate struct node *ret; 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate ASSERT(lhs != NULL || rhs != NULL); 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate ret = newnode(T_ARROW, 9230Sstevel@tonic-gate (lhs) ? lhs->file : rhs->file, 9240Sstevel@tonic-gate (lhs) ? lhs->line : rhs->line); 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate ret->u.arrow.lhs = lhs; 9270Sstevel@tonic-gate ret->u.arrow.nnp = nnp; 9280Sstevel@tonic-gate ret->u.arrow.knp = knp; 9290Sstevel@tonic-gate ret->u.arrow.rhs = rhs; 9300Sstevel@tonic-gate 9311414Scindi make_explicit(lhs, 0); 9321414Scindi make_explicit(rhs, 0); 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate check_arrow(ret); 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate return (ret); 9370Sstevel@tonic-gate } 9380Sstevel@tonic-gate 9390Sstevel@tonic-gate static struct lut * 9400Sstevel@tonic-gate nvpair2lut(struct node *np, struct lut *lutp, enum nodetype t) 9410Sstevel@tonic-gate { 9420Sstevel@tonic-gate if (np) { 9430Sstevel@tonic-gate if (np->t == T_NVPAIR) { 9440Sstevel@tonic-gate ASSERTeq(np->u.expr.left->t, T_NAME, 9450Sstevel@tonic-gate ptree_nodetype2str); 9460Sstevel@tonic-gate check_stmt_allowed_properties(t, np, lutp); 9470Sstevel@tonic-gate lutp = tree_s2np_lut_add(lutp, 9480Sstevel@tonic-gate np->u.expr.left->u.name.s, np->u.expr.right); 9490Sstevel@tonic-gate } else if (np->t == T_LIST) { 9500Sstevel@tonic-gate lutp = nvpair2lut(np->u.expr.left, lutp, t); 9510Sstevel@tonic-gate lutp = nvpair2lut(np->u.expr.right, lutp, t); 9520Sstevel@tonic-gate } else 9530Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 9540Sstevel@tonic-gate "internal error: nvpair2lut type %s", 9550Sstevel@tonic-gate ptree_nodetype2str(np->t)); 9560Sstevel@tonic-gate } 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate return (lutp); 9590Sstevel@tonic-gate } 9600Sstevel@tonic-gate 9610Sstevel@tonic-gate struct lut * 9620Sstevel@tonic-gate tree_s2np_lut_add(struct lut *root, const char *s, struct node *np) 9630Sstevel@tonic-gate { 9640Sstevel@tonic-gate return (lut_add(root, (void *)s, (void *)np, NULL)); 9650Sstevel@tonic-gate } 9660Sstevel@tonic-gate 9670Sstevel@tonic-gate struct node * 9680Sstevel@tonic-gate tree_s2np_lut_lookup(struct lut *root, const char *s) 9690Sstevel@tonic-gate { 9700Sstevel@tonic-gate return (struct node *)lut_lookup(root, (void *)s, NULL); 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate struct lut * 9740Sstevel@tonic-gate tree_name2np_lut_add(struct lut *root, struct node *namep, struct node *np) 9750Sstevel@tonic-gate { 9760Sstevel@tonic-gate return (lut_add(root, (void *)namep, (void *)np, 9770Sstevel@tonic-gate (lut_cmp)tree_namecmp)); 9780Sstevel@tonic-gate } 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate struct node * 9810Sstevel@tonic-gate tree_name2np_lut_lookup(struct lut *root, struct node *namep) 9820Sstevel@tonic-gate { 9830Sstevel@tonic-gate return (struct node *) 9840Sstevel@tonic-gate lut_lookup(root, (void *)namep, (lut_cmp)tree_namecmp); 9850Sstevel@tonic-gate } 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate struct node * 9880Sstevel@tonic-gate tree_name2np_lut_lookup_name(struct lut *root, struct node *namep) 9890Sstevel@tonic-gate { 9900Sstevel@tonic-gate return (struct node *) 9910Sstevel@tonic-gate lut_lookup_lhs(root, (void *)namep, (lut_cmp)tree_namecmp); 9920Sstevel@tonic-gate } 9930Sstevel@tonic-gate 9940Sstevel@tonic-gate struct lut * 9950Sstevel@tonic-gate tree_event2np_lut_add(struct lut *root, struct node *enp, struct node *np) 9960Sstevel@tonic-gate { 9970Sstevel@tonic-gate return (lut_add(root, (void *)enp, (void *)np, (lut_cmp)tree_eventcmp)); 9980Sstevel@tonic-gate } 9990Sstevel@tonic-gate 10000Sstevel@tonic-gate struct node * 10010Sstevel@tonic-gate tree_event2np_lut_lookup(struct lut *root, struct node *enp) 10020Sstevel@tonic-gate { 10030Sstevel@tonic-gate return ((struct node *) 10040Sstevel@tonic-gate lut_lookup(root, (void *)enp, (lut_cmp)tree_eventcmp)); 10050Sstevel@tonic-gate } 10060Sstevel@tonic-gate 10070Sstevel@tonic-gate struct node * 10080Sstevel@tonic-gate tree_event2np_lut_lookup_event(struct lut *root, struct node *enp) 10090Sstevel@tonic-gate { 10100Sstevel@tonic-gate return ((struct node *) 10110Sstevel@tonic-gate lut_lookup_lhs(root, (void *)enp, (lut_cmp)tree_eventcmp)); 10120Sstevel@tonic-gate } 10130Sstevel@tonic-gate 10140Sstevel@tonic-gate static struct node * 10150Sstevel@tonic-gate dodecl(enum nodetype t, const char *file, int line, 10160Sstevel@tonic-gate struct node *np, struct node *nvpairs, struct lut **lutpp, 10170Sstevel@tonic-gate struct stats *countp, int justpath) 10180Sstevel@tonic-gate { 10190Sstevel@tonic-gate struct node *ret; 10200Sstevel@tonic-gate struct node *decl; 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate /* allocate parse tree node */ 10230Sstevel@tonic-gate ret = newnode(t, file, line); 10240Sstevel@tonic-gate ret->u.stmt.np = np; 10250Sstevel@tonic-gate ret->u.stmt.nvpairs = nvpairs; 10260Sstevel@tonic-gate 10270Sstevel@tonic-gate /* 10280Sstevel@tonic-gate * the global lut pointed to by lutpp (Faults, Defects, Upsets, 10290Sstevel@tonic-gate * Errors, Ereports, Serds, FRUs, or ASRUs) keeps the first decl. 10300Sstevel@tonic-gate * if this isn't the first declr, we merge the 10310Sstevel@tonic-gate * nvpairs into the first decl so we have a 10320Sstevel@tonic-gate * merged table to look up properties from. 10330Sstevel@tonic-gate * if this is the first time we've seen this fault, 10340Sstevel@tonic-gate * we add it to the global lut and start lutp 10350Sstevel@tonic-gate * off with any nvpairs from this declaration statement. 10360Sstevel@tonic-gate */ 10370Sstevel@tonic-gate if (justpath && (decl = tree_name2np_lut_lookup(*lutpp, np)) == NULL) { 10380Sstevel@tonic-gate /* this is the first time name is declared */ 10390Sstevel@tonic-gate stats_counter_bump(countp); 10400Sstevel@tonic-gate *lutpp = tree_name2np_lut_add(*lutpp, np, ret); 10410Sstevel@tonic-gate ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t); 10420Sstevel@tonic-gate } else if (!justpath && 10430Sstevel@tonic-gate (decl = tree_event2np_lut_lookup(*lutpp, np)) == NULL) { 10440Sstevel@tonic-gate /* this is the first time event is declared */ 10450Sstevel@tonic-gate stats_counter_bump(countp); 10460Sstevel@tonic-gate *lutpp = tree_event2np_lut_add(*lutpp, np, ret); 10470Sstevel@tonic-gate ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, t); 10480Sstevel@tonic-gate } else { 10490Sstevel@tonic-gate /* was declared before, just add new nvpairs to its lutp */ 10500Sstevel@tonic-gate decl->u.stmt.lutp = nvpair2lut(nvpairs, decl->u.stmt.lutp, t); 10510Sstevel@tonic-gate } 10520Sstevel@tonic-gate 10530Sstevel@tonic-gate return (ret); 10540Sstevel@tonic-gate } 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate /*ARGSUSED*/ 10570Sstevel@tonic-gate static void 10580Sstevel@tonic-gate update_serd_refstmt(void *lhs, void *rhs, void *arg) 10590Sstevel@tonic-gate { 10600Sstevel@tonic-gate struct node *serd; 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate ASSERT(rhs != NULL); 10630Sstevel@tonic-gate 10640Sstevel@tonic-gate serd = tree_s2np_lut_lookup(((struct node *)rhs)->u.stmt.lutp, 10654436Sstephh L_engine); 10660Sstevel@tonic-gate if (serd == NULL) 10670Sstevel@tonic-gate return; 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate ASSERT(serd->t == T_EVENT); 10700Sstevel@tonic-gate if (arg != NULL && tree_eventcmp(serd, (struct node *)arg) != 0) 10710Sstevel@tonic-gate return; 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate serd = tree_event2np_lut_lookup(SERDs, serd); 10740Sstevel@tonic-gate if (serd != NULL) 10750Sstevel@tonic-gate serd->u.stmt.flags |= STMT_REF; 10760Sstevel@tonic-gate } 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate struct node * 10790Sstevel@tonic-gate tree_decl(enum nodetype t, struct node *np, struct node *nvpairs, 10800Sstevel@tonic-gate const char *file, int line) 10810Sstevel@tonic-gate { 10820Sstevel@tonic-gate struct node *decl; 10830Sstevel@tonic-gate struct node *ret; 10840Sstevel@tonic-gate 10850Sstevel@tonic-gate ASSERT(np != NULL); 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate check_type_iterator(np); 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate switch (t) { 10900Sstevel@tonic-gate case T_EVENT: 10910Sstevel@tonic-gate /* determine the type of event being declared */ 10920Sstevel@tonic-gate ASSERT(np->u.event.ename->t == T_NAME); 10930Sstevel@tonic-gate switch (np->u.event.ename->u.name.t) { 10940Sstevel@tonic-gate case N_FAULT: 10950Sstevel@tonic-gate ret = dodecl(T_FAULT, file, line, np, nvpairs, 10960Sstevel@tonic-gate &Faults, Faultcount, 0); 10970Sstevel@tonic-gate break; 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate case N_UPSET: 11000Sstevel@tonic-gate ret = dodecl(T_UPSET, file, line, np, nvpairs, 11010Sstevel@tonic-gate &Upsets, Upsetcount, 0); 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate /* increment serd statement reference */ 11040Sstevel@tonic-gate decl = tree_event2np_lut_lookup(Upsets, np); 11050Sstevel@tonic-gate update_serd_refstmt(NULL, decl, NULL); 11060Sstevel@tonic-gate break; 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate case N_DEFECT: 11090Sstevel@tonic-gate ret = dodecl(T_DEFECT, file, line, np, nvpairs, 11100Sstevel@tonic-gate &Defects, Defectcount, 0); 11110Sstevel@tonic-gate break; 11120Sstevel@tonic-gate 11130Sstevel@tonic-gate case N_ERROR: 11140Sstevel@tonic-gate ret = dodecl(T_ERROR, file, line, np, nvpairs, 11150Sstevel@tonic-gate &Errors, Errorcount, 0); 11160Sstevel@tonic-gate break; 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate case N_EREPORT: 11190Sstevel@tonic-gate ret = dodecl(T_EREPORT, file, line, np, nvpairs, 11200Sstevel@tonic-gate &Ereports, Ereportcount, 0); 11210Sstevel@tonic-gate /* 11220Sstevel@tonic-gate * keep a lut of just the enames, so that the DE 11230Sstevel@tonic-gate * can subscribe to a uniqified list of event 11240Sstevel@tonic-gate * classes. 11250Sstevel@tonic-gate */ 11260Sstevel@tonic-gate Ereportenames = 11270Sstevel@tonic-gate tree_name2np_lut_add(Ereportenames, 11280Sstevel@tonic-gate np->u.event.ename, np); 11290Sstevel@tonic-gate break; 11300Sstevel@tonic-gate 11310Sstevel@tonic-gate default: 11320Sstevel@tonic-gate outfl(O_ERR, file, line, 11330Sstevel@tonic-gate "tree_decl: internal error, event name type %s", 11340Sstevel@tonic-gate ptree_nametype2str(np->u.event.ename->u.name.t)); 11350Sstevel@tonic-gate } 11360Sstevel@tonic-gate break; 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate case T_ENGINE: 11390Sstevel@tonic-gate /* determine the type of engine being declared */ 11400Sstevel@tonic-gate ASSERT(np->u.event.ename->t == T_NAME); 11410Sstevel@tonic-gate switch (np->u.event.ename->u.name.t) { 11420Sstevel@tonic-gate case N_SERD: 11430Sstevel@tonic-gate ret = dodecl(T_SERD, file, line, np, nvpairs, 11440Sstevel@tonic-gate &SERDs, SERDcount, 0); 11450Sstevel@tonic-gate lut_walk(Upsets, update_serd_refstmt, np); 11460Sstevel@tonic-gate break; 11470Sstevel@tonic-gate 11481414Scindi case N_STAT: 11491414Scindi ret = dodecl(T_STAT, file, line, np, nvpairs, 11501414Scindi &STATs, STATcount, 0); 11511414Scindi break; 11521414Scindi 11530Sstevel@tonic-gate default: 11540Sstevel@tonic-gate outfl(O_ERR, file, line, 11550Sstevel@tonic-gate "tree_decl: internal error, engine name type %s", 11560Sstevel@tonic-gate ptree_nametype2str(np->u.event.ename->u.name.t)); 11570Sstevel@tonic-gate } 11580Sstevel@tonic-gate break; 11590Sstevel@tonic-gate case T_ASRU: 11600Sstevel@tonic-gate ret = dodecl(T_ASRU, file, line, np, nvpairs, 11610Sstevel@tonic-gate &ASRUs, ASRUcount, 1); 11620Sstevel@tonic-gate break; 11630Sstevel@tonic-gate 11640Sstevel@tonic-gate case T_FRU: 11650Sstevel@tonic-gate ret = dodecl(T_FRU, file, line, np, nvpairs, 11660Sstevel@tonic-gate &FRUs, FRUcount, 1); 11670Sstevel@tonic-gate break; 11680Sstevel@tonic-gate 11690Sstevel@tonic-gate case T_CONFIG: 11700Sstevel@tonic-gate /* 11710Sstevel@tonic-gate * config statements are different from above: they 11720Sstevel@tonic-gate * are not merged at all (until the configuration cache 11730Sstevel@tonic-gate * code does its own style of merging. and the properties 11740Sstevel@tonic-gate * are a free-for-all -- we don't check for allowed or 11750Sstevel@tonic-gate * required config properties. 11760Sstevel@tonic-gate */ 11770Sstevel@tonic-gate ret = newnode(T_CONFIG, file, line); 11780Sstevel@tonic-gate ret->u.stmt.np = np; 11790Sstevel@tonic-gate ret->u.stmt.nvpairs = nvpairs; 11800Sstevel@tonic-gate ret->u.stmt.lutp = nvpair2lut(nvpairs, NULL, T_CONFIG); 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate if (lut_lookup(Configs, np, (lut_cmp)tree_namecmp) == NULL) 11830Sstevel@tonic-gate stats_counter_bump(Configcount); 11840Sstevel@tonic-gate 11850Sstevel@tonic-gate Configs = lut_add(Configs, (void *)np, (void *)ret, NULL); 11860Sstevel@tonic-gate break; 11870Sstevel@tonic-gate 11880Sstevel@tonic-gate default: 11890Sstevel@tonic-gate out(O_DIE, "tree_decl: internal error, type %s", 11900Sstevel@tonic-gate ptree_nodetype2str(t)); 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate return (ret); 11940Sstevel@tonic-gate } 11950Sstevel@tonic-gate 11960Sstevel@tonic-gate /* keep backpointers in arrows to the prop they belong to (used for scoping) */ 11970Sstevel@tonic-gate static void 11980Sstevel@tonic-gate set_arrow_prop(struct node *prop, struct node *np) 11990Sstevel@tonic-gate { 12000Sstevel@tonic-gate if (np == NULL) 12010Sstevel@tonic-gate return; 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate if (np->t == T_ARROW) { 12040Sstevel@tonic-gate np->u.arrow.prop = prop; 12050Sstevel@tonic-gate set_arrow_prop(prop, np->u.arrow.lhs); 12060Sstevel@tonic-gate /* 12070Sstevel@tonic-gate * no need to recurse right or handle T_LIST since 12080Sstevel@tonic-gate * T_ARROWs always cascade left and are at the top 12090Sstevel@tonic-gate * of the parse tree. (you can see this in the rule 12100Sstevel@tonic-gate * for "propbody" in escparse.y.) 12110Sstevel@tonic-gate */ 12120Sstevel@tonic-gate } 12130Sstevel@tonic-gate } 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate struct node * 12160Sstevel@tonic-gate tree_stmt(enum nodetype t, struct node *np, const char *file, int line) 12170Sstevel@tonic-gate { 12180Sstevel@tonic-gate struct node *ret = newnode(t, file, line); 12190Sstevel@tonic-gate struct node *pp; 12200Sstevel@tonic-gate int inlist = 0; 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate ret->u.stmt.np = np; 12230Sstevel@tonic-gate 12240Sstevel@tonic-gate switch (t) { 12250Sstevel@tonic-gate case T_PROP: 1226854Srw145199 check_proplists(t, np); 12270Sstevel@tonic-gate check_propnames(t, np, 0, 0); 12280Sstevel@tonic-gate check_propscope(np); 12290Sstevel@tonic-gate set_arrow_prop(ret, np); 12300Sstevel@tonic-gate 12310Sstevel@tonic-gate for (pp = Props; pp; pp = pp->u.stmt.next) { 12320Sstevel@tonic-gate if (tree_treecmp(pp, ret, T_NAME, 12334436Sstephh (lut_cmp)tree_namecmp) == 0) { 12340Sstevel@tonic-gate inlist = 1; 12350Sstevel@tonic-gate break; 12360Sstevel@tonic-gate } 12370Sstevel@tonic-gate } 12380Sstevel@tonic-gate if (inlist == 0) 12390Sstevel@tonic-gate stats_counter_bump(Propcount); 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate /* "Props" is a linked list of all prop statements */ 12420Sstevel@tonic-gate if (Lastprops) 12430Sstevel@tonic-gate Lastprops->u.stmt.next = ret; 12440Sstevel@tonic-gate else 12450Sstevel@tonic-gate Props = ret; 12460Sstevel@tonic-gate Lastprops = ret; 12470Sstevel@tonic-gate break; 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate case T_MASK: 1250854Srw145199 check_proplists(t, np); 12510Sstevel@tonic-gate check_propnames(t, np, 0, 0); 12520Sstevel@tonic-gate check_propscope(np); 12530Sstevel@tonic-gate set_arrow_prop(ret, np); 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate for (pp = Masks; pp; pp = pp->u.stmt.next) { 12560Sstevel@tonic-gate if (tree_treecmp(pp, ret, T_NAME, 12574436Sstephh (lut_cmp)tree_namecmp) == 0) { 12580Sstevel@tonic-gate inlist = 1; 12590Sstevel@tonic-gate break; 12600Sstevel@tonic-gate } 12610Sstevel@tonic-gate } 12620Sstevel@tonic-gate if (inlist == 0) 12630Sstevel@tonic-gate stats_counter_bump(Maskcount); 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate /* "Masks" is a linked list of all mask statements */ 12660Sstevel@tonic-gate if (Lastmasks) 12670Sstevel@tonic-gate Lastmasks->u.stmt.next = ret; 12680Sstevel@tonic-gate else 12690Sstevel@tonic-gate Masks = ret; 12700Sstevel@tonic-gate Lastmasks = ret; 12710Sstevel@tonic-gate stats_counter_bump(Maskcount); 12720Sstevel@tonic-gate break; 12730Sstevel@tonic-gate 12740Sstevel@tonic-gate default: 12750Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 12760Sstevel@tonic-gate "tree_stmt: internal error (t %d)", t); 12770Sstevel@tonic-gate } 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate return (ret); 12800Sstevel@tonic-gate } 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate void 12830Sstevel@tonic-gate tree_report() 12840Sstevel@tonic-gate { 12850Sstevel@tonic-gate /* 12860Sstevel@tonic-gate * The only declarations with required properties 12870Sstevel@tonic-gate * currently are faults and serds. Make sure the 12880Sstevel@tonic-gate * the declarations have the required properties. 12890Sstevel@tonic-gate */ 12900Sstevel@tonic-gate lut_walk(Faults, (lut_cb)check_required_props, (void *)T_FAULT); 12910Sstevel@tonic-gate lut_walk(Upsets, (lut_cb)check_required_props, (void *)T_UPSET); 12920Sstevel@tonic-gate lut_walk(Errors, (lut_cb)check_required_props, (void *)T_ERROR); 12930Sstevel@tonic-gate lut_walk(Ereports, (lut_cb)check_required_props, (void *)T_EREPORT); 12940Sstevel@tonic-gate lut_walk(SERDs, (lut_cb)check_required_props, (void *)T_SERD); 12951414Scindi lut_walk(STATs, (lut_cb)check_required_props, (void *)T_STAT); 12960Sstevel@tonic-gate 12970Sstevel@tonic-gate /* 12980Sstevel@tonic-gate * we do this now rather than while building the parse 12990Sstevel@tonic-gate * tree because it is inconvenient for the user if we 13000Sstevel@tonic-gate * require SERD engines to be declared before used in 13010Sstevel@tonic-gate * an upset "engine" property. 13020Sstevel@tonic-gate */ 13030Sstevel@tonic-gate lut_walk(Faults, (lut_cb)check_refcount, (void *)T_FAULT); 13040Sstevel@tonic-gate lut_walk(Upsets, (lut_cb)check_upset_engine, (void *)T_UPSET); 13050Sstevel@tonic-gate lut_walk(Upsets, (lut_cb)check_refcount, (void *)T_UPSET); 13060Sstevel@tonic-gate lut_walk(Errors, (lut_cb)check_refcount, (void *)T_ERROR); 13070Sstevel@tonic-gate lut_walk(Ereports, (lut_cb)check_refcount, (void *)T_EREPORT); 13080Sstevel@tonic-gate lut_walk(SERDs, (lut_cb)check_refcount, (void *)T_SERD); 13090Sstevel@tonic-gate 13100Sstevel@tonic-gate /* check for cycles */ 13110Sstevel@tonic-gate lut_walk(Errors, (lut_cb)check_cycle, (void *)0); 13120Sstevel@tonic-gate } 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate /* compare two T_NAMES by only looking at components, not iterators */ 13150Sstevel@tonic-gate int 13160Sstevel@tonic-gate tree_namecmp(struct node *np1, struct node *np2) 13170Sstevel@tonic-gate { 13180Sstevel@tonic-gate ASSERT(np1 != NULL); 13190Sstevel@tonic-gate ASSERT(np2 != NULL); 13200Sstevel@tonic-gate ASSERTinfo(np1->t == T_NAME, ptree_nodetype2str(np1->t)); 13210Sstevel@tonic-gate ASSERTinfo(np2->t == T_NAME, ptree_nodetype2str(np1->t)); 13220Sstevel@tonic-gate 13230Sstevel@tonic-gate while (np1 && np2 && np1->u.name.s == np2->u.name.s) { 13240Sstevel@tonic-gate np1 = np1->u.name.next; 13250Sstevel@tonic-gate np2 = np2->u.name.next; 13260Sstevel@tonic-gate } 13270Sstevel@tonic-gate if (np1 == NULL) 13280Sstevel@tonic-gate if (np2 == NULL) 13290Sstevel@tonic-gate return (0); 13300Sstevel@tonic-gate else 13310Sstevel@tonic-gate return (-1); 13320Sstevel@tonic-gate else if (np2 == NULL) 13330Sstevel@tonic-gate return (1); 13340Sstevel@tonic-gate else 13350Sstevel@tonic-gate return (np2->u.name.s - np1->u.name.s); 13360Sstevel@tonic-gate } 13370Sstevel@tonic-gate 13380Sstevel@tonic-gate int 13390Sstevel@tonic-gate tree_eventcmp(struct node *np1, struct node *np2) 13400Sstevel@tonic-gate { 13410Sstevel@tonic-gate int ret; 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate ASSERT(np1 != NULL); 13440Sstevel@tonic-gate ASSERT(np2 != NULL); 13450Sstevel@tonic-gate ASSERTinfo(np1->t == T_EVENT, ptree_nodetype2str(np1->t)); 13460Sstevel@tonic-gate ASSERTinfo(np2->t == T_EVENT, ptree_nodetype2str(np2->t)); 13470Sstevel@tonic-gate 13480Sstevel@tonic-gate if ((ret = tree_namecmp(np1->u.event.ename, 13494436Sstephh np2->u.event.ename)) == 0) { 13500Sstevel@tonic-gate if (np1->u.event.epname == NULL && 13514436Sstephh np2->u.event.epname == NULL) 13520Sstevel@tonic-gate return (0); 13530Sstevel@tonic-gate else if (np1->u.event.epname == NULL) 13540Sstevel@tonic-gate return (-1); 13550Sstevel@tonic-gate else if (np2->u.event.epname == NULL) 13560Sstevel@tonic-gate return (1); 13570Sstevel@tonic-gate else 13580Sstevel@tonic-gate return tree_namecmp(np1->u.event.epname, 13594436Sstephh np2->u.event.epname); 13600Sstevel@tonic-gate } else 13610Sstevel@tonic-gate return (ret); 13620Sstevel@tonic-gate } 1363