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 |
* |
* |
63 |
}; |
}; |
64 |
typedef Ref<IntExpr,Node> IntExprRef; |
typedef Ref<IntExpr,Node> IntExprRef; |
65 |
|
|
66 |
|
/*class IntArrayExpr : virtual public VMIntArrayExpr, virtual public Expression { |
67 |
|
public: |
68 |
|
ExprType_t exprType() const { return INT_ARR_EXPR; } |
69 |
|
String evalCastToStr(); |
70 |
|
}; |
71 |
|
typedef Ref<IntArrayExpr,Node> IntArrayExprRef;*/ |
72 |
|
|
73 |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
class StringExpr : virtual public VMStringExpr, virtual public Expression { |
74 |
public: |
public: |
75 |
ExprType_t exprType() const { return STRING_EXPR; } |
ExprType_t exprType() const { return STRING_EXPR; } |
105 |
std::vector<ExpressionRef> args; |
std::vector<ExpressionRef> args; |
106 |
void add(ExpressionRef arg) { args.push_back(arg); } |
void add(ExpressionRef arg) { args.push_back(arg); } |
107 |
void dump(int level = 0); |
void dump(int level = 0); |
108 |
int argsCount() const { return args.size(); } |
int argsCount() const { return (int) args.size(); } |
109 |
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; } |
110 |
bool isPolyphonic() const; |
bool isPolyphonic() const; |
111 |
}; |
}; |
112 |
typedef Ref<Args,Node> ArgsRef; |
typedef Ref<Args,Node> ArgsRef; |
113 |
|
|
114 |
class Variable : virtual public Expression { |
class Variable : virtual public VMVariable, virtual public Expression { |
115 |
public: |
public: |
116 |
virtual bool isConstExpr() const { return bConst; } |
bool isConstExpr() const OVERRIDE { return bConst; } |
117 |
|
bool isAssignable() const OVERRIDE { return !bConst; } |
118 |
virtual void assign(Expression* expr) = 0; |
virtual void assign(Expression* expr) = 0; |
119 |
|
void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); } |
120 |
protected: |
protected: |
121 |
Variable(ParserContext* ctx, int _memPos, bool _bConst) |
Variable(ParserContext* ctx, int _memPos, bool _bConst) |
122 |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
: context(ctx), memPos(_memPos), bConst(_bConst) {} |
157 |
VMIntRelPtr* ptr; |
VMIntRelPtr* ptr; |
158 |
public: |
public: |
159 |
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
BuiltInIntVariable(const String& name, VMIntRelPtr* ptr); |
160 |
void assign(Expression* expr); |
bool isAssignable() const OVERRIDE { return !ptr->readonly; } |
161 |
int evalInt(); |
void assign(Expression* expr) OVERRIDE; |
162 |
void dump(int level = 0); |
int evalInt() OVERRIDE; |
163 |
|
void dump(int level = 0) OVERRIDE; |
164 |
}; |
}; |
165 |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef; |
166 |
|
|
330 |
virtual Statements* branch(uint i) const = 0; |
virtual Statements* branch(uint i) const = 0; |
331 |
}; |
}; |
332 |
|
|
333 |
|
class DynamicVariableCall : public Variable, virtual public IntExpr, virtual public StringExpr { |
334 |
|
VMDynVar* dynVar; |
335 |
|
String varName; |
336 |
|
public: |
337 |
|
DynamicVariableCall(const String& name, ParserContext* ctx, VMDynVar* v); |
338 |
|
ExprType_t exprType() const OVERRIDE { return dynVar->exprType(); } |
339 |
|
bool isConstExpr() const OVERRIDE { return dynVar->isConstExpr(); } |
340 |
|
bool isAssignable() const OVERRIDE { return dynVar->isAssignable(); } |
341 |
|
bool isPolyphonic() const OVERRIDE { return false; } |
342 |
|
void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); } |
343 |
|
VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); } |
344 |
|
int evalInt() OVERRIDE; |
345 |
|
String evalStr() OVERRIDE; |
346 |
|
String evalCastToStr() OVERRIDE; |
347 |
|
void dump(int level = 0) OVERRIDE; |
348 |
|
}; |
349 |
|
typedef Ref<DynamicVariableCall,Node> DynamicVariableCallRef; |
350 |
|
|
351 |
class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr { |
class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr { |
352 |
String functionName; |
String functionName; |
353 |
ArgsRef args; |
ArgsRef args; |
355 |
public: |
public: |
356 |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : |
FunctionCall(const char* function, ArgsRef args, VMFunction* fn) : |
357 |
functionName(function), args(args), fn(fn) { } |
functionName(function), args(args), fn(fn) { } |
358 |
void dump(int level = 0); |
void dump(int level = 0) OVERRIDE; |
359 |
StmtFlags_t exec(); |
StmtFlags_t exec() OVERRIDE; |
360 |
int evalInt(); |
int evalInt() OVERRIDE; |
361 |
String evalStr(); |
VMIntArrayExpr* asIntArray() const OVERRIDE; |
362 |
bool isConstExpr() const { return false; } |
String evalStr() OVERRIDE; |
363 |
ExprType_t exprType() const; |
bool isConstExpr() const OVERRIDE { return false; } |
364 |
String evalCastToStr(); |
ExprType_t exprType() const OVERRIDE; |
365 |
bool isPolyphonic() const { return args->isPolyphonic(); } |
String evalCastToStr() OVERRIDE; |
366 |
|
bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); } |
367 |
protected: |
protected: |
368 |
VMFnResult* execVMFn(); |
VMFnResult* execVMFn(); |
369 |
}; |
}; |
384 |
class OnNote : public EventHandler { |
class OnNote : public EventHandler { |
385 |
public: |
public: |
386 |
OnNote(StatementsRef statements) : EventHandler(statements) {} |
OnNote(StatementsRef statements) : EventHandler(statements) {} |
387 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; } |
388 |
String eventHandlerName() const { return "note"; } |
String eventHandlerName() const { return "note"; } |
389 |
}; |
}; |
390 |
typedef Ref<OnNote,Node> OnNoteRef; |
typedef Ref<OnNote,Node> OnNoteRef; |
392 |
class OnInit : public EventHandler { |
class OnInit : public EventHandler { |
393 |
public: |
public: |
394 |
OnInit(StatementsRef statements) : EventHandler(statements) {} |
OnInit(StatementsRef statements) : EventHandler(statements) {} |
395 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; } |
396 |
String eventHandlerName() const { return "init"; } |
String eventHandlerName() const { return "init"; } |
397 |
}; |
}; |
398 |
typedef Ref<OnInit,Node> OnInitRef; |
typedef Ref<OnInit,Node> OnInitRef; |
400 |
class OnRelease : public EventHandler { |
class OnRelease : public EventHandler { |
401 |
public: |
public: |
402 |
OnRelease(StatementsRef statements) : EventHandler(statements) {} |
OnRelease(StatementsRef statements) : EventHandler(statements) {} |
403 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; } |
404 |
String eventHandlerName() const { return "release"; } |
String eventHandlerName() const { return "release"; } |
405 |
}; |
}; |
406 |
typedef Ref<OnRelease,Node> OnReleaseRef; |
typedef Ref<OnRelease,Node> OnReleaseRef; |
408 |
class OnController : public EventHandler { |
class OnController : public EventHandler { |
409 |
public: |
public: |
410 |
OnController(StatementsRef statements) : EventHandler(statements) {} |
OnController(StatementsRef statements) : EventHandler(statements) {} |
411 |
|
VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; } |
412 |
String eventHandlerName() const { return "controller"; } |
String eventHandlerName() const { return "controller"; } |
413 |
}; |
}; |
414 |
typedef Ref<OnController,Node> OnControllerRef; |
typedef Ref<OnController,Node> OnControllerRef; |
423 |
int evalInt() { return 0; } |
int evalInt() { return 0; } |
424 |
EventHandler* eventHandlerByName(const String& name) const; |
EventHandler* eventHandlerByName(const String& name) const; |
425 |
EventHandler* eventHandler(uint index) const; |
EventHandler* eventHandler(uint index) const; |
426 |
inline uint size() const { return args.size(); } |
inline uint size() const { return (int) args.size(); } |
427 |
bool isPolyphonic() const; |
bool isPolyphonic() const; |
428 |
}; |
}; |
429 |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
typedef Ref<EventHandlers,Node> EventHandlersRef; |
436 |
Assignment(VariableRef variable, ExpressionRef value); |
Assignment(VariableRef variable, ExpressionRef value); |
437 |
void dump(int level = 0); |
void dump(int level = 0); |
438 |
StmtFlags_t exec(); |
StmtFlags_t exec(); |
439 |
bool isPolyphonic() const { return variable->isPolyphonic() || value->isPolyphonic(); } |
bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); } |
440 |
}; |
}; |
441 |
typedef Ref<Assignment,Node> AssignmentRef; |
typedef Ref<Assignment,Node> AssignmentRef; |
442 |
|
|
547 |
}; |
}; |
548 |
typedef Ref<Or,Node> OrRef; |
typedef Ref<Or,Node> OrRef; |
549 |
|
|
550 |
|
class BitwiseOr : virtual public BinaryOp, virtual public IntExpr { |
551 |
|
public: |
552 |
|
BitwiseOr(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
553 |
|
int evalInt(); |
554 |
|
void dump(int level = 0); |
555 |
|
}; |
556 |
|
typedef Ref<BitwiseOr,Node> BitwiseOrRef; |
557 |
|
|
558 |
class And : virtual public BinaryOp, virtual public IntExpr { |
class And : virtual public BinaryOp, virtual public IntExpr { |
559 |
public: |
public: |
560 |
And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
563 |
}; |
}; |
564 |
typedef Ref<And,Node> AndRef; |
typedef Ref<And,Node> AndRef; |
565 |
|
|
566 |
|
class BitwiseAnd : virtual public BinaryOp, virtual public IntExpr { |
567 |
|
public: |
568 |
|
BitwiseAnd(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {} |
569 |
|
int evalInt(); |
570 |
|
void dump(int level = 0); |
571 |
|
}; |
572 |
|
typedef Ref<BitwiseAnd,Node> BitwiseAndRef; |
573 |
|
|
574 |
class Not : virtual public IntExpr { |
class Not : virtual public IntExpr { |
575 |
IntExprRef expr; |
IntExprRef expr; |
576 |
public: |
public: |
582 |
}; |
}; |
583 |
typedef Ref<Not,Node> NotRef; |
typedef Ref<Not,Node> NotRef; |
584 |
|
|
585 |
|
class BitwiseNot : virtual public IntExpr { |
586 |
|
IntExprRef expr; |
587 |
|
public: |
588 |
|
BitwiseNot(IntExprRef expr) : expr(expr) {} |
589 |
|
int evalInt() { return ~expr->evalInt(); } |
590 |
|
void dump(int level = 0); |
591 |
|
bool isConstExpr() const { return expr->isConstExpr(); } |
592 |
|
bool isPolyphonic() const { return expr->isPolyphonic(); } |
593 |
|
}; |
594 |
|
typedef Ref<BitwiseNot,Node> BitwiseNotRef; |
595 |
|
|
596 |
class ParserContext : public VMParserContext { |
class ParserContext : public VMParserContext { |
597 |
public: |
public: |
598 |
struct Error { |
struct Error { |
611 |
std::set<String> userPreprocessorConditions; |
std::set<String> userPreprocessorConditions; |
612 |
|
|
613 |
std::map<String,VariableRef> vartable; |
std::map<String,VariableRef> vartable; |
614 |
|
std::map<String,StatementsRef> userFnTable; |
615 |
int globalIntVarCount; |
int globalIntVarCount; |
616 |
int globalStrVarCount; |
int globalStrVarCount; |
617 |
int polyphonicIntVarCount; |
int polyphonicIntVarCount; |
643 |
IntVariableRef globalIntVar(const String& name); |
IntVariableRef globalIntVar(const String& name); |
644 |
StringVariableRef globalStrVar(const String& name); |
StringVariableRef globalStrVar(const String& name); |
645 |
VariableRef variableByName(const String& name); |
VariableRef variableByName(const String& name); |
646 |
void addErr(int line, const char* txt); |
StatementsRef userFunctionByName(const String& name); |
647 |
void addWrn(int line, const char* txt); |
void addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt); |
648 |
|
void addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt); |
649 |
void createScanner(std::istream* is); |
void createScanner(std::istream* is); |
650 |
void destroyScanner(); |
void destroyScanner(); |
651 |
bool setPreprocessorCondition(const char* name); |
bool setPreprocessorCondition(const char* name); |
659 |
void registerBuiltInConstIntVariables(const std::map<String,int>& vars); |
void registerBuiltInConstIntVariables(const std::map<String,int>& vars); |
660 |
void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars); |
void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars); |
661 |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars); |
662 |
|
void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars); |
663 |
}; |
}; |
664 |
|
|
665 |
class ExecContext : public VMExecContext { |
class ExecContext : public VMExecContext { |