/[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 2942 - (hide annotations) (download) (as text)
Wed Jul 13 15:51:06 2016 UTC (3 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 22038 byte(s)
* NKSP: Implemented built-in script variable "$KSP_TIMER".
* NKSP: Implemented built-in script variable "$NKSP_REAL_TIMER".
* NKSP: Implemented built-in script variable "$NKSP_PERF_TIMER".
* NKSP: Implemented built-in script variable "$ENGINE_UPTIME".
* Bumped version (2.0.0.svn14).

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

  ViewVC Help
Powered by ViewVC