SeExpr

ExprFuncStandard.h
Go to the documentation of this file.
1 /*
2 Copyright Disney Enterprises, Inc. All rights reserved.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License
6 and the following modification to it: Section 6 Trademarks.
7 deleted and replaced with:
8
9 6. Trademarks. This License does not grant permission to use the
10 trade names, trademarks, service marks, or product names of the
11 Licensor and its affiliates, except as required for reproducing
12 the content of the NOTICE file.
13
14 You may obtain a copy of the License at
15 http://www.apache.org/licenses/LICENSE-2.0
16 */
17 #ifndef _ExprFuncStandard_h_
18 #define _ExprFuncStandard_h_
19
20 #include "Vec.h"
21 #include "ExprFuncX.h"
22
23 namespace SeExpr2 {
24
25 class ExprFuncStandard : public ExprFuncX {
26 public:
27 enum FuncType {
28 NONE = 0,
29 // scalar args and result
30 FUNC0,
31 FUNC1,
32 FUNC2,
33 FUNC3,
34 FUNC4,
35 FUNC5,
36 FUNC6,
37 FUNCN,
38 // vector args, scalar result
39 VEC,
40 FUNC1V = VEC,
41 FUNC2V,
42 FUNCNV,
43 // vector args and result
44 VECVEC,
45 FUNC1VV = VECVEC,
46 FUNC2VV,
47 FUNCNVV
48 };
49
50 typedef double Func0();
51 typedef double Func1(double);
52 typedef double Func2(double, double);
53 typedef double Func3(double, double, double);
54 typedef double Func4(double, double, double, double);
55 typedef double Func5(double, double, double, double, double);
56 typedef double Func6(double, double, double, double, double, double);
57 typedef double Func1v(const Vec3d&);
58 typedef double Func2v(const Vec3d&, const Vec3d&);
59 typedef Vec3d Func1vv(const Vec3d&);
60 typedef Vec3d Func2vv(const Vec3d&, const Vec3d&);
61 typedef double Funcn(int n, double* params);
62 typedef double Funcnv(int n, const Vec3d* params);
63 typedef Vec3d Funcnvv(int n, const Vec3d* params);
64
65 #if 0
66 Func0* func0() const { return (Func0*)_func; }
67 Func1* func1() const { return (Func1*)_func; }
68 Func2* func2() const { return (Func2*)_func; }
69 Func3* func3() const { return (Func3*)_func; }
70 Func4* func4() const { return (Func4*)_func; }
71 Func5* func5() const { return (Func5*)_func; }
72 Func6* func6() const { return (Func6*)_func; }
73 Func1v* func1v() const { return (Func1v*)_func; }
74 Func2v* func2v() const { return (Func2v*)_func; }
75 Func1vv* func1vv() const { return (Func1vv*)_func; }
76 Func2vv* func2vv() const { return (Func2vv*)_func; }
77 Funcn* funcn() const { return (Funcn*)_func; }
78 Funcnv* funcnv() const { return (Funcnv*)_func; }
79 Funcnvv* funcnvv() const { return (Funcnvv*)_func; }
80 #endif
81
83 ExprFuncStandard(FuncType funcType, void* f) : ExprFuncX(true), _funcType(funcType), _func(f) {}
84 #if 0
85 ExprFunc(Func1* f)
87 : _type(FUNC1), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(1), _maxargs(1)
88 {};
90 ExprFunc(Func2* f)
91 : _type(FUNC2), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(2), _maxargs(2)
92 {};
94 ExprFunc(Func3* f)
95 : _type(FUNC3), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(3), _maxargs(3)
96 {};
98 ExprFunc(Func4* f)
99 : _type(FUNC4), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(4), _maxargs(4)
100 {};
102 ExprFunc(Func5* f)
103 : _type(FUNC5), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(5), _maxargs(5)
104 {};
106 ExprFunc(Func6* f)
107 : _type(FUNC6), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(6), _maxargs(6)
108 {};
110 ExprFunc(Func1v* f)
111 : _type(FUNC1V), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(1), _maxargs(1)
112 {};
114 ExprFunc(Func2v* f)
115 : _type(FUNC2V), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(2), _maxargs(2)
116 {};
118 ExprFunc(Func1vv* f)
119 : _type(FUNC1VV), _retType(ExprType().FP(3).Varying()), _scalar(false), _func((void*)f), _minargs(1), _maxargs(1)
120 {};
122 ExprFunc(Func2vv* f)
123 : _type(FUNC2VV), _retType(ExprType().FP(3).Varying()), _scalar(false), _func((void*)f), _minargs(2), _maxargs(2)
124 {};
126 ExprFunc(Funcn* f, int min, int max)
127 : _type(FUNCN), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(min), _maxargs(max)
128 {};
130 ExprFunc(Funcnv* f, int min, int max)
131 : _type(FUNCNV), _retType(ExprType().FP(1).Varying()), _scalar(true), _func((void*)f), _minargs(min), _maxargs(max)
132 {};
134 ExprFunc(Funcnvv* f, int min, int max)
135 : _type(FUNCNVV), _retType(ExprType().FP(3).Varying()), _scalar(false), _func((void*)f), _minargs(min), _maxargs(max)
136 {};
137 #endif
138
139 public:
140 ExprFuncStandard() : ExprFuncX(true) {}
141
142 virtual ExprType prep(ExprFuncNode* node, bool scalarWanted, ExprVarEnvBuilder& envBuilder) const;
143 virtual int buildInterpreter(const ExprFuncNode* node, Interpreter* interpreter) const;
144 void* getFuncPointer() const { return _func; }
145 FuncType getFuncType() const { return _funcType; }
146
147 private:
148 FuncType _funcType;
149 void* _func; // blind func style
150 };
151 }
152
153 #endif
SeExpr2::ExprFuncStandard::FUNC6
Definition: ExprFuncStandard.h:36
SeExpr2::ExprFuncStandard::prep
virtual ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &envBuilder) const
Definition: ExprFuncStandard.cpp:23
SeExpr2::ExprFuncStandard::FUNCNV
Definition: ExprFuncStandard.h:42
f
with numParticles numAttributes A variable block contains variable names and types but doesn t care what the values are< pre > void f(const std::string &s, MyParticleData *p, int outputDim=3)
Definition: varblocks.txt:35
SeExpr2::ExprFuncStandard::FUNC5
Definition: ExprFuncStandard.h:35
SeExpr2::ExprFuncStandard::Func2
double Func2(double, double)
Definition: ExprFuncStandard.h:52
SeExpr2::Vec< double, 3, false >
SeExpr2::ExprFuncStandard::Func0
double Func0()
Definition: ExprFuncStandard.h:50
SeExpr2::ExprFuncStandard::NONE
Definition: ExprFuncStandard.h:28
SeExpr2::ExprFuncStandard::getFuncType
FuncType getFuncType() const
Definition: ExprFuncStandard.h:145
SeExpr2::ExprFuncStandard::FUNC2V
Definition: ExprFuncStandard.h:41
SeExpr2::ExprFuncStandard::FUNC1V
Definition: ExprFuncStandard.h:40
SeExpr2::ExprFuncX
Extension function spec, used for complicated argument custom functions.
Definition: ExprFuncX.h:35
SeExpr2::ExprType
Definition: ExprType.h:39
SeExpr2::ExprFuncNode
Node that calls a function.
Definition: ExprNode.h:517
SeExpr2::ExprFuncX::_type
ExprType _type
Definition: ExprFuncX.h:66
SeExpr2::ExprFunc
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:44
SeExpr2::ExprFuncStandard::FUNC3
Definition: ExprFuncStandard.h:33
SeExpr2::ExprFuncStandard::getFuncPointer
void * getFuncPointer() const
Definition: ExprFuncStandard.h:144
SeExpr2::ExprFuncStandard::Func2v
double Func2v(const Vec3d &, const Vec3d &)
Definition: ExprFuncStandard.h:58
SeExpr2::ExprFuncStandard::VECVEC
Definition: ExprFuncStandard.h:44
SeExpr2::ExprFuncStandard::Func3
double Func3(double, double, double)
Definition: ExprFuncStandard.h:53
SeExpr2::ExprFuncStandard::ExprFuncStandard
ExprFuncStandard()
Definition: ExprFuncStandard.h:140
SeExpr2::ExprFuncStandard::FuncType
FuncType
Definition: ExprFuncStandard.h:27
SeExpr2::ExprFuncStandard::Funcnvv
Vec3d Funcnvv(int n, const Vec3d *params)
Definition: ExprFuncStandard.h:63
SeExpr2::ExprFuncStandard::FUNC2VV
Definition: ExprFuncStandard.h:46
SeExpr2
Definition: Context.h:22
SeExpr2::ExprFuncStandard::Funcn
double Funcn(int n, double *params)
Definition: ExprFuncStandard.h:61
SeExpr2::ExprFuncStandard::Func1v
double Func1v(const Vec3d &)
Definition: ExprFuncStandard.h:57
SeExpr2::ExprFuncStandard::_func
void * _func
Definition: ExprFuncStandard.h:149
SeExpr2::ExprFuncStandard::Func4
double Func4(double, double, double, double)
Definition: ExprFuncStandard.h:54
SeExpr2::ExprFuncStandard::buildInterpreter
virtual int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const
Build an interpreter to evaluate the expression.
Definition: ExprFuncStandard.cpp:145
SeExpr2::ExprFuncStandard::Func1vv
Vec3d Func1vv(const Vec3d &)
Definition: ExprFuncStandard.h:59
Vec.h
SeExpr2::min
double min(double x, double y)
Definition: ExprBuiltins.h:43
SeExpr2::ExprFuncStandard::Func6
double Func6(double, double, double, double, double, double)
Definition: ExprFuncStandard.h:56
SeExpr2::ExprFuncStandard::FUNC0
Definition: ExprFuncStandard.h:30
SeExpr2::ExprFuncStandard::FUNCN
Definition: ExprFuncStandard.h:37
SeExpr2::ExprVarEnvBuilder
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
Definition: ExprEnv.h:148
ExprFuncX.h
SeExpr2::ExprFuncStandard::Funcnv
double Funcnv(int n, const Vec3d *params)
Definition: ExprFuncStandard.h:62
SeExpr2::max
double max(double x, double y)
Definition: ExprBuiltins.h:42
SeExpr2::ExprFuncStandard::FUNCNVV
Definition: ExprFuncStandard.h:47
SeExpr2::ExprFuncStandard::FUNC2
Definition: ExprFuncStandard.h:32
SeExpr2::ExprFuncStandard::Func2vv
Vec3d Func2vv(const Vec3d &, const Vec3d &)
Definition: ExprFuncStandard.h:60
SeExpr2::ExprFuncStandard::_funcType
FuncType _funcType
Definition: ExprFuncStandard.h:148
SeExpr2::ExprFuncStandard
Definition: ExprFuncStandard.h:25
SeExpr2::ExprFuncStandard::FUNC1
Definition: ExprFuncStandard.h:31
SeExpr2::Interpreter
Definition: Interpreter.h:40
SeExpr2::ExprFuncStandard::ExprFuncStandard
ExprFuncStandard(FuncType funcType, void *f)
No argument function.
Definition: ExprFuncStandard.h:83
SeExpr2::ExprFuncStandard::Func5
double Func5(double, double, double, double, double)
Definition: ExprFuncStandard.h:55
SeExpr2::ExprFuncStandard::Func1
double Func1(double)
Definition: ExprFuncStandard.h:51
SeExpr2::ExprFuncStandard::VEC
Definition: ExprFuncStandard.h:39
SeExpr2::ExprFuncStandard::FUNC1VV
Definition: ExprFuncStandard.h:45
SeExpr2::ExprFuncStandard::FUNC4
Definition: ExprFuncStandard.h:34