/[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 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 59  public: Line 80  public:
80  typedef Ref<Expression,Node> ExpressionRef;  typedef Ref<Expression,Node> ExpressionRef;
81    
82  class Unit : virtual public VMUnit, virtual public Node {  class Unit : virtual public VMUnit, virtual public Node {
     ArrayList<MetricPrefix_t> prefix;  
83      StdUnit_t unit;      StdUnit_t unit;
84  public:  public:
85      Unit() : unit(VM_NO_UNIT) {}      Unit(StdUnit_t type) : unit(type) {}
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
86      StdUnit_t unitType() const OVERRIDE { return unit; }      StdUnit_t unitType() const OVERRIDE { return unit; }
87      void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit);
88      void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor);
89      void copyUnitFrom(const Ref<Unit,Node>& src);      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;  typedef Ref<Unit,Node> UnitRef;
93    
94  class ScalarNumberExpr : virtual public Unit, virtual public VMScalarNumberExpr, virtual public Expression {  class NumberExpr : virtual public Unit, virtual public VMNumberExpr, virtual public Expression {
95  public:  public:
96  };  };
97  typedef Ref<ScalarNumberExpr,Node> ScalarNumberExprRef;  typedef Ref<NumberExpr,Node> NumberExprRef;
98    
99  class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {  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 RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {  class RealExpr : virtual public NumberExpr, virtual public VMRealExpr  {
108  public:  public:
109      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
110        vmfloat evalRealToUnitFactor(vmfloat unitFactor);
111      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
112  };  };
113  typedef Ref<RealExpr,Node> RealExprRef;  typedef Ref<RealExpr,Node> RealExprRef;
# Line 116  public: Line 138  public:
138  };  };
139  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
140    
141  class IntLiteral : public IntExpr {  struct IntLitDef {
142        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        vmfloat unitFactor = VM_NO_FACTOR;
144        StdUnit_t unitType = VM_NO_UNIT;
145        bool isFinal;
146    };
147    
148    class IntLiteral FINAL : public IntExpr {
149      bool finalVal;      bool finalVal;
150  public:      vmfloat unitPrefixFactor;
151      vmint value;      vmint value;
152      IntLiteral(vmint value) : IntExpr(),  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 RealLiteral : public RealExpr {  struct RealLitDef {
164      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.
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;      bool finalVal;
172        vmfloat unitPrefixFactor;
173        vmfloat value;
174  public:  public:
175      RealLiteral(vmfloat value) : RealExpr(),      RealLiteral(const RealLitDef& def);
         value(value), finalVal(false) { }  
176      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
177        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
178      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
179      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
180      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
181      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
182  };  };
183  typedef Ref<RealLiteral,Node> RealLiteralRef;  typedef Ref<RealLiteral,Node> RealLiteralRef;
184    
185  class StringLiteral : virtual public StringExpr {  class StringLiteral FINAL : public StringExpr {
 public:  
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 157  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 168  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 175  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 184  protected: Line 230  protected:
230  };  };
231  typedef Ref<Variable,Node> VariableRef;  typedef Ref<Variable,Node> VariableRef;
232    
233  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {  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:
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      ScalarNumberVariable(ParserContext* ctx, vmint _memPos,      NumberVariable(const VariableDecl& decl);
                          bool _bConst = false, bool _bPolyphonic = false,  
                          bool _bFinal = false);  
244  };  };
245  typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;  typedef Ref<NumberVariable,Node> NumberVariableRef;
246    
247  class IntVariable : public ScalarNumberVariable, virtual public IntExpr {  class IntVariable : public NumberVariable, virtual public IntExpr {
248  public:  public:
249      IntVariable(ParserContext* ctx);      IntVariable(const VariableDecl& decl);
250      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
251      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
252      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
253  };  };
254  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
255    
256  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {  class RealVariable : public NumberVariable, virtual public RealExpr {
257  public:  public:
258      RealVariable(ParserContext* ctx);      RealVariable(const VariableDecl& decl);
259      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
260      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
261      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     RealVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
262  };  };
263  typedef Ref<RealVariable,Node> RealVariableRef;  typedef Ref<RealVariable,Node> RealVariableRef;
264    
265  class ConstIntVariable : public IntVariable {  struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
266  public:      // copied from VariableDecl
267      vmint value;      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      ConstIntVariable(vmint value);  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 ConstRealVariable : public RealVariable {  struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
293  public:      // copied from VariableDecl
294      vmfloat value;      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      ConstRealVariable(vmfloat value);  class ConstRealVariable FINAL : public RealVariable {
308        vmfloat unitPrefixFactor;
309        vmfloat value;
310    public:
311        ConstRealVariable(const RealVarDef& def);
312      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
313      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
314        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
315      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
316  };  };
317  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
318    
319  class BuiltInIntVariable : public IntVariable {  class BuiltInIntVariable FINAL : public IntVariable {
320      String name;      String name;
321      VMIntPtr* ptr;      VMIntPtr* ptr;
322  public:  public:
# Line 250  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 : public RealVariable {  class PolyphonicRealVariable FINAL : public RealVariable {
340  public:  public:
341      PolyphonicRealVariable(ParserContext* ctx);      PolyphonicRealVariable(const VariableDecl& decl);
342      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
343  };  };
344  typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;  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 286  protected: Line 363  protected:
363  };  };
364  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
365    
366  class RealArrayVariable : public Variable, virtual public RealArrayExpr {  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
367      ArrayList<vmfloat> values;      ArrayList<vmfloat> values;
368        ArrayList<vmfloat> unitFactors;
369  public:  public:
370      RealArrayVariable(ParserContext* ctx, vmint size);      RealArrayVariable(ParserContext* ctx, vmint size);
371      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
372      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  
373      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
374      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
375      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
376      virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;      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;      void dump(int level = 0) OVERRIDE;
380      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
381  protected:  protected:
# Line 304  protected: Line 383  protected:
383  };  };
384  typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;  typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;
385    
386  class BuiltInIntArrayVariable : public IntArrayVariable {  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 : public RealVariable {  class RealArrayElement FINAL : public RealVariable {
415      RealArrayExprRef array;      RealArrayExprRef array;
416      IntExprRef index;      IntExprRef index;
417        vmint currentIndex;
418  public:  public:
419      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
420      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
421      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
422        vmfloat unitFactor() const OVERRIDE;
423      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
424  };  };
425  typedef Ref<RealArrayElement,Node> RealArrayElementRef;  typedef Ref<RealArrayElement,Node> RealArrayElementRef;
# Line 351  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 373  public: Line 457  public:
457  };  };
458  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
459    
460  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {  class NumberBinaryOp : public BinaryOp, virtual public NumberExpr {
461  public:  public:
462      ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef 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<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;  typedef Ref<NumberBinaryOp,Node> NumberBinaryOpRef;
466    
467  class IntBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr {  class IntBinaryOp : public NumberBinaryOp, virtual public IntExpr {
468  public:  public:
469      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
470  };  };
471  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
472    
473  class VaritypeScalarBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr, virtual public RealExpr {  class VaritypeScalarBinaryOp : public NumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
474  public:  public:
475      VaritypeScalarBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      VaritypeScalarBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
476      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
477      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
478  };  };
479  typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;  typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;
480    
481  class Add : public VaritypeScalarBinaryOp {  class Add FINAL : public VaritypeScalarBinaryOp {
482  public:  public:
483      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Add(NumberExprRef lhs, NumberExprRef rhs);
484      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
485      vmfloat evalReal() OVERRIDE;      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 VaritypeScalarBinaryOp {  class Sub FINAL : public VaritypeScalarBinaryOp {
492  public:  public:
493      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Sub(NumberExprRef lhs, NumberExprRef rhs);
494      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
495      vmfloat evalReal() OVERRIDE;      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 VaritypeScalarBinaryOp {  class Mul FINAL : public VaritypeScalarBinaryOp {
502  public:  public:
503      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Mul(NumberExprRef lhs, NumberExprRef rhs);
504      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
505      vmfloat evalReal() OVERRIDE;      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 VaritypeScalarBinaryOp {  class Div FINAL : public VaritypeScalarBinaryOp {
512  public:  public:
513      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Div(NumberExprRef lhs, NumberExprRef rhs);
514      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
515      vmfloat evalReal() OVERRIDE;      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 452  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 488  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 505  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;
# Line 516  class FunctionCall : virtual public Leaf Line 600  class FunctionCall : virtual public Leaf
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;
# Line 530  public: Line 614  public:
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 557  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 565  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 573  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 581  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 589  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 603  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 615  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 631  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 647  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 668  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 679  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 705  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 715  public: Line 795  public:
795          EQUAL,          EQUAL,
796          NOT_EQUAL          NOT_EQUAL
797      };      };
798      Relation(ExpressionRef lhs, Type type, ExpressionRef 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      ExpressionRef lhs;      ExpressionRef lhs;
# Line 731  private: Line 809  private:
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, virtual public RealExpr {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
875      ScalarNumberExprRef expr;      NumberExprRef expr;
876  public:  public:
877      Final(ScalarNumberExprRef expr) : expr(expr) {}      Final(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
878      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
879      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
880      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
# Line 806  public: Line 882  public:
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 835  public: Line 910  public:
910      vmint globalIntVarCount;      vmint globalIntVarCount;
911      vmint globalRealVarCount;      vmint globalRealVarCount;
912      vmint globalStrVarCount;      vmint globalStrVarCount;
913        vmint globalUnitFactorCount;
914      vmint polyphonicIntVarCount;      vmint polyphonicIntVarCount;
915      vmint polyphonicRealVarCount;      vmint polyphonicRealVarCount;
916        vmint polyphonicUnitFactorCount;
917    
918      EventHandlersRef handlers;      EventHandlersRef handlers;
919    
# Line 848  public: Line 925  public:
925      ArrayList<vmint>* globalIntMemory;      ArrayList<vmint>* globalIntMemory;
926      ArrayList<vmfloat>* globalRealMemory;      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 857  public: Line 935  public:
935      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
936          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
937          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
938            globalUnitFactorCount(0),
939          polyphonicIntVarCount(0), polyphonicRealVarCount(0),          polyphonicIntVarCount(0), polyphonicRealVarCount(0),
940            polyphonicUnitFactorCount(0),
941          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
942            globalUnitFactorMemory(NULL),
943          requiredMaxStackSize(-1),          requiredMaxStackSize(-1),
944          functionProvider(parent), execContext(NULL)          functionProvider(parent), execContext(NULL)
945      {      {
# Line 890  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 904  public: Line 985  public:
985    
986      ArrayList<vmint> polyphonicIntMemory;      ArrayList<vmint> polyphonicIntMemory;
987      ArrayList<vmfloat> polyphonicRealMemory;      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 913  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 956  public: Line 1041  public:
1041              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
1042          if (!polyphonicRealMemory.empty())          if (!polyphonicRealMemory.empty())
1043              memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));              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.3573  
changed lines
  Added in v.3583

  ViewVC Help
Powered by ViewVC