/[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 2945 - (hide annotations) (download) (as text)
Thu Jul 14 00:22:26 2016 UTC (7 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 22185 byte(s)
* NKSP: Implemented built-in script function "inc()".
* NKSP: Implemented built-in script function "dec()".
* NKSP language fix: division expressions were evaluated too often.
* NKSP language fix: string concatenation operator was right
  associative instead of left (to right).
* Bumped version (2.0.0.svn15).

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

  ViewVC Help
Powered by ViewVC