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 |
} |
} |
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); |
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);; |
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); |
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) { |
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) |
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) { |