/[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 2588 by schoenebeck, Sun Jun 1 14:44:38 2014 UTC revision 3551 by schoenebeck, Thu Aug 1 10:22:56 2019 UTC
# Line 1  Line 1 
1  /*                                                              -*- c++ -*-  /*                                                              -*- c++ -*-
2   *   *
3   * Copyright (c) 2014 Christian Schoenebeck and Andreas Persson   * Copyright (c) 2014 - 2019 Christian Schoenebeck and Andreas Persson
4   *   *
5   * http://www.linuxsampler.org   * http://www.linuxsampler.org
6   *   *
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <map>  #include <map>
22  #include <set>  #include <set>
23    #include <string.h> // for memset()
24  #include "../common/global.h"  #include "../common/global.h"
25  #include "../common/Ref.h"  #include "../common/Ref.h"
26  #include "../common/ArrayList.h"  #include "../common/ArrayList.h"
# Line 35  enum StmtType_t { Line 36  enum StmtType_t {
36      STMT_LIST,      STMT_LIST,
37      STMT_BRANCH,      STMT_BRANCH,
38      STMT_LOOP,      STMT_LOOP,
39        STMT_SYNC,
40        STMT_NOOP,
41  };  };
42    
43  class Node {  class Node {
# Line 42  public: Line 45  public:
45      Node();      Node();
46      virtual ~Node();      virtual ~Node();
47      virtual void dump(int level = 0) = 0;      virtual void dump(int level = 0) = 0;
48        virtual bool isPolyphonic() const = 0;
49      void printIndents(int n);      void printIndents(int n);
50  };  };
51  typedef Ref<Node> NodeRef;  typedef Ref<Node> NodeRef;
# Line 62  public: Line 66  public:
66  };  };
67  typedef Ref<IntExpr,Node> IntExprRef;  typedef Ref<IntExpr,Node> IntExprRef;
68    
69    class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression {
70    public:
71        ExprType_t exprType() const { return INT_ARR_EXPR; }
72        String evalCastToStr();
73    };
74    typedef Ref<IntArrayExpr,Node> IntArrayExprRef;
75    
76  class StringExpr : virtual public VMStringExpr, virtual public Expression {  class StringExpr : virtual public VMStringExpr, virtual public Expression {
77  public:  public:
78      ExprType_t exprType() const { return STRING_EXPR; }      ExprType_t exprType() const { return STRING_EXPR; }
# Line 71  public: Line 82  public:
82  typedef Ref<StringExpr,Node> StringExprRef;  typedef Ref<StringExpr,Node> StringExprRef;
83    
84  class IntLiteral : virtual public IntExpr {  class IntLiteral : virtual public IntExpr {
     int value;  
85  public:  public:
86        int value;
87      IntLiteral(int value) : value(value) { }      IntLiteral(int value) : value(value) { }
88      int evalInt();      int evalInt();
89      void dump(int level = 0);      void dump(int level = 0);
90      bool isConstExpr() const { return true; }      bool isConstExpr() const { return true; }
91        bool isPolyphonic() const { return false; }
92  };  };
93  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
94    
# Line 87  public: Line 99  public:
99      bool isConstExpr() const { return true; }      bool isConstExpr() const { return true; }
100      void dump(int level = 0);      void dump(int level = 0);
101      String evalStr() { return value; }      String evalStr() { return value; }
102        bool isPolyphonic() const { return false; }
103  };  };
104  typedef Ref<StringLiteral,Node> StringLiteralRef;  typedef Ref<StringLiteral,Node> StringLiteralRef;
105    
# Line 95  public: Line 108  public:
108      std::vector<ExpressionRef> args;      std::vector<ExpressionRef> args;
109      void add(ExpressionRef arg) { args.push_back(arg); }      void add(ExpressionRef arg) { args.push_back(arg); }
110      void dump(int level = 0);      void dump(int level = 0);
111      int argsCount() const { return args.size(); }      int argsCount() const { return (int) args.size(); }
112      VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; }      VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; }
113        bool isPolyphonic() const;
114  };  };
115  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
116    
117  class Variable : virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
118  public:  public:
119      virtual bool isConstExpr() const { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
120        bool isAssignable() const OVERRIDE { return !bConst; }
121      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
122        void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }
123  protected:  protected:
124      Variable(ParserContext* ctx, int _memPos, bool _bConst)      Variable(ParserContext* ctx, int _memPos, bool _bConst)
125          : context(ctx), memPos(_memPos), bConst(_bConst) {}          : context(ctx), memPos(_memPos), bConst(_bConst) {}
# Line 139  public: Line 155  public:
155  };  };
156  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
157    
158    class BuiltInIntVariable : public IntVariable {
159        String name;
160        VMIntRelPtr* ptr;
161    public:
162        BuiltInIntVariable(const String& name, VMIntRelPtr* ptr);
163        bool isAssignable() const OVERRIDE { return !ptr->readonly; }
164        void assign(Expression* expr) OVERRIDE;
165        int evalInt() OVERRIDE;
166        void dump(int level = 0) OVERRIDE;
167    };
168    typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
169    
170  class PolyphonicIntVariable : public IntVariable {  class PolyphonicIntVariable : public IntVariable {
171  public:  public:
172      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(ParserContext* ctx);
# Line 146  public: Line 174  public:
174  };  };
175  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
176    
177  class IntArrayVariable : public Variable {  class IntArrayVariable : public Variable, virtual public IntArrayExpr {
178      ArrayList<int> values;      ArrayList<int> values;
179  public:  public:
180      IntArrayVariable(ParserContext* ctx, int size);      IntArrayVariable(ParserContext* ctx, int size);
181      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values);      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst = false);
182      void assign(Expression* expr) {} // ignore scalar assignment      void assign(Expression* expr) {} // ignore scalar assignment
183      String evalCastToStr() { return ""; } // ignore cast to string      String evalCastToStr() { return ""; } // ignore scalar cast to string
184      ExprType_t exprType() const { return INT_ARR_EXPR; }      ExprType_t exprType() const { return INT_ARR_EXPR; }
185      const int arraySize() const { return values.size(); }      virtual int arraySize() const { return values.size(); }
186      int evalIntElement(uint i);      virtual int evalIntElement(uint i);
187      void assignIntElement(uint i, int value);      virtual void assignIntElement(uint i, int value);
188      void dump(int level = 0);      void dump(int level = 0);
189        bool isPolyphonic() const { return false; }
190    protected:
191        IntArrayVariable(ParserContext* ctx, bool bConst);
192  };  };
193  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
194    
195    class BuiltInIntArrayVariable : public IntArrayVariable {
196        String name;
197        VMInt8Array* array;
198    public:
199        BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
200        int arraySize() const OVERRIDE { return array->size; }
201        int evalIntElement(uint i) OVERRIDE;
202        bool isAssignable() const OVERRIDE { return !array->readonly; }
203        void assignIntElement(uint i, int value) OVERRIDE;
204        void dump(int level = 0) OVERRIDE;
205    };
206    typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
207    
208  class IntArrayElement : public IntVariable {  class IntArrayElement : public IntVariable {
209      IntArrayVariableRef array;      IntArrayExprRef array;
210      IntExprRef index;      IntExprRef index;
211  public:  public:
212      IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex);      IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex);
213      void assign(Expression* expr);      void assign(Expression* expr);
214      int evalInt();      int evalInt();
215      void dump(int level = 0);      void dump(int level = 0);
# Line 178  public: Line 222  public:
222      void assign(Expression* expr);      void assign(Expression* expr);
223      String evalStr();      String evalStr();
224      void dump(int level = 0);      void dump(int level = 0);
225        bool isPolyphonic() const { return false; }
226  protected:  protected:
227      StringVariable(ParserContext* ctx, bool bConst);      StringVariable(ParserContext* ctx, bool bConst);
228  };  };
# Line 201  protected: Line 246  protected:
246  public:  public:
247      BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }      BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }
248      bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }      bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }
249        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
250  };  };
251  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
252    
# Line 255  typedef Ref<Statement,Node> StatementRef Line 301  typedef Ref<Statement,Node> StatementRef
301  class NoOperation : public Statement {  class NoOperation : public Statement {
302  public:  public:
303      NoOperation() : Statement() {}      NoOperation() : Statement() {}
304      StmtType_t statementType() const { return STMT_LEAF; }      StmtType_t statementType() const { return STMT_NOOP; }
305      void dump(int level = 0) {}      void dump(int level = 0) {}
306        bool isPolyphonic() const { return false; }
307  };  };
308  typedef Ref<NoOperation,Node> NoOperationRef;  typedef Ref<NoOperation,Node> NoOperationRef;
309    
# Line 276  public: Line 323  public:
323      void dump(int level = 0);      void dump(int level = 0);
324      StmtType_t statementType() const { return STMT_LIST; }      StmtType_t statementType() const { return STMT_LIST; }
325      virtual Statement* statement(uint i);      virtual Statement* statement(uint i);
326        bool isPolyphonic() const;
327  };  };
328  typedef Ref<Statements,Node> StatementsRef;  typedef Ref<Statements,Node> StatementsRef;
329    
# Line 286  public: Line 334  public:
334      virtual Statements* branch(uint i) const = 0;      virtual Statements* branch(uint i) const = 0;
335  };  };
336    
337    class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr, virtual public IntArrayExpr {
338        VMDynVar* dynVar;
339        String varName;
340    public:
341        DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v);
342        ExprType_t exprType() const OVERRIDE { return dynVar->exprType(); }
343        bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); }
344        bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); }
345        bool isPolyphonic() const OVERRIDE { return false; }
346        void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); }
347        VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); }
348        int evalInt() OVERRIDE;
349        String evalStr() OVERRIDE;
350        String evalCastToStr() OVERRIDE;
351        int arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); }
352        int evalIntElement(uint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); }
353        void assignIntElement(uint i, int value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); }
354        void dump(int level = 0) OVERRIDE;
355    };
356    typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
357    
358  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {
359      String functionName;      String functionName;
360      ArgsRef args;      ArgsRef args;
# Line 293  class FunctionCall : virtual public Leaf Line 362  class FunctionCall : virtual public Leaf
362  public:  public:
363      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :      FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :
364          functionName(function), args(args), fn(fn) { }          functionName(function), args(args), fn(fn) { }
365      void dump(int level = 0);      void dump(int level = 0) OVERRIDE;
366      StmtFlags_t exec();      StmtFlags_t exec() OVERRIDE;
367      int evalInt();      int evalInt() OVERRIDE;
368      String evalStr();      VMIntArrayExpr* asIntArray() const OVERRIDE;
369      bool isConstExpr() const { return false; }      String evalStr() OVERRIDE;
370      ExprType_t exprType() const;      bool isConstExpr() const OVERRIDE { return false; }
371      String evalCastToStr();      ExprType_t exprType() const OVERRIDE;
372        String evalCastToStr() OVERRIDE;
373        bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
374  protected:  protected:
375      VMFnResult* execVMFn();      VMFnResult* execVMFn();
376  };  };
377  typedef Ref<FunctionCall,Node> FunctionCallRef;  typedef Ref<FunctionCall,Node> FunctionCallRef;
378    
379    class NoFunctionCall : public FunctionCall {
380    public:
381        NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {}
382        StmtType_t statementType() const { return STMT_NOOP; }
383    };
384    typedef Ref<NoFunctionCall,Node> NoFunctionCallRef;
385    
386  class EventHandler : virtual public Statements, virtual public VMEventHandler {  class EventHandler : virtual public Statements, virtual public VMEventHandler {
387      StatementsRef statements;      StatementsRef statements;
388        bool usingPolyphonics;
389  public:  public:
390      void dump(int level = 0);      void dump(int level = 0);
391      StmtFlags_t exec();      StmtFlags_t exec();
392      EventHandler(StatementsRef statements) { this->statements = statements; }      EventHandler(StatementsRef statements);
393      Statement* statement(uint i) { return statements->statement(i); }      Statement* statement(uint i) { return statements->statement(i); }
394        bool isPolyphonic() const { return usingPolyphonics; }
395  };  };
396  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
397    
398  class OnNote : public EventHandler {  class OnNote : public EventHandler {
399  public:  public:
400      OnNote(StatementsRef statements) : EventHandler(statements) {}      OnNote(StatementsRef statements) : EventHandler(statements) {}
401        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; }
402      String eventHandlerName() const { return "note"; }      String eventHandlerName() const { return "note"; }
403  };  };
404  typedef Ref<OnNote,Node> OnNoteRef;  typedef Ref<OnNote,Node> OnNoteRef;
# Line 325  typedef Ref<OnNote,Node> OnNoteRef; Line 406  typedef Ref<OnNote,Node> OnNoteRef;
406  class OnInit : public EventHandler {  class OnInit : public EventHandler {
407  public:  public:
408      OnInit(StatementsRef statements) : EventHandler(statements) {}      OnInit(StatementsRef statements) : EventHandler(statements) {}
409        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; }
410      String eventHandlerName() const { return "init"; }      String eventHandlerName() const { return "init"; }
411  };  };
412  typedef Ref<OnInit,Node> OnInitRef;  typedef Ref<OnInit,Node> OnInitRef;
# Line 332  typedef Ref<OnInit,Node> OnInitRef; Line 414  typedef Ref<OnInit,Node> OnInitRef;
414  class OnRelease : public EventHandler {  class OnRelease : public EventHandler {
415  public:  public:
416      OnRelease(StatementsRef statements) : EventHandler(statements) {}      OnRelease(StatementsRef statements) : EventHandler(statements) {}
417        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; }
418      String eventHandlerName() const { return "release"; }      String eventHandlerName() const { return "release"; }
419  };  };
420  typedef Ref<OnRelease,Node> OnReleaseRef;  typedef Ref<OnRelease,Node> OnReleaseRef;
# Line 339  typedef Ref<OnRelease,Node> OnReleaseRef Line 422  typedef Ref<OnRelease,Node> OnReleaseRef
422  class OnController : public EventHandler {  class OnController : public EventHandler {
423  public:  public:
424      OnController(StatementsRef statements) : EventHandler(statements) {}      OnController(StatementsRef statements) : EventHandler(statements) {}
425        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; }
426      String eventHandlerName() const { return "controller"; }      String eventHandlerName() const { return "controller"; }
427  };  };
428  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
# Line 353  public: Line 437  public:
437      int evalInt() { return 0; }      int evalInt() { return 0; }
438      EventHandler* eventHandlerByName(const String& name) const;      EventHandler* eventHandlerByName(const String& name) const;
439      EventHandler* eventHandler(uint index) const;      EventHandler* eventHandler(uint index) const;
440      inline uint size() const { return args.size(); }      inline uint size() const { return (int) args.size(); }
441        bool isPolyphonic() const;
442  };  };
443  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
444    
# Line 365  public: Line 450  public:
450      Assignment(VariableRef variable, ExpressionRef value);      Assignment(VariableRef variable, ExpressionRef value);
451      void dump(int level = 0);      void dump(int level = 0);
452      StmtFlags_t exec();      StmtFlags_t exec();
453        bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); }
454  };  };
455  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
456    
# Line 380  public: Line 466  public:
466      void dump(int level = 0);      void dump(int level = 0);
467      int evalBranch();      int evalBranch();
468      Statements* branch(uint i) const;      Statements* branch(uint i) const;
469        bool isPolyphonic() const;
470  };  };
471  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
472    
# Line 403  public: Line 490  public:
490      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);
491      //void addBranch(CaseBranchRef branch);      //void addBranch(CaseBranchRef branch);
492      //void addBranches(CaseBranchesRef branches);      //void addBranches(CaseBranchesRef branches);
493        bool isPolyphonic() const;
494  };  };
495  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
496    
# Line 416  public: Line 504  public:
504      void dump(int level = 0);      void dump(int level = 0);
505      bool evalLoopStartCondition();      bool evalLoopStartCondition();
506      Statements* statements() const;      Statements* statements() const;
507        bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
508    };
509    
510    class SyncBlock : public Statement {
511        StatementsRef m_statements;
512    public:
513        SyncBlock(StatementsRef statements) : m_statements(statements) {}
514        StmtType_t statementType() const { return STMT_SYNC; }
515        void dump(int level = 0);
516        Statements* statements() const;
517        bool isPolyphonic() const { return m_statements->isPolyphonic(); }
518  };  };
519    typedef Ref<SyncBlock,Node> SyncBlockRef;
520    
521  class Neg : public IntExpr {  class Neg : public IntExpr {
522      IntExprRef expr;      IntExprRef expr;
# Line 425  public: Line 525  public:
525      int evalInt() { return (expr) ? -expr->evalInt() : 0; }      int evalInt() { return (expr) ? -expr->evalInt() : 0; }
526      void dump(int level = 0);      void dump(int level = 0);
527      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
528        bool isPolyphonic() const { return expr->isPolyphonic(); }
529  };  };
530  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
531    
# Line 436  public: Line 537  public:
537      String evalStr();      String evalStr();
538      void dump(int level = 0);      void dump(int level = 0);
539      bool isConstExpr() const;      bool isConstExpr() const;
540        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
541  };  };
542  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
543    
# Line 454  public: Line 556  public:
556      int evalInt();      int evalInt();
557      void dump(int level = 0);      void dump(int level = 0);
558      bool isConstExpr() const;      bool isConstExpr() const;
559        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
560  private:  private:
561      IntExprRef lhs;      IntExprRef lhs;
562      IntExprRef rhs;      IntExprRef rhs;
# Line 469  public: Line 572  public:
572  };  };
573  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
574    
575    class BitwiseOr : virtual public BinaryOp, virtual public IntExpr {
576    public:
577        BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
578        int evalInt();
579        void dump(int level = 0);
580    };
581    typedef Ref<BitwiseOr,Node> BitwiseOrRef;
582    
583  class And : virtual public BinaryOp, virtual public IntExpr {  class And : virtual public BinaryOp, virtual public IntExpr {
584  public:  public:
585      And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
# Line 477  public: Line 588  public:
588  };  };
589  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
590    
591    class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr {
592    public:
593        BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
594        int evalInt();
595        void dump(int level = 0);
596    };
597    typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
598    
599  class Not : virtual public IntExpr {  class Not : virtual public IntExpr {
600      IntExprRef expr;      IntExprRef expr;
601  public:  public:
# Line 484  public: Line 603  public:
603      int evalInt() { return !expr->evalInt(); }      int evalInt() { return !expr->evalInt(); }
604      void dump(int level = 0);      void dump(int level = 0);
605      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
606        bool isPolyphonic() const { return expr->isPolyphonic(); }
607  };  };
608  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
609    
610    class BitwiseNot : virtual public IntExpr {
611        IntExprRef expr;
612    public:
613        BitwiseNot(IntExprRef expr) : expr(expr) {}
614        int evalInt() { return ~expr->evalInt(); }
615        void dump(int level = 0);
616        bool isConstExpr() const { return expr->isConstExpr(); }
617        bool isPolyphonic() const { return expr->isPolyphonic(); }
618    };
619    typedef Ref<BitwiseNot,Node> BitwiseNotRef;
620    
621  class ParserContext : public VMParserContext {  class ParserContext : public VMParserContext {
622  public:  public:
623      struct Error {      struct Error {
# Line 500  public: Line 631  public:
631      std::vector<ParserIssue> vErrors;      std::vector<ParserIssue> vErrors;
632      std::vector<ParserIssue> vWarnings;      std::vector<ParserIssue> vWarnings;
633      std::vector<ParserIssue> vIssues;      std::vector<ParserIssue> vIssues;
634        std::vector<CodeBlock>   vPreprocessorComments;
635    
636      std::set<String> builtinPreprocessorConditions;      std::set<String> builtinPreprocessorConditions;
637      std::set<String> userPreprocessorConditions;      std::set<String> userPreprocessorConditions;
638    
639      std::map<String,VariableRef> vartable;      std::map<String,VariableRef> vartable;
640        std::map<String,StatementsRef> userFnTable;
641      int globalIntVarCount;      int globalIntVarCount;
642      int globalStrVarCount;      int globalStrVarCount;
643      int polyphonicIntVarCount;      int polyphonicIntVarCount;
# Line 536  public: Line 669  public:
669      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
670      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
671      VariableRef variableByName(const String& name);      VariableRef variableByName(const String& name);
672      void addErr(int line, const char* txt);      StatementsRef userFunctionByName(const String& name);
673      void addWrn(int line, const char* txt);      void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
674        void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
675        void addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn);
676      void createScanner(std::istream* is);      void createScanner(std::istream* is);
677      void destroyScanner();      void destroyScanner();
678      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
# Line 546  public: Line 681  public:
681      std::vector<ParserIssue> issues() const OVERRIDE;      std::vector<ParserIssue> issues() const OVERRIDE;
682      std::vector<ParserIssue> errors() const OVERRIDE;      std::vector<ParserIssue> errors() const OVERRIDE;
683      std::vector<ParserIssue> warnings() const OVERRIDE;      std::vector<ParserIssue> warnings() const OVERRIDE;
684        std::vector<CodeBlock> preprocessorComments() const OVERRIDE;
685      VMEventHandler* eventHandler(uint index) OVERRIDE;      VMEventHandler* eventHandler(uint index) OVERRIDE;
686      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;      VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
687        void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
688        void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);
689        void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
690        void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
691  };  };
692    
693  class ExecContext : public VMExecContext {  class ExecContext : public VMExecContext {
# Line 564  public: Line 704  public:
704    
705      ArrayList<int> polyphonicIntMemory;      ArrayList<int> polyphonicIntMemory;
706      VMExecStatus_t status;      VMExecStatus_t status;
707        StmtFlags_t flags;
708      ArrayList<StackFrame> stack;      ArrayList<StackFrame> stack;
709      int stackFrame;      int stackFrame;
710      int suspendMicroseconds;      int suspendMicroseconds;
711        size_t instructionsCount;
712        struct ExitRes {
713            Expression* value;
714            IntLiteral intLiteral;
715            StringLiteral stringLiteral;
716    
717      ExecContext() :          ExitRes() : intLiteral(0), stringLiteral("") { }
718          status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {}      } exitRes;
719    
720        ExecContext();
721      virtual ~ExecContext() {}      virtual ~ExecContext() {}
722    
723      inline void pushStack(Statement* stmt) {      inline void pushStack(Statement* stmt) {
# Line 592  public: Line 739  public:
739          stack[0].statement = NULL;          stack[0].statement = NULL;
740          stack[0].subindex  = -1;          stack[0].subindex  = -1;
741          stackFrame = -1;          stackFrame = -1;
742            flags = STMT_SUCCESS;
743        }
744    
745        inline void clearExitRes() {
746            exitRes.value = NULL;
747      }      }
748    
749      int suspensionTimeMicroseconds() const OVERRIDE {      int suspensionTimeMicroseconds() const OVERRIDE {
750          return suspendMicroseconds;          return suspendMicroseconds;
751      }      }
752    
753        void resetPolyphonicData() OVERRIDE {
754            if (polyphonicIntMemory.empty()) return;
755            memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int));
756        }
757    
758        size_t instructionsPerformed() const OVERRIDE {
759            return instructionsCount;
760        }
761    
762        void signalAbort() OVERRIDE {
763            flags = StmtFlags_t(flags | STMT_ABORT_SIGNALLED);
764        }
765    
766        void forkTo(VMExecContext* ectx) const OVERRIDE;
767    
768        VMExpr* exitResult() OVERRIDE {
769            return exitRes.value;
770        }
771  };  };
772    
773  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2588  
changed lines
  Added in v.3551

  ViewVC Help
Powered by ViewVC