1277177Srrs#ifndef __eval_expr_h__
2277177Srrs#define __eval_expr_h__
3277177Srrs/*-
4277177Srrs * Copyright (c) 2015 Netflix Inc.
5277177Srrs * All rights reserved.
6277177Srrs *
7277177Srrs * Redistribution and use in source and binary forms, with or without
8277177Srrs * modification, are permitted provided that the following conditions
9277177Srrs * are met:
10277177Srrs * 1. Redistributions of source code must retain the above copyright
11277177Srrs *    notice, this list of conditions and the following disclaimer,
12277177Srrs *    in this position and unchanged.
13277177Srrs * 2. Redistributions in binary form must reproduce the above copyright
14277177Srrs *    notice, this list of conditions and the following disclaimer in the
15277177Srrs *    documentation and/or other materials provided with the distribution.
16277177Srrs * 3. The name of the author may not be used to endorse or promote products
17277177Srrs *    derived from this software without specific prior written permission
18277177Srrs *
19277177Srrs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20277177Srrs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21277177Srrs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22277177Srrs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23277177Srrs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24277177Srrs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25277177Srrs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26277177Srrs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27277177Srrs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28277177Srrs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29277177Srrs */
30277177Srrs__FBSDID("$FreeBSD$");
31277177Srrs
32277177Srrsenum exptype {
33277177Srrs	TYPE_OP_PLUS,
34277177Srrs	TYPE_OP_MINUS,
35277177Srrs	TYPE_OP_MULT,
36277177Srrs	TYPE_OP_DIVIDE,
37277177Srrs	TYPE_PARN_OPEN,
38277177Srrs	TYPE_PARN_CLOSE,
39277177Srrs	TYPE_VALUE_CON,
40277177Srrs	TYPE_VALUE_PMC
41277177Srrs};
42277177Srrs
43277177Srrs#define STATE_UNSET  0		/* We have no setting yet in value */
44277177Srrs#define STATE_FILLED 1		/* We have filled in value */
45277177Srrs
46277177Srrsstruct expression {
47277177Srrs	struct expression *next;	/* Next in expression. */
48277177Srrs	struct expression *prev;	/* Prev in expression. */
49277177Srrs	double value;			/* If there is a value to set */
50277177Srrs	enum exptype type;			/* What is it */
51277177Srrs	uint8_t state;			/* Current state if value type */
52277177Srrs	char name[252];			/* If a PMC whats the name, con value*/
53277177Srrs};
54277177Srrs
55277177Srrsstruct expression *parse_expression(char *str);
56277177Srrsdouble run_expr(struct expression *exp, int initial_call, struct expression **lastone);
57277177Srrsvoid print_exp(struct expression *exp);
58277177Srrs#endif
59