/[svn]/linuxsampler/trunk/src/scriptvm/tree.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/tree.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3581 by schoenebeck, Fri Aug 30 11:40:25 2019 UTC revision 3586 by schoenebeck, Fri Aug 30 18:59:21 2019 UTC
# Line 21  Line 21 
21  #include <map>  #include <map>
22  #include <set>  #include <set>
23  #include <string.h> // for memset()  #include <string.h> // for memset()
24    #include <assert.h>
25  #include "../common/global.h"  #include "../common/global.h"
26  #include "../common/Ref.h"  #include "../common/Ref.h"
27  #include "../common/ArrayList.h"  #include "../common/ArrayList.h"
# Line 40  enum StmtType_t { Line 41  enum StmtType_t {
41      STMT_NOOP,      STMT_NOOP,
42  };  };
43    
44    /**
45     * Convenience function used for retrieving the (assumed) data type of a given
46     * script variable name.
47     *
48     * @param name - some script variable name (e.g. "$foo")
49     * @return variable's assumed data type (e.g. INT_EXPR for example above)
50     */
51    inline ExprType_t exprTypeOfVarName(const String& name) {
52        if (name.empty()) return (ExprType_t) -1;
53        const char prefix = name[0];
54        switch (prefix) {
55            case '$': return INT_EXPR;
56            case '%': return INT_ARR_EXPR;
57            case '~': return REAL_EXPR;
58            case '?': return REAL_ARR_EXPR;
59            case '@': return STRING_EXPR;
60            case '!': return STRING_ARR_EXPR;
61        }
62        return (ExprType_t) -1;
63    }
64    
65    inline ExprType_t scalarTypeOfArray(ExprType_t arrayType) {
66        if (arrayType == INT_ARR_EXPR) return INT_EXPR;
67        if (arrayType == REAL_ARR_EXPR) return REAL_EXPR;
68        if (arrayType == STRING_ARR_EXPR) return STRING_EXPR;
69        assert(false);
70        return EMPTY_EXPR; // just to shut up the compiler
71    }
72    
73    /**
74     * Used by parser for parser error messages to provide a text with all data
75     * types accepted by the given built-in function @a fn for the respective
76     * function argument @a iArg.
77     */
78    String acceptedArgTypesStr(VMFunction* fn, vmint iArg);
79    
80  class Node {  class Node {
81  public:  public:
82      Node();      Node();
# Line 70  public: Line 107  public:
107  };  };
108  typedef Ref<Unit,Node> UnitRef;  typedef Ref<Unit,Node> UnitRef;
109    
110  class ScalarNumberExpr : virtual public Unit, virtual public VMScalarNumberExpr, virtual public Expression {  class NumberExpr : virtual public Unit, virtual public VMNumberExpr, virtual public Expression {
111  public:  public:
112  };  };
113  typedef Ref<ScalarNumberExpr,Node> ScalarNumberExprRef;  typedef Ref<NumberExpr,Node> NumberExprRef;
114    
115  class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {  class IntExpr : virtual public NumberExpr, virtual public VMIntExpr {
116  public:  public:
117      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
118      vmint evalIntToUnitFactor(vmfloat unitFactor);      vmint evalIntToUnitFactor(vmfloat unitFactor);
# Line 83  public: Line 120  public:
120  };  };
121  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
122    
123  class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {  class RealExpr : virtual public NumberExpr, virtual public VMRealExpr  {
124  public:  public:
125      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
126      vmfloat evalRealToUnitFactor(vmfloat unitFactor);      vmfloat evalRealToUnitFactor(vmfloat unitFactor);
# Line 209  protected: Line 246  protected:
246  };  };
247  typedef Ref<Variable,Node> VariableRef;  typedef Ref<Variable,Node> VariableRef;
248    
249  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {  class NumberVariable : public Variable, virtual public NumberExpr {
250      bool polyphonic;      bool polyphonic;
251      bool finalVal;      bool finalVal;
252  protected:  protected:
# Line 219  public: Line 256  public:
256      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
257      vmfloat unitFactor() const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
258  protected:  protected:
259      ScalarNumberVariable(const VariableDecl& decl);      NumberVariable(const VariableDecl& decl);
260  };  };
261  typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;  typedef Ref<NumberVariable,Node> NumberVariableRef;
262    
263  class IntVariable : public ScalarNumberVariable, virtual public IntExpr {  class IntVariable : public NumberVariable, virtual public IntExpr {
264  public:  public:
265      IntVariable(const VariableDecl& decl);      IntVariable(const VariableDecl& decl);
266      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
# Line 232  public: Line 269  public:
269  };  };
270  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
271    
272  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {  class RealVariable : public NumberVariable, virtual public RealExpr {
273  public:  public:
274      RealVariable(const VariableDecl& decl);      RealVariable(const VariableDecl& decl);
275      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
# Line 436  public: Line 473  public:
473  };  };
474  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
475    
476  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {  class NumberBinaryOp : public BinaryOp, virtual public NumberExpr {
477  public:  public:
478      ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : BinaryOp(lhs, rhs) { }      NumberBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : BinaryOp(lhs, rhs) { }
479      bool isFinal() const OVERRIDE;      bool isFinal() const OVERRIDE;
480  };  };
481  typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;  typedef Ref<NumberBinaryOp,Node> NumberBinaryOpRef;
482    
483  class IntBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr {  class IntBinaryOp : public NumberBinaryOp, virtual public IntExpr {
484  public:  public:
485      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
486  };  };
487  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
488    
489  class VaritypeScalarBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr, virtual public RealExpr {  class VaritypeScalarBinaryOp : public NumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
490  public:  public:
491      VaritypeScalarBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      VaritypeScalarBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
492      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
493      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
494  };  };
# Line 459  typedef Ref<VaritypeScalarBinaryOp,Node> Line 496  typedef Ref<VaritypeScalarBinaryOp,Node>
496    
497  class Add FINAL : public VaritypeScalarBinaryOp {  class Add FINAL : public VaritypeScalarBinaryOp {
498  public:  public:
499      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);      Add(NumberExprRef lhs, NumberExprRef rhs);
500      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
501      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
502      vmfloat unitFactor() const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
# Line 469  typedef Ref<Add,Node> AddRef; Line 506  typedef Ref<Add,Node> AddRef;
506    
507  class Sub FINAL : public VaritypeScalarBinaryOp {  class Sub FINAL : public VaritypeScalarBinaryOp {
508  public:  public:
509      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);      Sub(NumberExprRef lhs, NumberExprRef rhs);
510      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
511      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
512      vmfloat unitFactor() const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
# Line 479  typedef Ref<Sub,Node> SubRef; Line 516  typedef Ref<Sub,Node> SubRef;
516    
517  class Mul FINAL : public VaritypeScalarBinaryOp {  class Mul FINAL : public VaritypeScalarBinaryOp {
518  public:  public:
519      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);      Mul(NumberExprRef lhs, NumberExprRef rhs);
520      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
521      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
522      vmfloat unitFactor() const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
# Line 489  typedef Ref<Mul,Node> MulRef; Line 526  typedef Ref<Mul,Node> MulRef;
526    
527  class Div FINAL : public VaritypeScalarBinaryOp {  class Div FINAL : public VaritypeScalarBinaryOp {
528  public:  public:
529      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);      Div(NumberExprRef lhs, NumberExprRef rhs);
530      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
531      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
532      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
# Line 737  public: Line 774  public:
774  typedef Ref<SyncBlock,Node> SyncBlockRef;  typedef Ref<SyncBlock,Node> SyncBlockRef;
775    
776  class Neg FINAL : virtual public IntExpr, virtual public RealExpr {  class Neg FINAL : virtual public IntExpr, virtual public RealExpr {
777      ScalarNumberExprRef expr;      NumberExprRef expr;
778  public:  public:
779      Neg(ScalarNumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }      Neg(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }
780      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
781      vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }      vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }
782      vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }      vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }
# Line 851  public: Line 888  public:
888  typedef Ref<BitwiseNot,Node> BitwiseNotRef;  typedef Ref<BitwiseNot,Node> BitwiseNotRef;
889    
890  class Final FINAL : virtual public IntExpr, virtual public RealExpr {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
891      ScalarNumberExprRef expr;      NumberExprRef expr;
892  public:  public:
893      Final(ScalarNumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}      Final(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
894      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
895      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
896      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }

Legend:
Removed from v.3581  
changed lines
  Added in v.3586

  ViewVC Help
Powered by ViewVC