/[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 2945 by schoenebeck, Thu Jul 14 00:22:26 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    
107  class Variable : virtual public Expression {  class Variable : virtual public VMVariable, virtual public Expression {
108  public:  public:
109      virtual bool isConstExpr() const { return bConst; }      bool isConstExpr() const OVERRIDE { return bConst; }
110        bool isAssignable() const OVERRIDE { return !bConst; }
111      virtual void assign(Expression* expr) = 0;      virtual void assign(Expression* expr) = 0;
112        void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }
113  protected:  protected:
114      Variable(ParserContext* ctx, int _memPos, bool _bConst)      Variable(ParserContext* ctx, int _memPos, bool _bConst)
115          : context(ctx), memPos(_memPos), bConst(_bConst) {}          : context(ctx), memPos(_memPos), bConst(_bConst) {}
# Line 169  public: Line 175  public:
175      virtual int evalIntElement(uint i);      virtual int evalIntElement(uint i);
176      virtual void assignIntElement(uint i, int value);      virtual void assignIntElement(uint i, int value);
177      void dump(int level = 0);      void dump(int level = 0);
178        bool isPolyphonic() const { return false; }
179  protected:  protected:
180      IntArrayVariable(ParserContext* ctx, bool bConst);      IntArrayVariable(ParserContext* ctx, bool bConst);
181  };  };
# Line 203  public: Line 210  public:
210      void assign(Expression* expr);      void assign(Expression* expr);
211      String evalStr();      String evalStr();
212      void dump(int level = 0);      void dump(int level = 0);
213        bool isPolyphonic() const { return false; }
214  protected:  protected:
215      StringVariable(ParserContext* ctx, bool bConst);      StringVariable(ParserContext* ctx, bool bConst);
216  };  };
# Line 226  protected: Line 234  protected:
234  public:  public:
235      BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }      BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }
236      bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }      bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }
237        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
238  };  };
239  typedef Ref<BinaryOp,Node> BinaryOpRef;  typedef Ref<BinaryOp,Node> BinaryOpRef;
240    
# Line 282  public: Line 291  public:
291      NoOperation() : Statement() {}      NoOperation() : Statement() {}
292      StmtType_t statementType() const { return STMT_LEAF; }      StmtType_t statementType() const { return STMT_LEAF; }
293      void dump(int level = 0) {}      void dump(int level = 0) {}
294        bool isPolyphonic() const { return false; }
295  };  };
296  typedef Ref<NoOperation,Node> NoOperationRef;  typedef Ref<NoOperation,Node> NoOperationRef;
297    
# Line 301  public: Line 311  public:
311      void dump(int level = 0);      void dump(int level = 0);
312      StmtType_t statementType() const { return STMT_LIST; }      StmtType_t statementType() const { return STMT_LIST; }
313      virtual Statement* statement(uint i);      virtual Statement* statement(uint i);
314        bool isPolyphonic() const;
315  };  };
316  typedef Ref<Statements,Node> StatementsRef;  typedef Ref<Statements,Node> StatementsRef;
317    
# Line 311  public: Line 322  public:
322      virtual Statements* branch(uint i) const = 0;      virtual Statements* branch(uint i) const = 0;
323  };  };
324    
325    class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr {
326        VMDynVar* dynVar;
327        String varName;
328    public:
329        DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v);
330        ExprType_t exprType() const OVERRIDE { return dynVar->exprType(); }
331        bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); }
332        bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); }
333        bool isPolyphonic() const OVERRIDE { return false; }
334        void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); }
335        int evalInt() OVERRIDE;
336        String evalStr() OVERRIDE;
337        String evalCastToStr() OVERRIDE;
338        void dump(int level = 0) OVERRIDE;
339    };
340    typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef;
341    
342  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {  class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {
343      String functionName;      String functionName;
344      ArgsRef args;      ArgsRef args;
# Line 325  public: Line 353  public:
353      bool isConstExpr() const { return false; }      bool isConstExpr() const { return false; }
354      ExprType_t exprType() const;      ExprType_t exprType() const;
355      String evalCastToStr();      String evalCastToStr();
356        bool isPolyphonic() const { return args->isPolyphonic(); }
357  protected:  protected:
358      VMFnResult* execVMFn();      VMFnResult* execVMFn();
359  };  };
# Line 332  typedef Ref<FunctionCall,Node> FunctionC Line 361  typedef Ref<FunctionCall,Node> FunctionC
361    
362  class EventHandler : virtual public Statements, virtual public VMEventHandler {  class EventHandler : virtual public Statements, virtual public VMEventHandler {
363      StatementsRef statements;      StatementsRef statements;
364        bool usingPolyphonics;
365  public:  public:
366      void dump(int level = 0);      void dump(int level = 0);
367      StmtFlags_t exec();      StmtFlags_t exec();
368      EventHandler(StatementsRef statements) { this->statements = statements; }      EventHandler(StatementsRef statements);
369      Statement* statement(uint i) { return statements->statement(i); }      Statement* statement(uint i) { return statements->statement(i); }
370        bool isPolyphonic() const { return usingPolyphonics; }
371  };  };
372  typedef Ref<EventHandler,Node> EventHandlerRef;  typedef Ref<EventHandler,Node> EventHandlerRef;
373    
374  class OnNote : public EventHandler {  class OnNote : public EventHandler {
375  public:  public:
376      OnNote(StatementsRef statements) : EventHandler(statements) {}      OnNote(StatementsRef statements) : EventHandler(statements) {}
377        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; }
378      String eventHandlerName() const { return "note"; }      String eventHandlerName() const { return "note"; }
379  };  };
380  typedef Ref<OnNote,Node> OnNoteRef;  typedef Ref<OnNote,Node> OnNoteRef;
# Line 350  typedef Ref<OnNote,Node> OnNoteRef; Line 382  typedef Ref<OnNote,Node> OnNoteRef;
382  class OnInit : public EventHandler {  class OnInit : public EventHandler {
383  public:  public:
384      OnInit(StatementsRef statements) : EventHandler(statements) {}      OnInit(StatementsRef statements) : EventHandler(statements) {}
385        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; }
386      String eventHandlerName() const { return "init"; }      String eventHandlerName() const { return "init"; }
387  };  };
388  typedef Ref<OnInit,Node> OnInitRef;  typedef Ref<OnInit,Node> OnInitRef;
# Line 357  typedef Ref<OnInit,Node> OnInitRef; Line 390  typedef Ref<OnInit,Node> OnInitRef;
390  class OnRelease : public EventHandler {  class OnRelease : public EventHandler {
391  public:  public:
392      OnRelease(StatementsRef statements) : EventHandler(statements) {}      OnRelease(StatementsRef statements) : EventHandler(statements) {}
393        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; }
394      String eventHandlerName() const { return "release"; }      String eventHandlerName() const { return "release"; }
395  };  };
396  typedef Ref<OnRelease,Node> OnReleaseRef;  typedef Ref<OnRelease,Node> OnReleaseRef;
# Line 364  typedef Ref<OnRelease,Node> OnReleaseRef Line 398  typedef Ref<OnRelease,Node> OnReleaseRef
398  class OnController : public EventHandler {  class OnController : public EventHandler {
399  public:  public:
400      OnController(StatementsRef statements) : EventHandler(statements) {}      OnController(StatementsRef statements) : EventHandler(statements) {}
401        VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; }
402      String eventHandlerName() const { return "controller"; }      String eventHandlerName() const { return "controller"; }
403  };  };
404  typedef Ref<OnController,Node> OnControllerRef;  typedef Ref<OnController,Node> OnControllerRef;
# Line 379  public: Line 414  public:
414      EventHandler* eventHandlerByName(const String& name) const;      EventHandler* eventHandlerByName(const String& name) const;
415      EventHandler* eventHandler(uint index) const;      EventHandler* eventHandler(uint index) const;
416      inline uint size() const { return args.size(); }      inline uint size() const { return args.size(); }
417        bool isPolyphonic() const;
418  };  };
419  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
420    
# Line 390  public: Line 426  public:
426      Assignment(VariableRef variable, ExpressionRef value);      Assignment(VariableRef variable, ExpressionRef value);
427      void dump(int level = 0);      void dump(int level = 0);
428      StmtFlags_t exec();      StmtFlags_t exec();
429        bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); }
430  };  };
431  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
432    
# Line 405  public: Line 442  public:
442      void dump(int level = 0);      void dump(int level = 0);
443      int evalBranch();      int evalBranch();
444      Statements* branch(uint i) const;      Statements* branch(uint i) const;
445        bool isPolyphonic() const;
446  };  };
447  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
448    
# Line 428  public: Line 466  public:
466      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);
467      //void addBranch(CaseBranchRef branch);      //void addBranch(CaseBranchRef branch);
468      //void addBranches(CaseBranchesRef branches);      //void addBranches(CaseBranchesRef branches);
469        bool isPolyphonic() const;
470  };  };
471  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
472    
# Line 441  public: Line 480  public:
480      void dump(int level = 0);      void dump(int level = 0);
481      bool evalLoopStartCondition();      bool evalLoopStartCondition();
482      Statements* statements() const;      Statements* statements() const;
483        bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
484  };  };
485    
486  class Neg : public IntExpr {  class Neg : public IntExpr {
# Line 450  public: Line 490  public:
490      int evalInt() { return (expr) ? -expr->evalInt() : 0; }      int evalInt() { return (expr) ? -expr->evalInt() : 0; }
491      void dump(int level = 0);      void dump(int level = 0);
492      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
493        bool isPolyphonic() const { return expr->isPolyphonic(); }
494  };  };
495  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
496    
# Line 461  public: Line 502  public:
502      String evalStr();      String evalStr();
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  };  };
507  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
508    
# Line 479  public: Line 521  public:
521      int evalInt();      int evalInt();
522      void dump(int level = 0);      void dump(int level = 0);
523      bool isConstExpr() const;      bool isConstExpr() const;
524        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
525  private:  private:
526      IntExprRef lhs;      IntExprRef lhs;
527      IntExprRef rhs;      IntExprRef rhs;
# Line 494  public: Line 537  public:
537  };  };
538  typedef Ref<Or,Node> OrRef;  typedef Ref<Or,Node> OrRef;
539    
540    class BitwiseOr : virtual public BinaryOp, virtual public IntExpr {
541    public:
542        BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
543        int evalInt();
544        void dump(int level = 0);
545    };
546    typedef Ref<BitwiseOr,Node> BitwiseOrRef;
547    
548  class And : virtual public BinaryOp, virtual public IntExpr {  class And : virtual public BinaryOp, virtual public IntExpr {
549  public:  public:
550      And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}      And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
# Line 502  public: Line 553  public:
553  };  };
554  typedef Ref<And,Node> AndRef;  typedef Ref<And,Node> AndRef;
555    
556    class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr {
557    public:
558        BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
559        int evalInt();
560        void dump(int level = 0);
561    };
562    typedef Ref<BitwiseAnd,Node> BitwiseAndRef;
563    
564  class Not : virtual public IntExpr {  class Not : virtual public IntExpr {
565      IntExprRef expr;      IntExprRef expr;
566  public:  public:
# Line 509  public: Line 568  public:
568      int evalInt() { return !expr->evalInt(); }      int evalInt() { return !expr->evalInt(); }
569      void dump(int level = 0);      void dump(int level = 0);
570      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
571        bool isPolyphonic() const { return expr->isPolyphonic(); }
572  };  };
573  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
574    
575    class BitwiseNot : virtual public IntExpr {
576        IntExprRef expr;
577    public:
578        BitwiseNot(IntExprRef expr) : expr(expr) {}
579        int evalInt() { return ~expr->evalInt(); }
580        void dump(int level = 0);
581        bool isConstExpr() const { return expr->isConstExpr(); }
582        bool isPolyphonic() const { return expr->isPolyphonic(); }
583    };
584    typedef Ref<BitwiseNot,Node> BitwiseNotRef;
585    
586  class ParserContext : public VMParserContext {  class ParserContext : public VMParserContext {
587  public:  public:
588      struct Error {      struct Error {
# Line 561  public: Line 632  public:
632      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
633      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
634      VariableRef variableByName(const String& name);      VariableRef variableByName(const String& name);
635      void addErr(int line, const char* txt);      void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
636      void addWrn(int line, const char* txt);      void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt);
637      void createScanner(std::istream* is);      void createScanner(std::istream* is);
638      void destroyScanner();      void destroyScanner();
639      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
# Line 576  public: Line 647  public:
647      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);      void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
648      void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);      void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);
649      void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);      void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
650        void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
651  };  };
652    
653  class ExecContext : public VMExecContext {  class ExecContext : public VMExecContext {

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

  ViewVC Help
Powered by ViewVC