/[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 2581 by schoenebeck, Fri May 30 12:48:05 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 139  public: Line 143  public:
143  };  };
144  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;  typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
145    
146    class BuiltInIntVariable : public IntVariable {
147        String name;
148        VMIntRelPtr* ptr;
149    public:
150        BuiltInIntVariable(const String& name, VMIntRelPtr* ptr);
151        void assign(Expression* expr);
152        int evalInt();
153        void dump(int level = 0);
154    };
155    typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
156    
157  class PolyphonicIntVariable : public IntVariable {  class PolyphonicIntVariable : public IntVariable {
158  public:  public:
159      PolyphonicIntVariable(ParserContext* ctx);      PolyphonicIntVariable(ParserContext* ctx);
# Line 146  public: Line 161  public:
161  };  };
162  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;  typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
163    
164  class IntArrayVariable : public Variable {  class IntArrayVariable : public Variable, virtual public VMIntArrayExpr {
165      ArrayList<int> values;      ArrayList<int> values;
166  public:  public:
167      IntArrayVariable(ParserContext* ctx, int size);      IntArrayVariable(ParserContext* ctx, int size);
168      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values);      IntArrayVariable(ParserContext* ctx, int size, ArgsRef values);
169      void assign(Expression* expr) {} // ignore scalar assignment      void assign(Expression* expr) {} // ignore scalar assignment
170      String evalCastToStr() { return ""; } // ignore cast to string      String evalCastToStr() { return ""; } // ignore scalar cast to string
171      ExprType_t exprType() const { return INT_ARR_EXPR; }      ExprType_t exprType() const { return INT_ARR_EXPR; }
172      const int arraySize() const { return values.size(); }      virtual int arraySize() const { return values.size(); }
173        virtual int evalIntElement(uint i);
174        virtual void assignIntElement(uint i, int value);
175        void dump(int level = 0);
176        bool isPolyphonic() const { return false; }
177    protected:
178        IntArrayVariable(ParserContext* ctx, bool bConst);
179    };
180    typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
181    
182    class BuiltInIntArrayVariable : public IntArrayVariable {
183        String name;
184        VMInt8Array* array;
185    public:
186        BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
187        int arraySize() const { return array->size; }
188      int evalIntElement(uint i);      int evalIntElement(uint i);
189      void assignIntElement(uint i, int value);      void assignIntElement(uint i, int value);
190      void dump(int level = 0);      void dump(int level = 0);
191  };  };
192  typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;  typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
193    
194  class IntArrayElement : public IntVariable {  class IntArrayElement : public IntVariable {
195      IntArrayVariableRef array;      IntArrayVariableRef array;
# Line 178  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 201  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 257  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 276  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 300  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 307  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 325  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 332  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 339  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 354  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 365  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 380  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 403  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 416  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 425  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 436  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 454  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 484  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    
# Line 497  public: Line 547  public:
547    
548      void* scanner;      void* scanner;
549      std::istream* is;      std::istream* is;
550      std::vector<ParserIssue> errors;      std::vector<ParserIssue> vErrors;
551      std::vector<ParserIssue> warnings;      std::vector<ParserIssue> vWarnings;
552      std::vector<ParserIssue> issues;      std::vector<ParserIssue> vIssues;
553    
554      std::set<String> builtinPreprocessorConditions;      std::set<String> builtinPreprocessorConditions;
555      std::set<String> userPreprocessorConditions;      std::set<String> userPreprocessorConditions;
# Line 518  public: Line 568  public:
568    
569      ArrayList<int>* globalIntMemory;      ArrayList<int>* globalIntMemory;
570      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
571        int requiredMaxStackSize;
572    
573      VMFunctionProvider* functionProvider;      VMFunctionProvider* functionProvider;
574    
# Line 526  public: Line 577  public:
577      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
578          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
579          globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),          globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),
580          globalIntMemory(NULL), globalStrMemory(NULL), functionProvider(parent),          globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1),
581          execContext(NULL)          functionProvider(parent), execContext(NULL)
582      {      {
583      }      }
584      virtual ~ParserContext() { destroyScanner(); }      virtual ~ParserContext();
585      VariableRef globalVar(const String& name);      VariableRef globalVar(const String& name);
586      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
587      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
# Line 542  public: Line 593  public:
593      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
594      bool resetPreprocessorCondition(const char* name);      bool resetPreprocessorCondition(const char* name);
595      bool isPreprocessorConditionSet(const char* name);      bool isPreprocessorConditionSet(const char* name);
596        std::vector<ParserIssue> issues() const OVERRIDE;
597        std::vector<ParserIssue> errors() const OVERRIDE;
598        std::vector<ParserIssue> warnings() const OVERRIDE;
599        VMEventHandler* eventHandler(uint index) OVERRIDE;
600        VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
601        void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
602        void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);
603        void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
604  };  };
605    
606  class ExecContext : public VMExecContext {  class ExecContext : public VMExecContext {
# Line 588  public: Line 647  public:
647          stackFrame = -1;          stackFrame = -1;
648      }      }
649    
650      int suspensionTimeMicroseconds() const {      int suspensionTimeMicroseconds() const OVERRIDE {
651          return suspendMicroseconds;          return suspendMicroseconds;
652      }      }
653  };  };

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

  ViewVC Help
Powered by ViewVC