/[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 2619 by schoenebeck, Wed Jun 11 13:24:32 2014 UTC revision 2879 by schoenebeck, Tue Apr 19 14:07:53 2016 UTC
# Line 1  Line 1 
1  /*                                                              -*- c++ -*-  /*                                                              -*- c++ -*-
2   *   *
3   * Copyright (c) 2014 Christian Schoenebeck and Andreas Persson   * Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson
4   *   *
5   * http://www.linuxsampler.org   * http://www.linuxsampler.org
6   *   *
# Line 42  public: Line 42  public:
42      Node();      Node();
43      virtual ~Node();      virtual ~Node();
44      virtual void dump(int level = 0) = 0;      virtual void dump(int level = 0) = 0;
45        virtual bool isPolyphonic() const = 0;
46      void printIndents(int n);      void printIndents(int n);
47  };  };
48  typedef Ref<Node> NodeRef;  typedef Ref<Node> NodeRef;
# Line 77  public: Line 78  public:
78      int evalInt();      int evalInt();
79      void dump(int level = 0);      void dump(int level = 0);
80      bool isConstExpr() const { return true; }      bool isConstExpr() const { return true; }
81        bool isPolyphonic() const { return false; }
82  };  };
83  typedef Ref<IntLiteral,Node> IntLiteralRef;  typedef Ref<IntLiteral,Node> IntLiteralRef;
84    
# Line 87  public: Line 89  public:
89      bool isConstExpr() const { return true; }      bool isConstExpr() const { return true; }
90      void dump(int level = 0);      void dump(int level = 0);
91      String evalStr() { return value; }      String evalStr() { return value; }
92        bool isPolyphonic() const { return false; }
93  };  };
94  typedef Ref<StringLiteral,Node> StringLiteralRef;  typedef Ref<StringLiteral,Node> StringLiteralRef;
95    
# Line 97  public: Line 100  public:
100      void dump(int level = 0);      void dump(int level = 0);
101      int argsCount() const { return args.size(); }      int argsCount() const { return args.size(); }
102      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; }
103        bool isPolyphonic() const;
104  };  };
105  typedef Ref<Args,Node> ArgsRef;  typedef Ref<Args,Node> ArgsRef;
106    
# Line 169  public: Line 173  public:
173      virtual int evalIntElement(uint i);      virtual int evalIntElement(uint i);
174      virtual void assignIntElement(uint i, int value);      virtual void assignIntElement(uint i, int value);
175      void dump(int level = 0);      void dump(int level = 0);
176        bool isPolyphonic() const { return false; }
177  protected:  protected:
178      IntArrayVariable(ParserContext* ctx, bool bConst);      IntArrayVariable(ParserContext* ctx, bool bConst);
179  };  };
# Line 203  public: Line 208  public:
208      void assign(Expression* expr);      void assign(Expression* expr);
209      String evalStr();      String evalStr();
210      void dump(int level = 0);      void dump(int level = 0);
211        bool isPolyphonic() const { return false; }
212  protected:  protected:
213      StringVariable(ParserContext* ctx, bool bConst);      StringVariable(ParserContext* ctx, bool bConst);
214  };  };
# Line 226  protected: Line 232  protected:
232  public:  public:
233      BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }      BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }
234      bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }      bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }
235        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
236  };  };
237  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
238    
# Line 282  public: Line 289  public:
289      NoOperation() : Statement() {}      NoOperation() : Statement() {}
290      StmtType_t statementType() const { return STMT_LEAF; }      StmtType_t statementType() const { return STMT_LEAF; }
291      void dump(int level = 0) {}      void dump(int level = 0) {}
292        bool isPolyphonic() const { return false; }
293  };  };
294  typedef Ref<NoOperation,Node> NoOperationRef;  typedef Ref<NoOperation,Node> NoOperationRef;
295    
# Line 301  public: Line 309  public:
309      void dump(int level = 0);      void dump(int level = 0);
310      StmtType_t statementType() const { return STMT_LIST; }      StmtType_t statementType() const { return STMT_LIST; }
311      virtual Statement* statement(uint i);      virtual Statement* statement(uint i);
312        bool isPolyphonic() const;
313  };  };
314  typedef Ref<Statements,Node> StatementsRef;  typedef Ref<Statements,Node> StatementsRef;
315    
# Line 325  public: Line 334  public:
334      bool isConstExpr() const { return false; }      bool isConstExpr() const { return false; }
335      ExprType_t exprType() const;      ExprType_t exprType() const;
336      String evalCastToStr();      String evalCastToStr();
337        bool isPolyphonic() const { return args->isPolyphonic(); }
338  protected:  protected:
339      VMFnResult* execVMFn();      VMFnResult* execVMFn();
340  };  };
# Line 332  typedef Ref<FunctionCall,Node> FunctionC Line 342  typedef Ref<FunctionCall,Node> FunctionC
342    
343  class EventHandler : virtual public Statements, virtual public VMEventHandler {  class EventHandler : virtual public Statements, virtual public VMEventHandler {
344      StatementsRef statements;      StatementsRef statements;
345        bool usingPolyphonics;
346  public:  public:
347      void dump(int level = 0);      void dump(int level = 0);
348      StmtFlags_t exec();      StmtFlags_t exec();
349      EventHandler(StatementsRef statements) { this->statements = statements; }      EventHandler(StatementsRef statements);
350      Statement* statement(uint i) { return statements->statement(i); }      Statement* statement(uint i) { return statements->statement(i); }
351        bool isPolyphonic() const { return usingPolyphonics; }
352  };  };
353  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
354    
355  class OnNote : public EventHandler {  class OnNote : public EventHandler {
356  public:  public:
357      OnNote(StatementsRef statements) : EventHandler(statements) {}      OnNote(StatementsRef statements) : EventHandler(statements) {}
358        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; }
359      String eventHandlerName() const { return "note"; }      String eventHandlerName() const { return "note"; }
360  };  };
361  typedef Ref<OnNote,Node> OnNoteRef;  typedef Ref<OnNote,Node> OnNoteRef;
# Line 350  typedef Ref<OnNote,Node> OnNoteRef; Line 363  typedef Ref<OnNote,Node> OnNoteRef;
363  class OnInit : public EventHandler {  class OnInit : public EventHandler {
364  public:  public:
365      OnInit(StatementsRef statements) : EventHandler(statements) {}      OnInit(StatementsRef statements) : EventHandler(statements) {}
366        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; }
367      String eventHandlerName() const { return "init"; }      String eventHandlerName() const { return "init"; }
368  };  };
369  typedef Ref<OnInit,Node> OnInitRef;  typedef Ref<OnInit,Node> OnInitRef;
# Line 357  typedef Ref<OnInit,Node> OnInitRef; Line 371  typedef Ref<OnInit,Node> OnInitRef;
371  class OnRelease : public EventHandler {  class OnRelease : public EventHandler {
372  public:  public:
373      OnRelease(StatementsRef statements) : EventHandler(statements) {}      OnRelease(StatementsRef statements) : EventHandler(statements) {}
374        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; }
375      String eventHandlerName() const { return "release"; }      String eventHandlerName() const { return "release"; }
376  };  };
377  typedef Ref<OnRelease,Node> OnReleaseRef;  typedef Ref<OnRelease,Node> OnReleaseRef;
# Line 364  typedef Ref<OnRelease,Node> OnReleaseRef Line 379  typedef Ref<OnRelease,Node> OnReleaseRef
379  class OnController : public EventHandler {  class OnController : public EventHandler {
380  public:  public:
381      OnController(StatementsRef statements) : EventHandler(statements) {}      OnController(StatementsRef statements) : EventHandler(statements) {}
382        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; }
383      String eventHandlerName() const { return "controller"; }      String eventHandlerName() const { return "controller"; }
384  };  };
385  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
# Line 379  public: Line 395  public:
395      EventHandler* eventHandlerByName(const String& name) const;      EventHandler* eventHandlerByName(const String& name) const;
396      EventHandler* eventHandler(uint index) const;      EventHandler* eventHandler(uint index) const;
397      inline uint size() const { return args.size(); }      inline uint size() const { return args.size(); }
398        bool isPolyphonic() const;
399  };  };
400  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
401    
# Line 390  public: Line 407  public:
407      Assignment(VariableRef variable, ExpressionRef value);      Assignment(VariableRef variable, ExpressionRef value);
408      void dump(int level = 0);      void dump(int level = 0);
409      StmtFlags_t exec();      StmtFlags_t exec();
410        bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); }
411  };  };
412  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
413    
# Line 405  public: Line 423  public:
423      void dump(int level = 0);      void dump(int level = 0);
424      int evalBranch();      int evalBranch();
425      Statements* branch(uint i) const;      Statements* branch(uint i) const;
426        bool isPolyphonic() const;
427  };  };
428  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
429    
# Line 428  public: Line 447  public:
447      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);
448      //void addBranch(CaseBranchRef branch);      //void addBranch(CaseBranchRef branch);
449      //void addBranches(CaseBranchesRef branches);      //void addBranches(CaseBranchesRef branches);
450        bool isPolyphonic() const;
451  };  };
452  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
453    
# Line 441  public: Line 461  public:
461      void dump(int level = 0);      void dump(int level = 0);
462      bool evalLoopStartCondition();      bool evalLoopStartCondition();
463      Statements* statements() const;      Statements* statements() const;
464        bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
465  };  };
466    
467  class Neg : public IntExpr {  class Neg : public IntExpr {
# Line 450  public: Line 471  public:
471      int evalInt() { return (expr) ? -expr->evalInt() : 0; }      int evalInt() { return (expr) ? -expr->evalInt() : 0; }
472      void dump(int level = 0);      void dump(int level = 0);
473      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
474        bool isPolyphonic() const { return expr->isPolyphonic(); }
475  };  };
476  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
477    
# Line 461  public: Line 483  public:
483      String evalStr();      String evalStr();
484      void dump(int level = 0);      void dump(int level = 0);
485      bool isConstExpr() const;      bool isConstExpr() const;
486        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
487  };  };
488  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
489    
# Line 479  public: Line 502  public:
502      int evalInt();      int evalInt();
503      void dump(int level = 0);      void dump(int level = 0);
504      bool isConstExpr() const;      bool isConstExpr() const;
505        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
506  private:  private:
507      IntExprRef lhs;      IntExprRef lhs;
508      IntExprRef rhs;      IntExprRef rhs;
# Line 509  public: Line 533  public:
533      int evalInt() { return !expr->evalInt(); }      int evalInt() { return !expr->evalInt(); }
534      void dump(int level = 0);      void dump(int level = 0);
535      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
536        bool isPolyphonic() const { return expr->isPolyphonic(); }
537  };  };
538  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
539    

Legend:
Removed from v.2619  
changed lines
  Added in v.2879

  ViewVC Help
Powered by ViewVC