/[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 2645 by schoenebeck, Wed Jun 18 00:14:57 2014 UTC
# 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    
# Line 354  public: Line 391  public:
391      EventHandler* eventHandlerByName(const String& name) const;      EventHandler* eventHandlerByName(const String& name) const;
392      EventHandler* eventHandler(uint index) const;      EventHandler* eventHandler(uint index) const;
393      inline uint size() const { return args.size(); }      inline uint size() const { return args.size(); }
394        bool isPolyphonic() const;
395  };  };
396  typedef Ref<EventHandlers,Node> EventHandlersRef;  typedef Ref<EventHandlers,Node> EventHandlersRef;
397    
# Line 365  public: Line 403  public:
403      Assignment(VariableRef variable, ExpressionRef value);      Assignment(VariableRef variable, ExpressionRef value);
404      void dump(int level = 0);      void dump(int level = 0);
405      StmtFlags_t exec();      StmtFlags_t exec();
406        bool isPolyphonic() const { return variable->isPolyphonic() || value->isPolyphonic(); }
407  };  };
408  typedef Ref<Assignment,Node> AssignmentRef;  typedef Ref<Assignment,Node> AssignmentRef;
409    
# Line 380  public: Line 419  public:
419      void dump(int level = 0);      void dump(int level = 0);
420      int evalBranch();      int evalBranch();
421      Statements* branch(uint i) const;      Statements* branch(uint i) const;
422        bool isPolyphonic() const;
423  };  };
424  typedef Ref<If,Node> IfRef;  typedef Ref<If,Node> IfRef;
425    
# Line 403  public: Line 443  public:
443      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);      //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);
444      //void addBranch(CaseBranchRef branch);      //void addBranch(CaseBranchRef branch);
445      //void addBranches(CaseBranchesRef branches);      //void addBranches(CaseBranchesRef branches);
446        bool isPolyphonic() const;
447  };  };
448  typedef Ref<SelectCase,Node> SelectCaseRef;  typedef Ref<SelectCase,Node> SelectCaseRef;
449    
# Line 416  public: Line 457  public:
457      void dump(int level = 0);      void dump(int level = 0);
458      bool evalLoopStartCondition();      bool evalLoopStartCondition();
459      Statements* statements() const;      Statements* statements() const;
460        bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
461  };  };
462    
463  class Neg : public IntExpr {  class Neg : public IntExpr {
# Line 425  public: Line 467  public:
467      int evalInt() { return (expr) ? -expr->evalInt() : 0; }      int evalInt() { return (expr) ? -expr->evalInt() : 0; }
468      void dump(int level = 0);      void dump(int level = 0);
469      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
470        bool isPolyphonic() const { return expr->isPolyphonic(); }
471  };  };
472  typedef Ref<Neg,Node> NegRef;  typedef Ref<Neg,Node> NegRef;
473    
# Line 436  public: Line 479  public:
479      String evalStr();      String evalStr();
480      void dump(int level = 0);      void dump(int level = 0);
481      bool isConstExpr() const;      bool isConstExpr() const;
482        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
483  };  };
484  typedef Ref<ConcatString,Node> ConcatStringRef;  typedef Ref<ConcatString,Node> ConcatStringRef;
485    
# Line 454  public: Line 498  public:
498      int evalInt();      int evalInt();
499      void dump(int level = 0);      void dump(int level = 0);
500      bool isConstExpr() const;      bool isConstExpr() const;
501        bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
502  private:  private:
503      IntExprRef lhs;      IntExprRef lhs;
504      IntExprRef rhs;      IntExprRef rhs;
# Line 484  public: Line 529  public:
529      int evalInt() { return !expr->evalInt(); }      int evalInt() { return !expr->evalInt(); }
530      void dump(int level = 0);      void dump(int level = 0);
531      bool isConstExpr() const { return expr->isConstExpr(); }      bool isConstExpr() const { return expr->isConstExpr(); }
532        bool isPolyphonic() const { return expr->isPolyphonic(); }
533  };  };
534  typedef Ref<Not,Node> NotRef;  typedef Ref<Not,Node> NotRef;
535    
# Line 497  public: Line 543  public:
543    
544      void* scanner;      void* scanner;
545      std::istream* is;      std::istream* is;
546      std::vector<ParserIssue> errors;      std::vector<ParserIssue> vErrors;
547      std::vector<ParserIssue> warnings;      std::vector<ParserIssue> vWarnings;
548      std::vector<ParserIssue> issues;      std::vector<ParserIssue> vIssues;
549    
550      std::set<String> builtinPreprocessorConditions;      std::set<String> builtinPreprocessorConditions;
551      std::set<String> userPreprocessorConditions;      std::set<String> userPreprocessorConditions;
# Line 518  public: Line 564  public:
564    
565      ArrayList<int>* globalIntMemory;      ArrayList<int>* globalIntMemory;
566      ArrayList<String>* globalStrMemory;      ArrayList<String>* globalStrMemory;
567        int requiredMaxStackSize;
568    
569      VMFunctionProvider* functionProvider;      VMFunctionProvider* functionProvider;
570    
# Line 526  public: Line 573  public:
573      ParserContext(VMFunctionProvider* parent) :      ParserContext(VMFunctionProvider* parent) :
574          scanner(NULL), is(NULL),          scanner(NULL), is(NULL),
575          globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),          globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),
576          globalIntMemory(NULL), globalStrMemory(NULL), functionProvider(parent),          globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1),
577          execContext(NULL)          functionProvider(parent), execContext(NULL)
578      {      {
579      }      }
580      virtual ~ParserContext() { destroyScanner(); }      virtual ~ParserContext();
581      VariableRef globalVar(const String& name);      VariableRef globalVar(const String& name);
582      IntVariableRef globalIntVar(const String& name);      IntVariableRef globalIntVar(const String& name);
583      StringVariableRef globalStrVar(const String& name);      StringVariableRef globalStrVar(const String& name);
# Line 542  public: Line 589  public:
589      bool setPreprocessorCondition(const char* name);      bool setPreprocessorCondition(const char* name);
590      bool resetPreprocessorCondition(const char* name);      bool resetPreprocessorCondition(const char* name);
591      bool isPreprocessorConditionSet(const char* name);      bool isPreprocessorConditionSet(const char* name);
592        std::vector<ParserIssue> issues() const OVERRIDE;
593        std::vector<ParserIssue> errors() const OVERRIDE;
594        std::vector<ParserIssue> warnings() const OVERRIDE;
595        VMEventHandler* eventHandler(uint index) OVERRIDE;
596        VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
597        void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
598        void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);
599        void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
600  };  };
601    
602  class ExecContext : public VMExecContext {  class ExecContext : public VMExecContext {
# Line 588  public: Line 643  public:
643          stackFrame = -1;          stackFrame = -1;
644      }      }
645    
646      int suspensionTimeMicroseconds() const {      int suspensionTimeMicroseconds() const OVERRIDE {
647          return suspendMicroseconds;          return suspendMicroseconds;
648      }      }
649  };  };

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

  ViewVC Help
Powered by ViewVC