build: make the "rpm" rule work once again
[iwhd.git] / query.h
blob523dd91739defe489c542ab510b7c33a3ba1c108
1 /* Copyright (C) 2010 Red Hat, Inc.
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 3 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 #ifndef _QUERY_H
17 #define _QUERY_H 1
19 #if defined(__CPLUSPLUS__) || defined(__cplusplus)
20 extern "C" {
21 #endif
23 #include "iwhd-qparser.h"
26 * Comparisons are all the same type to the parser, but when it comes to
27 * evaluation we need to know the difference so we use these subtypes.
29 typedef enum {
30 C_LESSTHAN, C_LESSOREQ,
31 C_EQUAL, C_DIFFERENT,
32 C_GREATEROREQ, C_GREATERTHAN
33 } comp_t;
35 /* The actual values are generated by the parser. */
36 typedef enum yytokentype type_t;
39 * Universal AST object. T_NUMBER uses as_num, and some day T_DATE might as
40 * well. Several types (T_STRING, T_ID, T_*FIELD) all use as_str. The rest
41 * use as_tree, but there's a caveat. In most cases as_tree.right really is
42 * a value_t, but for T_LINK it's a bare string.
43 * TBD: use a separate as_link union member for T_LINK.
45 typedef struct value_t {
46 type_t type;
47 union {
48 long long as_num;
49 char *as_str;
50 struct {
51 comp_t op;
52 struct value_t *left;
53 struct value_t *right;
54 } as_tree;
56 const char *resolved; /* saved result for T_OFIELD/T_SFIELD/T_LINK */
57 } value_t;
60 * In a higher-level language, this would be a method pointer. It's just
61 * a pointer to a function plus a little piece of the caller's context (in
62 * the replication-policy case it's the current bucket and key) so that we
63 * can do concurrent evaluations with separate contexts.
65 typedef struct {
66 const char *(*func) (void *, const char *);
67 void *ctx;
68 } getter_t;
69 #define CALL_GETTER(g,x) g->func(g->ctx,x)
72 * In the normal case a caller would invoke parse once, eval multiple times,
73 * and free_value once. print_value is just for debugging/testing.
74 * TBD: make parse reentrant (eval already is, free_value doesn't need to be.
75 * Unfortunately, a quick scan of generated code and information on the web
76 * seems to indicate that even a "reentrant" bison parser only encapsulates
77 * user state and still relies quite a bit on internal globals. That might
78 * mean that we just have to put a lock around it instead.
80 int eval (const value_t *expr,
81 const getter_t *oget, const getter_t *sget);
82 void free_value (value_t *);
83 void print_value (const value_t *);
85 value_t *parse (const char *text);
87 #if defined(__CPLUSPLUS__) || defined(__cplusplus)
89 #endif
91 #endif