xref: /onnv-gate/usr/src/cmd/fm/eversholt/common/tree.h (revision 7197:6062b005c7ea)
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 /*
226640Scth  * Copyright 2008 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 {
434436Sstephh 		T_NOTHING,		/* 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 */
904436Sstephh 	} t:8;
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 	 */
964436Sstephh 	int line:24;
970Sstevel@tonic-gate 	const char *file;
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 
1514436Sstephh 			/*
1524436Sstephh 			 * note nametype is also declared as a three bit enum
1534436Sstephh 			 * in itree.h, so if this ever needs expanding that
1544436Sstephh 			 * will need changing too.
1554436Sstephh 			 */
1560Sstevel@tonic-gate 			enum nametype {
1570Sstevel@tonic-gate 				N_UNSPEC,
1580Sstevel@tonic-gate 				N_FAULT,
1590Sstevel@tonic-gate 				N_UPSET,
1600Sstevel@tonic-gate 				N_DEFECT,
1610Sstevel@tonic-gate 				N_ERROR,
1620Sstevel@tonic-gate 				N_EREPORT,
1631414Scindi 				N_SERD,
1641414Scindi 				N_STAT
1650Sstevel@tonic-gate 			} t:3;
1660Sstevel@tonic-gate 			enum itertype {
1670Sstevel@tonic-gate 				IT_NONE,
1680Sstevel@tonic-gate 				IT_VERTICAL,
1690Sstevel@tonic-gate 				IT_HORIZONTAL,
1700Sstevel@tonic-gate 				IT_ENAME
1710Sstevel@tonic-gate 			} it:2;
1720Sstevel@tonic-gate 			unsigned childgen:1;	/* child was auto-generated */
1730Sstevel@tonic-gate 		} name;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 		struct {
1760Sstevel@tonic-gate 			/*
1770Sstevel@tonic-gate 			 * info kept for T_GLOBID
1780Sstevel@tonic-gate 			 */
1790Sstevel@tonic-gate 			const char *s;		/* the name itself */
1800Sstevel@tonic-gate 		} globid;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 		/*
1830Sstevel@tonic-gate 		 * info kept for T_TIMEVAL and T_NUM
1840Sstevel@tonic-gate 		 *
1850Sstevel@tonic-gate 		 * timevals are kept in nanoseconds.
1860Sstevel@tonic-gate 		 */
1870Sstevel@tonic-gate 		unsigned long long ull;
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 		struct {
1900Sstevel@tonic-gate 			/*
1910Sstevel@tonic-gate 			 * info kept for T_QUOTE
1920Sstevel@tonic-gate 			 */
1930Sstevel@tonic-gate 			const char *s;		/* the quoted string */
1940Sstevel@tonic-gate 		} quote;
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 		struct {
1970Sstevel@tonic-gate 			/*
1980Sstevel@tonic-gate 			 * info kept for T_FUNC
1990Sstevel@tonic-gate 			 */
2000Sstevel@tonic-gate 			const char *s;		/* name of function */
2010Sstevel@tonic-gate 			struct node *arglist;
2020Sstevel@tonic-gate 		} func;
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 		struct {
2050Sstevel@tonic-gate 			/*
2060Sstevel@tonic-gate 			 * info kept for T_PROP and T_MASK statements
2070Sstevel@tonic-gate 			 * as well as declarations for:
2080Sstevel@tonic-gate 			 *	T_FAULT
2090Sstevel@tonic-gate 			 *	T_UPSET
2100Sstevel@tonic-gate 			 *	T_DEFECT
2110Sstevel@tonic-gate 			 *	T_ERROR
2120Sstevel@tonic-gate 			 *	T_EREPORT
2130Sstevel@tonic-gate 			 *	T_ASRU
2140Sstevel@tonic-gate 			 *	T_FRU
2150Sstevel@tonic-gate 			 *	T_CONFIG
2160Sstevel@tonic-gate 			 */
2170Sstevel@tonic-gate 			struct node *np;
2180Sstevel@tonic-gate 			struct node *nvpairs;	/* for declarations */
2190Sstevel@tonic-gate 			struct lut *lutp;	/* for declarations */
2200Sstevel@tonic-gate 			struct node *next;	/* for Props & Masks lists */
2210Sstevel@tonic-gate 			struct node *expr;	/* for if statements */
2220Sstevel@tonic-gate 			unsigned char flags;	/* see STMT_ flags below */
2230Sstevel@tonic-gate 		} stmt;			/* used for stmt */
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 		struct {
2260Sstevel@tonic-gate 			/*
2270Sstevel@tonic-gate 			 * info kept for T_EVENT
2280Sstevel@tonic-gate 			 */
2290Sstevel@tonic-gate 			struct node *ename;	/* event class name */
2300Sstevel@tonic-gate 			struct node *epname;	/* component path name */
2314436Sstephh 			struct node *oldepname;	/* unwildcarded path name */
2324436Sstephh 			struct node *ewname;	/* wildcarded portion */
2330Sstevel@tonic-gate 			struct node *eexprlist;	/* constraint expression */
2340Sstevel@tonic-gate 			struct node *declp;	/* event declaration */
2350Sstevel@tonic-gate 		} event;
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 		struct {
2380Sstevel@tonic-gate 			/*
2390Sstevel@tonic-gate 			 * info kept for T_ARROW
2400Sstevel@tonic-gate 			 */
2410Sstevel@tonic-gate 			struct node *lhs;	/* left side of arrow */
2420Sstevel@tonic-gate 			struct node *rhs;	/* right side of arrow */
2430Sstevel@tonic-gate 			struct node *nnp;	/* N value */
2440Sstevel@tonic-gate 			struct node *knp;	/* K value */
2450Sstevel@tonic-gate 			struct node *prop;	/* arrow is part of this prop */
2464436Sstephh 			int needed;
247*7197Sstephh 			struct node *parent;
2480Sstevel@tonic-gate 		} arrow;
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate 		struct {
2510Sstevel@tonic-gate 			/*
2520Sstevel@tonic-gate 			 * info kept for everything else (T_ADD, T_LIST, etc.)
2530Sstevel@tonic-gate 			 */
2540Sstevel@tonic-gate 			struct node *left;
2550Sstevel@tonic-gate 			struct node *right;
2564436Sstephh 			int temp;
2570Sstevel@tonic-gate 		} expr;
2580Sstevel@tonic-gate 	} u;
2594436Sstephh 	/*
2604436Sstephh 	 * Note to save memory the nodesize() function trims the end of this
2614436Sstephh 	 * structure, so best not to add anything after this point
2624436Sstephh 	 */
2630Sstevel@tonic-gate };
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate /* flags we keep with stmts */
2660Sstevel@tonic-gate #define	STMT_REF	0x01	/* declared item is referenced */
2670Sstevel@tonic-gate #define	STMT_CYMARK	0x02	/* declared item is marked for cycle check */
2680Sstevel@tonic-gate #define	STMT_CYCLE	0x04	/* cycle detected and already reported */
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate #define	TIMEVAL_EVENTUALLY (1000000000ULL*60*60*24*365*100)	/* 100 years */
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate void tree_init(void);
2730Sstevel@tonic-gate void tree_fini(void);
2740Sstevel@tonic-gate struct node *newnode(enum nodetype t, const char *file, int line);
2750Sstevel@tonic-gate void tree_free(struct node *root);
2760Sstevel@tonic-gate struct node *tree_root(struct node *np);
2770Sstevel@tonic-gate struct node *tree_nothing(void);
2780Sstevel@tonic-gate struct node *tree_expr(enum nodetype t, struct node *left, struct node *right);
2790Sstevel@tonic-gate struct node *tree_event(struct node *ename, struct node *epname,
2800Sstevel@tonic-gate     struct node *eexprlist);
2810Sstevel@tonic-gate struct node *tree_if(struct node *expr, struct node *stmts,
2820Sstevel@tonic-gate     const char *file, int line);
2830Sstevel@tonic-gate struct node *tree_name(const char *s, enum itertype it,
2840Sstevel@tonic-gate     const char *file, int line);
2850Sstevel@tonic-gate struct node *tree_iname(const char *s, const char *file, int line);
2860Sstevel@tonic-gate struct node *tree_globid(const char *s, const char *file, int line);
2870Sstevel@tonic-gate struct node *tree_name_append(struct node *np1, struct node *np2);
2880Sstevel@tonic-gate struct node *tree_name_repairdash(struct node *np1, const char *s);
2892869Sgavinm struct node *tree_name_repairdash2(const char *s, struct node *np1);
2900Sstevel@tonic-gate struct node *tree_name_iterator(struct node *np1, struct node *np2);
2910Sstevel@tonic-gate struct node *tree_timeval(const char *s, const char *suffix,
2920Sstevel@tonic-gate     const char *file, int line);
2930Sstevel@tonic-gate struct node *tree_num(const char *s, const char *file, int line);
2940Sstevel@tonic-gate struct node *tree_quote(const char *s, const char *file, int line);
2950Sstevel@tonic-gate struct node *tree_func(const char *s, struct node *np,
2960Sstevel@tonic-gate     const char *file, int line);
2970Sstevel@tonic-gate struct node *tree_pname(struct node *np);
2980Sstevel@tonic-gate struct node *tree_arrow(struct node *lhs, struct node *nnp, struct node *knp,
2990Sstevel@tonic-gate     struct node *rhs);
3000Sstevel@tonic-gate struct lut *tree_s2np_lut_add(struct lut *root, const char *s, struct node *np);
3010Sstevel@tonic-gate struct node *tree_s2np_lut_lookup(struct lut *root, const char *s);
3020Sstevel@tonic-gate struct lut *tree_name2np_lut_add(struct lut *root,
3030Sstevel@tonic-gate     struct node *namep, struct node *np);
3040Sstevel@tonic-gate struct node *tree_name2np_lut_lookup(struct lut *root, struct node *namep);
3050Sstevel@tonic-gate struct node *tree_name2np_lut_lookup_name(struct lut *root, struct node *namep);
3060Sstevel@tonic-gate struct lut *tree_event2np_lut_add(struct lut *root,
3070Sstevel@tonic-gate     struct node *enp, struct node *np);
3080Sstevel@tonic-gate struct node *tree_event2np_lut_lookup(struct lut *root, struct node *enp);
3090Sstevel@tonic-gate struct node *tree_event2np_lut_lookup_event(struct lut *root,
3100Sstevel@tonic-gate     struct node *enp);
3110Sstevel@tonic-gate struct node *tree_decl(enum nodetype t, struct node *enp, struct node *nvpairs,
3120Sstevel@tonic-gate     const char *file, int line);
3130Sstevel@tonic-gate struct node *tree_stmt(enum nodetype t, struct node *np,
3140Sstevel@tonic-gate     const char *file, int line);
3150Sstevel@tonic-gate void tree_report();
3160Sstevel@tonic-gate int tree_namecmp(struct node *np1, struct node *np2);
3170Sstevel@tonic-gate int tree_eventcmp(struct node *np1, struct node *np2);
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate struct lut *Faults;
3200Sstevel@tonic-gate struct lut *Upsets;
3210Sstevel@tonic-gate struct lut *Defects;
3220Sstevel@tonic-gate struct lut *Errors;
3230Sstevel@tonic-gate struct lut *Ereports;
3240Sstevel@tonic-gate struct lut *Ereportenames;
3256640Scth struct lut *Ereportenames_discard;
3260Sstevel@tonic-gate struct lut *SERDs;
3271414Scindi struct lut *STATs;
3280Sstevel@tonic-gate struct lut *ASRUs;
3290Sstevel@tonic-gate struct lut *FRUs;
3300Sstevel@tonic-gate struct lut *Configs;
3310Sstevel@tonic-gate struct node *Props;
3320Sstevel@tonic-gate struct node *Lastprops;
3330Sstevel@tonic-gate struct node *Masks;
3340Sstevel@tonic-gate struct node *Lastmasks;
3350Sstevel@tonic-gate struct node *Problems;
3360Sstevel@tonic-gate struct node *Lastproblems;
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate #ifdef	__cplusplus
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate #endif
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate #endif	/* _ESC_COMMON_TREE_H */
343