/[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 3557 by schoenebeck, Sun Aug 18 00:06:04 2019 UTC revision 3574 by schoenebeck, Wed Aug 28 08:26:54 2019 UTC
# Line 58  public: Line 58  public:
58  };  };
59  typedef Ref<Expression,Node> ExpressionRef;  typedef Ref<Expression,Node> ExpressionRef;
60    
61  class IntExpr : virtual public VMIntExpr, virtual public Expression {  class Unit : virtual public VMUnit, virtual public Node {
62        ArrayList<MetricPrefix_t> prefix;
63        StdUnit_t unit;
64    public:
65        Unit() : unit(VM_NO_UNIT) {}
66        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;
67        StdUnit_t unitType() const OVERRIDE { return unit; }
68        void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type);
69        void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type);
70        void copyUnitFrom(const Ref<Unit,Node>& src);
71    };
72    typedef Ref<Unit,Node> UnitRef;
73    
74    class ScalarNumberExpr : virtual public Unit, virtual public VMScalarNumberExpr, virtual public Expression {
75    public:
76    };
77    typedef Ref<ScalarNumberExpr,Node> ScalarNumberExprRef;
78    
79    class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr {
80  public:  public:
81      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
82      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
83  };  };
84  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
85    
86  class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression {  class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr  {
87    public:
88        ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
89        String evalCastToStr() OVERRIDE;
90    };
91    typedef Ref<RealExpr,Node> RealExprRef;
92    
93    class ArrayExpr : virtual public VMArrayExpr, virtual public Expression {
94    public:
95    };
96    typedef Ref<ArrayExpr,Node> ArrayExprRef;
97    
98    class IntArrayExpr : virtual public VMIntArrayExpr, virtual public ArrayExpr {
99  public:  public:
100      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }      ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
101      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
102  };  };
103  typedef Ref<IntArrayExpr,Node> IntArrayExprRef;  typedef Ref<IntArrayExpr,Node> IntArrayExprRef;
104    
105    class RealArrayExpr : virtual public VMRealArrayExpr, virtual public ArrayExpr {
106    public:
107        ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
108        String evalCastToStr() OVERRIDE;
109    };
110    typedef Ref<RealArrayExpr,Node> RealArrayExprRef;
111    
112  class StringExpr : virtual public VMStringExpr, virtual public Expression {  class StringExpr : virtual public VMStringExpr, virtual public Expression {
113  public:  public:
114      ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }      ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }
# Line 79  public: Line 116  public:
116  };  };
117  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
118    
119  class IntLiteral : virtual public IntExpr {  class IntLiteral FINAL : public IntExpr {
120        bool finalVal;
121  public:  public:
122      vmint value;      vmint value;
123      IntLiteral(vmint value) : value(value) { }      IntLiteral(vmint value) : IntExpr(),
124            value(value), finalVal(false) { }
125      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
126      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
127      bool isConstExpr() const OVERRIDE { return true; }      bool isConstExpr() const OVERRIDE { return true; }
128      bool isPolyphonic() const OVERRIDE { return false; }      bool isPolyphonic() const OVERRIDE { return false; }
129        bool isFinal() const OVERRIDE { return finalVal; }
130        void setFinal(bool b = true) { finalVal = b; }
131  };  };
132  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
133    
134  class StringLiteral : virtual public StringExpr {  class RealLiteral FINAL : public RealExpr {
135        vmfloat value;
136        bool finalVal;
137    public:
138        RealLiteral(vmfloat value) : RealExpr(),
139            value(value), finalVal(false) { }
140        vmfloat evalReal() OVERRIDE;
141        void dump(int level = 0) OVERRIDE;
142        bool isConstExpr() const OVERRIDE { return true; }
143        bool isPolyphonic() const OVERRIDE { return false; }
144        bool isFinal() const OVERRIDE { return finalVal; }
145        void setFinal(bool b = true) { finalVal = b; }
146    };
147    typedef Ref<RealLiteral,Node> RealLiteralRef;
148    
149    class StringLiteral FINAL : public StringExpr {
150  public:  public:
151      String value;      String value;
152      StringLiteral(const String& value) : value(value) { }      StringLiteral(const String& value) : value(value) { }
# Line 101  public: Line 157  public:
157  };  };
158  typedef Ref<StringLiteral,Node> StringLiteralRef;  typedef Ref<StringLiteral,Node> StringLiteralRef;
159    
160  class Args : virtual public VMFnArgs, virtual public Node {  class Args FINAL : virtual public VMFnArgs, virtual public Node {
161  public:  public:
162      std::vector<ExpressionRef> args;      std::vector<ExpressionRef> args;
163      void add(ExpressionRef arg) { args.push_back(arg); }      void add(ExpressionRef arg) { args.push_back(arg); }
# Line 128  protected: Line 184  protected:
184  };  };
185  typedef Ref<Variable,Node> VariableRef;  typedef Ref<Variable,Node> VariableRef;
186    
187  class IntVariable : public Variable, virtual public IntExpr {  class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr {
188      bool polyphonic;      bool polyphonic;
189        bool finalVal;
190    public:
191        bool isPolyphonic() const OVERRIDE { return polyphonic; }
192        bool isFinal() const OVERRIDE { return finalVal; }
193        void setFinal(bool b = true) { finalVal = b; }
194    protected:
195        ScalarNumberVariable(ParserContext* ctx, vmint _memPos,
196                             bool _bConst = false, bool _bPolyphonic = false,
197                             bool _bFinal = false);
198    };
199    typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef;
200    
201    class IntVariable : public ScalarNumberVariable, virtual public IntExpr {
202  public:  public:
203      IntVariable(ParserContext* ctx);      IntVariable(ParserContext* ctx);
204      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
205      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
206      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
     bool isPolyphonic() const OVERRIDE { return polyphonic; }  
207  protected:  protected:
208      IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);      IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);
209  };  };
210  typedef Ref<IntVariable,Node> IntVariableRef;  typedef Ref<IntVariable,Node> IntVariableRef;
211    
212  class ConstIntVariable : public IntVariable {  class RealVariable : public ScalarNumberVariable, virtual public RealExpr {
213    public:
214        RealVariable(ParserContext* ctx);
215        void assign(Expression* expr) OVERRIDE;
216        vmfloat evalReal() OVERRIDE;
217        void dump(int level = 0) OVERRIDE;
218    protected:
219        RealVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1);
220    };
221    typedef Ref<RealVariable,Node> RealVariableRef;
222    
223    class ConstIntVariable FINAL : public IntVariable {
224  public:  public:
225      vmint value;      vmint value;
226    
227      ConstIntVariable(vmint value);      ConstIntVariable(vmint value);
     //ConstIntVariable(ParserContext* ctx, int value = 0);  
228      void assign(Expression* expr) OVERRIDE;      void assign(Expression* expr) OVERRIDE;
229      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
230      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
231  };  };
232  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
233    
234  class BuiltInIntVariable : public IntVariable {  class ConstRealVariable FINAL : public RealVariable {
235    public:
236        vmfloat value;
237    
238        ConstRealVariable(vmfloat value);
239        void assign(Expression* expr) OVERRIDE;
240        vmfloat evalReal() OVERRIDE;
241        void dump(int level = 0) OVERRIDE;
242    };
243    typedef Ref<ConstRealVariable,Node> ConstRealVariableRef;
244    
245    class BuiltInIntVariable FINAL : public IntVariable {
246      String name;      String name;
247      VMIntPtr* ptr;      VMIntPtr* ptr;
248  public:  public:
# Line 165  public: Line 254  public:
254  };  };
255  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;  typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
256    
257  class PolyphonicIntVariable : public IntVariable {  class PolyphonicIntVariable FINAL : public IntVariable {
258  public:  public:
259      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(ParserContext* ctx);
260      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
261  };  };
262  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
263    
264    class PolyphonicRealVariable FINAL : public RealVariable {
265    public:
266        PolyphonicRealVariable(ParserContext* ctx);
267        void dump(int level = 0) OVERRIDE;
268    };
269    typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef;
270    
271  class IntArrayVariable : public Variable, virtual public IntArrayExpr {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
272      ArrayList<vmint> values;      ArrayList<vmint> values;
273  public:  public:
# Line 190  protected: Line 286  protected:
286  };  };
287  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
288    
289  class BuiltInIntArrayVariable : public IntArrayVariable {  class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr {
290        ArrayList<vmfloat> values;
291    public:
292        RealArrayVariable(ParserContext* ctx, vmint size);
293        RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false);
294        void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment
295        String evalCastToStr() OVERRIDE { return ""; } // ignore scalar cast to string
296        ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
297        virtual vmint arraySize() const OVERRIDE { return values.size(); }
298        virtual vmfloat evalRealElement(vmuint i) OVERRIDE;
299        virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE;
300        void dump(int level = 0) OVERRIDE;
301        bool isPolyphonic() const OVERRIDE { return false; }
302    protected:
303        RealArrayVariable(ParserContext* ctx, bool bConst);
304    };
305    typedef Ref<RealArrayVariable,Node> RealArrayVariableRef;
306    
307    class BuiltInIntArrayVariable FINAL : public IntArrayVariable {
308      String name;      String name;
309      VMInt8Array* array;      VMInt8Array* array;
310  public:  public:
# Line 203  public: Line 317  public:
317  };  };
318  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
319    
320  class IntArrayElement : public IntVariable {  class IntArrayElement FINAL : public IntVariable {
321      IntArrayExprRef array;      IntArrayExprRef array;
322      IntExprRef index;      IntExprRef index;
323  public:  public:
# Line 214  public: Line 328  public:
328  };  };
329  typedef Ref<IntArrayElement,Node> IntArrayElementRef;  typedef Ref<IntArrayElement,Node> IntArrayElementRef;
330    
331    class RealArrayElement FINAL : public RealVariable {
332        RealArrayExprRef array;
333        IntExprRef index;
334    public:
335        RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex);
336        void assign(Expression* expr) OVERRIDE;
337        vmfloat evalReal() OVERRIDE;
338        void dump(int level = 0) OVERRIDE;
339    };
340    typedef Ref<RealArrayElement,Node> RealArrayElementRef;
341    
342  class StringVariable : public Variable, virtual public StringExpr {  class StringVariable : public Variable, virtual public StringExpr {
343  public:  public:
344      StringVariable(ParserContext* ctx);      StringVariable(ParserContext* ctx);
# Line 226  protected: Line 351  protected:
351  };  };
352  typedef Ref<StringVariable,Node> StringVariableRef;  typedef Ref<StringVariable,Node> StringVariableRef;
353    
354  class ConstStringVariable : public StringVariable {  class ConstStringVariable FINAL : public StringVariable {
355  public:  public:
356      String value;      String value;
357    
# Line 248  public: Line 373  public:
373  };  };
374  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
375    
376  class Add : virtual public BinaryOp, virtual public IntExpr {  class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr {
377    public:
378        ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : BinaryOp(lhs, rhs) { }
379        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;
380        StdUnit_t unitType() const OVERRIDE;
381        bool isFinal() const OVERRIDE;
382    };
383    typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef;
384    
385    class IntBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr {
386    public:
387        IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }
388    };
389    typedef Ref<IntBinaryOp,Node> IntBinaryOpRef;
390    
391    class VaritypeScalarBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr, virtual public RealExpr {
392    public:
393        VaritypeScalarBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { }
394        ExprType_t exprType() const OVERRIDE;
395        String evalCastToStr() OVERRIDE;
396    };
397    typedef Ref<VaritypeScalarBinaryOp,Node> VaritypeScalarBinaryOpRef;
398    
399    class Add FINAL : public VaritypeScalarBinaryOp {
400  public:  public:
401      Add(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }      Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }
402      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
403        vmfloat evalReal() OVERRIDE;
404      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
405  };  };
406  typedef Ref<Add,Node> AddRef;  typedef Ref<Add,Node> AddRef;
407    
408  class Sub : virtual public BinaryOp, virtual public IntExpr {  class Sub FINAL : public VaritypeScalarBinaryOp {
409  public:  public:
410      Sub(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }      Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }
411      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
412        vmfloat evalReal() OVERRIDE;
413      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
414  };  };
415  typedef Ref<Sub,Node> SubRef;  typedef Ref<Sub,Node> SubRef;
416    
417  class Mul : virtual public BinaryOp, virtual public IntExpr {  class Mul FINAL : public VaritypeScalarBinaryOp {
418  public:  public:
419      Mul(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }      Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }
420      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
421        vmfloat evalReal() OVERRIDE;
422      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
423        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;
424        StdUnit_t unitType() const OVERRIDE;
425  };  };
426  typedef Ref<Mul,Node> MulRef;  typedef Ref<Mul,Node> MulRef;
427    
428  class Div : virtual public BinaryOp, virtual public IntExpr {  class Div FINAL : public VaritypeScalarBinaryOp {
429  public:  public:
430      Div(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }      Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { }
431      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
432        vmfloat evalReal() OVERRIDE;
433      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
434        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE;
435        StdUnit_t unitType() const OVERRIDE;
436  };  };
437  typedef Ref<Div,Node> DivRef;  typedef Ref<Div,Node> DivRef;
438    
439  class Mod : virtual public BinaryOp, virtual public IntExpr {  class Mod FINAL : public IntBinaryOp {
440  public:  public:
441      Mod(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }      Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { }
442      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
443      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
444  };  };
# Line 296  typedef Ref<Statement,Node> StatementRef Line 452  typedef Ref<Statement,Node> StatementRef
452    
453  // 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
454  // 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.
455  class NoOperation : public Statement {  class NoOperation FINAL : public Statement {
456  public:  public:
457      NoOperation() : Statement() {}      NoOperation() : Statement() {}
458      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
# Line 332  public: Line 488  public:
488      virtual Statements* branch(vmuint i) const = 0;      virtual Statements* branch(vmuint i) const = 0;
489  };  };
490    
491  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 {
492      VMDynVar* dynVar;      VMDynVar* dynVar;
493      String varName;      String varName;
494  public:  public:
# Line 350  public: Line 506  public:
506      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }      vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
507      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); }
508      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
509        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
510        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
511        bool isFinal() const OVERRIDE { return false; }
512  };  };
513  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;  typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
514    
515  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public RealExpr, virtual public StringExpr {
516      String functionName;      String functionName;
517      ArgsRef args;      ArgsRef args;
518      VMFunction* fn;      VMFunction* fn;
# Line 363  public: Line 522  public:
522      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
523      StmtFlags_t exec() OVERRIDE;      StmtFlags_t exec() OVERRIDE;
524      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
525        vmfloat evalReal() OVERRIDE;
526      VMIntArrayExpr* asIntArray() const OVERRIDE;      VMIntArrayExpr* asIntArray() const OVERRIDE;
527        VMRealArrayExpr* asRealArray() const OVERRIDE;
528      String evalStr() OVERRIDE;      String evalStr() OVERRIDE;
529      bool isConstExpr() const OVERRIDE { return false; }      bool isConstExpr() const OVERRIDE { return false; }
530      ExprType_t exprType() const OVERRIDE;      ExprType_t exprType() const OVERRIDE;
531      String evalCastToStr() OVERRIDE;      String evalCastToStr() OVERRIDE;
532      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
533        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
534        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
535        bool isFinal() const OVERRIDE { return false; }
536  protected:  protected:
537      VMFnResult* execVMFn();      VMFnResult* execVMFn();
538  };  };
539  typedef Ref<FunctionCall,Node> FunctionCallRef;  typedef Ref<FunctionCall,Node> FunctionCallRef;
540    
541  class NoFunctionCall : public FunctionCall {  class NoFunctionCall FINAL : public FunctionCall {
542  public:  public:
543      NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}      NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}
544      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }      StmtType_t statementType() const OVERRIDE { return STMT_NOOP; }
# Line 393  public: Line 557  public:
557  };  };
558  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
559    
560  class OnNote : public EventHandler {  class OnNote FINAL : public EventHandler {
561  public:  public:
562      OnNote(StatementsRef statements) : EventHandler(statements) {}      OnNote(StatementsRef statements) : EventHandler(statements) {}
563      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NOTE; }
# Line 401  public: Line 565  public:
565  };  };
566  typedef Ref<OnNote,Node> OnNoteRef;  typedef Ref<OnNote,Node> OnNoteRef;
567    
568  class OnInit : public EventHandler {  class OnInit FINAL : public EventHandler {
569  public:  public:
570      OnInit(StatementsRef statements) : EventHandler(statements) {}      OnInit(StatementsRef statements) : EventHandler(statements) {}
571      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_INIT; }
# Line 409  public: Line 573  public:
573  };  };
574  typedef Ref<OnInit,Node> OnInitRef;  typedef Ref<OnInit,Node> OnInitRef;
575    
576  class OnRelease : public EventHandler {  class OnRelease FINAL : public EventHandler {
577  public:  public:
578      OnRelease(StatementsRef statements) : EventHandler(statements) {}      OnRelease(StatementsRef statements) : EventHandler(statements) {}
579      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RELEASE; }
# Line 417  public: Line 581  public:
581  };  };
582  typedef Ref<OnRelease,Node> OnReleaseRef;  typedef Ref<OnRelease,Node> OnReleaseRef;
583    
584  class OnController : public EventHandler {  class OnController FINAL : public EventHandler {
585  public:  public:
586      OnController(StatementsRef statements) : EventHandler(statements) {}      OnController(StatementsRef statements) : EventHandler(statements) {}
587      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }      VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_CONTROLLER; }
# Line 425  public: Line 589  public:
589  };  };
590  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
591    
592  class EventHandlers : virtual public Node {  class EventHandlers FINAL : virtual public Node {
593      std::vector<EventHandlerRef> args;      std::vector<EventHandlerRef> args;
594  public:  public:
595      EventHandlers();      EventHandlers();
# Line 439  public: Line 603  public:
603  };  };
604  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
605    
606  class Assignment : public LeafStatement {  class Assignment FINAL : public LeafStatement {
607  protected:  protected:
608      VariableRef variable;      VariableRef variable;
609      ExpressionRef value;      ExpressionRef value;
# Line 451  public: Line 615  public:
615  };  };
616  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
617    
618  class If : public BranchStatement {  class If FINAL : public BranchStatement {
619      IntExprRef condition;      IntExprRef condition;
620      StatementsRef ifStatements;      StatementsRef ifStatements;
621      StatementsRef elseStatements;      StatementsRef elseStatements;
# Line 467  public: Line 631  public:
631  };  };
632  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
633    
634  struct CaseBranch {  struct CaseBranch FINAL {
635      IntExprRef from;      IntExprRef from;
636      IntExprRef to;      IntExprRef to;
637      StatementsRef statements;      StatementsRef statements;
638  };  };
   
639  typedef std::vector<CaseBranch> CaseBranches;  typedef std::vector<CaseBranch> CaseBranches;
640    
641  class SelectCase : public BranchStatement {  class SelectCase FINAL : public BranchStatement {
642      IntExprRef select;      IntExprRef select;
643      CaseBranches branches;      CaseBranches branches;
644  public:  public:
# Line 491  public: Line 654  public:
654  };  };
655  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
656    
657  class While : public Statement {  class While FINAL : public Statement {
658      IntExprRef m_condition;      IntExprRef m_condition;
659      StatementsRef m_statements;      StatementsRef m_statements;
660  public:  public:
# Line 504  public: Line 667  public:
667      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
668  };  };
669    
670  class SyncBlock : public Statement {  class SyncBlock FINAL : public Statement {
671      StatementsRef m_statements;      StatementsRef m_statements;
672  public:  public:
673      SyncBlock(StatementsRef statements) : m_statements(statements) {}      SyncBlock(StatementsRef statements) : m_statements(statements) {}
# Line 515  public: Line 678  public:
678  };  };
679  typedef Ref<SyncBlock,Node> SyncBlockRef;  typedef Ref<SyncBlock,Node> SyncBlockRef;
680    
681  class Neg : public IntExpr {  class Neg FINAL : public IntExpr {
682      IntExprRef expr;      IntExprRef expr;
683  public:  public:
684      Neg(IntExprRef expr) : expr(expr) { }      Neg(IntExprRef expr) : expr(expr) { }
# Line 523  public: Line 686  public:
686      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
687      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
688      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
689        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); }
690        StdUnit_t unitType() const OVERRIDE { return expr->unitType(); }
691        bool isFinal() const OVERRIDE { return expr->isFinal(); }
692  };  };
693  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
694    
695  class ConcatString : public StringExpr {  class ConcatString FINAL : public StringExpr {
696      ExpressionRef lhs;      ExpressionRef lhs;
697      ExpressionRef rhs;      ExpressionRef rhs;
698  public:  public:
# Line 538  public: Line 704  public:
704  };  };
705  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
706    
707  class Relation : public IntExpr {  class Relation FINAL : public IntExpr {
708  public:  public:
709      enum Type {      enum Type {
710          LESS_THAN,          LESS_THAN,
# Line 548  public: Line 714  public:
714          EQUAL,          EQUAL,
715          NOT_EQUAL          NOT_EQUAL
716      };      };
717      Relation(IntExprRef lhs, Type type, IntExprRef rhs) :      Relation(ExpressionRef lhs, Type type, ExpressionRef rhs) :
718          lhs(lhs), rhs(rhs), type(type) {}          lhs(lhs), rhs(rhs), type(type) {}
719      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
720      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
721      bool isConstExpr() const OVERRIDE;      bool isConstExpr() const OVERRIDE;
722      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
723        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
724        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
725        bool isFinal() const OVERRIDE { return false; }
726  private:  private:
727      IntExprRef lhs;      ExpressionRef lhs;
728      IntExprRef rhs;      ExpressionRef rhs;
729      Type type;      Type type;
730  };  };
731  typedef Ref<Relation,Node> RelationRef;  typedef Ref<Relation,Node> RelationRef;
732    
733  class Or : virtual public BinaryOp, virtual public IntExpr {  class Or FINAL : public IntBinaryOp {
734  public:  public:
735      Or(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}      Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}
736      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
737      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
738  };  };
739  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
740    
741  class BitwiseOr : virtual public BinaryOp, virtual public IntExpr {  class BitwiseOr FINAL : public IntBinaryOp {
742  public:  public:
743      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}      BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}
744      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
745      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
746        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
747        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
748  };  };
749  typedef Ref<BitwiseOr,Node> BitwiseOrRef;  typedef Ref<BitwiseOr,Node> BitwiseOrRef;
750    
751  class And : virtual public BinaryOp, virtual public IntExpr {  class And FINAL : public IntBinaryOp {
752  public:  public:
753      And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}
754      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
755      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
756  };  };
757  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
758    
759  class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr {  class BitwiseAnd FINAL : public IntBinaryOp {
760  public:  public:
761      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}      BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {}
762      vmint evalInt() OVERRIDE;      vmint evalInt() OVERRIDE;
763      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
764        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
765        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
766  };  };
767  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;  typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
768    
769  class Not : virtual public IntExpr {  class Not FINAL : virtual public IntExpr {
770      IntExprRef expr;      IntExprRef expr;
771  public:  public:
772      Not(IntExprRef expr) : expr(expr) {}      Not(IntExprRef expr) : expr(expr) {}
# Line 601  public: Line 774  public:
774      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
775      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
776      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
777        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
778        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
779        bool isFinal() const OVERRIDE { return expr->isFinal(); }
780  };  };
781  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
782    
783  class BitwiseNot : virtual public IntExpr {  class BitwiseNot FINAL : virtual public IntExpr {
784      IntExprRef expr;      IntExprRef expr;
785  public:  public:
786      BitwiseNot(IntExprRef expr) : expr(expr) {}      BitwiseNot(IntExprRef expr) : expr(expr) {}
# Line 612  public: Line 788  public:
788      void dump(int level = 0) OVERRIDE;      void dump(int level = 0) OVERRIDE;
789      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }      bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
790      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }      bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
791        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
792        StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
793        bool isFinal() const OVERRIDE { return expr->isFinal(); }
794  };  };
795  typedef Ref<BitwiseNot,Node> BitwiseNotRef;  typedef Ref<BitwiseNot,Node> BitwiseNotRef;
796    
797  class ParserContext : public VMParserContext {  class Final FINAL : virtual public IntExpr, virtual public RealExpr {
798        ScalarNumberExprRef expr;
799    public:
800        Final(ScalarNumberExprRef expr) : expr(expr) {}
801        ExprType_t exprType() const OVERRIDE { return expr->exprType(); }
802        vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); }
803        vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); }
804        String evalCastToStr() OVERRIDE;
805        void dump(int level = 0) OVERRIDE;
806        bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); }
807        bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); }
808        MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); }
809        StdUnit_t unitType() const OVERRIDE { return expr->unitType(); }
810        bool isFinal() const OVERRIDE { return true; }
811    };
812    typedef Ref<Final,Node> FinalRef;
813    
814    class ParserContext FINAL : public VMParserContext {
815  public:  public:
816      struct Error {      struct Error {
817          String txt;          String txt;
# Line 636  public: Line 832  public:
832      std::map<String,VariableRef> vartable;      std::map<String,VariableRef> vartable;
833      std::map<String,StatementsRef> userFnTable;      std::map<String,StatementsRef> userFnTable;
834      vmint globalIntVarCount;      vmint globalIntVarCount;
835        vmint globalRealVarCount;
836      vmint globalStrVarCount;      vmint globalStrVarCount;
837      vmint polyphonicIntVarCount;      vmint polyphonicIntVarCount;
838        vmint polyphonicRealVarCount;
839    
840      EventHandlersRef handlers;      EventHandlersRef handlers;
841    
# Line 647  public: Line 845  public:
845      OnControllerRef onController;      OnControllerRef onController;
846    
847      ArrayList<vmint>* globalIntMemory;      ArrayList<vmint>* globalIntMemory;
848        ArrayList<vmfloat>* globalRealMemory;
849      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
850      vmint requiredMaxStackSize;      vmint requiredMaxStackSize;
851    
# Line 656  public: Line 855  public:
855    
856      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
857          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
858          globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),          globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0),
859          globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1),          polyphonicIntVarCount(0), polyphonicRealVarCount(0),
860            globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL),
861            requiredMaxStackSize(-1),
862          functionProvider(parent), execContext(NULL)          functionProvider(parent), execContext(NULL)
863      {      {
864      }      }
865      virtual ~ParserContext();      virtual ~ParserContext();
866      VariableRef globalVar(const String& name);      VariableRef globalVar(const String& name);
867      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
868        RealVariableRef globalRealVar(const String& name);
869      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
870      VariableRef variableByName(const String& name);      VariableRef variableByName(const String& name);
871      StatementsRef userFunctionByName(const String& name);      StatementsRef userFunctionByName(const String& name);
# Line 687  public: Line 889  public:
889      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);      void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
890  };  };
891    
892  class ExecContext : public VMExecContext {  class ExecContext FINAL : public VMExecContext {
893  public:  public:
894      struct StackFrame {      struct StackFrame {
895          Statement* statement;          Statement* statement;
# Line 700  public: Line 902  public:
902      };      };
903    
904      ArrayList<vmint> polyphonicIntMemory;      ArrayList<vmint> polyphonicIntMemory;
905        ArrayList<vmfloat> polyphonicRealMemory;
906      VMExecStatus_t status;      VMExecStatus_t status;
907      StmtFlags_t flags;      StmtFlags_t flags;
908      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
# Line 748  public: Line 951  public:
951      }      }
952    
953      void resetPolyphonicData() OVERRIDE {      void resetPolyphonicData() OVERRIDE {
954          if (polyphonicIntMemory.empty()) return;          if (!polyphonicIntMemory.empty())
955          memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));              memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint));
956            if (!polyphonicRealMemory.empty())
957                memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat));
958      }      }
959    
960      size_t instructionsPerformed() const OVERRIDE {      size_t instructionsPerformed() const OVERRIDE {

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

  ViewVC Help
Powered by ViewVC