79 |
}; |
}; |
80 |
typedef Ref<StringExpr,Node> StringExprRef; |
typedef Ref<StringExpr,Node> StringExprRef; |
81 |
|
|
82 |
class IntLiteral : virtual public IntExpr { |
class Unit : virtual public VMUnit { |
83 |
|
ArrayList<MetricPrefix_t> prefix; |
84 |
|
StdUnit_t unit; |
85 |
|
public: |
86 |
|
Unit() : unit(VM_NO_UNIT) {} |
87 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
88 |
|
StdUnit_t unitType() const OVERRIDE { return unit; } |
89 |
|
void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type); |
90 |
|
void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type); |
91 |
|
void copyUnitFrom(const IntExprRef& src); |
92 |
|
}; |
93 |
|
|
94 |
|
class IntLiteral : public Unit, virtual public IntExpr { |
95 |
|
bool finalVal; |
96 |
public: |
public: |
97 |
vmint value; |
vmint value; |
98 |
IntLiteral(vmint value) : value(value) { } |
IntLiteral(vmint value) : Unit(), |
99 |
|
value(value), finalVal(false) { } |
100 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
101 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
102 |
bool isConstExpr() const OVERRIDE { return true; } |
bool isConstExpr() const OVERRIDE { return true; } |
103 |
bool isPolyphonic() const OVERRIDE { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
104 |
|
bool isFinal() const OVERRIDE { return finalVal; } |
105 |
|
void setFinal(bool b = true) { finalVal = b; } |
106 |
}; |
}; |
107 |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
108 |
|
|
144 |
}; |
}; |
145 |
typedef Ref<Variable,Node> VariableRef; |
typedef Ref<Variable,Node> VariableRef; |
146 |
|
|
147 |
class IntVariable : public Variable, virtual public IntExpr { |
class IntVariable : public Variable, public Unit, virtual public IntExpr { |
148 |
bool polyphonic; |
bool polyphonic; |
149 |
|
bool finalVal; |
150 |
public: |
public: |
151 |
IntVariable(ParserContext* ctx); |
IntVariable(ParserContext* ctx); |
152 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
153 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
154 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
155 |
bool isPolyphonic() const OVERRIDE { return polyphonic; } |
bool isPolyphonic() const OVERRIDE { return polyphonic; } |
156 |
|
bool isFinal() const OVERRIDE { return finalVal; } |
157 |
|
void setFinal(bool b = true) { finalVal = b; } |
158 |
protected: |
protected: |
159 |
IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1); |
IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1); |
160 |
}; |
}; |
267 |
}; |
}; |
268 |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
269 |
|
|
270 |
class Add : virtual public BinaryOp, virtual public IntExpr { |
class IntBinaryOp : public BinaryOp, virtual public IntExpr { |
271 |
|
public: |
272 |
|
IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
273 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
274 |
|
StdUnit_t unitType() const OVERRIDE; |
275 |
|
bool isFinal() const OVERRIDE; |
276 |
|
}; |
277 |
|
typedef Ref<IntBinaryOp,Node> IntBinaryOpRef; |
278 |
|
|
279 |
|
class Add : public IntBinaryOp { |
280 |
public: |
public: |
281 |
Add(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Add(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { } |
282 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
283 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
284 |
}; |
}; |
285 |
typedef Ref<Add,Node> AddRef; |
typedef Ref<Add,Node> AddRef; |
286 |
|
|
287 |
class Sub : virtual public BinaryOp, virtual public IntExpr { |
class Sub : public IntBinaryOp { |
288 |
public: |
public: |
289 |
Sub(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Sub(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { } |
290 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
291 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
292 |
}; |
}; |
293 |
typedef Ref<Sub,Node> SubRef; |
typedef Ref<Sub,Node> SubRef; |
294 |
|
|
295 |
class Mul : virtual public BinaryOp, virtual public IntExpr { |
class Mul : public IntBinaryOp { |
296 |
public: |
public: |
297 |
Mul(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Mul(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { } |
298 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
299 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
300 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
301 |
|
StdUnit_t unitType() const OVERRIDE; |
302 |
}; |
}; |
303 |
typedef Ref<Mul,Node> MulRef; |
typedef Ref<Mul,Node> MulRef; |
304 |
|
|
305 |
class Div : virtual public BinaryOp, virtual public IntExpr { |
class Div : public IntBinaryOp { |
306 |
public: |
public: |
307 |
Div(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Div(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { } |
308 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
309 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
310 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
311 |
|
StdUnit_t unitType() const OVERRIDE; |
312 |
}; |
}; |
313 |
typedef Ref<Div,Node> DivRef; |
typedef Ref<Div,Node> DivRef; |
314 |
|
|
315 |
class Mod : virtual public BinaryOp, virtual public IntExpr { |
class Mod : public IntBinaryOp { |
316 |
public: |
public: |
317 |
Mod(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { } |
Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { } |
318 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
319 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
320 |
}; |
}; |
382 |
vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); } |
vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); } |
383 |
void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); } |
void assignIntElement(vmuint i, vmint value) OVERRIDE { return dynVar->asIntArray()->assignIntElement(i, value); } |
384 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
385 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
386 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
387 |
|
bool isFinal() const OVERRIDE { return false; } |
388 |
}; |
}; |
389 |
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
390 |
|
|
404 |
ExprType_t exprType() const OVERRIDE; |
ExprType_t exprType() const OVERRIDE; |
405 |
String evalCastToStr() OVERRIDE; |
String evalCastToStr() OVERRIDE; |
406 |
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
407 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
408 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
409 |
|
bool isFinal() const OVERRIDE { return false; } |
410 |
protected: |
protected: |
411 |
VMFnResult* execVMFn(); |
VMFnResult* execVMFn(); |
412 |
}; |
}; |
561 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
562 |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
563 |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
564 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); } |
565 |
|
StdUnit_t unitType() const OVERRIDE { return expr->unitType(); } |
566 |
|
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
567 |
}; |
}; |
568 |
typedef Ref<Neg,Node> NegRef; |
typedef Ref<Neg,Node> NegRef; |
569 |
|
|
595 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
596 |
bool isConstExpr() const OVERRIDE; |
bool isConstExpr() const OVERRIDE; |
597 |
bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
598 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
599 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
600 |
|
bool isFinal() const OVERRIDE { return false; } |
601 |
private: |
private: |
602 |
IntExprRef lhs; |
IntExprRef lhs; |
603 |
IntExprRef rhs; |
IntExprRef rhs; |
605 |
}; |
}; |
606 |
typedef Ref<Relation,Node> RelationRef; |
typedef Ref<Relation,Node> RelationRef; |
607 |
|
|
608 |
class Or : virtual public BinaryOp, virtual public IntExpr { |
class Or : public IntBinaryOp { |
609 |
public: |
public: |
610 |
Or(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
611 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
612 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
613 |
}; |
}; |
614 |
typedef Ref<Or,Node> OrRef; |
typedef Ref<Or,Node> OrRef; |
615 |
|
|
616 |
class BitwiseOr : virtual public BinaryOp, virtual public IntExpr { |
class BitwiseOr : public IntBinaryOp { |
617 |
public: |
public: |
618 |
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
619 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
620 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
621 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
622 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
623 |
}; |
}; |
624 |
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
625 |
|
|
626 |
class And : virtual public BinaryOp, virtual public IntExpr { |
class And : public IntBinaryOp { |
627 |
public: |
public: |
628 |
And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
629 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
630 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
631 |
}; |
}; |
632 |
typedef Ref<And,Node> AndRef; |
typedef Ref<And,Node> AndRef; |
633 |
|
|
634 |
class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr { |
class BitwiseAnd : public IntBinaryOp { |
635 |
public: |
public: |
636 |
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
637 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
638 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
639 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
640 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
641 |
}; |
}; |
642 |
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
643 |
|
|
649 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
650 |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
651 |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
652 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
653 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
654 |
|
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
655 |
}; |
}; |
656 |
typedef Ref<Not,Node> NotRef; |
typedef Ref<Not,Node> NotRef; |
657 |
|
|
663 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
664 |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
665 |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
666 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
667 |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
668 |
|
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
669 |
}; |
}; |
670 |
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
671 |
|
|
672 |
|
class Final : virtual public IntExpr { |
673 |
|
IntExprRef expr; |
674 |
|
public: |
675 |
|
Final(IntExprRef expr) : expr(expr) {} |
676 |
|
vmint evalInt() OVERRIDE { return expr->evalInt(); } |
677 |
|
void dump(int level = 0) OVERRIDE; |
678 |
|
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
679 |
|
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
680 |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); } |
681 |
|
StdUnit_t unitType() const OVERRIDE { return expr->unitType(); } |
682 |
|
bool isFinal() const OVERRIDE { return true; } |
683 |
|
}; |
684 |
|
typedef Ref<Final,Node> FinalRef; |
685 |
|
|
686 |
class ParserContext : public VMParserContext { |
class ParserContext : public VMParserContext { |
687 |
public: |
public: |
688 |
struct Error { |
struct Error { |