From 17aacbd1bad146406c1a8248e97382ab96b2d26b Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Tue, 2 Jun 2015 14:52:32 -0400 Subject: [PATCH] update muparser to 2.2.4 --- bundled/muparser_v2_2_3/include/muParserDLL.h | 235 ---- bundled/muparser_v2_2_3/src/muParserDLL.cpp | 1060 ----------------- .../CMakeLists.txt | 0 .../Changes.txt | 20 +- .../License.txt | 0 .../include/muParser.h | 3 +- .../include/muParserBase.h | 10 +- .../include/muParserBytecode.h | 10 +- .../include/muParserCallback.h | 0 .../include/muParserDef.h | 6 +- .../include/muParserError.h | 6 +- .../include/muParserFixes.h | 0 .../include/muParserInt.h | 9 +- .../include/muParserStack.h | 2 +- .../include/muParserTemplateMagic.h | 37 - .../include/muParserTest.h | 32 +- .../include/muParserToken.h | 2 + .../include/muParserTokenReader.h | 0 .../src/muParser.cpp | 13 +- .../src/muParserBase.cpp | 121 +- .../src/muParserBytecode.cpp | 121 +- .../src/muParserCallback.cpp | 0 .../src/muParserError.cpp | 5 +- .../src/muParserInt.cpp | 0 .../src/muParserTest.cpp | 136 ++- .../src/muParserTokenReader.cpp | 19 +- bundled/setup_bundled.cmake | 2 +- 27 files changed, 337 insertions(+), 1512 deletions(-) delete mode 100644 bundled/muparser_v2_2_3/include/muParserDLL.h delete mode 100644 bundled/muparser_v2_2_3/src/muParserDLL.cpp rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/CMakeLists.txt (100%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/Changes.txt (94%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/License.txt (100%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParser.h (95%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserBase.h (94%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserBytecode.h (94%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserCallback.h (100%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserDef.h (96%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserError.h (95%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserFixes.h (100%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserInt.h (91%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserStack.h (96%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserTemplateMagic.h (54%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserTest.h (85%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserToken.h (96%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/include/muParserTokenReader.h (100%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParser.cpp (94%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParserBase.cpp (89%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParserBytecode.cpp (81%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParserCallback.cpp (100%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParserError.cpp (96%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParserInt.cpp (100%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParserTest.cpp (91%) rename bundled/{muparser_v2_2_3 => muparser_v2_2_4}/src/muParserTokenReader.cpp (95%) diff --git a/bundled/muparser_v2_2_3/include/muParserDLL.h b/bundled/muparser_v2_2_3/include/muParserDLL.h deleted file mode 100644 index db11c8db92..0000000000 --- a/bundled/muparser_v2_2_3/include/muParserDLL.h +++ /dev/null @@ -1,235 +0,0 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2011 Ingo Berg - - Permission is hereby granted, free of charge, to any person obtaining a copy of this - software and associated documentation files (the "Software"), to deal in the Software - without restriction, including without limitation the rights to use, copy, modify, - merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all copies or - substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#ifndef MU_PARSER_DLL_H -#define MU_PARSER_DLL_H - -#if defined(WIN32) || defined(_WIN32) - #ifdef MUPARSERLIB_EXPORTS - #define API_EXPORT(TYPE) __declspec(dllexport) TYPE __cdecl - #else - #define API_EXPORT(TYPE) __declspec(dllimport) TYPE __cdecl - #endif -#else - #define API_EXPORT(TYPE) TYPE -#endif - - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** \file - \brief This file contains the DLL interface of muparser. -*/ - -// Basic types -typedef void* muParserHandle_t; // parser handle -typedef char muChar_t; // character type -typedef int muBool_t; // boolean type -typedef int muInt_t; // integer type -typedef double muFloat_t; // floating point type - -// function types for calculation -typedef muFloat_t (*muFun0_t )(); -typedef muFloat_t (*muFun1_t )(muFloat_t); -typedef muFloat_t (*muFun2_t )(muFloat_t, muFloat_t); -typedef muFloat_t (*muFun3_t )(muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muFun4_t )(muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muFun5_t )(muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muFun6_t )(muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muFun7_t )(muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muFun8_t )(muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muFun9_t )(muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muFun10_t)(muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); - -// Function prototypes for bulkmode functions -typedef muFloat_t (*muBulkFun0_t )(int, int); -typedef muFloat_t (*muBulkFun1_t )(int, int, muFloat_t); -typedef muFloat_t (*muBulkFun2_t )(int, int, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun3_t )(int, int, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun4_t )(int, int, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun5_t )(int, int, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun6_t )(int, int, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun7_t )(int, int, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun8_t )(int, int, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun9_t )(int, int, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); -typedef muFloat_t (*muBulkFun10_t)(int, int, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t, muFloat_t); - -typedef muFloat_t (*muMultFun_t)(const muFloat_t*, muInt_t); -typedef muFloat_t (*muStrFun1_t)(const muChar_t*); -typedef muFloat_t (*muStrFun2_t)(const muChar_t*, muFloat_t); -typedef muFloat_t (*muStrFun3_t)(const muChar_t*, muFloat_t, muFloat_t); - -// Functions for parser management -typedef void (*muErrorHandler_t)(muParserHandle_t a_hParser); // [optional] callback to an error handler -typedef muFloat_t* (*muFacFun_t)(const muChar_t*, void*); // [optional] callback for creating new variables -typedef muInt_t (*muIdentFun_t)(const muChar_t*, muInt_t*, muFloat_t*); // [optional] value identification callbacks - -//----------------------------------------------------------------------------------------------------- -// Constants -static const int muOPRT_ASCT_LEFT = 0; -static const int muOPRT_ASCT_RIGHT = 1; - -static const int muBASETYPE_FLOAT = 0; -static const int muBASETYPE_INT = 1; - -//----------------------------------------------------------------------------------------------------- -// -// -// muParser C compatible bindings -// -// -//----------------------------------------------------------------------------------------------------- - - -// Basic operations / initialization -API_EXPORT(muParserHandle_t) mupCreate(int nBaseType); -API_EXPORT(void) mupRelease(muParserHandle_t a_hParser); -API_EXPORT(const muChar_t*) mupGetExpr(muParserHandle_t a_hParser); -API_EXPORT(void) mupSetExpr(muParserHandle_t a_hParser, const muChar_t *a_szExpr); -API_EXPORT(void) mupSetVarFactory(muParserHandle_t a_hParser, muFacFun_t a_pFactory, void* pUserData); -API_EXPORT(const muChar_t*) mupGetVersion(muParserHandle_t a_hParser); -API_EXPORT(muFloat_t) mupEval(muParserHandle_t a_hParser); -API_EXPORT(muFloat_t*) mupEvalMulti(muParserHandle_t a_hParser, int *nNum); -API_EXPORT(void) mupEvalBulk(muParserHandle_t a_hParser, muFloat_t *a_fResult, int nSize); - -// Defining callbacks / variables / constants -API_EXPORT(void) mupDefineFun0(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun0_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun1(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun1_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun2(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun2_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun3(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun3_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun4(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun4_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun5(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun5_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun6(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun6_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun7(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun7_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun8(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun8_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun9(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun9_t a_pFun, muBool_t a_bOptimize); -API_EXPORT(void) mupDefineFun10(muParserHandle_t a_hParser, const muChar_t *a_szName, muFun10_t a_pFun, muBool_t a_bOptimize); - -// Defining bulkmode functions -API_EXPORT(void) mupDefineBulkFun0(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun0_t a_pFun); -API_EXPORT(void) mupDefineBulkFun1(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun1_t a_pFun); -API_EXPORT(void) mupDefineBulkFun2(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun2_t a_pFun); -API_EXPORT(void) mupDefineBulkFun3(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun3_t a_pFun); -API_EXPORT(void) mupDefineBulkFun4(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun4_t a_pFun); -API_EXPORT(void) mupDefineBulkFun5(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun5_t a_pFun); -API_EXPORT(void) mupDefineBulkFun6(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun6_t a_pFun); -API_EXPORT(void) mupDefineBulkFun7(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun7_t a_pFun); -API_EXPORT(void) mupDefineBulkFun8(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun8_t a_pFun); -API_EXPORT(void) mupDefineBulkFun9(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun9_t a_pFun); -API_EXPORT(void) mupDefineBulkFun10(muParserHandle_t a_hParser, const muChar_t *a_szName, muBulkFun10_t a_pFun); - -// string functions -API_EXPORT(void) mupDefineStrFun1(muParserHandle_t a_hParser, const muChar_t *a_szName, muStrFun1_t a_pFun); -API_EXPORT(void) mupDefineStrFun2(muParserHandle_t a_hParser, const muChar_t *a_szName, muStrFun2_t a_pFun); -API_EXPORT(void) mupDefineStrFun3(muParserHandle_t a_hParser, const muChar_t *a_szName, muStrFun3_t a_pFun); - -API_EXPORT(void) mupDefineMultFun( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muMultFun_t a_pFun, - muBool_t a_bOptimize); - -API_EXPORT(void) mupDefineOprt( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun2_t a_pFun, - muInt_t a_nPrec, - muInt_t a_nOprtAsct, - muBool_t a_bOptimize); - -API_EXPORT(void) mupDefineConst( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFloat_t a_fVal ); - -API_EXPORT(void) mupDefineStrConst( muParserHandle_t a_hParser, - const muChar_t* a_szName, - const muChar_t *a_sVal ); - -API_EXPORT(void) mupDefineVar( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFloat_t *a_fVar); - -API_EXPORT(void) mupDefineBulkVar( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFloat_t *a_fVar); - -API_EXPORT(void) mupDefinePostfixOprt( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun1_t a_pOprt, - muBool_t a_bOptimize); - - -API_EXPORT(void) mupDefineInfixOprt( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun1_t a_pOprt, - muBool_t a_bOptimize); - -// Define character sets for identifiers -API_EXPORT(void) mupDefineNameChars(muParserHandle_t a_hParser, const muChar_t* a_szCharset); -API_EXPORT(void) mupDefineOprtChars(muParserHandle_t a_hParser, const muChar_t* a_szCharset); -API_EXPORT(void) mupDefineInfixOprtChars(muParserHandle_t a_hParser, const muChar_t* a_szCharset); - -// Remove all / single variables -API_EXPORT(void) mupRemoveVar(muParserHandle_t a_hParser, const muChar_t* a_szName); -API_EXPORT(void) mupClearVar(muParserHandle_t a_hParser); -API_EXPORT(void) mupClearConst(muParserHandle_t a_hParser); -API_EXPORT(void) mupClearOprt(muParserHandle_t a_hParser); -API_EXPORT(void) mupClearFun(muParserHandle_t a_hParser); - -// Querying variables / expression variables / constants -API_EXPORT(int) mupGetExprVarNum(muParserHandle_t a_hParser); -API_EXPORT(int) mupGetVarNum(muParserHandle_t a_hParser); -API_EXPORT(int) mupGetConstNum(muParserHandle_t a_hParser); -API_EXPORT(void) mupGetExprVar(muParserHandle_t a_hParser, unsigned a_iVar, const muChar_t** a_pszName, muFloat_t** a_pVar); -API_EXPORT(void) mupGetVar(muParserHandle_t a_hParser, unsigned a_iVar, const muChar_t** a_pszName, muFloat_t** a_pVar); -API_EXPORT(void) mupGetConst(muParserHandle_t a_hParser, unsigned a_iVar, const muChar_t** a_pszName, muFloat_t* a_pVar); -API_EXPORT(void) mupSetArgSep(muParserHandle_t a_hParser, const muChar_t cArgSep); -API_EXPORT(void) mupSetDecSep(muParserHandle_t a_hParser, const muChar_t cArgSep); -API_EXPORT(void) mupSetThousandsSep(muParserHandle_t a_hParser, const muChar_t cArgSep); -API_EXPORT(void) mupResetLocale(muParserHandle_t a_hParser); - -// Add value recognition callbacks -API_EXPORT(void) mupAddValIdent(muParserHandle_t a_hParser, muIdentFun_t); - -// Error handling -API_EXPORT(muBool_t) mupError(muParserHandle_t a_hParser); -API_EXPORT(void) mupErrorReset(muParserHandle_t a_hParser); -API_EXPORT(void) mupSetErrorHandler(muParserHandle_t a_hParser, muErrorHandler_t a_pErrHandler); -API_EXPORT(const muChar_t*) mupGetErrorMsg(muParserHandle_t a_hParser); -API_EXPORT(muInt_t) mupGetErrorCode(muParserHandle_t a_hParser); -API_EXPORT(muInt_t) mupGetErrorPos(muParserHandle_t a_hParser); -API_EXPORT(const muChar_t*) mupGetErrorToken(muParserHandle_t a_hParser); -//API_EXPORT(const muChar_t*) mupGetErrorExpr(muParserHandle_t a_hParser); - -// This is used for .NET only. It creates a new variable allowing the dll to -// manage the variable rather than the .NET garbage collector. -API_EXPORT(muFloat_t*) mupCreateVar(); -API_EXPORT(void) mupReleaseVar(muFloat_t*); - -#ifdef __cplusplus -} -#endif - -#endif // include guard diff --git a/bundled/muparser_v2_2_3/src/muParserDLL.cpp b/bundled/muparser_v2_2_3/src/muParserDLL.cpp deleted file mode 100644 index 619ed3e3ce..0000000000 --- a/bundled/muparser_v2_2_3/src/muParserDLL.cpp +++ /dev/null @@ -1,1060 +0,0 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2004-2011 Ingo Berg - - Permission is hereby granted, free of charge, to any person obtaining a copy of this - software and associated documentation files (the "Software"), to deal in the Software - without restriction, including without limitation the rights to use, copy, modify, - merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all copies or - substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#if defined(MUPARSER_DLL) - -#if defined(_WIN32) - #define WIN32_LEAN_AND_MEAN - #include -#endif - -#include "muParserDLL.h" -#include "muParser.h" -#include "muParserInt.h" -#include "muParserError.h" - - -#define MU_TRY \ - try \ - { - -#define MU_CATCH \ - } \ - catch(muError_t &e) \ - { \ - ParserTag *pTag = static_cast(a_hParser); \ - pTag->exc = e; \ - pTag->bError = true; \ - if (pTag->errHandler) \ - (pTag->errHandler)(a_hParser); \ - } \ - catch(...) \ - { \ - ParserTag *pTag = static_cast(a_hParser); \ - pTag->exc = muError_t(mu::ecINTERNAL_ERROR); \ - pTag->bError = true; \ - if (pTag->errHandler) \ - (pTag->errHandler)(a_hParser); \ - } - -/** \file - \brief This file contains the implementation of the DLL interface of muparser. -*/ - -//--------------------------------------------------------------------------- -// private types -typedef mu::ParserBase::exception_type muError_t; -typedef mu::ParserBase muParser_t; - -int g_nBulkSize; - -//--------------------------------------------------------------------------- -class ParserTag -{ -public: - ParserTag(int nType) - :pParser( (nType==muBASETYPE_FLOAT) ? (mu::ParserBase*)new mu::Parser() : - (nType==muBASETYPE_INT) ? (mu::ParserBase*)new mu::ParserInt() : NULL) - ,exc() - ,errHandler(NULL) - ,bError(false) - ,m_nParserType(nType) - {} - - ~ParserTag() - { - delete pParser; - } - - mu::ParserBase *pParser; - mu::ParserBase::exception_type exc; - muErrorHandler_t errHandler; - bool bError; - -private: - ParserTag(const ParserTag &ref); - ParserTag& operator=(const ParserTag &ref); - - int m_nParserType; -}; - -static muChar_t s_tmpOutBuf[2048]; - -//--------------------------------------------------------------------------- -// -// -// unexported functions -// -// -//--------------------------------------------------------------------------- - -//--------------------------------------------------------------------------- -muParser_t* AsParser(muParserHandle_t a_hParser) -{ - return static_cast(a_hParser)->pParser; -} - -//--------------------------------------------------------------------------- -ParserTag* AsParserTag(muParserHandle_t a_hParser) -{ - return static_cast(a_hParser); -} - -//--------------------------------------------------------------------------- -#if defined(_WIN32) - #define _CRT_SECURE_NO_DEPRECATE - - BOOL APIENTRY DllMain( HANDLE /*hModule*/, - DWORD ul_reason_for_call, - LPVOID /*lpReserved*/ ) - { - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - break; - - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - - return TRUE; - } - -#endif - -//--------------------------------------------------------------------------- -// -// -// exported functions -// -// -//--------------------------------------------------------------------------- - -API_EXPORT(void) mupSetVarFactory(muParserHandle_t a_hParser, muFacFun_t a_pFactory, void *pUserData) -{ - MU_TRY - muParser_t* p(AsParser(a_hParser)); - p->SetVarFactory(a_pFactory, pUserData); - MU_CATCH -} - -//--------------------------------------------------------------------------- -/** \brief Create a new Parser instance and return its handle. -*/ -API_EXPORT(muParserHandle_t) mupCreate(int nBaseType) -{ - switch(nBaseType) - { - case muBASETYPE_FLOAT: return (void*)(new ParserTag(muBASETYPE_FLOAT)); - case muBASETYPE_INT: return (void*)(new ParserTag(muBASETYPE_INT)); - default: return NULL; - } -} - -//--------------------------------------------------------------------------- -/** \brief Release the parser instance related with a parser handle. -*/ -API_EXPORT(void) mupRelease(muParserHandle_t a_hParser) -{ - MU_TRY - ParserTag* p = static_cast(a_hParser); - delete p; - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(const muChar_t*) mupGetVersion(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - sprintf(s_tmpOutBuf, "%s", p->GetVersion().c_str()); - return s_tmpOutBuf; - MU_CATCH - - return ""; -} - -//--------------------------------------------------------------------------- -/** \brief Evaluate the expression. -*/ -API_EXPORT(muFloat_t) mupEval(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - return p->Eval(); - MU_CATCH - - return 0; -} - -//--------------------------------------------------------------------------- -API_EXPORT(muFloat_t*) mupEvalMulti(muParserHandle_t a_hParser, int *nNum) -{ - MU_TRY - assert(nNum!=NULL); - - muParser_t* const p(AsParser(a_hParser)); - return p->Eval(*nNum); - MU_CATCH - - return 0; -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupEvalBulk(muParserHandle_t a_hParser, muFloat_t *a_res, int nSize) -{ - MU_TRY - muParser_t* p(AsParser(a_hParser)); - p->Eval(a_res, nSize); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupSetExpr(muParserHandle_t a_hParser, const muChar_t* a_szExpr) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->SetExpr(a_szExpr); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupRemoveVar(muParserHandle_t a_hParser, const muChar_t* a_szName) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->RemoveVar( a_szName ); - MU_CATCH -} - -//--------------------------------------------------------------------------- -/** \brief Release all parser variables. - \param a_hParser Handle to the parser instance. -*/ -API_EXPORT(void) mupClearVar(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->ClearVar(); - MU_CATCH -} - -//--------------------------------------------------------------------------- -/** \brief Release all parser variables. - \param a_hParser Handle to the parser instance. -*/ -API_EXPORT(void) mupClearConst(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->ClearConst(); - MU_CATCH -} - -//--------------------------------------------------------------------------- -/** \brief Clear all user defined operators. - \param a_hParser Handle to the parser instance. -*/ -API_EXPORT(void) mupClearOprt(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->ClearOprt(); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupClearFun(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->ClearFun(); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun0( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun0_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun1( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun1_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun2( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun2_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun3( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun3_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun4( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun4_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun5( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun5_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun6( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun6_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun7( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun7_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun8( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun8_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun9( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun9_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineFun10( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFun10_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun0(muParserHandle_t a_hParser, - const muChar_t* a_szName, - muBulkFun0_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun1(muParserHandle_t a_hParser, - const muChar_t* a_szName, - muBulkFun1_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun2(muParserHandle_t a_hParser, - const muChar_t* a_szName, - muBulkFun2_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun3(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun3_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun4(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun4_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun5(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun5_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun6(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun6_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun7(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun7_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun8(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun8_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun9(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun9_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkFun10( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muBulkFun10_t a_pFun) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineStrFun1( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muStrFun1_t a_pFun ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineStrFun2( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muStrFun2_t a_pFun ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineStrFun3( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muStrFun3_t a_pFun ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, false); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineMultFun( muParserHandle_t a_hParser, - const muChar_t *a_szName, - muMultFun_t a_pFun, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineFun(a_szName, a_pFun, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineOprt( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun2_t a_pFun, - muInt_t a_nPrec, - muInt_t a_nOprtAsct, - muBool_t a_bAllowOpt) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineOprt(a_szName, - a_pFun, - a_nPrec, - (mu::EOprtAssociativity)a_nOprtAsct, - a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineVar(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFloat_t *a_pVar) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineVar(a_szName, a_pVar); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineBulkVar(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFloat_t *a_pVar) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineVar(a_szName, a_pVar); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineConst(muParserHandle_t a_hParser, - const muChar_t *a_szName, - muFloat_t a_fVal) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineConst(a_szName, a_fVal); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineStrConst(muParserHandle_t a_hParser, - const muChar_t *a_szName, - const muChar_t *a_szVal) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineStrConst(a_szName, a_szVal); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(const muChar_t*) mupGetExpr(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - - // C# explodes when pMsg is returned directly. For some reason it can't access - // the memory where the message lies directly. - sprintf(s_tmpOutBuf, "%s", p->GetExpr().c_str()); - return s_tmpOutBuf; - - MU_CATCH - - return ""; -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefinePostfixOprt( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun1_t a_pOprt, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefinePostfixOprt(a_szName, a_pOprt, a_bAllowOpt!=0); - MU_CATCH -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineInfixOprt( muParserHandle_t a_hParser, - const muChar_t* a_szName, - muFun1_t a_pOprt, - muBool_t a_bAllowOpt ) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->DefineInfixOprt(a_szName, a_pOprt, a_bAllowOpt!=0); - MU_CATCH -} - -// Define character sets for identifiers -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineNameChars( muParserHandle_t a_hParser, - const muChar_t* a_szCharset ) -{ - muParser_t* const p(AsParser(a_hParser)); - p->DefineNameChars(a_szCharset); -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineOprtChars( muParserHandle_t a_hParser, - const muChar_t* a_szCharset ) -{ - muParser_t* const p(AsParser(a_hParser)); - p->DefineOprtChars(a_szCharset); -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupDefineInfixOprtChars(muParserHandle_t a_hParser, - const muChar_t *a_szCharset) -{ - muParser_t* const p(AsParser(a_hParser)); - p->DefineInfixOprtChars(a_szCharset); -} - -//--------------------------------------------------------------------------- -/** \brief Get the number of variables defined in the parser. - \param a_hParser [in] Must be a valid parser handle. - \return The number of used variables. - \sa mupGetExprVar -*/ -API_EXPORT(int) mupGetVarNum(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - const mu::varmap_type VarMap = p->GetVar(); - return (int)VarMap.size(); - MU_CATCH - - return 0; // never reached -} - -//--------------------------------------------------------------------------- -/** \brief Return a variable that is used in an expression. - \param a_hParser [in] A valid parser handle. - \param a_iVar [in] The index of the variable to return. - \param a_szName [out] Pointer to the variable name. - \param a_pVar [out] Pointer to the variable. - \throw nothrow - - Prior to calling this function call mupGetExprVarNum in order to get the - number of variables in the expression. If the parameter a_iVar is greater - than the number of variables both a_szName and a_pVar will be set to zero. - As a side effect this function will trigger an internal calculation of the - expression undefined variables will be set to zero during this calculation. - During the calculation user defined callback functions present in the expression - will be called, this is unavoidable. -*/ -API_EXPORT(void) mupGetVar(muParserHandle_t a_hParser, - unsigned a_iVar, - const muChar_t **a_szName, - muFloat_t **a_pVar) -{ - // A static buffer is needed for the name since i cant return the - // pointer from the map. - static muChar_t szName[1024]; - - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - const mu::varmap_type VarMap = p->GetVar(); - - if (a_iVar>=VarMap.size()) - { - *a_szName = 0; - *a_pVar = 0; - return; - } - mu::varmap_type::const_iterator item; - - item = VarMap.begin(); - for (unsigned i=0; ifirst.c_str(), sizeof(szName)); - szName[sizeof(szName)-1] = 0; - - *a_szName = &szName[0]; - *a_pVar = item->second; - return; - - MU_CATCH - - *a_szName = 0; - *a_pVar = 0; -} - -//--------------------------------------------------------------------------- -/** \brief Get the number of variables used in the expression currently set in the parser. - \param a_hParser [in] Must be a valid parser handle. - \return The number of used variables. - \sa mupGetExprVar -*/ -API_EXPORT(int) mupGetExprVarNum(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - const mu::varmap_type VarMap = p->GetUsedVar(); - return (int)VarMap.size(); - MU_CATCH - - return 0; // never reached -} - -//--------------------------------------------------------------------------- -/** \brief Return a variable that is used in an expression. - - Prior to calling this function call mupGetExprVarNum in order to get the - number of variables in the expression. If the parameter a_iVar is greater - than the number of variables both a_szName and a_pVar will be set to zero. - As a side effect this function will trigger an internal calculation of the - expression undefined variables will be set to zero during this calculation. - During the calculation user defined callback functions present in the expression - will be called, this is unavoidable. - - \param a_hParser [in] A valid parser handle. - \param a_iVar [in] The index of the variable to return. - \param a_szName [out] Pointer to the variable name. - \param a_pVar [out] Pointer to the variable. - \throw nothrow -*/ -API_EXPORT(void) mupGetExprVar(muParserHandle_t a_hParser, - unsigned a_iVar, - const muChar_t **a_szName, - muFloat_t **a_pVar) -{ - // A static buffer is needed for the name since i cant return the - // pointer from the map. - static muChar_t szName[1024]; - - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - const mu::varmap_type VarMap = p->GetUsedVar(); - - if (a_iVar>=VarMap.size()) - { - *a_szName = 0; - *a_pVar = 0; - return; - } - mu::varmap_type::const_iterator item; - - item = VarMap.begin(); - for (unsigned i=0; ifirst.c_str(), sizeof(szName)); - szName[sizeof(szName)-1] = 0; - - *a_szName = &szName[0]; - *a_pVar = item->second; - return; - - MU_CATCH - - *a_szName = 0; - *a_pVar = 0; -} - -//--------------------------------------------------------------------------- -/** \brief Return the number of constants defined in a parser. */ -API_EXPORT(int) mupGetConstNum(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - const mu::valmap_type ValMap = p->GetConst(); - return (int)ValMap.size(); - MU_CATCH - - return 0; // never reached -} - -//----------------------------------------------------------------------------------------------------- -API_EXPORT(void) mupSetArgSep(muParserHandle_t a_hParser, const muChar_t cArgSep) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->SetArgSep(cArgSep); - MU_CATCH -} - -//----------------------------------------------------------------------------------------------------- -API_EXPORT(void) mupResetLocale(muParserHandle_t a_hParser) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->ResetLocale(); - MU_CATCH -} - -//----------------------------------------------------------------------------------------------------- -API_EXPORT(void) mupSetDecSep(muParserHandle_t a_hParser, const muChar_t cDecSep) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->SetDecSep(cDecSep); - MU_CATCH -} - -//----------------------------------------------------------------------------------------------------- -API_EXPORT(void) mupSetThousandsSep(muParserHandle_t a_hParser, const muChar_t cThousandsSep) -{ - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - p->SetThousandsSep(cThousandsSep); - MU_CATCH -} - -//--------------------------------------------------------------------------- -/** \brief Retrieve name and value of a single parser constant. - \param a_hParser [in] a valid parser handle - \param a_iVar [in] Index of the constant to query - \param a_pszName [out] pointer to a null terminated string with the constant name - \param [out] The constant value -*/ -API_EXPORT(void) mupGetConst( muParserHandle_t a_hParser, - unsigned a_iVar, - const muChar_t **a_pszName, - muFloat_t *a_fVal) -{ - // A static buffer is needed for the name since i cant return the - // pointer from the map. - static muChar_t szName[1024]; - - MU_TRY - muParser_t* const p(AsParser(a_hParser)); - const mu::valmap_type ValMap = p->GetConst(); - - if (a_iVar>=ValMap.size()) - { - *a_pszName = 0; - *a_fVal = 0; - return; - } - - mu::valmap_type::const_iterator item; - item = ValMap.begin(); - for (unsigned i=0; ifirst.c_str(), sizeof(szName)); - szName[sizeof(szName)-1] = 0; - - *a_pszName = &szName[0]; - *a_fVal = item->second; - return; - - MU_CATCH - - *a_pszName = 0; - *a_fVal = 0; -} - -//--------------------------------------------------------------------------- -/** \brief Add a custom value regognition function. -*/ -API_EXPORT(void) mupAddValIdent(muParserHandle_t a_hParser, - muIdentFun_t a_pFun) -{ - MU_TRY - muParser_t* p(AsParser(a_hParser)); - p->AddValIdent(a_pFun); - MU_CATCH -} - -//--------------------------------------------------------------------------- -/** \brief Query if an error occured. - - After querying the internal error bit will be reset. So a consecutive call - will return false. -*/ -API_EXPORT(muBool_t) mupError(muParserHandle_t a_hParser) -{ - bool bError( AsParserTag(a_hParser)->bError ); - AsParserTag(a_hParser)->bError = false; - return bError; -} - -//--------------------------------------------------------------------------- -/** \brief Reset the internal error flag. -*/ -API_EXPORT(void) mupErrorReset(muParserHandle_t a_hParser) -{ - AsParserTag(a_hParser)->bError = false; -} - -//--------------------------------------------------------------------------- -API_EXPORT(void) mupSetErrorHandler(muParserHandle_t a_hParser, muErrorHandler_t a_pHandler) -{ - AsParserTag(a_hParser)->errHandler = a_pHandler; -} - -//--------------------------------------------------------------------------- -/** \brief Return the message associated with the last error. -*/ -API_EXPORT(const muChar_t*) mupGetErrorMsg(muParserHandle_t a_hParser) -{ - ParserTag* const p(AsParserTag(a_hParser)); - const muChar_t *pMsg = p->exc.GetMsg().c_str(); - - // C# explodes when pMsg is returned directly. For some reason it can't access - // the memory where the message lies directly. - sprintf(s_tmpOutBuf, "%s", pMsg); - return s_tmpOutBuf; -} - -//--------------------------------------------------------------------------- -/** \brief Return the message associated with the last error. -*/ -API_EXPORT(const muChar_t*) mupGetErrorToken(muParserHandle_t a_hParser) -{ - ParserTag* const p(AsParserTag(a_hParser)); - const muChar_t *pToken = p->exc.GetToken().c_str(); - - // C# explodes when pMsg is returned directly. For some reason it can't access - // the memory where the message lies directly. - sprintf(s_tmpOutBuf, "%s", pToken); - return s_tmpOutBuf; -} - -//--------------------------------------------------------------------------- -/** \brief Return the code associated with the last error. -*/ -API_EXPORT(int) mupGetErrorCode(muParserHandle_t a_hParser) -{ - return AsParserTag(a_hParser)->exc.GetCode(); -} - -//--------------------------------------------------------------------------- -/** \brief Return the postion associated with the last error. */ -API_EXPORT(int) mupGetErrorPos(muParserHandle_t a_hParser) -{ - return (int)AsParserTag(a_hParser)->exc.GetPos(); -} - -////----------------------------------------------------------------------------------------------------- -//API_EXPORT(const muChar_t*) mupGetErrorExpr(muParserHandle_t a_hParser) -//{ -// return AsParserTag(a_hParser)->exc.GetExpr().c_str(); -//} - -//----------------------------------------------------------------------------------------------------- -API_EXPORT(muFloat_t*) mupCreateVar() -{ - return new muFloat_t(0); -} - -//----------------------------------------------------------------------------------------------------- -API_EXPORT(void) mupReleaseVar(muFloat_t *ptr) -{ - delete ptr; -} - -#endif // MUPARSER_DLL diff --git a/bundled/muparser_v2_2_3/CMakeLists.txt b/bundled/muparser_v2_2_4/CMakeLists.txt similarity index 100% rename from bundled/muparser_v2_2_3/CMakeLists.txt rename to bundled/muparser_v2_2_4/CMakeLists.txt diff --git a/bundled/muparser_v2_2_3/Changes.txt b/bundled/muparser_v2_2_4/Changes.txt similarity index 94% rename from bundled/muparser_v2_2_3/Changes.txt rename to bundled/muparser_v2_2_4/Changes.txt index 26d40ae502..08d4dc7b3b 100644 --- a/bundled/muparser_v2_2_3/Changes.txt +++ b/bundled/muparser_v2_2_4/Changes.txt @@ -9,18 +9,34 @@ # \/ \/ \/ \/ # # Fast math parser Library # # # -# Copyright (C) 2013 Ingo Berg # +# Copyright (C) 2014 Ingo Berg # # # # Web: muparser.beltoforion.de # # e-mail: muparser@beltoforion.de # # # # # ####################################################################### - + History: -------- +Rev 2.2.4: 02.10.2014 +--------------------- + Changes: + * explicit positive sign allowed + + Bugfixes: + * Fix for Issue 6 (https://code.google.com/p/muparser/issues/detail?id=6) + * String constants did not work properly. Using more than a single one + was impossible. + * Project Files for VS2008 and VS2010 removed from the repository + * Fix for Issue 4 (https://code.google.com/p/muparser/issues/detail?id=4) + * Fix for VS2013 64 bit build option + * return type of ParserError::GetPos changed to int + * OpenMP support enabled in the VS2013 project files and precompiled windows DLL's + * Bulkmode did not evaluate properly if "=" and "," operator was used in the expression + Rev 2.2.3: 22.12.2012 --------------------- diff --git a/bundled/muparser_v2_2_3/License.txt b/bundled/muparser_v2_2_4/License.txt similarity index 100% rename from bundled/muparser_v2_2_3/License.txt rename to bundled/muparser_v2_2_4/License.txt diff --git a/bundled/muparser_v2_2_3/include/muParser.h b/bundled/muparser_v2_2_4/include/muParser.h similarity index 95% rename from bundled/muparser_v2_2_3/include/muParser.h rename to bundled/muparser_v2_2_4/include/muParser.h index 9e7bb6ffe9..39fe137fe7 100644 --- a/bundled/muparser_v2_2_3/include/muParser.h +++ b/bundled/muparser_v2_2_4/include/muParser.h @@ -45,7 +45,7 @@ namespace mu (C) 2011 Ingo Berg
- muparser(at)gmx.de + muparser(at)beltoforion.de
*/ /* final */ class Parser : public ParserBase @@ -99,6 +99,7 @@ namespace mu // Prefix operators // !!! Unary Minus is a MUST if you want to use negative signs !!! static value_type UnaryMinus(value_type); + static value_type UnaryPlus(value_type); // Functions with variable number of arguments static value_type Sum(const value_type*, int); // sum diff --git a/bundled/muparser_v2_2_3/include/muParserBase.h b/bundled/muparser_v2_2_4/include/muParserBase.h similarity index 94% rename from bundled/muparser_v2_2_3/include/muParserBase.h rename to bundled/muparser_v2_2_4/include/muParserBase.h index a189a26a24..beb15bb198 100644 --- a/bundled/muparser_v2_2_3/include/muParserBase.h +++ b/bundled/muparser_v2_2_4/include/muParserBase.h @@ -32,6 +32,7 @@ #include #include #include +#include //--- Parser includes -------------------------------------------------------------------------- #include "muParserDef.h" @@ -85,7 +86,7 @@ private: typedef ParserToken token_type; /** \brief Maximum number of threads spawned by OpenMP when using the bulk mode. */ - static const int s_MaxNumOpenMPThreads = 4; + static const int s_MaxNumOpenMPThreads = 16; public: @@ -220,7 +221,12 @@ private: virtual std::string do_grouping() const { - return std::string(1, m_nGroup); + // fix for issue 4: https://code.google.com/p/muparser/issues/detail?id=4 + // courtesy of Jens Bartsch + // original code: + // return std::string(1, (char)m_nGroup); + // new code: + return std::string(1, (char)(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX)); } private: diff --git a/bundled/muparser_v2_2_3/include/muParserBytecode.h b/bundled/muparser_v2_2_4/include/muParserBytecode.h similarity index 94% rename from bundled/muparser_v2_2_3/include/muParserBytecode.h rename to bundled/muparser_v2_2_4/include/muParserBytecode.h index 7ca0146fcc..39ab39d52d 100644 --- a/bundled/muparser_v2_2_3/include/muParserBytecode.h +++ b/bundled/muparser_v2_2_4/include/muParserBytecode.h @@ -46,16 +46,16 @@ namespace mu ECmdCode Cmd; int StackPos; - union u + union { - struct sVal + struct //SValData { value_type *ptr; value_type data; value_type data2; } Val; - struct sFun + struct //SFunData { // Note: generic_fun_type is merely a placeholder. The real type could be // anything between gun_type1 and fun_type9. I can't use a void @@ -66,12 +66,12 @@ namespace mu int idx; } Fun; - struct sOprt + struct //SOprtData { value_type *ptr; int offset; } Oprt; - } u; + }; }; diff --git a/bundled/muparser_v2_2_3/include/muParserCallback.h b/bundled/muparser_v2_2_4/include/muParserCallback.h similarity index 100% rename from bundled/muparser_v2_2_3/include/muParserCallback.h rename to bundled/muparser_v2_2_4/include/muParserCallback.h diff --git a/bundled/muparser_v2_2_3/include/muParserDef.h b/bundled/muparser_v2_2_4/include/muParserDef.h similarity index 96% rename from bundled/muparser_v2_2_3/include/muParserDef.h rename to bundled/muparser_v2_2_4/include/muParserDef.h index 54f4559314..5842921781 100644 --- a/bundled/muparser_v2_2_3/include/muParserDef.h +++ b/bundled/muparser_v2_2_4/include/muParserDef.h @@ -5,7 +5,7 @@ | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| \/ \/ \/ \/ - Copyright (C) 2013 Ingo Berg + Copyright (C) 2014 Ingo Berg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software @@ -36,8 +36,8 @@ \brief This file contains standard definitions used by the parser. */ -#define MUP_VERSION _T("2.2.3") -#define MUP_VERSION_DATE _T("20121222; SF") +#define MUP_VERSION _T("2.2.4") +#define MUP_VERSION_DATE _T("20141210; GC") #define MUP_CHARS _T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") diff --git a/bundled/muparser_v2_2_3/include/muParserError.h b/bundled/muparser_v2_2_4/include/muParserError.h similarity index 95% rename from bundled/muparser_v2_2_3/include/muParserError.h rename to bundled/muparser_v2_2_4/include/muParserError.h index 60244ac0aa..7f88e99192 100644 --- a/bundled/muparser_v2_2_3/include/muParserError.h +++ b/bundled/muparser_v2_2_4/include/muParserError.h @@ -87,8 +87,10 @@ enum EErrorCodes ecMISSING_ELSE_CLAUSE = 33, ecMISPLACED_COLON = 34, + ecUNREASONABLE_NUMBER_OF_COMPUTATIONS = 35, + // internal errors - ecINTERNAL_ERROR = 35, ///< Internal error of any kind. + ecINTERNAL_ERROR = 36, ///< Internal error of any kind. // The last two are special entries ecCOUNT, ///< This is no error code, It just stores just the total number of error codes @@ -155,7 +157,7 @@ public: void SetFormula(const string_type &a_strFormula); const string_type& GetExpr() const; const string_type& GetMsg() const; - std::size_t GetPos() const; + int GetPos() const; const string_type& GetToken() const; EErrorCodes GetCode() const; diff --git a/bundled/muparser_v2_2_3/include/muParserFixes.h b/bundled/muparser_v2_2_4/include/muParserFixes.h similarity index 100% rename from bundled/muparser_v2_2_3/include/muParserFixes.h rename to bundled/muparser_v2_2_4/include/muParserFixes.h diff --git a/bundled/muparser_v2_2_3/include/muParserInt.h b/bundled/muparser_v2_2_4/include/muParserInt.h similarity index 91% rename from bundled/muparser_v2_2_3/include/muParserInt.h rename to bundled/muparser_v2_2_4/include/muParserInt.h index 4d11afbe79..136de33971 100644 --- a/bundled/muparser_v2_2_3/include/muParserInt.h +++ b/bundled/muparser_v2_2_4/include/muParserInt.h @@ -110,7 +110,12 @@ private: virtual std::string do_grouping() const { - return std::string(1, m_nGroup); + // fix for issue 4: https://code.google.com/p/muparser/issues/detail?id=4 + // courtesy of Jens Bartsch + // original code: + // return std::string(1, (char)m_nGroup); + // new code: + return std::string(1, (char)(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX)); } private: @@ -124,7 +129,7 @@ public: ParserInt(); virtual void InitFun(); - virtual void InitOprt(); + virtual void InitOprt(); virtual void InitConst(); virtual void InitCharSets(); }; diff --git a/bundled/muparser_v2_2_3/include/muParserStack.h b/bundled/muparser_v2_2_4/include/muParserStack.h similarity index 96% rename from bundled/muparser_v2_2_3/include/muParserStack.h rename to bundled/muparser_v2_2_4/include/muParserStack.h index c97e09299e..f8437e30e4 100644 --- a/bundled/muparser_v2_2_3/include/muParserStack.h +++ b/bundled/muparser_v2_2_4/include/muParserStack.h @@ -108,7 +108,7 @@ namespace mu /** \brief Returns true if stack is empty false otherwise. */ bool empty() const { - return m_Stack.size()==0; + return m_Stack.empty(); } /** \brief Return reference to the top object in the stack. diff --git a/bundled/muparser_v2_2_3/include/muParserTemplateMagic.h b/bundled/muparser_v2_2_4/include/muParserTemplateMagic.h similarity index 54% rename from bundled/muparser_v2_2_3/include/muParserTemplateMagic.h rename to bundled/muparser_v2_2_4/include/muParserTemplateMagic.h index 8a9b7a6ba3..1626caea4e 100644 --- a/bundled/muparser_v2_2_3/include/muParserTemplateMagic.h +++ b/bundled/muparser_v2_2_4/include/muParserTemplateMagic.h @@ -108,43 +108,6 @@ namespace mu static T Sign(T v) { return (T)((v<0) ? -1 : (v>0) ? 1 : 0); } static T Pow(T v1, T v2) { return std::pow(v1, v2); } }; - - // Create (mostly) dummy math function definitions for integer types. They are mostly - // empty since they are not applicable for integer values. -#define MAKE_MATH_DUMMY(TYPE) \ - template<> \ - struct MathImpl \ - { \ - static TYPE Sin(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Cos(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Tan(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE ASin(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE ACos(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE ATan(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE ATan2(TYPE, TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Sinh(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Cosh(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Tanh(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE ASinh(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE ACosh(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE ATanh(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Log(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Log2(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Log10(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Exp(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Abs(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Sqrt(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Rint(TYPE) { throw ParserError(_T("unimplemented function.")); } \ - static TYPE Sign(TYPE v) { return (TYPE)((v<0) ? -1 : (v>0) ? 1 : 0); } \ - static TYPE Pow(TYPE v1, TYPE v2) { return (TYPE)std::pow((double)v1, (double)v2); } \ - }; - - MAKE_MATH_DUMMY(char) - MAKE_MATH_DUMMY(short) - MAKE_MATH_DUMMY(int) - MAKE_MATH_DUMMY(long) - -#undef MAKE_MATH_DUMMY } #endif diff --git a/bundled/muparser_v2_2_3/include/muParserTest.h b/bundled/muparser_v2_2_4/include/muParserTest.h similarity index 85% rename from bundled/muparser_v2_2_3/include/muParserTest.h rename to bundled/muparser_v2_2_4/include/muParserTest.h index cd2b2b439b..c02b0218a9 100644 --- a/bundled/muparser_v2_2_3/include/muParserTest.h +++ b/bundled/muparser_v2_2_4/include/muParserTest.h @@ -66,11 +66,11 @@ namespace mu static value_type f3of4(value_type , value_type, value_type v, value_type ) {return v;} static value_type f4of4(value_type , value_type, value_type , value_type v) {return v;} - static value_type f1of5(value_type v, value_type, value_type , value_type , value_type ) { return v; } - static value_type f2of5(value_type , value_type v, value_type , value_type , value_type ) { return v; } - static value_type f3of5(value_type , value_type, value_type v, value_type , value_type ) { return v; } - static value_type f4of5(value_type , value_type, value_type , value_type v, value_type ) { return v; } - static value_type f5of5(value_type , value_type, value_type , value_type , value_type v) { return v; } + static value_type f1of5(value_type v, value_type, value_type , value_type , value_type ) { return v; } + static value_type f2of5(value_type , value_type v, value_type , value_type , value_type ) { return v; } + static value_type f3of5(value_type , value_type, value_type v, value_type , value_type ) { return v; } + static value_type f4of5(value_type , value_type, value_type , value_type v, value_type ) { return v; } + static value_type f5of5(value_type , value_type, value_type , value_type , value_type v) { return v; } static value_type Min(value_type a_fVal1, value_type a_fVal2) { return (a_fVal1a_fVal2) ? a_fVal1 : a_fVal2; } @@ -166,17 +166,18 @@ namespace mu static int IsHexVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal); int TestNames(); - int TestSyntax(); - int TestMultiArg(); - int TestPostFix(); - int TestExpression(); - int TestInfixOprt(); - int TestBinOprt(); - int TestVarConst(); - int TestInterface(); - int TestException(); + int TestSyntax(); + int TestMultiArg(); + int TestPostFix(); + int TestExpression(); + int TestInfixOprt(); + int TestBinOprt(); + int TestVarConst(); + int TestInterface(); + int TestException(); int TestStrArg(); int TestIfThenElse(); + int TestBulkMode(); void Abort() const; @@ -201,6 +202,9 @@ namespace mu // Test Int Parser int EqnTestInt(const string_type& a_str, double a_fRes, bool a_fPass); + + // Test Bulkmode + int EqnTestBulk(const string_type& a_str, double a_fRes[4], bool a_fPass); }; } // namespace Test } // namespace mu diff --git a/bundled/muparser_v2_2_3/include/muParserToken.h b/bundled/muparser_v2_2_4/include/muParserToken.h similarity index 96% rename from bundled/muparser_v2_2_3/include/muParserToken.h rename to bundled/muparser_v2_2_4/include/muParserToken.h index 326d71735e..fc91d7818c 100644 --- a/bundled/muparser_v2_2_3/include/muParserToken.h +++ b/bundled/muparser_v2_2_4/include/muParserToken.h @@ -86,6 +86,8 @@ namespace mu ,m_pTok(0) ,m_iIdx(-1) ,m_strTok() + ,m_strVal() + ,m_fVal(0) ,m_pCallback() {} diff --git a/bundled/muparser_v2_2_3/include/muParserTokenReader.h b/bundled/muparser_v2_2_4/include/muParserTokenReader.h similarity index 100% rename from bundled/muparser_v2_2_3/include/muParserTokenReader.h rename to bundled/muparser_v2_2_4/include/muParserTokenReader.h diff --git a/bundled/muparser_v2_2_3/src/muParser.cpp b/bundled/muparser_v2_2_4/src/muParser.cpp similarity index 94% rename from bundled/muparser_v2_2_3/src/muParser.cpp rename to bundled/muparser_v2_2_4/src/muParser.cpp index 0eecd98fa0..eaa84493ad 100644 --- a/bundled/muparser_v2_2_3/src/muParser.cpp +++ b/bundled/muparser_v2_2_4/src/muParser.cpp @@ -128,6 +128,16 @@ namespace mu return -v; } + //--------------------------------------------------------------------------- + /** \brief Callback for the unary minus operator. + \param v The value to negate + \return -v + */ + value_type Parser::UnaryPlus(value_type v) + { + return v; + } + //--------------------------------------------------------------------------- /** \brief Callback for adding multiple values. \param [in] a_afArg Vector with the function arguments @@ -284,7 +294,7 @@ namespace mu // Logarithm functions DefineFun(_T("log2"), Log2); DefineFun(_T("log10"), Log10); - DefineFun(_T("log"), Log10); + DefineFun(_T("log"), Ln); DefineFun(_T("ln"), Ln); // misc DefineFun(_T("exp"), Exp); @@ -320,6 +330,7 @@ namespace mu void Parser::InitOprt() { DefineInfixOprt(_T("-"), UnaryMinus); + DefineInfixOprt(_T("+"), UnaryPlus); } //--------------------------------------------------------------------------- diff --git a/bundled/muparser_v2_2_3/src/muParserBase.cpp b/bundled/muparser_v2_2_4/src/muParserBase.cpp similarity index 89% rename from bundled/muparser_v2_2_3/src/muParserBase.cpp rename to bundled/muparser_v2_2_4/src/muParserBase.cpp index dd28a77088..5bd0d2ea7f 100644 --- a/bundled/muparser_v2_2_3/src/muParserBase.cpp +++ b/bundled/muparser_v2_2_4/src/muParserBase.cpp @@ -28,6 +28,7 @@ //--- Standard includes ------------------------------------------------------------------------ #include +#include #include #include #include @@ -265,8 +266,6 @@ namespace mu */ string_type ParserBase::GetVersion(EParserVersionInfo eInfo) const { - string_type sCompileTimeSettings; - stringstream_type ss; ss << MUP_VERSION; @@ -579,8 +578,8 @@ namespace mu CheckName(a_strName, ValidNameChars()); - m_vStringVarBuf.push_back(a_strVal); // Store variable string in internal buffer - m_StrVarDef[a_strName] = m_vStringBuf.size(); // bind buffer index to variable name + m_vStringVarBuf.push_back(a_strVal); // Store variable string in internal buffer + m_StrVarDef[a_strName] = m_vStringVarBuf.size()-1; // bind buffer index to variable name ReInit(); } @@ -695,13 +694,13 @@ namespace mu m_pParseFormula = &ParserBase::ParseString; m_pTokenReader->IgnoreUndefVar(false); } - catch(exception_type &e) + catch(exception_type & /*e*/) { // Make sure to stay in string parse mode, dont call ReInit() // because it deletes the array with the used variables m_pParseFormula = &ParserBase::ParseString; m_pTokenReader->IgnoreUndefVar(false); - throw e; + throw; } return m_pTokenReader->GetUsedVar(); @@ -1043,7 +1042,12 @@ namespace mu case cmLOR: --sidx; Stack[sidx] = Stack[sidx] || Stack[sidx+1]; continue; case cmASSIGN: - --sidx; Stack[sidx] = *pTok->u.Oprt.ptr = Stack[sidx+1]; continue; + // Bugfix for Bulkmode: + // for details see: + // https://groups.google.com/forum/embed/?place=forum/muparser-dev&showsearch=true&showpopout=true&showtabs=false&parenturl=http://muparser.beltoforion.de/mup_forum.html&afterlogin&pli=1#!topic/muparser-dev/szgatgoHTws + --sidx; Stack[sidx] = *(pTok->Oprt.ptr + nOffset) = Stack[sidx + 1]; continue; + // original code: + //--sidx; Stack[sidx] = *pTok->Oprt.ptr = Stack[sidx+1]; continue; //case cmBO: // unused, listed for compiler optimization purposes //case cmBC: @@ -1052,11 +1056,11 @@ namespace mu case cmIF: if (Stack[sidx--]==0) - pTok += pTok->u.Oprt.offset; + pTok += pTok->Oprt.offset; continue; case cmELSE: - pTok += pTok->u.Oprt.offset; + pTok += pTok->Oprt.offset; continue; case cmENDIF: @@ -1067,49 +1071,49 @@ namespace mu // continue; // value and variable tokens - case cmVAR: Stack[++sidx] = *(pTok->u.Val.ptr + nOffset); continue; - case cmVAL: Stack[++sidx] = pTok->u.Val.data2; continue; + case cmVAR: Stack[++sidx] = *(pTok->Val.ptr + nOffset); continue; + case cmVAL: Stack[++sidx] = pTok->Val.data2; continue; - case cmVARPOW2: buf = *(pTok->u.Val.ptr + nOffset); + case cmVARPOW2: buf = *(pTok->Val.ptr + nOffset); Stack[++sidx] = buf*buf; continue; - case cmVARPOW3: buf = *(pTok->u.Val.ptr + nOffset); + case cmVARPOW3: buf = *(pTok->Val.ptr + nOffset); Stack[++sidx] = buf*buf*buf; continue; - case cmVARPOW4: buf = *(pTok->u.Val.ptr + nOffset); + case cmVARPOW4: buf = *(pTok->Val.ptr + nOffset); Stack[++sidx] = buf*buf*buf*buf; continue; - case cmVARMUL: Stack[++sidx] = *(pTok->u.Val.ptr + nOffset) * pTok->u.Val.data + pTok->u.Val.data2; + case cmVARMUL: Stack[++sidx] = *(pTok->Val.ptr + nOffset) * pTok->Val.data + pTok->Val.data2; continue; // Next is treatment of numeric functions case cmFUNC: { - int iArgCount = pTok->u.Fun.argc; + int iArgCount = pTok->Fun.argc; // switch according to argument count switch(iArgCount) { - case 0: sidx += 1; Stack[sidx] = (*(fun_type0)pTok->u.Fun.ptr)(); continue; - case 1: Stack[sidx] = (*(fun_type1)pTok->u.Fun.ptr)(Stack[sidx]); continue; - case 2: sidx -= 1; Stack[sidx] = (*(fun_type2)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1]); continue; - case 3: sidx -= 2; Stack[sidx] = (*(fun_type3)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2]); continue; - case 4: sidx -= 3; Stack[sidx] = (*(fun_type4)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3]); continue; - case 5: sidx -= 4; Stack[sidx] = (*(fun_type5)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4]); continue; - case 6: sidx -= 5; Stack[sidx] = (*(fun_type6)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5]); continue; - case 7: sidx -= 6; Stack[sidx] = (*(fun_type7)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6]); continue; - case 8: sidx -= 7; Stack[sidx] = (*(fun_type8)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7]); continue; - case 9: sidx -= 8; Stack[sidx] = (*(fun_type9)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8]); continue; - case 10:sidx -= 9; Stack[sidx] = (*(fun_type10)pTok->u.Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8], Stack[sidx+9]); continue; + case 0: sidx += 1; Stack[sidx] = (*(fun_type0)pTok->Fun.ptr)(); continue; + case 1: Stack[sidx] = (*(fun_type1)pTok->Fun.ptr)(Stack[sidx]); continue; + case 2: sidx -= 1; Stack[sidx] = (*(fun_type2)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1]); continue; + case 3: sidx -= 2; Stack[sidx] = (*(fun_type3)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2]); continue; + case 4: sidx -= 3; Stack[sidx] = (*(fun_type4)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3]); continue; + case 5: sidx -= 4; Stack[sidx] = (*(fun_type5)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4]); continue; + case 6: sidx -= 5; Stack[sidx] = (*(fun_type6)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5]); continue; + case 7: sidx -= 6; Stack[sidx] = (*(fun_type7)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6]); continue; + case 8: sidx -= 7; Stack[sidx] = (*(fun_type8)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7]); continue; + case 9: sidx -= 8; Stack[sidx] = (*(fun_type9)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8]); continue; + case 10:sidx -= 9; Stack[sidx] = (*(fun_type10)pTok->Fun.ptr)(Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8], Stack[sidx+9]); continue; default: if (iArgCount>0) // function with variable arguments store the number as a negative value Error(ecINTERNAL_ERROR, 1); sidx -= -iArgCount - 1; - Stack[sidx] =(*(multfun_type)pTok->u.Fun.ptr)(&Stack[sidx], -iArgCount); + Stack[sidx] =(*(multfun_type)pTok->Fun.ptr)(&Stack[sidx], -iArgCount); continue; } } @@ -1117,17 +1121,17 @@ namespace mu // Next is treatment of string functions case cmFUNC_STR: { - sidx -= pTok->u.Fun.argc -1; + sidx -= pTok->Fun.argc -1; // The index of the string argument in the string table - int iIdxStack = pTok->u.Fun.idx; + int iIdxStack = pTok->Fun.idx; MUP_ASSERT( iIdxStack>=0 && iIdxStack<(int)m_vStringBuf.size() ); - switch(pTok->u.Fun.argc) // switch according to argument count + switch(pTok->Fun.argc) // switch according to argument count { - case 0: Stack[sidx] = (*(strfun_type1)pTok->u.Fun.ptr)(m_vStringBuf[iIdxStack].c_str()); continue; - case 1: Stack[sidx] = (*(strfun_type2)pTok->u.Fun.ptr)(m_vStringBuf[iIdxStack].c_str(), Stack[sidx]); continue; - case 2: Stack[sidx] = (*(strfun_type3)pTok->u.Fun.ptr)(m_vStringBuf[iIdxStack].c_str(), Stack[sidx], Stack[sidx+1]); continue; + case 0: Stack[sidx] = (*(strfun_type1)pTok->Fun.ptr)(m_vStringBuf[iIdxStack].c_str()); continue; + case 1: Stack[sidx] = (*(strfun_type2)pTok->Fun.ptr)(m_vStringBuf[iIdxStack].c_str(), Stack[sidx]); continue; + case 2: Stack[sidx] = (*(strfun_type3)pTok->Fun.ptr)(m_vStringBuf[iIdxStack].c_str(), Stack[sidx], Stack[sidx+1]); continue; } continue; @@ -1135,38 +1139,28 @@ namespace mu case cmFUNC_BULK: { - int iArgCount = pTok->u.Fun.argc; + int iArgCount = pTok->Fun.argc; // switch according to argument count switch(iArgCount) { - case 0: sidx += 1; Stack[sidx] = (*(bulkfun_type0 )pTok->u.Fun.ptr)(nOffset, nThreadID); continue; - case 1: Stack[sidx] = (*(bulkfun_type1 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx]); continue; - case 2: sidx -= 1; Stack[sidx] = (*(bulkfun_type2 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1]); continue; - case 3: sidx -= 2; Stack[sidx] = (*(bulkfun_type3 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2]); continue; - case 4: sidx -= 3; Stack[sidx] = (*(bulkfun_type4 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3]); continue; - case 5: sidx -= 4; Stack[sidx] = (*(bulkfun_type5 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4]); continue; - case 6: sidx -= 5; Stack[sidx] = (*(bulkfun_type6 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5]); continue; - case 7: sidx -= 6; Stack[sidx] = (*(bulkfun_type7 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6]); continue; - case 8: sidx -= 7; Stack[sidx] = (*(bulkfun_type8 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7]); continue; - case 9: sidx -= 8; Stack[sidx] = (*(bulkfun_type9 )pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8]); continue; - case 10:sidx -= 9; Stack[sidx] = (*(bulkfun_type10)pTok->u.Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8], Stack[sidx+9]); continue; + case 0: sidx += 1; Stack[sidx] = (*(bulkfun_type0 )pTok->Fun.ptr)(nOffset, nThreadID); continue; + case 1: Stack[sidx] = (*(bulkfun_type1 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx]); continue; + case 2: sidx -= 1; Stack[sidx] = (*(bulkfun_type2 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1]); continue; + case 3: sidx -= 2; Stack[sidx] = (*(bulkfun_type3 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2]); continue; + case 4: sidx -= 3; Stack[sidx] = (*(bulkfun_type4 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3]); continue; + case 5: sidx -= 4; Stack[sidx] = (*(bulkfun_type5 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4]); continue; + case 6: sidx -= 5; Stack[sidx] = (*(bulkfun_type6 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5]); continue; + case 7: sidx -= 6; Stack[sidx] = (*(bulkfun_type7 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6]); continue; + case 8: sidx -= 7; Stack[sidx] = (*(bulkfun_type8 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7]); continue; + case 9: sidx -= 8; Stack[sidx] = (*(bulkfun_type9 )pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8]); continue; + case 10:sidx -= 9; Stack[sidx] = (*(bulkfun_type10)pTok->Fun.ptr)(nOffset, nThreadID, Stack[sidx], Stack[sidx+1], Stack[sidx+2], Stack[sidx+3], Stack[sidx+4], Stack[sidx+5], Stack[sidx+6], Stack[sidx+7], Stack[sidx+8], Stack[sidx+9]); continue; default: Error(ecINTERNAL_ERROR, 2); continue; } } - //case cmSTRING: - //case cmOPRT_BIN: - //case cmOPRT_POSTFIX: - //case cmOPRT_INFIX: - // MUP_FAIL(INVALID_CODE_IN_BYTECODE); - // continue; - - //case cmEND: - // return Stack[m_nFinalResultIdx]; - default: Error(ecINTERNAL_ERROR, 3); return 0; @@ -1186,7 +1180,6 @@ namespace mu ParserStack stArgCount; token_type opta, opt; // for storing operators token_type val, tval; // for storing value - string_type strBuf; // buffer for string function arguments ReInit(); @@ -1215,7 +1208,7 @@ namespace mu break; case cmVAL: - stVal.push(opt); + stVal.push(opt); m_vRPN.AddVal( opt.GetVal() ); break; @@ -1720,6 +1713,16 @@ namespace mu //--------------------------------------------------------------------------- void ParserBase::Eval(value_type *results, int nBulkSize) { +/* Commented because it is making a unit test impossible + + // Parallelization does not make sense for fewer than 10000 computations + // due to thread creation overhead. If the bulk size is below 2000 + // computation is refused. + if (nBulkSize<2000) + { + throw ParserError(ecUNREASONABLE_NUMBER_OF_COMPUTATIONS); + } +*/ CreateRPN(); int i = 0; @@ -1732,7 +1735,7 @@ namespace mu #endif int nMaxThreads = std::min(omp_get_max_threads(), s_MaxNumOpenMPThreads); - int nThreadID, ct=0; + int nThreadID = 0, ct = 0; omp_set_num_threads(nMaxThreads); #pragma omp parallel for schedule(static, nBulkSize/nMaxThreads) private(nThreadID) diff --git a/bundled/muparser_v2_2_3/src/muParserBytecode.cpp b/bundled/muparser_v2_2_4/src/muParserBytecode.cpp similarity index 81% rename from bundled/muparser_v2_2_3/src/muParserBytecode.cpp rename to bundled/muparser_v2_2_4/src/muParserBytecode.cpp index c01bcba60b..f093eaa460 100644 --- a/bundled/muparser_v2_2_3/src/muParserBytecode.cpp +++ b/bundled/muparser_v2_2_4/src/muParserBytecode.cpp @@ -25,12 +25,12 @@ #include "muParserBytecode.h" +#include #include #include #include #include #include -#include #include "muParserDef.h" #include "muParserError.h" @@ -92,6 +92,7 @@ namespace mu m_iStackPos = a_ByteCode.m_iStackPos; m_vRPN = a_ByteCode.m_vRPN; m_iMaxStackSize = a_ByteCode.m_iMaxStackSize; + m_bEnableOptimizer = a_ByteCode.m_bEnableOptimizer; } //--------------------------------------------------------------------------- @@ -107,9 +108,9 @@ namespace mu // optimization does not apply SToken tok; tok.Cmd = cmVAR; - tok.u.Val.ptr = a_pVar; - tok.u.Val.data = 1; - tok.u.Val.data2 = 0; + tok.Val.ptr = a_pVar; + tok.Val.data = 1; + tok.Val.data2 = 0; m_vRPN.push_back(tok); } @@ -134,9 +135,9 @@ namespace mu // If optimization does not apply SToken tok; tok.Cmd = cmVAL; - tok.u.Val.ptr = NULL; - tok.u.Val.data = 0; - tok.u.Val.data2 = a_fVal; + tok.Val.ptr = NULL; + tok.Val.data = 0; + tok.Val.data2 = a_fVal; m_vRPN.push_back(tok); } @@ -144,8 +145,8 @@ namespace mu void ParserByteCode::ConstantFolding(ECmdCode a_Oprt) { std::size_t sz = m_vRPN.size(); - value_type &x = m_vRPN[sz-2].u.Val.data2, - &y = m_vRPN[sz-1].u.Val.data2; + value_type &x = m_vRPN[sz-2].Val.data2, + &y = m_vRPN[sz-1].Val.data2; switch (a_Oprt) { case cmLAND: x = (int)x && (int)y; m_vRPN.pop_back(); break; @@ -215,11 +216,11 @@ namespace mu // Optimization for ploynomials of low order if (m_vRPN[sz-2].Cmd == cmVAR && m_vRPN[sz-1].Cmd == cmVAL) { - if (m_vRPN[sz-1].u.Val.data2==2) + if (m_vRPN[sz-1].Val.data2==2) m_vRPN[sz-2].Cmd = cmVARPOW2; - else if (m_vRPN[sz-1].u.Val.data2==3) + else if (m_vRPN[sz-1].Val.data2==3) m_vRPN[sz-2].Cmd = cmVARPOW3; - else if (m_vRPN[sz-1].u.Val.data2==4) + else if (m_vRPN[sz-1].Val.data2==4) m_vRPN[sz-2].Cmd = cmVARPOW4; else break; @@ -237,19 +238,19 @@ namespace mu (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVAR) || (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVARMUL) || (m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVAL) || - (m_vRPN[sz-1].Cmd == cmVAR && m_vRPN[sz-2].Cmd == cmVAR && m_vRPN[sz-2].u.Val.ptr == m_vRPN[sz-1].u.Val.ptr) || - (m_vRPN[sz-1].Cmd == cmVAR && m_vRPN[sz-2].Cmd == cmVARMUL && m_vRPN[sz-2].u.Val.ptr == m_vRPN[sz-1].u.Val.ptr) || - (m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVAR && m_vRPN[sz-2].u.Val.ptr == m_vRPN[sz-1].u.Val.ptr) || - (m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVARMUL && m_vRPN[sz-2].u.Val.ptr == m_vRPN[sz-1].u.Val.ptr) ) + (m_vRPN[sz-1].Cmd == cmVAR && m_vRPN[sz-2].Cmd == cmVAR && m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) || + (m_vRPN[sz-1].Cmd == cmVAR && m_vRPN[sz-2].Cmd == cmVARMUL && m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) || + (m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVAR && m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) || + (m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVARMUL && m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) ) { - assert( (m_vRPN[sz-2].u.Val.ptr==NULL && m_vRPN[sz-1].u.Val.ptr!=NULL) || - (m_vRPN[sz-2].u.Val.ptr!=NULL && m_vRPN[sz-1].u.Val.ptr==NULL) || - (m_vRPN[sz-2].u.Val.ptr == m_vRPN[sz-1].u.Val.ptr) ); + assert( (m_vRPN[sz-2].Val.ptr==NULL && m_vRPN[sz-1].Val.ptr!=NULL) || + (m_vRPN[sz-2].Val.ptr!=NULL && m_vRPN[sz-1].Val.ptr==NULL) || + (m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) ); m_vRPN[sz-2].Cmd = cmVARMUL; - m_vRPN[sz-2].u.Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].u.Val.ptr) | (long long)(m_vRPN[sz-1].u.Val.ptr)); // variable - m_vRPN[sz-2].u.Val.data2 += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].u.Val.data2; // offset - m_vRPN[sz-2].u.Val.data += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].u.Val.data; // multiplikatior + m_vRPN[sz-2].Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); // variable + m_vRPN[sz-2].Val.data2 += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data2; // offset + m_vRPN[sz-2].Val.data += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data; // multiplikatior m_vRPN.pop_back(); bOptimized = true; } @@ -260,9 +261,9 @@ namespace mu (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVAR) ) { m_vRPN[sz-2].Cmd = cmVARMUL; - m_vRPN[sz-2].u.Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].u.Val.ptr) | (long long)(m_vRPN[sz-1].u.Val.ptr)); - m_vRPN[sz-2].u.Val.data = m_vRPN[sz-2].u.Val.data2 + m_vRPN[sz-1].u.Val.data2; - m_vRPN[sz-2].u.Val.data2 = 0; + m_vRPN[sz-2].Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); + m_vRPN[sz-2].Val.data = m_vRPN[sz-2].Val.data2 + m_vRPN[sz-1].Val.data2; + m_vRPN[sz-2].Val.data2 = 0; m_vRPN.pop_back(); bOptimized = true; } @@ -271,22 +272,22 @@ namespace mu { // Optimization: 2*(3*b+1) or (3*b+1)*2 -> 6*b+2 m_vRPN[sz-2].Cmd = cmVARMUL; - m_vRPN[sz-2].u.Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].u.Val.ptr) | (long long)(m_vRPN[sz-1].u.Val.ptr)); + m_vRPN[sz-2].Val.ptr = (value_type*)((long long)(m_vRPN[sz-2].Val.ptr) | (long long)(m_vRPN[sz-1].Val.ptr)); if (m_vRPN[sz-1].Cmd == cmVAL) { - m_vRPN[sz-2].u.Val.data *= m_vRPN[sz-1].u.Val.data2; - m_vRPN[sz-2].u.Val.data2 *= m_vRPN[sz-1].u.Val.data2; + m_vRPN[sz-2].Val.data *= m_vRPN[sz-1].Val.data2; + m_vRPN[sz-2].Val.data2 *= m_vRPN[sz-1].Val.data2; } else { - m_vRPN[sz-2].u.Val.data = m_vRPN[sz-1].u.Val.data * m_vRPN[sz-2].u.Val.data2; - m_vRPN[sz-2].u.Val.data2 = m_vRPN[sz-1].u.Val.data2 * m_vRPN[sz-2].u.Val.data2; + m_vRPN[sz-2].Val.data = m_vRPN[sz-1].Val.data * m_vRPN[sz-2].Val.data2; + m_vRPN[sz-2].Val.data2 = m_vRPN[sz-1].Val.data2 * m_vRPN[sz-2].Val.data2; } m_vRPN.pop_back(); bOptimized = true; } else if (m_vRPN[sz-1].Cmd == cmVAR && m_vRPN[sz-2].Cmd == cmVAR && - m_vRPN[sz-1].u.Val.ptr == m_vRPN[sz-2].u.Val.ptr) + m_vRPN[sz-1].Val.ptr == m_vRPN[sz-2].Val.ptr) { // Optimization: a*a -> a^2 m_vRPN[sz-2].Cmd = cmVARPOW2; @@ -296,11 +297,11 @@ namespace mu break; case cmDIV: - if (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVARMUL && m_vRPN[sz-1].u.Val.data2!=0) + if (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVARMUL && m_vRPN[sz-1].Val.data2!=0) { // Optimization: 4*a/2 -> 2*a - m_vRPN[sz-2].u.Val.data /= m_vRPN[sz-1].u.Val.data2; - m_vRPN[sz-2].u.Val.data2 /= m_vRPN[sz-1].u.Val.data2; + m_vRPN[sz-2].Val.data /= m_vRPN[sz-1].Val.data2; + m_vRPN[sz-2].Val.data2 /= m_vRPN[sz-1].Val.data2; m_vRPN.pop_back(); bOptimized = true; } @@ -345,7 +346,7 @@ namespace mu SToken tok; tok.Cmd = cmASSIGN; - tok.u.Val.ptr = a_pVar; + tok.Oprt.ptr = a_pVar; m_vRPN.push_back(tok); } @@ -370,8 +371,8 @@ namespace mu SToken tok; tok.Cmd = cmFUNC; - tok.u.Fun.argc = a_iArgc; - tok.u.Fun.ptr = a_pFun; + tok.Fun.argc = a_iArgc; + tok.Fun.ptr = a_pFun; m_vRPN.push_back(tok); } @@ -388,8 +389,8 @@ namespace mu SToken tok; tok.Cmd = cmFUNC_BULK; - tok.u.Fun.argc = a_iArgc; - tok.u.Fun.ptr = a_pFun; + tok.Fun.argc = a_iArgc; + tok.Fun.ptr = a_pFun; m_vRPN.push_back(tok); } @@ -407,9 +408,9 @@ namespace mu SToken tok; tok.Cmd = cmFUNC_STR; - tok.u.Fun.argc = a_iArgc; - tok.u.Fun.idx = a_iIdx; - tok.u.Fun.ptr = a_pFun; + tok.Fun.argc = a_iArgc; + tok.Fun.idx = a_iIdx; + tok.Fun.ptr = a_pFun; m_vRPN.push_back(tok); m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); @@ -441,12 +442,12 @@ namespace mu case cmELSE: stElse.push(i); idx = stIf.pop(); - m_vRPN[idx].u.Oprt.offset = i - idx; + m_vRPN[idx].Oprt.offset = i - idx; break; case cmENDIF: idx = stElse.pop(); - m_vRPN[idx].u.Oprt.offset = i - idx; + m_vRPN[idx].Oprt.offset = i - idx; break; default: @@ -510,42 +511,42 @@ namespace mu switch (m_vRPN[i].Cmd) { case cmVAL: mu::console() << _T("VAL \t"); - mu::console() << _T("[") << m_vRPN[i].u.Val.data2 << _T("]\n"); + mu::console() << _T("[") << m_vRPN[i].Val.data2 << _T("]\n"); break; case cmVAR: mu::console() << _T("VAR \t"); - mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n"); + mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n"); break; case cmVARPOW2: mu::console() << _T("VARPOW2 \t"); - mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n"); + mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n"); break; case cmVARPOW3: mu::console() << _T("VARPOW3 \t"); - mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n"); + mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n"); break; case cmVARPOW4: mu::console() << _T("VARPOW4 \t"); - mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]\n"); + mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]\n"); break; case cmVARMUL: mu::console() << _T("VARMUL \t"); - mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Val.ptr << _T("]"); - mu::console() << _T(" * [") << m_vRPN[i].u.Val.data << _T("]"); - mu::console() << _T(" + [") << m_vRPN[i].u.Val.data2 << _T("]\n"); + mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Val.ptr << _T("]"); + mu::console() << _T(" * [") << m_vRPN[i].Val.data << _T("]"); + mu::console() << _T(" + [") << m_vRPN[i].Val.data2 << _T("]\n"); break; case cmFUNC: mu::console() << _T("CALL\t"); - mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].u.Fun.argc << _T("]"); - mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].u.Fun.ptr << _T("]"); + mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].Fun.argc << _T("]"); + mu::console() << _T("[ADDR: 0x") << std::hex << m_vRPN[i].Fun.ptr << _T("]"); mu::console() << _T("\n"); break; case cmFUNC_STR: mu::console() << _T("CALL STRFUNC\t"); - mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].u.Fun.argc << _T("]"); - mu::console() << _T("[IDX:") << std::dec << m_vRPN[i].u.Fun.idx << _T("]"); - mu::console() << _T("[ADDR: 0x") << m_vRPN[i].u.Fun.ptr << _T("]\n"); + mu::console() << _T("[ARG:") << std::dec << m_vRPN[i].Fun.argc << _T("]"); + mu::console() << _T("[IDX:") << std::dec << m_vRPN[i].Fun.idx << _T("]"); + mu::console() << _T("[ADDR: 0x") << m_vRPN[i].Fun.ptr << _T("]\n"); break; case cmLT: mu::console() << _T("LT\n"); break; @@ -563,18 +564,18 @@ namespace mu case cmPOW: mu::console() << _T("POW\n"); break; case cmIF: mu::console() << _T("IF\t"); - mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].u.Oprt.offset << _T("]\n"); + mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].Oprt.offset << _T("]\n"); break; case cmELSE: mu::console() << _T("ELSE\t"); - mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].u.Oprt.offset << _T("]\n"); + mu::console() << _T("[OFFSET:") << std::dec << m_vRPN[i].Oprt.offset << _T("]\n"); break; case cmENDIF: mu::console() << _T("ENDIF\n"); break; case cmASSIGN: mu::console() << _T("ASSIGN\t"); - mu::console() << _T("[ADDR: 0x") << m_vRPN[i].u.Oprt.ptr << _T("]\n"); + mu::console() << _T("[ADDR: 0x") << m_vRPN[i].Oprt.ptr << _T("]\n"); break; default: mu::console() << _T("(unknown code: ") << m_vRPN[i].Cmd << _T(")\n"); diff --git a/bundled/muparser_v2_2_3/src/muParserCallback.cpp b/bundled/muparser_v2_2_4/src/muParserCallback.cpp similarity index 100% rename from bundled/muparser_v2_2_3/src/muParserCallback.cpp rename to bundled/muparser_v2_2_4/src/muParserCallback.cpp diff --git a/bundled/muparser_v2_2_3/src/muParserError.cpp b/bundled/muparser_v2_2_4/src/muParserError.cpp similarity index 96% rename from bundled/muparser_v2_2_3/src/muParserError.cpp rename to bundled/muparser_v2_2_4/src/muParserError.cpp index e3d334b28d..e1ac7215a1 100644 --- a/bundled/muparser_v2_2_3/src/muParserError.cpp +++ b/bundled/muparser_v2_2_4/src/muParserError.cpp @@ -100,7 +100,8 @@ namespace mu m_vErrMsg[ecUNEXPECTED_CONDITIONAL] = _T("The \"$TOK$\" operator must be preceeded by a closing bracket."); m_vErrMsg[ecMISSING_ELSE_CLAUSE] = _T("If-then-else operator is missing an else clause"); m_vErrMsg[ecMISPLACED_COLON] = _T("Misplaced colon at position $POS$"); - + m_vErrMsg[ecUNREASONABLE_NUMBER_OF_COMPUTATIONS] = _T("Number of computations to small for bulk mode. (Vectorisation overhead too costly)"); + #if defined(_DEBUG) for (int i=0; iDefineConst( _T("const"), 1); p1->DefineConst( _T("const1"), 2); p1->DefineConst( _T("const2"), 3); + // string constants + p1->DefineStrConst( _T("str1"), _T("1.11")); + p1->DefineStrConst( _T("str2"), _T("2.22")); // variables value_type vVarVal[] = { 1, 2, 3, -2}; p1->DefineVar( _T("a"), &vVarVal[0]); @@ -1344,9 +1384,14 @@ namespace mu // The tests equations never result in infinity, if they do thats a bug. // reference: // http://sourceforge.net/projects/muparser/forums/forum/462843/topic/5037825 - if (numeric_limits::has_infinity) + #pragma warning(push) + #pragma warning(disable:4127) + if (std::numeric_limits::has_infinity) + #pragma warning(pop) + { bCloseEnough &= (fabs(fVal[i]) != numeric_limits::infinity()); - } + } + } iRet = ((bCloseEnough && a_fPass) || (!bCloseEnough && !a_fPass)) ? 0 : 1; @@ -1393,11 +1438,11 @@ namespace mu ParserTester::c_iCount++; value_type vVarVal[] = {1, 2, 3}; // variable values - value_type fVal[2] = {-99, -999}; // results: initially should be different int iRet(0); try { + value_type fVal[2] = {-99, -999}; // results: initially should be different ParserInt p; p.DefineConst( _T("const1"), 1); p.DefineConst( _T("const2"), 2); @@ -1438,6 +1483,63 @@ namespace mu return iRet; } + //--------------------------------------------------------------------------- + /** \brief Test an expression in Bulk Mode. */ + int ParserTester::EqnTestBulk(const string_type &a_str, double a_fRes[4], bool a_fPass) + { + ParserTester::c_iCount++; + + // Define Bulk Variables + int nBulkSize = 4; + value_type vVariableA[] = { 1, 2, 3, 4 }; // variable values + value_type vVariableB[] = { 2, 2, 2, 2 }; // variable values + value_type vVariableC[] = { 3, 3, 3, 3 }; // variable values + value_type vResults[] = { 0, 0, 0, 0 }; // variable values + int iRet(0); + + try + { + Parser p; + p.DefineConst(_T("const1"), 1); + p.DefineConst(_T("const2"), 2); + p.DefineVar(_T("a"), vVariableA); + p.DefineVar(_T("b"), vVariableB); + p.DefineVar(_T("c"), vVariableC); + + p.SetExpr(a_str); + p.Eval(vResults, nBulkSize); + + bool bCloseEnough(true); + for (int i = 0; i < nBulkSize; ++i) + { + bCloseEnough &= (fabs(a_fRes[i] - vResults[i]) <= fabs(a_fRes[i] * 0.00001)); + } + + iRet = ((bCloseEnough && a_fPass) || (!bCloseEnough && !a_fPass)) ? 0 : 1; + if (iRet == 1) + { + mu::console() << _T("\n fail: ") << a_str.c_str() + << _T(" (incorrect result; expected: {") << a_fRes[0] << _T(",") << a_fRes[1] << _T(",") << a_fRes[2] << _T(",") << a_fRes[3] << _T("}") + << _T(" ;calculated: ") << vResults[0] << _T(",") << vResults[1] << _T(",") << vResults[2] << _T(",") << vResults[3] << _T("}"); + } + } + catch (Parser::exception_type &e) + { + if (a_fPass) + { + mu::console() << _T("\n fail: ") << e.GetExpr() << _T(" : ") << e.GetMsg(); + iRet = 1; + } + } + catch (...) + { + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); + iRet = 1; // exceptions other than ParserException are not allowed + } + + return iRet; + } + //--------------------------------------------------------------------------- /** \brief Internal error in test class Test is going to be aborted. */ void ParserTester::Abort() const diff --git a/bundled/muparser_v2_2_3/src/muParserTokenReader.cpp b/bundled/muparser_v2_2_4/src/muParserTokenReader.cpp similarity index 95% rename from bundled/muparser_v2_2_3/src/muParserTokenReader.cpp rename to bundled/muparser_v2_2_4/src/muParserTokenReader.cpp index 0719ea0419..4bafd3127a 100644 --- a/bundled/muparser_v2_2_3/src/muParserTokenReader.cpp +++ b/bundled/muparser_v2_2_4/src/muParserTokenReader.cpp @@ -97,6 +97,8 @@ namespace mu m_pFactoryData = a_Reader.m_pFactoryData; m_iBrackets = a_Reader.m_iBrackets; m_cArgSep = a_Reader.m_cArgSep; + m_fZero = a_Reader.m_fZero; + m_lastTok = a_Reader.m_lastTok; } //--------------------------------------------------------------------------- @@ -255,7 +257,6 @@ namespace mu { assert(m_pParser); - std::stack FunArgs; const char_type *szFormula = m_strFormula.c_str(); token_type tok; @@ -347,7 +348,8 @@ namespace mu int ParserTokenReader::ExtractOperatorToken(string_type &a_sTok, int a_iPos) const { - int iEnd = (int)m_strFormula.find_first_not_of(m_pParser->ValidInfixOprtChars(), a_iPos); + // Changed as per Issue 6: https://code.google.com/p/muparser/issues/detail?id=6 + int iEnd = (int)m_strFormula.find_first_not_of(m_pParser->ValidOprtChars(), a_iPos); if (iEnd==(int)string_type::npos) iEnd = (int)m_strFormula.length(); @@ -420,8 +422,7 @@ namespace mu Error(ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef[i]); } - m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE; - m_iSynFlags |= ( (i != cmEND) && ( i != cmBC) ) ? noEND : 0; + m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE | noEND; break; case cmBO: @@ -656,7 +657,7 @@ namespace mu } m_iPos += (int)sID.length(); - m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noBC | noASSIGN; + m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noASSIGN; return true; } } @@ -754,7 +755,9 @@ namespace mu int iStart = m_iPos; if ( (*item)(m_strFormula.c_str() + m_iPos, &m_iPos, &fVal)==1 ) { - strTok.assign(m_strFormula.c_str(), iStart, m_iPos); + // 2013-11-27 Issue 2: https://code.google.com/p/muparser/issues/detail?id=2 + strTok.assign(m_strFormula.c_str(), iStart, m_iPos-iStart); + if (m_iSynFlags & noVAL) Error(ecUNEXPECTED_VAL, m_iPos - (int)strTok.length(), strTok); @@ -774,7 +777,7 @@ namespace mu */ bool ParserTokenReader::IsVarTok(token_type &a_Tok) { - if (!m_pVarDef->size()) + if (m_pVarDef->empty()) return false; string_type strTok; @@ -805,7 +808,7 @@ namespace mu //--------------------------------------------------------------------------- bool ParserTokenReader::IsStrVarTok(token_type &a_Tok) { - if (!m_pStrVarDef || !m_pStrVarDef->size()) + if (!m_pStrVarDef || m_pStrVarDef->empty()) return false; string_type strTok; diff --git a/bundled/setup_bundled.cmake b/bundled/setup_bundled.cmake index 2bc6e5db13..ccbf11dc12 100644 --- a/bundled/setup_bundled.cmake +++ b/bundled/setup_bundled.cmake @@ -72,4 +72,4 @@ OPTION(DEAL_II_FORCE_BUNDLED_MUPARSER "Always use the bundled functionparser library instead of an external one." OFF) -SET(MUPARSER_FOLDER "${CMAKE_SOURCE_DIR}/bundled/muparser_v2_2_3/") +SET(MUPARSER_FOLDER "${CMAKE_SOURCE_DIR}/bundled/muparser_v2_2_4/") -- 2.39.5