/[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 3573 by schoenebeck, Tue Aug 27 21:36:53 2019 UTC revision 3581 by schoenebeck, Fri Aug 30 11:40:25 2019 UTC
# Line 59  public: Line 59  public:
59  typedef Ref<Expression,Node> ExpressionRef;  typedef Ref<Expression,Node> ExpressionRef;
60    
61  class Unit : virtual public VMUnit, virtual public Node {  class Unit : virtual public VMUnit, virtual public Node {
     ArrayList<MetricPrefix_t> prefix;  
62      StdUnit_t unit;      StdUnit_t unit;
63  public:  public:
64      Unit() : unit(VM_NO_UNIT) {}      Unit(StdUnit_t type) : unit(type) {}
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
65      StdUnit_t unitType() const OVERRIDE { return unit; }      StdUnit_t unitType() const OVERRIDE { return unit; }
66      void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit);
67      void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor);
68      void copyUnitFrom(const Ref<Unit,Node>& src);      static vmfloat convRealToUnitFactor(vmfloat fValue, VMUnit* srcUnit, VMUnit* dstUnit);
69        static vmfloat convRealToUnitFactor(vmfloat fValue, vmfloat srcFactor, vmfloat dstFactor);
70  };  };
71  typedef Ref<Unit,Node> UnitRef;  typedef Ref<Unit,Node> UnitRef;
72    
# Line 79  typedef Ref<ScalarNumberExpr,Node> Scala Line 78  typedef Ref<ScalarNumberExpr,Node> Scala
78  class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {  class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {
79  public:  public:
80      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
81        vmint evalIntToUnitFactor(vmfloat unitFactor);
82      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
83  };  };
84  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
# Line 86  typedef Ref<IntExpr,Node> IntExprRef; Line 86  typedef Ref<IntExpr,Node> IntExprRef;
86  class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {  class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {
87  public:  public:
88      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
89        vmfloat evalRealToUnitFactor(vmfloat unitFactor);
90      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
91  };  };
92  typedef Ref<RealExpr,Node> RealExprRef;  typedef Ref<RealExpr,Node> RealExprRef;
# Line 116  public: Line 117  public:
117  };  };
118  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
119    
120  class IntLiteral : public IntExpr {  struct IntLitDef {
121        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.
122        vmfloat unitFactor = VM_NO_FACTOR;
123        StdUnit_t unitType = VM_NO_UNIT;
124        bool isFinal;
125    };
126    
127    class IntLiteral FINAL : public IntExpr {
128      bool finalVal;      bool finalVal;
129  public:      vmfloat unitPrefixFactor;
130      vmint value;      vmint value;
131      IntLiteral(vmint value) : IntExpr(),  public:
132          value(value), finalVal(false) { }      IntLiteral(const IntLitDef& def);
133      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
134        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
135      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
136      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
137      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
138      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
139  };  };
140  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
141    
142  class RealLiteral : public RealExpr {  struct RealLitDef {
143      vmfloat value;      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.
144        vmfloat unitFactor = VM_NO_FACTOR;
145        StdUnit_t unitType = VM_NO_UNIT;
146        bool isFinal;
147    };
148    
149    class RealLiteral FINAL : public RealExpr {
150      bool finalVal;      bool finalVal;
151        vmfloat unitPrefixFactor;
152        vmfloat value;
153  public:  public:
154      RealLiteral(vmfloat value) : RealExpr(),      RealLiteral(const RealLitDef& def);
         value(value), finalVal(false) { }  
155      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
156        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
157      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
158      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
159      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
160      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
161  };  };
162  typedef Ref<RealLiteral,Node> RealLiteralRef;  typedef Ref<RealLiteral,Node> RealLiteralRef;
163    
164  class StringLiteral : virtual public StringExpr {  class StringLiteral FINAL : public StringExpr {
 public:  
165      String value;      String value;
166    public:
167      StringLiteral(const String& value) : value(value) { }      StringLiteral(const String& value) : value(value) { }
168      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
169      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
# Line 157  public: Line 172  public:
172  };  };
173  typedef Ref<StringLiteral,Node> StringLiteralRef;  typedef Ref<StringLiteral,Node> StringLiteralRef;
174    
175  class Args : virtual public VMFnArgs, virtual public Node {  class Args FINAL : virtual public VMFnArgs, virtual public Node {
176  public:  public:
177      std::vector<ExpressionRef> args;      std::vector<ExpressionRef> args;
178      void add(ExpressionRef arg) { args.push_back(arg); }      void add(ExpressionRef arg) { args.push_back(arg); }
# Line 168  public: Line 183  public:
183  };  };
184  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
185    
186    struct VariableDecl {
187        ParserContext* ctx;
188        bool isPolyphonic;
189        bool isConst;
190        bool isFinal;
191        vmint elements = 1;
192        vmint memPos;
193        vmint unitFactorMemPos;
194        StdUnit_t unitType = VM_NO_UNIT;
195    };
196    
197  class Variable : virtual public VMVariable, virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
198  public:  public:
199      bool isConstExpr() const OVERRIDE { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
# Line 175  public: Line 201  public:
201      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
202      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); }
203  protected:  protected:
204      Variable(ParserContext* ctx, vmint _memPos, bool _bConst)      Variable(const VariableDecl& decl);
         : context(ctx), memPos(_memPos), bConst(_bConst) {}  
205    
206      ParserContext* context;      ParserContext* context;
207      vmint memPos;      vmint memPos;
# Line 187  typedef Ref<Variable,Node> VariableRef; Line 212  typedef Ref<Variable,Node> VariableRef;
212  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {
213      bool polyphonic;      bool polyphonic;
214      bool finalVal;      bool finalVal;
215    protected:
216        vmint unitFactorMemPos;
217  public:  public:
218      bool isPolyphonic() const OVERRIDE { return polyphonic; }      bool isPolyphonic() const OVERRIDE { return polyphonic; }
219      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
220      void setFinal(bool b = true) { finalVal = b; }      vmfloat unitFactor() const OVERRIDE;
221  protected:  protected:
222      ScalarNumberVariable(ParserContext* ctx, vmint _memPos,      ScalarNumberVariable(const VariableDecl& decl);
                          bool _bConst = false, bool _bPolyphonic = false,  
                          bool _bFinal = false);  
223  };  };
224  typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;  typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;
225    
226  class IntVariable : public ScalarNumberVariable, virtual public IntExpr {  class IntVariable : public ScalarNumberVariable, virtual public IntExpr {
227  public:  public:
228      IntVariable(ParserContext* ctx);      IntVariable(const VariableDecl& decl);
229      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
230      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
231      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
232  };  };
233  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
234    
235  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {
236  public:  public:
237      RealVariable(ParserContext* ctx);      RealVariable(const VariableDecl& decl);
238      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
239      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
240      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     RealVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
241  };  };
242  typedef Ref<RealVariable,Node> RealVariableRef;  typedef Ref<RealVariable,Node> RealVariableRef;
243    
244  class ConstIntVariable : public IntVariable {  struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
245  public:      // copied from VariableDecl
246      vmint value;      ParserContext* ctx;
247        bool isPolyphonic;
248        bool isConst;
249        bool isFinal;
250        vmint elements = 1;
251        vmint memPos;
252        vmint unitFactorMemPos;
253        StdUnit_t unitType = VM_NO_UNIT;
254        // additions for RealVarDef
255        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.
256        vmfloat unitFactor = VM_NO_FACTOR;
257    };
258    
259      ConstIntVariable(vmint value);  class ConstIntVariable FINAL : public IntVariable {
260        vmfloat unitPrefixFactor;
261        vmint value;
262    public:
263        ConstIntVariable(const IntVarDef& def);
264      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
265      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
266        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
267      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
268  };  };
269  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
270    
271  class ConstRealVariable : public RealVariable {  struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
272  public:      // copied from VariableDecl
273      vmfloat value;      ParserContext* ctx;
274        bool isPolyphonic;
275        bool isConst;
276        bool isFinal;
277        vmint elements = 1;
278        vmint memPos;
279        vmint unitFactorMemPos;
280        StdUnit_t unitType = VM_NO_UNIT;
281        // additions for RealVarDef
282        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.
283        vmfloat unitFactor = VM_NO_FACTOR;
284    };
285    
286      ConstRealVariable(vmfloat value);  class ConstRealVariable FINAL : public RealVariable {
287        vmfloat unitPrefixFactor;
288        vmfloat value;
289    public:
290        ConstRealVariable(const RealVarDef& def);
291      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
292      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
293        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
294      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
295  };  };
296  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
297    
298  class BuiltInIntVariable : public IntVariable {  class BuiltInIntVariable FINAL : public IntVariable {
299      String name;      String name;
300      VMIntPtr* ptr;      VMIntPtr* ptr;
301  public:  public:
# Line 250  public: Line 303  public:
303      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }
304      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
305      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
306        vmfloat unitFactor() const OVERRIDE { return VM_NO_UNIT; }
307      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
308  };  };
309  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
310    
311  class PolyphonicIntVariable : public IntVariable {  class PolyphonicIntVariable FINAL : public IntVariable {
312  public:  public:
313      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(const VariableDecl& decl);
314      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
315  };  };
316  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
317    
318  class PolyphonicRealVariable : public RealVariable {  class PolyphonicRealVariable FINAL : public RealVariable {
319  public:  public:
320      PolyphonicRealVariable(ParserContext* ctx);      PolyphonicRealVariable(const VariableDecl& decl);
321      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
322  };  };
323  typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;  typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;
324    
325  class IntArrayVariable : public Variable, virtual public IntArrayExpr {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
326      ArrayList<vmint> values;      ArrayList<vmint> values;
327        ArrayList<vmfloat> unitFactors;
328  public:  public:
329      IntArrayVariable(ParserContext* ctx, vmint size);      IntArrayVariable(ParserContext* ctx, vmint size);
330      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
331      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  
332      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
333      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
334      virtual vmint evalIntElement(vmuint i) OVERRIDE;      virtual vmint evalIntElement(vmuint i) OVERRIDE;
335      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;
336        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
337        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
338      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
339      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
340  protected:  protected:
# Line 286  protected: Line 342  protected:
342  };  };
343  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
344    
345  class RealArrayVariable : public Variable, virtual public RealArrayExpr {  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
346      ArrayList<vmfloat> values;      ArrayList<vmfloat> values;
347        ArrayList<vmfloat> unitFactors;
348  public:  public:
349      RealArrayVariable(ParserContext* ctx, vmint size);      RealArrayVariable(ParserContext* ctx, vmint size);
350      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
351      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  
352      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
353      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
354      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
355      virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;      virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;
356        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
357        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
358      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
359      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
360  protected:  protected:
# Line 304  protected: Line 362  protected:
362  };  };
363  typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;  typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;
364    
365  class BuiltInIntArrayVariable : public IntArrayVariable {  class BuiltInIntArrayVariable FINAL : public IntArrayVariable {
366      String name;      String name;
367      VMInt8Array* array;      VMInt8Array* array;
368  public:  public:
369      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
370      vmint arraySize() const OVERRIDE { return array->size; }      vmint arraySize() const OVERRIDE { return array->size; }
371      vmint evalIntElement(vmuint i) OVERRIDE;      vmint evalIntElement(vmuint i) OVERRIDE;
     bool isAssignable() const OVERRIDE { return !array->readonly; }  
372      void assignIntElement(vmuint i, vmint value) OVERRIDE;      void assignIntElement(vmuint i, vmint value) OVERRIDE;
373        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
374        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
375        bool isAssignable() const OVERRIDE { return !array->readonly; }
376      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
377  };  };
378  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
379    
380  class IntArrayElement : public IntVariable {  class IntArrayElement FINAL : public IntVariable {
381      IntArrayExprRef array;      IntArrayExprRef array;
382      IntExprRef index;      IntExprRef index;
383        vmint currentIndex;
384  public:  public:
385      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
386      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
387      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
388        vmfloat unitFactor() const OVERRIDE;
389      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
390  };  };
391  typedef Ref<IntArrayElement,Node> IntArrayElementRef;  typedef Ref<IntArrayElement,Node> IntArrayElementRef;
392    
393  class RealArrayElement : public RealVariable {  class RealArrayElement FINAL : public RealVariable {
394      RealArrayExprRef array;      RealArrayExprRef array;
395      IntExprRef index;      IntExprRef index;
396        vmint currentIndex;
397  public:  public:
398      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
399      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
400      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
401        vmfloat unitFactor() const OVERRIDE;
402      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
403  };  };
404  typedef Ref<RealArrayElement,Node> RealArrayElementRef;  typedef Ref<RealArrayElement,Node> RealArrayElementRef;
# Line 351  protected: Line 415  protected:
415  };  };
416  typedef Ref<StringVariable,Node> StringVariableRef;  typedef Ref<StringVariable,Node> StringVariableRef;
417    
418  class ConstStringVariable : public StringVariable {  class ConstStringVariable FINAL : public StringVariable {
 public:  
419      String value;      String value;
420    public:
421      ConstStringVariable(ParserContext* ctx, String value = "");      ConstStringVariable(ParserContext* ctx, String value = "");
422      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
423      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
# Line 376  typedef Ref<BinaryOp,Node> BinaryOpRef; Line 439  typedef Ref<BinaryOp,Node> BinaryOpRef;
439  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {
440  public:  public:
441      ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : BinaryOp(lhs, rhs) { }      ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : BinaryOp(lhs, rhs) { }
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
442      bool isFinal() const OVERRIDE;      bool isFinal() const OVERRIDE;
443  };  };
444  typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;  typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;
# Line 396  public: Line 457  public:
457  };  };
458  typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;  typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;
459    
460  class Add : public VaritypeScalarBinaryOp {  class Add FINAL : public VaritypeScalarBinaryOp {
461  public:  public:
462      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
463      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
464      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
465        vmfloat unitFactor() const OVERRIDE;
466      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
467  };  };
468  typedef Ref<Add,Node> AddRef;  typedef Ref<Add,Node> AddRef;
469    
470  class Sub : public VaritypeScalarBinaryOp {  class Sub FINAL : public VaritypeScalarBinaryOp {
471  public:  public:
472      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
473      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
474      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
475        vmfloat unitFactor() const OVERRIDE;
476      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
477  };  };
478  typedef Ref<Sub,Node> SubRef;  typedef Ref<Sub,Node> SubRef;
479    
480  class Mul : public VaritypeScalarBinaryOp {  class Mul FINAL : public VaritypeScalarBinaryOp {
481  public:  public:
482      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
483      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
484      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
485        vmfloat unitFactor() const OVERRIDE;
486      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
487  };  };
488  typedef Ref<Mul,Node> MulRef;  typedef Ref<Mul,Node> MulRef;
489    
490  class Div : public VaritypeScalarBinaryOp {  class Div FINAL : public VaritypeScalarBinaryOp {
491  public:  public:
492      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs);
493      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
494      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
495      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
496      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
     StdUnit_t unitType() const OVERRIDE;  
497  };  };
498  typedef Ref<Div,Node> DivRef;  typedef Ref<Div,Node> DivRef;
499    
500  class Mod : public IntBinaryOp {  class Mod FINAL : public IntBinaryOp {
501  public:  public:
502      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs), Unit(VM_NO_UNIT) { }
503      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
504        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
505      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
506  };  };
507  typedef Ref<Mod,Node> ModRef;  typedef Ref<Mod,Node> ModRef;
# Line 452  typedef Ref<Statement,Node> StatementRef Line 514  typedef Ref<Statement,Node> StatementRef
514    
515  // 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
516  // 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.
517  class NoOperation : public Statement {  class NoOperation FINAL : public Statement {
518  public:  public:
519      NoOperation() : Statement() {}      NoOperation() : Statement() {}
520      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
# Line 488  public: Line 550  public:
550      virtual Statements* branch(vmuint i) const = 0;      virtual Statements* branch(vmuint i) const = 0;
551  };  };
552    
553  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 {
554      VMDynVar* dynVar;      VMDynVar* dynVar;
555      String varName;      String varName;
556  public:  public:
# Line 505  public: Line 567  public:
567      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
568      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
569      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); }
570        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
571        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
572      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
573      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; }  
574      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
575  };  };
576  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
# Line 516  class FunctionCall : virtual public Leaf Line 579  class FunctionCall : virtual public Leaf
579      String functionName;      String functionName;
580      ArgsRef args;      ArgsRef args;
581      VMFunction* fn;      VMFunction* fn;
582        VMFnResult* result;
583  public:  public:
584      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn);
         functionName(function), args(args), fn(fn) { }  
585      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
586      StmtFlags_t exec() OVERRIDE;      StmtFlags_t exec() OVERRIDE;
587      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
# Line 530  public: Line 593  public:
593      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
594      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
595      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
596      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE;
597      StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }      bool isFinal() const OVERRIDE;
     bool isFinal() const OVERRIDE { return false; }  
598  protected:  protected:
599      VMFnResult* execVMFn();      VMFnResult* execVMFn();
600  };  };
601  typedef Ref<FunctionCall,Node> FunctionCallRef;  typedef Ref<FunctionCall,Node> FunctionCallRef;
602    
603  class NoFunctionCall : public FunctionCall {  class NoFunctionCall FINAL : public FunctionCall {
604  public:  public:
605      NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}      NoFunctionCall() : FunctionCall("nothing", new Args, NULL), Unit(VM_NO_UNIT) {}
606      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
607  };  };
608  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;
# Line 557  public: Line 619  public:
619  };  };
620  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
621    
622  class OnNote : public EventHandler {  class OnNote FINAL : public EventHandler {
623  public:  public:
624      OnNote(StatementsRef statements) : EventHandler(statements) {}      OnNote(StatementsRef statements) : EventHandler(statements) {}
625      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }
# Line 565  public: Line 627  public:
627  };  };
628  typedef Ref<OnNote,Node> OnNoteRef;  typedef Ref<OnNote,Node> OnNoteRef;
629    
630  class OnInit : public EventHandler {  class OnInit FINAL : public EventHandler {
631  public:  public:
632      OnInit(StatementsRef statements) : EventHandler(statements) {}      OnInit(StatementsRef statements) : EventHandler(statements) {}
633      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }
# Line 573  public: Line 635  public:
635  };  };
636  typedef Ref<OnInit,Node> OnInitRef;  typedef Ref<OnInit,Node> OnInitRef;
637    
638  class OnRelease : public EventHandler {  class OnRelease FINAL : public EventHandler {
639  public:  public:
640      OnRelease(StatementsRef statements) : EventHandler(statements) {}      OnRelease(StatementsRef statements) : EventHandler(statements) {}
641      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }
# Line 581  public: Line 643  public:
643  };  };
644  typedef Ref<OnRelease,Node> OnReleaseRef;  typedef Ref<OnRelease,Node> OnReleaseRef;
645    
646  class OnController : public EventHandler {  class OnController FINAL : public EventHandler {
647  public:  public:
648      OnController(StatementsRef statements) : EventHandler(statements) {}      OnController(StatementsRef statements) : EventHandler(statements) {}
649      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }
# Line 589  public: Line 651  public:
651  };  };
652  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
653    
654  class EventHandlers : virtual public Node {  class EventHandlers FINAL : virtual public Node {
655      std::vector<EventHandlerRef> args;      std::vector<EventHandlerRef> args;
656  public:  public:
657      EventHandlers();      EventHandlers();
# Line 603  public: Line 665  public:
665  };  };
666  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
667    
668  class Assignment : public LeafStatement {  class Assignment FINAL : public LeafStatement {
669  protected:  protected:
670      VariableRef variable;      VariableRef variable;
671      ExpressionRef value;      ExpressionRef value;
# Line 615  public: Line 677  public:
677  };  };
678  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
679    
680  class If : public BranchStatement {  class If FINAL : public BranchStatement {
681      IntExprRef condition;      IntExprRef condition;
682      StatementsRef ifStatements;      StatementsRef ifStatements;
683      StatementsRef elseStatements;      StatementsRef elseStatements;
# Line 631  public: Line 693  public:
693  };  };
694  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
695    
696  struct CaseBranch {  struct CaseBranch FINAL {
697      IntExprRef from;      IntExprRef from;
698      IntExprRef to;      IntExprRef to;
699      StatementsRef statements;      StatementsRef statements;
700  };  };
   
701  typedef std::vector<CaseBranch> CaseBranches;  typedef std::vector<CaseBranch> CaseBranches;
702    
703  class SelectCase : public BranchStatement {  class SelectCase FINAL : public BranchStatement {
704      IntExprRef select;      IntExprRef select;
705      CaseBranches branches;      CaseBranches branches;
706  public:  public:
# Line 647  public: Line 708  public:
708      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
709      vmint evalBranch() OVERRIDE;      vmint evalBranch() OVERRIDE;
710      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);  
711      bool isPolyphonic() const OVERRIDE;      bool isPolyphonic() const OVERRIDE;
712  };  };
713  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
714    
715  class While : public Statement {  class While FINAL : public Statement {
716      IntExprRef m_condition;      IntExprRef m_condition;
717      StatementsRef m_statements;      StatementsRef m_statements;
718  public:  public:
# Line 668  public: Line 725  public:
725      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
726  };  };
727    
728  class SyncBlock : public Statement {  class SyncBlock FINAL : public Statement {
729      StatementsRef m_statements;      StatementsRef m_statements;
730  public:  public:
731      SyncBlock(StatementsRef statements) : m_statements(statements) {}      SyncBlock(StatementsRef statements) : m_statements(statements) {}
# Line 679  public: Line 736  public:
736  };  };
737  typedef Ref<SyncBlock,Node> SyncBlockRef;  typedef Ref<SyncBlock,Node> SyncBlockRef;
738    
739  class Neg : public IntExpr {  class Neg FINAL : virtual public IntExpr, virtual public RealExpr {
740      IntExprRef expr;      ScalarNumberExprRef expr;
741  public:  public:
742      Neg(IntExprRef expr) : expr(expr) { }      Neg(ScalarNumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }
743      vmint evalInt() OVERRIDE { return (expr) ? -expr->evalInt() : 0; }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
744        vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }
745        vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }
746        String evalCastToStr() OVERRIDE;
747      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
748      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
749      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
750      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(); }  
751      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
752  };  };
753  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
754    
755  class ConcatString : public StringExpr {  class ConcatString FINAL : public StringExpr {
756      ExpressionRef lhs;      ExpressionRef lhs;
757      ExpressionRef rhs;      ExpressionRef rhs;
758  public:  public:
# Line 705  public: Line 764  public:
764  };  };
765  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
766    
767  class Relation : public IntExpr {  class Relation FINAL : public IntExpr {
768  public:  public:
769      enum Type {      enum Type {
770          LESS_THAN,          LESS_THAN,
# Line 715  public: Line 774  public:
774          EQUAL,          EQUAL,
775          NOT_EQUAL          NOT_EQUAL
776      };      };
777      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs) :      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs);
         lhs(lhs), rhs(rhs), type(type) {}  
778      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
779      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
780      bool isConstExpr() const OVERRIDE;      bool isConstExpr() const OVERRIDE;
781      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
782      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; }  
783      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
784  private:  private:
785      ExpressionRef lhs;      ExpressionRef lhs;
# Line 731  private: Line 788  private:
788  };  };
789  typedef Ref<Relation,Node> RelationRef;  typedef Ref<Relation,Node> RelationRef;
790    
791  class Or : public IntBinaryOp {  class Or FINAL : public IntBinaryOp {
792  public:  public:
793      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
794      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
795        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
796      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
797  };  };
798  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
799    
800  class BitwiseOr : public IntBinaryOp {  class BitwiseOr FINAL : public IntBinaryOp {
801  public:  public:
802      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
803      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
804      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
805      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; }  
806  };  };
807  typedef Ref<BitwiseOr,Node> BitwiseOrRef;  typedef Ref<BitwiseOr,Node> BitwiseOrRef;
808    
809  class And : public IntBinaryOp {  class And FINAL : public IntBinaryOp {
810  public:  public:
811      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
812      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
813        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
814      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
815  };  };
816  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
817    
818  class BitwiseAnd : public IntBinaryOp {  class BitwiseAnd FINAL : public IntBinaryOp {
819  public:  public:
820      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
821      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
822      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
823      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; }  
824  };  };
825  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
826    
827  class Not : virtual public IntExpr {  class Not FINAL : virtual public IntExpr {
828      IntExprRef expr;      IntExprRef expr;
829  public:  public:
830      Not(IntExprRef expr) : expr(expr) {}      Not(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
831      vmint evalInt() OVERRIDE { return !expr->evalInt(); }      vmint evalInt() OVERRIDE { return !expr->evalInt(); }
832      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
833      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
834      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
835      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; }  
836      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
837  };  };
838  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
839    
840  class BitwiseNot : virtual public IntExpr {  class BitwiseNot FINAL : virtual public IntExpr {
841      IntExprRef expr;      IntExprRef expr;
842  public:  public:
843      BitwiseNot(IntExprRef expr) : expr(expr) {}      BitwiseNot(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
844      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }
845      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
846      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
847      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
848      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; }  
849      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
850  };  };
851  typedef Ref<BitwiseNot,Node> BitwiseNotRef;  typedef Ref<BitwiseNot,Node> BitwiseNotRef;
852    
853  class Final : virtual public IntExpr, virtual public RealExpr {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
854      ScalarNumberExprRef expr;      ScalarNumberExprRef expr;
855  public:  public:
856      Final(ScalarNumberExprRef expr) : expr(expr) {}      Final(ScalarNumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
857      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
858      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
859      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
# Line 806  public: Line 861  public:
861      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
862      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
863      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
864      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(); }  
865      bool isFinal() const OVERRIDE { return true; }      bool isFinal() const OVERRIDE { return true; }
866  };  };
867  typedef Ref<Final,Node> FinalRef;  typedef Ref<Final,Node> FinalRef;
868    
869  class ParserContext : public VMParserContext {  class ParserContext FINAL : public VMParserContext {
870  public:  public:
871      struct Error {      struct Error {
872          String txt;          String txt;
# Line 835  public: Line 889  public:
889      vmint globalIntVarCount;      vmint globalIntVarCount;
890      vmint globalRealVarCount;      vmint globalRealVarCount;
891      vmint globalStrVarCount;      vmint globalStrVarCount;
892        vmint globalUnitFactorCount;
893      vmint polyphonicIntVarCount;      vmint polyphonicIntVarCount;
894      vmint polyphonicRealVarCount;      vmint polyphonicRealVarCount;
895        vmint polyphonicUnitFactorCount;
896    
897      EventHandlersRef handlers;      EventHandlersRef handlers;
898    
# Line 848  public: Line 904  public:
904      ArrayList<vmint>* globalIntMemory;      ArrayList<vmint>* globalIntMemory;
905      ArrayList<vmfloat>* globalRealMemory;      ArrayList<vmfloat>* globalRealMemory;
906      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
907        ArrayList<vmfloat>* globalUnitFactorMemory;
908      vmint requiredMaxStackSize;      vmint requiredMaxStackSize;
909    
910      VMFunctionProvider* functionProvider;      VMFunctionProvider* functionProvider;
# Line 857  public: Line 914  public:
914      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
915          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
916          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
917            globalUnitFactorCount(0),
918          polyphonicIntVarCount(0), polyphonicRealVarCount(0),          polyphonicIntVarCount(0), polyphonicRealVarCount(0),
919            polyphonicUnitFactorCount(0),
920          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
921            globalUnitFactorMemory(NULL),
922          requiredMaxStackSize(-1),          requiredMaxStackSize(-1),
923          functionProvider(parent), execContext(NULL)          functionProvider(parent), execContext(NULL)
924      {      {
# Line 890  public: Line 950  public:
950      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
951  };  };
952    
953  class ExecContext : public VMExecContext {  class ExecContext FINAL : public VMExecContext {
954  public:  public:
955      struct StackFrame {      struct StackFrame {
956          Statement* statement;          Statement* statement;
# Line 904  public: Line 964  public:
964    
965      ArrayList<vmint> polyphonicIntMemory;      ArrayList<vmint> polyphonicIntMemory;
966      ArrayList<vmfloat> polyphonicRealMemory;      ArrayList<vmfloat> polyphonicRealMemory;
967        ArrayList<vmfloat> polyphonicUnitFactorMemory;
968      VMExecStatus_t status;      VMExecStatus_t status;
969      StmtFlags_t flags;      StmtFlags_t flags;
970      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
# Line 913  public: Line 974  public:
974      struct ExitRes {      struct ExitRes {
975          Expression* value;          Expression* value;
976          IntLiteral intLiteral;          IntLiteral intLiteral;
977            RealLiteral realLiteral;
978          StringLiteral stringLiteral;          StringLiteral stringLiteral;
979    
980          ExitRes() : intLiteral(0), stringLiteral("") { }          ExitRes() :
981                intLiteral({ .value = 0 }), realLiteral({ .value = 0.0 }),
982                stringLiteral("") { }
983      } exitRes;      } exitRes;
984    
985      ExecContext();      ExecContext();
# Line 956  public: Line 1020  public:
1020              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
1021          if (!polyphonicRealMemory.empty())          if (!polyphonicRealMemory.empty())
1022              memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));              memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));
1023            if (!polyphonicUnitFactorMemory.empty()) {
1024                const vmint sz = polyphonicUnitFactorMemory.size();
1025                for (vmint i = 0; i < sz; ++i)
1026                    polyphonicUnitFactorMemory[i] = VM_NO_FACTOR;
1027            }
1028      }      }
1029    
1030      size_t instructionsPerformed() const OVERRIDE {      size_t instructionsPerformed() const OVERRIDE {

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

  ViewVC Help
Powered by ViewVC