/[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 3561 by schoenebeck, Fri Aug 23 11:44:00 2019 UTC revision 3583 by schoenebeck, Fri Aug 30 12:39:18 2019 UTC
# Line 40  enum StmtType_t { Line 40  enum StmtType_t {
40      STMT_NOOP,      STMT_NOOP,
41  };  };
42    
43    /**
44     * Convenience function used for retrieving the (assumed) data type of a given
45     * script variable name.
46     *
47     * @param name - some script variable name (e.g. "$foo")
48     * @return variable's assumed data type (e.g. INT_EXPR for example above)
49     */
50    inline ExprType_t exprTypeOfVarName(const String& name) {
51        if (name.empty()) return (ExprType_t) -1;
52        const char prefix = name[0];
53        switch (prefix) {
54            case '$': return INT_EXPR;
55            case '%': return INT_ARR_EXPR;
56            case '~': return REAL_EXPR;
57            case '?': return REAL_ARR_EXPR;
58            case '@': return STRING_EXPR;
59            case '!': return STRING_ARR_EXPR;
60        }
61        return (ExprType_t) -1;
62    }
63    
64  class Node {  class Node {
65  public:  public:
66      Node();      Node();
# Line 58  public: Line 79  public:
79  };  };
80  typedef Ref<Expression,Node> ExpressionRef;  typedef Ref<Expression,Node> ExpressionRef;
81    
82  class IntExpr : virtual public VMIntExpr, virtual public Expression {  class Unit : virtual public VMUnit, virtual public Node {
83        StdUnit_t unit;
84    public:
85        Unit(StdUnit_t type) : unit(type) {}
86        StdUnit_t unitType() const OVERRIDE { return unit; }
87        static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit);
88        static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor);
89        static vmfloat convRealToUnitFactor(vmfloat fValue, VMUnit* srcUnit, VMUnit* dstUnit);
90        static vmfloat convRealToUnitFactor(vmfloat fValue, vmfloat srcFactor, vmfloat dstFactor);
91    };
92    typedef Ref<Unit,Node> UnitRef;
93    
94    class NumberExpr : virtual public Unit, virtual public VMNumberExpr, virtual public Expression {
95    public:
96    };
97    typedef Ref<NumberExpr,Node> NumberExprRef;
98    
99    class IntExpr : virtual public NumberExpr, virtual public VMIntExpr {
100  public:  public:
101      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
102        vmint evalIntToUnitFactor(vmfloat unitFactor);
103      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
104  };  };
105  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
106    
107  class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression {  class RealExpr : virtual public NumberExpr, virtual public VMRealExpr  {
108    public:
109        ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
110        vmfloat evalRealToUnitFactor(vmfloat unitFactor);
111        String evalCastToStr() OVERRIDE;
112    };
113    typedef Ref<RealExpr,Node> RealExprRef;
114    
115    class ArrayExpr : virtual public VMArrayExpr, virtual public Expression {
116    public:
117    };
118    typedef Ref<ArrayExpr,Node> ArrayExprRef;
119    
120    class IntArrayExpr : virtual public VMIntArrayExpr, virtual public ArrayExpr {
121  public:  public:
122      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
123      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
124  };  };
125  typedef Ref<IntArrayExpr,Node> IntArrayExprRef;  typedef Ref<IntArrayExpr,Node> IntArrayExprRef;
126    
127    class RealArrayExpr : virtual public VMRealArrayExpr, virtual public ArrayExpr {
128    public:
129        ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
130        String evalCastToStr() OVERRIDE;
131    };
132    typedef Ref<RealArrayExpr,Node> RealArrayExprRef;
133    
134  class StringExpr : virtual public VMStringExpr, virtual public Expression {  class StringExpr : virtual public VMStringExpr, virtual public Expression {
135  public:  public:
136      ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }      ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }
# Line 79  public: Line 138  public:
138  };  };
139  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
140    
141  class Unit : virtual public VMUnit {  struct IntLitDef {
142      ArrayList<MetricPrefix_t> prefix;      vmint value; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression.
143      StdUnit_t unit;      vmfloat unitFactor = VM_NO_FACTOR;
144  public:      StdUnit_t unitType = VM_NO_UNIT;
145      Unit() : unit(VM_NO_UNIT) {}      bool isFinal;
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE { return unit; }  
     void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type);  
     void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type);  
     void copyUnitFrom(const IntExprRef& src);  
146  };  };
147    
148  class IntLiteral : public Unit, virtual public IntExpr {  class IntLiteral FINAL : public IntExpr {
149      bool finalVal;      bool finalVal;
150  public:      vmfloat unitPrefixFactor;
151      vmint value;      vmint value;
152      IntLiteral(vmint value) : Unit(),  public:
153          value(value), finalVal(false) { }      IntLiteral(const IntLitDef& def);
154      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
155        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
156      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
157      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
158      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
159      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
160  };  };
161  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
162    
163  class StringLiteral : virtual public StringExpr {  struct RealLitDef {
164        vmfloat value; //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression.
165        vmfloat unitFactor = VM_NO_FACTOR;
166        StdUnit_t unitType = VM_NO_UNIT;
167        bool isFinal;
168    };
169    
170    class RealLiteral FINAL : public RealExpr {
171        bool finalVal;
172        vmfloat unitPrefixFactor;
173        vmfloat value;
174  public:  public:
175        RealLiteral(const RealLitDef& def);
176        vmfloat evalReal() OVERRIDE;
177        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
178        void dump(int level = 0) OVERRIDE;
179        bool isConstExpr() const OVERRIDE { return true; }
180        bool isPolyphonic() const OVERRIDE { return false; }
181        bool isFinal() const OVERRIDE { return finalVal; }
182    };
183    typedef Ref<RealLiteral,Node> RealLiteralRef;
184    
185    class StringLiteral FINAL : public StringExpr {
186      String value;      String value;
187    public:
188      StringLiteral(const String& value) : value(value) { }      StringLiteral(const String& value) : value(value) { }
189      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
190      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
# Line 117  public: Line 193  public:
193  };  };
194  typedef Ref<StringLiteral,Node> StringLiteralRef;  typedef Ref<StringLiteral,Node> StringLiteralRef;
195    
196  class Args : virtual public VMFnArgs, virtual public Node {  class Args FINAL : virtual public VMFnArgs, virtual public Node {
197  public:  public:
198      std::vector<ExpressionRef> args;      std::vector<ExpressionRef> args;
199      void add(ExpressionRef arg) { args.push_back(arg); }      void add(ExpressionRef arg) { args.push_back(arg); }
# Line 128  public: Line 204  public:
204  };  };
205  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
206    
207    struct VariableDecl {
208        ParserContext* ctx;
209        bool isPolyphonic;
210        bool isConst;
211        bool isFinal;
212        vmint elements = 1;
213        vmint memPos;
214        vmint unitFactorMemPos;
215        StdUnit_t unitType = VM_NO_UNIT;
216    };
217    
218  class Variable : virtual public VMVariable, virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
219  public:  public:
220      bool isConstExpr() const OVERRIDE { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
# Line 135  public: Line 222  public:
222      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
223      void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }      void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }
224  protected:  protected:
225      Variable(ParserContext* ctx, vmint _memPos, bool _bConst)      Variable(const VariableDecl& decl);
         : context(ctx), memPos(_memPos), bConst(_bConst) {}  
226    
227      ParserContext* context;      ParserContext* context;
228      vmint memPos;      vmint memPos;
# Line 144  protected: Line 230  protected:
230  };  };
231  typedef Ref<Variable,Node> VariableRef;  typedef Ref<Variable,Node> VariableRef;
232    
233  class IntVariable : public Variable, public Unit, virtual public IntExpr {  class NumberVariable : public Variable, virtual public NumberExpr {
234      bool polyphonic;      bool polyphonic;
235      bool finalVal;      bool finalVal;
236    protected:
237        vmint unitFactorMemPos;
238  public:  public:
     IntVariable(ParserContext* ctx);  
     void assign(Expression* expr) OVERRIDE;  
     vmint evalInt() OVERRIDE;  
     void dump(int level = 0) OVERRIDE;  
239      bool isPolyphonic() const OVERRIDE { return polyphonic; }      bool isPolyphonic() const OVERRIDE { return polyphonic; }
240      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
241      void setFinal(bool b = true) { finalVal = b; }      vmfloat unitFactor() const OVERRIDE;
242  protected:  protected:
243      IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);      NumberVariable(const VariableDecl& decl);
244    };
245    typedef Ref<NumberVariable,Node> NumberVariableRef;
246    
247    class IntVariable : public NumberVariable, virtual public IntExpr {
248    public:
249        IntVariable(const VariableDecl& decl);
250        void assign(Expression* expr) OVERRIDE;
251        vmint evalInt() OVERRIDE;
252        void dump(int level = 0) OVERRIDE;
253  };  };
254  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
255    
256  class ConstIntVariable : public IntVariable {  class RealVariable : public NumberVariable, virtual public RealExpr {
257  public:  public:
258      vmint value;      RealVariable(const VariableDecl& decl);
259        void assign(Expression* expr) OVERRIDE;
260        vmfloat evalReal() OVERRIDE;
261        void dump(int level = 0) OVERRIDE;
262    };
263    typedef Ref<RealVariable,Node> RealVariableRef;
264    
265      ConstIntVariable(vmint value);  struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
266      //ConstIntVariable(ParserContext* ctx, int value = 0);      // copied from VariableDecl
267        ParserContext* ctx;
268        bool isPolyphonic;
269        bool isConst;
270        bool isFinal;
271        vmint elements = 1;
272        vmint memPos;
273        vmint unitFactorMemPos;
274        StdUnit_t unitType = VM_NO_UNIT;
275        // additions for RealVarDef
276        vmint value = 0; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression.
277        vmfloat unitFactor = VM_NO_FACTOR;
278    };
279    
280    class ConstIntVariable FINAL : public IntVariable {
281        vmfloat unitPrefixFactor;
282        vmint value;
283    public:
284        ConstIntVariable(const IntVarDef& def);
285      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
286      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
287        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
288      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
289  };  };
290  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
291    
292  class BuiltInIntVariable : public IntVariable {  struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
293        // copied from VariableDecl
294        ParserContext* ctx;
295        bool isPolyphonic;
296        bool isConst;
297        bool isFinal;
298        vmint elements = 1;
299        vmint memPos;
300        vmint unitFactorMemPos;
301        StdUnit_t unitType = VM_NO_UNIT;
302        // additions for RealVarDef
303        vmfloat value = vmfloat(0); //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression.
304        vmfloat unitFactor = VM_NO_FACTOR;
305    };
306    
307    class ConstRealVariable FINAL : public RealVariable {
308        vmfloat unitPrefixFactor;
309        vmfloat value;
310    public:
311        ConstRealVariable(const RealVarDef& def);
312        void assign(Expression* expr) OVERRIDE;
313        vmfloat evalReal() OVERRIDE;
314        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
315        void dump(int level = 0) OVERRIDE;
316    };
317    typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
318    
319    class BuiltInIntVariable FINAL : public IntVariable {
320      String name;      String name;
321      VMIntPtr* ptr;      VMIntPtr* ptr;
322  public:  public:
# Line 180  public: Line 324  public:
324      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }
325      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
326      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
327        vmfloat unitFactor() const OVERRIDE { return VM_NO_UNIT; }
328      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
329  };  };
330  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
331    
332  class PolyphonicIntVariable : public IntVariable {  class PolyphonicIntVariable FINAL : public IntVariable {
333  public:  public:
334      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(const VariableDecl& decl);
335      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
336  };  };
337  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
338    
339    class PolyphonicRealVariable FINAL : public RealVariable {
340    public:
341        PolyphonicRealVariable(const VariableDecl& decl);
342        void dump(int level = 0) OVERRIDE;
343    };
344    typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;
345    
346  class IntArrayVariable : public Variable, virtual public IntArrayExpr {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
347      ArrayList<vmint> values;      ArrayList<vmint> values;
348        ArrayList<vmfloat> unitFactors;
349  public:  public:
350      IntArrayVariable(ParserContext* ctx, vmint size);      IntArrayVariable(ParserContext* ctx, vmint size);
351      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
352      void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment      void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment
     String evalCastToStr() OVERRIDE { return ""; } // ignore scalar cast to string  
353      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
354      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
355      virtual vmint evalIntElement(vmuint i) OVERRIDE;      virtual vmint evalIntElement(vmuint i) OVERRIDE;
356      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;
357        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
358        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
359      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
360      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
361  protected:  protected:
# Line 209  protected: Line 363  protected:
363  };  };
364  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
365    
366  class BuiltInIntArrayVariable : public IntArrayVariable {  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
367        ArrayList<vmfloat> values;
368        ArrayList<vmfloat> unitFactors;
369    public:
370        RealArrayVariable(ParserContext* ctx, vmint size);
371        RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
372        void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment
373        ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
374        virtual vmint arraySize() const OVERRIDE { return values.size(); }
375        virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
376        virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;
377        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
378        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
379        void dump(int level = 0) OVERRIDE;
380        bool isPolyphonic() const OVERRIDE { return false; }
381    protected:
382        RealArrayVariable(ParserContext* ctx, bool bConst);
383    };
384    typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;
385    
386    class BuiltInIntArrayVariable FINAL : public IntArrayVariable {
387      String name;      String name;
388      VMInt8Array* array;      VMInt8Array* array;
389  public:  public:
390      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
391      vmint arraySize() const OVERRIDE { return array->size; }      vmint arraySize() const OVERRIDE { return array->size; }
392      vmint evalIntElement(vmuint i) OVERRIDE;      vmint evalIntElement(vmuint i) OVERRIDE;
     bool isAssignable() const OVERRIDE { return !array->readonly; }  
393      void assignIntElement(vmuint i, vmint value) OVERRIDE;      void assignIntElement(vmuint i, vmint value) OVERRIDE;
394        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
395        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
396        bool isAssignable() const OVERRIDE { return !array->readonly; }
397      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
398  };  };
399  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
400    
401  class IntArrayElement : public IntVariable {  class IntArrayElement FINAL : public IntVariable {
402      IntArrayExprRef array;      IntArrayExprRef array;
403      IntExprRef index;      IntExprRef index;
404        vmint currentIndex;
405  public:  public:
406      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
407      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
408      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
409        vmfloat unitFactor() const OVERRIDE;
410      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
411  };  };
412  typedef Ref<IntArrayElement,Node> IntArrayElementRef;  typedef Ref<IntArrayElement,Node> IntArrayElementRef;
413    
414    class RealArrayElement FINAL : public RealVariable {
415        RealArrayExprRef array;
416        IntExprRef index;
417        vmint currentIndex;
418    public:
419        RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
420        void assign(Expression* expr) OVERRIDE;
421        vmfloat evalReal() OVERRIDE;
422        vmfloat unitFactor() const OVERRIDE;
423        void dump(int level = 0) OVERRIDE;
424    };
425    typedef Ref<RealArrayElement,Node> RealArrayElementRef;
426    
427  class StringVariable : public Variable, virtual public StringExpr {  class StringVariable : public Variable, virtual public StringExpr {
428  public:  public:
429      StringVariable(ParserContext* ctx);      StringVariable(ParserContext* ctx);
# Line 245  protected: Line 436  protected:
436  };  };
437  typedef Ref<StringVariable,Node> StringVariableRef;  typedef Ref<StringVariable,Node> StringVariableRef;
438    
439  class ConstStringVariable : public StringVariable {  class ConstStringVariable FINAL : public StringVariable {
 public:  
440      String value;      String value;
441    public:
442      ConstStringVariable(ParserContext* ctx, String value = "");      ConstStringVariable(ParserContext* ctx, String value = "");
443      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
444      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
# Line 267  public: Line 457  public:
457  };  };
458  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
459    
460  class IntBinaryOp : public BinaryOp, virtual public IntExpr {  class NumberBinaryOp : public BinaryOp, virtual public NumberExpr {
461  public:  public:
462      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }      NumberBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : BinaryOp(lhs, rhs) { }
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
463      bool isFinal() const OVERRIDE;      bool isFinal() const OVERRIDE;
464  };  };
465    typedef Ref<NumberBinaryOp,Node> NumberBinaryOpRef;
466    
467    class IntBinaryOp : public NumberBinaryOp, virtual public IntExpr {
468    public:
469        IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
470    };
471  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
472    
473  class Add : public IntBinaryOp {  class VaritypeScalarBinaryOp : public NumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
474    public:
475        VaritypeScalarBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
476        ExprType_t exprType() const OVERRIDE;
477        String evalCastToStr() OVERRIDE;
478    };
479    typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;
480    
481    class Add FINAL : public VaritypeScalarBinaryOp {
482  public:  public:
483      Add(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Add(NumberExprRef lhs, NumberExprRef rhs);
484      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
485        vmfloat evalReal() OVERRIDE;
486        vmfloat unitFactor() const OVERRIDE;
487      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
488  };  };
489  typedef Ref<Add,Node> AddRef;  typedef Ref<Add,Node> AddRef;
490    
491  class Sub : public IntBinaryOp {  class Sub FINAL : public VaritypeScalarBinaryOp {
492  public:  public:
493      Sub(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Sub(NumberExprRef lhs, NumberExprRef rhs);
494      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
495        vmfloat evalReal() OVERRIDE;
496        vmfloat unitFactor() const OVERRIDE;
497      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
498  };  };
499  typedef Ref<Sub,Node> SubRef;  typedef Ref<Sub,Node> SubRef;
500    
501  class Mul : public IntBinaryOp {  class Mul FINAL : public VaritypeScalarBinaryOp {
502  public:  public:
503      Mul(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Mul(NumberExprRef lhs, NumberExprRef rhs);
504      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
505        vmfloat evalReal() OVERRIDE;
506        vmfloat unitFactor() const OVERRIDE;
507      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
508  };  };
509  typedef Ref<Mul,Node> MulRef;  typedef Ref<Mul,Node> MulRef;
510    
511  class Div : public IntBinaryOp {  class Div FINAL : public VaritypeScalarBinaryOp {
512  public:  public:
513      Div(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Div(NumberExprRef lhs, NumberExprRef rhs);
514      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
515        vmfloat evalReal() OVERRIDE;
516      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
517      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
     StdUnit_t unitType() const OVERRIDE;  
518  };  };
519  typedef Ref<Div,Node> DivRef;  typedef Ref<Div,Node> DivRef;
520    
521  class Mod : public IntBinaryOp {  class Mod FINAL : public IntBinaryOp {
522  public:  public:
523      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs), Unit(VM_NO_UNIT) { }
524      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
525        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
526      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
527  };  };
528  typedef Ref<Mod,Node> ModRef;  typedef Ref<Mod,Node> ModRef;
# Line 328  typedef Ref<Statement,Node> StatementRef Line 535  typedef Ref<Statement,Node> StatementRef
535    
536  // Just used by parser to avoid "not a statement" parser warning, will be  // Just used by parser to avoid "not a statement" parser warning, will be
537  // filtered out by parser. So it will not be part of the VM tree after parsing.  // filtered out by parser. So it will not be part of the VM tree after parsing.
538  class NoOperation : public Statement {  class NoOperation FINAL : public Statement {
539  public:  public:
540      NoOperation() : Statement() {}      NoOperation() : Statement() {}
541      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
# Line 364  public: Line 571  public:
571      virtual Statements* branch(vmuint i) const = 0;      virtual Statements* branch(vmuint i) const = 0;
572  };  };
573    
574  class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr {  class DynamicVariableCall FINAL : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr {
575      VMDynVar* dynVar;      VMDynVar* dynVar;
576      String varName;      String varName;
577  public:  public:
# Line 381  public: Line 588  public:
588      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
589      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
590      void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); }      void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); }
591        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
592        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
593      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
594      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
595      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
596  };  };
597  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
598    
599  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public RealExpr, virtual public StringExpr {
600      String functionName;      String functionName;
601      ArgsRef args;      ArgsRef args;
602      VMFunction* fn;      VMFunction* fn;
603        VMFnResult* result;
604  public:  public:
605      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn);
         functionName(function), args(args), fn(fn) { }  
606      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
607      StmtFlags_t exec() OVERRIDE;      StmtFlags_t exec() OVERRIDE;
608      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
609        vmfloat evalReal() OVERRIDE;
610      VMIntArrayExpr* asIntArray() const OVERRIDE;      VMIntArrayExpr* asIntArray() const OVERRIDE;
611        VMRealArrayExpr* asRealArray() const OVERRIDE;
612      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
613      bool isConstExpr() const OVERRIDE { return false; }      bool isConstExpr() const OVERRIDE { return false; }
614      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
615      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
616      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
617      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE;
618      StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }      bool isFinal() const OVERRIDE;
     bool isFinal() const OVERRIDE { return false; }  
619  protected:  protected:
620      VMFnResult* execVMFn();      VMFnResult* execVMFn();
621  };  };
622  typedef Ref<FunctionCall,Node> FunctionCallRef;  typedef Ref<FunctionCall,Node> FunctionCallRef;
623    
624  class NoFunctionCall : public FunctionCall {  class NoFunctionCall FINAL : public FunctionCall {
625  public:  public:
626      NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}      NoFunctionCall() : FunctionCall("nothing", new Args, NULL), Unit(VM_NO_UNIT) {}
627      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
628  };  };
629  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;
# Line 431  public: Line 640  public:
640  };  };
641  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
642    
643  class OnNote : public EventHandler {  class OnNote FINAL : public EventHandler {
644  public:  public:
645      OnNote(StatementsRef statements) : EventHandler(statements) {}      OnNote(StatementsRef statements) : EventHandler(statements) {}
646      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }
# Line 439  public: Line 648  public:
648  };  };
649  typedef Ref<OnNote,Node> OnNoteRef;  typedef Ref<OnNote,Node> OnNoteRef;
650    
651  class OnInit : public EventHandler {  class OnInit FINAL : public EventHandler {
652  public:  public:
653      OnInit(StatementsRef statements) : EventHandler(statements) {}      OnInit(StatementsRef statements) : EventHandler(statements) {}
654      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }
# Line 447  public: Line 656  public:
656  };  };
657  typedef Ref<OnInit,Node> OnInitRef;  typedef Ref<OnInit,Node> OnInitRef;
658    
659  class OnRelease : public EventHandler {  class OnRelease FINAL : public EventHandler {
660  public:  public:
661      OnRelease(StatementsRef statements) : EventHandler(statements) {}      OnRelease(StatementsRef statements) : EventHandler(statements) {}
662      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }
# Line 455  public: Line 664  public:
664  };  };
665  typedef Ref<OnRelease,Node> OnReleaseRef;  typedef Ref<OnRelease,Node> OnReleaseRef;
666    
667  class OnController : public EventHandler {  class OnController FINAL : public EventHandler {
668  public:  public:
669      OnController(StatementsRef statements) : EventHandler(statements) {}      OnController(StatementsRef statements) : EventHandler(statements) {}
670      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }
# Line 463  public: Line 672  public:
672  };  };
673  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
674    
675  class EventHandlers : virtual public Node {  class EventHandlers FINAL : virtual public Node {
676      std::vector<EventHandlerRef> args;      std::vector<EventHandlerRef> args;
677  public:  public:
678      EventHandlers();      EventHandlers();
# Line 477  public: Line 686  public:
686  };  };
687  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
688    
689  class Assignment : public LeafStatement {  class Assignment FINAL : public LeafStatement {
690  protected:  protected:
691      VariableRef variable;      VariableRef variable;
692      ExpressionRef value;      ExpressionRef value;
# Line 489  public: Line 698  public:
698  };  };
699  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
700    
701  class If : public BranchStatement {  class If FINAL : public BranchStatement {
702      IntExprRef condition;      IntExprRef condition;
703      StatementsRef ifStatements;      StatementsRef ifStatements;
704      StatementsRef elseStatements;      StatementsRef elseStatements;
# Line 505  public: Line 714  public:
714  };  };
715  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
716    
717  struct CaseBranch {  struct CaseBranch FINAL {
718      IntExprRef from;      IntExprRef from;
719      IntExprRef to;      IntExprRef to;
720      StatementsRef statements;      StatementsRef statements;
721  };  };
   
722  typedef std::vector<CaseBranch> CaseBranches;  typedef std::vector<CaseBranch> CaseBranches;
723    
724  class SelectCase : public BranchStatement {  class SelectCase FINAL : public BranchStatement {
725      IntExprRef select;      IntExprRef select;
726      CaseBranches branches;      CaseBranches branches;
727  public:  public:
# Line 521  public: Line 729  public:
729      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
730      vmint evalBranch() OVERRIDE;      vmint evalBranch() OVERRIDE;
731      Statements* branch(vmuint i) const OVERRIDE;      Statements* branch(vmuint i) const OVERRIDE;
     //void addBranch(IntExprRef condition, StatementsRef statements);  
     //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);  
     //void addBranch(CaseBranchRef branch);  
     //void addBranches(CaseBranchesRef branches);  
732      bool isPolyphonic() const OVERRIDE;      bool isPolyphonic() const OVERRIDE;
733  };  };
734  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
735    
736  class While : public Statement {  class While FINAL : public Statement {
737      IntExprRef m_condition;      IntExprRef m_condition;
738      StatementsRef m_statements;      StatementsRef m_statements;
739  public:  public:
# Line 542  public: Line 746  public:
746      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
747  };  };
748    
749  class SyncBlock : public Statement {  class SyncBlock FINAL : public Statement {
750      StatementsRef m_statements;      StatementsRef m_statements;
751  public:  public:
752      SyncBlock(StatementsRef statements) : m_statements(statements) {}      SyncBlock(StatementsRef statements) : m_statements(statements) {}
# Line 553  public: Line 757  public:
757  };  };
758  typedef Ref<SyncBlock,Node> SyncBlockRef;  typedef Ref<SyncBlock,Node> SyncBlockRef;
759    
760  class Neg : public IntExpr {  class Neg FINAL : virtual public IntExpr, virtual public RealExpr {
761      IntExprRef expr;      NumberExprRef expr;
762  public:  public:
763      Neg(IntExprRef expr) : expr(expr) { }      Neg(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }
764      vmint evalInt() OVERRIDE { return (expr) ? -expr->evalInt() : 0; }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
765        vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }
766        vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }
767        String evalCastToStr() OVERRIDE;
768      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
769      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
770      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
771      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); }      vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); }
     StdUnit_t unitType() const OVERRIDE { return expr->unitType(); }  
772      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
773  };  };
774  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
775    
776  class ConcatString : public StringExpr {  class ConcatString FINAL : public StringExpr {
777      ExpressionRef lhs;      ExpressionRef lhs;
778      ExpressionRef rhs;      ExpressionRef rhs;
779  public:  public:
# Line 579  public: Line 785  public:
785  };  };
786  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
787    
788  class Relation : public IntExpr {  class Relation FINAL : public IntExpr {
789  public:  public:
790      enum Type {      enum Type {
791          LESS_THAN,          LESS_THAN,
# Line 589  public: Line 795  public:
795          EQUAL,          EQUAL,
796          NOT_EQUAL          NOT_EQUAL
797      };      };
798      Relation(IntExprRef lhs, Type type, IntExprRef rhs) :      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs);
         lhs(lhs), rhs(rhs), type(type) {}  
799      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
800      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
801      bool isConstExpr() const OVERRIDE;      bool isConstExpr() const OVERRIDE;
802      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
803      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
804      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
805  private:  private:
806      IntExprRef lhs;      ExpressionRef lhs;
807      IntExprRef rhs;      ExpressionRef rhs;
808      Type type;      Type type;
809  };  };
810  typedef Ref<Relation,Node> RelationRef;  typedef Ref<Relation,Node> RelationRef;
811    
812  class Or : public IntBinaryOp {  class Or FINAL : public IntBinaryOp {
813  public:  public:
814      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
815      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
816        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
817      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
818  };  };
819  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
820    
821  class BitwiseOr : public IntBinaryOp {  class BitwiseOr FINAL : public IntBinaryOp {
822  public:  public:
823      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
824      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
825      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
826      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
827  };  };
828  typedef Ref<BitwiseOr,Node> BitwiseOrRef;  typedef Ref<BitwiseOr,Node> BitwiseOrRef;
829    
830  class And : public IntBinaryOp {  class And FINAL : public IntBinaryOp {
831  public:  public:
832      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
833      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
834        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
835      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
836  };  };
837  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
838    
839  class BitwiseAnd : public IntBinaryOp {  class BitwiseAnd FINAL : public IntBinaryOp {
840  public:  public:
841      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
842      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
843      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
844      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
845  };  };
846  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
847    
848  class Not : virtual public IntExpr {  class Not FINAL : virtual public IntExpr {
849      IntExprRef expr;      IntExprRef expr;
850  public:  public:
851      Not(IntExprRef expr) : expr(expr) {}      Not(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
852      vmint evalInt() OVERRIDE { return !expr->evalInt(); }      vmint evalInt() OVERRIDE { return !expr->evalInt(); }
853      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
854      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
855      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
856      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
857      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
858  };  };
859  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
860    
861  class BitwiseNot : virtual public IntExpr {  class BitwiseNot FINAL : virtual public IntExpr {
862      IntExprRef expr;      IntExprRef expr;
863  public:  public:
864      BitwiseNot(IntExprRef expr) : expr(expr) {}      BitwiseNot(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
865      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }
866      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
867      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
868      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
869      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
     StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }  
870      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
871  };  };
872  typedef Ref<BitwiseNot,Node> BitwiseNotRef;  typedef Ref<BitwiseNot,Node> BitwiseNotRef;
873    
874  class Final : virtual public IntExpr {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
875      IntExprRef expr;      NumberExprRef expr;
876  public:  public:
877      Final(IntExprRef expr) : expr(expr) {}      Final(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
878      vmint evalInt() OVERRIDE { return expr->evalInt(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
879        vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
880        vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
881        String evalCastToStr() OVERRIDE;
882      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
883      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
884      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
885      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); }      vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); }
     StdUnit_t unitType() const OVERRIDE { return expr->unitType(); }  
886      bool isFinal() const OVERRIDE { return true; }      bool isFinal() const OVERRIDE { return true; }
887  };  };
888  typedef Ref<Final,Node> FinalRef;  typedef Ref<Final,Node> FinalRef;
889    
890  class ParserContext : public VMParserContext {  class ParserContext FINAL : public VMParserContext {
891  public:  public:
892      struct Error {      struct Error {
893          String txt;          String txt;
# Line 704  public: Line 908  public:
908      std::map<String,VariableRef> vartable;      std::map<String,VariableRef> vartable;
909      std::map<String,StatementsRef> userFnTable;      std::map<String,StatementsRef> userFnTable;
910      vmint globalIntVarCount;      vmint globalIntVarCount;
911        vmint globalRealVarCount;
912      vmint globalStrVarCount;      vmint globalStrVarCount;
913        vmint globalUnitFactorCount;
914      vmint polyphonicIntVarCount;      vmint polyphonicIntVarCount;
915        vmint polyphonicRealVarCount;
916        vmint polyphonicUnitFactorCount;
917    
918      EventHandlersRef handlers;      EventHandlersRef handlers;
919    
# Line 715  public: Line 923  public:
923      OnControllerRef onController;      OnControllerRef onController;
924    
925      ArrayList<vmint>* globalIntMemory;      ArrayList<vmint>* globalIntMemory;
926        ArrayList<vmfloat>* globalRealMemory;
927      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
928        ArrayList<vmfloat>* globalUnitFactorMemory;
929      vmint requiredMaxStackSize;      vmint requiredMaxStackSize;
930    
931      VMFunctionProvider* functionProvider;      VMFunctionProvider* functionProvider;
# Line 724  public: Line 934  public:
934    
935      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
936          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
937          globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
938          globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1),          globalUnitFactorCount(0),
939            polyphonicIntVarCount(0), polyphonicRealVarCount(0),
940            polyphonicUnitFactorCount(0),
941            globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
942            globalUnitFactorMemory(NULL),
943            requiredMaxStackSize(-1),
944          functionProvider(parent), execContext(NULL)          functionProvider(parent), execContext(NULL)
945      {      {
946      }      }
947      virtual ~ParserContext();      virtual ~ParserContext();
948      VariableRef globalVar(const String& name);      VariableRef globalVar(const String& name);
949      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
950        RealVariableRef globalRealVar(const String& name);
951      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
952      VariableRef variableByName(const String& name);      VariableRef variableByName(const String& name);
953      StatementsRef userFunctionByName(const String& name);      StatementsRef userFunctionByName(const String& name);
# Line 755  public: Line 971  public:
971      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
972  };  };
973    
974  class ExecContext : public VMExecContext {  class ExecContext FINAL : public VMExecContext {
975  public:  public:
976      struct StackFrame {      struct StackFrame {
977          Statement* statement;          Statement* statement;
# Line 768  public: Line 984  public:
984      };      };
985    
986      ArrayList<vmint> polyphonicIntMemory;      ArrayList<vmint> polyphonicIntMemory;
987        ArrayList<vmfloat> polyphonicRealMemory;
988        ArrayList<vmfloat> polyphonicUnitFactorMemory;
989      VMExecStatus_t status;      VMExecStatus_t status;
990      StmtFlags_t flags;      StmtFlags_t flags;
991      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
# Line 777  public: Line 995  public:
995      struct ExitRes {      struct ExitRes {
996          Expression* value;          Expression* value;
997          IntLiteral intLiteral;          IntLiteral intLiteral;
998            RealLiteral realLiteral;
999          StringLiteral stringLiteral;          StringLiteral stringLiteral;
1000    
1001          ExitRes() : intLiteral(0), stringLiteral("") { }          ExitRes() :
1002                intLiteral({ .value = 0 }), realLiteral({ .value = 0.0 }),
1003                stringLiteral("") { }
1004      } exitRes;      } exitRes;
1005    
1006      ExecContext();      ExecContext();
# Line 816  public: Line 1037  public:
1037      }      }
1038    
1039      void resetPolyphonicData() OVERRIDE {      void resetPolyphonicData() OVERRIDE {
1040          if (polyphonicIntMemory.empty()) return;          if (!polyphonicIntMemory.empty())
1041          memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
1042            if (!polyphonicRealMemory.empty())
1043                memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));
1044            if (!polyphonicUnitFactorMemory.empty()) {
1045                const vmint sz = polyphonicUnitFactorMemory.size();
1046                for (vmint i = 0; i < sz; ++i)
1047                    polyphonicUnitFactorMemory[i] = VM_NO_FACTOR;
1048            }
1049      }      }
1050    
1051      size_t instructionsPerformed() const OVERRIDE {      size_t instructionsPerformed() const OVERRIDE {

Legend:
Removed from v.3561  
changed lines
  Added in v.3583

  ViewVC Help
Powered by ViewVC