expression.h 3.29 KB
Newer Older
Brice Videau's avatar
Brice Videau committed
1
2
3
#ifndef _CCS_CONDITION_H
#define _CCS_CONDITION_H

Brice Videau's avatar
Brice Videau committed
4
5
6
7
#ifdef __cplusplus
extern "C" {
#endif

Brice Videau's avatar
WIP.  
Brice Videau committed
8
enum ccs_expression_type_e {
9
10
11
12
13
14
15
16
	CCS_OR = 0,
	CCS_AND,
	CCS_EQUAL,
	CCS_NOT_EQUAL,
	CCS_LESS,
	CCS_GREATER,
	CCS_LESS_OR_EQUAL,
	CCS_GREATER_OR_EQUAL,
Brice Videau's avatar
WIP.  
Brice Videau committed
17
	CCS_IN,
18
19
20
21
22
23
24
	CCS_ADD,
	CCS_SUBSTRACT,
	CCS_MULTIPLY,
	CCS_DIVIDE,
	CCS_MODULO,
	CCS_POSITIVE,
	CCS_NEGATIVE,
Brice Videau's avatar
Brice Videau committed
25
	CCS_NOT,
26
27
28
	CCS_LIST,
	CCS_EXPRESSION_TYPE_MAX,
	CCS_EXPRESSION_FORCE_32BIT = INT_MAX
Brice Videau's avatar
WIP.  
Brice Videau committed
29
30
};

Brice Videau's avatar
Brice Videau committed
31
typedef enum ccs_expression_type_e ccs_expression_type_t;
Brice Videau's avatar
WIP.  
Brice Videau committed
32

33
34
35
36
37
38
39
40
41
42
43
44
// Precedence classes: least from most (taken from C)
// Needed to parentheses correctly
// 0 : OR
// 1 : AND
// 2 : EQUAL, NOT_EQUAL
// 3 : LESS, GREATER, LESS_OR_EQUAL, GREATER_OR_EQUAL
// 4 : IN
// 5 : ADD, SUBSTRACT
// 6 : MULTIPLY, DIVIDE, MODULO
// 7 : POSITIVE, NEGATIVE, NOT
// max - 1: LIST
// max : LITERAL, VARIABLE, HYPERPARAMETER
Brice Videau's avatar
Brice Videau committed
45

46
47
// One for each expression type:
extern const int ccs_expression_precedence[];
Brice Videau's avatar
Brice Videau committed
48

49
extern const char *ccs_expression_symbols[];
Brice Videau's avatar
Brice Videau committed
50

51
52
53
extern const int ccs_expression_arity[];

// Expressions
Brice Videau's avatar
Brice Videau committed
54
extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
55
ccs_create_binary_expression(ccs_expression_type_t  type,
56
57
58
                             ccs_datum_t            node_left,
                             ccs_datum_t            node_right,
                             ccs_expression_t      *expression_ret);
Brice Videau's avatar
Brice Videau committed
59
60

extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
61
ccs_create_unary_expression(ccs_expression_type_t  type,
62
63
                            ccs_datum_t            node,
                            ccs_expression_t      *expression_ret);
Brice Videau's avatar
Brice Videau committed
64
65

extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
66
ccs_create_expression(ccs_expression_type_t  type,
Brice Videau's avatar
Brice Videau committed
67
68
69
	              size_t                 num_nodes,
                      ccs_datum_t           *nodes,
                      ccs_expression_t      *expression_ret);
Brice Videau's avatar
Brice Videau committed
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
extern ccs_error_t
ccs_expression_get_type(ccs_expression_t       expression,
                        ccs_expression_type_t *type_ret);

extern ccs_error_t
ccs_expression_get_num_nodes(ccs_expression_t  expression,
                             size_t           *num_nodes_ret);

extern ccs_error_t
ccs_expression_get_nodes(ccs_expression_t  expression,
                         size_t            num_nodes,
                         ccs_datum_t      *nodes,
                         size_t           *num_nodes_ret);

Brice Videau's avatar
Brice Videau committed
85
extern ccs_error_t
Brice Videau's avatar
Brice Videau committed
86
ccs_expression_eval(ccs_expression_t           expression,
87
88
89
                    ccs_configuration_space_t  context,
                    ccs_datum_t               *values,
                    ccs_datum_t               *result);
Brice Videau's avatar
Brice Videau committed
90

91
92
93
94
95
96
97
extern ccs_error_t
ccs_expression_list_eval_node(ccs_expression_t           expression,
                              ccs_configuration_space_t  context,
                              ccs_datum_t               *values,
                              size_t                     index,
                              ccs_datum_t               *result);

98
99
100
101
102
extern ccs_error_t
ccs_expression_get_hyperparameters(ccs_expression_t      expression,
                                   size_t                num_hyperparameters,
                                   ccs_hyperparameter_t *hyperparameters,
                                   size_t               *num_hyperparameters_ret);
103
104
105
106

extern ccs_error_t
ccs_expression_check_context(ccs_expression_t          expression,
                             ccs_configuration_space_t context);
Brice Videau's avatar
Brice Videau committed
107
108
109
110
#ifdef __cplusplus
}
#endif

Brice Videau's avatar
Brice Videau committed
111
#endif //_CCS_CONDITION_H