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 |
|
enum Qualifier_t { |
45 |
|
QUALIFIER_NONE = 0, |
46 |
|
QUALIFIER_CONST = 1, |
47 |
|
QUALIFIER_POLYPHONIC = (1<<1), |
48 |
|
}; |
49 |
|
|
50 |
/** |
/** |
51 |
* Convenience function used for retrieving the (assumed) data type of a given |
* Convenience function used for retrieving the (assumed) data type of a given |
52 |
* script variable name. |
* script variable name. |
68 |
return (ExprType_t) -1; |
return (ExprType_t) -1; |
69 |
} |
} |
70 |
|
|
71 |
|
inline ExprType_t scalarTypeOfArray(ExprType_t arrayType) { |
72 |
|
if (arrayType == INT_ARR_EXPR) return INT_EXPR; |
73 |
|
if (arrayType == REAL_ARR_EXPR) return REAL_EXPR; |
74 |
|
if (arrayType == STRING_ARR_EXPR) return STRING_EXPR; |
75 |
|
assert(false); |
76 |
|
return EMPTY_EXPR; // just to shut up the compiler |
77 |
|
} |
78 |
|
|
79 |
|
inline String qualifierStr(Qualifier_t qualifier) { |
80 |
|
switch (qualifier) { |
81 |
|
case QUALIFIER_NONE: return "none"; |
82 |
|
case QUALIFIER_CONST: return "const"; |
83 |
|
case QUALIFIER_POLYPHONIC: return "polyphonic"; |
84 |
|
} |
85 |
|
return "unknown"; |
86 |
|
} |
87 |
|
|
88 |
|
/** |
89 |
|
* Used by parser for parser error messages to provide a text with all data |
90 |
|
* types accepted by the given built-in function @a fn for the respective |
91 |
|
* function argument @a iArg. |
92 |
|
*/ |
93 |
|
String acceptedArgTypesStr(VMFunction* fn, vmint iArg); |
94 |
|
|
95 |
class Node { |
class Node { |
96 |
public: |
public: |
97 |
Node(); |
Node(); |
239 |
ParserContext* ctx; |
ParserContext* ctx; |
240 |
bool isPolyphonic; |
bool isPolyphonic; |
241 |
bool isConst; |
bool isConst; |
|
bool isFinal; |
|
242 |
vmint elements = 1; |
vmint elements = 1; |
243 |
vmint memPos; |
vmint memPos; |
244 |
vmint unitFactorMemPos; |
vmint unitFactorMemPos; |
245 |
StdUnit_t unitType = VM_NO_UNIT; |
StdUnit_t unitType = VM_NO_UNIT; |
246 |
|
bool isFinal; |
247 |
}; |
}; |
248 |
|
|
249 |
class Variable : virtual public VMVariable, virtual public Expression { |
class Variable : virtual public VMVariable, virtual public Expression { |
294 |
typedef Ref<RealVariable,Node> RealVariableRef; |
typedef Ref<RealVariable,Node> RealVariableRef; |
295 |
|
|
296 |
struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17 |
struct IntVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17 |
297 |
|
// additions for RealVarDef |
298 |
|
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. |
299 |
|
vmfloat unitFactor = VM_NO_FACTOR; |
300 |
// copied from VariableDecl |
// copied from VariableDecl |
301 |
ParserContext* ctx; |
ParserContext* ctx; |
302 |
bool isPolyphonic; |
bool isPolyphonic; |
303 |
bool isConst; |
bool isConst; |
|
bool isFinal; |
|
304 |
vmint elements = 1; |
vmint elements = 1; |
305 |
vmint memPos; |
vmint memPos; |
306 |
vmint unitFactorMemPos; |
vmint unitFactorMemPos; |
307 |
StdUnit_t unitType = VM_NO_UNIT; |
StdUnit_t unitType = VM_NO_UNIT; |
308 |
// additions for RealVarDef |
bool isFinal; |
|
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. |
|
|
vmfloat unitFactor = VM_NO_FACTOR; |
|
309 |
}; |
}; |
310 |
|
|
311 |
class ConstIntVariable FINAL : public IntVariable { |
class ConstIntVariable FINAL : public IntVariable { |
321 |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
322 |
|
|
323 |
struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17 |
struct RealVarDef /* : VariableDecl*/ { //NOTE: derived, aggregate initializer-lists requires C++17 |
324 |
|
// additions for RealVarDef |
325 |
|
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. |
326 |
|
vmfloat unitFactor = VM_NO_FACTOR; |
327 |
// copied from VariableDecl |
// copied from VariableDecl |
328 |
ParserContext* ctx; |
ParserContext* ctx; |
329 |
bool isPolyphonic; |
bool isPolyphonic; |
330 |
bool isConst; |
bool isConst; |
|
bool isFinal; |
|
331 |
vmint elements = 1; |
vmint elements = 1; |
332 |
vmint memPos; |
vmint memPos; |
333 |
vmint unitFactorMemPos; |
vmint unitFactorMemPos; |
334 |
StdUnit_t unitType = VM_NO_UNIT; |
StdUnit_t unitType = VM_NO_UNIT; |
335 |
// additions for RealVarDef |
bool isFinal; |
|
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. |
|
|
vmfloat unitFactor = VM_NO_FACTOR; |
|
336 |
}; |
}; |
337 |
|
|
338 |
class ConstRealVariable FINAL : public RealVariable { |
class ConstRealVariable FINAL : public RealVariable { |
355 |
bool isAssignable() const OVERRIDE { return ptr->isAssignable(); } |
bool isAssignable() const OVERRIDE { return ptr->isAssignable(); } |
356 |
void assign(Expression* expr) OVERRIDE; |
void assign(Expression* expr) OVERRIDE; |
357 |
vmint evalInt() OVERRIDE; |
vmint evalInt() OVERRIDE; |
358 |
vmfloat unitFactor() const OVERRIDE { return VM_NO_UNIT; } |
vmfloat unitFactor() const OVERRIDE { return VM_NO_FACTOR; } |
359 |
void dump(int level = 0) OVERRIDE; |
void dump(int level = 0) OVERRIDE; |
360 |
}; |
}; |
361 |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
703 |
}; |
}; |
704 |
typedef Ref<OnController,Node> OnControllerRef; |
typedef Ref<OnController,Node> OnControllerRef; |
705 |
|
|
706 |
|
class OnRpn FINAL : public EventHandler { |
707 |
|
public: |
708 |
|
OnRpn(StatementsRef statements) : EventHandler(statements) {} |
709 |
|
VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_RPN; } |
710 |
|
String eventHandlerName() const OVERRIDE { return "rpn"; } |
711 |
|
}; |
712 |
|
typedef Ref<OnRpn,Node> OnRpnRef; |
713 |
|
|
714 |
|
class OnNrpn FINAL : public EventHandler { |
715 |
|
public: |
716 |
|
OnNrpn(StatementsRef statements) : EventHandler(statements) {} |
717 |
|
VMEventHandlerType_t eventHandlerType() const OVERRIDE { return VM_EVENT_HANDLER_NRPN; } |
718 |
|
String eventHandlerName() const OVERRIDE { return "nrpn"; } |
719 |
|
}; |
720 |
|
typedef Ref<OnNrpn,Node> OnNrpnRef; |
721 |
|
|
722 |
class EventHandlers FINAL : virtual public Node { |
class EventHandlers FINAL : virtual public Node { |
723 |
std::vector<EventHandlerRef> args; |
std::vector<EventHandlerRef> args; |
724 |
public: |
public: |
968 |
OnNoteRef onNote; |
OnNoteRef onNote; |
969 |
OnReleaseRef onRelease; |
OnReleaseRef onRelease; |
970 |
OnControllerRef onController; |
OnControllerRef onController; |
971 |
|
OnRpnRef onRpn; |
972 |
|
OnNrpnRef onNrpn; |
973 |
|
|
974 |
ArrayList<vmint>* globalIntMemory; |
ArrayList<vmint>* globalIntMemory; |
975 |
ArrayList<vmfloat>* globalRealMemory; |
ArrayList<vmfloat>* globalRealMemory; |
1015 |
VMEventHandler* eventHandler(uint index) OVERRIDE; |
VMEventHandler* eventHandler(uint index) OVERRIDE; |
1016 |
VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; |
VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; |
1017 |
void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars); |
void registerBuiltInConstIntVariables(const std::map<String,vmint>& vars); |
1018 |
|
void registerBuiltInConstRealVariables(const std::map<String,vmfloat>& vars); |
1019 |
void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars); |
void registerBuiltInIntVariables(const std::map<String,VMIntPtr*>& vars); |
1020 |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
1021 |
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |