xref: /onnv-gate/usr/src/cmd/fm/eversholt/common/tree.h (revision 1414:b4126407ac5b)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*1414Scindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  *
260Sstevel@tonic-gate  * tree.h -- public definitions for tree module
270Sstevel@tonic-gate  *
280Sstevel@tonic-gate  * the parse tree is made up of struct node's.  the struct is
290Sstevel@tonic-gate  * a "variant record" with a type, the filename and line number
300Sstevel@tonic-gate  * related to the node, and then type-specific node data.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #ifndef	_ESC_COMMON_TREE_H
340Sstevel@tonic-gate #define	_ESC_COMMON_TREE_H
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate struct node {
430Sstevel@tonic-gate 	enum nodetype {
440Sstevel@tonic-gate 		T_NOTHING = 1000,	/* used to keep going on error cases */
450Sstevel@tonic-gate 		T_NAME,			/* identifiers, sometimes chained */
460Sstevel@tonic-gate 		T_GLOBID,		/* globals (e.g. $a) */
470Sstevel@tonic-gate 		T_EVENT,		/* class@path{expr} */
480Sstevel@tonic-gate 		T_ENGINE,		/* upset threshold engine (e.g. SERD) */
490Sstevel@tonic-gate 		T_ASRU,			/* ASRU declaration */
500Sstevel@tonic-gate 		T_FRU,			/* FRU declaration */
510Sstevel@tonic-gate 		T_TIMEVAL,		/* num w/time suffix (ns internally) */
520Sstevel@tonic-gate 		T_NUM,			/* num (ull internally) */
530Sstevel@tonic-gate 		T_QUOTE,		/* quoted string */
540Sstevel@tonic-gate 		T_FUNC,			/* func(arglist) */
550Sstevel@tonic-gate 		T_NVPAIR,		/* name=value pair in decl */
560Sstevel@tonic-gate 		T_ASSIGN,		/* assignment statement */
570Sstevel@tonic-gate 		T_CONDIF,		/* a and T_CONDELSE in (a ? b : c ) */
580Sstevel@tonic-gate 		T_CONDELSE,		/* lists b and c in (a ? b : c ) */
590Sstevel@tonic-gate 		T_NOT,			/* boolean ! operator */
600Sstevel@tonic-gate 		T_AND,			/* boolean && operator */
610Sstevel@tonic-gate 		T_OR,			/* boolean || operator */
620Sstevel@tonic-gate 		T_EQ,			/* boolean == operator */
630Sstevel@tonic-gate 		T_NE,			/* boolean != operator */
640Sstevel@tonic-gate 		T_SUB,			/* integer - operator */
650Sstevel@tonic-gate 		T_ADD,			/* integer + operator */
660Sstevel@tonic-gate 		T_MUL,			/* integer * operator */
670Sstevel@tonic-gate 		T_DIV,			/* integer / operator */
680Sstevel@tonic-gate 		T_MOD,			/* integer % operator */
690Sstevel@tonic-gate 		T_LT,			/* boolean < operator */
700Sstevel@tonic-gate 		T_LE,			/* boolean <= operator */
710Sstevel@tonic-gate 		T_GT,			/* boolean > operator */
720Sstevel@tonic-gate 		T_GE,			/* boolean >= operator */
730Sstevel@tonic-gate 		T_BITAND,		/* bitwise & operator */
740Sstevel@tonic-gate 		T_BITOR,		/* bitwise | operator */
750Sstevel@tonic-gate 		T_BITXOR,		/* bitwise ^ operator */
760Sstevel@tonic-gate 		T_BITNOT,		/* bitwise ~ operator */
770Sstevel@tonic-gate 		T_LSHIFT,		/* bitwise << operator */
780Sstevel@tonic-gate 		T_RSHIFT,		/* bitwise >> operator */
790Sstevel@tonic-gate 		T_ARROW,		/* lhs (N)->(K) rhs */
800Sstevel@tonic-gate 		T_LIST,			/* comma-separated list */
810Sstevel@tonic-gate 		T_FAULT,		/* fault declaration */
820Sstevel@tonic-gate 		T_UPSET,		/* upset declaration */
830Sstevel@tonic-gate 		T_DEFECT,		/* defect declaration */
840Sstevel@tonic-gate 		T_ERROR,		/* error declaration */
850Sstevel@tonic-gate 		T_EREPORT,		/* ereport declaration */
860Sstevel@tonic-gate 		T_SERD,			/* SERD engine declaration */
87*1414Scindi 		T_STAT,			/* STAT engine declaration */
880Sstevel@tonic-gate 		T_PROP,			/* prop statement */
890Sstevel@tonic-gate 		T_MASK,			/* mask statement */
900Sstevel@tonic-gate 		T_CONFIG		/* config statement */
910Sstevel@tonic-gate 	} t;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	/*
940Sstevel@tonic-gate 	 * regardless of the type of node, filename and line number
950Sstevel@tonic-gate 	 * information from the original .esc file is tracked here.
960Sstevel@tonic-gate 	 */
970Sstevel@tonic-gate 	const char *file;
980Sstevel@tonic-gate 	int line;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	/*
1010Sstevel@tonic-gate 	 * the variant part of a struct node...
1020Sstevel@tonic-gate 	 */
1030Sstevel@tonic-gate 	union {
1040Sstevel@tonic-gate 		struct {
1050Sstevel@tonic-gate 			/*
1060Sstevel@tonic-gate 			 * info kept for T_NAME, used in several ways:
1070Sstevel@tonic-gate 			 *
1080Sstevel@tonic-gate 			 *	1 for simple variable names.
1090Sstevel@tonic-gate 			 *		example: j
1100Sstevel@tonic-gate 			 *
1110Sstevel@tonic-gate 			 *	2 for event class names, with component
1120Sstevel@tonic-gate 			 *	  names chained together via the "next"
1130Sstevel@tonic-gate 			 *	  pointers.
1140Sstevel@tonic-gate 			 *		example: fault.fan.broken
1150Sstevel@tonic-gate 			 *
1160Sstevel@tonic-gate 			 *	3 for component pathnames, with component
1170Sstevel@tonic-gate 			 *	  names chained together via the "next"
1180Sstevel@tonic-gate 			 *	  pointers and iterators or instance numbers
1190Sstevel@tonic-gate 			 *	  attached via the "child" pointers.
1200Sstevel@tonic-gate 			 *		example: sysboard[0]/cpu[n]
1210Sstevel@tonic-gate 			 *
1220Sstevel@tonic-gate 			 * case 3 is the most interesting.
1230Sstevel@tonic-gate 			 *	- if child is set, there's an iterator
1240Sstevel@tonic-gate 			 *	- if child is a T_NAME, it is x[j] or x<j> and
1250Sstevel@tonic-gate 			 *	  iterator type tells you vertical or horizontal
1260Sstevel@tonic-gate 			 *	- if child is a T_NUM, it is x[0] or x<0> or
1270Sstevel@tonic-gate 			 *	  x0 and iterator type tells you which one
1280Sstevel@tonic-gate 			 *	- if cp pointer is set, then we recently
1290Sstevel@tonic-gate 			 *	  matched it to a config cache entry and one
1300Sstevel@tonic-gate 			 *	  can ignore child for now because it still
1310Sstevel@tonic-gate 			 *	  represents the *pattern* you're matching.
1320Sstevel@tonic-gate 			 *	  cp represents what you matched.  ptree()
1330Sstevel@tonic-gate 			 *	  knows that if cp is set, to print that number
1340Sstevel@tonic-gate 			 *	  instead of following child.
1350Sstevel@tonic-gate 			 *
1360Sstevel@tonic-gate 			 * when T_NAME nodes are chained:
1370Sstevel@tonic-gate 			 * the "last" pointer takes you to the end of the
1380Sstevel@tonic-gate 			 * chain, but only the first component's last pointer
1390Sstevel@tonic-gate 			 * is kept up to date.  it is used to determine
1400Sstevel@tonic-gate 			 * where to append newly-created T_NAME nodes (see
1410Sstevel@tonic-gate 			 * tree_name_append()).
1420Sstevel@tonic-gate 			 */
1430Sstevel@tonic-gate 			const char *s;		/* the name itself */
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 			struct node *child;
1460Sstevel@tonic-gate 			struct node *next;
1470Sstevel@tonic-gate 			struct node *last;
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 			/* opaque pointer used during config matching */
1500Sstevel@tonic-gate 			struct config *cp;
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 			enum nametype {
1530Sstevel@tonic-gate 				N_UNSPEC,
1540Sstevel@tonic-gate 				N_FAULT,
1550Sstevel@tonic-gate 				N_UPSET,
1560Sstevel@tonic-gate 				N_DEFECT,
1570Sstevel@tonic-gate 				N_ERROR,
1580Sstevel@tonic-gate 				N_EREPORT,
159*1414Scindi 				N_SERD,
160*1414Scindi 				N_STAT
1610Sstevel@tonic-gate 			} t:3;
1620Sstevel@tonic-gate 			enum itertype {
1630Sstevel@tonic-gate 				IT_NONE,
1640Sstevel@tonic-gate 				IT_VERTICAL,
1650Sstevel@tonic-gate 				IT_HORIZONTAL,
1660Sstevel@tonic-gate 				IT_ENAME
1670Sstevel@tonic-gate 			} it:2;
1680Sstevel@tonic-gate 			unsigned childgen:1;	/* child was auto-generated */
1690Sstevel@tonic-gate 		} name;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 		struct {
1720Sstevel@tonic-gate 			/*
1730Sstevel@tonic-gate 			 * info kept for T_GLOBID
1740Sstevel@tonic-gate 			 */
1750Sstevel@tonic-gate 			const char *s;		/* the name itself */
1760Sstevel@tonic-gate 		} globid;
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 		/*
1790Sstevel@tonic-gate 		 * info kept for T_TIMEVAL and T_NUM
1800Sstevel@tonic-gate 		 *
1810Sstevel@tonic-gate 		 * timevals are kept in nanoseconds.
1820Sstevel@tonic-gate 		 */
1830Sstevel@tonic-gate 		unsigned long long ull;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 		struct {
1860Sstevel@tonic-gate 			/*
1870Sstevel@tonic-gate 			 * info kept for T_QUOTE
1880Sstevel@tonic-gate 			 */
1890Sstevel@tonic-gate 			const char *s;		/* the quoted string */
1900Sstevel@tonic-gate 		} quote;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 		struct {
1930Sstevel@tonic-gate 			/*
1940Sstevel@tonic-gate 			 * info kept for T_FUNC
1950Sstevel@tonic-gate 			 */
1960Sstevel@tonic-gate 			const char *s;		/* name of function */
1970Sstevel@tonic-gate 			struct node *arglist;
1980Sstevel@tonic-gate 		} func;
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate 		struct {
2010Sstevel@tonic-gate 			/*
2020Sstevel@tonic-gate 			 * info kept for T_PROP and T_MASK statements
2030Sstevel@tonic-gate 			 * as well as declarations for:
2040Sstevel@tonic-gate 			 *	T_FAULT
2050Sstevel@tonic-gate 			 *	T_UPSET
2060Sstevel@tonic-gate 			 *	T_DEFECT
2070Sstevel@tonic-gate 			 *	T_ERROR
2080Sstevel@tonic-gate 			 *	T_EREPORT
2090Sstevel@tonic-gate 			 *	T_ASRU
2100Sstevel@tonic-gate 			 *	T_FRU
2110Sstevel@tonic-gate 			 *	T_CONFIG
2120Sstevel@tonic-gate 			 */
2130Sstevel@tonic-gate 			struct node *np;
2140Sstevel@tonic-gate 			struct node *nvpairs;	/* for declarations */
2150Sstevel@tonic-gate 			struct lut *lutp;	/* for declarations */
2160Sstevel@tonic-gate 			struct node *next;	/* for Props & Masks lists */
2170Sstevel@tonic-gate 			struct node *expr;	/* for if statements */
2180Sstevel@tonic-gate 			unsigned char flags;	/* see STMT_ flags below */
2190Sstevel@tonic-gate 		} stmt;			/* used for stmt */
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 		struct {
2220Sstevel@tonic-gate 			/*
2230Sstevel@tonic-gate 			 * info kept for T_EVENT
2240Sstevel@tonic-gate 			 */
2250Sstevel@tonic-gate 			struct node *ename;	/* event class name */
2260Sstevel@tonic-gate 			struct node *epname;	/* component path name */
2270Sstevel@tonic-gate 			struct node *eexprlist;	/* constraint expression */
2280Sstevel@tonic-gate 			struct node *declp;	/* event declaration */
2290Sstevel@tonic-gate 		} event;
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 		struct {
2320Sstevel@tonic-gate 			/*
2330Sstevel@tonic-gate 			 * info kept for T_ARROW
2340Sstevel@tonic-gate 			 */
2350Sstevel@tonic-gate 			struct node *lhs;	/* left side of arrow */
2360Sstevel@tonic-gate 			struct node *rhs;	/* right side of arrow */
2370Sstevel@tonic-gate 			struct node *nnp;	/* N value */
2380Sstevel@tonic-gate 			struct node *knp;	/* K value */
2390Sstevel@tonic-gate 			struct node *prop;	/* arrow is part of this prop */
2400Sstevel@tonic-gate 		} arrow;
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 		struct {
2430Sstevel@tonic-gate 			/*
2440Sstevel@tonic-gate 			 * info kept for everything else (T_ADD, T_LIST, etc.)
2450Sstevel@tonic-gate 			 */
2460Sstevel@tonic-gate 			struct node *left;
2470Sstevel@tonic-gate 			struct node *right;
2480Sstevel@tonic-gate 		} expr;
2490Sstevel@tonic-gate 	} u;
2500Sstevel@tonic-gate };
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate /* flags we keep with stmts */
2530Sstevel@tonic-gate #define	STMT_REF	0x01	/* declared item is referenced */
2540Sstevel@tonic-gate #define	STMT_CYMARK	0x02	/* declared item is marked for cycle check */
2550Sstevel@tonic-gate #define	STMT_CYCLE	0x04	/* cycle detected and already reported */
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate #define	TIMEVAL_EVENTUALLY (1000000000ULL*60*60*24*365*100)	/* 100 years */
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate void tree_init(void);
2600Sstevel@tonic-gate void tree_fini(void);
2610Sstevel@tonic-gate struct node *newnode(enum nodetype t, const char *file, int line);
2620Sstevel@tonic-gate void tree_free(struct node *root);
2630Sstevel@tonic-gate struct node *tree_root(struct node *np);
2640Sstevel@tonic-gate struct node *tree_nothing(void);
2650Sstevel@tonic-gate struct node *tree_expr(enum nodetype t, struct node *left, struct node *right);
2660Sstevel@tonic-gate struct node *tree_event(struct node *ename, struct node *epname,
2670Sstevel@tonic-gate     struct node *eexprlist);
2680Sstevel@tonic-gate struct node *tree_if(struct node *expr, struct node *stmts,
2690Sstevel@tonic-gate     const char *file, int line);
2700Sstevel@tonic-gate struct node *tree_name(const char *s, enum itertype it,
2710Sstevel@tonic-gate     const char *file, int line);
2720Sstevel@tonic-gate struct node *tree_iname(const char *s, const char *file, int line);
2730Sstevel@tonic-gate struct node *tree_globid(const char *s, const char *file, int line);
2740Sstevel@tonic-gate struct node *tree_name_append(struct node *np1, struct node *np2);
2750Sstevel@tonic-gate struct node *tree_name_repairdash(struct node *np1, const char *s);
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;
312*1414Scindi 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