xref: /onnv-gate/usr/src/cmd/fm/eversholt/common/tree.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  *
26*0Sstevel@tonic-gate  * tree.h -- public definitions for tree module
27*0Sstevel@tonic-gate  *
28*0Sstevel@tonic-gate  * the parse tree is made up of struct node's.  the struct is
29*0Sstevel@tonic-gate  * a "variant record" with a type, the filename and line number
30*0Sstevel@tonic-gate  * related to the node, and then type-specific node data.
31*0Sstevel@tonic-gate  */
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #ifndef	_ESC_COMMON_TREE_H
34*0Sstevel@tonic-gate #define	_ESC_COMMON_TREE_H
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #ifdef	__cplusplus
39*0Sstevel@tonic-gate extern "C" {
40*0Sstevel@tonic-gate #endif
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate struct node {
43*0Sstevel@tonic-gate 	enum nodetype {
44*0Sstevel@tonic-gate 		T_NOTHING = 1000,	/* used to keep going on error cases */
45*0Sstevel@tonic-gate 		T_NAME,			/* identifiers, sometimes chained */
46*0Sstevel@tonic-gate 		T_GLOBID,		/* globals (e.g. $a) */
47*0Sstevel@tonic-gate 		T_EVENT,		/* class@path{expr} */
48*0Sstevel@tonic-gate 		T_ENGINE,		/* upset threshold engine (e.g. SERD) */
49*0Sstevel@tonic-gate 		T_ASRU,			/* ASRU declaration */
50*0Sstevel@tonic-gate 		T_FRU,			/* FRU declaration */
51*0Sstevel@tonic-gate 		T_TIMEVAL,		/* num w/time suffix (ns internally) */
52*0Sstevel@tonic-gate 		T_NUM,			/* num (ull internally) */
53*0Sstevel@tonic-gate 		T_QUOTE,		/* quoted string */
54*0Sstevel@tonic-gate 		T_FUNC,			/* func(arglist) */
55*0Sstevel@tonic-gate 		T_NVPAIR,		/* name=value pair in decl */
56*0Sstevel@tonic-gate 		T_ASSIGN,		/* assignment statement */
57*0Sstevel@tonic-gate 		T_CONDIF,		/* a and T_CONDELSE in (a ? b : c ) */
58*0Sstevel@tonic-gate 		T_CONDELSE,		/* lists b and c in (a ? b : c ) */
59*0Sstevel@tonic-gate 		T_NOT,			/* boolean ! operator */
60*0Sstevel@tonic-gate 		T_AND,			/* boolean && operator */
61*0Sstevel@tonic-gate 		T_OR,			/* boolean || operator */
62*0Sstevel@tonic-gate 		T_EQ,			/* boolean == operator */
63*0Sstevel@tonic-gate 		T_NE,			/* boolean != operator */
64*0Sstevel@tonic-gate 		T_SUB,			/* integer - operator */
65*0Sstevel@tonic-gate 		T_ADD,			/* integer + operator */
66*0Sstevel@tonic-gate 		T_MUL,			/* integer * operator */
67*0Sstevel@tonic-gate 		T_DIV,			/* integer / operator */
68*0Sstevel@tonic-gate 		T_MOD,			/* integer % operator */
69*0Sstevel@tonic-gate 		T_LT,			/* boolean < operator */
70*0Sstevel@tonic-gate 		T_LE,			/* boolean <= operator */
71*0Sstevel@tonic-gate 		T_GT,			/* boolean > operator */
72*0Sstevel@tonic-gate 		T_GE,			/* boolean >= operator */
73*0Sstevel@tonic-gate 		T_BITAND,		/* bitwise & operator */
74*0Sstevel@tonic-gate 		T_BITOR,		/* bitwise | operator */
75*0Sstevel@tonic-gate 		T_BITXOR,		/* bitwise ^ operator */
76*0Sstevel@tonic-gate 		T_BITNOT,		/* bitwise ~ operator */
77*0Sstevel@tonic-gate 		T_LSHIFT,		/* bitwise << operator */
78*0Sstevel@tonic-gate 		T_RSHIFT,		/* bitwise >> operator */
79*0Sstevel@tonic-gate 		T_ARROW,		/* lhs (N)->(K) rhs */
80*0Sstevel@tonic-gate 		T_LIST,			/* comma-separated list */
81*0Sstevel@tonic-gate 		T_FAULT,		/* fault declaration */
82*0Sstevel@tonic-gate 		T_UPSET,		/* upset declaration */
83*0Sstevel@tonic-gate 		T_DEFECT,		/* defect declaration */
84*0Sstevel@tonic-gate 		T_ERROR,		/* error declaration */
85*0Sstevel@tonic-gate 		T_EREPORT,		/* ereport declaration */
86*0Sstevel@tonic-gate 		T_SERD,			/* SERD engine declaration */
87*0Sstevel@tonic-gate 		T_PROP,			/* prop statement */
88*0Sstevel@tonic-gate 		T_MASK,			/* mask statement */
89*0Sstevel@tonic-gate 		T_CONFIG		/* config statement */
90*0Sstevel@tonic-gate 	} t;
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate 	/*
93*0Sstevel@tonic-gate 	 * regardless of the type of node, filename and line number
94*0Sstevel@tonic-gate 	 * information from the original .esc file is tracked here.
95*0Sstevel@tonic-gate 	 */
96*0Sstevel@tonic-gate 	const char *file;
97*0Sstevel@tonic-gate 	int line;
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate 	/*
100*0Sstevel@tonic-gate 	 * the variant part of a struct node...
101*0Sstevel@tonic-gate 	 */
102*0Sstevel@tonic-gate 	union {
103*0Sstevel@tonic-gate 		struct {
104*0Sstevel@tonic-gate 			/*
105*0Sstevel@tonic-gate 			 * info kept for T_NAME, used in several ways:
106*0Sstevel@tonic-gate 			 *
107*0Sstevel@tonic-gate 			 *	1 for simple variable names.
108*0Sstevel@tonic-gate 			 *		example: j
109*0Sstevel@tonic-gate 			 *
110*0Sstevel@tonic-gate 			 *	2 for event class names, with component
111*0Sstevel@tonic-gate 			 *	  names chained together via the "next"
112*0Sstevel@tonic-gate 			 *	  pointers.
113*0Sstevel@tonic-gate 			 *		example: fault.fan.broken
114*0Sstevel@tonic-gate 			 *
115*0Sstevel@tonic-gate 			 *	3 for component pathnames, with component
116*0Sstevel@tonic-gate 			 *	  names chained together via the "next"
117*0Sstevel@tonic-gate 			 *	  pointers and iterators or instance numbers
118*0Sstevel@tonic-gate 			 *	  attached via the "child" pointers.
119*0Sstevel@tonic-gate 			 *		example: sysboard[0]/cpu[n]
120*0Sstevel@tonic-gate 			 *
121*0Sstevel@tonic-gate 			 * case 3 is the most interesting.
122*0Sstevel@tonic-gate 			 *	- if child is set, there's an iterator
123*0Sstevel@tonic-gate 			 *	- if child is a T_NAME, it is x[j] or x<j> and
124*0Sstevel@tonic-gate 			 *	  iterator type tells you vertical or horizontal
125*0Sstevel@tonic-gate 			 *	- if child is a T_NUM, it is x[0] or x<0> or
126*0Sstevel@tonic-gate 			 *	  x0 and iterator type tells you which one
127*0Sstevel@tonic-gate 			 *	- if cp pointer is set, then we recently
128*0Sstevel@tonic-gate 			 *	  matched it to a config cache entry and one
129*0Sstevel@tonic-gate 			 *	  can ignore child for now because it still
130*0Sstevel@tonic-gate 			 *	  represents the *pattern* you're matching.
131*0Sstevel@tonic-gate 			 *	  cp represents what you matched.  ptree()
132*0Sstevel@tonic-gate 			 *	  knows that if cp is set, to print that number
133*0Sstevel@tonic-gate 			 *	  instead of following child.
134*0Sstevel@tonic-gate 			 *
135*0Sstevel@tonic-gate 			 * when T_NAME nodes are chained:
136*0Sstevel@tonic-gate 			 * the "last" pointer takes you to the end of the
137*0Sstevel@tonic-gate 			 * chain, but only the first component's last pointer
138*0Sstevel@tonic-gate 			 * is kept up to date.  it is used to determine
139*0Sstevel@tonic-gate 			 * where to append newly-created T_NAME nodes (see
140*0Sstevel@tonic-gate 			 * tree_name_append()).
141*0Sstevel@tonic-gate 			 */
142*0Sstevel@tonic-gate 			const char *s;		/* the name itself */
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate 			struct node *child;
145*0Sstevel@tonic-gate 			struct node *next;
146*0Sstevel@tonic-gate 			struct node *last;
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate 			/* opaque pointer used during config matching */
149*0Sstevel@tonic-gate 			struct config *cp;
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate 			enum nametype {
152*0Sstevel@tonic-gate 				N_UNSPEC,
153*0Sstevel@tonic-gate 				N_FAULT,
154*0Sstevel@tonic-gate 				N_UPSET,
155*0Sstevel@tonic-gate 				N_DEFECT,
156*0Sstevel@tonic-gate 				N_ERROR,
157*0Sstevel@tonic-gate 				N_EREPORT,
158*0Sstevel@tonic-gate 				N_SERD
159*0Sstevel@tonic-gate 			} t:3;
160*0Sstevel@tonic-gate 			enum itertype {
161*0Sstevel@tonic-gate 				IT_NONE,
162*0Sstevel@tonic-gate 				IT_VERTICAL,
163*0Sstevel@tonic-gate 				IT_HORIZONTAL,
164*0Sstevel@tonic-gate 				IT_ENAME
165*0Sstevel@tonic-gate 			} it:2;
166*0Sstevel@tonic-gate 			unsigned childgen:1;	/* child was auto-generated */
167*0Sstevel@tonic-gate 		} name;
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 		struct {
170*0Sstevel@tonic-gate 			/*
171*0Sstevel@tonic-gate 			 * info kept for T_GLOBID
172*0Sstevel@tonic-gate 			 */
173*0Sstevel@tonic-gate 			const char *s;		/* the name itself */
174*0Sstevel@tonic-gate 		} globid;
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate 		/*
177*0Sstevel@tonic-gate 		 * info kept for T_TIMEVAL and T_NUM
178*0Sstevel@tonic-gate 		 *
179*0Sstevel@tonic-gate 		 * timevals are kept in nanoseconds.
180*0Sstevel@tonic-gate 		 */
181*0Sstevel@tonic-gate 		unsigned long long ull;
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate 		struct {
184*0Sstevel@tonic-gate 			/*
185*0Sstevel@tonic-gate 			 * info kept for T_QUOTE
186*0Sstevel@tonic-gate 			 */
187*0Sstevel@tonic-gate 			const char *s;		/* the quoted string */
188*0Sstevel@tonic-gate 		} quote;
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 		struct {
191*0Sstevel@tonic-gate 			/*
192*0Sstevel@tonic-gate 			 * info kept for T_FUNC
193*0Sstevel@tonic-gate 			 */
194*0Sstevel@tonic-gate 			const char *s;		/* name of function */
195*0Sstevel@tonic-gate 			struct node *arglist;
196*0Sstevel@tonic-gate 			void *cachedval;	/* runtime cache of value */
197*0Sstevel@tonic-gate 		} func;
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 		struct {
200*0Sstevel@tonic-gate 			/*
201*0Sstevel@tonic-gate 			 * info kept for T_PROP and T_MASK statements
202*0Sstevel@tonic-gate 			 * as well as declarations for:
203*0Sstevel@tonic-gate 			 *	T_FAULT
204*0Sstevel@tonic-gate 			 *	T_UPSET
205*0Sstevel@tonic-gate 			 *	T_DEFECT
206*0Sstevel@tonic-gate 			 *	T_ERROR
207*0Sstevel@tonic-gate 			 *	T_EREPORT
208*0Sstevel@tonic-gate 			 *	T_ASRU
209*0Sstevel@tonic-gate 			 *	T_FRU
210*0Sstevel@tonic-gate 			 *	T_CONFIG
211*0Sstevel@tonic-gate 			 */
212*0Sstevel@tonic-gate 			struct node *np;
213*0Sstevel@tonic-gate 			struct node *nvpairs;	/* for declarations */
214*0Sstevel@tonic-gate 			struct lut *lutp;	/* for declarations */
215*0Sstevel@tonic-gate 			struct node *next;	/* for Props & Masks lists */
216*0Sstevel@tonic-gate 			struct node *expr;	/* for if statements */
217*0Sstevel@tonic-gate 			unsigned char flags;	/* see STMT_ flags below */
218*0Sstevel@tonic-gate 		} stmt;			/* used for stmt */
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate 		struct {
221*0Sstevel@tonic-gate 			/*
222*0Sstevel@tonic-gate 			 * info kept for T_EVENT
223*0Sstevel@tonic-gate 			 */
224*0Sstevel@tonic-gate 			struct node *ename;	/* event class name */
225*0Sstevel@tonic-gate 			struct node *epname;	/* component path name */
226*0Sstevel@tonic-gate 			struct node *eexprlist;	/* constraint expression */
227*0Sstevel@tonic-gate 			struct node *declp;	/* event declaration */
228*0Sstevel@tonic-gate 		} event;
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate 		struct {
231*0Sstevel@tonic-gate 			/*
232*0Sstevel@tonic-gate 			 * info kept for T_ARROW
233*0Sstevel@tonic-gate 			 */
234*0Sstevel@tonic-gate 			struct node *lhs;	/* left side of arrow */
235*0Sstevel@tonic-gate 			struct node *rhs;	/* right side of arrow */
236*0Sstevel@tonic-gate 			struct node *nnp;	/* N value */
237*0Sstevel@tonic-gate 			struct node *knp;	/* K value */
238*0Sstevel@tonic-gate 			struct node *prop;	/* arrow is part of this prop */
239*0Sstevel@tonic-gate 		} arrow;
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate 		struct {
242*0Sstevel@tonic-gate 			/*
243*0Sstevel@tonic-gate 			 * info kept for everything else (T_ADD, T_LIST, etc.)
244*0Sstevel@tonic-gate 			 */
245*0Sstevel@tonic-gate 			struct node *left;
246*0Sstevel@tonic-gate 			struct node *right;
247*0Sstevel@tonic-gate 		} expr;
248*0Sstevel@tonic-gate 	} u;
249*0Sstevel@tonic-gate };
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate /* flags we keep with stmts */
252*0Sstevel@tonic-gate #define	STMT_REF	0x01	/* declared item is referenced */
253*0Sstevel@tonic-gate #define	STMT_CYMARK	0x02	/* declared item is marked for cycle check */
254*0Sstevel@tonic-gate #define	STMT_CYCLE	0x04	/* cycle detected and already reported */
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate #define	TIMEVAL_EVENTUALLY (1000000000ULL*60*60*24*365*100)	/* 100 years */
257*0Sstevel@tonic-gate 
258*0Sstevel@tonic-gate void tree_init(void);
259*0Sstevel@tonic-gate void tree_fini(void);
260*0Sstevel@tonic-gate struct node *newnode(enum nodetype t, const char *file, int line);
261*0Sstevel@tonic-gate void tree_free(struct node *root);
262*0Sstevel@tonic-gate struct node *tree_root(struct node *np);
263*0Sstevel@tonic-gate struct node *tree_nothing(void);
264*0Sstevel@tonic-gate struct node *tree_expr(enum nodetype t, struct node *left, struct node *right);
265*0Sstevel@tonic-gate struct node *tree_event(struct node *ename, struct node *epname,
266*0Sstevel@tonic-gate     struct node *eexprlist);
267*0Sstevel@tonic-gate struct node *tree_if(struct node *expr, struct node *stmts,
268*0Sstevel@tonic-gate     const char *file, int line);
269*0Sstevel@tonic-gate struct node *tree_name(const char *s, enum itertype it,
270*0Sstevel@tonic-gate     const char *file, int line);
271*0Sstevel@tonic-gate struct node *tree_iname(const char *s, const char *file, int line);
272*0Sstevel@tonic-gate struct node *tree_globid(const char *s, const char *file, int line);
273*0Sstevel@tonic-gate struct node *tree_name_append(struct node *np1, struct node *np2);
274*0Sstevel@tonic-gate struct node *tree_name_repairdash(struct node *np1, const char *s);
275*0Sstevel@tonic-gate struct node *tree_name_iterator(struct node *np1, struct node *np2);
276*0Sstevel@tonic-gate struct node *tree_timeval(const char *s, const char *suffix,
277*0Sstevel@tonic-gate     const char *file, int line);
278*0Sstevel@tonic-gate struct node *tree_num(const char *s, const char *file, int line);
279*0Sstevel@tonic-gate struct node *tree_quote(const char *s, const char *file, int line);
280*0Sstevel@tonic-gate struct node *tree_func(const char *s, struct node *np,
281*0Sstevel@tonic-gate     const char *file, int line);
282*0Sstevel@tonic-gate struct node *tree_pname(struct node *np);
283*0Sstevel@tonic-gate struct node *tree_arrow(struct node *lhs, struct node *nnp, struct node *knp,
284*0Sstevel@tonic-gate     struct node *rhs);
285*0Sstevel@tonic-gate struct lut *tree_s2np_lut_add(struct lut *root, const char *s, struct node *np);
286*0Sstevel@tonic-gate struct node *tree_s2np_lut_lookup(struct lut *root, const char *s);
287*0Sstevel@tonic-gate struct lut *tree_name2np_lut_add(struct lut *root,
288*0Sstevel@tonic-gate     struct node *namep, struct node *np);
289*0Sstevel@tonic-gate struct node *tree_name2np_lut_lookup(struct lut *root, struct node *namep);
290*0Sstevel@tonic-gate struct node *tree_name2np_lut_lookup_name(struct lut *root, struct node *namep);
291*0Sstevel@tonic-gate struct lut *tree_event2np_lut_add(struct lut *root,
292*0Sstevel@tonic-gate     struct node *enp, struct node *np);
293*0Sstevel@tonic-gate struct node *tree_event2np_lut_lookup(struct lut *root, struct node *enp);
294*0Sstevel@tonic-gate struct node *tree_event2np_lut_lookup_event(struct lut *root,
295*0Sstevel@tonic-gate     struct node *enp);
296*0Sstevel@tonic-gate struct node *tree_decl(enum nodetype t, struct node *enp, struct node *nvpairs,
297*0Sstevel@tonic-gate     const char *file, int line);
298*0Sstevel@tonic-gate struct node *tree_stmt(enum nodetype t, struct node *np,
299*0Sstevel@tonic-gate     const char *file, int line);
300*0Sstevel@tonic-gate void tree_report();
301*0Sstevel@tonic-gate int tree_namecmp(struct node *np1, struct node *np2);
302*0Sstevel@tonic-gate int tree_eventcmp(struct node *np1, struct node *np2);
303*0Sstevel@tonic-gate 
304*0Sstevel@tonic-gate struct lut *Faults;
305*0Sstevel@tonic-gate struct lut *Upsets;
306*0Sstevel@tonic-gate struct lut *Defects;
307*0Sstevel@tonic-gate struct lut *Errors;
308*0Sstevel@tonic-gate struct lut *Ereports;
309*0Sstevel@tonic-gate struct lut *Ereportenames;
310*0Sstevel@tonic-gate struct lut *SERDs;
311*0Sstevel@tonic-gate struct lut *ASRUs;
312*0Sstevel@tonic-gate struct lut *FRUs;
313*0Sstevel@tonic-gate struct lut *Configs;
314*0Sstevel@tonic-gate struct node *Props;
315*0Sstevel@tonic-gate struct node *Lastprops;
316*0Sstevel@tonic-gate struct node *Masks;
317*0Sstevel@tonic-gate struct node *Lastmasks;
318*0Sstevel@tonic-gate struct node *Problems;
319*0Sstevel@tonic-gate struct node *Lastproblems;
320*0Sstevel@tonic-gate 
321*0Sstevel@tonic-gate #ifdef	__cplusplus
322*0Sstevel@tonic-gate }
323*0Sstevel@tonic-gate #endif
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate #endif	/* _ESC_COMMON_TREE_H */
326