xref: /onnv-gate/usr/src/cmd/fm/eversholt/common/tree.h (revision 2869:324151eecd58)
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
5*2869Sgavinm  * Common Development and Distribution License (the "License").
6*2869Sgavinm  * 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 /*
221414Scindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  *
250Sstevel@tonic-gate  * tree.h -- public definitions for tree module
260Sstevel@tonic-gate  *
270Sstevel@tonic-gate  * the parse tree is made up of struct node's.  the struct is
280Sstevel@tonic-gate  * a "variant record" with a type, the filename and line number
290Sstevel@tonic-gate  * related to the node, and then type-specific node data.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifndef	_ESC_COMMON_TREE_H
330Sstevel@tonic-gate #define	_ESC_COMMON_TREE_H
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #ifdef	__cplusplus
380Sstevel@tonic-gate extern "C" {
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
410Sstevel@tonic-gate struct node {
420Sstevel@tonic-gate 	enum nodetype {
430Sstevel@tonic-gate 		T_NOTHING = 1000,	/* used to keep going on error cases */
440Sstevel@tonic-gate 		T_NAME,			/* identifiers, sometimes chained */
450Sstevel@tonic-gate 		T_GLOBID,		/* globals (e.g. $a) */
460Sstevel@tonic-gate 		T_EVENT,		/* class@path{expr} */
470Sstevel@tonic-gate 		T_ENGINE,		/* upset threshold engine (e.g. SERD) */
480Sstevel@tonic-gate 		T_ASRU,			/* ASRU declaration */
490Sstevel@tonic-gate 		T_FRU,			/* FRU declaration */
500Sstevel@tonic-gate 		T_TIMEVAL,		/* num w/time suffix (ns internally) */
510Sstevel@tonic-gate 		T_NUM,			/* num (ull internally) */
520Sstevel@tonic-gate 		T_QUOTE,		/* quoted string */
530Sstevel@tonic-gate 		T_FUNC,			/* func(arglist) */
540Sstevel@tonic-gate 		T_NVPAIR,		/* name=value pair in decl */
550Sstevel@tonic-gate 		T_ASSIGN,		/* assignment statement */
560Sstevel@tonic-gate 		T_CONDIF,		/* a and T_CONDELSE in (a ? b : c ) */
570Sstevel@tonic-gate 		T_CONDELSE,		/* lists b and c in (a ? b : c ) */
580Sstevel@tonic-gate 		T_NOT,			/* boolean ! operator */
590Sstevel@tonic-gate 		T_AND,			/* boolean && operator */
600Sstevel@tonic-gate 		T_OR,			/* boolean || operator */
610Sstevel@tonic-gate 		T_EQ,			/* boolean == operator */
620Sstevel@tonic-gate 		T_NE,			/* boolean != operator */
630Sstevel@tonic-gate 		T_SUB,			/* integer - operator */
640Sstevel@tonic-gate 		T_ADD,			/* integer + operator */
650Sstevel@tonic-gate 		T_MUL,			/* integer * operator */
660Sstevel@tonic-gate 		T_DIV,			/* integer / operator */
670Sstevel@tonic-gate 		T_MOD,			/* integer % operator */
680Sstevel@tonic-gate 		T_LT,			/* boolean < operator */
690Sstevel@tonic-gate 		T_LE,			/* boolean <= operator */
700Sstevel@tonic-gate 		T_GT,			/* boolean > operator */
710Sstevel@tonic-gate 		T_GE,			/* boolean >= operator */
720Sstevel@tonic-gate 		T_BITAND,		/* bitwise & operator */
730Sstevel@tonic-gate 		T_BITOR,		/* bitwise | operator */
740Sstevel@tonic-gate 		T_BITXOR,		/* bitwise ^ operator */
750Sstevel@tonic-gate 		T_BITNOT,		/* bitwise ~ operator */
760Sstevel@tonic-gate 		T_LSHIFT,		/* bitwise << operator */
770Sstevel@tonic-gate 		T_RSHIFT,		/* bitwise >> operator */
780Sstevel@tonic-gate 		T_ARROW,		/* lhs (N)->(K) rhs */
790Sstevel@tonic-gate 		T_LIST,			/* comma-separated list */
800Sstevel@tonic-gate 		T_FAULT,		/* fault declaration */
810Sstevel@tonic-gate 		T_UPSET,		/* upset declaration */
820Sstevel@tonic-gate 		T_DEFECT,		/* defect declaration */
830Sstevel@tonic-gate 		T_ERROR,		/* error declaration */
840Sstevel@tonic-gate 		T_EREPORT,		/* ereport declaration */
850Sstevel@tonic-gate 		T_SERD,			/* SERD engine declaration */
861414Scindi 		T_STAT,			/* STAT engine declaration */
870Sstevel@tonic-gate 		T_PROP,			/* prop statement */
880Sstevel@tonic-gate 		T_MASK,			/* mask statement */
890Sstevel@tonic-gate 		T_CONFIG		/* config statement */
900Sstevel@tonic-gate 	} t;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	/*
930Sstevel@tonic-gate 	 * regardless of the type of node, filename and line number
940Sstevel@tonic-gate 	 * information from the original .esc file is tracked here.
950Sstevel@tonic-gate 	 */
960Sstevel@tonic-gate 	const char *file;
970Sstevel@tonic-gate 	int line;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	/*
1000Sstevel@tonic-gate 	 * the variant part of a struct node...
1010Sstevel@tonic-gate 	 */
1020Sstevel@tonic-gate 	union {
1030Sstevel@tonic-gate 		struct {
1040Sstevel@tonic-gate 			/*
1050Sstevel@tonic-gate 			 * info kept for T_NAME, used in several ways:
1060Sstevel@tonic-gate 			 *
1070Sstevel@tonic-gate 			 *	1 for simple variable names.
1080Sstevel@tonic-gate 			 *		example: j
1090Sstevel@tonic-gate 			 *
1100Sstevel@tonic-gate 			 *	2 for event class names, with component
1110Sstevel@tonic-gate 			 *	  names chained together via the "next"
1120Sstevel@tonic-gate 			 *	  pointers.
1130Sstevel@tonic-gate 			 *		example: fault.fan.broken
1140Sstevel@tonic-gate 			 *
1150Sstevel@tonic-gate 			 *	3 for component pathnames, with component
1160Sstevel@tonic-gate 			 *	  names chained together via the "next"
1170Sstevel@tonic-gate 			 *	  pointers and iterators or instance numbers
1180Sstevel@tonic-gate 			 *	  attached via the "child" pointers.
1190Sstevel@tonic-gate 			 *		example: sysboard[0]/cpu[n]
1200Sstevel@tonic-gate 			 *
1210Sstevel@tonic-gate 			 * case 3 is the most interesting.
1220Sstevel@tonic-gate 			 *	- if child is set, there's an iterator
1230Sstevel@tonic-gate 			 *	- if child is a T_NAME, it is x[j] or x<j> and
1240Sstevel@tonic-gate 			 *	  iterator type tells you vertical or horizontal
1250Sstevel@tonic-gate 			 *	- if child is a T_NUM, it is x[0] or x<0> or
1260Sstevel@tonic-gate 			 *	  x0 and iterator type tells you which one
1270Sstevel@tonic-gate 			 *	- if cp pointer is set, then we recently
1280Sstevel@tonic-gate 			 *	  matched it to a config cache entry and one
1290Sstevel@tonic-gate 			 *	  can ignore child for now because it still
1300Sstevel@tonic-gate 			 *	  represents the *pattern* you're matching.
1310Sstevel@tonic-gate 			 *	  cp represents what you matched.  ptree()
1320Sstevel@tonic-gate 			 *	  knows that if cp is set, to print that number
1330Sstevel@tonic-gate 			 *	  instead of following child.
1340Sstevel@tonic-gate 			 *
1350Sstevel@tonic-gate 			 * when T_NAME nodes are chained:
1360Sstevel@tonic-gate 			 * the "last" pointer takes you to the end of the
1370Sstevel@tonic-gate 			 * chain, but only the first component's last pointer
1380Sstevel@tonic-gate 			 * is kept up to date.  it is used to determine
1390Sstevel@tonic-gate 			 * where to append newly-created T_NAME nodes (see
1400Sstevel@tonic-gate 			 * tree_name_append()).
1410Sstevel@tonic-gate 			 */
1420Sstevel@tonic-gate 			const char *s;		/* the name itself */
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 			struct node *child;
1450Sstevel@tonic-gate 			struct node *next;
1460Sstevel@tonic-gate 			struct node *last;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 			/* opaque pointer used during config matching */
1490Sstevel@tonic-gate 			struct config *cp;
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 			enum nametype {
1520Sstevel@tonic-gate 				N_UNSPEC,
1530Sstevel@tonic-gate 				N_FAULT,
1540Sstevel@tonic-gate 				N_UPSET,
1550Sstevel@tonic-gate 				N_DEFECT,
1560Sstevel@tonic-gate 				N_ERROR,
1570Sstevel@tonic-gate 				N_EREPORT,
1581414Scindi 				N_SERD,
1591414Scindi 				N_STAT
1600Sstevel@tonic-gate 			} t:3;
1610Sstevel@tonic-gate 			enum itertype {
1620Sstevel@tonic-gate 				IT_NONE,
1630Sstevel@tonic-gate 				IT_VERTICAL,
1640Sstevel@tonic-gate 				IT_HORIZONTAL,
1650Sstevel@tonic-gate 				IT_ENAME
1660Sstevel@tonic-gate 			} it:2;
1670Sstevel@tonic-gate 			unsigned childgen:1;	/* child was auto-generated */
1680Sstevel@tonic-gate 		} name;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 		struct {
1710Sstevel@tonic-gate 			/*
1720Sstevel@tonic-gate 			 * info kept for T_GLOBID
1730Sstevel@tonic-gate 			 */
1740Sstevel@tonic-gate 			const char *s;		/* the name itself */
1750Sstevel@tonic-gate 		} globid;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 		/*
1780Sstevel@tonic-gate 		 * info kept for T_TIMEVAL and T_NUM
1790Sstevel@tonic-gate 		 *
1800Sstevel@tonic-gate 		 * timevals are kept in nanoseconds.
1810Sstevel@tonic-gate 		 */
1820Sstevel@tonic-gate 		unsigned long long ull;
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 		struct {
1850Sstevel@tonic-gate 			/*
1860Sstevel@tonic-gate 			 * info kept for T_QUOTE
1870Sstevel@tonic-gate 			 */
1880Sstevel@tonic-gate 			const char *s;		/* the quoted string */
1890Sstevel@tonic-gate 		} quote;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 		struct {
1920Sstevel@tonic-gate 			/*
1930Sstevel@tonic-gate 			 * info kept for T_FUNC
1940Sstevel@tonic-gate 			 */
1950Sstevel@tonic-gate 			const char *s;		/* name of function */
1960Sstevel@tonic-gate 			struct node *arglist;
1970Sstevel@tonic-gate 		} func;
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 		struct {
2000Sstevel@tonic-gate 			/*
2010Sstevel@tonic-gate 			 * info kept for T_PROP and T_MASK statements
2020Sstevel@tonic-gate 			 * as well as declarations for:
2030Sstevel@tonic-gate 			 *	T_FAULT
2040Sstevel@tonic-gate 			 *	T_UPSET
2050Sstevel@tonic-gate 			 *	T_DEFECT
2060Sstevel@tonic-gate 			 *	T_ERROR
2070Sstevel@tonic-gate 			 *	T_EREPORT
2080Sstevel@tonic-gate 			 *	T_ASRU
2090Sstevel@tonic-gate 			 *	T_FRU
2100Sstevel@tonic-gate 			 *	T_CONFIG
2110Sstevel@tonic-gate 			 */
2120Sstevel@tonic-gate 			struct node *np;
2130Sstevel@tonic-gate 			struct node *nvpairs;	/* for declarations */
2140Sstevel@tonic-gate 			struct lut *lutp;	/* for declarations */
2150Sstevel@tonic-gate 			struct node *next;	/* for Props & Masks lists */
2160Sstevel@tonic-gate 			struct node *expr;	/* for if statements */
2170Sstevel@tonic-gate 			unsigned char flags;	/* see STMT_ flags below */
2180Sstevel@tonic-gate 		} stmt;			/* used for stmt */
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 		struct {
2210Sstevel@tonic-gate 			/*
2220Sstevel@tonic-gate 			 * info kept for T_EVENT
2230Sstevel@tonic-gate 			 */
2240Sstevel@tonic-gate 			struct node *ename;	/* event class name */
2250Sstevel@tonic-gate 			struct node *epname;	/* component path name */
2260Sstevel@tonic-gate 			struct node *eexprlist;	/* constraint expression */
2270Sstevel@tonic-gate 			struct node *declp;	/* event declaration */
2280Sstevel@tonic-gate 		} event;
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 		struct {
2310Sstevel@tonic-gate 			/*
2320Sstevel@tonic-gate 			 * info kept for T_ARROW
2330Sstevel@tonic-gate 			 */
2340Sstevel@tonic-gate 			struct node *lhs;	/* left side of arrow */
2350Sstevel@tonic-gate 			struct node *rhs;	/* right side of arrow */
2360Sstevel@tonic-gate 			struct node *nnp;	/* N value */
2370Sstevel@tonic-gate 			struct node *knp;	/* K value */
2380Sstevel@tonic-gate 			struct node *prop;	/* arrow is part of this prop */
2390Sstevel@tonic-gate 		} arrow;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 		struct {
2420Sstevel@tonic-gate 			/*
2430Sstevel@tonic-gate 			 * info kept for everything else (T_ADD, T_LIST, etc.)
2440Sstevel@tonic-gate 			 */
2450Sstevel@tonic-gate 			struct node *left;
2460Sstevel@tonic-gate 			struct node *right;
2470Sstevel@tonic-gate 		} expr;
2480Sstevel@tonic-gate 	} u;
2490Sstevel@tonic-gate };
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate /* flags we keep with stmts */
2520Sstevel@tonic-gate #define	STMT_REF	0x01	/* declared item is referenced */
2530Sstevel@tonic-gate #define	STMT_CYMARK	0x02	/* declared item is marked for cycle check */
2540Sstevel@tonic-gate #define	STMT_CYCLE	0x04	/* cycle detected and already reported */
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate #define	TIMEVAL_EVENTUALLY (1000000000ULL*60*60*24*365*100)	/* 100 years */
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate void tree_init(void);
2590Sstevel@tonic-gate void tree_fini(void);
2600Sstevel@tonic-gate struct node *newnode(enum nodetype t, const char *file, int line);
2610Sstevel@tonic-gate void tree_free(struct node *root);
2620Sstevel@tonic-gate struct node *tree_root(struct node *np);
2630Sstevel@tonic-gate struct node *tree_nothing(void);
2640Sstevel@tonic-gate struct node *tree_expr(enum nodetype t, struct node *left, struct node *right);
2650Sstevel@tonic-gate struct node *tree_event(struct node *ename, struct node *epname,
2660Sstevel@tonic-gate     struct node *eexprlist);
2670Sstevel@tonic-gate struct node *tree_if(struct node *expr, struct node *stmts,
2680Sstevel@tonic-gate     const char *file, int line);
2690Sstevel@tonic-gate struct node *tree_name(const char *s, enum itertype it,
2700Sstevel@tonic-gate     const char *file, int line);
2710Sstevel@tonic-gate struct node *tree_iname(const char *s, const char *file, int line);
2720Sstevel@tonic-gate struct node *tree_globid(const char *s, const char *file, int line);
2730Sstevel@tonic-gate struct node *tree_name_append(struct node *np1, struct node *np2);
2740Sstevel@tonic-gate struct node *tree_name_repairdash(struct node *np1, const char *s);
275*2869Sgavinm struct node *tree_name_repairdash2(const char *s, struct node *np1);
2760Sstevel@tonic-gate struct node *tree_name_iterator(struct node *np1, struct node *np2);
2770Sstevel@tonic-gate struct node *tree_timeval(const char *s, const char *suffix,
2780Sstevel@tonic-gate     const char *file, int line);
2790Sstevel@tonic-gate struct node *tree_num(const char *s, const char *file, int line);
2800Sstevel@tonic-gate struct node *tree_quote(const char *s, const char *file, int line);
2810Sstevel@tonic-gate struct node *tree_func(const char *s, struct node *np,
2820Sstevel@tonic-gate     const char *file, int line);
2830Sstevel@tonic-gate struct node *tree_pname(struct node *np);
2840Sstevel@tonic-gate struct node *tree_arrow(struct node *lhs, struct node *nnp, struct node *knp,
2850Sstevel@tonic-gate     struct node *rhs);
2860Sstevel@tonic-gate struct lut *tree_s2np_lut_add(struct lut *root, const char *s, struct node *np);
2870Sstevel@tonic-gate struct node *tree_s2np_lut_lookup(struct lut *root, const char *s);
2880Sstevel@tonic-gate struct lut *tree_name2np_lut_add(struct lut *root,
2890Sstevel@tonic-gate     struct node *namep, struct node *np);
2900Sstevel@tonic-gate struct node *tree_name2np_lut_lookup(struct lut *root, struct node *namep);
2910Sstevel@tonic-gate struct node *tree_name2np_lut_lookup_name(struct lut *root, struct node *namep);
2920Sstevel@tonic-gate struct lut *tree_event2np_lut_add(struct lut *root,
2930Sstevel@tonic-gate     struct node *enp, struct node *np);
2940Sstevel@tonic-gate struct node *tree_event2np_lut_lookup(struct lut *root, struct node *enp);
2950Sstevel@tonic-gate struct node *tree_event2np_lut_lookup_event(struct lut *root,
2960Sstevel@tonic-gate     struct node *enp);
2970Sstevel@tonic-gate struct node *tree_decl(enum nodetype t, struct node *enp, struct node *nvpairs,
2980Sstevel@tonic-gate     const char *file, int line);
2990Sstevel@tonic-gate struct node *tree_stmt(enum nodetype t, struct node *np,
3000Sstevel@tonic-gate     const char *file, int line);
3010Sstevel@tonic-gate void tree_report();
3020Sstevel@tonic-gate int tree_namecmp(struct node *np1, struct node *np2);
3030Sstevel@tonic-gate int tree_eventcmp(struct node *np1, struct node *np2);
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate struct lut *Faults;
3060Sstevel@tonic-gate struct lut *Upsets;
3070Sstevel@tonic-gate struct lut *Defects;
3080Sstevel@tonic-gate struct lut *Errors;
3090Sstevel@tonic-gate struct lut *Ereports;
3100Sstevel@tonic-gate struct lut *Ereportenames;
3110Sstevel@tonic-gate struct lut *SERDs;
3121414Scindi struct lut *STATs;
3130Sstevel@tonic-gate struct lut *ASRUs;
3140Sstevel@tonic-gate struct lut *FRUs;
3150Sstevel@tonic-gate struct lut *Configs;
3160Sstevel@tonic-gate struct node *Props;
3170Sstevel@tonic-gate struct node *Lastprops;
3180Sstevel@tonic-gate struct node *Masks;
3190Sstevel@tonic-gate struct node *Lastmasks;
3200Sstevel@tonic-gate struct node *Problems;
3210Sstevel@tonic-gate struct node *Lastproblems;
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate #ifdef	__cplusplus
3240Sstevel@tonic-gate }
3250Sstevel@tonic-gate #endif
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate #endif	/* _ESC_COMMON_TREE_H */
328