/[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 3574 by schoenebeck, Wed Aug 28 08:26:54 2019 UTC revision 3585 by schoenebeck, Fri Aug 30 17:51:24 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    /**
65     * Used by parser for parser error messages to provide a text with all data
66     * types accepted by the given built-in function @a fn for the respective
67     * function argument @a iArg.
68     */
69    String acceptedArgTypesStr(VMFunction* fn, vmint iArg);
70    
71  class Node {  class Node {
72  public:  public:
73      Node();      Node();
# Line 59  public: Line 87  public:
87  typedef Ref<Expression,Node> ExpressionRef;  typedef Ref<Expression,Node> ExpressionRef;
88    
89  class Unit : virtual public VMUnit, virtual public Node {  class Unit : virtual public VMUnit, virtual public Node {
     ArrayList<MetricPrefix_t> prefix;  
90      StdUnit_t unit;      StdUnit_t unit;
91  public:  public:
92      Unit() : unit(VM_NO_UNIT) {}      Unit(StdUnit_t type) : unit(type) {}
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
93      StdUnit_t unitType() const OVERRIDE { return unit; }      StdUnit_t unitType() const OVERRIDE { return unit; }
94      void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit);
95      void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type);      static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor);
96      void copyUnitFrom(const Ref<Unit,Node>& src);      static vmfloat convRealToUnitFactor(vmfloat fValue, VMUnit* srcUnit, VMUnit* dstUnit);
97        static vmfloat convRealToUnitFactor(vmfloat fValue, vmfloat srcFactor, vmfloat dstFactor);
98  };  };
99  typedef Ref<Unit,Node> UnitRef;  typedef Ref<Unit,Node> UnitRef;
100    
101  class ScalarNumberExpr : virtual public Unit, virtual public VMScalarNumberExpr, virtual public Expression {  class NumberExpr : virtual public Unit, virtual public VMNumberExpr, virtual public Expression {
102  public:  public:
103  };  };
104  typedef Ref<ScalarNumberExpr,Node> ScalarNumberExprRef;  typedef Ref<NumberExpr,Node> NumberExprRef;
105    
106  class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {  class IntExpr : virtual public NumberExpr, virtual public VMIntExpr {
107  public:  public:
108      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
109        vmint evalIntToUnitFactor(vmfloat unitFactor);
110      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
111  };  };
112  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
113    
114  class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {  class RealExpr : virtual public NumberExpr, virtual public VMRealExpr  {
115  public:  public:
116      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
117        vmfloat evalRealToUnitFactor(vmfloat unitFactor);
118      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
119  };  };
120  typedef Ref<RealExpr,Node> RealExprRef;  typedef Ref<RealExpr,Node> RealExprRef;
# Line 116  public: Line 145  public:
145  };  };
146  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
147    
148    struct IntLitDef {
149        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.
150        vmfloat unitFactor = VM_NO_FACTOR;
151        StdUnit_t unitType = VM_NO_UNIT;
152        bool isFinal;
153    };
154    
155  class IntLiteral FINAL : public IntExpr {  class IntLiteral FINAL : public IntExpr {
156      bool finalVal;      bool finalVal;
157  public:      vmfloat unitPrefixFactor;
158      vmint value;      vmint value;
159      IntLiteral(vmint value) : IntExpr(),  public:
160          value(value), finalVal(false) { }      IntLiteral(const IntLitDef& def);
161      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
162        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
163      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
164      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
165      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
166      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
167  };  };
168  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
169    
170    struct RealLitDef {
171        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.
172        vmfloat unitFactor = VM_NO_FACTOR;
173        StdUnit_t unitType = VM_NO_UNIT;
174        bool isFinal;
175    };
176    
177  class RealLiteral FINAL : public RealExpr {  class RealLiteral FINAL : public RealExpr {
     vmfloat value;  
178      bool finalVal;      bool finalVal;
179        vmfloat unitPrefixFactor;
180        vmfloat value;
181  public:  public:
182      RealLiteral(vmfloat value) : RealExpr(),      RealLiteral(const RealLitDef& def);
         value(value), finalVal(false) { }  
183      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
184        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
185      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
186      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
187      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
188      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
     void setFinal(bool b = true) { finalVal = b; }  
189  };  };
190  typedef Ref<RealLiteral,Node> RealLiteralRef;  typedef Ref<RealLiteral,Node> RealLiteralRef;
191    
192  class StringLiteral FINAL : public StringExpr {  class StringLiteral FINAL : public StringExpr {
 public:  
193      String value;      String value;
194    public:
195      StringLiteral(const String& value) : value(value) { }      StringLiteral(const String& value) : value(value) { }
196      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
197      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
# Line 168  public: Line 211  public:
211  };  };
212  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
213    
214    struct VariableDecl {
215        ParserContext* ctx;
216        bool isPolyphonic;
217        bool isConst;
218        bool isFinal;
219        vmint elements = 1;
220        vmint memPos;
221        vmint unitFactorMemPos;
222        StdUnit_t unitType = VM_NO_UNIT;
223    };
224    
225  class Variable : virtual public VMVariable, virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
226  public:  public:
227      bool isConstExpr() const OVERRIDE { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
# Line 175  public: Line 229  public:
229      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
230      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); }
231  protected:  protected:
232      Variable(ParserContext* ctx, vmint _memPos, bool _bConst)      Variable(const VariableDecl& decl);
         : context(ctx), memPos(_memPos), bConst(_bConst) {}  
233    
234      ParserContext* context;      ParserContext* context;
235      vmint memPos;      vmint memPos;
# Line 184  protected: Line 237  protected:
237  };  };
238  typedef Ref<Variable,Node> VariableRef;  typedef Ref<Variable,Node> VariableRef;
239    
240  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {  class NumberVariable : public Variable, virtual public NumberExpr {
241      bool polyphonic;      bool polyphonic;
242      bool finalVal;      bool finalVal;
243    protected:
244        vmint unitFactorMemPos;
245  public:  public:
246      bool isPolyphonic() const OVERRIDE { return polyphonic; }      bool isPolyphonic() const OVERRIDE { return polyphonic; }
247      bool isFinal() const OVERRIDE { return finalVal; }      bool isFinal() const OVERRIDE { return finalVal; }
248      void setFinal(bool b = true) { finalVal = b; }      vmfloat unitFactor() const OVERRIDE;
249  protected:  protected:
250      ScalarNumberVariable(ParserContext* ctx, vmint _memPos,      NumberVariable(const VariableDecl& decl);
                          bool _bConst = false, bool _bPolyphonic = false,  
                          bool _bFinal = false);  
251  };  };
252  typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;  typedef Ref<NumberVariable,Node> NumberVariableRef;
253    
254  class IntVariable : public ScalarNumberVariable, virtual public IntExpr {  class IntVariable : public NumberVariable, virtual public IntExpr {
255  public:  public:
256      IntVariable(ParserContext* ctx);      IntVariable(const VariableDecl& decl);
257      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
258      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
259      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
260  };  };
261  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
262    
263  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {  class RealVariable : public NumberVariable, virtual public RealExpr {
264  public:  public:
265      RealVariable(ParserContext* ctx);      RealVariable(const VariableDecl& decl);
266      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
267      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
268      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
 protected:  
     RealVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);  
269  };  };
270  typedef Ref<RealVariable,Node> RealVariableRef;  typedef Ref<RealVariable,Node> RealVariableRef;
271    
272    struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
273        // copied from VariableDecl
274        ParserContext* ctx;
275        bool isPolyphonic;
276        bool isConst;
277        bool isFinal;
278        vmint elements = 1;
279        vmint memPos;
280        vmint unitFactorMemPos;
281        StdUnit_t unitType = VM_NO_UNIT;
282        // additions for RealVarDef
283        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.
284        vmfloat unitFactor = VM_NO_FACTOR;
285    };
286    
287  class ConstIntVariable FINAL : public IntVariable {  class ConstIntVariable FINAL : public IntVariable {
288  public:      vmfloat unitPrefixFactor;
289      vmint value;      vmint value;
290    public:
291      ConstIntVariable(vmint value);      ConstIntVariable(const IntVarDef& def);
292      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
293      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
294        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
295      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
296  };  };
297  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
298    
299    struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17
300        // copied from VariableDecl
301        ParserContext* ctx;
302        bool isPolyphonic;
303        bool isConst;
304        bool isFinal;
305        vmint elements = 1;
306        vmint memPos;
307        vmint unitFactorMemPos;
308        StdUnit_t unitType = VM_NO_UNIT;
309        // additions for RealVarDef
310        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.
311        vmfloat unitFactor = VM_NO_FACTOR;
312    };
313    
314  class ConstRealVariable FINAL : public RealVariable {  class ConstRealVariable FINAL : public RealVariable {
315  public:      vmfloat unitPrefixFactor;
316      vmfloat value;      vmfloat value;
317    public:
318      ConstRealVariable(vmfloat value);      ConstRealVariable(const RealVarDef& def);
319      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
320      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
321        vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; }
322      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
323  };  };
324  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;  typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
# Line 250  public: Line 331  public:
331      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }      bool isAssignable() const OVERRIDE { return ptr->isAssignable(); }
332      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
333      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
334        vmfloat unitFactor() const OVERRIDE { return VM_NO_UNIT; }
335      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
336  };  };
337  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
338    
339  class PolyphonicIntVariable FINAL : public IntVariable {  class PolyphonicIntVariable FINAL : public IntVariable {
340  public:  public:
341      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(const VariableDecl& decl);
342      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
343  };  };
344  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
345    
346  class PolyphonicRealVariable FINAL : public RealVariable {  class PolyphonicRealVariable FINAL : public RealVariable {
347  public:  public:
348      PolyphonicRealVariable(ParserContext* ctx);      PolyphonicRealVariable(const VariableDecl& decl);
349      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
350  };  };
351  typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;  typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;
352    
353  class IntArrayVariable : public Variable, virtual public IntArrayExpr {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
354      ArrayList<vmint> values;      ArrayList<vmint> values;
355        ArrayList<vmfloat> unitFactors;
356  public:  public:
357      IntArrayVariable(ParserContext* ctx, vmint size);      IntArrayVariable(ParserContext* ctx, vmint size);
358      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
359      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  
360      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
361      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
362      virtual vmint evalIntElement(vmuint i) OVERRIDE;      virtual vmint evalIntElement(vmuint i) OVERRIDE;
363      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;      virtual void assignIntElement(vmuint i, vmint value) OVERRIDE;
364        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
365        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
366      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
367      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
368  protected:  protected:
# Line 288  typedef Ref<IntArrayVariable,Node> IntAr Line 372  typedef Ref<IntArrayVariable,Node> IntAr
372    
373  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
374      ArrayList<vmfloat> values;      ArrayList<vmfloat> values;
375        ArrayList<vmfloat> unitFactors;
376  public:  public:
377      RealArrayVariable(ParserContext* ctx, vmint size);      RealArrayVariable(ParserContext* ctx, vmint size);
378      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);      RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
379      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  
380      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
381      virtual vmint arraySize() const OVERRIDE { return values.size(); }      virtual vmint arraySize() const OVERRIDE { return values.size(); }
382      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;      virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
383      virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;      virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;
384        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE;
385        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE;
386      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
387      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
388  protected:  protected:
# Line 311  public: Line 397  public:
397      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);      BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
398      vmint arraySize() const OVERRIDE { return array->size; }      vmint arraySize() const OVERRIDE { return array->size; }
399      vmint evalIntElement(vmuint i) OVERRIDE;      vmint evalIntElement(vmuint i) OVERRIDE;
     bool isAssignable() const OVERRIDE { return !array->readonly; }  
400      void assignIntElement(vmuint i, vmint value) OVERRIDE;      void assignIntElement(vmuint i, vmint value) OVERRIDE;
401        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
402        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
403        bool isAssignable() const OVERRIDE { return !array->readonly; }
404      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
405  };  };
406  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
# Line 320  typedef Ref<BuiltInIntArrayVariable,Node Line 408  typedef Ref<BuiltInIntArrayVariable,Node
408  class IntArrayElement FINAL : public IntVariable {  class IntArrayElement FINAL : public IntVariable {
409      IntArrayExprRef array;      IntArrayExprRef array;
410      IntExprRef index;      IntExprRef index;
411        vmint currentIndex;
412  public:  public:
413      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
414      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
415      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
416        vmfloat unitFactor() const OVERRIDE;
417      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
418  };  };
419  typedef Ref<IntArrayElement,Node> IntArrayElementRef;  typedef Ref<IntArrayElement,Node> IntArrayElementRef;
# Line 331  typedef Ref<IntArrayElement,Node> IntArr Line 421  typedef Ref<IntArrayElement,Node> IntArr
421  class RealArrayElement FINAL : public RealVariable {  class RealArrayElement FINAL : public RealVariable {
422      RealArrayExprRef array;      RealArrayExprRef array;
423      IntExprRef index;      IntExprRef index;
424        vmint currentIndex;
425  public:  public:
426      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);      RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
427      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
428      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
429        vmfloat unitFactor() const OVERRIDE;
430      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
431  };  };
432  typedef Ref<RealArrayElement,Node> RealArrayElementRef;  typedef Ref<RealArrayElement,Node> RealArrayElementRef;
# Line 352  protected: Line 444  protected:
444  typedef Ref<StringVariable,Node> StringVariableRef;  typedef Ref<StringVariable,Node> StringVariableRef;
445    
446  class ConstStringVariable FINAL : public StringVariable {  class ConstStringVariable FINAL : public StringVariable {
 public:  
447      String value;      String value;
448    public:
449      ConstStringVariable(ParserContext* ctx, String value = "");      ConstStringVariable(ParserContext* ctx, String value = "");
450      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
451      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
# Line 373  public: Line 464  public:
464  };  };
465  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
466    
467  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {  class NumberBinaryOp : public BinaryOp, virtual public NumberExpr {
468  public:  public:
469      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;  
470      bool isFinal() const OVERRIDE;      bool isFinal() const OVERRIDE;
471  };  };
472  typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;  typedef Ref<NumberBinaryOp,Node> NumberBinaryOpRef;
473    
474  class IntBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr {  class IntBinaryOp : public NumberBinaryOp, virtual public IntExpr {
475  public:  public:
476      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
477  };  };
478  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;  typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
479    
480  class VaritypeScalarBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr, virtual public RealExpr {  class VaritypeScalarBinaryOp : public NumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
481  public:  public:
482      VaritypeScalarBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }      VaritypeScalarBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : NumberBinaryOp(lhs, rhs) { }
483      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
484      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
485  };  };
# Line 398  typedef Ref<VaritypeScalarBinaryOp,Node> Line 487  typedef Ref<VaritypeScalarBinaryOp,Node>
487    
488  class Add FINAL : public VaritypeScalarBinaryOp {  class Add FINAL : public VaritypeScalarBinaryOp {
489  public:  public:
490      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Add(NumberExprRef lhs, NumberExprRef rhs);
491      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
492      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
493        vmfloat unitFactor() const OVERRIDE;
494      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
495  };  };
496  typedef Ref<Add,Node> AddRef;  typedef Ref<Add,Node> AddRef;
497    
498  class Sub FINAL : public VaritypeScalarBinaryOp {  class Sub FINAL : public VaritypeScalarBinaryOp {
499  public:  public:
500      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Sub(NumberExprRef lhs, NumberExprRef rhs);
501      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
502      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
503        vmfloat unitFactor() const OVERRIDE;
504      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
505  };  };
506  typedef Ref<Sub,Node> SubRef;  typedef Ref<Sub,Node> SubRef;
507    
508  class Mul FINAL : public VaritypeScalarBinaryOp {  class Mul FINAL : public VaritypeScalarBinaryOp {
509  public:  public:
510      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Mul(NumberExprRef lhs, NumberExprRef rhs);
511      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
512      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
513        vmfloat unitFactor() const OVERRIDE;
514      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
     MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;  
     StdUnit_t unitType() const OVERRIDE;  
515  };  };
516  typedef Ref<Mul,Node> MulRef;  typedef Ref<Mul,Node> MulRef;
517    
518  class Div FINAL : public VaritypeScalarBinaryOp {  class Div FINAL : public VaritypeScalarBinaryOp {
519  public:  public:
520      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }      Div(NumberExprRef lhs, NumberExprRef rhs);
521      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
522      vmfloat evalReal() OVERRIDE;      vmfloat evalReal() OVERRIDE;
523      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
524      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;      vmfloat unitFactor() const OVERRIDE;
     StdUnit_t unitType() const OVERRIDE;  
525  };  };
526  typedef Ref<Div,Node> DivRef;  typedef Ref<Div,Node> DivRef;
527    
528  class Mod FINAL : public IntBinaryOp {  class Mod FINAL : public IntBinaryOp {
529  public:  public:
530      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs), Unit(VM_NO_UNIT) { }
531      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
532        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
533      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
534  };  };
535  typedef Ref<Mod,Node> ModRef;  typedef Ref<Mod,Node> ModRef;
# Line 505  public: Line 595  public:
595      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }      vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
596      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
597      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); }
598        vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
599        void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {}
600      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
601      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; }  
602      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
603  };  };
604  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
# Line 516  class FunctionCall : virtual public Leaf Line 607  class FunctionCall : virtual public Leaf
607      String functionName;      String functionName;
608      ArgsRef args;      ArgsRef args;
609      VMFunction* fn;      VMFunction* fn;
610        VMFnResult* result;
611  public:  public:
612      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn);
         functionName(function), args(args), fn(fn) { }  
613      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
614      StmtFlags_t exec() OVERRIDE;      StmtFlags_t exec() OVERRIDE;
615      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
# Line 530  public: Line 621  public:
621      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
622      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
623      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
624      MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }      vmfloat unitFactor() const OVERRIDE;
625      StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }      bool isFinal() const OVERRIDE;
     bool isFinal() const OVERRIDE { return false; }  
626  protected:  protected:
627      VMFnResult* execVMFn();      VMFnResult* execVMFn();
628  };  };
# Line 540  typedef Ref<FunctionCall,Node> FunctionC Line 630  typedef Ref<FunctionCall,Node> FunctionC
630    
631  class NoFunctionCall FINAL : public FunctionCall {  class NoFunctionCall FINAL : public FunctionCall {
632  public:  public:
633      NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}      NoFunctionCall() : FunctionCall("nothing", new Args, NULL), Unit(VM_NO_UNIT) {}
634      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
635  };  };
636  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;  typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;
# Line 646  public: Line 736  public:
736      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
737      vmint evalBranch() OVERRIDE;      vmint evalBranch() OVERRIDE;
738      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);  
739      bool isPolyphonic() const OVERRIDE;      bool isPolyphonic() const OVERRIDE;
740  };  };
741  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
# Line 678  public: Line 764  public:
764  };  };
765  typedef Ref<SyncBlock,Node> SyncBlockRef;  typedef Ref<SyncBlock,Node> SyncBlockRef;
766    
767  class Neg FINAL : public IntExpr {  class Neg FINAL : virtual public IntExpr, virtual public RealExpr {
768      IntExprRef expr;      NumberExprRef expr;
769  public:  public:
770      Neg(IntExprRef expr) : expr(expr) { }      Neg(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) { }
771      vmint evalInt() OVERRIDE { return (expr) ? -expr->evalInt() : 0; }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
772        vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; }
773        vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); }
774        String evalCastToStr() OVERRIDE;
775      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
776      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
777      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
778      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(); }  
779      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
780  };  };
781  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
# Line 714  public: Line 802  public:
802          EQUAL,          EQUAL,
803          NOT_EQUAL          NOT_EQUAL
804      };      };
805      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs) :      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs);
         lhs(lhs), rhs(rhs), type(type) {}  
806      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
807      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
808      bool isConstExpr() const OVERRIDE;      bool isConstExpr() const OVERRIDE;
809      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
810      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; }  
811      bool isFinal() const OVERRIDE { return false; }      bool isFinal() const OVERRIDE { return false; }
812  private:  private:
813      ExpressionRef lhs;      ExpressionRef lhs;
# Line 732  typedef Ref<Relation,Node> RelationRef; Line 818  typedef Ref<Relation,Node> RelationRef;
818    
819  class Or FINAL : public IntBinaryOp {  class Or FINAL : public IntBinaryOp {
820  public:  public:
821      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
822      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
823        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
824      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
825  };  };
826  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
827    
828  class BitwiseOr FINAL : public IntBinaryOp {  class BitwiseOr FINAL : public IntBinaryOp {
829  public:  public:
830      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
831      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
832      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
833      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; }  
834  };  };
835  typedef Ref<BitwiseOr,Node> BitwiseOrRef;  typedef Ref<BitwiseOr,Node> BitwiseOrRef;
836    
837  class And FINAL : public IntBinaryOp {  class And FINAL : public IntBinaryOp {
838  public:  public:
839      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
840      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
841        vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; }
842      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
843  };  };
844  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
845    
846  class BitwiseAnd FINAL : public IntBinaryOp {  class BitwiseAnd FINAL : public IntBinaryOp {
847  public:  public:
848      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {}
849      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
850      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
851      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; }  
852  };  };
853  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
854    
855  class Not FINAL : virtual public IntExpr {  class Not FINAL : virtual public IntExpr {
856      IntExprRef expr;      IntExprRef expr;
857  public:  public:
858      Not(IntExprRef expr) : expr(expr) {}      Not(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
859      vmint evalInt() OVERRIDE { return !expr->evalInt(); }      vmint evalInt() OVERRIDE { return !expr->evalInt(); }
860      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
861      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
862      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
863      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; }  
864      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
865  };  };
866  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
# Line 783  typedef Ref<Not,Node> NotRef; Line 868  typedef Ref<Not,Node> NotRef;
868  class BitwiseNot FINAL : virtual public IntExpr {  class BitwiseNot FINAL : virtual public IntExpr {
869      IntExprRef expr;      IntExprRef expr;
870  public:  public:
871      BitwiseNot(IntExprRef expr) : expr(expr) {}      BitwiseNot(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {}
872      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }      vmint evalInt() OVERRIDE { return ~expr->evalInt(); }
873      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
874      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
875      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
876      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; }  
877      bool isFinal() const OVERRIDE { return expr->isFinal(); }      bool isFinal() const OVERRIDE { return expr->isFinal(); }
878  };  };
879  typedef Ref<BitwiseNot,Node> BitwiseNotRef;  typedef Ref<BitwiseNot,Node> BitwiseNotRef;
880    
881  class Final FINAL : virtual public IntExpr, virtual public RealExpr {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
882      ScalarNumberExprRef expr;      NumberExprRef expr;
883  public:  public:
884      Final(ScalarNumberExprRef expr) : expr(expr) {}      Final(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) {}
885      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }      ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
886      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }      vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
887      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }      vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
# Line 805  public: Line 889  public:
889      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
890      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
891      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
892      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(); }  
893      bool isFinal() const OVERRIDE { return true; }      bool isFinal() const OVERRIDE { return true; }
894  };  };
895  typedef Ref<Final,Node> FinalRef;  typedef Ref<Final,Node> FinalRef;
# Line 834  public: Line 917  public:
917      vmint globalIntVarCount;      vmint globalIntVarCount;
918      vmint globalRealVarCount;      vmint globalRealVarCount;
919      vmint globalStrVarCount;      vmint globalStrVarCount;
920        vmint globalUnitFactorCount;
921      vmint polyphonicIntVarCount;      vmint polyphonicIntVarCount;
922      vmint polyphonicRealVarCount;      vmint polyphonicRealVarCount;
923        vmint polyphonicUnitFactorCount;
924    
925      EventHandlersRef handlers;      EventHandlersRef handlers;
926    
# Line 847  public: Line 932  public:
932      ArrayList<vmint>* globalIntMemory;      ArrayList<vmint>* globalIntMemory;
933      ArrayList<vmfloat>* globalRealMemory;      ArrayList<vmfloat>* globalRealMemory;
934      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
935        ArrayList<vmfloat>* globalUnitFactorMemory;
936      vmint requiredMaxStackSize;      vmint requiredMaxStackSize;
937    
938      VMFunctionProvider* functionProvider;      VMFunctionProvider* functionProvider;
# Line 856  public: Line 942  public:
942      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
943          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
944          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
945            globalUnitFactorCount(0),
946          polyphonicIntVarCount(0), polyphonicRealVarCount(0),          polyphonicIntVarCount(0), polyphonicRealVarCount(0),
947            polyphonicUnitFactorCount(0),
948          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),          globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
949            globalUnitFactorMemory(NULL),
950          requiredMaxStackSize(-1),          requiredMaxStackSize(-1),
951          functionProvider(parent), execContext(NULL)          functionProvider(parent), execContext(NULL)
952      {      {
# Line 903  public: Line 992  public:
992    
993      ArrayList<vmint> polyphonicIntMemory;      ArrayList<vmint> polyphonicIntMemory;
994      ArrayList<vmfloat> polyphonicRealMemory;      ArrayList<vmfloat> polyphonicRealMemory;
995        ArrayList<vmfloat> polyphonicUnitFactorMemory;
996      VMExecStatus_t status;      VMExecStatus_t status;
997      StmtFlags_t flags;      StmtFlags_t flags;
998      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
# Line 912  public: Line 1002  public:
1002      struct ExitRes {      struct ExitRes {
1003          Expression* value;          Expression* value;
1004          IntLiteral intLiteral;          IntLiteral intLiteral;
1005            RealLiteral realLiteral;
1006          StringLiteral stringLiteral;          StringLiteral stringLiteral;
1007    
1008          ExitRes() : intLiteral(0), stringLiteral("") { }          ExitRes() :
1009                intLiteral({ .value = 0 }), realLiteral({ .value = 0.0 }),
1010                stringLiteral("") { }
1011      } exitRes;      } exitRes;
1012    
1013      ExecContext();      ExecContext();
# Line 955  public: Line 1048  public:
1048              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
1049          if (!polyphonicRealMemory.empty())          if (!polyphonicRealMemory.empty())
1050              memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));              memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));
1051            if (!polyphonicUnitFactorMemory.empty()) {
1052                const vmint sz = polyphonicUnitFactorMemory.size();
1053                for (vmint i = 0; i < sz; ++i)
1054                    polyphonicUnitFactorMemory[i] = VM_NO_FACTOR;
1055            }
1056      }      }
1057    
1058      size_t instructionsPerformed() const OVERRIDE {      size_t instructionsPerformed() const OVERRIDE {

Legend:
Removed from v.3574  
changed lines
  Added in v.3585

  ViewVC Help
Powered by ViewVC