/[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 2581 by schoenebeck, Fri May 30 12:48:05 2014 UTC revision 2611 by schoenebeck, Mon Jun 9 19:20:37 2014 UTC
# Line 11  Line 11 
11  #include <string.h>  #include <string.h>
12  #include "tree.h"  #include "tree.h"
13  #include "../common/global_private.h"  #include "../common/global_private.h"
14    #include <assert.h>
15    
16  namespace LinuxSampler {  namespace LinuxSampler {
17            
# Line 274  String FunctionCall::evalCastToStr() { Line 275  String FunctionCall::evalCastToStr() {
275  IntVariable::IntVariable(ParserContext* ctx)  IntVariable::IntVariable(ParserContext* ctx)
276      : Variable(ctx, ctx ? ctx->globalIntVarCount++ : 0, false), polyphonic(false)      : Variable(ctx, ctx ? ctx->globalIntVarCount++ : 0, false), polyphonic(false)
277  {  {
278        //printf("globalIntVar parserctx=0x%lx memPOS=%d\n", ctx, memPos);
279        assert(ctx);
280    }
281    
282    inline static int postfixInc(int& object, int incBy) {
283        const int i = object;
284        object += incBy;
285        return i;
286  }  }
287    
288  IntVariable::IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size)  IntVariable::IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size)
289      : Variable(ctx, !ctx ? 0 : polyphonic ? ctx->polyphonicIntVarCount += size : ctx->globalIntVarCount += size, bConst),      : Variable(ctx, !ctx ? 0 : polyphonic ? postfixInc(ctx->polyphonicIntVarCount, size) : postfixInc(ctx->globalIntVarCount, size), bConst),
290        polyphonic(polyphonic)        polyphonic(polyphonic)
291  {  {
292        //printf("InvVar size=%d parserCtx=0x%lx\n", size, (uint64_t)ctx);
293        if (polyphonic) {
294            //printf("polyIntVar memPOS=%d\n", memPos);
295            assert(ctx);
296        }
297  }  }
298    
299  void IntVariable::assign(Expression* expr) {  void IntVariable::assign(Expression* expr) {
# Line 293  void IntVariable::assign(Expression* exp Line 307  void IntVariable::assign(Expression* exp
307    
308  int IntVariable::evalInt() {  int IntVariable::evalInt() {
309      //printf("IntVariable::eval pos=%d\n", memPos);      //printf("IntVariable::eval pos=%d\n", memPos);
310      if (polyphonic)      if (polyphonic) {
311            //printf("evalInt() poly memPos=%d execCtx=0x%lx\n", memPos, (uint64_t)context->execContext);
312          return context->execContext->polyphonicIntMemory[memPos];          return context->execContext->polyphonicIntMemory[memPos];
313        }
314      return (*context->globalIntMemory)[memPos];      return (*context->globalIntMemory)[memPos];
315  }  }
316    
317  void IntVariable::dump(int level) {  void IntVariable::dump(int level) {
318      printIndents(level);      printIndents(level);
319      printf("IntVariable memPos=%d\n", memPos);      //printf("IntVariable memPos=%d\n", memPos);
320  }  }
321    
322  //ConstIntVariable::ConstIntVariable(ParserContext* ctx, int value)  //ConstIntVariable::ConstIntVariable(ParserContext* ctx, int value)
# Line 329  void ConstIntVariable::dump(int level) { Line 345  void ConstIntVariable::dump(int level) {
345      printf("ConstIntVariable val=%d\n", value);      printf("ConstIntVariable val=%d\n", value);
346  }  }
347    
348    BuiltInIntVariable::BuiltInIntVariable(const String& name, VMIntRelPtr* ptr)
349        : IntVariable(NULL,false,false), name(name), ptr(ptr)
350    {
351    }
352    
353    void BuiltInIntVariable::assign(Expression* expr) {
354        IntExpr* valueExpr = dynamic_cast<IntExpr*>(expr);
355        if (!valueExpr) return;
356        ptr->assign(valueExpr->evalInt());
357    }
358    
359    int BuiltInIntVariable::evalInt() {
360        return ptr->evalInt();
361    }
362    
363    void BuiltInIntVariable::dump(int level) {
364        printIndents(level);
365        printf("Built-in IntVar '%s'\n", name.c_str());
366    }
367    
368  PolyphonicIntVariable::PolyphonicIntVariable(ParserContext* ctx)  PolyphonicIntVariable::PolyphonicIntVariable(ParserContext* ctx)
369      : IntVariable(ctx,true,false)      : IntVariable(ctx,true,false)
370  {  {
# Line 356  IntArrayVariable::IntArrayVariable(Parse Line 392  IntArrayVariable::IntArrayVariable(Parse
392      }      }
393  }  }
394    
395    IntArrayVariable::IntArrayVariable(ParserContext* ctx, bool bConst)
396        : Variable(ctx, 0, bConst)
397    {
398    }
399    
400  int IntArrayVariable::evalIntElement(uint i) {  int IntArrayVariable::evalIntElement(uint i) {
401      if (i >= values.size()) return 0;      if (i >= values.size()) return 0;
402      return values[i];      return values[i];
# Line 380  void IntArrayVariable::dump(int level) { Line 421  void IntArrayVariable::dump(int level) {
421      printf(")\n");      printf(")\n");
422  }  }
423    
424    BuiltInIntArrayVariable::BuiltInIntArrayVariable(const String& name, VMInt8Array* array)
425        : IntArrayVariable(NULL, false), name(name), array(array)
426    {
427    }
428    
429    int BuiltInIntArrayVariable::evalIntElement(uint i) {
430        return i >= array->size ? 0 : array->data[i];
431    }
432    
433    void BuiltInIntArrayVariable::assignIntElement(uint i, int value) {
434        if (i >= array->size) return;
435        array->data[i] = value;
436    }
437    
438    void BuiltInIntArrayVariable::dump(int level) {
439        printIndents(level);
440        printf("Built-In Int Array Variable '%s'\n", name.c_str());
441    }
442    
443  IntArrayElement::IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex)  IntArrayElement::IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex)
444      : IntVariable(NULL, false, false, 0), array(array), index(arrayIndex)      : IntVariable(NULL, false, false, 0), array(array), index(arrayIndex)
445  {      {    
# Line 653  bool Relation::isConstExpr() const { Line 713  bool Relation::isConstExpr() const {
713    
714  int Or::evalInt() {  int Or::evalInt() {
715      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);
716        if (pLHS->evalInt()) return 1;
717      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);;      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);;
718      return pLHS->evalInt() || pRHS->evalInt();      return (pRHS->evalInt()) ? 1 : 0;
719  }  }
720    
721  void Or::dump(int level) {  void Or::dump(int level) {
# Line 670  void Or::dump(int level) { Line 731  void Or::dump(int level) {
731    
732  int And::evalInt() {  int And::evalInt() {
733      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);
734      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);;      if (!pLHS->evalInt()) return 0;
735      return pLHS->evalInt() && pRHS->evalInt();      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);
736        return (pRHS->evalInt()) ? 1 : 0;
737  }  }
738    
739  void And::dump(int level) {  void And::dump(int level) {
# Line 718  StringVariableRef ParserContext::globalS Line 780  StringVariableRef ParserContext::globalS
780      return globalVar(name);      return globalVar(name);
781  }  }
782    
783    ParserContext::~ParserContext() {
784        destroyScanner();
785        if (globalIntMemory) {
786            delete globalIntMemory;
787            globalIntMemory = NULL;
788        }
789    }
790    
791  void ParserContext::addErr(int line, const char* txt) {  void ParserContext::addErr(int line, const char* txt) {
792      ParserIssue e;      ParserIssue e;
793      e.type = PARSER_ERROR;      e.type = PARSER_ERROR;
794      e.txt = txt;      e.txt = txt;
795      e.line = line;      e.line = line;
796      errors.push_back(e);      vErrors.push_back(e);
797      issues.push_back(e);      vIssues.push_back(e);
798  }  }
799    
800  void ParserContext::addWrn(int line, const char* txt) {  void ParserContext::addWrn(int line, const char* txt) {
# Line 732  void ParserContext::addWrn(int line, con Line 802  void ParserContext::addWrn(int line, con
802      w.type = PARSER_WARNING;      w.type = PARSER_WARNING;
803      w.txt = txt;      w.txt = txt;
804      w.line = line;      w.line = line;
805      warnings.push_back(w);      vWarnings.push_back(w);
806      issues.push_back(w);      vIssues.push_back(w);
807  }  }
808    
809  bool ParserContext::setPreprocessorCondition(const char* name) {  bool ParserContext::setPreprocessorCondition(const char* name) {
# Line 755  bool ParserContext::isPreprocessorCondit Line 825  bool ParserContext::isPreprocessorCondit
825      return userPreprocessorConditions.count(name);      return userPreprocessorConditions.count(name);
826  }  }
827    
828    std::vector<ParserIssue> ParserContext::issues() const {
829        return vIssues;
830    }
831    
832    std::vector<ParserIssue> ParserContext::errors() const {
833        return vErrors;
834    }
835    
836    std::vector<ParserIssue> ParserContext::warnings() const {
837        return vWarnings;
838    }
839    
840    VMEventHandler* ParserContext::eventHandler(uint index) {
841        if (!handlers) return NULL;
842        return handlers->eventHandler(index);
843    }
844    
845    VMEventHandler* ParserContext::eventHandlerByName(const String& name) {
846        if (!handlers) return NULL;
847        return handlers->eventHandlerByName(name);
848    }
849    
850    void ParserContext::registerBuiltInConstIntVariables(const std::map<String,int>& vars) {
851        for (std::map<String,int>::const_iterator it = vars.begin();
852             it != vars.end(); ++it)
853        {
854            ConstIntVariableRef ref = new ConstIntVariable(it->second);
855            vartable[it->first] = ref;
856        }
857    }
858    
859    void ParserContext::registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars) {
860        for (std::map<String,VMIntRelPtr*>::const_iterator it = vars.begin();
861             it != vars.end(); ++it)
862        {
863            BuiltInIntVariableRef ref = new BuiltInIntVariable(it->first, it->second);
864            vartable[it->first] = ref;
865        }
866    }
867    
868    void ParserContext::registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars) {
869        for (std::map<String,VMInt8Array*>::const_iterator it = vars.begin();
870             it != vars.end(); ++it)
871        {
872            BuiltInIntArrayVariableRef ref = new BuiltInIntArrayVariable(it->first, it->second);
873            vartable[it->first] = ref;
874        }
875    }
876    
877  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC