21 |
#include <map> |
#include <map> |
22 |
#include <set> |
#include <set> |
23 |
#include <string.h> // for memset() |
#include <string.h> // for memset() |
24 |
|
#include <assert.h> |
25 |
#include "../common/global.h" |
#include "../common/global.h" |
26 |
#include "../common/Ref.h" |
#include "../common/Ref.h" |
27 |
#include "../common/ArrayList.h" |
#include "../common/ArrayList.h" |
41 |
STMT_NOOP, |
STMT_NOOP, |
42 |
}; |
}; |
43 |
|
|
44 |
|
/** |
45 |
|
* Convenience function used for retrieving the (assumed) data type of a given |
46 |
|
* script variable name. |
47 |
|
* |
48 |
|
* @param name - some script variable name (e.g. "$foo") |
49 |
|
* @return variable's assumed data type (e.g. INT_EXPR for example above) |
50 |
|
*/ |
51 |
|
inline ExprType_t exprTypeOfVarName(const String& name) { |
52 |
|
if (name.empty()) return (ExprType_t) -1; |
53 |
|
const char prefix = name[0]; |
54 |
|
switch (prefix) { |
55 |
|
case '$': return INT_EXPR; |
56 |
|
case '%': return INT_ARR_EXPR; |
57 |
|
case '~': return REAL_EXPR; |
58 |
|
case '?': return REAL_ARR_EXPR; |
59 |
|
case '@': return STRING_EXPR; |
60 |
|
case '!': return STRING_ARR_EXPR; |
61 |
|
} |
62 |
|
return (ExprType_t) -1; |
63 |
|
} |
64 |
|
|
65 |
|
inline ExprType_t scalarTypeOfArray(ExprType_t arrayType) { |
66 |
|
if (arrayType == INT_ARR_EXPR) return INT_EXPR; |
67 |
|
if (arrayType == REAL_ARR_EXPR) return REAL_EXPR; |
68 |
|
if (arrayType == STRING_ARR_EXPR) return STRING_EXPR; |
69 |
|
assert(false); |
70 |
|
return EMPTY_EXPR; // just to shut up the compiler |
71 |
|
} |
72 |
|
|
73 |
|
/** |
74 |
|
* Used by parser for parser error messages to provide a text with all data |
75 |
|
* types accepted by the given built-in function @a fn for the respective |
76 |
|
* function argument @a iArg. |
77 |
|
*/ |
78 |
|
String acceptedArgTypesStr(VMFunction* fn, vmint iArg); |
79 |
|
|
80 |
class Node { |
class Node { |
81 |
public: |
public: |
82 |
Node(); |
Node(); |
96 |
typedef Ref<Expression,Node> ExpressionRef; |
typedef Ref<Expression,Node> ExpressionRef; |
97 |
|
|
98 |
class Unit : virtual public VMUnit, virtual public Node { |
class Unit : virtual public VMUnit, virtual public Node { |
|
ArrayList<MetricPrefix_t> prefix; |
|
99 |
StdUnit_t unit; |
StdUnit_t unit; |
100 |
public: |
public: |
101 |
Unit() : unit(VM_NO_UNIT) {} |
Unit(StdUnit_t type) : unit(type) {} |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
|
102 |
StdUnit_t unitType() const OVERRIDE { return unit; } |
StdUnit_t unitType() const OVERRIDE { return unit; } |
103 |
void setUnit(const std::vector<MetricPrefix_t>& prefix, StdUnit_t type); |
static vmint convIntToUnitFactor(vmint iValue, VMUnit* srcUnit, VMUnit* dstUnit); |
104 |
void setUnit(const MetricPrefix_t* prefixes, StdUnit_t type); |
static vmint convIntToUnitFactor(vmint iValue, vmfloat srcFactor, vmfloat dstFactor); |
105 |
void copyUnitFrom(const Ref<Unit,Node>& src); |
static vmfloat convRealToUnitFactor(vmfloat fValue, VMUnit* srcUnit, VMUnit* dstUnit); |
106 |
|
static vmfloat convRealToUnitFactor(vmfloat fValue, vmfloat srcFactor, vmfloat dstFactor); |
107 |
}; |
}; |
108 |
typedef Ref<Unit,Node> UnitRef; |
typedef Ref<Unit,Node> UnitRef; |
109 |
|
|
110 |
class ScalarNumberExpr : virtual public Unit, virtual public VMScalarNumberExpr, virtual public Expression { |
class NumberExpr : virtual public Unit, virtual public VMNumberExpr, virtual public Expression { |
111 |
public: |
public: |
112 |
}; |
}; |
113 |
typedef Ref<ScalarNumberExpr,Node> ScalarNumberExprRef; |
typedef Ref<NumberExpr,Node> NumberExprRef; |
114 |
|
|
115 |
class IntExpr : virtual public ScalarNumberExpr, virtual public VMIntExpr { |
class IntExpr : virtual public NumberExpr, virtual public VMIntExpr { |
116 |
public: |
public: |
117 |
ExprType_t exprType() const OVERRIDE { return INT_EXPR; } |
ExprType_t exprType() const OVERRIDE { return INT_EXPR; } |
118 |
|
vmint evalIntToUnitFactor(vmfloat unitFactor); |
119 |
String evalCastToStr() OVERRIDE; |
String evalCastToStr() OVERRIDE; |
120 |
}; |
}; |
121 |
typedef Ref<IntExpr,Node> IntExprRef; |
typedef Ref<IntExpr,Node> IntExprRef; |
122 |
|
|
123 |
class RealExpr : virtual public ScalarNumberExpr, virtual public VMRealExpr { |
class RealExpr : virtual public NumberExpr, virtual public VMRealExpr { |
124 |
public: |
public: |
125 |
ExprType_t exprType() const OVERRIDE { return REAL_EXPR; } |
ExprType_t exprType() const OVERRIDE { return REAL_EXPR; } |
126 |
|
vmfloat evalRealToUnitFactor(vmfloat unitFactor); |
127 |
String evalCastToStr() OVERRIDE; |
String evalCastToStr() OVERRIDE; |
128 |
}; |
}; |
129 |
typedef Ref<RealExpr,Node> RealExprRef; |
typedef Ref<RealExpr,Node> RealExprRef; |
154 |
}; |
}; |
155 |
typedef Ref<StringExpr,Node> StringExprRef; |
typedef Ref<StringExpr,Node> StringExprRef; |
156 |
|
|
157 |
|
struct IntLitDef { |
158 |
|
vmint value; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression. |
159 |
|
vmfloat unitFactor = VM_NO_FACTOR; |
160 |
|
StdUnit_t unitType = VM_NO_UNIT; |
161 |
|
bool isFinal; |
162 |
|
}; |
163 |
|
|
164 |
class IntLiteral FINAL : public IntExpr { |
class IntLiteral FINAL : public IntExpr { |
165 |
bool finalVal; |
bool finalVal; |
166 |
public: |
vmfloat unitPrefixFactor; |
167 |
vmint value; |
vmint value; |
168 |
IntLiteral(vmint value) : IntExpr(), |
public: |
169 |
value(value), finalVal(false) { } |
IntLiteral(const IntLitDef& def); |
170 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
171 |
|
vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; } |
172 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
173 |
bool isConstExpr() const OVERRIDE { return true; } |
bool isConstExpr() const OVERRIDE { return true; } |
174 |
bool isPolyphonic() const OVERRIDE { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
175 |
bool isFinal() const OVERRIDE { return finalVal; } |
bool isFinal() const OVERRIDE { return finalVal; } |
|
void setFinal(bool b = true) { finalVal = b; } |
|
176 |
}; |
}; |
177 |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
178 |
|
|
179 |
|
struct RealLitDef { |
180 |
|
vmfloat value; //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression. |
181 |
|
vmfloat unitFactor = VM_NO_FACTOR; |
182 |
|
StdUnit_t unitType = VM_NO_UNIT; |
183 |
|
bool isFinal; |
184 |
|
}; |
185 |
|
|
186 |
class RealLiteral FINAL : public RealExpr { |
class RealLiteral FINAL : public RealExpr { |
|
vmfloat value; |
|
187 |
bool finalVal; |
bool finalVal; |
188 |
|
vmfloat unitPrefixFactor; |
189 |
|
vmfloat value; |
190 |
public: |
public: |
191 |
RealLiteral(vmfloat value) : RealExpr(), |
RealLiteral(const RealLitDef& def); |
|
value(value), finalVal(false) { } |
|
192 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
193 |
|
vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; } |
194 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
195 |
bool isConstExpr() const OVERRIDE { return true; } |
bool isConstExpr() const OVERRIDE { return true; } |
196 |
bool isPolyphonic() const OVERRIDE { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
197 |
bool isFinal() const OVERRIDE { return finalVal; } |
bool isFinal() const OVERRIDE { return finalVal; } |
|
void setFinal(bool b = true) { finalVal = b; } |
|
198 |
}; |
}; |
199 |
typedef Ref<RealLiteral,Node> RealLiteralRef; |
typedef Ref<RealLiteral,Node> RealLiteralRef; |
200 |
|
|
201 |
class StringLiteral FINAL : public StringExpr { |
class StringLiteral FINAL : public StringExpr { |
|
public: |
|
202 |
String value; |
String value; |
203 |
|
public: |
204 |
StringLiteral(const String& value) : value(value) { } |
StringLiteral(const String& value) : value(value) { } |
205 |
bool isConstExpr() const OVERRIDE { return true; } |
bool isConstExpr() const OVERRIDE { return true; } |
206 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
220 |
}; |
}; |
221 |
typedef Ref<Args,Node> ArgsRef; |
typedef Ref<Args,Node> ArgsRef; |
222 |
|
|
223 |
|
struct VariableDecl { |
224 |
|
ParserContext* ctx; |
225 |
|
bool isPolyphonic; |
226 |
|
bool isConst; |
227 |
|
vmint elements = 1; |
228 |
|
vmint memPos; |
229 |
|
vmint unitFactorMemPos; |
230 |
|
StdUnit_t unitType = VM_NO_UNIT; |
231 |
|
bool isFinal; |
232 |
|
}; |
233 |
|
|
234 |
class Variable : virtual public VMVariable, virtual public Expression { |
class Variable : virtual public VMVariable, virtual public Expression { |
235 |
public: |
public: |
236 |
bool isConstExpr() const OVERRIDE { return bConst; } |
bool isConstExpr() const OVERRIDE { return bConst; } |
238 |
virtual void assign(Expression* expr) = 0; |
virtual void assign(Expression* expr) = 0; |
239 |
void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); } |
void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); } |
240 |
protected: |
protected: |
241 |
Variable(ParserContext* ctx, vmint _memPos, bool _bConst) |
Variable(const VariableDecl& decl); |
|
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
|
242 |
|
|
243 |
ParserContext* context; |
ParserContext* context; |
244 |
vmint memPos; |
vmint memPos; |
246 |
}; |
}; |
247 |
typedef Ref<Variable,Node> VariableRef; |
typedef Ref<Variable,Node> VariableRef; |
248 |
|
|
249 |
class ScalarNumberVariable : public Variable, virtual public ScalarNumberExpr { |
class NumberVariable : public Variable, virtual public NumberExpr { |
250 |
bool polyphonic; |
bool polyphonic; |
251 |
bool finalVal; |
bool finalVal; |
252 |
|
protected: |
253 |
|
vmint unitFactorMemPos; |
254 |
public: |
public: |
255 |
bool isPolyphonic() const OVERRIDE { return polyphonic; } |
bool isPolyphonic() const OVERRIDE { return polyphonic; } |
256 |
bool isFinal() const OVERRIDE { return finalVal; } |
bool isFinal() const OVERRIDE { return finalVal; } |
257 |
void setFinal(bool b = true) { finalVal = b; } |
vmfloat unitFactor() const OVERRIDE; |
258 |
protected: |
protected: |
259 |
ScalarNumberVariable(ParserContext* ctx, vmint _memPos, |
NumberVariable(const VariableDecl& decl); |
|
bool _bConst = false, bool _bPolyphonic = false, |
|
|
bool _bFinal = false); |
|
260 |
}; |
}; |
261 |
typedef Ref<ScalarNumberVariable,Node> ScalarNumberVariableRef; |
typedef Ref<NumberVariable,Node> NumberVariableRef; |
262 |
|
|
263 |
class IntVariable : public ScalarNumberVariable, virtual public IntExpr { |
class IntVariable : public NumberVariable, virtual public IntExpr { |
264 |
public: |
public: |
265 |
IntVariable(ParserContext* ctx); |
IntVariable(const VariableDecl& decl); |
266 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
267 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
268 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
|
protected: |
|
|
IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1); |
|
269 |
}; |
}; |
270 |
typedef Ref<IntVariable,Node> IntVariableRef; |
typedef Ref<IntVariable,Node> IntVariableRef; |
271 |
|
|
272 |
class RealVariable : public ScalarNumberVariable, virtual public RealExpr { |
class RealVariable : public NumberVariable, virtual public RealExpr { |
273 |
public: |
public: |
274 |
RealVariable(ParserContext* ctx); |
RealVariable(const VariableDecl& decl); |
275 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
276 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
277 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
|
protected: |
|
|
RealVariable(ParserContext* ctx, bool polyphonic, bool bConst, vmint size = 1); |
|
278 |
}; |
}; |
279 |
typedef Ref<RealVariable,Node> RealVariableRef; |
typedef Ref<RealVariable,Node> RealVariableRef; |
280 |
|
|
281 |
|
struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17 |
282 |
|
// additions for RealVarDef |
283 |
|
vmint value = 0; //NOTE: sequence matters! Since this is usually initialized with VMIntExpr::evalInt() it should be before member unitFactor, since the latter is usually initialized with VMIntExpr::unitFactor() which does not evaluate the expression. |
284 |
|
vmfloat unitFactor = VM_NO_FACTOR; |
285 |
|
// copied from VariableDecl |
286 |
|
ParserContext* ctx; |
287 |
|
bool isPolyphonic; |
288 |
|
bool isConst; |
289 |
|
vmint elements = 1; |
290 |
|
vmint memPos; |
291 |
|
vmint unitFactorMemPos; |
292 |
|
StdUnit_t unitType = VM_NO_UNIT; |
293 |
|
bool isFinal; |
294 |
|
}; |
295 |
|
|
296 |
class ConstIntVariable FINAL : public IntVariable { |
class ConstIntVariable FINAL : public IntVariable { |
297 |
public: |
vmfloat unitPrefixFactor; |
298 |
vmint value; |
vmint value; |
299 |
|
public: |
300 |
ConstIntVariable(vmint value); |
ConstIntVariable(const IntVarDef& def); |
301 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
302 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
303 |
|
vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; } |
304 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
305 |
}; |
}; |
306 |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
307 |
|
|
308 |
|
struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17 |
309 |
|
// additions for RealVarDef |
310 |
|
vmfloat value = vmfloat(0); //NOTE: sequence matters! Since this is usually initialized with VMRealExpr::evalReal() it should be before member unitFactor, since the latter is usually initialized with VMRealExpr::unitFactor() which does not evaluate the expression. |
311 |
|
vmfloat unitFactor = VM_NO_FACTOR; |
312 |
|
// copied from VariableDecl |
313 |
|
ParserContext* ctx; |
314 |
|
bool isPolyphonic; |
315 |
|
bool isConst; |
316 |
|
vmint elements = 1; |
317 |
|
vmint memPos; |
318 |
|
vmint unitFactorMemPos; |
319 |
|
StdUnit_t unitType = VM_NO_UNIT; |
320 |
|
bool isFinal; |
321 |
|
}; |
322 |
|
|
323 |
class ConstRealVariable FINAL : public RealVariable { |
class ConstRealVariable FINAL : public RealVariable { |
324 |
public: |
vmfloat unitPrefixFactor; |
325 |
vmfloat value; |
vmfloat value; |
326 |
|
public: |
327 |
ConstRealVariable(vmfloat value); |
ConstRealVariable(const RealVarDef& def); |
328 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
329 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
330 |
|
vmfloat unitFactor() const OVERRIDE { return unitPrefixFactor; } |
331 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
332 |
}; |
}; |
333 |
typedef Ref<ConstRealVariable,Node> ConstRealVariableRef; |
typedef Ref<ConstRealVariable,Node> ConstRealVariableRef; |
340 |
bool isAssignable() const OVERRIDE { return ptr->isAssignable(); } |
bool isAssignable() const OVERRIDE { return ptr->isAssignable(); } |
341 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
342 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
343 |
|
vmfloat unitFactor() const OVERRIDE { return VM_NO_UNIT; } |
344 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
345 |
}; |
}; |
346 |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
347 |
|
|
348 |
class PolyphonicIntVariable FINAL : public IntVariable { |
class PolyphonicIntVariable FINAL : public IntVariable { |
349 |
public: |
public: |
350 |
PolyphonicIntVariable(ParserContext* ctx); |
PolyphonicIntVariable(const VariableDecl& decl); |
351 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
352 |
}; |
}; |
353 |
typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef; |
typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef; |
354 |
|
|
355 |
class PolyphonicRealVariable FINAL : public RealVariable { |
class PolyphonicRealVariable FINAL : public RealVariable { |
356 |
public: |
public: |
357 |
PolyphonicRealVariable(ParserContext* ctx); |
PolyphonicRealVariable(const VariableDecl& decl); |
358 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
359 |
}; |
}; |
360 |
typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef; |
typedef Ref<PolyphonicRealVariable,Node> PolyphonicRealVariableRef; |
361 |
|
|
362 |
class IntArrayVariable : public Variable, virtual public IntArrayExpr { |
class IntArrayVariable : public Variable, virtual public IntArrayExpr { |
363 |
ArrayList<vmint> values; |
ArrayList<vmint> values; |
364 |
|
ArrayList<vmfloat> unitFactors; |
365 |
public: |
public: |
366 |
IntArrayVariable(ParserContext* ctx, vmint size); |
IntArrayVariable(ParserContext* ctx, vmint size); |
367 |
IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false); |
IntArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false); |
368 |
void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment |
void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment |
|
String evalCastToStr() OVERRIDE { return ""; } // ignore scalar cast to string |
|
369 |
ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; } |
ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; } |
370 |
virtual vmint arraySize() const OVERRIDE { return values.size(); } |
virtual vmint arraySize() const OVERRIDE { return values.size(); } |
371 |
virtual vmint evalIntElement(vmuint i) OVERRIDE; |
virtual vmint evalIntElement(vmuint i) OVERRIDE; |
372 |
virtual void assignIntElement(vmuint i, vmint value) OVERRIDE; |
virtual void assignIntElement(vmuint i, vmint value) OVERRIDE; |
373 |
|
vmfloat unitFactorOfElement(vmuint i) const OVERRIDE; |
374 |
|
void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE; |
375 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
376 |
bool isPolyphonic() const OVERRIDE { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
377 |
protected: |
protected: |
381 |
|
|
382 |
class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr { |
class RealArrayVariable FINAL : public Variable, virtual public RealArrayExpr { |
383 |
ArrayList<vmfloat> values; |
ArrayList<vmfloat> values; |
384 |
|
ArrayList<vmfloat> unitFactors; |
385 |
public: |
public: |
386 |
RealArrayVariable(ParserContext* ctx, vmint size); |
RealArrayVariable(ParserContext* ctx, vmint size); |
387 |
RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false); |
RealArrayVariable(ParserContext* ctx, vmint size, ArgsRef values, bool _bConst = false); |
388 |
void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment |
void assign(Expression* expr) OVERRIDE {} // ignore scalar assignment |
|
String evalCastToStr() OVERRIDE { return ""; } // ignore scalar cast to string |
|
389 |
ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; } |
ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; } |
390 |
virtual vmint arraySize() const OVERRIDE { return values.size(); } |
virtual vmint arraySize() const OVERRIDE { return values.size(); } |
391 |
virtual vmfloat evalRealElement(vmuint i) OVERRIDE; |
virtual vmfloat evalRealElement(vmuint i) OVERRIDE; |
392 |
virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE; |
virtual void assignRealElement(vmuint i, vmfloat value) OVERRIDE; |
393 |
|
vmfloat unitFactorOfElement(vmuint i) const OVERRIDE; |
394 |
|
void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE; |
395 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
396 |
bool isPolyphonic() const OVERRIDE { return false; } |
bool isPolyphonic() const OVERRIDE { return false; } |
397 |
protected: |
protected: |
406 |
BuiltInIntArrayVariable(const String& name, VMInt8Array* array); |
BuiltInIntArrayVariable(const String& name, VMInt8Array* array); |
407 |
vmint arraySize() const OVERRIDE { return array->size; } |
vmint arraySize() const OVERRIDE { return array->size; } |
408 |
vmint evalIntElement(vmuint i) OVERRIDE; |
vmint evalIntElement(vmuint i) OVERRIDE; |
|
bool isAssignable() const OVERRIDE { return !array->readonly; } |
|
409 |
void assignIntElement(vmuint i, vmint value) OVERRIDE; |
void assignIntElement(vmuint i, vmint value) OVERRIDE; |
410 |
|
vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; } |
411 |
|
void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {} |
412 |
|
bool isAssignable() const OVERRIDE { return !array->readonly; } |
413 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
414 |
}; |
}; |
415 |
typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef; |
typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef; |
417 |
class IntArrayElement FINAL : public IntVariable { |
class IntArrayElement FINAL : public IntVariable { |
418 |
IntArrayExprRef array; |
IntArrayExprRef array; |
419 |
IntExprRef index; |
IntExprRef index; |
420 |
|
vmint currentIndex; |
421 |
public: |
public: |
422 |
IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex); |
IntArrayElement(IntArrayExprRef array, IntExprRef arrayIndex); |
423 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
424 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
425 |
|
vmfloat unitFactor() const OVERRIDE; |
426 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
427 |
}; |
}; |
428 |
typedef Ref<IntArrayElement,Node> IntArrayElementRef; |
typedef Ref<IntArrayElement,Node> IntArrayElementRef; |
430 |
class RealArrayElement FINAL : public RealVariable { |
class RealArrayElement FINAL : public RealVariable { |
431 |
RealArrayExprRef array; |
RealArrayExprRef array; |
432 |
IntExprRef index; |
IntExprRef index; |
433 |
|
vmint currentIndex; |
434 |
public: |
public: |
435 |
RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex); |
RealArrayElement(RealArrayExprRef array, IntExprRef arrayIndex); |
436 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
437 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
438 |
|
vmfloat unitFactor() const OVERRIDE; |
439 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
440 |
}; |
}; |
441 |
typedef Ref<RealArrayElement,Node> RealArrayElementRef; |
typedef Ref<RealArrayElement,Node> RealArrayElementRef; |
453 |
typedef Ref<StringVariable,Node> StringVariableRef; |
typedef Ref<StringVariable,Node> StringVariableRef; |
454 |
|
|
455 |
class ConstStringVariable FINAL : public StringVariable { |
class ConstStringVariable FINAL : public StringVariable { |
|
public: |
|
456 |
String value; |
String value; |
457 |
|
public: |
458 |
ConstStringVariable(ParserContext* ctx, String value = ""); |
ConstStringVariable(ParserContext* ctx, String value = ""); |
459 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
460 |
String evalStr() OVERRIDE; |
String evalStr() OVERRIDE; |
473 |
}; |
}; |
474 |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
475 |
|
|
476 |
class ScalarNumberBinaryOp : public BinaryOp, virtual public ScalarNumberExpr { |
class NumberBinaryOp : public BinaryOp, virtual public NumberExpr { |
477 |
public: |
public: |
478 |
ScalarNumberBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : BinaryOp(lhs, rhs) { } |
NumberBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : BinaryOp(lhs, rhs) { } |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
|
|
StdUnit_t unitType() const OVERRIDE; |
|
479 |
bool isFinal() const OVERRIDE; |
bool isFinal() const OVERRIDE; |
480 |
}; |
}; |
481 |
typedef Ref<ScalarNumberBinaryOp,Node> ScalarNumberBinaryOpRef; |
typedef Ref<NumberBinaryOp,Node> NumberBinaryOpRef; |
482 |
|
|
483 |
class IntBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr { |
class IntBinaryOp : public NumberBinaryOp, virtual public IntExpr { |
484 |
public: |
public: |
485 |
IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { } |
IntBinaryOp(IntExprRef lhs, IntExprRef rhs) : NumberBinaryOp(lhs, rhs) { } |
486 |
}; |
}; |
487 |
typedef Ref<IntBinaryOp,Node> IntBinaryOpRef; |
typedef Ref<IntBinaryOp,Node> IntBinaryOpRef; |
488 |
|
|
489 |
class VaritypeScalarBinaryOp : public ScalarNumberBinaryOp, virtual public IntExpr, virtual public RealExpr { |
class VaritypeScalarBinaryOp : public NumberBinaryOp, virtual public IntExpr, virtual public RealExpr { |
490 |
public: |
public: |
491 |
VaritypeScalarBinaryOp(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : ScalarNumberBinaryOp(lhs, rhs) { } |
VaritypeScalarBinaryOp(NumberExprRef lhs, NumberExprRef rhs) : NumberBinaryOp(lhs, rhs) { } |
492 |
ExprType_t exprType() const OVERRIDE; |
ExprType_t exprType() const OVERRIDE; |
493 |
String evalCastToStr() OVERRIDE; |
String evalCastToStr() OVERRIDE; |
494 |
}; |
}; |
496 |
|
|
497 |
class Add FINAL : public VaritypeScalarBinaryOp { |
class Add FINAL : public VaritypeScalarBinaryOp { |
498 |
public: |
public: |
499 |
Add(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { } |
Add(NumberExprRef lhs, NumberExprRef rhs); |
500 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
501 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
502 |
|
vmfloat unitFactor() const OVERRIDE; |
503 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
504 |
}; |
}; |
505 |
typedef Ref<Add,Node> AddRef; |
typedef Ref<Add,Node> AddRef; |
506 |
|
|
507 |
class Sub FINAL : public VaritypeScalarBinaryOp { |
class Sub FINAL : public VaritypeScalarBinaryOp { |
508 |
public: |
public: |
509 |
Sub(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { } |
Sub(NumberExprRef lhs, NumberExprRef rhs); |
510 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
511 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
512 |
|
vmfloat unitFactor() const OVERRIDE; |
513 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
514 |
}; |
}; |
515 |
typedef Ref<Sub,Node> SubRef; |
typedef Ref<Sub,Node> SubRef; |
516 |
|
|
517 |
class Mul FINAL : public VaritypeScalarBinaryOp { |
class Mul FINAL : public VaritypeScalarBinaryOp { |
518 |
public: |
public: |
519 |
Mul(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { } |
Mul(NumberExprRef lhs, NumberExprRef rhs); |
520 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
521 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
522 |
|
vmfloat unitFactor() const OVERRIDE; |
523 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
|
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
|
|
StdUnit_t unitType() const OVERRIDE; |
|
524 |
}; |
}; |
525 |
typedef Ref<Mul,Node> MulRef; |
typedef Ref<Mul,Node> MulRef; |
526 |
|
|
527 |
class Div FINAL : public VaritypeScalarBinaryOp { |
class Div FINAL : public VaritypeScalarBinaryOp { |
528 |
public: |
public: |
529 |
Div(ScalarNumberExprRef lhs, ScalarNumberExprRef rhs) : VaritypeScalarBinaryOp(lhs, rhs) { } |
Div(NumberExprRef lhs, NumberExprRef rhs); |
530 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
531 |
vmfloat evalReal() OVERRIDE; |
vmfloat evalReal() OVERRIDE; |
532 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
533 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE; |
vmfloat unitFactor() const OVERRIDE; |
|
StdUnit_t unitType() const OVERRIDE; |
|
534 |
}; |
}; |
535 |
typedef Ref<Div,Node> DivRef; |
typedef Ref<Div,Node> DivRef; |
536 |
|
|
537 |
class Mod FINAL : public IntBinaryOp { |
class Mod FINAL : public IntBinaryOp { |
538 |
public: |
public: |
539 |
Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs) { } |
Mod(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs, rhs), Unit(VM_NO_UNIT) { } |
540 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
541 |
|
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
542 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
543 |
}; |
}; |
544 |
typedef Ref<Mod,Node> ModRef; |
typedef Ref<Mod,Node> ModRef; |
604 |
vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); } |
vmint arraySize() const OVERRIDE { return dynVar->asIntArray()->arraySize(); } |
605 |
vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); } |
vmint evalIntElement(vmuint i) OVERRIDE { return dynVar->asIntArray()->evalIntElement(i); } |
606 |
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); } |
607 |
|
vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; } |
608 |
|
void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {} |
609 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
610 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
|
611 |
bool isFinal() const OVERRIDE { return false; } |
bool isFinal() const OVERRIDE { return false; } |
612 |
}; |
}; |
613 |
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
616 |
String functionName; |
String functionName; |
617 |
ArgsRef args; |
ArgsRef args; |
618 |
VMFunction* fn; |
VMFunction* fn; |
619 |
|
VMFnResult* result; |
620 |
public: |
public: |
621 |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn); |
|
functionName(function), args(args), fn(fn) { } |
|
622 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
623 |
StmtFlags_t exec() OVERRIDE; |
StmtFlags_t exec() OVERRIDE; |
624 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
630 |
ExprType_t exprType() const OVERRIDE; |
ExprType_t exprType() const OVERRIDE; |
631 |
String evalCastToStr() OVERRIDE; |
String evalCastToStr() OVERRIDE; |
632 |
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
633 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
vmfloat unitFactor() const OVERRIDE; |
634 |
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
bool isFinal() const OVERRIDE; |
|
bool isFinal() const OVERRIDE { return false; } |
|
635 |
protected: |
protected: |
636 |
VMFnResult* execVMFn(); |
VMFnResult* execVMFn(); |
637 |
}; |
}; |
639 |
|
|
640 |
class NoFunctionCall FINAL : public FunctionCall { |
class NoFunctionCall FINAL : public FunctionCall { |
641 |
public: |
public: |
642 |
NoFunctionCall() : FunctionCall("nothing", new Args, NULL) {} |
NoFunctionCall() : FunctionCall("nothing", new Args, NULL), Unit(VM_NO_UNIT) {} |
643 |
StmtType_t statementType() const OVERRIDE { return STMT_NOOP; } |
StmtType_t statementType() const OVERRIDE { return STMT_NOOP; } |
644 |
}; |
}; |
645 |
typedef Ref<NoFunctionCall,Node> NoFunctionCallRef; |
typedef Ref<NoFunctionCall,Node> NoFunctionCallRef; |
745 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
746 |
vmint evalBranch() OVERRIDE; |
vmint evalBranch() OVERRIDE; |
747 |
Statements* branch(vmuint i) const OVERRIDE; |
Statements* branch(vmuint i) const OVERRIDE; |
|
//void addBranch(IntExprRef condition, StatementsRef statements); |
|
|
//void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements); |
|
|
//void addBranch(CaseBranchRef branch); |
|
|
//void addBranches(CaseBranchesRef branches); |
|
748 |
bool isPolyphonic() const OVERRIDE; |
bool isPolyphonic() const OVERRIDE; |
749 |
}; |
}; |
750 |
typedef Ref<SelectCase,Node> SelectCaseRef; |
typedef Ref<SelectCase,Node> SelectCaseRef; |
773 |
}; |
}; |
774 |
typedef Ref<SyncBlock,Node> SyncBlockRef; |
typedef Ref<SyncBlock,Node> SyncBlockRef; |
775 |
|
|
776 |
class Neg FINAL : public IntExpr { |
class Neg FINAL : virtual public IntExpr, virtual public RealExpr { |
777 |
IntExprRef expr; |
NumberExprRef expr; |
778 |
public: |
public: |
779 |
Neg(IntExprRef expr) : expr(expr) { } |
Neg(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) { } |
780 |
vmint evalInt() OVERRIDE { return (expr) ? -expr->evalInt() : 0; } |
ExprType_t exprType() const OVERRIDE { return expr->exprType(); } |
781 |
|
vmint evalInt() OVERRIDE { return (expr) ? -(expr->asInt()->evalInt()) : 0; } |
782 |
|
vmfloat evalReal() OVERRIDE { return (expr) ? -(expr->asReal()->evalReal()) : vmfloat(0); } |
783 |
|
String evalCastToStr() OVERRIDE; |
784 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
785 |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
786 |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
787 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); } |
vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); } |
|
StdUnit_t unitType() const OVERRIDE { return expr->unitType(); } |
|
788 |
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
789 |
}; |
}; |
790 |
typedef Ref<Neg,Node> NegRef; |
typedef Ref<Neg,Node> NegRef; |
811 |
EQUAL, |
EQUAL, |
812 |
NOT_EQUAL |
NOT_EQUAL |
813 |
}; |
}; |
814 |
Relation(ExpressionRef lhs, Type type, ExpressionRef rhs) : |
Relation(ExpressionRef lhs, Type type, ExpressionRef rhs); |
|
lhs(lhs), rhs(rhs), type(type) {} |
|
815 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
816 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
817 |
bool isConstExpr() const OVERRIDE; |
bool isConstExpr() const OVERRIDE; |
818 |
bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
819 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
|
820 |
bool isFinal() const OVERRIDE { return false; } |
bool isFinal() const OVERRIDE { return false; } |
821 |
private: |
private: |
822 |
ExpressionRef lhs; |
ExpressionRef lhs; |
827 |
|
|
828 |
class Or FINAL : public IntBinaryOp { |
class Or FINAL : public IntBinaryOp { |
829 |
public: |
public: |
830 |
Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
Or(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {} |
831 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
832 |
|
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
833 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
834 |
}; |
}; |
835 |
typedef Ref<Or,Node> OrRef; |
typedef Ref<Or,Node> OrRef; |
836 |
|
|
837 |
class BitwiseOr FINAL : public IntBinaryOp { |
class BitwiseOr FINAL : public IntBinaryOp { |
838 |
public: |
public: |
839 |
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {} |
840 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
841 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
842 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
|
843 |
}; |
}; |
844 |
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
845 |
|
|
846 |
class And FINAL : public IntBinaryOp { |
class And FINAL : public IntBinaryOp { |
847 |
public: |
public: |
848 |
And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
And(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {} |
849 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
850 |
|
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
851 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
852 |
}; |
}; |
853 |
typedef Ref<And,Node> AndRef; |
typedef Ref<And,Node> AndRef; |
854 |
|
|
855 |
class BitwiseAnd FINAL : public IntBinaryOp { |
class BitwiseAnd FINAL : public IntBinaryOp { |
856 |
public: |
public: |
857 |
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs) {} |
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : IntBinaryOp(lhs,rhs), Unit(VM_NO_UNIT) {} |
858 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
859 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
860 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
|
861 |
}; |
}; |
862 |
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
863 |
|
|
864 |
class Not FINAL : virtual public IntExpr { |
class Not FINAL : virtual public IntExpr { |
865 |
IntExprRef expr; |
IntExprRef expr; |
866 |
public: |
public: |
867 |
Not(IntExprRef expr) : expr(expr) {} |
Not(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {} |
868 |
vmint evalInt() OVERRIDE { return !expr->evalInt(); } |
vmint evalInt() OVERRIDE { return !expr->evalInt(); } |
869 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
870 |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
871 |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
872 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
|
873 |
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
874 |
}; |
}; |
875 |
typedef Ref<Not,Node> NotRef; |
typedef Ref<Not,Node> NotRef; |
877 |
class BitwiseNot FINAL : virtual public IntExpr { |
class BitwiseNot FINAL : virtual public IntExpr { |
878 |
IntExprRef expr; |
IntExprRef expr; |
879 |
public: |
public: |
880 |
BitwiseNot(IntExprRef expr) : expr(expr) {} |
BitwiseNot(IntExprRef expr) : Unit(VM_NO_UNIT), expr(expr) {} |
881 |
vmint evalInt() OVERRIDE { return ~expr->evalInt(); } |
vmint evalInt() OVERRIDE { return ~expr->evalInt(); } |
882 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
883 |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
884 |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
885 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; } |
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
|
StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; } |
|
886 |
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
bool isFinal() const OVERRIDE { return expr->isFinal(); } |
887 |
}; |
}; |
888 |
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
889 |
|
|
890 |
class Final FINAL : virtual public IntExpr, virtual public RealExpr { |
class Final FINAL : virtual public IntExpr, virtual public RealExpr { |
891 |
ScalarNumberExprRef expr; |
NumberExprRef expr; |
892 |
public: |
public: |
893 |
Final(ScalarNumberExprRef expr) : expr(expr) {} |
Final(NumberExprRef expr) : Unit(expr->unitType()), expr(expr) {} |
894 |
ExprType_t exprType() const OVERRIDE { return expr->exprType(); } |
ExprType_t exprType() const OVERRIDE { return expr->exprType(); } |
895 |
vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); } |
vmint evalInt() OVERRIDE { return expr->asInt()->evalInt(); } |
896 |
vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); } |
vmfloat evalReal() OVERRIDE { return expr->asReal()->evalReal(); } |
898 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
899 |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
bool isConstExpr() const OVERRIDE { return expr->isConstExpr(); } |
900 |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
bool isPolyphonic() const OVERRIDE { return expr->isPolyphonic(); } |
901 |
MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return expr->unitPrefix(i); } |
vmfloat unitFactor() const OVERRIDE { return expr->unitFactor(); } |
|
StdUnit_t unitType() const OVERRIDE { return expr->unitType(); } |
|
902 |
bool isFinal() const OVERRIDE { return true; } |
bool isFinal() const OVERRIDE { return true; } |
903 |
}; |
}; |
904 |
typedef Ref<Final,Node> FinalRef; |
typedef Ref<Final,Node> FinalRef; |
926 |
vmint globalIntVarCount; |
vmint globalIntVarCount; |
927 |
vmint globalRealVarCount; |
vmint globalRealVarCount; |
928 |
vmint globalStrVarCount; |
vmint globalStrVarCount; |
929 |
|
vmint globalUnitFactorCount; |
930 |
vmint polyphonicIntVarCount; |
vmint polyphonicIntVarCount; |
931 |
vmint polyphonicRealVarCount; |
vmint polyphonicRealVarCount; |
932 |
|
vmint polyphonicUnitFactorCount; |
933 |
|
|
934 |
EventHandlersRef handlers; |
EventHandlersRef handlers; |
935 |
|
|
941 |
ArrayList<vmint>* globalIntMemory; |
ArrayList<vmint>* globalIntMemory; |
942 |
ArrayList<vmfloat>* globalRealMemory; |
ArrayList<vmfloat>* globalRealMemory; |
943 |
ArrayList<String>* globalStrMemory; |
ArrayList<String>* globalStrMemory; |
944 |
|
ArrayList<vmfloat>* globalUnitFactorMemory; |
945 |
vmint requiredMaxStackSize; |
vmint requiredMaxStackSize; |
946 |
|
|
947 |
VMFunctionProvider* functionProvider; |
VMFunctionProvider* functionProvider; |
951 |
ParserContext(VMFunctionProvider* parent) : |
ParserContext(VMFunctionProvider* parent) : |
952 |
scanner(NULL), is(NULL), |
scanner(NULL), is(NULL), |
953 |
globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0), |
globalIntVarCount(0), globalRealVarCount(0), globalStrVarCount(0), |
954 |
|
globalUnitFactorCount(0), |
955 |
polyphonicIntVarCount(0), polyphonicRealVarCount(0), |
polyphonicIntVarCount(0), polyphonicRealVarCount(0), |
956 |
|
polyphonicUnitFactorCount(0), |
957 |
globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL), |
globalIntMemory(NULL), globalRealMemory(NULL), globalStrMemory(NULL), |
958 |
|
globalUnitFactorMemory(NULL), |
959 |
requiredMaxStackSize(-1), |
requiredMaxStackSize(-1), |
960 |
functionProvider(parent), execContext(NULL) |
functionProvider(parent), execContext(NULL) |
961 |
{ |
{ |
982 |
VMEventHandler* eventHandler(uint index) OVERRIDE; |
VMEventHandler* eventHandler(uint index) OVERRIDE; |
983 |
VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; |
VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; |
984 |
void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars); |
void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars); |
985 |
|
void registerBuiltInConstRealVariables(const std::map<String,vmfloat>& vars); |
986 |
void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars); |
void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars); |
987 |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
988 |
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |
1002 |
|
|
1003 |
ArrayList<vmint> polyphonicIntMemory; |
ArrayList<vmint> polyphonicIntMemory; |
1004 |
ArrayList<vmfloat> polyphonicRealMemory; |
ArrayList<vmfloat> polyphonicRealMemory; |
1005 |
|
ArrayList<vmfloat> polyphonicUnitFactorMemory; |
1006 |
VMExecStatus_t status; |
VMExecStatus_t status; |
1007 |
StmtFlags_t flags; |
StmtFlags_t flags; |
1008 |
ArrayList<StackFrame> stack; |
ArrayList<StackFrame> stack; |
1012 |
struct ExitRes { |
struct ExitRes { |
1013 |
Expression* value; |
Expression* value; |
1014 |
IntLiteral intLiteral; |
IntLiteral intLiteral; |
1015 |
|
RealLiteral realLiteral; |
1016 |
StringLiteral stringLiteral; |
StringLiteral stringLiteral; |
1017 |
|
|
1018 |
ExitRes() : intLiteral(0), stringLiteral("") { } |
ExitRes() : |
1019 |
|
intLiteral({ .value = 0 }), realLiteral({ .value = 0.0 }), |
1020 |
|
stringLiteral("") { } |
1021 |
} exitRes; |
} exitRes; |
1022 |
|
|
1023 |
ExecContext(); |
ExecContext(); |
1058 |
memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint)); |
memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(vmint)); |
1059 |
if (!polyphonicRealMemory.empty()) |
if (!polyphonicRealMemory.empty()) |
1060 |
memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat)); |
memset(&polyphonicRealMemory[0], 0, polyphonicRealMemory.size() * sizeof(vmfloat)); |
1061 |
|
if (!polyphonicUnitFactorMemory.empty()) { |
1062 |
|
const vmint sz = polyphonicUnitFactorMemory.size(); |
1063 |
|
for (vmint i = 0; i < sz; ++i) |
1064 |
|
polyphonicUnitFactorMemory[i] = VM_NO_FACTOR; |
1065 |
|
} |
1066 |
} |
} |
1067 |
|
|
1068 |
size_t instructionsPerformed() const OVERRIDE { |
size_t instructionsPerformed() const OVERRIDE { |