/[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 3208 - (hide annotations) (download) (as text)
Thu May 25 11:39:03 2017 UTC (6 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 23047 byte(s)
- Fixed compilation error with some compilers.

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

  ViewVC Help
Powered by ViewVC