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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2945 by schoenebeck, Thu Jul 14 00:22:26 2016 UTC revision 3034 by schoenebeck, Mon Oct 31 00:05:00 2016 UTC
# Line 168  namespace LinuxSampler { Line 168  namespace LinuxSampler {
168           * expression's constant value may be evaluated already at script           * expression's constant value may be evaluated already at script
169           * parse time, which may result in performance benefits during script           * parse time, which may result in performance benefits during script
170           * runtime.           * runtime.
171             *
172             * @b NOTE: A constant expression is per se always also non modifyable.
173             * But a non modifyable expression may not necessarily be a constant
174             * expression!
175             *
176             * @see isModifyable()
177           */           */
178          virtual bool isConstExpr() const = 0;          virtual bool isConstExpr() const = 0;
179    
180            /**
181             * Returns true in case this expression is allowed to be modified.
182             * If this method returns @c false then this expression must be handled
183             * as read-only expression, which means that assigning a new value to it
184             * is either not possible or not allowed.
185             *
186             * @b NOTE: A constant expression is per se always also non modifyable.
187             * But a non modifyable expression may not necessarily be a constant
188             * expression!
189             *
190             * @see isConstExpr()
191             */
192          bool isModifyable() const;          bool isModifyable() const;
193      };      };
194    
# Line 450  namespace LinuxSampler { Line 468  namespace LinuxSampler {
468      struct VMRelPtr {      struct VMRelPtr {
469          void** base; ///< Base pointer.          void** base; ///< Base pointer.
470          int offset;  ///< Offset (in bytes) relative to base pointer.          int offset;  ///< Offset (in bytes) relative to base pointer.
471            bool readonly; ///< Whether the pointed data may be modified or just be read.
472      };      };
473    
474      /** @brief Pointer to built-in VM integer variable (of C/C++ type int).      /** @brief Pointer to built-in VM integer variable (of C/C++ type int).
# Line 477  namespace LinuxSampler { Line 496  namespace LinuxSampler {
496          VMIntRelPtr() {          VMIntRelPtr() {
497              base   = NULL;              base   = NULL;
498              offset = 0;              offset = 0;
499                readonly = false;
500          }          }
501          VMIntRelPtr(const VMRelPtr& data) {          VMIntRelPtr(const VMRelPtr& data) {
502              base   = data.base;              base   = data.base;
503              offset = data.offset;              offset = data.offset;
504                readonly = false;
505          }          }
506          virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; }          virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; }
507          virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; }          virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; }
# Line 560  namespace LinuxSampler { Line 581  namespace LinuxSampler {
581       * complexity inside the sampler engines which provide the actual script       * complexity inside the sampler engines which provide the actual script
582       * functionalities.       * functionalities.
583       */       */
584      #define DECLARE_VMINT(basePtr, T_struct, T_member) ( \      #define DECLARE_VMINT(basePtr, T_struct, T_member) (          \
585          (VMRelPtr) {                                     \          /* Disable offsetof warning, trust us, we are cautios. */ \
586              (void**) &basePtr,                           \          _Pragma("GCC diagnostic push")                            \
587              offsetof(T_struct, T_member)                 \          _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"")  \
588          }                                                \          (VMRelPtr) {                                              \
589      )                                                    \              (void**) &basePtr,                                    \
590                offsetof(T_struct, T_member),                         \
591                false                                                 \
592            }                                                         \
593            _Pragma("GCC diagnostic pop")                             \
594        )                                                             \
595    
596        /**
597         * Same as DECLARE_VMINT(), but this one defines the VMIntRelPtr and
598         * VMInt8RelPtr structures to be of read-only type. That means the script
599         * parser will abort any script at parser time if the script is trying to
600         * modify such a read-only built-in variable.
601         *
602         * @b NOTE: this is only intended for built-in read-only variables that
603         * may change during runtime! If your built-in variable's data is rather
604         * already available at parser time and won't change during runtime, then
605         * you should rather register a built-in constant in your VM class instead!
606         *
607         * @see ScriptVM::builtInConstIntVariables()
608         */
609        #define DECLARE_VMINT_READONLY(basePtr, T_struct, T_member) ( \
610            /* Disable offsetof warning, trust us, we are cautios. */ \
611            _Pragma("GCC diagnostic push")                            \
612            _Pragma("GCC diagnostic ignored \"-Winvalid-offsetof\"")  \
613            (VMRelPtr) {                                              \
614                (void**) &basePtr,                                    \
615                offsetof(T_struct, T_member),                         \
616                true                                                  \
617            }                                                         \
618            _Pragma("GCC diagnostic pop")                             \
619        )                                                             \
620    
621      /** @brief Built-in VM 8 bit integer array variable.      /** @brief Built-in VM 8 bit integer array variable.
622       *       *
# Line 665  namespace LinuxSampler { Line 716  namespace LinuxSampler {
716           * @param expr - new value to be assigned to this variable           * @param expr - new value to be assigned to this variable
717           */           */
718          void assignExpr(VMExpr* expr) OVERRIDE {}          void assignExpr(VMExpr* expr) OVERRIDE {}
719    
720            virtual ~VMDynVar() {}
721      };      };
722    
723      /** @brief Dynamically executed variable (of integer data type).      /** @brief Dynamically executed variable (of integer data type).
# Line 805  namespace LinuxSampler { Line 858  namespace LinuxSampler {
858       * issue (either a parser error or parser warning), a human readable       * issue (either a parser error or parser warning), a human readable
859       * explanation text of the error or warning and the location of the       * explanation text of the error or warning and the location of the
860       * encountered parser issue within the script.       * encountered parser issue within the script.
861         *
862         * @see VMSourceToken for processing syntax highlighting instead.
863       */       */
864      struct ParserIssue {      struct ParserIssue {
865          String txt; ///< Human readable explanation text of the parser issue.          String txt; ///< Human readable explanation text of the parser issue.
# Line 923  namespace LinuxSampler { Line 978  namespace LinuxSampler {
978       * This class is not actually used by the sampler itself. It is rather       * This class is not actually used by the sampler itself. It is rather
979       * provided for external script editor applications. Primary purpose of       * provided for external script editor applications. Primary purpose of
980       * this class is syntax highlighting for external script editors.       * this class is syntax highlighting for external script editors.
981         *
982         * @see ParserIssue for processing compile errors and warnings instead.
983       */       */
984      class VMSourceToken {      class VMSourceToken {
985      public:      public:
# Line 935  namespace LinuxSampler { Line 992  namespace LinuxSampler {
992          String text() const;          String text() const;
993    
994          // position of token in script          // position of token in script
995          int firstLine() const; ///< First line this source token is located at in script source code (indexed with 0 being the very first line).          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.
996          int firstColumn() const; ///< Last line this source token is located at in script source code.          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().
997    
998          // base types          // base types
999          bool isEOF() const;          bool isEOF() const; ///< Returns true in case this source token represents the end of the source code file.
1000          bool isNewLine() const;          bool isNewLine() const; ///< Returns true in case this source token represents a line feed character (i.e. "\n" on Unix systems).
1001          bool isKeyword() const;          bool isKeyword() const; ///< Returns true in case this source token represents a language keyword (i.e. "while", "function", "declare", "on", etc.).
1002          bool isVariableName() const;          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.
1003          bool isIdentifier() const;          bool isIdentifier() const; ///< Returns true in case this source token represents an identifier, which currently always means a function name.
1004          bool isNumberLiteral() const;          bool isNumberLiteral() const; ///< Returns true in case this source token represents a number literal (i.e. 123).
1005          bool isStringLiteral() const;          bool isStringLiteral() const; ///< Returns true in case this source token represents a string literal (i.e. "Some text").
1006          bool isComment() const;          bool isComment() const; ///< Returns true in case this source token represents a source code comment.
1007          bool isPreprocessor() const;          bool isPreprocessor() const; ///< Returns true in case this source token represents a preprocessor statement.
1008          bool isOther() const;          bool isOther() const; ///< Returns true in case this source token represents anything else not covered by the token types mentioned above.
1009    
1010          // extended types          // extended types
1011          bool isIntegerVariable() const;          bool isIntegerVariable() const; ///< Returns true in case this source token represents an integer variable name (i.e. "$someIntVariable").
1012          bool isStringVariable() const;          bool isStringVariable() const; ///< Returns true in case this source token represents an string variable name (i.e. "\@someStringVariable").
1013          bool isArrayVariable() const;          bool isArrayVariable() const; ///< Returns true in case this source token represents an array variable name (i.e. "%someArryVariable").
1014          bool isEventHandlerName() const;          bool isEventHandlerName() const; ///< Returns true in case this source token represents an event handler name (i.e. "note", "release", "controller").
1015    
1016          VMSourceToken& operator=(const VMSourceToken& other);          VMSourceToken& operator=(const VMSourceToken& other);
1017    

Legend:
Removed from v.2945  
changed lines
  Added in v.3034

  ViewVC Help
Powered by ViewVC