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
38  // vector args, scalar result
39  VEC,
43  // vector args and result
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:
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:
149  void* _func; // blind func style
150 };
151 }
152 
153 #endif
double Func2v(const Vec3d &, const Vec3d &)
double Func3(double, double, double)
double Func1v(const Vec3d &)
Function Definition, used in parse tree and func table.
Definition: ExprFunc.h:44
double Funcnv(int n, const Vec3d *params)
Vec3d Funcnvv(int n, const Vec3d *params)
void * getFuncPointer() const
Vec3d Func1vv(const Vec3d &)
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
double Func6(double, double, double, double, double, double)
Vec3d Func2vv(const Vec3d &, const Vec3d &)
double max(double x, double y)
Definition: ExprBuiltins.h:42
Node that calls a function.
Definition: ExprNode.h:514
double min(double x, double y)
Definition: ExprBuiltins.h:43
virtual int buildInterpreter(const ExprFuncNode *node, Interpreter *interpreter) const
Build an interpreter to evaluate the expression.
double Funcn(int n, double *params)
ExprType _type
Definition: ExprFuncX.h:66
ExprFuncStandard(FuncType funcType, void *f)
No argument function.
double Func5(double, double, double, double, double)
virtual ExprType prep(ExprFuncNode *node, bool scalarWanted, ExprVarEnvBuilder &envBuilder) const
double Func4(double, double, double, double)
Extension function spec, used for complicated argument custom functions.
Definition: ExprFuncX.h:35
FuncType getFuncType() const
double Func2(double, double)
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
Definition: ExprEnv.h:152