/[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 3581 by schoenebeck, Fri Aug 30 11:40:25 2019 UTC revision 3582 by schoenebeck, Fri Aug 30 12:23:40 2019 UTC
# Line 175  void StringLiteral::dump(int level) { Line 175  void StringLiteral::dump(int level) {
175      printf("StringLiteral: '%s'\n", value.c_str());      printf("StringLiteral: '%s'\n", value.c_str());
176  }  }
177    
178  Add::Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) :  Add::Add(NumberExprRef lhs, NumberExprRef rhs) :
179      VaritypeScalarBinaryOp(lhs, rhs),      VaritypeScalarBinaryOp(lhs, rhs),
180      Unit(      Unit(
181          // lhs and rhs are forced to be same unit type at parse time, so either one is fine here          // lhs and rhs are forced to be same unit type at parse time, so either one is fine here
# Line 215  vmfloat Add::evalReal() { Line 215  vmfloat Add::evalReal() {
215  }  }
216    
217  vmfloat Add::unitFactor() const {  vmfloat Add::unitFactor() const {
218      const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs);      const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs);
219      const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs);      const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs);
220      return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor();      return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor();
221  }  }
222    
# Line 231  void Add::dump(int level) { Line 231  void Add::dump(int level) {
231      printf(")\n");      printf(")\n");
232  }  }
233    
234  Sub::Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) :  Sub::Sub(NumberExprRef lhs, NumberExprRef rhs) :
235      VaritypeScalarBinaryOp(lhs, rhs),      VaritypeScalarBinaryOp(lhs, rhs),
236      Unit(      Unit(
237          // lhs and rhs are forced to be same unit type at parse time, so either one is fine here          // lhs and rhs are forced to be same unit type at parse time, so either one is fine here
# Line 271  vmfloat Sub::evalReal() { Line 271  vmfloat Sub::evalReal() {
271  }  }
272    
273  vmfloat Sub::unitFactor() const {  vmfloat Sub::unitFactor() const {
274      const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs);      const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs);
275      const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs);      const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs);
276      return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor();      return (pLHS->unitFactor() < pRHS->unitFactor()) ? pLHS->unitFactor() : pRHS->unitFactor();
277  }  }
278    
# Line 287  void Sub::dump(int level) { Line 287  void Sub::dump(int level) {
287      printf(")\n");      printf(")\n");
288  }  }
289    
290  Mul::Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) :  Mul::Mul(NumberExprRef lhs, NumberExprRef rhs) :
291      VaritypeScalarBinaryOp(lhs, rhs),      VaritypeScalarBinaryOp(lhs, rhs),
292      Unit(      Unit(
293          // currently the NKSP parser only allows a unit type on either side on multiplications          // currently the NKSP parser only allows a unit type on either side on multiplications
# Line 320  void Mul::dump(int level) { Line 320  void Mul::dump(int level) {
320  }  }
321    
322  vmfloat Mul::unitFactor() const {  vmfloat Mul::unitFactor() const {
323      const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs);      const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs);
324      const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs);      const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs);
325      return pLHS->unitFactor() * pRHS->unitFactor();      return pLHS->unitFactor() * pRHS->unitFactor();
326  }  }
327    
328  Div::Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) :  Div::Div(NumberExprRef lhs, NumberExprRef rhs) :
329      VaritypeScalarBinaryOp(lhs, rhs),      VaritypeScalarBinaryOp(lhs, rhs),
330      Unit(      Unit(
331          // the NKSP parser only allows either A) a unit type on left side and none          // the NKSP parser only allows either A) a unit type on left side and none
# Line 367  void Div::dump(int level) { Line 367  void Div::dump(int level) {
367  }  }
368    
369  vmfloat Div::unitFactor() const {  vmfloat Div::unitFactor() const {
370      const ScalarNumberExpr* pLHS = dynamic_cast<const ScalarNumberExpr*>(&*lhs);      const NumberExpr* pLHS = dynamic_cast<const NumberExpr*>(&*lhs);
371      const ScalarNumberExpr* pRHS = dynamic_cast<const ScalarNumberExpr*>(&*rhs);      const NumberExpr* pRHS = dynamic_cast<const NumberExpr*>(&*rhs);
372      return pLHS->unitFactor() / pRHS->unitFactor();      return pLHS->unitFactor() / pRHS->unitFactor();
373  }  }
374    
# Line 560  vmfloat FunctionCall::unitFactor() const Line 560  vmfloat FunctionCall::unitFactor() const
560      if (!fn || !result) return VM_NO_FACTOR;      if (!fn || !result) return VM_NO_FACTOR;
561      VMExpr* expr = result->resultValue();      VMExpr* expr = result->resultValue();
562      if (!expr) return VM_NO_FACTOR;      if (!expr) return VM_NO_FACTOR;
563      VMScalarNumberExpr* scalar = expr->asScalarNumberExpr();      VMNumberExpr* scalar = expr->asNumber();
564      if (!scalar) return VM_NO_FACTOR;      if (!scalar) return VM_NO_FACTOR;
565      return scalar->unitFactor();      return scalar->unitFactor();
566  }  }
# Line 642  Variable::Variable(const VariableDecl& d Line 642  Variable::Variable(const VariableDecl& d
642  {  {
643  }  }
644    
645  ScalarNumberVariable::ScalarNumberVariable(const VariableDecl& decl) :  NumberVariable::NumberVariable(const VariableDecl& decl) :
646      Variable(decl),      Variable(decl),
647      Unit(decl.unitType),      Unit(decl.unitType),
648      unitFactorMemPos(decl.unitFactorMemPos), polyphonic(decl.isPolyphonic),      unitFactorMemPos(decl.unitFactorMemPos), polyphonic(decl.isPolyphonic),
# Line 650  ScalarNumberVariable::ScalarNumberVariab Line 650  ScalarNumberVariable::ScalarNumberVariab
650  {  {
651  }  }
652    
653  vmfloat ScalarNumberVariable::unitFactor() const {  vmfloat NumberVariable::unitFactor() const {
654      if (isPolyphonic()) {      if (isPolyphonic()) {
655          return context->execContext->polyphonicUnitFactorMemory[unitFactorMemPos];          return context->execContext->polyphonicUnitFactorMemory[unitFactorMemPos];
656      }      }
# Line 664  inline static vmint postfixInc(vmint& ob Line 664  inline static vmint postfixInc(vmint& ob
664  }  }
665    
666  IntVariable::IntVariable(const VariableDecl& decl) :  IntVariable::IntVariable(const VariableDecl& decl) :
667      ScalarNumberVariable({      NumberVariable({
668          .ctx = decl.ctx,          .ctx = decl.ctx,
669          .isPolyphonic = decl.isPolyphonic,          .isPolyphonic = decl.isPolyphonic,
670          .isConst = decl.isConst,          .isConst = decl.isConst,
# Line 720  void IntVariable::dump(int level) { Line 720  void IntVariable::dump(int level) {
720  }  }
721    
722  RealVariable::RealVariable(const VariableDecl& decl) :  RealVariable::RealVariable(const VariableDecl& decl) :
723      ScalarNumberVariable({      NumberVariable({
724          .ctx = decl.ctx,          .ctx = decl.ctx,
725          .isPolyphonic = decl.isPolyphonic,          .isPolyphonic = decl.isPolyphonic,
726          .isConst = decl.isConst,          .isConst = decl.isConst,
# Line 1271  void ConstStringVariable::dump(int level Line 1271  void ConstStringVariable::dump(int level
1271      printf("ConstStringVariable val='%s'\n", value.c_str());      printf("ConstStringVariable val='%s'\n", value.c_str());
1272  }  }
1273    
1274  bool ScalarNumberBinaryOp::isFinal() const {  bool NumberBinaryOp::isFinal() const {
1275      ScalarNumberExprRef l = (ScalarNumberExprRef) lhs;      NumberExprRef l = (NumberExprRef) lhs;
1276      ScalarNumberExprRef r = (ScalarNumberExprRef) rhs;      NumberExprRef r = (NumberExprRef) rhs;
1277      return l->isFinal() || r->isFinal();      return l->isFinal() || r->isFinal();
1278  }  }
1279    

Legend:
Removed from v.3581  
changed lines
  Added in v.3582

  ViewVC Help
Powered by ViewVC