/[svn]/linuxsampler/trunk/src/scriptvm/tree.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/tree.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2611 by schoenebeck, Mon Jun 9 19:20:37 2014 UTC revision 2935 by schoenebeck, Sun Jul 10 14:24:13 2016 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014 Christian Schoenebeck and Andreas Persson   * Copyright (c) 2014 - 2016 Christian Schoenebeck and Andreas Persson
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 144  void Args::dump(int level) { Line 144  void Args::dump(int level) {
144      printf(")\n");      printf(")\n");
145  }  }
146    
147    bool Args::isPolyphonic() const {
148        for (int i = 0; i < args.size(); ++i)
149            if (args[i]->isPolyphonic())
150                return true;
151        return false;
152    }
153    
154  EventHandlers::EventHandlers() {  EventHandlers::EventHandlers() {
155      //printf("EventHandlers::Constructor 0x%lx\n", (long long)this);      //printf("EventHandlers::Constructor 0x%lx\n", (long long)this);
156  }  }
# Line 177  EventHandler* EventHandlers::eventHandle Line 184  EventHandler* EventHandlers::eventHandle
184      return const_cast<EventHandler*>(&*args.at(index));      return const_cast<EventHandler*>(&*args.at(index));
185  }  }
186    
187    bool EventHandlers::isPolyphonic() const {
188        for (int i = 0; i < args.size(); ++i)
189            if (args[i]->isPolyphonic())
190                return true;
191        return false;
192    }
193    
194  Assignment::Assignment(VariableRef variable, ExpressionRef value)  Assignment::Assignment(VariableRef variable, ExpressionRef value)
195     : variable(variable), value(value)     : variable(variable), value(value)
196  {  {
# Line 194  StmtFlags_t Assignment::exec() { Line 208  StmtFlags_t Assignment::exec() {
208      return STMT_SUCCESS;      return STMT_SUCCESS;
209  }  }
210    
211    EventHandler::EventHandler(StatementsRef statements) {
212        this->statements = statements;
213        usingPolyphonics = statements->isPolyphonic();
214    }
215    
216  void EventHandler::dump(int level) {  void EventHandler::dump(int level) {
217      printIndents(level);      printIndents(level);
218      printf("EventHandler {\n");      printf("EventHandler {\n");
# Line 217  Statement* Statements::statement(uint i) Line 236  Statement* Statements::statement(uint i)
236      return &*args.at(i);      return &*args.at(i);
237  }  }
238    
239    bool Statements::isPolyphonic() const {
240        for (int i = 0; i < args.size(); ++i)
241            if (args[i]->isPolyphonic())
242                return true;
243        return false;
244    }
245    
246  void FunctionCall::dump(int level) {  void FunctionCall::dump(int level) {
247      printIndents(level);      printIndents(level);
248      printf("FunctionCall '%s' args={\n", functionName.c_str());      printf("FunctionCall '%s' args={\n", functionName.c_str());
# Line 537  Statements* If::branch(uint i) const { Line 563  Statements* If::branch(uint i) const {
563      return NULL;      return NULL;
564  }  }
565    
566    bool If::isPolyphonic() const {
567        if (condition->isPolyphonic() || ifStatements->isPolyphonic())
568            return true;
569        return elseStatements ? elseStatements->isPolyphonic() : false;
570    }
571    
572  void SelectCase::dump(int level) {  void SelectCase::dump(int level) {
573      printIndents(level);      printIndents(level);
574      if (select)      if (select)
# Line 587  Statements* SelectCase::branch(uint i) c Line 619  Statements* SelectCase::branch(uint i) c
619      return NULL;      return NULL;
620  }  }
621    
622    bool SelectCase::isPolyphonic() const {
623        if (select->isPolyphonic()) return true;
624        for (int i = 0; i < branches.size(); ++i)
625            if (branches[i].statements->isPolyphonic())
626                return true;
627        return false;
628    }
629    
630  // void Case::addBranch(IntExprRef condition, StatementsRef statements) {  // void Case::addBranch(IntExprRef condition, StatementsRef statements) {
631  //     CaseBranchRef b = new CaseBranchRef;  //     CaseBranchRef b = new CaseBranchRef;
632  //     b->from = condition;  //     b->from = condition;
# Line 729  void Or::dump(int level) { Line 769  void Or::dump(int level) {
769      printf(")\n");      printf(")\n");
770  }  }
771    
772    int BitwiseOr::evalInt() {
773        IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);
774        IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);
775        return pLHS->evalInt() | pRHS->evalInt();
776    }
777    
778    void BitwiseOr::dump(int level) {
779        printIndents(level);
780        printf("BitwiseOr(\n");
781        lhs->dump(level+1);
782        printIndents(level);
783        printf(",\n");
784        rhs->dump(level+1);
785        printIndents(level);
786        printf(")\n");
787    }
788    
789  int And::evalInt() {  int And::evalInt() {
790      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);
791      if (!pLHS->evalInt()) return 0;      if (!pLHS->evalInt()) return 0;
# Line 747  void And::dump(int level) { Line 804  void And::dump(int level) {
804      printf(")\n");      printf(")\n");
805  }  }
806    
807    int BitwiseAnd::evalInt() {
808        IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);
809        IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);
810        return pLHS->evalInt() & pRHS->evalInt();
811    }
812    
813    void BitwiseAnd::dump(int level) {
814        printIndents(level);
815        printf("BitwiseAnd(\n");
816        lhs->dump(level+1);
817        printIndents(level);
818        printf(",\n");
819        rhs->dump(level+1);
820        printIndents(level);
821        printf(")\n");
822    }
823    
824  void Not::dump(int level) {  void Not::dump(int level) {
825      printIndents(level);      printIndents(level);
826      printf("Not(\n");      printf("Not(\n");
# Line 755  void Not::dump(int level) { Line 829  void Not::dump(int level) {
829      printf(")\n");      printf(")\n");
830  }  }
831    
832    void BitwiseNot::dump(int level) {
833        printIndents(level);
834        printf("BitwiseNot(\n");
835        expr->dump(level+1);
836        printIndents(level);
837        printf(")\n");
838    }
839    
840  VariableRef ParserContext::variableByName(const String& name) {  VariableRef ParserContext::variableByName(const String& name) {
841      if (!vartable.count(name)) {      if (!vartable.count(name)) {
842          return VariableRef();          return VariableRef();
# Line 788  ParserContext::~ParserContext() { Line 870  ParserContext::~ParserContext() {
870      }      }
871  }  }
872    
873  void ParserContext::addErr(int line, const char* txt) {  void ParserContext::addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) {
874      ParserIssue e;      ParserIssue e;
875      e.type = PARSER_ERROR;      e.type = PARSER_ERROR;
876      e.txt = txt;      e.txt = txt;
877      e.line = line;      e.firstLine = firstLine;
878        e.lastLine = lastLine;
879        e.firstColumn = firstColumn;
880        e.lastColumn = lastColumn;
881      vErrors.push_back(e);      vErrors.push_back(e);
882      vIssues.push_back(e);      vIssues.push_back(e);
883  }  }
884    
885  void ParserContext::addWrn(int line, const char* txt) {  void ParserContext::addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) {
886      ParserIssue w;      ParserIssue w;
887      w.type = PARSER_WARNING;      w.type = PARSER_WARNING;
888      w.txt = txt;      w.txt = txt;
889      w.line = line;      w.firstLine = firstLine;
890        w.lastLine = lastLine;
891        w.firstColumn = firstColumn;
892        w.lastColumn = lastColumn;
893      vWarnings.push_back(w);      vWarnings.push_back(w);
894      vIssues.push_back(w);      vIssues.push_back(w);
895  }  }

Legend:
Removed from v.2611  
changed lines
  Added in v.2935

  ViewVC Help
Powered by ViewVC