/[svn]/linuxsampler/trunk/src/scriptvm/tree.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/scriptvm/tree.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3118 - (hide annotations) (download) (as text)
Fri Apr 21 13:33:03 2017 UTC (2 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 22827 byte(s)
* NKSP: Fixed crash when using built-in script array variable "%ALL_EVENTS".
* NKSP: Added built-in function "change_amp_lfo_depth()".
* NKSP: Added built-in function "change_amp_lfo_freq()".
* NKSP: Added built-in function "change_pitch_lfo_depth()".
* NKSP: Added built-in function "change_pitch_lfo_freq()".
* Bumped version (2.0.0.svn44).

1 schoenebeck 2581 /* -*- c++ -*-
2     *
3 schoenebeck 3118 * Copyright (c) 2014 - 2017 Christian Schoenebeck and Andreas Persson
4 schoenebeck 2581 *
5     * http://www.linuxsampler.org
6     *
7     * This file is part of LinuxSampler and released under the same terms.
8     * See README file for details.
9     */
10    
11     // This header defines VM core implementation internal data types only used
12     // inside the parser and core VM implementation of this source directory. Not
13     // intended to be used in other source code parts (other source code
14     // directories) of the sampler.
15    
16     #ifndef LS_INSTRPARSERTREE_H
17     #define LS_INSTRPARSERTREE_H
18    
19     #include <vector>
20     #include <iostream>
21     #include <map>
22     #include <set>
23     #include "../common/global.h"
24     #include "../common/Ref.h"
25     #include "../common/ArrayList.h"
26     #include "common.h"
27    
28     namespace LinuxSampler {
29    
30     class ParserContext;
31     class ExecContext;
32    
33     enum StmtType_t {
34     STMT_LEAF,
35     STMT_LIST,
36     STMT_BRANCH,
37     STMT_LOOP,
38     };
39    
40     class Node {
41     public:
42     Node();
43     virtual ~Node();
44     virtual void dump(int level = 0) = 0;
45 schoenebeck 2645 virtual bool isPolyphonic() const = 0;
46 schoenebeck 2581 void printIndents(int n);
47     };
48     typedef Ref<Node> NodeRef;
49    
50     class Expression : virtual public VMExpr, virtual public Node {
51     public:
52     virtual ExprType_t exprType() const = 0;
53     virtual bool isConstExpr() const = 0;
54     virtual String evalCastToStr() = 0;
55     };
56     typedef Ref<Expression,Node> ExpressionRef;
57    
58     class IntExpr : virtual public VMIntExpr, virtual public Expression {
59     public:
60     ExprType_t exprType() const { return INT_EXPR; }
61     virtual int evalInt() = 0;
62     String evalCastToStr();
63     };
64     typedef Ref<IntExpr,Node> IntExprRef;
65    
66 schoenebeck 3056 /*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 schoenebeck 2581 class StringExpr : virtual public VMStringExpr, virtual public Expression {
74     public:
75     ExprType_t exprType() const { return STRING_EXPR; }
76     virtual String evalStr() = 0;
77     String evalCastToStr() { return evalStr(); }
78     };
79     typedef Ref<StringExpr,Node> StringExprRef;
80    
81     class IntLiteral : virtual public IntExpr {
82     int value;
83     public:
84     IntLiteral(int value) : value(value) { }
85     int evalInt();
86     void dump(int level = 0);
87     bool isConstExpr() const { return true; }
88 schoenebeck 2645 bool isPolyphonic() const { return false; }
89 schoenebeck 2581 };
90     typedef Ref<IntLiteral,Node> IntLiteralRef;
91    
92     class StringLiteral : virtual public StringExpr {
93     public:
94     String value;
95     StringLiteral(const String& value) : value(value) { }
96     bool isConstExpr() const { return true; }
97     void dump(int level = 0);
98     String evalStr() { return value; }
99 schoenebeck 2645 bool isPolyphonic() const { return false; }
100 schoenebeck 2581 };
101     typedef Ref<StringLiteral,Node> StringLiteralRef;
102    
103     class Args : virtual public VMFnArgs, virtual public Node {
104     public:
105     std::vector<ExpressionRef> args;
106     void add(ExpressionRef arg) { args.push_back(arg); }
107     void dump(int level = 0);
108 schoenebeck 3054 int argsCount() const { return (int) args.size(); }
109 schoenebeck 2581 VMExpr* arg(int i) { return (i >= 0 && i < argsCount()) ? &*args.at(i) : NULL; }
110 schoenebeck 2645 bool isPolyphonic() const;
111 schoenebeck 2581 };
112     typedef Ref<Args,Node> ArgsRef;
113    
114 schoenebeck 2945 class Variable : virtual public VMVariable, virtual public Expression {
115 schoenebeck 2581 public:
116 schoenebeck 2945 bool isConstExpr() const OVERRIDE { return bConst; }
117     bool isAssignable() const OVERRIDE { return !bConst; }
118 schoenebeck 2581 virtual void assign(Expression* expr) = 0;
119 schoenebeck 2945 void assignExpr(VMExpr* expr) OVERRIDE { Expression* e = dynamic_cast<Expression*>(expr); if (e) assign(e); }
120 schoenebeck 2581 protected:
121     Variable(ParserContext* ctx, int _memPos, bool _bConst)
122     : context(ctx), memPos(_memPos), bConst(_bConst) {}
123    
124     ParserContext* context;
125     int memPos;
126     bool bConst;
127     };
128     typedef Ref<Variable,Node> VariableRef;
129    
130     class IntVariable : public Variable, virtual public IntExpr {
131     bool polyphonic;
132     public:
133     IntVariable(ParserContext* ctx);
134     void assign(Expression* expr);
135     int evalInt();
136     void dump(int level = 0);
137     bool isPolyphonic() const { return polyphonic; }
138     protected:
139     IntVariable(ParserContext* ctx, bool polyphonic, bool bConst, int size = 1);
140     };
141     typedef Ref<IntVariable,Node> IntVariableRef;
142    
143     class ConstIntVariable : public IntVariable {
144     public:
145     int value;
146    
147     ConstIntVariable(int value);
148     //ConstIntVariable(ParserContext* ctx, int value = 0);
149     void assign(Expression* expr);
150     int evalInt();
151     void dump(int level = 0);
152     };
153     typedef Ref<ConstIntVariable,Node> ConstIntVariableRef;
154    
155 schoenebeck 2594 class BuiltInIntVariable : public IntVariable {
156     String name;
157     VMIntRelPtr* ptr;
158     public:
159     BuiltInIntVariable(const String& name, VMIntRelPtr* ptr);
160 schoenebeck 2948 bool isAssignable() const OVERRIDE { return !ptr->readonly; }
161 schoenebeck 3054 void assign(Expression* expr) OVERRIDE;
162     int evalInt() OVERRIDE;
163     void dump(int level = 0) OVERRIDE;
164 schoenebeck 2594 };
165     typedef Ref<BuiltInIntVariable,Node> BuiltInIntVariableRef;
166    
167 schoenebeck 2581 class PolyphonicIntVariable : public IntVariable {
168     public:
169     PolyphonicIntVariable(ParserContext* ctx);
170     void dump(int level = 0);
171     };
172     typedef Ref<PolyphonicIntVariable,Node> PolyphonicIntVariableRef;
173    
174 schoenebeck 2619 class IntArrayVariable : public Variable, virtual public VMIntArrayExpr {
175 schoenebeck 2581 ArrayList<int> values;
176     public:
177     IntArrayVariable(ParserContext* ctx, int size);
178     IntArrayVariable(ParserContext* ctx, int size, ArgsRef values);
179     void assign(Expression* expr) {} // ignore scalar assignment
180 schoenebeck 2594 String evalCastToStr() { return ""; } // ignore scalar cast to string
181 schoenebeck 2581 ExprType_t exprType() const { return INT_ARR_EXPR; }
182 schoenebeck 2594 virtual int arraySize() const { return values.size(); }
183     virtual int evalIntElement(uint i);
184     virtual void assignIntElement(uint i, int value);
185     void dump(int level = 0);
186 schoenebeck 2645 bool isPolyphonic() const { return false; }
187 schoenebeck 2594 protected:
188     IntArrayVariable(ParserContext* ctx, bool bConst);
189     };
190     typedef Ref<IntArrayVariable,Node> IntArrayVariableRef;
191    
192     class BuiltInIntArrayVariable : public IntArrayVariable {
193     String name;
194     VMInt8Array* array;
195     public:
196     BuiltInIntArrayVariable(const String& name, VMInt8Array* array);
197     int arraySize() const { return array->size; }
198 schoenebeck 2581 int evalIntElement(uint i);
199     void assignIntElement(uint i, int value);
200     void dump(int level = 0);
201     };
202 schoenebeck 2594 typedef Ref<BuiltInIntArrayVariable,Node> BuiltInIntArrayVariableRef;
203 schoenebeck 2581
204     class IntArrayElement : public IntVariable {
205     IntArrayVariableRef array;
206     IntExprRef index;
207     public:
208     IntArrayElement(IntArrayVariableRef array, IntExprRef arrayIndex);
209     void assign(Expression* expr);
210     int evalInt();
211     void dump(int level = 0);
212     };
213     typedef Ref<IntArrayElement,Node> IntArrayElementRef;
214    
215     class StringVariable : public Variable, virtual public StringExpr {
216     public:
217     StringVariable(ParserContext* ctx);
218     void assign(Expression* expr);
219     String evalStr();
220     void dump(int level = 0);
221 schoenebeck 2645 bool isPolyphonic() const { return false; }
222 schoenebeck 2581 protected:
223     StringVariable(ParserContext* ctx, bool bConst);
224     };
225     typedef Ref<StringVariable,Node> StringVariableRef;
226    
227     class ConstStringVariable : public StringVariable {
228     public:
229     String value;
230    
231     ConstStringVariable(ParserContext* ctx, String value = "");
232     void assign(Expression* expr);
233     String evalStr();
234     void dump(int level = 0);
235     };
236     typedef Ref<ConstStringVariable,Node> ConstStringVariableRef;
237    
238     class BinaryOp : virtual public Expression {
239     protected:
240     ExpressionRef lhs;
241     ExpressionRef rhs;
242     public:
243     BinaryOp(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) { }
244     bool isConstExpr() const { return lhs->isConstExpr() && rhs->isConstExpr(); }
245 schoenebeck 2645 bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
246 schoenebeck 2581 };
247     typedef Ref<BinaryOp,Node> BinaryOpRef;
248    
249     class Add : virtual public BinaryOp, virtual public IntExpr {
250     public:
251     Add(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
252     int evalInt();
253     void dump(int level = 0);
254     };
255     typedef Ref<Add,Node> AddRef;
256    
257     class Sub : virtual public BinaryOp, virtual public IntExpr {
258     public:
259     Sub(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
260     int evalInt();
261     void dump(int level = 0);
262     };
263     typedef Ref<Sub,Node> SubRef;
264    
265     class Mul : virtual public BinaryOp, virtual public IntExpr {
266     public:
267     Mul(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
268     int evalInt();
269     void dump(int level = 0);
270     };
271     typedef Ref<Mul,Node> MulRef;
272    
273     class Div : virtual public BinaryOp, virtual public IntExpr {
274     public:
275     Div(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
276     int evalInt();
277     void dump(int level = 0);
278     };
279     typedef Ref<Div,Node> DivRef;
280    
281     class Mod : virtual public BinaryOp, virtual public IntExpr {
282     public:
283     Mod(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs, rhs) { }
284     int evalInt();
285     void dump(int level = 0);
286     };
287     typedef Ref<Mod,Node> ModRef;
288    
289     class Statement : virtual public Node {
290     public:
291     virtual StmtType_t statementType() const = 0;
292     };
293     typedef Ref<Statement,Node> StatementRef;
294    
295     // Just used by parser to avoid "not a statement" parser warning, will be
296     // filtered out by parser. So it will not be part of the VM tree after parsing.
297     class NoOperation : public Statement {
298     public:
299     NoOperation() : Statement() {}
300     StmtType_t statementType() const { return STMT_LEAF; }
301     void dump(int level = 0) {}
302 schoenebeck 2645 bool isPolyphonic() const { return false; }
303 schoenebeck 2581 };
304     typedef Ref<NoOperation,Node> NoOperationRef;
305    
306     bool isNoOperation(StatementRef statement);
307    
308     class LeafStatement : public Statement {
309     public:
310     virtual StmtFlags_t exec() = 0;
311     virtual StmtType_t statementType() const { return STMT_LEAF; }
312     };
313     typedef Ref<LeafStatement,Node> LeafStatementRef;
314    
315     class Statements : public Statement {
316     std::vector<StatementRef> args;
317     public:
318     void add(StatementRef arg) { args.push_back(arg); }
319     void dump(int level = 0);
320     StmtType_t statementType() const { return STMT_LIST; }
321     virtual Statement* statement(uint i);
322 schoenebeck 2645 bool isPolyphonic() const;
323 schoenebeck 2581 };
324     typedef Ref<Statements,Node> StatementsRef;
325    
326     class BranchStatement : public Statement {
327     public:
328     StmtType_t statementType() const { return STMT_BRANCH; }
329     virtual int evalBranch() = 0;
330     virtual Statements* branch(uint i) const = 0;
331     };
332    
333 schoenebeck 2942 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 schoenebeck 2945 void assign(Expression* expr) OVERRIDE { dynVar->assignExpr(expr); }
343 schoenebeck 3118 VMIntArrayExpr* asIntArray() const OVERRIDE { return dynVar->asIntArray(); }
344 schoenebeck 2942 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 schoenebeck 2581 class FunctionCall : virtual public LeafStatement, virtual public IntExpr, virtual public StringExpr {
352     String functionName;
353     ArgsRef args;
354     VMFunction* fn;
355     public:
356     FunctionCall(const char* function, ArgsRef args, VMFunction* fn) :
357     functionName(function), args(args), fn(fn) { }
358 schoenebeck 3060 void dump(int level = 0) OVERRIDE;
359     StmtFlags_t exec() OVERRIDE;
360     int evalInt() OVERRIDE;
361 schoenebeck 3056 VMIntArrayExpr* asIntArray() const OVERRIDE;
362 schoenebeck 3060 String evalStr() OVERRIDE;
363     bool isConstExpr() const OVERRIDE { return false; }
364     ExprType_t exprType() const OVERRIDE;
365     String evalCastToStr() OVERRIDE;
366     bool isPolyphonic() const OVERRIDE { return args->isPolyphonic(); }
367 schoenebeck 2581 protected:
368     VMFnResult* execVMFn();
369     };
370     typedef Ref<FunctionCall,Node> FunctionCallRef;
371    
372     class EventHandler : virtual public Statements, virtual public VMEventHandler {
373     StatementsRef statements;
374 schoenebeck 2645 bool usingPolyphonics;
375 schoenebeck 2581 public:
376     void dump(int level = 0);
377     StmtFlags_t exec();
378 schoenebeck 2645 EventHandler(StatementsRef statements);
379 schoenebeck 2581 Statement* statement(uint i) { return statements->statement(i); }
380 schoenebeck 2645 bool isPolyphonic() const { return usingPolyphonics; }
381 schoenebeck 2581 };
382     typedef Ref<EventHandler,Node> EventHandlerRef;
383    
384     class OnNote : public EventHandler {
385     public:
386     OnNote(StatementsRef statements) : EventHandler(statements) {}
387 schoenebeck 2879 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_NOTE; }
388 schoenebeck 2581 String eventHandlerName() const { return "note"; }
389     };
390     typedef Ref<OnNote,Node> OnNoteRef;
391    
392     class OnInit : public EventHandler {
393     public:
394     OnInit(StatementsRef statements) : EventHandler(statements) {}
395 schoenebeck 2879 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_INIT; }
396 schoenebeck 2581 String eventHandlerName() const { return "init"; }
397     };
398     typedef Ref<OnInit,Node> OnInitRef;
399    
400     class OnRelease : public EventHandler {
401     public:
402     OnRelease(StatementsRef statements) : EventHandler(statements) {}
403 schoenebeck 2879 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_RELEASE; }
404 schoenebeck 2581 String eventHandlerName() const { return "release"; }
405     };
406     typedef Ref<OnRelease,Node> OnReleaseRef;
407    
408     class OnController : public EventHandler {
409     public:
410     OnController(StatementsRef statements) : EventHandler(statements) {}
411 schoenebeck 2879 VMEventHandlerType_t eventHandlerType() const { return VM_EVENT_HANDLER_CONTROLLER; }
412 schoenebeck 2581 String eventHandlerName() const { return "controller"; }
413     };
414     typedef Ref<OnController,Node> OnControllerRef;
415    
416     class EventHandlers : virtual public Node {
417     std::vector<EventHandlerRef> args;
418     public:
419     EventHandlers();
420     ~EventHandlers();
421     void add(EventHandlerRef arg);
422     void dump(int level = 0);
423     int evalInt() { return 0; }
424     EventHandler* eventHandlerByName(const String& name) const;
425     EventHandler* eventHandler(uint index) const;
426 schoenebeck 3054 inline uint size() const { return (int) args.size(); }
427 schoenebeck 2645 bool isPolyphonic() const;
428 schoenebeck 2581 };
429     typedef Ref<EventHandlers,Node> EventHandlersRef;
430    
431     class Assignment : public LeafStatement {
432     protected:
433     VariableRef variable;
434     ExpressionRef value;
435     public:
436     Assignment(VariableRef variable, ExpressionRef value);
437     void dump(int level = 0);
438     StmtFlags_t exec();
439 schoenebeck 2871 bool isPolyphonic() const { return (variable && variable->isPolyphonic()) || (value && value->isPolyphonic()); }
440 schoenebeck 2581 };
441     typedef Ref<Assignment,Node> AssignmentRef;
442    
443     class If : public BranchStatement {
444     IntExprRef condition;
445     StatementsRef ifStatements;
446     StatementsRef elseStatements;
447     public:
448     If(IntExprRef condition, StatementsRef ifStatements, StatementsRef elseStatements) :
449     condition(condition), ifStatements(ifStatements), elseStatements(elseStatements) { }
450     If(IntExprRef condition, StatementsRef statements) :
451     condition(condition), ifStatements(statements) { }
452     void dump(int level = 0);
453     int evalBranch();
454     Statements* branch(uint i) const;
455 schoenebeck 2645 bool isPolyphonic() const;
456 schoenebeck 2581 };
457     typedef Ref<If,Node> IfRef;
458    
459     struct CaseBranch {
460     IntExprRef from;
461     IntExprRef to;
462     StatementsRef statements;
463     };
464    
465     typedef std::vector<CaseBranch> CaseBranches;
466    
467     class SelectCase : public BranchStatement {
468     IntExprRef select;
469     CaseBranches branches;
470     public:
471     SelectCase(IntExprRef select, const CaseBranches& branches) : select(select), branches(branches) { }
472     void dump(int level = 0);
473     int evalBranch();
474     Statements* branch(uint i) const;
475     //void addBranch(IntExprRef condition, StatementsRef statements);
476     //void addBranch(IntExprRef from, IntExprRef to, StatementsRef statements);
477     //void addBranch(CaseBranchRef branch);
478     //void addBranches(CaseBranchesRef branches);
479 schoenebeck 2645 bool isPolyphonic() const;
480 schoenebeck 2581 };
481     typedef Ref<SelectCase,Node> SelectCaseRef;
482    
483     class While : public Statement {
484     IntExprRef m_condition;
485     StatementsRef m_statements;
486     public:
487     While(IntExprRef condition, StatementsRef statements) :
488     m_condition(condition), m_statements(statements) {}
489     StmtType_t statementType() const { return STMT_LOOP; }
490     void dump(int level = 0);
491     bool evalLoopStartCondition();
492     Statements* statements() const;
493 schoenebeck 2645 bool isPolyphonic() const { return m_condition->isPolyphonic() || m_statements->isPolyphonic(); }
494 schoenebeck 2581 };
495    
496     class Neg : public IntExpr {
497     IntExprRef expr;
498     public:
499     Neg(IntExprRef expr) : expr(expr) { }
500     int evalInt() { return (expr) ? -expr->evalInt() : 0; }
501     void dump(int level = 0);
502     bool isConstExpr() const { return expr->isConstExpr(); }
503 schoenebeck 2645 bool isPolyphonic() const { return expr->isPolyphonic(); }
504 schoenebeck 2581 };
505     typedef Ref<Neg,Node> NegRef;
506    
507     class ConcatString : public StringExpr {
508     ExpressionRef lhs;
509     ExpressionRef rhs;
510     public:
511     ConcatString(ExpressionRef lhs, ExpressionRef rhs) : lhs(lhs), rhs(rhs) {}
512     String evalStr();
513     void dump(int level = 0);
514     bool isConstExpr() const;
515 schoenebeck 2645 bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
516 schoenebeck 2581 };
517     typedef Ref<ConcatString,Node> ConcatStringRef;
518    
519     class Relation : public IntExpr {
520     public:
521     enum Type {
522     LESS_THAN,
523     GREATER_THAN,
524     LESS_OR_EQUAL,
525     GREATER_OR_EQUAL,
526     EQUAL,
527     NOT_EQUAL
528     };
529     Relation(IntExprRef lhs, Type type, IntExprRef rhs) :
530     lhs(lhs), rhs(rhs), type(type) {}
531     int evalInt();
532     void dump(int level = 0);
533     bool isConstExpr() const;
534 schoenebeck 2645 bool isPolyphonic() const { return lhs->isPolyphonic() || rhs->isPolyphonic(); }
535 schoenebeck 2581 private:
536     IntExprRef lhs;
537     IntExprRef rhs;
538     Type type;
539     };
540     typedef Ref<Relation,Node> RelationRef;
541    
542     class Or : virtual public BinaryOp, virtual public IntExpr {
543     public:
544     Or(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
545     int evalInt();
546     void dump(int level = 0);
547     };
548     typedef Ref<Or,Node> OrRef;
549    
550 schoenebeck 2935 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 schoenebeck 2581 class And : virtual public BinaryOp, virtual public IntExpr {
559     public:
560     And(IntExprRef lhs, IntExprRef rhs) : BinaryOp(lhs,rhs) {}
561     int evalInt();
562     void dump(int level = 0);
563     };
564     typedef Ref<And,Node> AndRef;
565    
566 schoenebeck 2935 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 schoenebeck 2581 class Not : virtual public IntExpr {
575     IntExprRef expr;
576     public:
577     Not(IntExprRef expr) : expr(expr) {}
578     int evalInt() { return !expr->evalInt(); }
579     void dump(int level = 0);
580     bool isConstExpr() const { return expr->isConstExpr(); }
581 schoenebeck 2645 bool isPolyphonic() const { return expr->isPolyphonic(); }
582 schoenebeck 2581 };
583     typedef Ref<Not,Node> NotRef;
584    
585 schoenebeck 2935 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 schoenebeck 2581 class ParserContext : public VMParserContext {
597     public:
598     struct Error {
599     String txt;
600     int line;
601     };
602     typedef Error Warning;
603    
604     void* scanner;
605     std::istream* is;
606 schoenebeck 2588 std::vector<ParserIssue> vErrors;
607     std::vector<ParserIssue> vWarnings;
608     std::vector<ParserIssue> vIssues;
609 schoenebeck 2581
610     std::set<String> builtinPreprocessorConditions;
611     std::set<String> userPreprocessorConditions;
612    
613     std::map<String,VariableRef> vartable;
614 schoenebeck 2951 std::map<String,StatementsRef> userFnTable;
615 schoenebeck 2581 int globalIntVarCount;
616     int globalStrVarCount;
617     int polyphonicIntVarCount;
618    
619     EventHandlersRef handlers;
620    
621     OnInitRef onInit;
622     OnNoteRef onNote;
623     OnReleaseRef onRelease;
624     OnControllerRef onController;
625    
626     ArrayList<int>* globalIntMemory;
627     ArrayList<String>* globalStrMemory;
628 schoenebeck 2588 int requiredMaxStackSize;
629 schoenebeck 2581
630     VMFunctionProvider* functionProvider;
631    
632     ExecContext* execContext;
633    
634     ParserContext(VMFunctionProvider* parent) :
635     scanner(NULL), is(NULL),
636     globalIntVarCount(0), globalStrVarCount(0), polyphonicIntVarCount(0),
637 schoenebeck 2588 globalIntMemory(NULL), globalStrMemory(NULL), requiredMaxStackSize(-1),
638     functionProvider(parent), execContext(NULL)
639 schoenebeck 2581 {
640     }
641 schoenebeck 2588 virtual ~ParserContext();
642 schoenebeck 2581 VariableRef globalVar(const String& name);
643     IntVariableRef globalIntVar(const String& name);
644     StringVariableRef globalStrVar(const String& name);
645     VariableRef variableByName(const String& name);
646 schoenebeck 2951 StatementsRef userFunctionByName(const String& name);
647 schoenebeck 2889 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 schoenebeck 2581 void createScanner(std::istream* is);
650     void destroyScanner();
651     bool setPreprocessorCondition(const char* name);
652     bool resetPreprocessorCondition(const char* name);
653     bool isPreprocessorConditionSet(const char* name);
654 schoenebeck 2588 std::vector<ParserIssue> issues() const OVERRIDE;
655     std::vector<ParserIssue> errors() const OVERRIDE;
656     std::vector<ParserIssue> warnings() const OVERRIDE;
657     VMEventHandler* eventHandler(uint index) OVERRIDE;
658     VMEventHandler* eventHandlerByName(const String& name) OVERRIDE;
659 schoenebeck 2594 void registerBuiltInConstIntVariables(const std::map<String,int>& vars);
660     void registerBuiltInIntVariables(const std::map<String,VMIntRelPtr*>& vars);
661     void registerBuiltInIntArrayVariables(const std::map<String,VMInt8Array*>& vars);
662 schoenebeck 2942 void registerBuiltInDynVariables(const std::map<String,VMDynVar*>& vars);
663 schoenebeck 2581 };
664    
665     class ExecContext : public VMExecContext {
666     public:
667     struct StackFrame {
668     Statement* statement;
669     int subindex;
670    
671     StackFrame() {
672     statement = NULL;
673     subindex = -1;
674     }
675     };
676    
677     ArrayList<int> polyphonicIntMemory;
678     VMExecStatus_t status;
679     ArrayList<StackFrame> stack;
680     int stackFrame;
681     int suspendMicroseconds;
682    
683     ExecContext() :
684     status(VM_EXEC_NOT_RUNNING), stackFrame(-1), suspendMicroseconds(0) {}
685    
686     virtual ~ExecContext() {}
687    
688     inline void pushStack(Statement* stmt) {
689     stackFrame++;
690     //printf("pushStack() -> %d\n", stackFrame);
691     if (stackFrame >= stack.size()) return;
692     stack[stackFrame].statement = stmt;
693     stack[stackFrame].subindex = 0;
694     }
695    
696     inline void popStack() {
697     stack[stackFrame].statement = NULL;
698     stack[stackFrame].subindex = -1;
699     stackFrame--;
700     //printf("popStack() -> %d\n", stackFrame);
701     }
702    
703     inline void reset() {
704     stack[0].statement = NULL;
705     stack[0].subindex = -1;
706     stackFrame = -1;
707     }
708    
709 schoenebeck 2588 int suspensionTimeMicroseconds() const OVERRIDE {
710 schoenebeck 2581 return suspendMicroseconds;
711     }
712     };
713    
714     } // namespace LinuxSampler
715    
716     #endif // LS_INSTRPARSERTREE_H

  ViewVC Help
Powered by ViewVC