BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
2 * @file NCDEvaluator.h
3 * @author Ambroz Bizjak <ambrop7@gmail.com>
4 *
5 * @section LICENSE
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29  
30 #ifndef BADVPN_NCDEVALUATOR_H
31 #define BADVPN_NCDEVALUATOR_H
32  
33 #include <stddef.h>
34  
35 #include <misc/debug.h>
36 #include <structure/Vector.h>
37 #include <ncd/NCDAst.h>
38 #include <ncd/NCDStringIndex.h>
39 #include <ncd/NCDVal.h>
40  
41 struct NCDEvaluator__Expr {
42 NCDValMem mem;
43 NCDValSafeRef ref;
44 NCDValReplaceProg prog;
45 };
46  
47 struct NCDEvaluator__Var {
48 NCD_string_id_t *varnames;
49 size_t num_names;
50 };
51  
52 #include "NCDEvaluator_var_vec.h"
53 #include <structure/Vector_decl.h>
54  
55 struct NCDEvaluator__Call {
56 NCD_string_id_t func_name_id;
57 struct NCDEvaluator__Expr *args;
58 size_t num_args;
59 };
60  
61 #include "NCDEvaluator_call_vec.h"
62 #include <structure/Vector_decl.h>
63  
64 struct NCDEvaluator__eval_context;
65  
66 typedef struct {
67 NCDStringIndex *string_index;
68 NCDEvaluator__VarVec vars;
69 NCDEvaluator__CallVec calls;
70 } NCDEvaluator;
71  
72 typedef struct {
73 struct NCDEvaluator__Expr expr;
74 } NCDEvaluatorExpr;
75  
76 typedef struct {
77 struct NCDEvaluator__eval_context const *context;
78 int call_index;
79 } NCDEvaluatorArgs;
80  
81 typedef struct {
82 void *user;
83 int (*func_eval_var) (void *user, NCD_string_id_t const *varnames, size_t num_names, NCDValMem *mem, NCDValRef *out);
84 int (*func_eval_call) (void *user, NCD_string_id_t func_name_id, NCDEvaluatorArgs args, NCDValMem *mem, NCDValRef *out);
85 } NCDEvaluator_EvalFuncs;
86  
87 int NCDEvaluator_Init (NCDEvaluator *o, NCDStringIndex *string_index) WARN_UNUSED;
88 void NCDEvaluator_Free (NCDEvaluator *o);
89 int NCDEvaluatorExpr_Init (NCDEvaluatorExpr *o, NCDEvaluator *eval, NCDValue *value) WARN_UNUSED;
90 void NCDEvaluatorExpr_Free (NCDEvaluatorExpr *o);
91 int NCDEvaluatorExpr_Eval (NCDEvaluatorExpr *o, NCDEvaluator *eval, NCDEvaluator_EvalFuncs const *funcs, NCDValMem *out_newmem, NCDValRef *out_val) WARN_UNUSED;
92 size_t NCDEvaluatorArgs_Count (NCDEvaluatorArgs *o);
93 int NCDEvaluatorArgs_EvalArg (NCDEvaluatorArgs *o, size_t index, NCDValMem *mem, NCDValRef *out_ref) WARN_UNUSED;
94 int NCDEvaluatorArgs_EvalArgNewMem (NCDEvaluatorArgs *o, size_t index, NCDValMem *out_newmem, NCDValRef *out_ref) WARN_UNUSED;
95  
96 #endif