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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3054 - (show annotations) (download) (as text)
Thu Dec 15 12:47:45 2016 UTC (7 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 22396 byte(s)
* Fixed numerous compiler warnings.
* Bumped version (2.0.0.svn32).

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

  ViewVC Help
Powered by ViewVC