KSeExpr  4.0.4.0
ExprFuncStandard.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2 // SPDX-License-Identifier: LicenseRef-Apache-2.0
3 // SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
6 #pragma once
7 
8 #include "ExprFuncX.h"
9 #include "Vec.h"
10 
11 
12 namespace KSeExpr
13 {
15 {
16 public:
17  enum FuncType {
18  NONE = 0,
19  // scalar args and result
28  // vector args, scalar result
29  VEC,
33  // vector args and result
37  FUNCNVV
38  };
39 
40  using Func0 = double();
41  using Func1 = double(double);
42  using Func2 = double(double, double);
43  using Func3 = double(double, double, double);
44  using Func4 = double(double, double, double, double);
45  using Func5 = double(double, double, double, double, double);
46  using Func6 = double(double, double, double, double, double, double);
47  using Func1v = double(const Vec3d &);
48  using Func2v = double(const Vec3d &, const Vec3d &);
49  using Func1vv = Vec3d(const Vec3d &);
50  using Func2vv = Vec3d(const Vec3d &, const Vec3d &);
51  using Funcn = double(int, double *);
52  using Funcnv = double(int, const Vec3d *);
53  using Funcnvv = Vec3d(int, const Vec3d *);
54 
55 #if 0
56  Func0* func0() const { return (Func0*)_func; }
57  Func1* func1() const { return (Func1*)_func; }
58  Func2* func2() const { return (Func2*)_func; }
59  Func3* func3() const { return (Func3*)_func; }
60  Func4* func4() const { return (Func4*)_func; }
61  Func5* func5() const { return (Func5*)_func; }
62  Func6* func6() const { return (Func6*)_func; }
63  Func1v* func1v() const { return (Func1v*)_func; }
64  Func2v* func2v() const { return (Func2v*)_func; }
65  Func1vv* func1vv() const { return (Func1vv*)_func; }
66  Func2vv* func2vv() const { return (Func2vv*)_func; }
67  Funcn* funcn() const { return (Funcn*)_func; }
68  Funcnv* funcnv() const { return (Funcnv*)_func; }
69  Funcnvv* funcnvv() const { return (Funcnvv*)_func; }
70 #endif
71 
73  ExprFuncStandard(FuncType funcType, void *f)
74  : ExprFuncX(true)
75  , _funcType(funcType)
76  , _func(f)
77  {
78  }
79 #if 0
81  ExprFunc(Func1* f)
82  : _type(FUNC1), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(1), _maxargs(1)
83  {};
85  ExprFunc(Func2* f)
86  : _type(FUNC2), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(2), _maxargs(2)
87  {};
89  ExprFunc(Func3* f)
90  : _type(FUNC3), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(3), _maxargs(3)
91  {};
93  ExprFunc(Func4* f)
94  : _type(FUNC4), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(4), _maxargs(4)
95  {};
97  ExprFunc(Func5* f)
98  : _type(FUNC5), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(5), _maxargs(5)
99  {};
101  ExprFunc(Func6* f)
102  : _type(FUNC6), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(6), _maxargs(6)
103  {};
105  ExprFunc(Func1v* f)
106  : _type(FUNC1V), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(1), _maxargs(1)
107  {};
109  ExprFunc(Func2v* f)
110  : _type(FUNC2V), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(2), _maxargs(2)
111  {};
113  ExprFunc(Func1vv* f)
114  : _type(FUNC1VV), _retType(ExprType().FP(3).Varying()), _scalar(false), _func((void*)f), _minargs(1), _maxargs(1)
115  {};
117  ExprFunc(Func2vv* f)
118  : _type(FUNC2VV), _retType(ExprType().FP(3).Varying()), _scalar(false), _func((void*)f), _minargs(2), _maxargs(2)
119  {};
121  ExprFunc(Funcn* f, int min, int max)
122  : _type(FUNCN), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(min), _maxargs(max)
123  {};
125  ExprFunc(Funcnv* f, int min, int max)
126  : _type(FUNCNV), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(min), _maxargs(max)
127  {};
129  ExprFunc(Funcnvv* f, int min, int max)
130  : _type(FUNCNVV), _retType(ExprType().FP(3).Varying()), _scalar(false), _func((void*)f), _minargs(min), _maxargs(max)
131  {};
132 #endif
133 
134 public:
136  : ExprFuncX(true)
137  {
138  }
139 
140  ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &envBuilder) const override;
141  int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const override;
142  void *getFuncPointer() const
143  {
144  return _func;
145  }
147  {
148  return _funcType;
149  }
150 
151 private:
153  void *_func {nullptr}; // blind func style
154 };
155 } // namespace KSeExpr
Node that calls a function.
Definition: ExprNode.h:654
double(double, double, double, double) Func4
Vec3d(int, const Vec3d *) Funcnvv
double(int, double *) Funcn
ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &envBuilder) const override
int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const override
Build an interpreter to evaluate the expression.
ExprFuncStandard(FuncType funcType, void *f)
No argument function.
FuncType getFuncType() const
double(const Vec3d &) Func1v
double(const Vec3d &, const Vec3d &) Func2v
double(double, double, double, double, double, double) Func6
double(double, double, double) Func3
Vec3d(const Vec3d &) Func1vv
double(int, const Vec3d *) Funcnv
double(double, double, double, double, double) Func5
Vec3d(const Vec3d &, const Vec3d &) Func2vv
double(double, double) Func2
Extension function spec, used for complicated argument custom functions.
Definition: ExprFuncX.h:23
ExprType _type
Definition: ExprFuncX.h:58
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:35
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
Definition: ExprEnv.h:181
double max(double x, double y)
Definition: ExprBuiltins.h:74
double min(double x, double y)
Definition: ExprBuiltins.h:78
Vec< double, 3, false > Vec3d
Definition: Vec.h:352