1 |
/* -*- c++ -*- |
/* -*- c++ -*- |
2 |
* |
* |
3 |
* Copyright (c) 2014 Christian Schoenebeck and Andreas Persson |
* Copyright (c) 2014 - 2017 Christian Schoenebeck and Andreas Persson |
4 |
* |
* |
5 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
6 |
* |
* |
20 |
#include <iostream> |
#include <iostream> |
21 |
#include <map> |
#include <map> |
22 |
#include <set> |
#include <set> |
23 |
|
#include <string.h> // for memset() |
24 |
#include "../common/global.h" |
#include "../common/global.h" |
25 |
#include "../common/Ref.h" |
#include "../common/Ref.h" |
26 |
#include "../common/ArrayList.h" |
#include "../common/ArrayList.h" |
36 |
STMT_LIST, |
STMT_LIST, |
37 |
STMT_BRANCH, |
STMT_BRANCH, |
38 |
STMT_LOOP, |
STMT_LOOP, |
39 |
|
STMT_SYNC, |
40 |
}; |
}; |
41 |
|
|
42 |
class Node { |
class Node { |
44 |
Node(); |
Node(); |
45 |
virtual ~Node(); |
virtual ~Node(); |
46 |
virtual void dump(int level = 0) = 0; |
virtual void dump(int level = 0) = 0; |
47 |
|
virtual bool isPolyphonic() const = 0; |
48 |
void printIndents(int n); |
void printIndents(int n); |
49 |
}; |
}; |
50 |
typedef Ref<Node> NodeRef; |
typedef Ref<Node> NodeRef; |
65 |
}; |
}; |
66 |
typedef Ref<IntExpr,Node> IntExprRef; |
typedef Ref<IntExpr,Node> IntExprRef; |
67 |
|
|
68 |
|
/*class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { |
69 |
|
public: |
70 |
|
ExprType_t exprType() const { return INT_ARR_EXPR; } |
71 |
|
String evalCastToStr(); |
72 |
|
}; |
73 |
|
typedef Ref<IntArrayExpr,Node> IntArrayExprRef;*/ |
74 |
|
|
75 |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
76 |
public: |
public: |
77 |
ExprType_t exprType() const { return STRING_EXPR; } |
ExprType_t exprType() const { return STRING_EXPR; } |
87 |
int evalInt(); |
int evalInt(); |
88 |
void dump(int level = 0); |
void dump(int level = 0); |
89 |
bool isConstExpr() const { return true; } |
bool isConstExpr() const { return true; } |
90 |
|
bool isPolyphonic() const { return false; } |
91 |
}; |
}; |
92 |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
typedef Ref<IntLiteral,Node> IntLiteralRef; |
93 |
|
|
98 |
bool isConstExpr() const { return true; } |
bool isConstExpr() const { return true; } |
99 |
void dump(int level = 0); |
void dump(int level = 0); |
100 |
String evalStr() { return value; } |
String evalStr() { return value; } |
101 |
|
bool isPolyphonic() const { return false; } |
102 |
}; |
}; |
103 |
typedef Ref<StringLiteral,Node> StringLiteralRef; |
typedef Ref<StringLiteral,Node> StringLiteralRef; |
104 |
|
|
107 |
std::vector<ExpressionRef> args; |
std::vector<ExpressionRef> args; |
108 |
void add(ExpressionRef arg) { args.push_back(arg); } |
void add(ExpressionRef arg) { args.push_back(arg); } |
109 |
void dump(int level = 0); |
void dump(int level = 0); |
110 |
int argsCount() const { return args.size(); } |
int argsCount() const { return (int) args.size(); } |
111 |
VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; } |
VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; } |
112 |
|
bool isPolyphonic() const; |
113 |
}; |
}; |
114 |
typedef Ref<Args,Node> ArgsRef; |
typedef Ref<Args,Node> ArgsRef; |
115 |
|
|
116 |
class Variable : virtual public Expression { |
class Variable : virtual public VMVariable, virtual public Expression { |
117 |
public: |
public: |
118 |
virtual bool isConstExpr() const { return bConst; } |
bool isConstExpr() const OVERRIDE { return bConst; } |
119 |
|
bool isAssignable() const OVERRIDE { return !bConst; } |
120 |
virtual void assign(Expression* expr) = 0; |
virtual void assign(Expression* expr) = 0; |
121 |
|
void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); } |
122 |
protected: |
protected: |
123 |
Variable(ParserContext* ctx, int _memPos, bool _bConst) |
Variable(ParserContext* ctx, int _memPos, bool _bConst) |
124 |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
154 |
}; |
}; |
155 |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
typedef Ref<ConstIntVariable,Node> ConstIntVariableRef; |
156 |
|
|
157 |
|
class BuiltInIntVariable : public IntVariable { |
158 |
|
String name; |
159 |
|
VMIntRelPtr* ptr; |
160 |
|
public: |
161 |
|
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
162 |
|
bool isAssignable() const OVERRIDE { return !ptr->readonly; } |
163 |
|
void assign(Expression* expr) OVERRIDE; |
164 |
|
int evalInt() OVERRIDE; |
165 |
|
void dump(int level = 0) OVERRIDE; |
166 |
|
}; |
167 |
|
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
168 |
|
|
169 |
class PolyphonicIntVariable : public IntVariable { |
class PolyphonicIntVariable : public IntVariable { |
170 |
public: |
public: |
171 |
PolyphonicIntVariable(ParserContext* ctx); |
PolyphonicIntVariable(ParserContext* ctx); |
173 |
}; |
}; |
174 |
typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef; |
typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef; |
175 |
|
|
176 |
class IntArrayVariable : public Variable { |
class IntArrayVariable : public Variable, virtual public VMIntArrayExpr { |
177 |
ArrayList<int> values; |
ArrayList<int> values; |
178 |
public: |
public: |
179 |
IntArrayVariable(ParserContext* ctx, int size); |
IntArrayVariable(ParserContext* ctx, int size); |
180 |
IntArrayVariable(ParserContext* ctx, int size, ArgsRef values); |
IntArrayVariable(ParserContext* ctx, int size, ArgsRef values, bool _bConst = false); |
181 |
void assign(Expression* expr) {} // ignore scalar assignment |
void assign(Expression* expr) {} // ignore scalar assignment |
182 |
String evalCastToStr() { return ""; } // ignore cast to string |
String evalCastToStr() { return ""; } // ignore scalar cast to string |
183 |
ExprType_t exprType() const { return INT_ARR_EXPR; } |
ExprType_t exprType() const { return INT_ARR_EXPR; } |
184 |
const int arraySize() const { return values.size(); } |
virtual int arraySize() const { return values.size(); } |
185 |
|
virtual int evalIntElement(uint i); |
186 |
|
virtual void assignIntElement(uint i, int value); |
187 |
|
void dump(int level = 0); |
188 |
|
bool isPolyphonic() const { return false; } |
189 |
|
protected: |
190 |
|
IntArrayVariable(ParserContext* ctx, bool bConst); |
191 |
|
}; |
192 |
|
typedef Ref<IntArrayVariable,Node> IntArrayVariableRef; |
193 |
|
|
194 |
|
class BuiltInIntArrayVariable : public IntArrayVariable { |
195 |
|
String name; |
196 |
|
VMInt8Array* array; |
197 |
|
public: |
198 |
|
BuiltInIntArrayVariable(const String& name, VMInt8Array* array); |
199 |
|
int arraySize() const { return array->size; } |
200 |
int evalIntElement(uint i); |
int evalIntElement(uint i); |
201 |
|
bool isAssignable() const OVERRIDE { return !array->readonly; } |
202 |
void assignIntElement(uint i, int value); |
void assignIntElement(uint i, int value); |
203 |
void dump(int level = 0); |
void dump(int level = 0); |
204 |
}; |
}; |
205 |
typedef Ref<IntArrayVariable,Node> IntArrayVariableRef; |
typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef; |
206 |
|
|
207 |
class IntArrayElement : public IntVariable { |
class IntArrayElement : public IntVariable { |
208 |
IntArrayVariableRef array; |
IntArrayVariableRef array; |
221 |
void assign(Expression* expr); |
void assign(Expression* expr); |
222 |
String evalStr(); |
String evalStr(); |
223 |
void dump(int level = 0); |
void dump(int level = 0); |
224 |
|
bool isPolyphonic() const { return false; } |
225 |
protected: |
protected: |
226 |
StringVariable(ParserContext* ctx, bool bConst); |
StringVariable(ParserContext* ctx, bool bConst); |
227 |
}; |
}; |
245 |
public: |
public: |
246 |
BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { } |
BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { } |
247 |
bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); } |
bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); } |
248 |
|
bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
249 |
}; |
}; |
250 |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
typedef Ref<BinaryOp,Node> BinaryOpRef; |
251 |
|
|
302 |
NoOperation() : Statement() {} |
NoOperation() : Statement() {} |
303 |
StmtType_t statementType() const { return STMT_LEAF; } |
StmtType_t statementType() const { return STMT_LEAF; } |
304 |
void dump(int level = 0) {} |
void dump(int level = 0) {} |
305 |
|
bool isPolyphonic() const { return false; } |
306 |
}; |
}; |
307 |
typedef Ref<NoOperation,Node> NoOperationRef; |
typedef Ref<NoOperation,Node> NoOperationRef; |
308 |
|
|
322 |
void dump(int level = 0); |
void dump(int level = 0); |
323 |
StmtType_t statementType() const { return STMT_LIST; } |
StmtType_t statementType() const { return STMT_LIST; } |
324 |
virtual Statement* statement(uint i); |
virtual Statement* statement(uint i); |
325 |
|
bool isPolyphonic() const; |
326 |
}; |
}; |
327 |
typedef Ref<Statements,Node> StatementsRef; |
typedef Ref<Statements,Node> StatementsRef; |
328 |
|
|
333 |
virtual Statements* branch(uint i) const = 0; |
virtual Statements* branch(uint i) const = 0; |
334 |
}; |
}; |
335 |
|
|
336 |
|
class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr { |
337 |
|
VMDynVar* dynVar; |
338 |
|
String varName; |
339 |
|
public: |
340 |
|
DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v); |
341 |
|
ExprType_t exprType() const OVERRIDE { return dynVar->exprType(); } |
342 |
|
bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); } |
343 |
|
bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); } |
344 |
|
bool isPolyphonic() const OVERRIDE { return false; } |
345 |
|
void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); } |
346 |
|
VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); } |
347 |
|
int evalInt() OVERRIDE; |
348 |
|
String evalStr() OVERRIDE; |
349 |
|
String evalCastToStr() OVERRIDE; |
350 |
|
void dump(int level = 0) OVERRIDE; |
351 |
|
}; |
352 |
|
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
353 |
|
|
354 |
class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr { |
class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr { |
355 |
String functionName; |
String functionName; |
356 |
ArgsRef args; |
ArgsRef args; |
358 |
public: |
public: |
359 |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : |
360 |
functionName(function), args(args), fn(fn) { } |
functionName(function), args(args), fn(fn) { } |
361 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
362 |
StmtFlags_t exec(); |
StmtFlags_t exec() OVERRIDE; |
363 |
int evalInt(); |
int evalInt() OVERRIDE; |
364 |
String evalStr(); |
VMIntArrayExpr* asIntArray() const OVERRIDE; |
365 |
bool isConstExpr() const { return false; } |
String evalStr() OVERRIDE; |
366 |
ExprType_t exprType() const; |
bool isConstExpr() const OVERRIDE { return false; } |
367 |
String evalCastToStr(); |
ExprType_t exprType() const OVERRIDE; |
368 |
|
String evalCastToStr() OVERRIDE; |
369 |
|
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
370 |
protected: |
protected: |
371 |
VMFnResult* execVMFn(); |
VMFnResult* execVMFn(); |
372 |
}; |
}; |
374 |
|
|
375 |
class EventHandler : virtual public Statements, virtual public VMEventHandler { |
class EventHandler : virtual public Statements, virtual public VMEventHandler { |
376 |
StatementsRef statements; |
StatementsRef statements; |
377 |
|
bool usingPolyphonics; |
378 |
public: |
public: |
379 |
void dump(int level = 0); |
void dump(int level = 0); |
380 |
StmtFlags_t exec(); |
StmtFlags_t exec(); |
381 |
EventHandler(StatementsRef statements) { this->statements = statements; } |
EventHandler(StatementsRef statements); |
382 |
Statement* statement(uint i) { return statements->statement(i); } |
Statement* statement(uint i) { return statements->statement(i); } |
383 |
|
bool isPolyphonic() const { return usingPolyphonics; } |
384 |
}; |
}; |
385 |
typedef Ref<EventHandler,Node> EventHandlerRef; |
typedef Ref<EventHandler,Node> EventHandlerRef; |
386 |
|
|
387 |
class OnNote : public EventHandler { |
class OnNote : public EventHandler { |
388 |
public: |
public: |
389 |
OnNote(StatementsRef statements) : EventHandler(statements) {} |
OnNote(StatementsRef statements) : EventHandler(statements) {} |
390 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; } |
391 |
String eventHandlerName() const { return "note"; } |
String eventHandlerName() const { return "note"; } |
392 |
}; |
}; |
393 |
typedef Ref<OnNote,Node> OnNoteRef; |
typedef Ref<OnNote,Node> OnNoteRef; |
395 |
class OnInit : public EventHandler { |
class OnInit : public EventHandler { |
396 |
public: |
public: |
397 |
OnInit(StatementsRef statements) : EventHandler(statements) {} |
OnInit(StatementsRef statements) : EventHandler(statements) {} |
398 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; } |
399 |
String eventHandlerName() const { return "init"; } |
String eventHandlerName() const { return "init"; } |
400 |
}; |
}; |
401 |
typedef Ref<OnInit,Node> OnInitRef; |
typedef Ref<OnInit,Node> OnInitRef; |
403 |
class OnRelease : public EventHandler { |
class OnRelease : public EventHandler { |
404 |
public: |
public: |
405 |
OnRelease(StatementsRef statements) : EventHandler(statements) {} |
OnRelease(StatementsRef statements) : EventHandler(statements) {} |
406 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; } |
407 |
String eventHandlerName() const { return "release"; } |
String eventHandlerName() const { return "release"; } |
408 |
}; |
}; |
409 |
typedef Ref<OnRelease,Node> OnReleaseRef; |
typedef Ref<OnRelease,Node> OnReleaseRef; |
411 |
class OnController : public EventHandler { |
class OnController : public EventHandler { |
412 |
public: |
public: |
413 |
OnController(StatementsRef statements) : EventHandler(statements) {} |
OnController(StatementsRef statements) : EventHandler(statements) {} |
414 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; } |
415 |
String eventHandlerName() const { return "controller"; } |
String eventHandlerName() const { return "controller"; } |
416 |
}; |
}; |
417 |
typedef Ref<OnController,Node> OnControllerRef; |
typedef Ref<OnController,Node> OnControllerRef; |
426 |
int evalInt() { return 0; } |
int evalInt() { return 0; } |
427 |
EventHandler* eventHandlerByName(const String& name) const; |
EventHandler* eventHandlerByName(const String& name) const; |
428 |
EventHandler* eventHandler(uint index) const; |
EventHandler* eventHandler(uint index) const; |
429 |
inline uint size() const { return args.size(); } |
inline uint size() const { return (int) args.size(); } |
430 |
|
bool isPolyphonic() const; |
431 |
}; |
}; |
432 |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
433 |
|
|
439 |
Assignment(VariableRef variable, ExpressionRef value); |
Assignment(VariableRef variable, ExpressionRef value); |
440 |
void dump(int level = 0); |
void dump(int level = 0); |
441 |
StmtFlags_t exec(); |
StmtFlags_t exec(); |
442 |
|
bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); } |
443 |
}; |
}; |
444 |
typedef Ref<Assignment,Node> AssignmentRef; |
typedef Ref<Assignment,Node> AssignmentRef; |
445 |
|
|
455 |
void dump(int level = 0); |
void dump(int level = 0); |
456 |
int evalBranch(); |
int evalBranch(); |
457 |
Statements* branch(uint i) const; |
Statements* branch(uint i) const; |
458 |
|
bool isPolyphonic() const; |
459 |
}; |
}; |
460 |
typedef Ref<If,Node> IfRef; |
typedef Ref<If,Node> IfRef; |
461 |
|
|
479 |
//void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements); |
//void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements); |
480 |
//void addBranch(CaseBranchRef branch); |
//void addBranch(CaseBranchRef branch); |
481 |
//void addBranches(CaseBranchesRef branches); |
//void addBranches(CaseBranchesRef branches); |
482 |
|
bool isPolyphonic() const; |
483 |
}; |
}; |
484 |
typedef Ref<SelectCase,Node> SelectCaseRef; |
typedef Ref<SelectCase,Node> SelectCaseRef; |
485 |
|
|
493 |
void dump(int level = 0); |
void dump(int level = 0); |
494 |
bool evalLoopStartCondition(); |
bool evalLoopStartCondition(); |
495 |
Statements* statements() const; |
Statements* statements() const; |
496 |
|
bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); } |
497 |
}; |
}; |
498 |
|
|
499 |
|
class SyncBlock : public Statement { |
500 |
|
StatementsRef m_statements; |
501 |
|
public: |
502 |
|
SyncBlock(StatementsRef statements) : m_statements(statements) {} |
503 |
|
StmtType_t statementType() const { return STMT_SYNC; } |
504 |
|
void dump(int level = 0); |
505 |
|
Statements* statements() const; |
506 |
|
bool isPolyphonic() const { return m_statements->isPolyphonic(); } |
507 |
|
}; |
508 |
|
typedef Ref<SyncBlock,Node> SyncBlockRef; |
509 |
|
|
510 |
class Neg : public IntExpr { |
class Neg : public IntExpr { |
511 |
IntExprRef expr; |
IntExprRef expr; |
512 |
public: |
public: |
514 |
int evalInt() { return (expr) ? -expr->evalInt() : 0; } |
int evalInt() { return (expr) ? -expr->evalInt() : 0; } |
515 |
void dump(int level = 0); |
void dump(int level = 0); |
516 |
bool isConstExpr() const { return expr->isConstExpr(); } |
bool isConstExpr() const { return expr->isConstExpr(); } |
517 |
|
bool isPolyphonic() const { return expr->isPolyphonic(); } |
518 |
}; |
}; |
519 |
typedef Ref<Neg,Node> NegRef; |
typedef Ref<Neg,Node> NegRef; |
520 |
|
|
526 |
String evalStr(); |
String evalStr(); |
527 |
void dump(int level = 0); |
void dump(int level = 0); |
528 |
bool isConstExpr() const; |
bool isConstExpr() const; |
529 |
|
bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
530 |
}; |
}; |
531 |
typedef Ref<ConcatString,Node> ConcatStringRef; |
typedef Ref<ConcatString,Node> ConcatStringRef; |
532 |
|
|
545 |
int evalInt(); |
int evalInt(); |
546 |
void dump(int level = 0); |
void dump(int level = 0); |
547 |
bool isConstExpr() const; |
bool isConstExpr() const; |
548 |
|
bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); } |
549 |
private: |
private: |
550 |
IntExprRef lhs; |
IntExprRef lhs; |
551 |
IntExprRef rhs; |
IntExprRef rhs; |
561 |
}; |
}; |
562 |
typedef Ref<Or,Node> OrRef; |
typedef Ref<Or,Node> OrRef; |
563 |
|
|
564 |
|
class BitwiseOr : virtual public BinaryOp, virtual public IntExpr { |
565 |
|
public: |
566 |
|
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
567 |
|
int evalInt(); |
568 |
|
void dump(int level = 0); |
569 |
|
}; |
570 |
|
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
571 |
|
|
572 |
class And : virtual public BinaryOp, virtual public IntExpr { |
class And : virtual public BinaryOp, virtual public IntExpr { |
573 |
public: |
public: |
574 |
And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
577 |
}; |
}; |
578 |
typedef Ref<And,Node> AndRef; |
typedef Ref<And,Node> AndRef; |
579 |
|
|
580 |
|
class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr { |
581 |
|
public: |
582 |
|
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
583 |
|
int evalInt(); |
584 |
|
void dump(int level = 0); |
585 |
|
}; |
586 |
|
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
587 |
|
|
588 |
class Not : virtual public IntExpr { |
class Not : virtual public IntExpr { |
589 |
IntExprRef expr; |
IntExprRef expr; |
590 |
public: |
public: |
592 |
int evalInt() { return !expr->evalInt(); } |
int evalInt() { return !expr->evalInt(); } |
593 |
void dump(int level = 0); |
void dump(int level = 0); |
594 |
bool isConstExpr() const { return expr->isConstExpr(); } |
bool isConstExpr() const { return expr->isConstExpr(); } |
595 |
|
bool isPolyphonic() const { return expr->isPolyphonic(); } |
596 |
}; |
}; |
597 |
typedef Ref<Not,Node> NotRef; |
typedef Ref<Not,Node> NotRef; |
598 |
|
|
599 |
|
class BitwiseNot : virtual public IntExpr { |
600 |
|
IntExprRef expr; |
601 |
|
public: |
602 |
|
BitwiseNot(IntExprRef expr) : expr(expr) {} |
603 |
|
int evalInt() { return ~expr->evalInt(); } |
604 |
|
void dump(int level = 0); |
605 |
|
bool isConstExpr() const { return expr->isConstExpr(); } |
606 |
|
bool isPolyphonic() const { return expr->isPolyphonic(); } |
607 |
|
}; |
608 |
|
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
609 |
|
|
610 |
class ParserContext : public VMParserContext { |
class ParserContext : public VMParserContext { |
611 |
public: |
public: |
612 |
struct Error { |
struct Error { |
617 |
|
|
618 |
void* scanner; |
void* scanner; |
619 |
std::istream* is; |
std::istream* is; |
620 |
std::vector<ParserIssue> errors; |
std::vector<ParserIssue> vErrors; |
621 |
std::vector<ParserIssue> warnings; |
std::vector<ParserIssue> vWarnings; |
622 |
std::vector<ParserIssue> issues; |
std::vector<ParserIssue> vIssues; |
623 |
|
|
624 |
std::set<String> builtinPreprocessorConditions; |
std::set<String> builtinPreprocessorConditions; |
625 |
std::set<String> userPreprocessorConditions; |
std::set<String> userPreprocessorConditions; |
626 |
|
|
627 |
std::map<String,VariableRef> vartable; |
std::map<String,VariableRef> vartable; |
628 |
|
std::map<String,StatementsRef> userFnTable; |
629 |
int globalIntVarCount; |
int globalIntVarCount; |
630 |
int globalStrVarCount; |
int globalStrVarCount; |
631 |
int polyphonicIntVarCount; |
int polyphonicIntVarCount; |
639 |
|
|
640 |
ArrayList<int>* globalIntMemory; |
ArrayList<int>* globalIntMemory; |
641 |
ArrayList<String>* globalStrMemory; |
ArrayList<String>* globalStrMemory; |
642 |
|
int requiredMaxStackSize; |
643 |
|
|
644 |
VMFunctionProvider* functionProvider; |
VMFunctionProvider* functionProvider; |
645 |
|
|
648 |
ParserContext(VMFunctionProvider* parent) : |
ParserContext(VMFunctionProvider* parent) : |
649 |
scanner(NULL), is(NULL), |
scanner(NULL), is(NULL), |
650 |
globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0), |
globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0), |
651 |
globalIntMemory(NULL), globalStrMemory(NULL), functionProvider(parent), |
globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1), |
652 |
execContext(NULL) |
functionProvider(parent), execContext(NULL) |
653 |
{ |
{ |
654 |
} |
} |
655 |
virtual ~ParserContext() { destroyScanner(); } |
virtual ~ParserContext(); |
656 |
VariableRef globalVar(const String& name); |
VariableRef globalVar(const String& name); |
657 |
IntVariableRef globalIntVar(const String& name); |
IntVariableRef globalIntVar(const String& name); |
658 |
StringVariableRef globalStrVar(const String& name); |
StringVariableRef globalStrVar(const String& name); |
659 |
VariableRef variableByName(const String& name); |
VariableRef variableByName(const String& name); |
660 |
void addErr(int line, const char* txt); |
StatementsRef userFunctionByName(const String& name); |
661 |
void addWrn(int line, const char* txt); |
void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt); |
662 |
|
void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt); |
663 |
void createScanner(std::istream* is); |
void createScanner(std::istream* is); |
664 |
void destroyScanner(); |
void destroyScanner(); |
665 |
bool setPreprocessorCondition(const char* name); |
bool setPreprocessorCondition(const char* name); |
666 |
bool resetPreprocessorCondition(const char* name); |
bool resetPreprocessorCondition(const char* name); |
667 |
bool isPreprocessorConditionSet(const char* name); |
bool isPreprocessorConditionSet(const char* name); |
668 |
|
std::vector<ParserIssue> issues() const OVERRIDE; |
669 |
|
std::vector<ParserIssue> errors() const OVERRIDE; |
670 |
|
std::vector<ParserIssue> warnings() const OVERRIDE; |
671 |
|
VMEventHandler* eventHandler(uint index) OVERRIDE; |
672 |
|
VMEventHandler* eventHandlerByName(const String& name) OVERRIDE; |
673 |
|
void registerBuiltInConstIntVariables(const std::map<String,int>& vars); |
674 |
|
void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars); |
675 |
|
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
676 |
|
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |
677 |
}; |
}; |
678 |
|
|
679 |
class ExecContext : public VMExecContext { |
class ExecContext : public VMExecContext { |
690 |
|
|
691 |
ArrayList<int> polyphonicIntMemory; |
ArrayList<int> polyphonicIntMemory; |
692 |
VMExecStatus_t status; |
VMExecStatus_t status; |
693 |
|
StmtFlags_t flags; |
694 |
ArrayList<StackFrame> stack; |
ArrayList<StackFrame> stack; |
695 |
int stackFrame; |
int stackFrame; |
696 |
int suspendMicroseconds; |
int suspendMicroseconds; |
697 |
|
size_t instructionsCount; |
698 |
|
|
699 |
ExecContext() : |
ExecContext() : |
700 |
status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {} |
status(VM_EXEC_NOT_RUNNING), flags(STMT_SUCCESS), stackFrame(-1), |
701 |
|
suspendMicroseconds(0), instructionsCount(0) {} |
702 |
|
|
703 |
virtual ~ExecContext() {} |
virtual ~ExecContext() {} |
704 |
|
|
721 |
stack[0].statement = NULL; |
stack[0].statement = NULL; |
722 |
stack[0].subindex = -1; |
stack[0].subindex = -1; |
723 |
stackFrame = -1; |
stackFrame = -1; |
724 |
|
flags = STMT_SUCCESS; |
725 |
} |
} |
726 |
|
|
727 |
int suspensionTimeMicroseconds() const { |
int suspensionTimeMicroseconds() const OVERRIDE { |
728 |
return suspendMicroseconds; |
return suspendMicroseconds; |
729 |
} |
} |
730 |
|
|
731 |
|
void resetPolyphonicData() OVERRIDE { |
732 |
|
if (polyphonicIntMemory.empty()) return; |
733 |
|
memset(&polyphonicIntMemory[0], 0, polyphonicIntMemory.size() * sizeof(int)); |
734 |
|
} |
735 |
|
|
736 |
|
size_t instructionsPerformed() const OVERRIDE { |
737 |
|
return instructionsCount; |
738 |
|
} |
739 |
|
|
740 |
|
void signalAbort() OVERRIDE { |
741 |
|
flags = StmtFlags_t(flags | STMT_ABORT_SIGNALLED); |
742 |
|
} |
743 |
}; |
}; |
744 |
|
|
745 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |