/[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 3557 by schoenebeck, Sun Aug 18 00:06:04 2019 UTC revision 3561 by schoenebeck, Fri Aug 23 11:44:00 2019 UTC
# Line 45  String IntArrayExpr::evalCastToStr() { Line 45  String IntArrayExpr::evalCastToStr() {
45      return s;      return s;
46  }  }
47    
48    MetricPrefix_t Unit::unitPrefix(vmuint i) const {
49        if (i >= prefix.size()) return VM_NO_PREFIX;
50        return prefix[i];
51    }
52    
53    void Unit::setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type) {
54        this->prefix.resize( prefix.size() );
55        for (vmuint i = 0; i < prefix.size(); ++i)
56            this->prefix[i] = prefix[i];
57    
58        unit = type;
59    }
60    
61    void Unit::setUnit(const MetricPrefix_t* prefixes, StdUnit_t type) {
62        unit = type;
63        prefix.clear();
64        for (int i = 0; i < 2 && prefixes[i]; ++i)
65            prefix.add(prefixes[i]);
66    }
67    
68    void Unit::copyUnitFrom(const IntExprRef& src) {
69        unit = src->unitType();
70        prefix.clear();
71        for (int i = 0; true; ++i) {
72            MetricPrefix_t p = src->unitPrefix(i);
73            if (!p) return;
74            prefix.add(p);
75        }
76    }
77    
78  vmint IntLiteral::evalInt() {  vmint IntLiteral::evalInt() {
79      return value;      return value;
80  }  }
# Line 110  void Mul::dump(int level) { Line 140  void Mul::dump(int level) {
140      printf(")\n");      printf(")\n");
141  }  }
142    
143    MetricPrefix_t Mul::unitPrefix(vmuint i) const {
144        const IntExpr* pLHS = dynamic_cast<const IntExpr*>(&*lhs);
145        const IntExpr* pRHS = dynamic_cast<const IntExpr*>(&*rhs);
146        // currently the NKSP parser only allows a unit prefix on either side
147        return (pLHS->unitPrefix(0)) ? pLHS->unitPrefix(i) : pRHS->unitPrefix(i);
148    }
149    
150    StdUnit_t Mul::unitType() const {
151        const IntExpr* pLHS = dynamic_cast<const IntExpr*>(&*lhs);
152        const IntExpr* pRHS = dynamic_cast<const IntExpr*>(&*rhs);
153        // currently the NKSP parser only allows a unit type on either side
154        return (pLHS->unitType()) ? pLHS->unitType() : pRHS->unitType();
155    }
156    
157  vmint Div::evalInt() {  vmint Div::evalInt() {
158      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);
159      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);
# Line 131  void Div::dump(int level) { Line 175  void Div::dump(int level) {
175      printf(")\n");      printf(")\n");
176  }  }
177    
178    MetricPrefix_t Div::unitPrefix(vmuint i) const {
179        const IntExpr* pLHS = dynamic_cast<const IntExpr*>(&*lhs);
180        const IntExpr* pRHS = dynamic_cast<const IntExpr*>(&*rhs);
181        // currently the NKSP parser only allows either A) a unit prefix on left
182        // side and none on right side or B) an identical unit prefix on both sides
183        return (pLHS->unitPrefix(0) && pRHS->unitPrefix(0)) ? VM_NO_PREFIX : pLHS->unitPrefix(i);
184    }
185    
186    StdUnit_t Div::unitType() const {
187        const IntExpr* pLHS = dynamic_cast<const IntExpr*>(&*lhs);
188        const IntExpr* pRHS = dynamic_cast<const IntExpr*>(&*rhs);
189        // the NKSP parser only allows either A) a unit type on left side and none
190        // on right side or B) an identical unit type on both sides
191        return (pLHS->unitType() && pRHS->unitType()) ? VM_NO_UNIT : pLHS->unitType();
192    }
193    
194  vmint Mod::evalInt() {  vmint Mod::evalInt() {
195      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);      IntExpr* pLHS = dynamic_cast<IntExpr*>(&*lhs);
196      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);;      IntExpr* pRHS = dynamic_cast<IntExpr*>(&*rhs);;
# Line 351  String FunctionCall::evalCastToStr() { Line 411  String FunctionCall::evalCastToStr() {
411  }  }
412    
413  IntVariable::IntVariable(ParserContext* ctx)  IntVariable::IntVariable(ParserContext* ctx)
414      : Variable(ctx, ctx ? ctx->globalIntVarCount++ : 0, false), polyphonic(false)      : Variable(ctx, ctx ? ctx->globalIntVarCount++ : 0, false),
415          Unit(),
416          polyphonic(false), finalVal(false)
417  {  {
418      //printf("globalIntVar parserctx=0x%lx memPOS=%d\n", ctx, memPos);      //printf("globalIntVar parserctx=0x%lx memPOS=%d\n", ctx, memPos);
419      assert(ctx);      assert(ctx);
# Line 365  inline static vmint postfixInc(vmint& ob Line 427  inline static vmint postfixInc(vmint& ob
427    
428  IntVariable::IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size)  IntVariable::IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size)
429      : Variable(ctx, !ctx ? 0 : polyphonic ? postfixInc(ctx->polyphonicIntVarCount, size) : postfixInc(ctx->globalIntVarCount, size), bConst),      : Variable(ctx, !ctx ? 0 : polyphonic ? postfixInc(ctx->polyphonicIntVarCount, size) : postfixInc(ctx->globalIntVarCount, size), bConst),
430        polyphonic(polyphonic)        Unit(),
431          polyphonic(polyphonic), finalVal(false)
432  {  {
433      //printf("InvVar size=%d parserCtx=0x%lx\n", size, (uint64_t)ctx);      //printf("InvVar size=%d parserCtx=0x%lx\n", size, (uint64_t)ctx);
434      if (polyphonic) {      if (polyphonic) {
# Line 595  void ConstStringVariable::dump(int level Line 658  void ConstStringVariable::dump(int level
658      printf("ConstStringVariable val='%s'\n", value.c_str());      printf("ConstStringVariable val='%s'\n", value.c_str());
659  }  }
660    
661    MetricPrefix_t IntBinaryOp::unitPrefix(vmuint i) const {
662        IntExprRef l = (IntExprRef) lhs;
663        IntExprRef r = (IntExprRef) rhs;
664        return (r->unitFactor() < l->unitFactor()) ? r->unitPrefix(i) : l->unitPrefix(i);
665    }
666    
667    StdUnit_t IntBinaryOp::unitType() const {
668        IntExprRef l = (IntExprRef) lhs;
669        IntExprRef r = (IntExprRef) rhs;
670        return (l->unitType()) ? l->unitType() : r->unitType();
671    }
672    
673    bool IntBinaryOp::isFinal() const {
674        IntExprRef l = (IntExprRef) lhs;
675        IntExprRef r = (IntExprRef) rhs;
676        return l->isFinal() || r->isFinal();
677    }
678    
679  void If::dump(int level) {  void If::dump(int level) {
680      printIndents(level);      printIndents(level);
681      if (ifStatements && elseStatements)      if (ifStatements && elseStatements)
# Line 910  void BitwiseNot::dump(int level) { Line 991  void BitwiseNot::dump(int level) {
991      expr->dump(level+1);      expr->dump(level+1);
992      printIndents(level);      printIndents(level);
993      printf(")\n");      printf(")\n");
994    }
995    
996    void Final::dump(int level) {
997        printIndents(level);
998        printf("Final(\n");
999        expr->dump(level+1);
1000        printIndents(level);
1001        printf(")\n");
1002  }  }
1003    
1004  StatementsRef ParserContext::userFunctionByName(const String& name) {  StatementsRef ParserContext::userFunctionByName(const String& name) {

Legend:
Removed from v.3557  
changed lines
  Added in v.3561

  ViewVC Help
Powered by ViewVC