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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3293 - (hide annotations) (download) (as text)
Tue Jun 27 22:19:19 2017 UTC (6 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 50757 byte(s)
* NKSP: Added built-in script function "fork()".
* NKSP: Added built-in array variable %NKSP_CALLBACK_CHILD_ID[].
* NKSP: Added built-in variable $NKSP_CALLBACK_PARENT_ID.
* NKSP: Fixed potential crash when accessing dynamic built-in
  array variables.
* Bumped version (2.0.0.svn65).

1 schoenebeck 2581 /*
2 schoenebeck 3073 * Copyright (c) 2014-2017 Christian Schoenebeck
3 schoenebeck 2581 *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     // This header defines data types shared between the VM core implementation
11     // (inside the current source directory) and other parts of the sampler
12 schoenebeck 3292 // (located at other source directories). It also acts as public API of the
13     // Real-Time script engine for other applications.
14 schoenebeck 2581
15     #ifndef LS_INSTR_SCRIPT_PARSER_COMMON_H
16     #define LS_INSTR_SCRIPT_PARSER_COMMON_H
17    
18     #include "../common/global.h"
19 schoenebeck 2588 #include <vector>
20 schoenebeck 2594 #include <map>
21     #include <stddef.h> // offsetof()
22 schoenebeck 2581
23     namespace LinuxSampler {
24 schoenebeck 2727
25     /**
26     * Identifies the type of a noteworthy issue identified by the script
27     * parser. That's either a parser error or parser warning.
28     */
29 schoenebeck 2581 enum ParserIssueType_t {
30 schoenebeck 2727 PARSER_ERROR, ///< Script parser encountered an error, the script cannot be executed.
31     PARSER_WARNING ///< Script parser encountered a warning, the script may be executed if desired, but the script may not necessarily behave as originally intended by the script author.
32 schoenebeck 2581 };
33    
34 schoenebeck 2727 /** @brief Expression's data type.
35     *
36     * Identifies to which data type an expression within a script evaluates to.
37     * This can for example reflect the data type of script function arguments,
38     * script function return values, but also the resulting data type of some
39     * mathematical formula within a script.
40     */
41 schoenebeck 2581 enum ExprType_t {
42 schoenebeck 2727 EMPTY_EXPR, ///< i.e. on invalid expressions or i.e. a function call that does not return a result value (the built-in wait() or message() functions for instance)
43     INT_EXPR, ///< integer (scalar) expression
44     INT_ARR_EXPR, ///< integer array expression
45     STRING_EXPR, ///< string expression
46     STRING_ARR_EXPR, ///< string array expression
47 schoenebeck 2581 };
48    
49 schoenebeck 2727 /** @brief Result flags of a script statement or script function call.
50     *
51     * A set of bit flags which provide informations about the success or
52     * failure of a statement within a script. That's also especially used for
53     * providing informations about success / failure of a call to a built-in
54     * script function. The virtual machine evaluates these flags during runtime
55     * to decide whether it should i.e. stop or suspend execution of a script.
56     *
57     * Since these are bit flags, these constants are bitwise combined.
58     */
59 schoenebeck 2581 enum StmtFlags_t {
60     STMT_SUCCESS = 0, ///< Function / statement was executed successfully, no error occurred.
61 schoenebeck 2727 STMT_ABORT_SIGNALLED = 1, ///< VM should stop the current callback execution (usually because of an error, but might also be without an error reason, i.e. when the built-in script function exit() was called).
62     STMT_SUSPEND_SIGNALLED = (1<<1), ///< VM supended execution, either because the script called the built-in wait() script function or because the script consumed too much execution time and was forced by the VM to be suspended for some time
63     STMT_ERROR_OCCURRED = (1<<2), ///< VM stopped execution due to some script runtime error that occurred
64 schoenebeck 2581 };
65    
66 schoenebeck 2727 /** @brief Virtual machine execution status.
67     *
68     * A set of bit flags which reflect the current overall execution status of
69     * the virtual machine concerning a certain script execution instance.
70     *
71     * Since these are bit flags, these constants are bitwise combined.
72     */
73 schoenebeck 2581 enum VMExecStatus_t {
74 schoenebeck 2727 VM_EXEC_NOT_RUNNING = 0, ///< Script is currently not executed by the VM.
75     VM_EXEC_RUNNING = 1, ///< The VM is currently executing the script.
76     VM_EXEC_SUSPENDED = (1<<1), ///< Script is currently suspended by the VM, either because the script called the built-in wait() script function or because the script consumed too much execution time and was forced by the VM to be suspended for some time.
77     VM_EXEC_ERROR = (1<<2), ///< A runtime error occurred while executing the script (i.e. a call to some built-in script function failed).
78 schoenebeck 2581 };
79    
80 schoenebeck 2879 /** @brief Script event handler type.
81     *
82     * Identifies one of the possible event handler callback types defined by
83     * the NKSP script language.
84     */
85     enum VMEventHandlerType_t {
86     VM_EVENT_HANDLER_INIT, ///< Initilization event handler, that is script's "on init ... end on" code block.
87     VM_EVENT_HANDLER_NOTE, ///< Note event handler, that is script's "on note ... end on" code block.
88     VM_EVENT_HANDLER_RELEASE, ///< Release event handler, that is script's "on release ... end on" code block.
89     VM_EVENT_HANDLER_CONTROLLER, ///< Controller event handler, that is script's "on controller ... end on" code block.
90     };
91    
92 schoenebeck 2727 // just symbol prototyping
93 schoenebeck 2596 class VMIntExpr;
94     class VMStringExpr;
95 schoenebeck 2619 class VMIntArrayExpr;
96     class VMStringArrayExpr;
97 schoenebeck 2596
98 schoenebeck 2727 /** @brief Virtual machine expression
99     *
100     * This is the abstract base class for all expressions of scripts.
101     * Deriving classes must implement the abstract method exprType().
102     *
103     * An expression within a script is translated into one instance of this
104     * class. It allows a high level access for the virtual machine to evaluate
105     * and handle expressions appropriately during execution. Expressions are
106     * for example all kinds of formulas, function calls, statements or a
107     * combination of them. Most of them evaluate to some kind of value, which
108     * might be further processed as part of encompassing expressions to outer
109     * expression results and so forth.
110     */
111 schoenebeck 2581 class VMExpr {
112     public:
113 schoenebeck 2727 /**
114     * Identifies the data type to which the result of this expression
115     * evaluates to. This abstract method must be implemented by deriving
116     * classes.
117     */
118 schoenebeck 2581 virtual ExprType_t exprType() const = 0;
119 schoenebeck 2727
120     /**
121     * In case this expression is an integer expression, then this method
122     * returns a casted pointer to that VMIntExpr object. It returns NULL
123     * if this expression is not an integer expression.
124     *
125     * @b Note: type casting performed by this method is strict! That means
126     * if this expression is i.e. actually a string expression like "12",
127     * calling asInt() will @b not cast that numerical string expression to
128     * an integer expression 12 for you, instead this method will simply
129     * return NULL!
130     *
131     * @see exprType()
132     */
133 schoenebeck 2596 VMIntExpr* asInt() const;
134 schoenebeck 2727
135     /**
136     * In case this expression is a string expression, then this method
137     * returns a casted pointer to that VMStringExpr object. It returns NULL
138     * if this expression is not a string expression.
139     *
140     * @b Note: type casting performed by this method is strict! That means
141     * if this expression is i.e. actually an integer expression like 120,
142     * calling asString() will @b not cast that integer expression to a
143     * string expression "120" for you, instead this method will simply
144     * return NULL!
145     *
146     * @see exprType()
147     */
148 schoenebeck 2596 VMStringExpr* asString() const;
149 schoenebeck 2727
150     /**
151     * In case this expression is an integer array expression, then this
152     * method returns a casted pointer to that VMIntArrayExpr object. It
153     * returns NULL if this expression is not an integer array expression.
154     *
155     * @b Note: type casting performed by this method is strict! That means
156     * if this expression is i.e. an integer expression or a string
157     * expression, calling asIntArray() will @b not cast those scalar
158     * expressions to an array expression for you, instead this method will
159     * simply return NULL!
160     *
161 schoenebeck 3056 * @b Note: this method is currently, and in contrast to its other
162     * counter parts, declared as virtual method. Some deriving classes are
163     * currently using this to override this default implementation in order
164     * to implement an "evaluate now as integer array" behavior. This has
165     * efficiency reasons, however this also currently makes this part of
166     * the API less clean and should thus be addressed in future with
167     * appropriate changes to the API.
168     *
169 schoenebeck 2727 * @see exprType()
170     */
171 schoenebeck 3056 virtual VMIntArrayExpr* asIntArray() const;
172 schoenebeck 2945
173     /**
174     * Returns true in case this expression can be considered to be a
175     * constant expression. A constant expression will retain the same
176     * value throughout the entire life time of a script and the
177     * expression's constant value may be evaluated already at script
178     * parse time, which may result in performance benefits during script
179     * runtime.
180 schoenebeck 2960 *
181     * @b NOTE: A constant expression is per se always also non modifyable.
182     * But a non modifyable expression may not necessarily be a constant
183     * expression!
184     *
185     * @see isModifyable()
186 schoenebeck 2945 */
187     virtual bool isConstExpr() const = 0;
188    
189 schoenebeck 2960 /**
190     * Returns true in case this expression is allowed to be modified.
191     * If this method returns @c false then this expression must be handled
192     * as read-only expression, which means that assigning a new value to it
193     * is either not possible or not allowed.
194     *
195     * @b NOTE: A constant expression is per se always also non modifyable.
196     * But a non modifyable expression may not necessarily be a constant
197     * expression!
198     *
199     * @see isConstExpr()
200     */
201 schoenebeck 2945 bool isModifyable() const;
202 schoenebeck 2581 };
203    
204 schoenebeck 2727 /** @brief Virtual machine integer expression
205     *
206     * This is the abstract base class for all expressions inside scripts which
207     * evaluate to an integer (scalar) value. Deriving classes implement the
208     * abstract method evalInt() to return the actual integer result value of
209     * the expression.
210     */
211 schoenebeck 2581 class VMIntExpr : virtual public VMExpr {
212     public:
213 schoenebeck 2727 /**
214     * Returns the result of this expression as integer (scalar) value.
215     * This abstract method must be implemented by deriving classes.
216     */
217 schoenebeck 2581 virtual int evalInt() = 0;
218 schoenebeck 2727
219     /**
220     * Returns always INT_EXPR for instances of this class.
221     */
222     ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
223 schoenebeck 2581 };
224    
225 schoenebeck 2727 /** @brief Virtual machine string expression
226     *
227     * This is the abstract base class for all expressions inside scripts which
228     * evaluate to a string value. Deriving classes implement the abstract
229     * method evalStr() to return the actual string result value of the
230     * expression.
231     */
232 schoenebeck 2581 class VMStringExpr : virtual public VMExpr {
233     public:
234 schoenebeck 2727 /**
235     * Returns the result of this expression as string value. This abstract
236     * method must be implemented by deriving classes.
237     */
238 schoenebeck 2581 virtual String evalStr() = 0;
239 schoenebeck 2727
240     /**
241     * Returns always STRING_EXPR for instances of this class.
242     */
243     ExprType_t exprType() const OVERRIDE { return STRING_EXPR; }
244 schoenebeck 2581 };
245    
246 schoenebeck 2727 /** @brief Virtual Machine Array Value Expression
247     *
248     * This is the abstract base class for all expressions inside scripts which
249     * evaluate to some kind of array value. Deriving classes implement the
250     * abstract method arraySize() to return the amount of elements within the
251     * array.
252     */
253 schoenebeck 2619 class VMArrayExpr : virtual public VMExpr {
254     public:
255 schoenebeck 2727 /**
256     * Returns amount of elements in this array. This abstract method must
257     * be implemented by deriving classes.
258     */
259 schoenebeck 2619 virtual int arraySize() const = 0;
260     };
261    
262 schoenebeck 2727 /** @brief Virtual Machine Integer Array Expression
263     *
264     * This is the abstract base class for all expressions inside scripts which
265     * evaluate to an array of integer values. Deriving classes implement the
266     * abstract methods arraySize(), evalIntElement() and assignIntElement() to
267     * access the individual integer array values.
268     */
269 schoenebeck 2619 class VMIntArrayExpr : virtual public VMArrayExpr {
270     public:
271 schoenebeck 2727 /**
272     * Returns the (scalar) integer value of the array element given by
273     * element index @a i.
274     *
275     * @param i - array element index (must be between 0 .. arraySize() - 1)
276     */
277 schoenebeck 2619 virtual int evalIntElement(uint i) = 0;
278 schoenebeck 2727
279     /**
280     * Changes the current value of an element (given by array element
281     * index @a i) of this integer array.
282     *
283     * @param i - array element index (must be between 0 .. arraySize() - 1)
284     * @param value - new integer scalar value to be assigned to that array element
285     */
286 schoenebeck 2619 virtual void assignIntElement(uint i, int value) = 0;
287 schoenebeck 2727
288     /**
289     * Returns always INT_ARR_EXPR for instances of this class.
290     */
291     ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
292 schoenebeck 2619 };
293    
294 schoenebeck 2727 /** @brief Arguments (parameters) for being passed to a built-in script function.
295     *
296     * An argument or a set of arguments passed to a script function are
297     * translated by the parser to an instance of this class. This abstract
298     * interface class is used by implementations of built-in functions to
299     * obtain the individual function argument values being passed to them at
300     * runtime.
301     */
302 schoenebeck 2581 class VMFnArgs {
303     public:
304 schoenebeck 2727 /**
305     * Returns the amount of arguments going to be passed to the script
306     * function.
307     */
308 schoenebeck 2581 virtual int argsCount() const = 0;
309 schoenebeck 2727
310     /**
311     * Returns the respective argument (requested by argument index @a i) of
312     * this set of arguments. This method is called by implementations of
313     * built-in script functions to obtain the value of each function
314     * argument passed to the function at runtime.
315     *
316     * @param i - function argument index (indexed from left to right)
317     */
318 schoenebeck 2581 virtual VMExpr* arg(int i) = 0;
319     };
320    
321 schoenebeck 2727 /** @brief Result value returned from a call to a built-in script function.
322     *
323     * Implementations of built-in script functions return an instance of this
324     * object to let the virtual machine obtain the result value of the function
325     * call, which might then be further processed by the virtual machine
326     * according to the script. It also provides informations about the success
327     * or failure of the function call.
328     */
329 schoenebeck 2581 class VMFnResult {
330     public:
331 schoenebeck 2727 /**
332     * Returns the result value of the function call, represented by a high
333     * level expression object.
334     */
335 schoenebeck 2581 virtual VMExpr* resultValue() = 0;
336 schoenebeck 2727
337     /**
338     * Provides detailed informations of the success / failure of the
339     * function call. The virtual machine is evaluating the flags returned
340     * here to decide whether it must abort or suspend execution of the
341     * script at this point.
342     */
343 schoenebeck 2581 virtual StmtFlags_t resultFlags() { return STMT_SUCCESS; }
344     };
345    
346 schoenebeck 2727 /** @brief Virtual machine built-in function.
347 schoenebeck 2612 *
348     * Abstract base class for built-in script functions, defining the interface
349 schoenebeck 2727 * for all built-in script function implementations. All built-in script
350     * functions are deriving from this abstract interface class in order to
351     * provide their functionality to the virtual machine with this unified
352     * interface.
353     *
354     * The methods of this interface class provide two purposes:
355     *
356     * 1. When a script is loaded, the script parser uses the methods of this
357     * interface to check whether the script author was calling the
358     * respective built-in script function in a correct way. For example
359     * the parser checks whether the required amount of parameters were
360     * passed to the function and whether the data types passed match the
361     * data types expected by the function. If not, loading the script will
362     * be aborted with a parser error, describing to the user (i.e. script
363     * author) the precise misusage of the respective function.
364     * 2. After the script was loaded successfully and the script is executed,
365     * the virtual machine calls the exec() method of the respective built-in
366     * function to provide the actual functionality of the built-in function
367     * call.
368 schoenebeck 2612 */
369 schoenebeck 2581 class VMFunction {
370     public:
371 schoenebeck 2612 /**
372     * Script data type of the function's return value. If the function does
373 schoenebeck 2727 * not return any value (void), then it returns EMPTY_EXPR here.
374 schoenebeck 2612 */
375 schoenebeck 2581 virtual ExprType_t returnType() = 0;
376 schoenebeck 2612
377     /**
378     * Minimum amount of function arguments this function accepts. If a
379     * script is calling this function with less arguments, the script
380     * parser will throw a parser error.
381     */
382 schoenebeck 2581 virtual int minRequiredArgs() const = 0;
383 schoenebeck 2612
384     /**
385     * Maximum amount of function arguments this functions accepts. If a
386     * script is calling this function with more arguments, the script
387     * parser will throw a parser error.
388     */
389 schoenebeck 2581 virtual int maxAllowedArgs() const = 0;
390 schoenebeck 2612
391     /**
392     * Script data type of the function's @c iArg 'th function argument.
393     * The information provided here is less strong than acceptsArgType().
394     * The parser will compare argument data types provided in scripts by
395 schoenebeck 2871 * calling acceptsArgType(). The return value of argType() is used by the
396 schoenebeck 2612 * parser instead to show an appropriate parser error which data type
397     * this function usually expects as "default" data type. Reason: a
398     * function may accept multiple data types for a certain function
399     * argument and would automatically cast the passed argument value in
400     * that case to the type it actually needs.
401     *
402     * @param iArg - index of the function argument in question
403 schoenebeck 2727 * (must be between 0 .. maxAllowedArgs() - 1)
404 schoenebeck 2612 */
405 schoenebeck 2581 virtual ExprType_t argType(int iArg) const = 0;
406 schoenebeck 2612
407     /**
408 schoenebeck 2945 * This method is called by the parser to check whether arguments
409 schoenebeck 2612 * passed in scripts to this function are accepted by this function. If
410     * a script calls this function with an argument's data type not
411 schoenebeck 2727 * accepted by this function, the parser will throw a parser error. On
412     * such errors the data type returned by argType() will be used to
413     * assemble an appropriate error message regarding the precise misusage
414     * of the built-in function.
415 schoenebeck 2612 *
416     * @param iArg - index of the function argument in question
417 schoenebeck 2727 * (must be between 0 .. maxAllowedArgs() - 1)
418 schoenebeck 2612 * @param type - script data type used for this function argument by
419     * currently parsed script
420 schoenebeck 2727 * @return true if the given data type would be accepted for the
421     * respective function argument by the function
422 schoenebeck 2612 */
423 schoenebeck 2581 virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0;
424 schoenebeck 2612
425     /**
426 schoenebeck 2945 * This method is called by the parser to check whether some arguments
427     * (and if yes which ones) passed to this script function will be
428     * modified by this script function. Most script functions simply use
429     * their arguments as inputs, that is they only read the argument's
430     * values. However some script function may also use passed
431     * argument(s) as output variables. In this case the function
432     * implementation must return @c true for the respective argument
433     * index here.
434     *
435     * @param iArg - index of the function argument in question
436     * (must be between 0 .. maxAllowedArgs() - 1)
437     */
438     virtual bool modifiesArg(int iArg) const = 0;
439    
440     /**
441 schoenebeck 2727 * Implements the actual function execution. This exec() method is
442     * called by the VM whenever this function implementation shall be
443     * executed at script runtime. This method blocks until the function
444     * call completed.
445 schoenebeck 2612 *
446     * @param args - function arguments for executing this built-in function
447 schoenebeck 2727 * @returns function's return value (if any) and general status
448     * informations (i.e. whether the function call caused a
449     * runtime error)
450 schoenebeck 2612 */
451 schoenebeck 2581 virtual VMFnResult* exec(VMFnArgs* args) = 0;
452 schoenebeck 2612
453     /**
454 schoenebeck 2727 * Convenience method for function implementations to show warning
455     * messages during actual execution of the built-in function.
456 schoenebeck 2612 *
457 schoenebeck 2727 * @param txt - runtime warning text to be shown to user
458 schoenebeck 2612 */
459 schoenebeck 2598 void wrnMsg(const String& txt);
460 schoenebeck 2612
461     /**
462 schoenebeck 2727 * Convenience method for function implementations to show error
463     * messages during actual execution of the built-in function.
464 schoenebeck 2612 *
465 schoenebeck 2727 * @param txt - runtime error text to be shown to user
466 schoenebeck 2612 */
467 schoenebeck 2598 void errMsg(const String& txt);
468 schoenebeck 2581 };
469    
470 schoenebeck 2727 /** @brief Virtual machine relative pointer.
471     *
472 schoenebeck 2594 * POD base of VMIntRelPtr and VMInt8RelPtr structures. Not intended to be
473     * used directly. Use VMIntRelPtr or VMInt8RelPtr instead.
474 schoenebeck 2727 *
475     * @see VMIntRelPtr, VMInt8RelPtr
476 schoenebeck 2594 */
477     struct VMRelPtr {
478     void** base; ///< Base pointer.
479 schoenebeck 2727 int offset; ///< Offset (in bytes) relative to base pointer.
480 schoenebeck 2948 bool readonly; ///< Whether the pointed data may be modified or just be read.
481 schoenebeck 2594 };
482    
483     /** @brief Pointer to built-in VM integer variable (of C/C++ type int).
484     *
485 schoenebeck 2727 * Used for defining built-in 32 bit integer script variables.
486 schoenebeck 2594 *
487     * @b CAUTION: You may only use this class for pointing to C/C++ variables
488     * of type "int" (which on most systems is 32 bit in size). If the C/C++ int
489     * variable you want to reference is only 8 bit in size, then you @b must
490     * use VMInt8RelPtr instead!
491     *
492     * For efficiency reasons the actual native C/C++ int variable is referenced
493     * by two components here. The actual native int C/C++ variable in memory
494     * is dereferenced at VM run-time by taking the @c base pointer dereference
495     * and adding @c offset bytes. This has the advantage that for a large
496     * number of built-in int variables, only one (or few) base pointer need
497     * to be re-assigned before running a script, instead of updating each
498     * built-in variable each time before a script is executed.
499     *
500     * Refer to DECLARE_VMINT() for example code.
501     *
502     * @see VMInt8RelPtr, DECLARE_VMINT()
503     */
504     struct VMIntRelPtr : VMRelPtr {
505     VMIntRelPtr() {
506     base = NULL;
507     offset = 0;
508 schoenebeck 2948 readonly = false;
509 schoenebeck 2594 }
510     VMIntRelPtr(const VMRelPtr& data) {
511     base = data.base;
512     offset = data.offset;
513 schoenebeck 2948 readonly = false;
514 schoenebeck 2594 }
515     virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; }
516     virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; }
517     };
518    
519     /** @brief Pointer to built-in VM integer variable (of C/C++ type int8_t).
520     *
521 schoenebeck 2727 * Used for defining built-in 8 bit integer script variables.
522 schoenebeck 2594 *
523     * @b CAUTION: You may only use this class for pointing to C/C++ variables
524     * of type "int8_t" (8 bit integer). If the C/C++ int variable you want to
525     * reference is an "int" type (which is 32 bit on most systems), then you
526     * @b must use VMIntRelPtr instead!
527     *
528     * For efficiency reasons the actual native C/C++ int variable is referenced
529     * by two components here. The actual native int C/C++ variable in memory
530     * is dereferenced at VM run-time by taking the @c base pointer dereference
531     * and adding @c offset bytes. This has the advantage that for a large
532     * number of built-in int variables, only one (or few) base pointer need
533     * to be re-assigned before running a script, instead of updating each
534     * built-in variable each time before a script is executed.
535     *
536     * Refer to DECLARE_VMINT() for example code.
537     *
538     * @see VMIntRelPtr, DECLARE_VMINT()
539     */
540     struct VMInt8RelPtr : VMIntRelPtr {
541     VMInt8RelPtr() : VMIntRelPtr() {}
542     VMInt8RelPtr(const VMRelPtr& data) : VMIntRelPtr(data) {}
543     virtual int evalInt() OVERRIDE {
544     return *(uint8_t*)&(*(uint8_t**)base)[offset];
545     }
546     virtual void assign(int i) OVERRIDE {
547     *(uint8_t*)&(*(uint8_t**)base)[offset] = i;
548     }
549     };
550    
551 schoenebeck 3035 #if HAVE_CXX_EMBEDDED_PRAGMA_DIAGNOSTICS
552     # define COMPILER_DISABLE_OFFSETOF_WARNING \
553     _Pragma("GCC diagnostic push") \
554     _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"")
555     # define COMPILER_RESTORE_OFFSETOF_WARNING \
556     _Pragma("GCC diagnostic pop")
557     #else
558     # define COMPILER_DISABLE_OFFSETOF_WARNING
559     # define COMPILER_RESTORE_OFFSETOF_WARNING
560     #endif
561    
562 schoenebeck 2594 /**
563     * Convenience macro for initializing VMIntRelPtr and VMInt8RelPtr
564 schoenebeck 2727 * structures. Usage example:
565 schoenebeck 2594 * @code
566     * struct Foo {
567 schoenebeck 2727 * uint8_t a; // native representation of a built-in integer script variable
568     * int b; // native representation of another built-in integer script variable
569     * int c; // native representation of another built-in integer script variable
570     * uint8_t d; // native representation of another built-in integer script variable
571 schoenebeck 2594 * };
572     *
573 schoenebeck 2727 * // initializing the built-in script variables to some values
574     * Foo foo1 = (Foo) { 1, 2000, 3000, 4 };
575     * Foo foo2 = (Foo) { 5, 6000, 7000, 8 };
576 schoenebeck 2594 *
577     * Foo* pFoo;
578     *
579 schoenebeck 2727 * VMInt8RelPtr varA = DECLARE_VMINT(pFoo, class Foo, a);
580     * VMIntRelPtr varB = DECLARE_VMINT(pFoo, class Foo, b);
581     * VMIntRelPtr varC = DECLARE_VMINT(pFoo, class Foo, c);
582     * VMInt8RelPtr varD = DECLARE_VMINT(pFoo, class Foo, d);
583 schoenebeck 2594 *
584     * pFoo = &foo1;
585 schoenebeck 2727 * printf("%d\n", varA->evalInt()); // will print 1
586     * printf("%d\n", varB->evalInt()); // will print 2000
587     * printf("%d\n", varC->evalInt()); // will print 3000
588     * printf("%d\n", varD->evalInt()); // will print 4
589 schoenebeck 2594 *
590 schoenebeck 2727 * // same printf() code, just with pFoo pointer being changed ...
591     *
592 schoenebeck 2594 * pFoo = &foo2;
593 schoenebeck 2727 * printf("%d\n", varA->evalInt()); // will print 5
594     * printf("%d\n", varB->evalInt()); // will print 6000
595     * printf("%d\n", varC->evalInt()); // will print 7000
596     * printf("%d\n", varD->evalInt()); // will print 8
597 schoenebeck 2594 * @endcode
598 schoenebeck 2727 * As you can see above, by simply changing one single pointer, you can
599     * remap a huge bunch of built-in integer script variables to completely
600     * different native values/native variables. Which especially reduces code
601     * complexity inside the sampler engines which provide the actual script
602     * functionalities.
603 schoenebeck 2594 */
604 schoenebeck 3034 #define DECLARE_VMINT(basePtr, T_struct, T_member) ( \
605     /* Disable offsetof warning, trust us, we are cautios. */ \
606 schoenebeck 3035 COMPILER_DISABLE_OFFSETOF_WARNING \
607 schoenebeck 3034 (VMRelPtr) { \
608     (void**) &basePtr, \
609     offsetof(T_struct, T_member), \
610     false \
611     } \
612 schoenebeck 3035 COMPILER_RESTORE_OFFSETOF_WARNING \
613 schoenebeck 3034 ) \
614 schoenebeck 2594
615 schoenebeck 2948 /**
616     * Same as DECLARE_VMINT(), but this one defines the VMIntRelPtr and
617     * VMInt8RelPtr structures to be of read-only type. That means the script
618     * parser will abort any script at parser time if the script is trying to
619     * modify such a read-only built-in variable.
620     *
621     * @b NOTE: this is only intended for built-in read-only variables that
622     * may change during runtime! If your built-in variable's data is rather
623     * already available at parser time and won't change during runtime, then
624     * you should rather register a built-in constant in your VM class instead!
625     *
626     * @see ScriptVM::builtInConstIntVariables()
627     */
628     #define DECLARE_VMINT_READONLY(basePtr, T_struct, T_member) ( \
629 schoenebeck 3034 /* Disable offsetof warning, trust us, we are cautios. */ \
630 schoenebeck 3035 COMPILER_DISABLE_OFFSETOF_WARNING \
631 schoenebeck 3034 (VMRelPtr) { \
632     (void**) &basePtr, \
633     offsetof(T_struct, T_member), \
634     true \
635     } \
636 schoenebeck 3035 COMPILER_RESTORE_OFFSETOF_WARNING \
637 schoenebeck 3034 ) \
638 schoenebeck 2948
639 schoenebeck 2594 /** @brief Built-in VM 8 bit integer array variable.
640     *
641 schoenebeck 2727 * Used for defining built-in integer array script variables (8 bit per
642     * array element). Currently there is no support for any other kind of array
643     * type. So all integer arrays of scripts use 8 bit data types.
644 schoenebeck 2594 */
645     struct VMInt8Array {
646     int8_t* data;
647     int size;
648 schoenebeck 3253 bool readonly; ///< Whether the array data may be modified or just be read.
649 schoenebeck 2594
650 schoenebeck 3253 VMInt8Array() : data(NULL), size(0), readonly(false) {}
651 schoenebeck 2594 };
652    
653 schoenebeck 2945 /** @brief Virtual machine script variable.
654     *
655     * Common interface for all variables accessed in scripts.
656     */
657     class VMVariable : virtual public VMExpr {
658     public:
659     /**
660     * Whether a script may modify the content of this variable by
661     * assigning a new value to it.
662     *
663     * @see isConstExpr(), assign()
664     */
665     virtual bool isAssignable() const = 0;
666    
667     /**
668     * In case this variable is assignable, this method will be called to
669     * perform the value assignment to this variable with @a expr
670     * reflecting the new value to be assigned.
671     *
672     * @param expr - new value to be assigned to this variable
673     */
674     virtual void assignExpr(VMExpr* expr) = 0;
675     };
676    
677 schoenebeck 2942 /** @brief Dynamically executed variable (abstract base class).
678     *
679     * Interface for the implementation of a dynamically generated content of
680     * a built-in script variable. Most built-in variables are simply pointers
681     * to some native location in memory. So when a script reads them, the
682     * memory location is simply read to get the value of the variable. A
683     * dynamic variable however is not simply a memory location. For each access
684     * to a dynamic variable some native code is executed to actually generate
685     * and provide the content (value) of this type of variable.
686     */
687 schoenebeck 2945 class VMDynVar : public VMVariable {
688 schoenebeck 2942 public:
689     /**
690     * Returns true in case this dynamic variable can be considered to be a
691     * constant expression. A constant expression will retain the same value
692     * throughout the entire life time of a script and the expression's
693     * constant value may be evaluated already at script parse time, which
694     * may result in performance benefits during script runtime.
695     *
696     * However due to the "dynamic" behavior of dynamic variables, almost
697     * all dynamic variables are probably not constant expressions. That's
698     * why this method returns @c false by default. If you are really sure
699     * that your dynamic variable implementation can be considered a
700     * constant expression then you may override this method and return
701     * @c true instead. Note that when you return @c true here, your
702     * dynamic variable will really just be executed once; and exectly
703     * already when the script is loaded!
704     *
705     * As an example you may implement a "constant" built-in dynamic
706     * variable that checks for a certain operating system feature and
707     * returns the result of that OS feature check as content (value) of
708     * this dynamic variable. Since the respective OS feature might become
709     * available/unavailable after OS updates, software migration, etc. the
710     * OS feature check should at least be performed once each time the
711     * application is launched. And since the OS feature check might take a
712     * certain amount of execution time, it might make sense to only
713     * perform the check if the respective variable name is actually
714     * referenced at all in the script to be loaded. Note that the dynamic
715     * variable will still be evaluated again though if the script is
716     * loaded again. So it is up to you to probably cache the result in the
717     * implementation of your dynamic variable.
718     *
719     * On doubt, please rather consider to use a constant built-in script
720     * variable instead of implementing a "constant" dynamic variable, due
721     * to the runtime overhead a dynamic variable may cause.
722     *
723     * @see isAssignable()
724     */
725 schoenebeck 2945 bool isConstExpr() const OVERRIDE { return false; }
726 schoenebeck 2942
727     /**
728     * In case this dynamic variable is assignable, the new value (content)
729     * to be assigned to this dynamic variable.
730     *
731     * By default this method does nothing. Override and implement this
732     * method in your subclass in case your dynamic variable allows to
733     * assign a new value by script.
734     *
735     * @param expr - new value to be assigned to this variable
736     */
737 schoenebeck 2945 void assignExpr(VMExpr* expr) OVERRIDE {}
738 schoenebeck 3034
739     virtual ~VMDynVar() {}
740 schoenebeck 2942 };
741    
742     /** @brief Dynamically executed variable (of integer data type).
743     *
744     * This is the base class for all built-in integer script variables whose
745     * variable content needs to be provided dynamically by executable native
746     * code on each script variable access.
747     */
748     class VMDynIntVar : virtual public VMDynVar, virtual public VMIntExpr {
749     public:
750     };
751    
752     /** @brief Dynamically executed variable (of string data type).
753     *
754     * This is the base class for all built-in string script variables whose
755     * variable content needs to be provided dynamically by executable native
756     * code on each script variable access.
757     */
758     class VMDynStringVar : virtual public VMDynVar, virtual public VMStringExpr {
759     public:
760     };
761    
762 schoenebeck 3073 /** @brief Dynamically executed variable (of integer array data type).
763     *
764     * This is the base class for all built-in integer array script variables
765     * whose variable content needs to be provided dynamically by executable
766     * native code on each script variable access.
767     */
768     class VMDynIntArrayVar : virtual public VMDynVar, virtual public VMIntArrayExpr {
769     public:
770     };
771    
772 schoenebeck 2612 /** @brief Provider for built-in script functions and variables.
773     *
774 schoenebeck 2727 * Abstract base class defining the high-level interface for all classes
775     * which add and implement built-in script functions and built-in script
776     * variables.
777 schoenebeck 2612 */
778 schoenebeck 2581 class VMFunctionProvider {
779     public:
780 schoenebeck 2612 /**
781     * Returns pointer to the built-in function with the given function
782 schoenebeck 2727 * @a name, or NULL if there is no built-in function with that function
783     * name.
784 schoenebeck 2612 *
785 schoenebeck 2727 * @param name - function name (i.e. "wait" or "message" or "exit", etc.)
786 schoenebeck 2612 */
787 schoenebeck 2581 virtual VMFunction* functionByName(const String& name) = 0;
788 schoenebeck 2612
789     /**
790     * Returns a variable name indexed map of all built-in script variables
791 schoenebeck 2727 * which point to native "int" scalar (usually 32 bit) variables.
792 schoenebeck 2612 */
793 schoenebeck 2594 virtual std::map<String,VMIntRelPtr*> builtInIntVariables() = 0;
794 schoenebeck 2612
795     /**
796 schoenebeck 2727 * Returns a variable name indexed map of all built-in script integer
797     * array variables with array element type "int8_t" (8 bit).
798 schoenebeck 2612 */
799 schoenebeck 2594 virtual std::map<String,VMInt8Array*> builtInIntArrayVariables() = 0;
800 schoenebeck 2612
801     /**
802     * Returns a variable name indexed map of all built-in constant script
803     * variables, which never change their value at runtime.
804     */
805 schoenebeck 2594 virtual std::map<String,int> builtInConstIntVariables() = 0;
806 schoenebeck 2942
807     /**
808     * Returns a variable name indexed map of all built-in dynamic variables,
809     * which are not simply data stores, rather each one of them executes
810     * natively to provide or alter the respective script variable data.
811     */
812     virtual std::map<String,VMDynVar*> builtInDynamicVariables() = 0;
813 schoenebeck 2581 };
814    
815 schoenebeck 2594 /** @brief Execution state of a virtual machine.
816     *
817     * An instance of this abstract base class represents exactly one execution
818     * state of a virtual machine. This encompasses most notably the VM
819 schoenebeck 2612 * execution stack, and VM polyphonic variables. It does not contain global
820 schoenebeck 2727 * variables. Global variables are contained in the VMParserContext object.
821 schoenebeck 2612 * You might see a VMExecContext object as one virtual thread of the virtual
822     * machine.
823 schoenebeck 2594 *
824 schoenebeck 2612 * In contrast to a VMParserContext, a VMExecContext is not tied to a
825     * ScriptVM instance. Thus you can use a VMExecContext with different
826     * ScriptVM instances, however not concurrently at the same time.
827     *
828 schoenebeck 2594 * @see VMParserContext
829     */
830 schoenebeck 2581 class VMExecContext {
831     public:
832     virtual ~VMExecContext() {}
833 schoenebeck 2727
834     /**
835     * In case the script was suspended for some reason, this method returns
836     * the amount of microseconds before the script shall continue its
837     * execution. Note that the virtual machine itself does never put its
838     * own execution thread(s) to sleep. So the respective class (i.e. sampler
839     * engine) which is using the virtual machine classes here, must take
840     * care by itself about taking time stamps, determining the script
841     * handlers that shall be put aside for the requested amount of
842 schoenebeck 2871 * microseconds, indicated by this method by comparing the time stamps in
843 schoenebeck 2727 * real-time, and to continue passing the respective handler to
844     * ScriptVM::exec() as soon as its suspension exceeded, etc. Or in other
845     * words: all classes in this directory never have an idea what time it
846     * is.
847     *
848     * You should check the return value of ScriptVM::exec() to determine
849     * whether the script was actually suspended before calling this method
850     * here.
851     *
852     * @see ScriptVM::exec()
853     */
854 schoenebeck 2581 virtual int suspensionTimeMicroseconds() const = 0;
855 schoenebeck 3207
856     /**
857     * Causes all polyphonic variables to be reset to zero values. A
858     * polyphonic variable is expected to be zero when entering a new event
859     * handler instance. As an exception the values of polyphonic variables
860     * shall only be preserved from an note event handler instance to its
861     * correspending specific release handler instance. So in the latter
862     * case the script author may pass custom data from the note handler to
863     * the release handler, but only for the same specific note!
864     */
865     virtual void resetPolyphonicData() = 0;
866 schoenebeck 3221
867     /**
868     * Returns amount of virtual machine instructions which have been
869     * performed the last time when this execution context was executing a
870     * script. So in case you need the overall amount of instructions
871     * instead, then you need to add them by yourself after each
872     * ScriptVM::exec() call.
873     */
874     virtual size_t instructionsPerformed() const = 0;
875 schoenebeck 3277
876     /**
877     * Sends a signal to this script execution instance to abort its script
878     * execution as soon as possible. This method is called i.e. when one
879     * script execution instance intends to stop another script execution
880     * instance.
881     */
882     virtual void signalAbort() = 0;
883 schoenebeck 3293
884     /**
885     * Copies the current entire execution state from this object to the
886     * given object. So this can be used to "fork" a new script thread which
887     * then may run independently with its own polyphonic data for instance.
888     */
889     virtual void forkTo(VMExecContext* ectx) const = 0;
890 schoenebeck 2581 };
891    
892 schoenebeck 2645 /** @brief Script callback for a certain event.
893     *
894     * Represents a script callback for a certain event, i.e.
895 schoenebeck 2727 * "on note ... end on" code block.
896 schoenebeck 2645 */
897 schoenebeck 2581 class VMEventHandler {
898     public:
899 schoenebeck 2645 /**
900 schoenebeck 2879 * Type of this event handler, which identifies its purpose. For example
901     * for a "on note ... end on" script callback block,
902     * @c VM_EVENT_HANDLER_NOTE would be returned here.
903     */
904     virtual VMEventHandlerType_t eventHandlerType() const = 0;
905    
906     /**
907 schoenebeck 2645 * Name of the event handler which identifies its purpose. For example
908     * for a "on note ... end on" script callback block, the name "note"
909     * would be returned here.
910     */
911 schoenebeck 2581 virtual String eventHandlerName() const = 0;
912 schoenebeck 2645
913     /**
914     * Whether or not the event handler makes any use of so called
915     * "polyphonic" variables.
916     */
917     virtual bool isPolyphonic() const = 0;
918 schoenebeck 2581 };
919    
920 schoenebeck 2727 /**
921 schoenebeck 3285 * Reflects the precise position and span of a specific code block within
922     * a script. This is currently only used for the locations of commented
923 schoenebeck 3292 * code blocks due to preprocessor statements, and for parser errors and
924     * parser warnings.
925 schoenebeck 3285 *
926 schoenebeck 3292 * @see ParserIssue for code locations of parser errors and parser warnings
927     *
928     * @see VMParserContext::preprocessorComments() for locations of code which
929     * have been filtered out by preprocessor statements
930 schoenebeck 3285 */
931     struct CodeBlock {
932     int firstLine; ///< The first line number of this code block within the script (indexed with 1 being the very first line).
933     int lastLine; ///< The last line number of this code block within the script.
934     int firstColumn; ///< The first column of this code block within the script (indexed with 1 being the very first column).
935     int lastColumn; ///< The last column of this code block within the script.
936     };
937    
938     /**
939 schoenebeck 2727 * Encapsulates a noteworty parser issue. This encompasses the type of the
940     * issue (either a parser error or parser warning), a human readable
941     * explanation text of the error or warning and the location of the
942     * encountered parser issue within the script.
943 schoenebeck 3012 *
944     * @see VMSourceToken for processing syntax highlighting instead.
945 schoenebeck 2727 */
946 schoenebeck 3292 struct ParserIssue : CodeBlock {
947 schoenebeck 2727 String txt; ///< Human readable explanation text of the parser issue.
948     ParserIssueType_t type; ///< Whether this issue is either a parser error or just a parser warning.
949 schoenebeck 2581
950 schoenebeck 2727 /**
951     * Print this issue out to the console (stdio).
952     */
953 schoenebeck 2581 inline void dump() {
954     switch (type) {
955     case PARSER_ERROR:
956 schoenebeck 2889 printf("[ERROR] line %d, column %d: %s\n", firstLine, firstColumn, txt.c_str());
957 schoenebeck 2581 break;
958     case PARSER_WARNING:
959 schoenebeck 2889 printf("[Warning] line %d, column %d: %s\n", firstLine, firstColumn, txt.c_str());
960 schoenebeck 2581 break;
961     }
962     }
963 schoenebeck 2727
964     /**
965     * Returns true if this issue is a parser error. In this case the parsed
966     * script may not be executed!
967     */
968 schoenebeck 2581 inline bool isErr() const { return type == PARSER_ERROR; }
969 schoenebeck 2727
970     /**
971     * Returns true if this issue is just a parser warning. A parsed script
972     * that only raises warnings may be executed if desired, however the
973     * script may not behave exactly as intended by the script author.
974     */
975 schoenebeck 2581 inline bool isWrn() const { return type == PARSER_WARNING; }
976     };
977    
978 schoenebeck 2727 /**
979     * Convenience function used for converting an ExprType_t constant to a
980     * string, i.e. for generating error message by the parser.
981     */
982 schoenebeck 2581 inline String typeStr(const ExprType_t& type) {
983     switch (type) {
984     case EMPTY_EXPR: return "empty";
985     case INT_EXPR: return "integer";
986     case INT_ARR_EXPR: return "integer array";
987     case STRING_EXPR: return "string";
988     case STRING_ARR_EXPR: return "string array";
989     }
990     return "invalid";
991     }
992    
993 schoenebeck 2594 /** @brief Virtual machine representation of a script.
994     *
995     * An instance of this abstract base class represents a parsed script,
996 schoenebeck 2727 * translated into a virtual machine tree. You should first check if there
997     * were any parser errors. If there were any parser errors, you should
998     * refrain from executing the virtual machine. Otherwise if there were no
999     * parser errors (i.e. only warnings), then you might access one of the
1000     * script's event handlers by i.e. calling eventHandlerByName() and pass the
1001     * respective event handler to the ScriptVM class (or to one of the ScriptVM
1002 schoenebeck 2594 * descendants) for execution.
1003     *
1004 schoenebeck 2727 * @see VMExecContext, ScriptVM
1005 schoenebeck 2594 */
1006 schoenebeck 2588 class VMParserContext {
1007     public:
1008     virtual ~VMParserContext() {}
1009 schoenebeck 2727
1010     /**
1011     * Returns all noteworthy issues encountered when the script was parsed.
1012     * These are parser errors and parser warnings.
1013     */
1014 schoenebeck 2588 virtual std::vector<ParserIssue> issues() const = 0;
1015 schoenebeck 2727
1016     /**
1017     * Same as issues(), but this method only returns parser errors.
1018     */
1019 schoenebeck 2588 virtual std::vector<ParserIssue> errors() const = 0;
1020 schoenebeck 2727
1021     /**
1022     * Same as issues(), but this method only returns parser warnings.
1023     */
1024 schoenebeck 2588 virtual std::vector<ParserIssue> warnings() const = 0;
1025 schoenebeck 2727
1026     /**
1027 schoenebeck 3285 * Returns all code blocks of the script which were filtered out by the
1028     * preprocessor.
1029     */
1030     virtual std::vector<CodeBlock> preprocessorComments() const = 0;
1031    
1032     /**
1033 schoenebeck 2727 * Returns the translated virtual machine representation of an event
1034     * handler block (i.e. "on note ... end on" code block) within the
1035     * parsed script. This translated representation of the event handler
1036     * can be executed by the virtual machine.
1037     *
1038     * @param index - index of the event handler within the script
1039     */
1040 schoenebeck 2588 virtual VMEventHandler* eventHandler(uint index) = 0;
1041 schoenebeck 2727
1042     /**
1043     * Same as eventHandler(), but this method returns the event handler by
1044     * its name. So for a "on note ... end on" code block of the parsed
1045     * script you would pass "note" for argument @a name here.
1046     *
1047     * @param name - name of the event handler (i.e. "init", "note",
1048     * "controller", "release")
1049     */
1050 schoenebeck 2588 virtual VMEventHandler* eventHandlerByName(const String& name) = 0;
1051     };
1052    
1053 schoenebeck 2885 class SourceToken;
1054    
1055     /** @brief Recognized token of a script's source code.
1056     *
1057     * Represents one recognized token of a script's source code, for example
1058     * a keyword, variable name, etc. and it provides further informations about
1059     * that particular token, i.e. the precise location (line and column) of the
1060     * token within the original script's source code.
1061     *
1062     * This class is not actually used by the sampler itself. It is rather
1063     * provided for external script editor applications. Primary purpose of
1064     * this class is syntax highlighting for external script editors.
1065 schoenebeck 3012 *
1066     * @see ParserIssue for processing compile errors and warnings instead.
1067 schoenebeck 2885 */
1068     class VMSourceToken {
1069     public:
1070     VMSourceToken();
1071     VMSourceToken(SourceToken* ct);
1072     VMSourceToken(const VMSourceToken& other);
1073     virtual ~VMSourceToken();
1074    
1075     // original text of this token as it is in the script's source code
1076     String text() const;
1077    
1078     // position of token in script
1079 schoenebeck 3012 int firstLine() const; ///< First line this source token is located at in script source code (indexed with 0 being the very first line). Most source code tokens are not spanning over multiple lines, the only current exception are comments, in the latter case you need to process text() to get the last line and last column for the comment.
1080     int firstColumn() const; ///< First column on the first line this source token is located at in script source code (indexed with 0 being the very first column). To get the length of this token use text().length().
1081 schoenebeck 2885
1082     // base types
1083 schoenebeck 3012 bool isEOF() const; ///< Returns true in case this source token represents the end of the source code file.
1084     bool isNewLine() const; ///< Returns true in case this source token represents a line feed character (i.e. "\n" on Unix systems).
1085     bool isKeyword() const; ///< Returns true in case this source token represents a language keyword (i.e. "while", "function", "declare", "on", etc.).
1086     bool isVariableName() const; ///< Returns true in case this source token represents a variable name (i.e. "$someIntVariable", "%someArrayVariable", "\@someStringVariable"). @see isIntegerVariable(), isStringVariable(), isArrayVariable() for the precise variable type.
1087     bool isIdentifier() const; ///< Returns true in case this source token represents an identifier, which currently always means a function name.
1088     bool isNumberLiteral() const; ///< Returns true in case this source token represents a number literal (i.e. 123).
1089     bool isStringLiteral() const; ///< Returns true in case this source token represents a string literal (i.e. "Some text").
1090     bool isComment() const; ///< Returns true in case this source token represents a source code comment.
1091     bool isPreprocessor() const; ///< Returns true in case this source token represents a preprocessor statement.
1092     bool isOther() const; ///< Returns true in case this source token represents anything else not covered by the token types mentioned above.
1093 schoenebeck 2885
1094     // extended types
1095 schoenebeck 3012 bool isIntegerVariable() const; ///< Returns true in case this source token represents an integer variable name (i.e. "$someIntVariable").
1096     bool isStringVariable() const; ///< Returns true in case this source token represents an string variable name (i.e. "\@someStringVariable").
1097     bool isArrayVariable() const; ///< Returns true in case this source token represents an array variable name (i.e. "%someArryVariable").
1098     bool isEventHandlerName() const; ///< Returns true in case this source token represents an event handler name (i.e. "note", "release", "controller").
1099 schoenebeck 2885
1100     VMSourceToken& operator=(const VMSourceToken& other);
1101    
1102     private:
1103     SourceToken* m_token;
1104     };
1105    
1106 schoenebeck 2581 } // namespace LinuxSampler
1107    
1108     #endif // LS_INSTR_SCRIPT_PARSER_COMMON_H

  ViewVC Help
Powered by ViewVC