diff --git a/3rdParty/MuParser/CMakeLists.txt b/3rdParty/MuParser/CMakeLists.txt index 8855bcb3b92f7e8cbbcb5483d8089f3fa33b82f1..3f2d48be099fd660030424c1d7f5b92c216ee8ac 100644 --- a/3rdParty/MuParser/CMakeLists.txt +++ b/3rdParty/MuParser/CMakeLists.txt @@ -1,7 +1,91 @@ +# By default, build in Release mode. Must appear before project() command +#if (NOT DEFINED CMAKE_BUILD_TYPE) +# set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type") +#endif () -vf_add_library(BUILDTYPE static) +project(muParserProject) -vf_get_library_name(library_name) -target_include_directories(${library_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) -groupTarget(${library_name} ${thirdFolder}) \ No newline at end of file +# Bump versions on release +set(MUPARSER_VERSION_MAJOR 2) +set(MUPARSER_VERSION_MINOR 3) +set(MUPARSER_VERSION_PATCH 2) +set(MUPARSER_VERSION ${MUPARSER_VERSION_MAJOR}.${MUPARSER_VERSION_MINOR}.${MUPARSER_VERSION_PATCH}) + +# Build options +option(ENABLE_SAMPLES "Build the samples" OFF) +option(ENABLE_OPENMP "Enable OpenMP for multithreading" ON) +#option(BUILD_SHARED_LIBS "Build shared/static libs" ON) + +if(ENABLE_OPENMP) + find_package(OpenMP REQUIRED) + set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") + set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") +endif() + + +# Credit: https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake/3818084 +if(MSVC) + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") + endif() +elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + # Update if necessary + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic") +endif() + +add_library(muparser + src/muParserBase.cpp + src/muParserBytecode.cpp + src/muParserCallback.cpp + src/muParser.cpp + src/muParserDLL.cpp + src/muParserError.cpp + src/muParserInt.cpp + src/muParserTest.cpp + src/muParserTokenReader.cpp + ) + +target_link_libraries(muparser PUBLIC OpenMP::OpenMP_CXX) +target_include_directories(muparser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) + +# this compiles the "DLL" interface (C API) +target_compile_definitions(muparser PRIVATE MUPARSER_DLL) + +if (BUILD_SHARED_LIBS) + target_compile_definitions(muparser PRIVATE MUPARSERLIB_EXPORTS) +else () + target_compile_definitions(muparser PUBLIC MUPARSER_STATIC) +endif() + +if (CMAKE_BUILD_TYPE STREQUAL Debug) + target_compile_definitions(muparser PRIVATE _DEBUG) +endif () + +if(ENABLE_OPENMP) + target_compile_definitions(muparser PRIVATE MUP_USE_OPENMP) +endif() +set_target_properties(muparser PROPERTIES + VERSION ${MUPARSER_VERSION} + SOVERSION ${MUPARSER_VERSION_MAJOR} + ) + +if(ENABLE_SAMPLES) + add_executable(example1 samples/example1/example1.cpp) + target_link_libraries(example1 muparser) + + add_executable(example2 samples/example2/example2.c) + target_link_libraries(example2 muparser) +endif() + +#include(CTest) +#enable_testing() + +#add_executable (t_ParserTest test/t_ParserTest.cpp) +#target_link_libraries(t_ParserTest muparser) +#add_test (NAME ParserTest COMMAND t_ParserTest) + +groupTarget(muparser ${thirdFolder}) \ No newline at end of file diff --git a/3rdParty/MuParser/CMakePackage.txt b/3rdParty/MuParser/CMakePackage.txt deleted file mode 100644 index a65591860b49b37cf92b5c00243342cc9368eaaf..0000000000000000000000000000000000000000 --- a/3rdParty/MuParser/CMakePackage.txt +++ /dev/null @@ -1,36 +0,0 @@ -GET_FILENAME_COMPONENT( CURRENT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH) -COLLECT_PACKAGE_DATA_WITH_OPTION(${CURRENT_DIR} ALL_SOURCES outOption outSourceGroupName) - -IF( ${outOption} ) - - #verzeichnis als std-include adden - INCLUDE_DIRECTORIES( ${CURRENT_DIR}/include ) - - OPTION(USE_MUPARSER_AS_LIB "MuParser will be compiled as lib" ON) - - IF(USE_MUPARSER_AS_LIB) - FILE( GLOB muparser_HEADER_FILES ${CURRENT_DIR}/include/*.h ) - FILE( GLOB muparser_CXX_FILES ${CURRENT_DIR}/src/*.cpp ) - - SET(MUPARSER_SRC_FILES ${muparser_HEADER_FILES} ${muparser_CXX_FILES}) - - ADD_LIBRARY(muParserLib ${MUPARSER_SRC_FILES}) - - #lib projekt hinzufuegen - LIST(APPEND CAB_ADDITIONAL_LINK_LIBRARIES muParserLib) - - ADD_TARGET_PROPERTIES(muParserLib COMPILE_FLAGS "-I${CURRENT_DIR}/include") - - #compilerflags aktuellem projekt hinzufuegen - ADD_COMPILER_FLAGS_TO_PROJECT(${CAB_COMPILER} "muParserLib" "CXX" "STATIC") - - ELSE() #not as lib - SET( CURRENT_DIR_TMP ${CURRENT_DIR} ) #wird im naechsten befehl geaendert - INCLUDE( ${CURRENT_DIR_TMP}/include/CMakePackage.txt) - INCLUDE( ${CURRENT_DIR_TMP}/src/CMakePackage.txt) - ENDIF() - -ENDIF( ${outOption} ) - - - diff --git a/3rdParty/MuParser/Changes.txt b/3rdParty/MuParser/Changes.txt index abe969770b09170a50d8f9dfb8d26bfa2d3ba1fa..85c687284103667a6fa5d2269f8ffee901e3b009 100644 --- a/3rdParty/MuParser/Changes.txt +++ b/3rdParty/MuParser/Changes.txt @@ -1,557 +1,594 @@ -####################################################################### -# # -# # -# __________ # -# _____ __ __\______ \_____ _______ ______ ____ _______ # -# / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ # -# | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ # -# |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| # -# \/ \/ \/ \/ # -# Fast math parser Library # -# # -# Copyright (C) 2015 Ingo Berg # -# # -# Web: muparser.beltoforion.de # -# e-mail: muparser@beltoforion.de # -# # -# # -####################################################################### - - -History: --------- - -Rev 2.2.5: 27.04.2015 ---------------------- - Changes: - * example2 extended to work with UNICODE character set - * Applied patch from Issue 9 - - Bugfixes: - * muChar_t in muParserDLL.h was not set properly when UNICODE was used - * muparser.dll did not build on UNICODE systems - -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 ---------------------- - - Removed features: - * build files for msvc2005, borland and watcom compiler were removed - - Bugfixes: - * Bugfix for Intel Compilers added: The power operator did not work properly - with Intel C++ composer XE 2011. - (see https://sourceforge.net/projects/muparser/forums/forum/462843/topic/5117983/index/page/1) - * Issue 3509860: Callbacks of functions with string parameters called twice - (see http://sourceforge.net/tracker/?func=detail&aid=3509860&group_id=137191&atid=737979) - * Issue 3570423: example1 shows slot number in hexadecimal - (see https://sourceforge.net/tracker/?func=detail&aid=3570423&group_id=137191&atid=737979) - * Fixes for compiling with the "MUP_MATH_EXCEPTIONS" macro definition: - - division by zero in constant expressions was reported with the code "ec_GENERIC" - instead of "ecDIV_BY_ZERO" - - added throwing of "ecDOMAIN_ERROR" to sqrt and log functions - - -Rev 2.2.2: 18.02.2012 ---------------------- - Bugfixes: - * Optimizer did'nt work properly for division: - (see https://sourceforge.net/projects/muparser/forums/forum/462843/topic/5037825) - -Rev 2.2.1: 22.01.2012 ---------------------- - Bugfixes: - * Optimizer bug in 64 bit systems fixed - (see https://sourceforge.net/projects/muparser/forums/forum/462843/topic/4977977/index/page/1) - -Rev 2.2.0: 22.01.2012 ---------------------- - Improvements: - * Optimizer rewritten and improved. In general: more optimizations are - now applied to the bytecode. The downside is that callback Functions - can no longer be flagged as non-optimizable. (The flag is still present - but ignored) This is necessary since the optimizer had to call the - functions in order to precalculate the result (see Bugfixes). These calls - posed a problems for callback functions with side effects and if-then-else - clauses in general since they undermined the shortcut evaluation prinziple. - - Bugfixes: - * Infix operators where not properly detected in the presence of a constant - name starting with an underscore which is a valid character for infix - operators too (i.e. "-_pi"). - * Issue 3463353: Callback functions are called twice during the first call to eval. - * Issue 3447007: GetUsedVar unnecessaryly executes callback functions. - - -Rev 2.1.0: 19.11.2011 ---------------------- - New feature: - * Function atan2 added - - Bugfixes: - * Issue 3438380: Changed behaviour of tellg with GCC >4.6 led to failures - in value detection callbacks. - * Issue 3438715: only "double" is a valid MUP_BASETYPE - MUP_BASETYPE can now be any of: - float, - double, - long double, - short, - unsigned short, - unsigned int, - long, - unsigned long. - Previousely only floating point types were allowed. - Using "int" is still not allowed! - * Compiler issues with GCC 4.6 fixed - * Custom value recognition callbacks added with AddValIdent had lower - priority than built in functions. This was causing problems with - hex value recognition since detection of non hex values had priority - over the detection of hex values. The "0" in the hex prefix "0x" would - be read as a separate non-hex number leaving the rest of the expression - unparseable. - -Rev 2.0.0: 04.09.2011 ---------------------- -This release introduces a new version numbering scheme in order to make -future changes in the ABI apparent to users of the library. The number is -now based on the SONAME property as used by GNU/Linux. - - Changes: - * Beginning with this version all version numbers will be SONAME compliant - * Project files for MSVC2010 added - * Project files for MSVC2003 removed - * Bytecode parsing engine cleaned up and rewritten - * Retrieving all results of expressions made up of comma separate - subexpressions is now possible with a new Eval overload. - * Callback functions with fixed number of arguments can now have up to 10 - Parameters (previous limit was 5) - - New features: - * ternary if-then-else operator added (C++ like; "(...) ? ... : ..." ) - * new intrinsic binary operators: "&&", "||" (logical and, or) - * A new bulkmode allows submitting large arrays as variables to compute large - numbers of expressions with a single call. This can drastically improve - parsing performance when interfacing the library from managed languages like - C#. (It doesn't bring any performance benefit for C++ users though...) - - Removed features: - * intrinsic "and", "or" and "xor" operators have been removed. I'd like to let - users the freedom of defining them on their own versions (either as logical or bitwise - operators). - * Implementation for complex numbers removed. This was merely a hack. If you - need complex numbers try muParserX which provides native support for them. - (see: http://beltoforion.de/muparserx/math_expression_parser_en.html) - - Bugfixes: - * User defined operators could collide with built in operators that entirely - contained their identifier. i.e. user defined "&" would not work with the built - in "&&" operator since the user defined operator was detected with a higher - priority resulting in a syntax error. - * Detection of unknown variables did not work properly in case a postfix operator - was defined which was part of the undefined variable. - i.e. If a postfix operator "m" was defined expressions like "multi*1.0" did - not detect "multi" as an undefined variable. - (Reference: http://sourceforge.net/tracker/index.php?func=detail&aid=3343891&group_id=137191&atid=737979) - * Postfix operators sharing the first few characters were causing bogus parsing exception. - (Reference: https://sourceforge.net/tracker/?func=detail&aid=3358571&group_id=137191&atid=737979) - -Rev 1.34: 04.09.2010 --------------------- - Changes: - * The prefix needed for parsing hex values is now "0x" and no longer "$". - * AddValIdent reintroduced into the DLL interface - - New features: - * The associativity of binary operators can now be changed. The pow operator - is now right associative. (This is what Mathematica is using) - * Seperator can now be used outside of functions. This allows compound - expressions like: - "a=10,b=20,c=a*b" The last "argument" will be taken as the return value - - Bugfixes: - * The copy constructor did not copy binary operator definitions. Those were lost - in the copied parser instance. - * Mixing special characters and alphabetic characters in binary operator names - led to inconsistent parsing behaviour when parsing expressions like "a ++ b" - and "a++b" when "++" is defined as a binary operator. Binary operators must - now consist entirely of special characters or of alphabetic ones. - (original bug report: https://sourceforge.net/projects/muparser/forums/forum/462843/topic/3696881/index/page/1) - * User defined operators were not exactly handled like built in operators. This - led to inconsistencies in expression evaluation when using them. The results - differed due to slightly different precedence rules. - * Using empty string arguments ("") would cause a crash of muParser - - -Rev 1.32: 29.01.2010 --------------------- - - Changes: - * "example3" renamed to "example2" - * Project/Makefiles files are now provided for: - - msvc2003 - - msvc2005 - - msvc2008 - - watcom (makefile) - - mingw (makefile) - - bcc (makefile) - * Project files for borland cpp builder were removed - - - New features: - * Added function returning muparsers version number - * Added function for resetting the locale - - - Bugfixes: - * Changes example1 in order to fix issues with irritating memory leak reports. - Added conditional code for memory leak detection with MSVC in example1. - (see: http://www.codeproject.com/KB/recipes/FastMathParser.aspx?msg=3286367#xx3286367xx) - * Fixed some warnings for gcc - - - -Rev 1.31cp: 15.01.2010 (Maintainance release for CodeProject) ----------------------- - - Changes: - * Archive structure changed - * C# wrapper added - * Fixed issued that prevented compiling with VS2010 Beta2 - - -Rev 1.30: 09.06.2008 --------------------- - - Changes: - * Epsilon of the numerical differentiation algorithm changed to allow greater accuracy. - - New features: - * Setting thousands separator and decimal separator is now possible - - Bugfixes: - * The dll interface did not provide a callback for functions without any arguments. - - -Rev 1.29: Januar 2008 ---------------------- - - Unrelease Version available only via SVN. - - -Rev 1.28: 02. July, 2007 ---------------------------- - - Library changes: - * Interface for the dynamic library changed and extended to create an interface - using pure C functions only. - * mupInit() removed - - Build system: - * MSVC7 Project files removed in favor of MSVC8 - - Bugfixes: - * The dynamic library did not build on other systems than linux due to a misplaced - preprocessor definition. This is fixed now. - - -Rev 1.27: ---------------------------- - - Build system: - * Modified build\ directory layout introducing some subfolders - for the various IDE supported - * Project files for BCB and MSVC7 added - * Switched to use bakefile 0.2.1 which now correctly creates the - "make uninstall" target for autoconf's Makefile.in - * Now the library debug builds are named "muparserd" instead of "muparser" - to allow multiple mixed release/debug builds to coexist; so e.g. on Windows - when building with DEBUG=1, you'll get "muparserd.lib" instead of "muparser.lib" - - New Features: - * Factory functions can now take a user defined pointer - * String functions can now be used with up to two additional - double parameters - * Support for UNICODE character types added - * Infix operator priority can now be changed by the user - - Bugfixes: - * An internal error was raised when evaluating an empty - expressions - * The error message raised in case of name collisions between - implicitely defined variables and postfix operators did contain - misleading data. - - -Rev 1.26: (unofficial release) ------------------------------- - - New Features: - * Unary operator precedence can now be changed by the user. - - -Rev 1.25: 5. February, 2006 ---------------------------- - - Build system: (special thanks to Francesco Montorsi for implementing it!) - * created a bakefile-based build system which adds support for the following win32 compilers: - -> MS visual C++ (6 and .NET) - -> BorlandC++ (5 or greater) - -> Mingw32 (tested with gcc 3.2) - -> Watcom (not tested) - and for GCC on Unix (using a standard autoconf's configure script). - - Compatibility improvements: - * fixed some small warnings when using -Wall with GCC on Unix - * added inclusion guards for win32-specific portions of code - * added fixes that remove compiler warnings on Intel C++ and the Solaris C++ compiler. - - -Rev 1.24: 29. October, 2005 ---------------------------- - -Changes: - - Compatibility improvements: - * parser now works on 64 bit compilers - * (bytecode base datatype can now be changed freely) - - -Rev 1.23: 19. October, 2005 ---------------------------- - -Changes: - - Bugfixes: - * Variable factory examples in Example1.cpp and Example3.cpp contained a subtle bug. - - New features: - * Added a MSVC6 project file and introduced muParserFixes.h in order to make it compile with MSVC6 - - -Rev 1.22: October, 2005 ------------------------ - -Release notes: - -All features of Version 1.22 are similar to Version 1.21. Version 1.22 fixes a compilation issue with -gcc 4.0. In order to fix this issue I rewrote part of the library to remove some unnecessary templates. -This should make the code cleaner. The Borland Project files were removed. If you want to use it -with Borland either use the dll version or create your own project files. I can't support it since I don't -have this compiler at hand. - -Changes: - - Project Changes: - * Borland project files removed - (The code should still compile with BCB but I cant provide you with project files) - - Internal Changes: - * unnecessary template files have been removed: - - new files: muParserError.cpp, muParserTokenReader.cpp, muParserCallback.cpp - - removed Files: muIParserTypes.h - - -Rev 1.2 / 1.21: April, 2005 ---------------------------- - -Release Notes: -First of all the interface has changed so this version is not backwards compatible. -After receiving a couple of questions about it, this version features support for -user defined binary operators. Consequently the built in operators can now be -turned off, thus you can deactivate them and write complete customized parser -subclasses that only contain the functionality you want. Another new feature is -the introduction of callback functions taking string arguments, implicit -generation of variables and the Assignement operator. - - Functionality - * New built in operator: xor; Logical xor. - * New built in operator: Assignement operator; Defining variables in terms of - other variables/constants - * New feature: Strings as arguments for callback functions - * New feature: User defined binary operators - * New feature: ParserInt a class with a sample implementation for - integer numbers. - * New feature: Callbacks to value regognition functions. - - * Removed: all predefined postfix operators have been removed. - * New project file: Now comes with a ready to use windows DLL. - * New project file: Makefile for cygwin now included. - * New example: Example3 shows usage of the DLL. - - Interface changes - * New member function: DefineOprt For adding user defined binary operators. - * New member function: EnableBuiltInOprt(bool) Enables/Disables built in - binary operators. - * New member function: AddValIdent(...) to add callbacks for custom value - recognition functions. - * Removed: SetVar(), SetConst(). - * Renamed: Most interface functions have been renamed - * Changed: The type for multiargument callbacks multfun_type has changed. - It no longer takes a std::vector as input. - - Internal changes - * new class muParserTokenReader.h encapsulates the token identification - and token assignement. - * Internal handling of function callbacks unified as a result the performance - of the bytecode evaluation increased. - - -Rev 1.10 : December 30, 2004 ----------------------------- - -Release Notes: -This version does not contain major new feature compared to V1.07 but its internal structure has -changed significantly. The String parsing routine is slower than the one of V1.07 but bytecode -parsing is equally fast. On the other hand the error messages of V1.09 are more flexible and you -can change its value datatype. It should work on 64-bit systems. For this reason I supply both -versions for download. If you use V1.07 and are happy with it there is no need for updating -your version. - - * New example program: Archive now contains two demo programs: One for standard C++ and one for - managed C++. - * New member function: RemoveVar(...) can be used for removing a single variable from the internal - storage. - * New member function: GetVar() can be used for querying the variable names and pointers of all - variables defined in the parser. - * New member function: GetConst() can be used for querying all defined constants and their values. - * New member function: GetFunDef() can be used for querying all defined functions and the number of - arguments they expect. - * Internal structure changed; hanging base datatype at compile time is now possible. - * Bugfix: Postfix operator parsing could fail in certain cases; This has been fixed now. - * Bugfix: Variable names must will now be tested if they conflict with constant or function names. - * Internal change: Removed most dependencies from the C-string libraries. - * Internal change: Bytecode is now stored in a separate class: ParserByteCode.h - * Internal change: GetUsedVar() does no longer require that variables are defined at time of call. - * Internal change: Error treatment changed. ParserException is no longer derived from - std::runtime_error; Internal treatment of Error messages changed. - * New functions in Parser interface: ValidNameChars(), ValidOprtChars() and ValidPrefixOprtChars() - they are used for defining the charset allowed for variable-, operator- and - function names. - - -Rev 1.09 : November 20, 2004 ----------------------------- - - * New member function: RemoveVar(...) can be used for removing a single variable from the internal - storage. - * Internal structure changed; changing base datatype at compile time is now possible. - * Bug fix: Postfix operator parsing could fail in certain cases; This has been fixed now. - * Internal change: Removed most dependencies from the C-string libraries. - * Internal change: Bytecode is now stored in a seperate class: ParserByteCode.h. - * Internal change: GetUsedVar() does no longer require that variables are defined at time of call. - * Internal change: Error treatment changed. ParserException is no longer derived from - std::runtime_error; Internal treatment of Error messages changed. - * New functions in Parser interface; ValidNameChars(), ValidOprtChars() and ValidPrefixOprtChars() - they are used for defining the charset allowed for variable-, operator- and function names. - - -Rev 1.08 : November, 2004 -------------------------- - - * unpublished; experimental template version with respect to data type and underlying string - type (string <-> widestring). The idea was dropped... - - -Rev 1.07 : September 4 2004 ---------------------------- - - * Improved portability; Changes to make life for MSVC 6 user easier, there are probably still some - issues left. - * Improved portability; Changes in order to allow compiling on BCB. - * New function; value_type Diff(value_type *a_Var, value_type a_fPos) 4th order Differentiation with - respect to a certain variable; added in muParser.h. - - -Rev 1.06 : August 20 2004 -------------------------- - - * Volatile functions added; All overloaded AddFun(...) functions can now take a third parameter - indicating that the function can not be optimized. - * Internal changes: muParserStack.h simplified; refactorings - * Parser is now distributed under the MIT License; all comments changed accordingly. - - -Rev 1.05 : August 20 2004 -------------------------- - - * Variable/constant names will now be checked for invalid characters. - * Querying the names of all variables used in an expression is now possible; new function: GetUsedVar(). - * Disabling bytecode parsing is now possible; new function: EnableByteCode(bool bStat). - * Predefined functions with variable number of arguments added: sum, avg, min, max. - * Unary prefix operators added; new functions: AddPrefixOp(...), ClearPrefixOp(). - * Postfix operator interface names changed; new function names: AddPostfixOp(...), ClearPostfixOp(). - * Hardcoded sign operators removed in favor of prefix operators; bytecode format changed accordingly. - * Internal changes: static array removed in Command code calculation routine; misc. changes. - - -Rev 1.04 : August 16 2004 -------------------------- - - * Support for functions with variable number of arguments added. - * Internal structure changed; new: ParserBase.h, ParserBase.cpp; removed: ParserException.h; - changed: Parser.h, Parser.cpp. - * Bug in the bytecode calculation function fixed (affected the unary minus operator). - * Optimizer can be deactivated; new function: EnableOptimizer(bool bStat). - - -Rev 1.03 : August 10 2004 -------------------------- - - * Support for user-defined unary postfix operators added; new functions: AddPostOp(), InitPostOp(), - ClearPostOp(). - * Minor changes to the bytecode parsing routine. - * User defined functions can now have up to four parameters. - * Performance optimized: simple formula optimization added; (precalculation of constant parts of the - expression). - * Bug fixes: Multi-arg function parameters, constant name lookup and unary minus did not work properly. - - -Rev 1.02 : July 30 2004 ------------------------ - - * Support for user defined constants added; new functions: InitConst(), AddConst(), SetConst(), - ClearConst(). - * Single variables can now be added using AddVar(); you have now the choice of adding them either - one by one or all at the same time using SetVar(const varmap_type &a_vVar). - * Internal handling of variables changed, is now similar to function handling. - * Virtual destructor added; InitFun(), InitConst() are now virtual too thus making it possible to - derive new parsers with a modified set of default functions and constants. - * Support for user defined functions with 2 or 3 parameters added; bytecode format changed to hold - function parameter count. - - -Rev 1.01 : July 23 2004 ------------------------ - - * Support for user defined functions has been added; new functions: AddFun(), ClearFun(), - InitFunctions(). - * Built in constants have been removed; the parser contained undocumented built in - constants pi, e. - There was the possibility of name conflicts with user defined variables. - * Setting multiple variables with SetVar can now be done with a map of names and pointers as the only - argument. For this reason, a new type Parser::varmap_type was added. The old version that took 3 - arguments (array of names, array of pointers, and array length) is now marked as deprecated. - * The names of logarithm functions have changed. The new names are: log2 for base 2, log10 or log for - base 10, and ln for base e. - - -Rev 1.00 : July 21 2004 ------------------------ - - * Initial release + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + +======================================================================= + https://muparser.beltoforion.de +======================================================================= + +History: +-------- + +Rev 2.3.2: 17.06.2020 +--------------------- + API-Changes: + * removed final keyword from Parser class (added in 2.3.0) as this was breaking existing Applications + + Security Fixes: (The issues were present in all prior stable releases) + * Prevented multiple access violations for malformed expressions with if then else and functions taking multiple arguments like "sum(0?1,2,3,4:5)" + * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23410 + +Rev 2.3.1: +---------- +Only prerelease with the version number exist Version 2.3.2 replaced it. + + +Rev 2.3.0: 13.06.2020 +--------------------- + Changes: + * made Parser class final + * using OpenMP is now the default settings for cmake based builds + * added optimization for trivial expressions. (Expressions whose RPN only has a single entry) + * introduced a maximum length for expressions (5000 Character) + * introduced a maximum length for identifiers (100 Characters) + * removed the MUP_MATH_EXCEPTION macro and related functionality. (C++ exceptions for divide by zero or sqrt of a negative number are no longer supported) + * removed ParserStack.h (replaced with std::stack) + * removed macros for defining E and PI (replaced with a static constants) + * source code is now aimed at C++17 + * the MUP_ASSERT macro is no longer removed in release builds for better protection against segmentation faults + + Security Fixes: (The issues were present in all prior stable releases) + * Prevented multiple access violations for malformed expressions with if then else and functions taking multiple arguments like "sum(0?1,2,3,4:5)" + * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23330 + * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22922 + * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22938 + * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23330 + * Added additional runtime checks for release builds to prevent segmentation faults for invalid expressions + + Bugfixes: + * Fixed an issue where the bulk mode could hang on GCC/CLANG builds due to OpenMP chunksize dropping below 1. + +Rev 2.2.6: 04.10.2018 +--------------------- + Changes: + * Build system is now based on cmake + * several compiler warnings fixed + +Rev 2.2.5: 27.04.2015 +--------------------- + Changes: + * example2 extended to work with UNICODE character set + * Applied patch from Issue 9 + + Bugfixes: + * muChar_t in muParserDLL.h was not set properly when UNICODE was used + * muparser.dll did not build on UNICODE systems + +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 +--------------------- + + Removed features: + * build files for msvc2005, borland and watcom compiler were removed + + Bugfixes: + * Bugfix for Intel Compilers added: The power operator did not work properly + with Intel C++ composer XE 2011. + (see https://sourceforge.net/projects/muparser/forums/forum/462843/topic/5117983/index/page/1) + * Issue 3509860: Callbacks of functions with string parameters called twice + (see http://sourceforge.net/tracker/?func=detail&aid=3509860&group_id=137191&atid=737979) + * Issue 3570423: example1 shows slot number in hexadecimal + (see https://sourceforge.net/tracker/?func=detail&aid=3570423&group_id=137191&atid=737979) + * Fixes for compiling with the "MUP_MATH_EXCEPTIONS" macro definition: + - division by zero in constant expressions was reported with the code "ec_GENERIC" + instead of "ecDIV_BY_ZERO" + - added throwing of "ecDOMAIN_ERROR" to sqrt and log functions + + +Rev 2.2.2: 18.02.2012 +--------------------- + Bugfixes: + * Optimizer did'nt work properly for division: + (see https://sourceforge.net/projects/muparser/forums/forum/462843/topic/5037825) + +Rev 2.2.1: 22.01.2012 +--------------------- + Bugfixes: + * Optimizer bug in 64 bit systems fixed + (see https://sourceforge.net/projects/muparser/forums/forum/462843/topic/4977977/index/page/1) + +Rev 2.2.0: 22.01.2012 +--------------------- + Improvements: + * Optimizer rewritten and improved. In general: more optimizations are + now applied to the bytecode. The downside is that callback Functions + can no longer be flagged as non-optimizable. (The flag is still present + but ignored) This is necessary since the optimizer had to call the + functions in order to precalculate the result (see Bugfixes). These calls + posed a problems for callback functions with side effects and if-then-else + clauses in general since they undermined the shortcut evaluation prinziple. + + Bugfixes: + * Infix operators where not properly detected in the presence of a constant + name starting with an underscore which is a valid character for infix + operators too (i.e. "-_pi"). + * Issue 3463353: Callback functions are called twice during the first call to eval. + * Issue 3447007: GetUsedVar unnecessaryly executes callback functions. + + +Rev 2.1.0: 19.11.2011 +--------------------- + New feature: + * Function atan2 added + + Bugfixes: + * Issue 3438380: Changed behaviour of tellg with GCC >4.6 led to failures + in value detection callbacks. + * Issue 3438715: only "double" is a valid MUP_BASETYPE + MUP_BASETYPE can now be any of: + float, + double, + long double, + short, + unsigned short, + unsigned int, + long, + unsigned long. + Previousely only floating point types were allowed. + Using "int" is still not allowed! + * Compiler issues with GCC 4.6 fixed + * Custom value recognition callbacks added with AddValIdent had lower + priority than built in functions. This was causing problems with + hex value recognition since detection of non hex values had priority + over the detection of hex values. The "0" in the hex prefix "0x" would + be read as a separate non-hex number leaving the rest of the expression + unparseable. + +Rev 2.0.0: 04.09.2011 +--------------------- +This release introduces a new version numbering scheme in order to make +future changes in the ABI apparent to users of the library. The number is +now based on the SONAME property as used by GNU/Linux. + + Changes: + * Beginning with this version all version numbers will be SONAME compliant + * Project files for MSVC2010 added + * Project files for MSVC2003 removed + * Bytecode parsing engine cleaned up and rewritten + * Retrieving all results of expressions made up of comma separate + subexpressions is now possible with a new Eval overload. + * Callback functions with fixed number of arguments can now have up to 10 + Parameters (previous limit was 5) + + New features: + * ternary if-then-else operator added (C++ like; "(...) ? ... : ..." ) + * new intrinsic binary operators: "&&", "||" (logical and, or) + * A new bulkmode allows submitting large arrays as variables to compute large + numbers of expressions with a single call. This can drastically improve + parsing performance when interfacing the library from managed languages like + C#. (It doesn't bring any performance benefit for C++ users though...) + + Removed features: + * intrinsic "and", "or" and "xor" operators have been removed. I'd like to let + users the freedom of defining them on their own versions (either as logical or bitwise + operators). + * Implementation for complex numbers removed. This was merely a hack. If you + need complex numbers try muParserX which provides native support for them. + (see: http://beltoforion.de/muparserx/math_expression_parser_en.html) + + Bugfixes: + * User defined operators could collide with built in operators that entirely + contained their identifier. i.e. user defined "&" would not work with the built + in "&&" operator since the user defined operator was detected with a higher + priority resulting in a syntax error. + * Detection of unknown variables did not work properly in case a postfix operator + was defined which was part of the undefined variable. + i.e. If a postfix operator "m" was defined expressions like "multi*1.0" did + not detect "multi" as an undefined variable. + (Reference: http://sourceforge.net/tracker/index.php?func=detail&aid=3343891&group_id=137191&atid=737979) + * Postfix operators sharing the first few characters were causing bogus parsing exception. + (Reference: https://sourceforge.net/tracker/?func=detail&aid=3358571&group_id=137191&atid=737979) + +Rev 1.34: 04.09.2010 +-------------------- + Changes: + * The prefix needed for parsing hex values is now "0x" and no longer "$". + * AddValIdent reintroduced into the DLL interface + + New features: + * The associativity of binary operators can now be changed. The pow operator + is now right associative. (This is what Mathematica is using) + * Separator can now be used outside of functions. This allows compound + expressions like: + "a=10,b=20,c=a*b" The last "argument" will be taken as the return value + + Bugfixes: + * The copy constructor did not copy binary operator definitions. Those were lost + in the copied parser instance. + * Mixing special characters and alphabetic characters in binary operator names + led to inconsistent parsing behaviour when parsing expressions like "a ++ b" + and "a++b" when "++" is defined as a binary operator. Binary operators must + now consist entirely of special characters or of alphabetic ones. + (original bug report: https://sourceforge.net/projects/muparser/forums/forum/462843/topic/3696881/index/page/1) + * User defined operators were not exactly handled like built in operators. This + led to inconsistencies in expression evaluation when using them. The results + differed due to slightly different precedence rules. + * Using empty string arguments ("") would cause a crash of muParser + + +Rev 1.32: 29.01.2010 +-------------------- + + Changes: + * "example3" renamed to "example2" + * Project/Makefiles files are now provided for: + - msvc2003 + - msvc2005 + - msvc2008 + - watcom (makefile) + - mingw (makefile) + - bcc (makefile) + * Project files for borland cpp builder were removed + + + New features: + * Added function returning muparsers version number + * Added function for resetting the locale + + + Bugfixes: + * Changes example1 in order to fix issues with irritating memory leak reports. + Added conditional code for memory leak detection with MSVC in example1. + (see: http://www.codeproject.com/KB/recipes/FastMathParser.aspx?msg=3286367#xx3286367xx) + * Fixed some warnings for gcc + + + +Rev 1.31cp: 15.01.2010 (Maintenance release for CodeProject) +---------------------- + + Changes: + * Archive structure changed + * C# wrapper added + * Fixed issued that prevented compiling with VS2010 Beta2 + + +Rev 1.30: 09.06.2008 +-------------------- + + Changes: + * Epsilon of the numerical differentiation algorithm changed to allow greater accuracy. + + New features: + * Setting thousands separator and decimal separator is now possible + + Bugfixes: + * The dll interface did not provide a callback for functions without any arguments. + + +Rev 1.29: Januar 2008 +--------------------- + + Unrelease Version available only via SVN. + + +Rev 1.28: 02. July, 2007 +--------------------------- + + Library changes: + * Interface for the dynamic library changed and extended to create an interface + using pure C functions only. + * mupInit() removed + + Build system: + * MSVC7 Project files removed in favor of MSVC8 + + Bugfixes: + * The dynamic library did not build on other systems than linux due to a misplaced + preprocessor definition. This is fixed now. + + +Rev 1.27: +--------------------------- + + Build system: + * Modified build\ directory layout introducing some subfolders + for the various IDE supported + * Project files for BCB and MSVC7 added + * Switched to use bakefile 0.2.1 which now correctly creates the + "make uninstall" target for autoconf's Makefile.in + * Now the library debug builds are named "muparserd" instead of "muparser" + to allow multiple mixed release/debug builds to coexist; so e.g. on Windows + when building with DEBUG=1, you'll get "muparserd.lib" instead of "muparser.lib" + + New Features: + * Factory functions can now take a user defined pointer + * String functions can now be used with up to two additional + double parameters + * Support for UNICODE character types added + * Infix operator priority can now be changed by the user + + Bugfixes: + * An internal error was raised when evaluating an empty + expressions + * The error message raised in case of name collisions between + implicitely defined variables and postfix operators did contain + misleading data. + + +Rev 1.26: (unofficial release) +------------------------------ + + New Features: + * Unary operator precedence can now be changed by the user. + + +Rev 1.25: 5. February, 2006 +--------------------------- + + Build system: (special thanks to Francesco Montorsi for implementing it!) + * created a bakefile-based build system which adds support for the following win32 compilers: + -> MS visual C++ (6 and .NET) + -> BorlandC++ (5 or greater) + -> Mingw32 (tested with gcc 3.2) + -> Watcom (not tested) + and for GCC on Unix (using a standard autoconf's configure script). + + Compatibility improvements: + * fixed some small warnings when using -Wall with GCC on Unix + * added inclusion guards for win32-specific portions of code + * added fixes that remove compiler warnings on Intel C++ and the Solaris C++ compiler. + + +Rev 1.24: 29. October, 2005 +--------------------------- + +Changes: + + Compatibility improvements: + * parser now works on 64 bit compilers + * (bytecode base datatype can now be changed freely) + + +Rev 1.23: 19. October, 2005 +--------------------------- + +Changes: + + Bugfixes: + * Variable factory examples in Example1.cpp and Example3.cpp contained a subtle bug. + + New features: + * Added a MSVC6 project file and introduced muParserFixes.h in order to make it compile with MSVC6 + + +Rev 1.22: October, 2005 +----------------------- + +Release notes: + +All features of Version 1.22 are similar to Version 1.21. Version 1.22 fixes a compilation issue with +gcc 4.0. In order to fix this issue I rewrote part of the library to remove some unnecessary templates. +This should make the code cleaner. The Borland Project files were removed. If you want to use it +with Borland either use the dll version or create your own project files. I can't support it since I don't +have this compiler at hand. + +Changes: + + Project Changes: + * Borland project files removed + (The code should still compile with BCB but I can't provide you with project files) + + Internal Changes: + * unnecessary template files have been removed: + - new files: muParserError.cpp, muParserTokenReader.cpp, muParserCallback.cpp + - removed Files: muIParserTypes.h + + +Rev 1.2 / 1.21: April, 2005 +--------------------------- + +Release Notes: +First of all the interface has changed so this version is not backwards compatible. +After receiving a couple of questions about it, this version features support for +user defined binary operators. Consequently the built in operators can now be +turned off, thus you can deactivate them and write complete customized parser +subclasses that only contain the functionality you want. Another new feature is +the introduction of callback functions taking string arguments, implicit +generation of variables and the Assignment operator. + + Functionality + * New built in operator: xor; Logical xor. + * New built in operator: Assignment operator; Defining variables in terms of + other variables/constants + * New feature: Strings as arguments for callback functions + * New feature: User defined binary operators + * New feature: ParserInt a class with a sample implementation for + integer numbers. + * New feature: Callbacks to value regognition functions. + + * Removed: all predefined postfix operators have been removed. + * New project file: Now comes with a ready to use windows DLL. + * New project file: Makefile for cygwin now included. + * New example: Example3 shows usage of the DLL. + + Interface changes + * New member function: DefineOprt For adding user defined binary operators. + * New member function: EnableBuiltInOprt(bool) Enables/Disables built in + binary operators. + * New member function: AddValIdent(...) to add callbacks for custom value + recognition functions. + * Removed: SetVar(), SetConst(). + * Renamed: Most interface functions have been renamed + * Changed: The type for multiargument callbacks multfun_type has changed. + It no longer takes a std::vector as input. + + Internal changes + * new class muParserTokenReader.h encapsulates the token identification + and token assignment. + * Internal handling of function callbacks unified as a result the performance + of the bytecode evaluation increased. + + +Rev 1.10 : December 30, 2004 +---------------------------- + +Release Notes: +This version does not contain major new feature compared to V1.07 but its internal structure has +changed significantly. The String parsing routine is slower than the one of V1.07 but bytecode +parsing is equally fast. On the other hand the error messages of V1.09 are more flexible and you +can change its value datatype. It should work on 64-bit systems. For this reason I supply both +versions for download. If you use V1.07 and are happy with it there is no need for updating +your version. + + * New example program: Archive now contains two demo programs: One for standard C++ and one for + managed C++. + * New member function: RemoveVar(...) can be used for removing a single variable from the internal + storage. + * New member function: GetVar() can be used for querying the variable names and pointers of all + variables defined in the parser. + * New member function: GetConst() can be used for querying all defined constants and their values. + * New member function: GetFunDef() can be used for querying all defined functions and the number of + arguments they expect. + * Internal structure changed; hanging base datatype at compile time is now possible. + * Bugfix: Postfix operator parsing could fail in certain cases; This has been fixed now. + * Bugfix: Variable names must will now be tested if they conflict with constant or function names. + * Internal change: Removed most dependencies from the C-string libraries. + * Internal change: Bytecode is now stored in a separate class: ParserByteCode.h + * Internal change: GetUsedVar() does no longer require that variables are defined at time of call. + * Internal change: Error treatment changed. ParserException is no longer derived from + std::runtime_error; Internal treatment of Error messages changed. + * New functions in Parser interface: ValidNameChars(), ValidOprtChars() and ValidPrefixOprtChars() + they are used for defining the charset allowed for variable-, operator- and + function names. + + +Rev 1.09 : November 20, 2004 +---------------------------- + + * New member function: RemoveVar(...) can be used for removing a single variable from the internal + storage. + * Internal structure changed; changing base datatype at compile time is now possible. + * Bug fix: Postfix operator parsing could fail in certain cases; This has been fixed now. + * Internal change: Removed most dependencies from the C-string libraries. + * Internal change: Bytecode is now stored in a separate class: ParserByteCode.h. + * Internal change: GetUsedVar() does no longer require that variables are defined at time of call. + * Internal change: Error treatment changed. ParserException is no longer derived from + std::runtime_error; Internal treatment of Error messages changed. + * New functions in Parser interface; ValidNameChars(), ValidOprtChars() and ValidPrefixOprtChars() + they are used for defining the charset allowed for variable-, operator- and function names. + + +Rev 1.08 : November, 2004 +------------------------- + + * unpublished; experimental template version with respect to data type and underlying string + type (string <-> widestring). The idea was dropped... + + +Rev 1.07 : September 4 2004 +--------------------------- + + * Improved portability; Changes to make life for MSVC 6 user easier, there are probably still some + issues left. + * Improved portability; Changes in order to allow compiling on BCB. + * New function; value_type Diff(value_type *a_Var, value_type a_fPos) 4th order Differentiation with + respect to a certain variable; added in muParser.h. + + +Rev 1.06 : August 20 2004 +------------------------- + + * Volatile functions added; All overloaded AddFun(...) functions can now take a third parameter + indicating that the function can not be optimized. + * Internal changes: muParserStack.h simplified; refactorings + * Parser is now distributed under the MIT License; all comments changed accordingly. + + +Rev 1.05 : August 20 2004 +------------------------- + + * Variable/constant names will now be checked for invalid characters. + * Querying the names of all variables used in an expression is now possible; new function: GetUsedVar(). + * Disabling bytecode parsing is now possible; new function: EnableByteCode(bool bStat). + * Predefined functions with variable number of arguments added: sum, avg, min, max. + * Unary prefix operators added; new functions: AddPrefixOp(...), ClearPrefixOp(). + * Postfix operator interface names changed; new function names: AddPostfixOp(...), ClearPostfixOp(). + * Hardcoded sign operators removed in favor of prefix operators; bytecode format changed accordingly. + * Internal changes: static array removed in Command code calculation routine; misc. changes. + + +Rev 1.04 : August 16 2004 +------------------------- + + * Support for functions with variable number of arguments added. + * Internal structure changed; new: ParserBase.h, ParserBase.cpp; removed: ParserException.h; + changed: Parser.h, Parser.cpp. + * Bug in the bytecode calculation function fixed (affected the unary minus operator). + * Optimizer can be deactivated; new function: EnableOptimizer(bool bStat). + + +Rev 1.03 : August 10 2004 +------------------------- + + * Support for user-defined unary postfix operators added; new functions: AddPostOp(), InitPostOp(), + ClearPostOp(). + * Minor changes to the bytecode parsing routine. + * User defined functions can now have up to four parameters. + * Performance optimized: simple formula optimization added; (precalculation of constant parts of the + expression). + * Bug fixes: Multi-arg function parameters, constant name lookup and unary minus did not work properly. + + +Rev 1.02 : July 30 2004 +----------------------- + + * Support for user defined constants added; new functions: InitConst(), AddConst(), SetConst(), + ClearConst(). + * Single variables can now be added using AddVar(); you have now the choice of adding them either + one by one or all at the same time using SetVar(const varmap_type &a_vVar). + * Internal handling of variables changed, is now similar to function handling. + * Virtual destructor added; InitFun(), InitConst() are now virtual too thus making it possible to + derive new parsers with a modified set of default functions and constants. + * Support for user defined functions with 2 or 3 parameters added; bytecode format changed to hold + function parameter count. + + +Rev 1.01 : July 23 2004 +----------------------- + + * Support for user defined functions has been added; new functions: AddFun(), ClearFun(), + InitFunctions(). + * Built in constants have been removed; the parser contained undocumented built in + constants pi, e. + There was the possibility of name conflicts with user defined variables. + * Setting multiple variables with SetVar can now be done with a map of names and pointers as the only + argument. For this reason, a new type Parser::varmap_type was added. The old version that took 3 + arguments (array of names, array of pointers, and array length) is now marked as deprecated. + * The names of logarithm functions have changed. The new names are: log2 for base 2, log10 or log for + base 10, and ln for base e. + + +Rev 1.00 : July 21 2004 +----------------------- + + * Initial release diff --git a/3rdParty/MuParser/Install.txt b/3rdParty/MuParser/Install.txt index 95d365de3ccd03b52a8ff3346fa6e4276346c3a2..06095017a9f03b1857f00a4bc9129d91f2ee8a96 100644 --- a/3rdParty/MuParser/Install.txt +++ b/3rdParty/MuParser/Install.txt @@ -1,133 +1,68 @@ -####################################################################### -# # -# # -# __________ # -# _____ __ __\______ \_____ _______ ______ ____ _______ # -# / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ # -# | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ # -# |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| # -# \/ \/ \/ \/ # -# Fast math parser Library # -# # -# Copyright (C) 2012 Ingo Berg # -# # -# Web: muparser.beltoforion.de # -# e-mail: muparser@beltoforion.de # -# # -# # -####################################################################### - - - - Contents - ======== - - 1. Installation on win32 - 2. Installation on unix - 2.1 Other miscellaneous info Unix-specific - 3. Where to ask for help - - - - 1. Installation on win32 - ======================== - - muParser supports various win32 command-line compilers: - -> mingw - -> watcom - -> microsoft CL - and provides also the project files for MSVC6 IDE. - - In order to compile muParser from makefiles, open an MSDOS - prompt and then move to the muParser/build directory and - type: - - mingw32-make -fmakefile.mingw for mingw - nmake -fmakefile.vc for msvc - make -fmakefile.bcc for borland - wmake -fmakefile.wat for watcom - - All makefiles supports the following options: - - # Set to 1 to build debug version [0,1] - # 0 - Release - # 1 - Debug - DEBUG = 0 - - # Set to 1 to build shared (DLL) version [0,1] - # 0 - Static - # 1 - DLL - SHARED = 0 - - # Set to 1 to compile samples [0,1] - SAMPLES = 1 - - The muParser library is created in the 'lib' folder and the sample - binaries are created in samples\example1 or samples\example2. - - NOTE: samples\example1 can be compiled *only* when building - muParser as a STATIC library (SHARED=0). - samples\example2 can be compiled *only* when building - muParser as a SHARED library (SHARED=1). - - - - 2. Installation on Unix/Linux - ============================= - - muParser can be installed just extracting the sources somewhere - and then, from a terminal, typing: - - cd [path to muParser] - ./configure [--enable-shared=yes/no] [--enable-samples=yes/no] - [--enable-debug=yes/no] - make - [sudo*] make install - [sudo*] ldconfig - cd samples/example1 - ./example1 - - * = this command must be executed with root permissions and thus - you have to use 'sudo' or just 'su' to gain root access. - Note that installation and ldconfig are not strictly required unless - you built in shared mode. - - The "make" step will create the muParser library in 'lib' and the - sample binary in samples/example1. - The samples/example2 is win32-specific and thus won't be built. - - - - 2.1 Other miscellaneous info Unix-specific - ========================================== - - If you don't like to have your muParser folder filled by temporary - files created by GCC, then you can do the following: - - mkdir mybuild && cd mybuild && ../configure && make - - to put all object files in the "mybuild" directory. - - If you want to use muParser library in your programs, you can use - the pkg-config program (this works only if muParser was installed - with 'make install' !). The commands: - - pkg-config muparser --cflags - pkg-config muparser --libs - - will return all useful info you need to build your programs against - muParser ! - - - - 3. Where to ask for help - ======================== - - If you find problems with either compilation, installation or usage - of muParser, then you can ask in the muParser forum at: - - https://sourceforge.net/forum/forum.php?forum_id=462843 - - For more info about muParser, visit: - http://sourceforge.net/projects/muparser/ - http://muparser.sourceforge.net + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + +======================================================================= + https://muparser.beltoforion.de +======================================================================= + + Installation + ============ + + muParser can be installed just extracting the sources somewhere + and then, from a terminal, typing: + + cd [path to muParser] + cmake . [-DENABLE_SAMPLES=ON/OFF] [-DENABLE_OPENMP=OFF/ON] + [-DBUILD_SHARED_LIBS=ON/OFF] + make + [sudo*] make install + [sudo*] ldconfig + cd samples/example1 + ./example1 + + * = this command must be executed with root permissions and thus + you have to use 'sudo' or just 'su' to gain root access. + Note that installation and ldconfig are not strictly required unless + you built in shared mode. + + The "make" step will create the muParser library in 'lib' and the + sample binary in samples/example1. + The samples/example2 is win32-specific and thus won't be built. + + + + Other miscellaneous info Unix-specific + ====================================== + + If you don't like to have your muParser folder filled by temporary + files created by GCC, then you can do the following: + + mkdir mybuild && cd mybuild && cmake .. && make + + to put all object files in the "mybuild" directory. + + If you want to use muParser library in your programs, you can use + the pkg-config program (this works only if muParser was installed + with 'make install' !). The commands: + + pkg-config muparser --cflags + pkg-config muparser --libs + + will return all useful info you need to build your programs against + muParser ! + + + + 3. Where to ask for help + ======================== + + Please report any bugs or issues at the muparser project page at GitHub: + + https://github.com/beltoforion/muparser/issues + + \ No newline at end of file diff --git a/3rdParty/MuParser/License.txt b/3rdParty/MuParser/License.txt index c4c0d2b1313f5530c7357a6df9998fd0c418c49d..556ceba18322a4320c8735977cccb6526f9f7332 100644 --- a/3rdParty/MuParser/License.txt +++ b/3rdParty/MuParser/License.txt @@ -1,35 +1,35 @@ -####################################################################### -# # -# # -# __________ # -# _____ __ __\______ \_____ _______ ______ ____ _______ # -# / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ # -# | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ # -# |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| # -# \/ \/ \/ \/ # -# Fast math parser Library # -# # -# Copyright (C) 2011 Ingo Berg # -# # -# Web: muparser.beltoforion.de # -# e-mail: muparser@beltoforion.de # -# # -# # -####################################################################### - - - 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. - OR OTHER DEALINGS IN THE SOFTWARE. + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Fast math parser Library + + Copyright (C) 2004 - 2020 Ingo Berg + + Web: https://muparser.beltoforion.de + Git: https://github.com/beltoforion/muparser + + This software is distributed under the terms of the + BSD - Clause 2 "Simplified" or "FreeBSD" Licence (BSD-2-Clause) + +############################################################################################### + +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/3rdParty/MuParser/README.rst b/3rdParty/MuParser/README.rst new file mode 100644 index 0000000000000000000000000000000000000000..4811b64175b609bc301f3ab07e9fc0f76dffd34c --- /dev/null +++ b/3rdParty/MuParser/README.rst @@ -0,0 +1,75 @@ +.. image:: https://travis-ci.org/beltoforion/muparser.svg?branch=master + :target: https://travis-ci.org/beltoforion/muparser + +.. image:: https://ci.appveyor.com/api/projects/status/u4882uj8btuspj9x?svg=true + :target: https://ci.appveyor.com/project/jschueller/muparser-9ib44 + +muparser - Fast Math Parser 2.3.2 +=========================== + +For a detailed description of the parser go to http://beltoforion.de/article.php?a=muparser. + +See Install.txt for installation + +Change Notes for Revision 2.3.2 +------------ +Changes: +------------ +* removed "final" keyword from Parser class since this API change broke multiple client applications + +Security Fixes: +------------ +The following issue was present in all older releases. + +* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23410 (Heap-buffer-overflow) + +API and ABI compliance check with version 2.2.6 +------------ + +Version 2.3 will extend existing enumerators. New Error codes have been added. In the muparser base class protected functions for implementing basic mathematical operations such as sin,cos, sqrt,tan,... have been removed. + +The binary interface should be compatible with versions 2.2.6 unless the parser is used in ways that i did not forsee. I checked the compliance against the sample application compiled for 2.2.6 by exchanging the library with the new version 2.3. I did not see any problems. You can find a complete ABI compliance report here: + +https://www.beltoforion.de/en/muparser/compat_reports/2.2.6_to_2.3.2/compat_report.html + +I recommend replacing existing versions of 2.2.6 with version 2.3.2. Please report all incompatibilities that you find (API and ABI). I will try to fix them before the final release (if reasonable) + + +Change Notes for Revision 2.3.1 +------------ +No changes, only prereleases exist. Version 2.3.2 replaced them. + + +Change Notes for Revision 2.3.0 +------------ + +Version 2.3.0 will bring fixes for parsing in bulk mode. It will enable OpenMP by default thus allowing the parallelization of expression evaluation. It will also fix a range of issues reported by oss-fuz (https://github.com/google/oss-fuzz). + +Changes: +------------ + +* using OpenMP is now the default settings for cmake based builds +* added optimization for trivial expressions. (Expressions with an RPN length of 1) +* introduced a maximum length for expressions (5000 Character) +* introduced a maximum length for identifiers (100 Characters) +* removed the MUP_MATH_EXCEPTION macro and related functionality. (C++ exceptions for divide by zero or sqrt of a negative number are no longer supported) +* removed ParserStack.h (replaced with std::stack) +* removed macros for defining E and PI +* the MUP_ASSERT macro is no longer removed in release builds for better protection against segmentation faults + +Security Fixes: +------------ + +Fixed several issues reported by oss-fuzz. The issues were present in older releases. Most of them resulted in segmentation faults. + +* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23330 +* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22922 +* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22938 +* https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23330 +* Added additional runtime checks for release builds to prevent segmentation faults for invalid expressions + +Bugfixes: +------------ + +* Fixed an issue where the bulk mode could hang on GCC/CLANG builds due to OpenMP chunksize dropping below 1. + diff --git a/3rdParty/MuParser/docs/Doxyfile b/3rdParty/MuParser/docs/Doxyfile index 9793afe34369e1dc4c9300d19984a89952d06ee1..842ecf114743f5a96fafc815855bb78859100033 100644 --- a/3rdParty/MuParser/docs/Doxyfile +++ b/3rdParty/MuParser/docs/Doxyfile @@ -282,7 +282,7 @@ TYPEDEF_HIDES_STRUCT = NO # causing a significant performance penality. # If the system has enough physical memory increasing the cache will improve the # performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will rougly double the +# a logarithmic scale so increasing the size by one will roughly double the # memory usage. The cache size is given by this formula: # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, # corresponding to a cache size of 2^16 = 65536 symbols diff --git a/3rdParty/MuParser/include/muParser.h b/3rdParty/MuParser/include/muParser.h index 39fe137fe7386dc793aef31bff94296cfe6b6e12..321fba9c793179e29ce50438a332547fd1a3927f 100644 --- a/3rdParty/MuParser/include/muParser.h +++ b/3rdParty/MuParser/include/muParser.h @@ -1,115 +1,71 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2013 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_H -#define MU_PARSER_H - -//--- Standard includes ------------------------------------------------------------------------ -#include <vector> - -//--- Parser includes -------------------------------------------------------------------------- -#include "muParserBase.h" -#include "muParserTemplateMagic.h" - -/** \file - \brief Definition of the standard floating point parser. -*/ - -namespace mu -{ - /** \brief Mathematical expressions parser. - - Standard implementation of the mathematical expressions parser. - Can be used as a reference implementation for subclassing the parser. - - <small> - (C) 2011 Ingo Berg<br> - muparser(at)beltoforion.de - </small> - */ - /* final */ class Parser : public ParserBase - { - public: - - Parser(); - - virtual void InitCharSets(); - virtual void InitFun(); - virtual void InitConst(); - virtual void InitOprt(); - virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd); - - value_type Diff(value_type *a_Var, - value_type a_fPos, - value_type a_fEpsilon = 0) const; - - protected: - - // Trigonometric functions - static value_type Sin(value_type); - static value_type Cos(value_type); - static value_type Tan(value_type); - static value_type Tan2(value_type, value_type); - // arcus functions - static value_type ASin(value_type); - static value_type ACos(value_type); - static value_type ATan(value_type); - static value_type ATan2(value_type, value_type); - - // hyperbolic functions - static value_type Sinh(value_type); - static value_type Cosh(value_type); - static value_type Tanh(value_type); - // arcus hyperbolic functions - static value_type ASinh(value_type); - static value_type ACosh(value_type); - static value_type ATanh(value_type); - // Logarithm functions - static value_type Log2(value_type); // Logarithm Base 2 - static value_type Log10(value_type); // Logarithm Base 10 - static value_type Ln(value_type); // Logarithm Base e (natural logarithm) - // misc - static value_type Exp(value_type); - static value_type Abs(value_type); - static value_type Sqrt(value_type); - static value_type Rint(value_type); - static value_type Sign(value_type); - - // 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 - static value_type Avg(const value_type*, int); // mean value - static value_type Min(const value_type*, int); // minimum - static value_type Max(const value_type*, int); // maximum - - static int IsVal(const char_type* a_szExpr, int *a_iPos, value_type *a_fVal); - }; -} // namespace mu - -#endif - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_H +#define MU_PARSER_H + +//--- Standard includes ------------------------------------------------------------------------ +#include <vector> + +//--- Parser includes -------------------------------------------------------------------------- +#include "muParserBase.h" +#include "muParserTemplateMagic.h" + +/** \file + \brief Definition of the standard floating point parser. +*/ + +namespace mu +{ + /** \brief Mathematical expressions parser. + + Standard implementation of the mathematical expressions parser. + Can be used as a reference implementation for subclassing the parser. + */ + class API_EXPORT_CXX Parser : public ParserBase + { + public: + + Parser(); + + virtual void InitCharSets(); + virtual void InitFun(); + virtual void InitConst(); + virtual void InitOprt(); + virtual void OnDetectVar(string_type* pExpr, int& nStart, int& nEnd); + + value_type Diff(value_type* a_Var, value_type a_fPos, value_type a_fEpsilon = 0) const; + + protected: + + static int IsVal(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal); + }; +} // namespace mu + +#endif + diff --git a/3rdParty/MuParser/include/muParserBase.h b/3rdParty/MuParser/include/muParserBase.h index beb15bb198080beb26543f131c65c7625b3134b3..7793818a9c90a6f40c3df877099ed53d135f5f91 100644 --- a/3rdParty/MuParser/include/muParserBase.h +++ b/3rdParty/MuParser/include/muParserBase.h @@ -1,317 +1,294 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2013 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_BASE_H -#define MU_PARSER_BASE_H - -//--- Standard includes ------------------------------------------------------------------------ -#include <cmath> -#include <string> -#include <iostream> -#include <map> -#include <memory> -#include <locale> -#include <limits.h> - -//--- Parser includes -------------------------------------------------------------------------- -#include "muParserDef.h" -#include "muParserStack.h" -#include "muParserTokenReader.h" -#include "muParserBytecode.h" -#include "muParserError.h" - - -namespace mu -{ -/** \file - \brief This file contains the class definition of the muparser engine. -*/ - -//-------------------------------------------------------------------------------------------------- -/** \brief Mathematical expressions parser (base parser engine). - \author (C) 2013 Ingo Berg - - This is the implementation of a bytecode based mathematical expressions parser. - The formula will be parsed from string and converted into a bytecode. - Future calculations will be done with the bytecode instead the formula string - resulting in a significant performance increase. - Complementary to a set of internally implemented functions the parser is able to handle - user defined functions and variables. -*/ -class ParserBase -{ -friend class ParserTokenReader; - -private: - - /** \brief Typedef for the parse functions. - - The parse function do the actual work. The parser exchanges - the function pointer to the parser function depending on - which state it is in. (i.e. bytecode parser vs. string parser) - */ - typedef value_type (ParserBase::*ParseFunction)() const; - - /** \brief Type used for storing an array of values. */ - typedef std::vector<value_type> valbuf_type; - - /** \brief Type for a vector of strings. */ - typedef std::vector<string_type> stringbuf_type; - - /** \brief Typedef for the token reader. */ - typedef ParserTokenReader token_reader_type; - - /** \brief Type used for parser tokens. */ - typedef ParserToken<value_type, string_type> token_type; - - /** \brief Maximum number of threads spawned by OpenMP when using the bulk mode. */ - static const int s_MaxNumOpenMPThreads = 16; - - public: - - /** \brief Type of the error class. - - Included for backwards compatibility. - */ - typedef ParserError exception_type; - - static void EnableDebugDump(bool bDumpCmd, bool bDumpStack); - - ParserBase(); - ParserBase(const ParserBase &a_Parser); - ParserBase& operator=(const ParserBase &a_Parser); - - virtual ~ParserBase(); - - value_type Eval() const; - value_type* Eval(int &nStackSize) const; - void Eval(value_type *results, int nBulkSize); - - int GetNumResults() const; - - void SetExpr(const string_type &a_sExpr); - void SetVarFactory(facfun_type a_pFactory, void *pUserData = NULL); - - void SetDecSep(char_type cDecSep); - void SetThousandsSep(char_type cThousandsSep = 0); - void ResetLocale(); - - void EnableOptimizer(bool a_bIsOn=true); - void EnableBuiltInOprt(bool a_bIsOn=true); - - bool HasBuiltInOprt() const; - void AddValIdent(identfun_type a_pCallback); - - /** \fn void mu::ParserBase::DefineFun(const string_type &a_strName, fun_type0 a_pFun, bool a_bAllowOpt = true) - \brief Define a parser function without arguments. - \param a_strName Name of the function - \param a_pFun Pointer to the callback function - \param a_bAllowOpt A flag indicating this function may be optimized - */ - template<typename T> - void DefineFun(const string_type &a_strName, T a_pFun, bool a_bAllowOpt = true) - { - AddCallback( a_strName, ParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars() ); - } - - void DefineOprt(const string_type &a_strName, - fun_type2 a_pFun, - unsigned a_iPri=0, - EOprtAssociativity a_eAssociativity = oaLEFT, - bool a_bAllowOpt = false); - void DefineConst(const string_type &a_sName, value_type a_fVal); - void DefineStrConst(const string_type &a_sName, const string_type &a_strVal); - void DefineVar(const string_type &a_sName, value_type *a_fVar); - void DefinePostfixOprt(const string_type &a_strFun, fun_type1 a_pOprt, bool a_bAllowOpt=true); - void DefineInfixOprt(const string_type &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX, bool a_bAllowOpt=true); - - // Clear user defined variables, constants or functions - void ClearVar(); - void ClearFun(); - void ClearConst(); - void ClearInfixOprt(); - void ClearPostfixOprt(); - void ClearOprt(); - - void RemoveVar(const string_type &a_strVarName); - const varmap_type& GetUsedVar() const; - const varmap_type& GetVar() const; - const valmap_type& GetConst() const; - const string_type& GetExpr() const; - const funmap_type& GetFunDef() const; - string_type GetVersion(EParserVersionInfo eInfo = pviFULL) const; - - const char_type ** GetOprtDef() const; - void DefineNameChars(const char_type *a_szCharset); - void DefineOprtChars(const char_type *a_szCharset); - void DefineInfixOprtChars(const char_type *a_szCharset); - - const char_type* ValidNameChars() const; - const char_type* ValidOprtChars() const; - const char_type* ValidInfixOprtChars() const; - - void SetArgSep(char_type cArgSep); - char_type GetArgSep() const; - - void Error(EErrorCodes a_iErrc, - int a_iPos = (int)mu::string_type::npos, - const string_type &a_strTok = string_type() ) const; - - protected: - - void Init(); - - virtual void InitCharSets() = 0; - virtual void InitFun() = 0; - virtual void InitConst() = 0; - virtual void InitOprt() = 0; - - virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd); - - static const char_type *c_DefaultOprt[]; - static std::locale s_locale; ///< The locale used by the parser - static bool g_DbgDumpCmdCode; - static bool g_DbgDumpStack; - - /** \brief A facet class used to change decimal and thousands separator. */ - template<class TChar> - class change_dec_sep : public std::numpunct<TChar> - { - public: - - explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3) - :std::numpunct<TChar>() - ,m_nGroup(nGroup) - ,m_cDecPoint(cDecSep) - ,m_cThousandsSep(cThousandsSep) - {} - - protected: - - virtual char_type do_decimal_point() const - { - return m_cDecPoint; - } - - virtual char_type do_thousands_sep() const - { - return m_cThousandsSep; - } - - virtual std::string do_grouping() const - { - // 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: - - int m_nGroup; - char_type m_cDecPoint; - char_type m_cThousandsSep; - }; - - private: - - void Assign(const ParserBase &a_Parser); - void InitTokenReader(); - void ReInit() const; - - void AddCallback( const string_type &a_strName, - const ParserCallback &a_Callback, - funmap_type &a_Storage, - const char_type *a_szCharSet ); - - void ApplyRemainingOprt(ParserStack<token_type> &a_stOpt, - ParserStack<token_type> &a_stVal) const; - void ApplyBinOprt(ParserStack<token_type> &a_stOpt, - ParserStack<token_type> &a_stVal) const; - - void ApplyIfElse(ParserStack<token_type> &a_stOpt, - ParserStack<token_type> &a_stVal) const; - - void ApplyFunc(ParserStack<token_type> &a_stOpt, - ParserStack<token_type> &a_stVal, - int iArgCount) const; - - token_type ApplyStrFunc(const token_type &a_FunTok, - const std::vector<token_type> &a_vArg) const; - - int GetOprtPrecedence(const token_type &a_Tok) const; - EOprtAssociativity GetOprtAssociativity(const token_type &a_Tok) const; - - void CreateRPN() const; - - value_type ParseString() const; - value_type ParseCmdCode() const; - value_type ParseCmdCodeBulk(int nOffset, int nThreadID) const; - - void CheckName(const string_type &a_strName, const string_type &a_CharSet) const; - void CheckOprt(const string_type &a_sName, - const ParserCallback &a_Callback, - const string_type &a_szCharSet) const; - - void StackDump(const ParserStack<token_type > &a_stVal, - const ParserStack<token_type > &a_stOprt) const; - - /** \brief Pointer to the parser function. - - Eval() calls the function whose address is stored there. - */ - mutable ParseFunction m_pParseFormula; - mutable ParserByteCode m_vRPN; ///< The Bytecode class. - mutable stringbuf_type m_vStringBuf; ///< String buffer, used for storing string function arguments - stringbuf_type m_vStringVarBuf; - - std::auto_ptr<token_reader_type> m_pTokenReader; ///< Managed pointer to the token reader object. - - funmap_type m_FunDef; ///< Map of function names and pointers. - funmap_type m_PostOprtDef; ///< Postfix operator callbacks - funmap_type m_InfixOprtDef; ///< unary infix operator. - funmap_type m_OprtDef; ///< Binary operator callbacks - valmap_type m_ConstDef; ///< user constants. - strmap_type m_StrVarDef; ///< user defined string constants - varmap_type m_VarDef; ///< user defind variables. - - bool m_bBuiltInOp; ///< Flag that can be used for switching built in operators on and off - - string_type m_sNameChars; ///< Charset for names - string_type m_sOprtChars; ///< Charset for postfix/ binary operator tokens - string_type m_sInfixOprtChars; ///< Charset for infix operator tokens - - mutable int m_nIfElseCounter; ///< Internal counter for keeping track of nested if-then-else clauses - - // items merely used for caching state information - mutable valbuf_type m_vStackBuffer; ///< This is merely a buffer used for the stack in the cmd parsing routine - mutable int m_nFinalResultIdx; -}; - -} // namespace mu - -#endif - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_BASE_H +#define MU_PARSER_BASE_H + +//--- Standard includes ------------------------------------------------------------------------ +#include <cmath> +#include <string> +#include <iostream> +#include <map> +#include <memory> +#include <locale> +#include <limits.h> + +//--- Parser includes -------------------------------------------------------------------------- +#include "muParserDef.h" +#include "muParserTokenReader.h" +#include "muParserBytecode.h" +#include "muParserError.h" + + +namespace mu +{ + /** \file + \brief This file contains the class definition of the muparser engine. + */ + + /** \brief Mathematical expressions parser (base parser engine). + + This is the implementation of a bytecode based mathematical expressions parser. + The formula will be parsed from string and converted into a bytecode. + Future calculations will be done with the bytecode instead the formula string + resulting in a significant performance increase. + Complementary to a set of internally implemented functions the parser is able to handle + user defined functions and variables. + */ + class API_EXPORT_CXX ParserBase + { + friend class ParserTokenReader; + + private: + + /** \brief Typedef for the parse functions. + + The parse function do the actual work. The parser exchanges + the function pointer to the parser function depending on + which state it is in. (i.e. bytecode parser vs. string parser) + */ + typedef value_type(ParserBase::* ParseFunction)() const; + + /** \brief Type used for storing an array of values. */ + typedef std::vector<value_type> valbuf_type; + + /** \brief Type for a vector of strings. */ + typedef std::vector<string_type> stringbuf_type; + + /** \brief Typedef for the token reader. */ + typedef ParserTokenReader token_reader_type; + + /** \brief Type used for parser tokens. */ + typedef ParserToken<value_type, string_type> token_type; + + /** \brief Maximum number of threads spawned by OpenMP when using the bulk mode. */ + static const int s_MaxNumOpenMPThreads; + + public: + + /** \brief Type of the error class. + + Included for backwards compatibility. + */ + typedef ParserError exception_type; + + static void EnableDebugDump(bool bDumpCmd, bool bDumpStack); + + ParserBase(); + ParserBase(const ParserBase& a_Parser); + ParserBase& operator=(const ParserBase& a_Parser); + + virtual ~ParserBase(); + + value_type Eval() const; + value_type* Eval(int& nStackSize) const; + void Eval(value_type* results, int nBulkSize); + + int GetNumResults() const; + + void SetExpr(const string_type& a_sExpr); + void SetVarFactory(facfun_type a_pFactory, void* pUserData = nullptr); + + void SetDecSep(char_type cDecSep); + void SetThousandsSep(char_type cThousandsSep = 0); + void ResetLocale(); + + void EnableOptimizer(bool a_bIsOn = true); + void EnableBuiltInOprt(bool a_bIsOn = true); + + bool HasBuiltInOprt() const; + void AddValIdent(identfun_type a_pCallback); + + /** \fn void mu::ParserBase::DefineFun(const string_type &a_strName, fun_type0 a_pFun, bool a_bAllowOpt = true) + \brief Define a parser function without arguments. + \param a_strName Name of the function + \param a_pFun Pointer to the callback function + \param a_bAllowOpt A flag indicating this function may be optimized + */ + template<typename T> + void DefineFun(const string_type& a_strName, T a_pFun, bool a_bAllowOpt = true) + { + AddCallback(a_strName, ParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars()); + } + + void DefineOprt(const string_type& a_strName, fun_type2 a_pFun, unsigned a_iPri = 0, EOprtAssociativity a_eAssociativity = oaLEFT, bool a_bAllowOpt = false); + void DefineConst(const string_type& a_sName, value_type a_fVal); + void DefineStrConst(const string_type& a_sName, const string_type& a_strVal); + void DefineVar(const string_type& a_sName, value_type* a_fVar); + void DefinePostfixOprt(const string_type& a_strFun, fun_type1 a_pOprt, bool a_bAllowOpt = true); + void DefineInfixOprt(const string_type& a_strName, fun_type1 a_pOprt, int a_iPrec = prINFIX, bool a_bAllowOpt = true); + + // Clear user defined variables, constants or functions + void ClearVar(); + void ClearFun(); + void ClearConst(); + void ClearInfixOprt(); + void ClearPostfixOprt(); + void ClearOprt(); + + void RemoveVar(const string_type& a_strVarName); + const varmap_type& GetUsedVar() const; + const varmap_type& GetVar() const; + const valmap_type& GetConst() const; + const string_type& GetExpr() const; + const funmap_type& GetFunDef() const; + string_type GetVersion(EParserVersionInfo eInfo = pviFULL) const; + + const char_type** GetOprtDef() const; + void DefineNameChars(const char_type* a_szCharset); + void DefineOprtChars(const char_type* a_szCharset); + void DefineInfixOprtChars(const char_type* a_szCharset); + + const char_type* ValidNameChars() const; + const char_type* ValidOprtChars() const; + const char_type* ValidInfixOprtChars() const; + + void SetArgSep(char_type cArgSep); + char_type GetArgSep() const; + + protected: + + void Init(); + void Error(EErrorCodes a_iErrc, int a_iPos = (int)mu::string_type::npos, const string_type& a_strTok = string_type()) const; + + virtual void InitCharSets() = 0; + virtual void InitFun() = 0; + virtual void InitConst() = 0; + virtual void InitOprt() = 0; + + virtual void OnDetectVar(string_type* pExpr, int& nStart, int& nEnd); + + static const char_type* c_DefaultOprt[]; + static std::locale s_locale; ///< The locale used by the parser + static bool g_DbgDumpCmdCode; + static bool g_DbgDumpStack; + + /** \brief A facet class used to change decimal and thousands separator. */ + template<class TChar> + class change_dec_sep : public std::numpunct<TChar> + { + public: + + explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3) + :std::numpunct<TChar>() + , m_nGroup(nGroup) + , m_cDecPoint(cDecSep) + , m_cThousandsSep(cThousandsSep) + {} + + protected: + + virtual char_type do_decimal_point() const + { + return m_cDecPoint; + } + + virtual char_type do_thousands_sep() const + { + return m_cThousandsSep; + } + + virtual std::string do_grouping() const + { + // 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: + + int m_nGroup; + char_type m_cDecPoint; + char_type m_cThousandsSep; + }; + + private: + + void Assign(const ParserBase& a_Parser); + void InitTokenReader(); + void ReInit() const; + + void AddCallback(const string_type& a_strName, const ParserCallback& a_Callback, funmap_type& a_Storage, const char_type* a_szCharSet); + void ApplyRemainingOprt(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal) const; + void ApplyBinOprt(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal) const; + void ApplyIfElse(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal) const; + void ApplyFunc(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal, int iArgCount) const; + + token_type ApplyStrFunc(const token_type& a_FunTok, const std::vector<token_type>& a_vArg) const; + + int GetOprtPrecedence(const token_type& a_Tok) const; + EOprtAssociativity GetOprtAssociativity(const token_type& a_Tok) const; + + void CreateRPN() const; + + value_type ParseString() const; + value_type ParseCmdCode() const; + value_type ParseCmdCodeShort() const; + value_type ParseCmdCodeBulk(int nOffset, int nThreadID) const; + + void CheckName(const string_type& a_strName, const string_type& a_CharSet) const; + void CheckOprt(const string_type& a_sName, const ParserCallback& a_Callback, const string_type& a_szCharSet) const; + + void StackDump(const std::stack<token_type >& a_stVal, const std::stack<token_type >& a_stOprt) const; + + /** \brief Pointer to the parser function. + + Eval() calls the function whose address is stored there. + */ + mutable ParseFunction m_pParseFormula; + mutable ParserByteCode m_vRPN; ///< The Bytecode class. + mutable stringbuf_type m_vStringBuf; ///< String buffer, used for storing string function arguments + stringbuf_type m_vStringVarBuf; + + std::unique_ptr<token_reader_type> m_pTokenReader; ///< Managed pointer to the token reader object. + + funmap_type m_FunDef; ///< Map of function names and pointers. + funmap_type m_PostOprtDef; ///< Postfix operator callbacks + funmap_type m_InfixOprtDef; ///< unary infix operator. + funmap_type m_OprtDef; ///< Binary operator callbacks + valmap_type m_ConstDef; ///< user constants. + strmap_type m_StrVarDef; ///< user defined string constants + varmap_type m_VarDef; ///< user defind variables. + + bool m_bBuiltInOp; ///< Flag that can be used for switching built in operators on and off + + string_type m_sNameChars; ///< Charset for names + string_type m_sOprtChars; ///< Charset for postfix/ binary operator tokens + string_type m_sInfixOprtChars; ///< Charset for infix operator tokens + + // items merely used for caching state information + mutable valbuf_type m_vStackBuffer; ///< This is merely a buffer used for the stack in the cmd parsing routine + mutable int m_nFinalResultIdx; + }; + +} // namespace mu + +#endif diff --git a/3rdParty/MuParser/include/muParserBytecode.h b/3rdParty/MuParser/include/muParserBytecode.h index 39ab39d52d4afac1ffc766baa1cfe490e5d870e8..5074e2348c9afe02a5e8229916e9ec23b589ada5 100644 --- a/3rdParty/MuParser/include/muParserBytecode.h +++ b/3rdParty/MuParser/include/muParserBytecode.h @@ -1,141 +1,152 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2004-2013 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_BYTECODE_H -#define MU_PARSER_BYTECODE_H - -#include <cassert> -#include <string> -#include <stack> -#include <vector> - -#include "muParserDef.h" -#include "muParserError.h" -#include "muParserToken.h" - -/** \file - \brief Definition of the parser bytecode class. -*/ - - -namespace mu -{ - struct SToken - { - ECmdCode Cmd; - int StackPos; - - union - { - struct //SValData - { - value_type *ptr; - value_type data; - value_type data2; - } Val; - - 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 - // pointer due to constraints in the ANSI standard which allows - // data pointers and function pointers to differ in size. - generic_fun_type ptr; - int argc; - int idx; - } Fun; - - struct //SOprtData - { - value_type *ptr; - int offset; - } Oprt; - }; - }; - - - /** \brief Bytecode implementation of the Math Parser. - - The bytecode contains the formula converted to revers polish notation stored in a continious - memory area. Associated with this data are operator codes, variable pointers, constant - values and function pointers. Those are necessary in order to calculate the result. - All those data items will be casted to the underlying datatype of the bytecode. - - \author (C) 2004-2013 Ingo Berg -*/ -class ParserByteCode -{ -private: - - /** \brief Token type for internal use only. */ - typedef ParserToken<value_type, string_type> token_type; - - /** \brief Token vector for storing the RPN. */ - typedef std::vector<SToken> rpn_type; - - /** \brief Position in the Calculation array. */ - unsigned m_iStackPos; - - /** \brief Maximum size needed for the stack. */ - std::size_t m_iMaxStackSize; - - /** \brief The actual rpn storage. */ - rpn_type m_vRPN; - - bool m_bEnableOptimizer; - - void ConstantFolding(ECmdCode a_Oprt); - -public: - - ParserByteCode(); - ParserByteCode(const ParserByteCode &a_ByteCode); - ParserByteCode& operator=(const ParserByteCode &a_ByteCode); - void Assign(const ParserByteCode &a_ByteCode); - - void AddVar(value_type *a_pVar); - void AddVal(value_type a_fVal); - void AddOp(ECmdCode a_Oprt); - void AddIfElse(ECmdCode a_Oprt); - void AddAssignOp(value_type *a_pVar); - void AddFun(generic_fun_type a_pFun, int a_iArgc); - void AddBulkFun(generic_fun_type a_pFun, int a_iArgc); - void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx); - - void EnableOptimizer(bool bStat); - - void Finalize(); - void clear(); - std::size_t GetMaxStackSize() const; - std::size_t GetSize() const; - - const SToken* GetBase() const; - void AsciiDump(); -}; - -} // namespace mu - -#endif - - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_BYTECODE_H +#define MU_PARSER_BYTECODE_H + +#include <string> +#include <stack> +#include <vector> + +#include "muParserDef.h" +#include "muParserError.h" +#include "muParserToken.h" + +/** \file + \brief Definition of the parser bytecode class. +*/ + + +namespace mu +{ + struct SToken + { + ECmdCode Cmd; + + union + { + struct //SValData + { + value_type* ptr; + value_type data; + value_type data2; + } Val; + + 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 + // pointer due to constraints in the ANSI standard which allows + // data pointers and function pointers to differ in size. + generic_fun_type ptr; + int argc; + int idx; + } Fun; + + struct //SOprtData + { + value_type* ptr; + int offset; + } Oprt; + }; + }; + + + /** \brief Bytecode implementation of the Math Parser. + + The bytecode contains the formula converted to revers polish notation stored in a continious + memory area. Associated with this data are operator codes, variable pointers, constant + values and function pointers. Those are necessary in order to calculate the result. + All those data items will be casted to the underlying datatype of the bytecode. + */ + class ParserByteCode final + { + private: + + /** \brief Token type for internal use only. */ + typedef ParserToken<value_type, string_type> token_type; + + /** \brief Token vector for storing the RPN. */ + typedef std::vector<SToken> rpn_type; + + /** \brief Position in the Calculation array. */ + unsigned m_iStackPos; + + /** \brief Maximum size needed for the stack. */ + std::size_t m_iMaxStackSize; + + /** \brief The actual rpn storage. */ + rpn_type m_vRPN; + + bool m_bEnableOptimizer; + + void ConstantFolding(ECmdCode a_Oprt); + + public: + + ParserByteCode(); + ParserByteCode(const ParserByteCode& a_ByteCode); + ParserByteCode& operator=(const ParserByteCode& a_ByteCode); + void Assign(const ParserByteCode& a_ByteCode); + + void AddVar(value_type* a_pVar); + void AddVal(value_type a_fVal); + void AddOp(ECmdCode a_Oprt); + void AddIfElse(ECmdCode a_Oprt); + void AddAssignOp(value_type* a_pVar); + void AddFun(generic_fun_type a_pFun, int a_iArgc); + void AddBulkFun(generic_fun_type a_pFun, int a_iArgc); + void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx); + + void EnableOptimizer(bool bStat); + + void Finalize(); + void clear(); + std::size_t GetMaxStackSize() const; + + std::size_t GetSize() const + { + return m_vRPN.size(); + } + + inline const SToken* GetBase() const + { + if (m_vRPN.size() == 0) + throw ParserError(ecINTERNAL_ERROR); + else + return &m_vRPN[0]; + } + + void AsciiDump(); + }; + +} // namespace mu + +#endif + + diff --git a/3rdParty/MuParser/include/muParserCallback.h b/3rdParty/MuParser/include/muParserCallback.h index ef32b4989e34b92c82ad06daf50014022781657c..1a8d0602edc0739ad0f8c5821507e5f5206adb07 100644 --- a/3rdParty/MuParser/include/muParserCallback.h +++ b/3rdParty/MuParser/include/muParserCallback.h @@ -1,118 +1,123 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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. -*/ - -#ifndef MU_PARSER_CALLBACK_H -#define MU_PARSER_CALLBACK_H - -#include "muParserDef.h" - -/** \file - \brief Definition of the parser callback class. -*/ - -namespace mu -{ - -/** \brief Encapsulation of prototypes for a numerical parser function. - - Encapsulates the prototyp for numerical parser functions. The class - stores the number of arguments for parser functions as well - as additional flags indication the function is non optimizeable. - The pointer to the callback function pointer is stored as void* - and needs to be casted according to the argument count. - Negative argument counts indicate a parser function with a variable number - of arguments. - - \author (C) 2004-2011 Ingo Berg -*/ -class ParserCallback -{ -public: - ParserCallback(fun_type0 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type1 a_pFun, bool a_bAllowOpti, int a_iPrec = -1, ECmdCode a_iCode=cmFUNC); - ParserCallback(fun_type2 a_pFun, bool a_bAllowOpti, int a_iPrec, EOprtAssociativity a_eAssociativity); - ParserCallback(fun_type2 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type3 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type4 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type5 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type6 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type7 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type8 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type9 a_pFun, bool a_bAllowOpti); - ParserCallback(fun_type10 a_pFun, bool a_bAllowOpti); - - ParserCallback(bulkfun_type0 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type1 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type2 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type3 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type4 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type5 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type6 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type7 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type8 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type9 a_pFun, bool a_bAllowOpti); - ParserCallback(bulkfun_type10 a_pFun, bool a_bAllowOpti); - - ParserCallback(multfun_type a_pFun, bool a_bAllowOpti); - ParserCallback(strfun_type1 a_pFun, bool a_bAllowOpti); - ParserCallback(strfun_type2 a_pFun, bool a_bAllowOpti); - ParserCallback(strfun_type3 a_pFun, bool a_bAllowOpti); - ParserCallback(); - ParserCallback(const ParserCallback &a_Fun); - - ParserCallback* Clone() const; - - bool IsOptimizable() const; - void* GetAddr() const; - ECmdCode GetCode() const; - ETypeCode GetType() const; - int GetPri() const; - EOprtAssociativity GetAssociativity() const; - int GetArgc() const; - -private: - void *m_pFun; ///< Pointer to the callback function, casted to void - - /** \brief Number of numeric function arguments - - This number is negative for functions with variable number of arguments. in this cases - they represent the actual number of arguments found. - */ - int m_iArgc; - int m_iPri; ///< Valid only for binary and infix operators; Operator precedence. - EOprtAssociativity m_eOprtAsct; ///< Operator associativity; Valid only for binary operators - ECmdCode m_iCode; - ETypeCode m_iType; - bool m_bAllowOpti; ///< Flag indication optimizeability -}; - -//------------------------------------------------------------------------------ -/** \brief Container for Callback objects. */ -typedef std::map<string_type, ParserCallback> funmap_type; - -} // namespace mu - -#endif - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef MU_PARSER_CALLBACK_H +#define MU_PARSER_CALLBACK_H + +#include "muParserDef.h" + +/** \file + \brief Definition of the parser callback class. +*/ + +namespace mu +{ + + /** \brief Encapsulation of prototypes for a numerical parser function. + + Encapsulates the prototyp for numerical parser functions. The class + stores the number of arguments for parser functions as well + as additional flags indication the function is non optimizeable. + The pointer to the callback function pointer is stored as void* + and needs to be casted according to the argument count. + Negative argument counts indicate a parser function with a variable number + of arguments. + */ + class API_EXPORT_CXX ParserCallback final + { + public: + ParserCallback(fun_type0 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type1 a_pFun, bool a_bAllowOpti, int a_iPrec = -1, ECmdCode a_iCode = cmFUNC); + ParserCallback(fun_type2 a_pFun, bool a_bAllowOpti, int a_iPrec, EOprtAssociativity a_eAssociativity); + ParserCallback(fun_type2 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type3 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type4 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type5 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type6 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type7 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type8 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type9 a_pFun, bool a_bAllowOpti); + ParserCallback(fun_type10 a_pFun, bool a_bAllowOpti); + + ParserCallback(bulkfun_type0 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type1 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type2 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type3 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type4 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type5 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type6 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type7 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type8 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type9 a_pFun, bool a_bAllowOpti); + ParserCallback(bulkfun_type10 a_pFun, bool a_bAllowOpti); + + ParserCallback(multfun_type a_pFun, bool a_bAllowOpti); + ParserCallback(strfun_type1 a_pFun, bool a_bAllowOpti); + ParserCallback(strfun_type2 a_pFun, bool a_bAllowOpti); + ParserCallback(strfun_type3 a_pFun, bool a_bAllowOpti); + ParserCallback(strfun_type4 a_pFun, bool a_bAllowOpti); + ParserCallback(strfun_type5 a_pFun, bool a_bAllowOpti); + ParserCallback(); + ParserCallback(const ParserCallback& a_Fun); + ParserCallback & operator=(const ParserCallback& a_Fun); + + ParserCallback* Clone() const; + + bool IsOptimizable() const; + void* GetAddr() const; + ECmdCode GetCode() const; + ETypeCode GetType() const; + int GetPri() const; + EOprtAssociativity GetAssociativity() const; + int GetArgc() const; + + private: + void* m_pFun; ///< Pointer to the callback function, casted to void + + /** \brief Number of numeric function arguments + + This number is negative for functions with variable number of arguments. in this cases + they represent the actual number of arguments found. + */ + int m_iArgc; + int m_iPri; ///< Valid only for binary and infix operators; Operator precedence. + EOprtAssociativity m_eOprtAsct; ///< Operator associativity; Valid only for binary operators + ECmdCode m_iCode; + ETypeCode m_iType; + bool m_bAllowOpti; ///< Flag indication optimizeability + }; + + + /** \brief Container for Callback objects. */ + typedef std::map<string_type, ParserCallback> funmap_type; + +} // namespace mu + +#endif + diff --git a/3rdParty/MuParser/include/muParserDLL.h b/3rdParty/MuParser/include/muParserDLL.h index 155ef8a06c449a3e834cb6c484f94a5398a7f9f8..18051c4d7835b266a463bd36f974d66d5729b13d 100644 --- a/3rdParty/MuParser/include/muParserDLL.h +++ b/3rdParty/MuParser/include/muParserDLL.h @@ -1,241 +1,236 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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 - -#ifndef _UNICODE - typedef char muChar_t; // character type -#else - typedef wchar_t muChar_t; // character type -#endif - -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 +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_DLL_H +#define MU_PARSER_DLL_H + +#include "muParserFixes.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** \file + \brief This file contains the DLL interface of muparser. + */ + + // Basic types + typedef void* muParserHandle_t; // parser handle + +#ifndef _UNICODE + typedef char muChar_t; // character type +#else + typedef wchar_t muChar_t; // character type +#endif + + 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)(void); + 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(void); + API_EXPORT(void) mupReleaseVar(muFloat_t*); + +#ifdef __cplusplus +} +#endif + +#endif // include guard diff --git a/3rdParty/MuParser/include/muParserDef.h b/3rdParty/MuParser/include/muParserDef.h index 437f2eaf572c1971292e8ffe7df4b55f53b77ea3..7ce24f2142454a76901a77748a00e51603bc9854 100644 --- a/3rdParty/MuParser/include/muParserDef.h +++ b/3rdParty/MuParser/include/muParserDef.h @@ -1,368 +1,428 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - 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 - 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 MUP_DEF_H -#define MUP_DEF_H - -#include <iostream> -#include <string> -#include <sstream> -#include <map> - -#include "muParserFixes.h" - -/** \file - \brief This file contains standard definitions used by the parser. -*/ - -#define MUP_VERSION _T("2.2.5") -#define MUP_VERSION_DATE _T("20150427; GC") - -#define MUP_CHARS _T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - -/** \brief If this macro is defined mathematical exceptions (div by zero) will be thrown as exceptions. */ -//#define MUP_MATH_EXCEPTIONS - -/** \brief Define the base datatype for values. - - This datatype must be a built in value type. You can not use custom classes. - It should be working with all types except "int"! -*/ -#define MUP_BASETYPE double - -/** \brief Activate this option in order to compile with OpenMP support. - - OpenMP is used only in the bulk mode it may increase the performance a bit. -*/ -//#define MUP_USE_OPENMP - -#if defined(_UNICODE) - /** \brief Definition of the basic parser string type. */ - #define MUP_STRING_TYPE std::wstring - - #if !defined(_T) - #define _T(x) L##x - #endif // not defined _T -#else - #ifndef _T - #define _T(x) x - #endif - - /** \brief Definition of the basic parser string type. */ - #define MUP_STRING_TYPE std::string -#endif - -#if defined(_DEBUG) - /** \brief Debug macro to force an abortion of the programm with a certain message. - */ - #define MUP_FAIL(MSG) \ - { \ - bool MSG=false; \ - assert(MSG); \ - } - - /** \brief An assertion that does not kill the program. - - This macro is neutralised in UNICODE builds. It's - too difficult to translate. - */ - #define MUP_ASSERT(COND) \ - if (!(COND)) \ - { \ - stringstream_type ss; \ - ss << _T("Assertion \"") _T(#COND) _T("\" failed: ") \ - << __FILE__ << _T(" line ") \ - << __LINE__ << _T("."); \ - throw ParserError( ss.str() ); \ - } -#else - #define MUP_FAIL(MSG) - #define MUP_ASSERT(COND) -#endif - - -namespace mu -{ -#if defined(_UNICODE) - - //------------------------------------------------------------------------------ - /** \brief Encapsulate wcout. */ - inline std::wostream& console() - { - return std::wcout; - } - - /** \brief Encapsulate cin. */ - inline std::wistream& console_in() - { - return std::wcin; - } - -#else - - /** \brief Encapsulate cout. - - Used for supporting UNICODE more easily. - */ - inline std::ostream& console() - { - return std::cout; - } - - /** \brief Encapsulate cin. - - Used for supporting UNICODE more easily. - */ - inline std::istream& console_in() - { - return std::cin; - } - -#endif - - //------------------------------------------------------------------------------ - /** \brief Bytecode values. - - \attention The order of the operator entries must match the order in ParserBase::c_DefaultOprt! - */ - enum ECmdCode - { - // The following are codes for built in binary operators - // apart from built in operators the user has the opportunity to - // add user defined operators. - cmLE = 0, ///< Operator item: less or equal - cmGE = 1, ///< Operator item: greater or equal - cmNEQ = 2, ///< Operator item: not equal - cmEQ = 3, ///< Operator item: equals - cmLT = 4, ///< Operator item: less than - cmGT = 5, ///< Operator item: greater than - cmADD = 6, ///< Operator item: add - cmSUB = 7, ///< Operator item: subtract - cmMUL = 8, ///< Operator item: multiply - cmDIV = 9, ///< Operator item: division - cmPOW = 10, ///< Operator item: y to the power of ... - cmLAND = 11, - cmLOR = 12, - cmASSIGN = 13, ///< Operator item: Assignment operator - cmBO = 14, ///< Operator item: opening bracket - cmBC = 15, ///< Operator item: closing bracket - cmIF = 16, ///< For use in the ternary if-then-else operator - cmELSE = 17, ///< For use in the ternary if-then-else operator - cmENDIF = 18, ///< For use in the ternary if-then-else operator - cmARG_SEP = 19, ///< function argument separator - cmVAR = 20, ///< variable item - cmVAL = 21, ///< value item - - // For optimization purposes - cmVARPOW2, - cmVARPOW3, - cmVARPOW4, - cmVARMUL, - cmPOW2, - - // operators and functions - cmFUNC, ///< Code for a generic function item - cmFUNC_STR, ///< Code for a function with a string parameter - cmFUNC_BULK, ///< Special callbacks for Bulk mode with an additional parameter for the bulk index - cmSTRING, ///< Code for a string token - cmOPRT_BIN, ///< user defined binary operator - cmOPRT_POSTFIX, ///< code for postfix operators - cmOPRT_INFIX, ///< code for infix operators - cmEND, ///< end of formula - cmUNKNOWN ///< uninitialized item - }; - - //------------------------------------------------------------------------------ - /** \brief Types internally used by the parser. - */ - enum ETypeCode - { - tpSTR = 0, ///< String type (Function arguments and constants only, no string variables) - tpDBL = 1, ///< Floating point variables - tpVOID = 2 ///< Undefined type. - }; - - //------------------------------------------------------------------------------ - enum EParserVersionInfo - { - pviBRIEF, - pviFULL - }; - - //------------------------------------------------------------------------------ - /** \brief Parser operator precedence values. */ - enum EOprtAssociativity - { - oaLEFT = 0, - oaRIGHT = 1, - oaNONE = 2 - }; - - //------------------------------------------------------------------------------ - /** \brief Parser operator precedence values. */ - enum EOprtPrecedence - { - // binary operators - prLOR = 1, - prLAND = 2, - prLOGIC = 3, ///< logic operators - prCMP = 4, ///< comparsion operators - prADD_SUB = 5, ///< addition - prMUL_DIV = 6, ///< multiplication/division - prPOW = 7, ///< power operator priority (highest) - - // infix operators - prINFIX = 6, ///< Signs have a higher priority than ADD_SUB, but lower than power operator - prPOSTFIX = 6 ///< Postfix operator priority (currently unused) - }; - - //------------------------------------------------------------------------------ - // basic types - - /** \brief The numeric datatype used by the parser. - - Normally this is a floating point type either single or double precision. - */ - typedef MUP_BASETYPE value_type; - - /** \brief The stringtype used by the parser. - - Depends on wether UNICODE is used or not. - */ - typedef MUP_STRING_TYPE string_type; - - /** \brief The character type used by the parser. - - Depends on wether UNICODE is used or not. - */ - typedef string_type::value_type char_type; - - /** \brief Typedef for easily using stringstream that respect the parser stringtype. */ - typedef std::basic_stringstream<char_type, - std::char_traits<char_type>, - std::allocator<char_type> > stringstream_type; - - // Data container types - - /** \brief Type used for storing variables. */ - typedef std::map<string_type, value_type*> varmap_type; - - /** \brief Type used for storing constants. */ - typedef std::map<string_type, value_type> valmap_type; - - /** \brief Type for assigning a string name to an index in the internal string table. */ - typedef std::map<string_type, std::size_t> strmap_type; - - // Parser callbacks - - /** \brief Callback type used for functions without arguments. */ - typedef value_type (*generic_fun_type)(); - - /** \brief Callback type used for functions without arguments. */ - typedef value_type (*fun_type0)(); - - /** \brief Callback type used for functions with a single arguments. */ - typedef value_type (*fun_type1)(value_type); - - /** \brief Callback type used for functions with two arguments. */ - typedef value_type (*fun_type2)(value_type, value_type); - - /** \brief Callback type used for functions with three arguments. */ - typedef value_type (*fun_type3)(value_type, value_type, value_type); - - /** \brief Callback type used for functions with four arguments. */ - typedef value_type (*fun_type4)(value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type5)(value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type6)(value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type7)(value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type8)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type9)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*fun_type10)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions without arguments. */ - typedef value_type (*bulkfun_type0)(int, int); - - /** \brief Callback type used for functions with a single arguments. */ - typedef value_type (*bulkfun_type1)(int, int, value_type); - - /** \brief Callback type used for functions with two arguments. */ - typedef value_type (*bulkfun_type2)(int, int, value_type, value_type); - - /** \brief Callback type used for functions with three arguments. */ - typedef value_type (*bulkfun_type3)(int, int, value_type, value_type, value_type); - - /** \brief Callback type used for functions with four arguments. */ - typedef value_type (*bulkfun_type4)(int, int, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type5)(int, int, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type6)(int, int, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type7)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type8)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type9)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with five arguments. */ - typedef value_type (*bulkfun_type10)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); - - /** \brief Callback type used for functions with a variable argument list. */ - typedef value_type (*multfun_type)(const value_type*, int); - - /** \brief Callback type used for functions taking a string as an argument. */ - typedef value_type (*strfun_type1)(const char_type*); - - /** \brief Callback type used for functions taking a string and a value as arguments. */ - typedef value_type (*strfun_type2)(const char_type*, value_type); - - /** \brief Callback type used for functions taking a string and two values as arguments. */ - typedef value_type (*strfun_type3)(const char_type*, value_type, value_type); - - /** \brief Callback used for functions that identify values in a string. */ - typedef int (*identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal); - - /** \brief Callback used for variable creation factory functions. */ - typedef value_type* (*facfun_type)(const char_type*, void*); -} // end of namespace - -#endif - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MUP_DEF_H +#define MUP_DEF_H + +#include <iostream> +#include <string> +#include <sstream> +#include <map> + +#include "muParserFixes.h" + +/** \file + \brief This file contains standard definitions used by the parser. +*/ + +/** \brief Define the base datatype for values. + + This datatype must be a built in value type. You can not use custom classes. + It should be working with all types except "int"! +*/ +#define MUP_BASETYPE double + +/** \brief Activate this option in order to compile with OpenMP support. + + OpenMP is used only in the bulk mode it may increase the performance a bit. + + !!! DO NOT ACTIVATE THIS MACRO HERE IF YOU USE CMAKE FOR BUILDING !!! + + use the cmake option instead! +*/ +//#define MUP_USE_OPENMP + +#if defined(_UNICODE) + /** \brief Definition of the basic parser string type. */ + #define MUP_STRING_TYPE std::wstring + + #if !defined(_T) + #define _T(x) L##x + #endif // not defined _T +#else + #ifndef _T + #define _T(x) x + #endif + + /** \brief Definition of the basic parser string type. */ + #define MUP_STRING_TYPE std::string +#endif + +/** \brief An assertion that does not kill the program. */ +#define MUP_ASSERT(COND) \ + if (!(COND)) \ + { \ + stringstream_type ss; \ + ss << _T("Assertion \"") _T(#COND) _T("\" failed: ") \ + << __FILE__ << _T(" line ") \ + << __LINE__ << _T("."); \ + throw ParserError( ecINTERNAL_ERROR, -1, ss.str()); \ + } + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable : 26812) +#endif + + +namespace mu +{ +#if defined(_UNICODE) + + /** \brief Encapsulate wcout. */ + inline std::wostream& console() + { + return std::wcout; + } + + /** \brief Encapsulate cin. */ + inline std::wistream& console_in() + { + return std::wcin; + } + +#else + + /** \brief Encapsulate cout. + + Used for supporting UNICODE more easily. + */ + inline std::ostream& console() + { + return std::cout; + } + + /** \brief Encapsulate cin. + + Used for supporting UNICODE more easily. + */ + inline std::istream& console_in() + { + return std::cin; + } + +#endif + + /** \brief Bytecode values. + + \attention The order of the operator entries must match the order in ParserBase::c_DefaultOprt! + */ + enum ECmdCode + { + // The following are codes for built in binary operators + // apart from built in operators the user has the opportunity to + // add user defined operators. + cmLE = 0, ///< Operator item: less or equal + cmGE = 1, ///< Operator item: greater or equal + cmNEQ = 2, ///< Operator item: not equal + cmEQ = 3, ///< Operator item: equals + cmLT = 4, ///< Operator item: less than + cmGT = 5, ///< Operator item: greater than + cmADD = 6, ///< Operator item: add + cmSUB = 7, ///< Operator item: subtract + cmMUL = 8, ///< Operator item: multiply + cmDIV = 9, ///< Operator item: division + cmPOW = 10, ///< Operator item: y to the power of ... + cmLAND = 11, + cmLOR = 12, + cmASSIGN = 13, ///< Operator item: Assignment operator + cmBO = 14, ///< Operator item: opening bracket + cmBC = 15, ///< Operator item: closing bracket + cmIF = 16, ///< For use in the ternary if-then-else operator + cmELSE = 17, ///< For use in the ternary if-then-else operator + cmENDIF = 18, ///< For use in the ternary if-then-else operator + cmARG_SEP = 19, ///< function argument separator + cmVAR = 20, ///< variable item + cmVAL = 21, ///< value item + + // For optimization purposes + cmVARPOW2 = 22, + cmVARPOW3 = 23, + cmVARPOW4 = 24, + cmVARMUL = 25, + + // operators and functions + cmFUNC = 26, ///< Code for a generic function item + cmFUNC_STR, ///< Code for a function with a string parameter + cmFUNC_BULK, ///< Special callbacks for Bulk mode with an additional parameter for the bulk index + cmSTRING, ///< Code for a string token + cmOPRT_BIN, ///< user defined binary operator + cmOPRT_POSTFIX, ///< code for postfix operators + cmOPRT_INFIX, ///< code for infix operators + cmEND, ///< end of formula + cmUNKNOWN ///< uninitialized item + }; + + /** \brief Types internally used by the parser. + */ + enum ETypeCode + { + tpSTR = 0, ///< String type (Function arguments and constants only, no string variables) + tpDBL = 1, ///< Floating point variables + tpVOID = 2 ///< Undefined type. + }; + + + enum EParserVersionInfo + { + pviBRIEF, + pviFULL + }; + + + /** \brief Parser operator precedence values. */ + enum EOprtAssociativity + { + oaLEFT = 0, + oaRIGHT = 1, + oaNONE = 2 + }; + + + /** \brief Parser operator precedence values. */ + enum EOprtPrecedence + { + // binary operators + prLOR = 1, + prLAND = 2, + prLOGIC = 3, ///< logic operators + prCMP = 4, ///< comparsion operators + prADD_SUB = 5, ///< addition + prMUL_DIV = 6, ///< multiplication/division + prPOW = 7, ///< power operator priority (highest) + + // infix operators + prINFIX = 6, ///< Signs have a higher priority than ADD_SUB, but lower than power operator + prPOSTFIX = 6 ///< Postfix operator priority (currently unused) + }; + + + /** \brief Error codes. */ + enum EErrorCodes + { + // Formula syntax errors + ecUNEXPECTED_OPERATOR = 0, ///< Unexpected binary operator found + ecUNASSIGNABLE_TOKEN = 1, ///< Token can't be identified. + ecUNEXPECTED_EOF = 2, ///< Unexpected end of formula. (Example: "2+sin(") + ecUNEXPECTED_ARG_SEP = 3, ///< An unexpected comma has been found. (Example: "1,23") + ecUNEXPECTED_ARG = 4, ///< An unexpected argument has been found + ecUNEXPECTED_VAL = 5, ///< An unexpected value token has been found + ecUNEXPECTED_VAR = 6, ///< An unexpected variable token has been found + ecUNEXPECTED_PARENS = 7, ///< Unexpected Parenthesis, opening or closing + ecUNEXPECTED_STR = 8, ///< A string has been found at an inapropriate position + ecSTRING_EXPECTED = 9, ///< A string function has been called with a different type of argument + ecVAL_EXPECTED = 10, ///< A numerical function has been called with a non value type of argument + ecMISSING_PARENS = 11, ///< Missing parens. (Example: "3*sin(3") + ecUNEXPECTED_FUN = 12, ///< Unexpected function found. (Example: "sin(8)cos(9)") + ecUNTERMINATED_STRING = 13, ///< unterminated string constant. (Example: "3*valueof("hello)") + ecTOO_MANY_PARAMS = 14, ///< Too many function parameters + ecTOO_FEW_PARAMS = 15, ///< Too few function parameters. (Example: "ite(1<2,2)") + ecOPRT_TYPE_CONFLICT = 16, ///< binary operators may only be applied to value items of the same type + ecSTR_RESULT = 17, ///< result is a string + + // Invalid Parser input Parameters + ecINVALID_NAME = 18, ///< Invalid function, variable or constant name. + ecINVALID_BINOP_IDENT = 19, ///< Invalid binary operator identifier + ecINVALID_INFIX_IDENT = 20, ///< Invalid function, variable or constant name. + ecINVALID_POSTFIX_IDENT = 21, ///< Invalid function, variable or constant name. + + ecBUILTIN_OVERLOAD = 22, ///< Trying to overload builtin operator + ecINVALID_FUN_PTR = 23, ///< Invalid callback function pointer + ecINVALID_VAR_PTR = 24, ///< Invalid variable pointer + ecEMPTY_EXPRESSION = 25, ///< The Expression is empty + ecNAME_CONFLICT = 26, ///< Name conflict + ecOPT_PRI = 27, ///< Invalid operator priority + // + ecDOMAIN_ERROR = 28, ///< catch division by zero, sqrt(-1), log(0) (currently unused) + ecDIV_BY_ZERO = 29, ///< Division by zero (currently unused) + ecGENERIC = 30, ///< Generic error + ecLOCALE = 31, ///< Conflict with current locale + + ecUNEXPECTED_CONDITIONAL = 32, + ecMISSING_ELSE_CLAUSE = 33, + ecMISPLACED_COLON = 34, + + ecUNREASONABLE_NUMBER_OF_COMPUTATIONS = 35, + + ecIDENTIFIER_TOO_LONG = 36, ///< Thrown when an identifier with more then 255 characters is used. + + ecEXPRESSION_TOO_LONG = 37, ///< Throw an exception if the expression has more than 10000 characters. (an arbitrary limit) + + ecINVALID_CHARACTERS_FOUND = 38,///< The expression or identifier contains invalid non printable characters + + // internal errors + ecINTERNAL_ERROR = 39, ///< 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 + ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages + }; + + //------------------------------------------------------------------------------ + // Basic Types + //------------------------------------------------------------------------------ + + /** \brief The numeric datatype used by the parser. + + Normally this is a floating point type either single or double precision. + */ + typedef MUP_BASETYPE value_type; + + /** \brief The stringtype used by the parser. + + Depends on whether UNICODE is used or not. + */ + typedef MUP_STRING_TYPE string_type; + + /** \brief The character type used by the parser. + + Depends on whether UNICODE is used or not. + */ + typedef string_type::value_type char_type; + + /** \brief Typedef for easily using stringstream that respect the parser stringtype. */ + typedef std::basic_stringstream<char_type, std::char_traits<char_type>, std::allocator<char_type> > stringstream_type; + + // Data container types + + /** \brief Type used for storing variables. */ + typedef std::map<string_type, value_type*> varmap_type; + + /** \brief Type used for storing constants. */ + typedef std::map<string_type, value_type> valmap_type; + + /** \brief Type for assigning a string name to an index in the internal string table. */ + typedef std::map<string_type, std::size_t> strmap_type; + + // Parser callbacks + + /** \brief Callback type used for functions without arguments. */ + typedef value_type(*generic_fun_type)(); + + /** \brief Callback type used for functions without arguments. */ + typedef value_type(*fun_type0)(); + + /** \brief Callback type used for functions with a single arguments. */ + typedef value_type(*fun_type1)(value_type); + + /** \brief Callback type used for functions with two arguments. */ + typedef value_type(*fun_type2)(value_type, value_type); + + /** \brief Callback type used for functions with three arguments. */ + typedef value_type(*fun_type3)(value_type, value_type, value_type); + + /** \brief Callback type used for functions with four arguments. */ + typedef value_type(*fun_type4)(value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with five arguments. */ + typedef value_type(*fun_type5)(value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with six arguments. */ + typedef value_type(*fun_type6)(value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with seven arguments. */ + typedef value_type(*fun_type7)(value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with eight arguments. */ + typedef value_type(*fun_type8)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with nine arguments. */ + typedef value_type(*fun_type9)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with ten arguments. */ + typedef value_type(*fun_type10)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions without arguments. */ + typedef value_type(*bulkfun_type0)(int, int); + + /** \brief Callback type used for functions with a single arguments. */ + typedef value_type(*bulkfun_type1)(int, int, value_type); + + /** \brief Callback type used for functions with two arguments. */ + typedef value_type(*bulkfun_type2)(int, int, value_type, value_type); + + /** \brief Callback type used for functions with three arguments. */ + typedef value_type(*bulkfun_type3)(int, int, value_type, value_type, value_type); + + /** \brief Callback type used for functions with four arguments. */ + typedef value_type(*bulkfun_type4)(int, int, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with five arguments. */ + typedef value_type(*bulkfun_type5)(int, int, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with six arguments. */ + typedef value_type(*bulkfun_type6)(int, int, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with seven arguments. */ + typedef value_type(*bulkfun_type7)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with eight arguments. */ + typedef value_type(*bulkfun_type8)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with nine arguments. */ + typedef value_type(*bulkfun_type9)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with ten arguments. */ + typedef value_type(*bulkfun_type10)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type); + + /** \brief Callback type used for functions with a variable argument list. */ + typedef value_type(*multfun_type)(const value_type*, int); + + /** \brief Callback type used for functions taking a string as an argument. */ + typedef value_type(*strfun_type1)(const char_type*); + + /** \brief Callback type used for functions taking a string and a value as arguments. */ + typedef value_type(*strfun_type2)(const char_type*, value_type); + + /** \brief Callback type used for functions taking a string and two values as arguments. */ + typedef value_type(*strfun_type3)(const char_type*, value_type, value_type); + + /** \brief Callback type used for functions taking a string and a value as arguments. */ + typedef value_type(*strfun_type4)(const char_type*, value_type, value_type, value_type); + + /** \brief Callback type used for functions taking a string and two values as arguments. */ + typedef value_type(*strfun_type5)(const char_type*, value_type, value_type, value_type, value_type); + + /** \brief Callback used for functions that identify values in a string. */ + typedef int (*identfun_type)(const char_type* sExpr, int* nPos, value_type* fVal); + + /** \brief Callback used for variable creation factory functions. */ + typedef value_type* (*facfun_type)(const char_type*, void*); + + static const int MaxLenExpression = 5000; + static const int MaxLenIdentifier = 100; + static const string_type ParserVersion = string_type(_T("2.3.2")); + static const string_type ParserVersionDate = string_type(_T("20200617")); +} // end of namespace + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif + +#endif + diff --git a/3rdParty/MuParser/include/muParserError.h b/3rdParty/MuParser/include/muParserError.h index 7f88e99192ebf61d3b546a17892681af53a4f5f9..438b8b65f0698b3fd532c6a260e003e7d031f123 100644 --- a/3rdParty/MuParser/include/muParserError.h +++ b/3rdParty/MuParser/include/muParserError.h @@ -1,176 +1,108 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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. -*/ - -#ifndef MU_PARSER_ERROR_H -#define MU_PARSER_ERROR_H - -#include <cassert> -#include <stdexcept> -#include <string> -#include <sstream> -#include <vector> -#include <memory> - -#include "muParserDef.h" - -/** \file - \brief This file defines the error class used by the parser. -*/ - -namespace mu -{ - -/** \brief Error codes. */ -enum EErrorCodes -{ - // Formula syntax errors - ecUNEXPECTED_OPERATOR = 0, ///< Unexpected binary operator found - ecUNASSIGNABLE_TOKEN = 1, ///< Token cant be identified. - ecUNEXPECTED_EOF = 2, ///< Unexpected end of formula. (Example: "2+sin(") - ecUNEXPECTED_ARG_SEP = 3, ///< An unexpected comma has been found. (Example: "1,23") - ecUNEXPECTED_ARG = 4, ///< An unexpected argument has been found - ecUNEXPECTED_VAL = 5, ///< An unexpected value token has been found - ecUNEXPECTED_VAR = 6, ///< An unexpected variable token has been found - ecUNEXPECTED_PARENS = 7, ///< Unexpected Parenthesis, opening or closing - ecUNEXPECTED_STR = 8, ///< A string has been found at an inapropriate position - ecSTRING_EXPECTED = 9, ///< A string function has been called with a different type of argument - ecVAL_EXPECTED = 10, ///< A numerical function has been called with a non value type of argument - ecMISSING_PARENS = 11, ///< Missing parens. (Example: "3*sin(3") - ecUNEXPECTED_FUN = 12, ///< Unexpected function found. (Example: "sin(8)cos(9)") - ecUNTERMINATED_STRING = 13, ///< unterminated string constant. (Example: "3*valueof("hello)") - ecTOO_MANY_PARAMS = 14, ///< Too many function parameters - ecTOO_FEW_PARAMS = 15, ///< Too few function parameters. (Example: "ite(1<2,2)") - ecOPRT_TYPE_CONFLICT = 16, ///< binary operators may only be applied to value items of the same type - ecSTR_RESULT = 17, ///< result is a string - - // Invalid Parser input Parameters - ecINVALID_NAME = 18, ///< Invalid function, variable or constant name. - ecINVALID_BINOP_IDENT = 19, ///< Invalid binary operator identifier - ecINVALID_INFIX_IDENT = 20, ///< Invalid function, variable or constant name. - ecINVALID_POSTFIX_IDENT = 21, ///< Invalid function, variable or constant name. - - ecBUILTIN_OVERLOAD = 22, ///< Trying to overload builtin operator - ecINVALID_FUN_PTR = 23, ///< Invalid callback function pointer - ecINVALID_VAR_PTR = 24, ///< Invalid variable pointer - ecEMPTY_EXPRESSION = 25, ///< The Expression is empty - ecNAME_CONFLICT = 26, ///< Name conflict - ecOPT_PRI = 27, ///< Invalid operator priority - // - ecDOMAIN_ERROR = 28, ///< catch division by zero, sqrt(-1), log(0) (currently unused) - ecDIV_BY_ZERO = 29, ///< Division by zero (currently unused) - ecGENERIC = 30, ///< Generic error - ecLOCALE = 31, ///< Conflict with current locale - - ecUNEXPECTED_CONDITIONAL = 32, - ecMISSING_ELSE_CLAUSE = 33, - ecMISPLACED_COLON = 34, - - ecUNREASONABLE_NUMBER_OF_COMPUTATIONS = 35, - - // internal errors - 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 - ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages -}; - -//--------------------------------------------------------------------------- -/** \brief A class that handles the error messages. -*/ -class ParserErrorMsg -{ -public: - typedef ParserErrorMsg self_type; - - ParserErrorMsg& operator=(const ParserErrorMsg &); - ParserErrorMsg(const ParserErrorMsg&); - ParserErrorMsg(); - - ~ParserErrorMsg(); - - static const ParserErrorMsg& Instance(); - string_type operator[](unsigned a_iIdx) const; - -private: - std::vector<string_type> m_vErrMsg; ///< A vector with the predefined error messages - static const self_type m_Instance; ///< The instance pointer -}; - -//--------------------------------------------------------------------------- -/** \brief Error class of the parser. - \author Ingo Berg - - Part of the math parser package. -*/ -class ParserError -{ -private: - - /** \brief Replace all ocuurences of a substring with another string. */ - void ReplaceSubString( string_type &strSource, - const string_type &strFind, - const string_type &strReplaceWith); - void Reset(); - -public: - - ParserError(); - explicit ParserError(EErrorCodes a_iErrc); - explicit ParserError(const string_type &sMsg); - ParserError( EErrorCodes a_iErrc, - const string_type &sTok, - const string_type &sFormula = string_type(), - int a_iPos = -1); - ParserError( EErrorCodes a_iErrc, - int a_iPos, - const string_type &sTok); - ParserError( const char_type *a_szMsg, - int a_iPos = -1, - const string_type &sTok = string_type()); - ParserError(const ParserError &a_Obj); - ParserError& operator=(const ParserError &a_Obj); - ~ParserError(); - - void SetFormula(const string_type &a_strFormula); - const string_type& GetExpr() const; - const string_type& GetMsg() const; - int GetPos() const; - const string_type& GetToken() const; - EErrorCodes GetCode() const; - -private: - string_type m_strMsg; ///< The message string - string_type m_strFormula; ///< Formula string - string_type m_strTok; ///< Token related with the error - int m_iPos; ///< Formula position related to the error - EErrorCodes m_iErrc; ///< Error code - const ParserErrorMsg &m_ErrMsg; -}; - -} // namespace mu - -#endif - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_ERROR_H +#define MU_PARSER_ERROR_H + +#include <stdexcept> +#include <string> +#include <sstream> +#include <vector> +#include <memory> + +#include "muParserDef.h" + +/** \file + \brief This file defines the error class used by the parser. +*/ + +namespace mu +{ + /** \brief A class that handles the error messages. */ + class ParserErrorMsg final + { + public: + static const ParserErrorMsg& Instance(); + string_type operator[](unsigned a_iIdx) const; + + private: + ParserErrorMsg& operator=(const ParserErrorMsg&) = delete; + ParserErrorMsg(const ParserErrorMsg&) = delete; + ParserErrorMsg(); + + ~ParserErrorMsg() = default; + + std::vector<string_type> m_vErrMsg; ///< A vector with the predefined error messages + }; + + + /** \brief Error class of the parser. + + Part of the math parser package. + */ + class API_EXPORT_CXX ParserError + { + private: + + /** \brief Replace all ocuurences of a substring with another string. */ + void ReplaceSubString(string_type& strSource, const string_type& strFind, const string_type& strReplaceWith); + void Reset(); + + public: + + ParserError(); + explicit ParserError(EErrorCodes a_iErrc); + explicit ParserError(const string_type& sMsg); + ParserError(EErrorCodes a_iErrc, const string_type& sTok, const string_type& sFormula = string_type(), int a_iPos = -1); + ParserError(EErrorCodes a_iErrc, int a_iPos, const string_type& sTok); + ParserError(const char_type* a_szMsg, int a_iPos = -1, const string_type& sTok = string_type()); + ParserError(const ParserError& a_Obj); + + ParserError& operator=(const ParserError& a_Obj); + ~ParserError(); + + void SetFormula(const string_type& a_strFormula); + const string_type& GetExpr() const; + const string_type& GetMsg() const; + int GetPos() const; + const string_type& GetToken() const; + EErrorCodes GetCode() const; + + private: + string_type m_strMsg; ///< The message string + string_type m_strFormula; ///< Formula string + string_type m_strTok; ///< Token related with the error + int m_iPos; ///< Formula position related to the error + EErrorCodes m_iErrc; ///< Error code + const ParserErrorMsg& m_ErrMsg; + }; + +} // namespace mu + +#endif + diff --git a/3rdParty/MuParser/include/muParserFixes.h b/3rdParty/MuParser/include/muParserFixes.h index 1cd15e02edbf1af43c24a5490eca51e5e45bd05d..59aecad19530e74678f493946503ffebfd74c762 100644 --- a/3rdParty/MuParser/include/muParserFixes.h +++ b/3rdParty/MuParser/include/muParserFixes.h @@ -1,62 +1,90 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2013 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_FIXES_H -#define MU_PARSER_FIXES_H - -/** \file - \brief This file contains compatibility fixes for some platforms. -*/ - -// -// Compatibility fixes -// - -//--------------------------------------------------------------------------- -// -// Intel Compiler -// -//--------------------------------------------------------------------------- - -#ifdef __INTEL_COMPILER - -// remark #981: operands are evaluated in unspecified order -// disabled -> completely pointless if the functions do not have side effects -// -#pragma warning(disable:981) - -// remark #383: value copied to temporary, reference to temporary used -#pragma warning(disable:383) - -// remark #1572: floating-point equality and inequality comparisons are unreliable -// disabled -> everyone knows it, the parser passes this problem -// deliberately to the user -#pragma warning(disable:1572) - -#endif - -#endif // include guard - - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_FIXES_H +#define MU_PARSER_FIXES_H + +/** \file + \brief This file contains compatibility fixes for some platforms. +*/ + +// +// Compatibility fixes +// + +/* From http://gcc.gnu.org/wiki/Visibility */ +/* Generic helper definitions for shared library support */ +#if defined _WIN32 || defined __CYGWIN__ + #define MUPARSER_HELPER_DLL_IMPORT __declspec(dllimport) + #define MUPARSER_HELPER_DLL_EXPORT __declspec(dllexport) + #define MUPARSER_HELPER_DLL_LOCAL +#else + #if __GNUC__ >= 4 + #define MUPARSER_HELPER_DLL_IMPORT __attribute__ ((visibility ("default"))) + #define MUPARSER_HELPER_DLL_EXPORT __attribute__ ((visibility ("default"))) + #define MUPARSER_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden"))) + #else + #define MUPARSER_HELPER_DLL_IMPORT + #define MUPARSER_HELPER_DLL_EXPORT + #define MUPARSER_HELPER_DLL_LOCAL + #endif +#endif + +/* + Now we use the generic helper definitions above to define API_EXPORT_CXX and MUPARSER_LOCAL. + API_EXPORT_CXX is used for the public API symbols. It either DLL imports or DLL exports (or does nothing for static build) + MUPARSER_LOCAL is used for non-api symbols. +*/ + +#ifndef MUPARSER_STATIC /* defined if muParser is compiled as a DLL */ + + #ifdef MUPARSERLIB_EXPORTS /* defined if we are building the muParser DLL (instead of using it) */ + #define API_EXPORT_CXX MUPARSER_HELPER_DLL_EXPORT + #else + #define API_EXPORT_CXX MUPARSER_HELPER_DLL_IMPORT + #endif /* MUPARSER_DLL_EXPORTS */ + #define MUPARSER_LOCAL MUPARSER_HELPER_DLL_LOCAL + +#else /* MUPARSER_STATIC is defined: this means muParser is a static lib. */ + + #define API_EXPORT_CXX + #define MUPARSER_LOCAL + +#endif /* !MUPARSER_STATIC */ + + +#ifdef _WIN32 + #define API_EXPORT(TYPE) API_EXPORT_CXX TYPE __cdecl +#else + #define API_EXPORT(TYPE) TYPE +#endif + + +#endif // include guard + + diff --git a/3rdParty/MuParser/include/muParserInt.h b/3rdParty/MuParser/include/muParserInt.h index 136de339714588c26d48430d9e17778d367d0a26..dd772cfa370ae54b1f0d4a69865ca3a1df692772 100644 --- a/3rdParty/MuParser/include/muParserInt.h +++ b/3rdParty/MuParser/include/muParserInt.h @@ -1,140 +1,143 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2004-2013 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_INT_H -#define MU_PARSER_INT_H - -#include "muParserBase.h" -#include <vector> - - -/** \file - \brief Definition of a parser using integer value. -*/ - - -namespace mu -{ - -/** \brief Mathematical expressions parser. - - This version of the parser handles only integer numbers. It disables the built in operators thus it is - slower than muParser. Integer values are stored in the double value_type and converted if needed. -*/ -class ParserInt : public ParserBase -{ -private: - static int Round(value_type v) { return (int)(v + ((v>=0) ? 0.5 : -0.5) ); }; - - static value_type Abs(value_type); - static value_type Sign(value_type); - static value_type Ite(value_type, value_type, value_type); - // !! The unary Minus is a MUST, otherwise you cant use negative signs !! - static value_type UnaryMinus(value_type); - // Functions with variable number of arguments - static value_type Sum(const value_type* a_afArg, int a_iArgc); // sum - static value_type Min(const value_type* a_afArg, int a_iArgc); // minimum - static value_type Max(const value_type* a_afArg, int a_iArgc); // maximum - // binary operator callbacks - static value_type Add(value_type v1, value_type v2); - static value_type Sub(value_type v1, value_type v2); - static value_type Mul(value_type v1, value_type v2); - static value_type Div(value_type v1, value_type v2); - static value_type Mod(value_type v1, value_type v2); - static value_type Pow(value_type v1, value_type v2); - static value_type Shr(value_type v1, value_type v2); - static value_type Shl(value_type v1, value_type v2); - static value_type LogAnd(value_type v1, value_type v2); - static value_type LogOr(value_type v1, value_type v2); - static value_type And(value_type v1, value_type v2); - static value_type Or(value_type v1, value_type v2); - static value_type Xor(value_type v1, value_type v2); - static value_type Less(value_type v1, value_type v2); - static value_type Greater(value_type v1, value_type v2); - static value_type LessEq(value_type v1, value_type v2); - static value_type GreaterEq(value_type v1, value_type v2); - static value_type Equal(value_type v1, value_type v2); - static value_type NotEqual(value_type v1, value_type v2); - static value_type Not(value_type v1); - - static int IsHexVal(const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); - static int IsBinVal(const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); - static int IsVal (const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); - - /** \brief A facet class used to change decimal and thousands separator. */ - template<class TChar> - class change_dec_sep : public std::numpunct<TChar> - { - public: - - explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3) - :std::numpunct<TChar>() - ,m_cDecPoint(cDecSep) - ,m_cThousandsSep(cThousandsSep) - ,m_nGroup(nGroup) - {} - - protected: - - virtual char_type do_decimal_point() const - { - return m_cDecPoint; - } - - virtual char_type do_thousands_sep() const - { - return m_cThousandsSep; - } - - virtual std::string do_grouping() const - { - // 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: - - int m_nGroup; - char_type m_cDecPoint; - char_type m_cThousandsSep; - }; - -public: - ParserInt(); - - virtual void InitFun(); - virtual void InitOprt(); - virtual void InitConst(); - virtual void InitCharSets(); -}; - -} // namespace mu - -#endif - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_INT_H +#define MU_PARSER_INT_H + +#include "muParserBase.h" +#include <vector> + + +/** \file + \brief Definition of a parser using integer value. +*/ + + +namespace mu +{ + + /** \brief Mathematical expressions parser. + + This version of the parser handles only integer numbers. It disables the built in operators thus it is + slower than muParser. Integer values are stored in the double value_type and converted if needed. + */ + class ParserInt : public ParserBase + { + private: + static int Round(value_type v) { return (int)(v + ((v >= 0) ? 0.5 : -0.5)); }; + + static value_type Abs(value_type); + static value_type Sign(value_type); + static value_type Ite(value_type, value_type, value_type); + // !! The unary Minus is a MUST, otherwise you can't use negative signs !! + static value_type UnaryMinus(value_type); + // Functions with variable number of arguments + static value_type Sum(const value_type* a_afArg, int a_iArgc); // sum + static value_type Min(const value_type* a_afArg, int a_iArgc); // minimum + static value_type Max(const value_type* a_afArg, int a_iArgc); // maximum + // binary operator callbacks + static value_type Add(value_type v1, value_type v2); + static value_type Sub(value_type v1, value_type v2); + static value_type Mul(value_type v1, value_type v2); + static value_type Div(value_type v1, value_type v2); + static value_type Mod(value_type v1, value_type v2); + static value_type Pow(value_type v1, value_type v2); + static value_type Shr(value_type v1, value_type v2); + static value_type Shl(value_type v1, value_type v2); + static value_type LogAnd(value_type v1, value_type v2); + static value_type LogOr(value_type v1, value_type v2); + static value_type And(value_type v1, value_type v2); + static value_type Or(value_type v1, value_type v2); + static value_type Xor(value_type v1, value_type v2); + static value_type Less(value_type v1, value_type v2); + static value_type Greater(value_type v1, value_type v2); + static value_type LessEq(value_type v1, value_type v2); + static value_type GreaterEq(value_type v1, value_type v2); + static value_type Equal(value_type v1, value_type v2); + static value_type NotEqual(value_type v1, value_type v2); + static value_type Not(value_type v1); + + static int IsHexVal(const char_type* a_szExpr, int* a_iPos, value_type* a_iVal); + static int IsBinVal(const char_type* a_szExpr, int* a_iPos, value_type* a_iVal); + static int IsVal(const char_type* a_szExpr, int* a_iPos, value_type* a_iVal); + + /** \brief A facet class used to change decimal and thousands separator. */ + template<class TChar> + class change_dec_sep : public std::numpunct<TChar> + { + public: + + explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3) + :std::numpunct<TChar>() + , m_cDecPoint(cDecSep) + , m_cThousandsSep(cThousandsSep) + , m_nGroup(nGroup) + {} + + protected: + + virtual char_type do_decimal_point() const + { + return m_cDecPoint; + } + + virtual char_type do_thousands_sep() const + { + return m_cThousandsSep; + } + + virtual std::string do_grouping() const + { + // 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: + + int m_nGroup; + char_type m_cDecPoint; + char_type m_cThousandsSep; + }; + + public: + ParserInt(); + + virtual void InitFun(); + virtual void InitOprt(); + virtual void InitConst(); + virtual void InitCharSets(); + }; + +} // namespace mu + +#endif + diff --git a/3rdParty/MuParser/include/muParserStack.h b/3rdParty/MuParser/include/muParserStack.h deleted file mode 100644 index f8437e30e43cec17465c09da0d10641d251dc550..0000000000000000000000000000000000000000 --- a/3rdParty/MuParser/include/muParserStack.h +++ /dev/null @@ -1,125 +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. -*/ - -#ifndef MU_PARSER_STACK_H -#define MU_PARSER_STACK_H - -#include <cassert> -#include <string> -#include <stack> -#include <vector> - -#include "muParserError.h" -#include "muParserToken.h" - -/** \file - \brief This file defines the stack used by muparser. -*/ - -namespace mu -{ - - /** \brief Parser stack implementation. - - Stack implementation based on a std::stack. The behaviour of pop() had been - slightly changed in order to get an error code if the stack is empty. - The stack is used within the Parser both as a value stack and as an operator stack. - - \author (C) 2004-2011 Ingo Berg - */ - template <typename TValueType> - class ParserStack - { - private: - - /** \brief Type of the underlying stack implementation. */ - typedef std::stack<TValueType, std::vector<TValueType> > impl_type; - - impl_type m_Stack; ///< This is the actual stack. - - public: - - //--------------------------------------------------------------------------- - ParserStack() - :m_Stack() - {} - - //--------------------------------------------------------------------------- - virtual ~ParserStack() - {} - - //--------------------------------------------------------------------------- - /** \brief Pop a value from the stack. - - Unlike the standard implementation this function will return the value that - is going to be taken from the stack. - - \throw ParserException in case the stack is empty. - \sa pop(int &a_iErrc) - */ - TValueType pop() - { - if (empty()) - throw ParserError( _T("stack is empty.") ); - - TValueType el = top(); - m_Stack.pop(); - return el; - } - - /** \brief Push an object into the stack. - - \param a_Val object to push into the stack. - \throw nothrow - */ - void push(const TValueType& a_Val) - { - m_Stack.push(a_Val); - } - - /** \brief Return the number of stored elements. */ - unsigned size() const - { - return (unsigned)m_Stack.size(); - } - - /** \brief Returns true if stack is empty false otherwise. */ - bool empty() const - { - return m_Stack.empty(); - } - - /** \brief Return reference to the top object in the stack. - - The top object is the one pushed most recently. - */ - TValueType& top() - { - return m_Stack.top(); - } - }; -} // namespace MathUtils - -#endif diff --git a/3rdParty/MuParser/include/muParserTemplateMagic.h b/3rdParty/MuParser/include/muParserTemplateMagic.h index 1626caea4eeee2238d2eb874e9173e079c9d4853..1b26d004efe7f6351ab324e2ce6b7a335bb426bb 100644 --- a/3rdParty/MuParser/include/muParserTemplateMagic.h +++ b/3rdParty/MuParser/include/muParserTemplateMagic.h @@ -1,113 +1,198 @@ -#ifndef MU_PARSER_TEMPLATE_MAGIC_H -#define MU_PARSER_TEMPLATE_MAGIC_H - -#include <cmath> -#include "muParserError.h" - - -namespace mu -{ - //----------------------------------------------------------------------------------------------- - // - // Compile time type detection - // - //----------------------------------------------------------------------------------------------- - - /** \brief A class singling out integer types at compile time using - template meta programming. - */ - template<typename T> - struct TypeInfo - { - static bool IsInteger() { return false; } - }; - - template<> - struct TypeInfo<char> - { - static bool IsInteger() { return true; } - }; - - template<> - struct TypeInfo<short> - { - static bool IsInteger() { return true; } - }; - - template<> - struct TypeInfo<int> - { - static bool IsInteger() { return true; } - }; - - template<> - struct TypeInfo<long> - { - static bool IsInteger() { return true; } - }; - - template<> - struct TypeInfo<unsigned char> - { - static bool IsInteger() { return true; } - }; - - template<> - struct TypeInfo<unsigned short> - { - static bool IsInteger() { return true; } - }; - - template<> - struct TypeInfo<unsigned int> - { - static bool IsInteger() { return true; } - }; - - template<> - struct TypeInfo<unsigned long> - { - static bool IsInteger() { return true; } - }; - - - //----------------------------------------------------------------------------------------------- - // - // Standard math functions with dummy overload for integer types - // - //----------------------------------------------------------------------------------------------- - - /** \brief A template class for providing wrappers for essential math functions. - - This template is spezialized for several types in order to provide a unified interface - for parser internal math function calls regardless of the data type. - */ - template<typename T> - struct MathImpl - { - static T Sin(T v) { return sin(v); } - static T Cos(T v) { return cos(v); } - static T Tan(T v) { return tan(v); } - static T ASin(T v) { return asin(v); } - static T ACos(T v) { return acos(v); } - static T ATan(T v) { return atan(v); } - static T ATan2(T v1, T v2) { return atan2(v1, v2); } - static T Sinh(T v) { return sinh(v); } - static T Cosh(T v) { return cosh(v); } - static T Tanh(T v) { return tanh(v); } - static T ASinh(T v) { return log(v + sqrt(v * v + 1)); } - static T ACosh(T v) { return log(v + sqrt(v * v - 1)); } - static T ATanh(T v) { return ((T)0.5 * log((1 + v) / (1 - v))); } - static T Log(T v) { return log(v); } - static T Log2(T v) { return log(v)/log((T)2); } // Logarithm base 2 - static T Log10(T v) { return log10(v); } // Logarithm base 10 - static T Exp(T v) { return exp(v); } - static T Abs(T v) { return (v>=0) ? v : -v; } - static T Sqrt(T v) { return sqrt(v); } - static T Rint(T v) { return floor(v + (T)0.5); } - 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); } - }; -} - -#endif +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_TEMPLATE_MAGIC_H +#define MU_PARSER_TEMPLATE_MAGIC_H + +#include <cmath> +#include "muParserError.h" + + +namespace mu +{ + //----------------------------------------------------------------------------------------------- + // + // Compile time type detection + // + //----------------------------------------------------------------------------------------------- + + /** \brief A class singling out integer types at compile time using + template meta programming. + */ + template<typename T> + struct TypeInfo + { + static bool IsInteger() { return false; } + }; + + template<> + struct TypeInfo<char> + { + static bool IsInteger() { return true; } + }; + + template<> + struct TypeInfo<short> + { + static bool IsInteger() { return true; } + }; + + template<> + struct TypeInfo<int> + { + static bool IsInteger() { return true; } + }; + + template<> + struct TypeInfo<long> + { + static bool IsInteger() { return true; } + }; + + template<> + struct TypeInfo<unsigned char> + { + static bool IsInteger() { return true; } + }; + + template<> + struct TypeInfo<unsigned short> + { + static bool IsInteger() { return true; } + }; + + template<> + struct TypeInfo<unsigned int> + { + static bool IsInteger() { return true; } + }; + + template<> + struct TypeInfo<unsigned long> + { + static bool IsInteger() { return true; } + }; + + + //----------------------------------------------------------------------------------------------- + // + // Standard math functions with dummy overload for integer types + // + //----------------------------------------------------------------------------------------------- + + /** \brief A template class for providing wrappers for essential math functions. + + This template is spezialized for several types in order to provide a unified interface + for parser internal math function calls regardless of the data type. + */ + template<typename T> + struct MathImpl + { + static T Sin(T v) { return sin(v); } + static T Cos(T v) { return cos(v); } + static T Tan(T v) { return tan(v); } + static T ASin(T v) { return asin(v); } + static T ACos(T v) { return acos(v); } + static T ATan(T v) { return atan(v); } + static T ATan2(T v1, T v2) { return atan2(v1, v2); } + static T Sinh(T v) { return sinh(v); } + static T Cosh(T v) { return cosh(v); } + static T Tanh(T v) { return tanh(v); } + static T ASinh(T v) { return log(v + sqrt(v * v + 1)); } + static T ACosh(T v) { return log(v + sqrt(v * v - 1)); } + static T ATanh(T v) { return ((T)0.5 * log((1 + v) / (1 - v))); } + static T Log(T v) { return log(v); } + static T Log2(T v) { return log(v) / log((T)2); } // Logarithm base 2 + static T Log10(T v) { return log10(v); } // Logarithm base 10 + static T Exp(T v) { return exp(v); } + static T Abs(T v) { return (v >= 0) ? v : -v; } + static T Sqrt(T v) { return sqrt(v); } + static T Rint(T v) { return floor(v + (T)0.5); } + 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); } + + static T UnaryMinus(T v) { return -v; } + static T UnaryPlus(T v) { return v; } + + static T Sum(const T *a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw ParserError(_T("too few arguments for function sum.")); + + T fRes = 0; + for (int i = 0; i < a_iArgc; ++i) fRes += a_afArg[i]; + return fRes; + } + + static T Avg(const T *a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw ParserError(_T("too few arguments for function sum.")); + + T fRes = 0; + for (int i = 0; i < a_iArgc; ++i) fRes += a_afArg[i]; + return fRes / (T)a_iArgc; + } + + static T Min(const T *a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw ParserError(_T("too few arguments for function min.")); + + T fRes = a_afArg[0]; + for (int i = 0; i < a_iArgc; ++i) + fRes = std::min(fRes, a_afArg[i]); + + return fRes; + } + + static T Max(const T *a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw ParserError(_T("too few arguments for function min.")); + + T fRes = a_afArg[0]; + for (int i = 0; i < a_iArgc; ++i) fRes = std::max(fRes, a_afArg[i]); + + return fRes; + } + + +#if defined (__GNUG__) + // Bei zu genauer definition von pi kann die Berechnung von + // sin(pi*a) mit a=1 10 x langsamer sein! + static constexpr T CONST_PI = (T)3.141592653589; +#else + static constexpr T CONST_PI = (T)3.141592653589793238462643; +#endif + + static constexpr T CONST_E = (T)2.718281828459045235360287; + }; +} + +#endif diff --git a/3rdParty/MuParser/include/muParserTest.h b/3rdParty/MuParser/include/muParserTest.h index c02b0218a9b5a320f7e16d680d7e7def13a00eec..9f4be55193a62591bbd052c823452db461bfb1f4 100644 --- a/3rdParty/MuParser/include/muParserTest.h +++ b/3rdParty/MuParser/include/muParserTest.h @@ -1,214 +1,226 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2013 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_TEST_H -#define MU_PARSER_TEST_H - -#include <string> -#include <cstdlib> -#include <numeric> // for accumulate -#include "muParser.h" -#include "muParserInt.h" - -/** \file - \brief This file contains the parser test class. -*/ - -namespace mu -{ - /** \brief Namespace for test cases. */ - namespace Test - { - //------------------------------------------------------------------------------ - /** \brief Test cases for unit testing. - - (C) 2004-2011 Ingo Berg - */ - class ParserTester // final - { - private: - static int c_iCount; - - // Multiarg callbacks - static value_type f1of1(value_type v) { return v;}; - - static value_type f1of2(value_type v, value_type ) {return v;}; - static value_type f2of2(value_type , value_type v) {return v;}; - - static value_type f1of3(value_type v, value_type , value_type ) {return v;}; - static value_type f2of3(value_type , value_type v, value_type ) {return v;}; - static value_type f3of3(value_type , value_type , value_type v) {return v;}; - - static value_type f1of4(value_type v, value_type, value_type , value_type ) {return v;} - static value_type f2of4(value_type , value_type v, value_type , value_type ) {return v;} - 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 Min(value_type a_fVal1, value_type a_fVal2) { return (a_fVal1<a_fVal2) ? a_fVal1 : a_fVal2; } - static value_type Max(value_type a_fVal1, value_type a_fVal2) { return (a_fVal1>a_fVal2) ? a_fVal1 : a_fVal2; } - - static value_type plus2(value_type v1) { return v1+2; } - static value_type times3(value_type v1) { return v1*3; } - static value_type sqr(value_type v1) { return v1*v1; } - static value_type sign(value_type v) { return -v; } - static value_type add(value_type v1, value_type v2) { return v1+v2; } - static value_type land(value_type v1, value_type v2) { return (int)v1 & (int)v2; } - - - static value_type FirstArg(const value_type* a_afArg, int a_iArgc) - { - if (!a_iArgc) - throw mu::Parser::exception_type( _T("too few arguments for function FirstArg.") ); - - return a_afArg[0]; - } - - static value_type LastArg(const value_type* a_afArg, int a_iArgc) - { - if (!a_iArgc) - throw mu::Parser::exception_type( _T("too few arguments for function LastArg.") ); - - return a_afArg[a_iArgc-1]; - } - - static value_type Sum(const value_type* a_afArg, int a_iArgc) - { - if (!a_iArgc) - throw mu::Parser::exception_type( _T("too few arguments for function sum.") ); - - value_type fRes=0; - for (int i=0; i<a_iArgc; ++i) fRes += a_afArg[i]; - return fRes; - } - - static value_type Rnd(value_type v) - { - return (value_type)(1+(v*std::rand()/(RAND_MAX+1.0))); - } - - static value_type RndWithString(const char_type*) - { - return (value_type)( 1 + (1000.0f * std::rand() / (RAND_MAX + 1.0) ) ); - } - - static value_type Ping() - { - return 10; - } - - static value_type ValueOf(const char_type*) - { - return 123; - } - - static value_type StrFun1(const char_type* v1) - { - int val(0); - stringstream_type(v1) >> val; - return (value_type)val; - } - - static value_type StrFun2(const char_type* v1, value_type v2) - { - int val(0); - stringstream_type(v1) >> val; - return (value_type)(val + v2); - } - - static value_type StrFun3(const char_type* v1, value_type v2, value_type v3) - { - int val(0); - stringstream_type(v1) >> val; - return val + v2 + v3; - } - - static value_type StrToFloat(const char_type* a_szMsg) - { - value_type val(0); - stringstream_type(a_szMsg) >> val; - return val; - } - - // postfix operator callback - static value_type Mega(value_type a_fVal) { return a_fVal * (value_type)1e6; } - static value_type Micro(value_type a_fVal) { return a_fVal * (value_type)1e-6; } - static value_type Milli(value_type a_fVal) { return a_fVal / (value_type)1e3; } - - // Custom value recognition - 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 TestStrArg(); - int TestIfThenElse(); - int TestBulkMode(); - - void Abort() const; - - public: - typedef int (ParserTester::*testfun_type)(); - - ParserTester(); - void Run(); - - private: - std::vector<testfun_type> m_vTestFun; - void AddTest(testfun_type a_pFun); - - // Test Double Parser - int EqnTest(const string_type& a_str, double a_fRes, bool a_fPass); - int EqnTestWithVarChange(const string_type& a_str, - double a_fRes1, - double a_fVar1, - double a_fRes2, - double a_fVar2); - int ThrowTest(const string_type& a_str, int a_iErrc, bool a_bFail = true); - - // 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 - -#endif - - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_TEST_H +#define MU_PARSER_TEST_H + +#include <string> +#include <cstdlib> +#include <numeric> // for accumulate +#include "muParser.h" +#include "muParserInt.h" + +/** \file + \brief This file contains the parser test class. +*/ + +namespace mu +{ + /** \brief Namespace for test cases. */ + namespace Test + { + /** \brief Test cases for unit testing. */ + class API_EXPORT_CXX ParserTester final + { + private: + static int c_iCount; + + static value_type f0() { return 42; }; + + // Multiarg callbacks + static value_type f1of1(value_type v) { return v; }; + + static value_type f1of2(value_type v, value_type) { return v; }; + static value_type f2of2(value_type, value_type v) { return v; }; + + static value_type f1of3(value_type v, value_type, value_type) { return v; }; + static value_type f2of3(value_type, value_type v, value_type) { return v; }; + static value_type f3of3(value_type, value_type, value_type v) { return v; }; + + static value_type f1of4(value_type v, value_type, value_type, value_type) { return v; } + static value_type f2of4(value_type, value_type v, value_type, value_type) { return v; } + 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 Min(value_type a_fVal1, value_type a_fVal2) { return (a_fVal1 < a_fVal2) ? a_fVal1 : a_fVal2; } + static value_type Max(value_type a_fVal1, value_type a_fVal2) { return (a_fVal1 > a_fVal2) ? a_fVal1 : a_fVal2; } + + static value_type plus2(value_type v1) { return v1 + 2; } + static value_type times3(value_type v1) { return v1 * 3; } + static value_type sqr(value_type v1) { return v1 * v1; } + static value_type sign(value_type v) { return -v; } + static value_type add(value_type v1, value_type v2) { return v1 + v2; } + static value_type land(value_type v1, value_type v2) { return (int)v1 & (int)v2; } + + + static value_type FirstArg(const value_type* a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw mu::Parser::exception_type(_T("too few arguments for function FirstArg.")); + + return a_afArg[0]; + } + + static value_type LastArg(const value_type* a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw mu::Parser::exception_type(_T("too few arguments for function LastArg.")); + + return a_afArg[a_iArgc - 1]; + } + + static value_type Sum(const value_type* a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw mu::Parser::exception_type(_T("too few arguments for function sum.")); + + value_type fRes = 0; + for (int i = 0; i < a_iArgc; ++i) fRes += a_afArg[i]; + return fRes; + } + + static value_type Rnd(value_type v) + { + return (value_type)(1 + (v * std::rand() / (RAND_MAX + 1.0))); + } + + static value_type RndWithString(const char_type*) + { + return (value_type)(1.0 + (1000.0 * std::rand() / (RAND_MAX + 1.0))); + } + + static value_type Ping() + { + return 10; + } + + static value_type ValueOf(const char_type*) + { + return 123; + } + + static value_type StrFun1(const char_type* v1) + { + int val(0); + stringstream_type(v1) >> val; + return (value_type)val; + } + + static value_type StrFun2(const char_type* v1, value_type v2) + { + int val(0); + stringstream_type(v1) >> val; + return (value_type)(val + v2); + } + + static value_type StrFun3(const char_type* v1, value_type v2, value_type v3) + { + int val(0); + stringstream_type(v1) >> val; + return val + v2 + v3; + } + + static value_type StrFun4(const char_type* v1, value_type v2, value_type v3, value_type v4) + { + int val(0); + stringstream_type(v1) >> val; + return val + v2 + v3 + v4; + } + + static value_type StrFun5(const char_type* v1, value_type v2, value_type v3, value_type v4, value_type v5) + { + int val(0); + stringstream_type(v1) >> val; + return val + v2 + v3 + v4 + v5; + } + + static value_type StrToFloat(const char_type* a_szMsg) + { + value_type val(0); + stringstream_type(a_szMsg) >> val; + return val; + } + + // postfix operator callback + static value_type Mega(value_type a_fVal) { return a_fVal * (value_type)1e6; } + static value_type Micro(value_type a_fVal) { return a_fVal * (value_type)1e-6; } + static value_type Milli(value_type a_fVal) { return a_fVal / (value_type)1e3; } + + // Custom value recognition + 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 TestStrArg(); + int TestIfThenElse(); + int TestBulkMode(); + int TestOssFuzzTestCases(); + + void Abort() const; + + public: + typedef int (ParserTester::* testfun_type)(); + + ParserTester(); + int Run(); + + private: + std::vector<testfun_type> m_vTestFun; + void AddTest(testfun_type a_pFun); + + // Test Double Parser + int EqnTest(const string_type& a_str, double a_fRes, bool a_fPass); + int EqnTestWithVarChange(const string_type& a_str, double a_fRes1, double a_fVar1, double a_fRes2, double a_fVar2); + int ThrowTest(const string_type& a_str, int a_iErrc, bool a_bFail = true); + + // 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 + +#endif + diff --git a/3rdParty/MuParser/include/muParserToken.h b/3rdParty/MuParser/include/muParserToken.h index fc91d7818c0648e8a79cecd489195e4ade5b927d..f12a4e8d0c2af398a791124a0643d2394400d3cf 100644 --- a/3rdParty/MuParser/include/muParserToken.h +++ b/3rdParty/MuParser/include/muParserToken.h @@ -1,401 +1,409 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2004-2013 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_TOKEN_H -#define MU_PARSER_TOKEN_H - -#include <cassert> -#include <string> -#include <stack> -#include <vector> -#include <memory> - -#include "muParserError.h" -#include "muParserCallback.h" - -/** \file - \brief This file contains the parser token definition. -*/ - -namespace mu -{ - /** \brief Encapsulation of the data for a single formula token. - - Formula token implementation. Part of the Math Parser Package. - Formula tokens can be either one of the following: - <ul> - <li>value</li> - <li>variable</li> - <li>function with numerical arguments</li> - <li>functions with a string as argument</li> - <li>prefix operators</li> - <li>infix operators</li> - <li>binary operator</li> - </ul> - - \author (C) 2004-2013 Ingo Berg - */ - template<typename TBase, typename TString> - class ParserToken - { - private: - - ECmdCode m_iCode; ///< Type of the token; The token type is a constant of type #ECmdCode. - ETypeCode m_iType; - void *m_pTok; ///< Stores Token pointer; not applicable for all tokens - int m_iIdx; ///< An otional index to an external buffer storing the token data - TString m_strTok; ///< Token string - TString m_strVal; ///< Value for string variables - value_type m_fVal; ///< the value - std::auto_ptr<ParserCallback> m_pCallback; - - public: - - //--------------------------------------------------------------------------- - /** \brief Constructor (default). - - Sets token to an neutral state of type cmUNKNOWN. - \throw nothrow - \sa ECmdCode - */ - ParserToken() - :m_iCode(cmUNKNOWN) - ,m_iType(tpVOID) - ,m_pTok(0) - ,m_iIdx(-1) - ,m_strTok() - ,m_strVal() - ,m_fVal(0) - ,m_pCallback() - {} - - //------------------------------------------------------------------------------ - /** \brief Create token from another one. - - Implemented by calling Assign(...) - \throw nothrow - \post m_iType==cmUNKNOWN - \sa #Assign - */ - ParserToken(const ParserToken &a_Tok) - { - Assign(a_Tok); - } - - //------------------------------------------------------------------------------ - /** \brief Assignement operator. - - Copy token state from another token and return this. - Implemented by calling Assign(...). - \throw nothrow - */ - ParserToken& operator=(const ParserToken &a_Tok) - { - Assign(a_Tok); - return *this; - } - - //------------------------------------------------------------------------------ - /** \brief Copy token information from argument. - - \throw nothrow - */ - void Assign(const ParserToken &a_Tok) - { - m_iCode = a_Tok.m_iCode; - m_pTok = a_Tok.m_pTok; - m_strTok = a_Tok.m_strTok; - m_iIdx = a_Tok.m_iIdx; - m_strVal = a_Tok.m_strVal; - m_iType = a_Tok.m_iType; - m_fVal = a_Tok.m_fVal; - // create new callback object if a_Tok has one - m_pCallback.reset(a_Tok.m_pCallback.get() ? a_Tok.m_pCallback->Clone() : 0); - } - - //------------------------------------------------------------------------------ - /** \brief Assign a token type. - - Token may not be of type value, variable or function. Those have seperate set functions. - - \pre [assert] a_iType!=cmVAR - \pre [assert] a_iType!=cmVAL - \pre [assert] a_iType!=cmFUNC - \post m_fVal = 0 - \post m_pTok = 0 - */ - ParserToken& Set(ECmdCode a_iType, const TString &a_strTok=TString()) - { - // The following types cant be set this way, they have special Set functions - assert(a_iType!=cmVAR); - assert(a_iType!=cmVAL); - assert(a_iType!=cmFUNC); - - m_iCode = a_iType; - m_iType = tpVOID; - m_pTok = 0; - m_strTok = a_strTok; - m_iIdx = -1; - - return *this; - } - - //------------------------------------------------------------------------------ - /** \brief Set Callback type. */ - ParserToken& Set(const ParserCallback &a_pCallback, const TString &a_sTok) - { - assert(a_pCallback.GetAddr()); - - m_iCode = a_pCallback.GetCode(); - m_iType = tpVOID; - m_strTok = a_sTok; - m_pCallback.reset(new ParserCallback(a_pCallback)); - - m_pTok = 0; - m_iIdx = -1; - - return *this; - } - - //------------------------------------------------------------------------------ - /** \brief Make this token a value token. - - Member variables not necessary for value tokens will be invalidated. - \throw nothrow - */ - ParserToken& SetVal(TBase a_fVal, const TString &a_strTok=TString()) - { - m_iCode = cmVAL; - m_iType = tpDBL; - m_fVal = a_fVal; - m_strTok = a_strTok; - m_iIdx = -1; - - m_pTok = 0; - m_pCallback.reset(0); - - return *this; - } - - //------------------------------------------------------------------------------ - /** \brief make this token a variable token. - - Member variables not necessary for variable tokens will be invalidated. - \throw nothrow - */ - ParserToken& SetVar(TBase *a_pVar, const TString &a_strTok) - { - m_iCode = cmVAR; - m_iType = tpDBL; - m_strTok = a_strTok; - m_iIdx = -1; - m_pTok = (void*)a_pVar; - m_pCallback.reset(0); - return *this; - } - - //------------------------------------------------------------------------------ - /** \brief Make this token a variable token. - - Member variables not necessary for variable tokens will be invalidated. - \throw nothrow - */ - ParserToken& SetString(const TString &a_strTok, std::size_t a_iSize) - { - m_iCode = cmSTRING; - m_iType = tpSTR; - m_strTok = a_strTok; - m_iIdx = static_cast<int>(a_iSize); - - m_pTok = 0; - m_pCallback.reset(0); - return *this; - } - - //------------------------------------------------------------------------------ - /** \brief Set an index associated with the token related data. - - In cmSTRFUNC - This is the index to a string table in the main parser. - \param a_iIdx The index the string function result will take in the bytecode parser. - \throw exception_type if #a_iIdx<0 or #m_iType!=cmSTRING - */ - void SetIdx(int a_iIdx) - { - if (m_iCode!=cmSTRING || a_iIdx<0) - throw ParserError(ecINTERNAL_ERROR); - - m_iIdx = a_iIdx; - } - - //------------------------------------------------------------------------------ - /** \brief Return Index associated with the token related data. - - In cmSTRFUNC - This is the index to a string table in the main parser. - - \throw exception_type if #m_iIdx<0 or #m_iType!=cmSTRING - \return The index the result will take in the Bytecode calculatin array (#m_iIdx). - */ - int GetIdx() const - { - if (m_iIdx<0 || m_iCode!=cmSTRING ) - throw ParserError(ecINTERNAL_ERROR); - - return m_iIdx; - } - - //------------------------------------------------------------------------------ - /** \brief Return the token type. - - \return #m_iType - \throw nothrow - */ - ECmdCode GetCode() const - { - if (m_pCallback.get()) - { - return m_pCallback->GetCode(); - } - else - { - return m_iCode; - } - } - - //------------------------------------------------------------------------------ - ETypeCode GetType() const - { - if (m_pCallback.get()) - { - return m_pCallback->GetType(); - } - else - { - return m_iType; - } - } - - //------------------------------------------------------------------------------ - int GetPri() const - { - if ( !m_pCallback.get()) - throw ParserError(ecINTERNAL_ERROR); - - if ( m_pCallback->GetCode()!=cmOPRT_BIN && m_pCallback->GetCode()!=cmOPRT_INFIX) - throw ParserError(ecINTERNAL_ERROR); - - return m_pCallback->GetPri(); - } - - //------------------------------------------------------------------------------ - EOprtAssociativity GetAssociativity() const - { - if (m_pCallback.get()==NULL || m_pCallback->GetCode()!=cmOPRT_BIN) - throw ParserError(ecINTERNAL_ERROR); - - return m_pCallback->GetAssociativity(); - } - - //------------------------------------------------------------------------------ - /** \brief Return the address of the callback function assoziated with - function and operator tokens. - - \return The pointer stored in #m_pTok. - \throw exception_type if token type is non of: - <ul> - <li>cmFUNC</li> - <li>cmSTRFUNC</li> - <li>cmPOSTOP</li> - <li>cmINFIXOP</li> - <li>cmOPRT_BIN</li> - </ul> - \sa ECmdCode - */ - generic_fun_type GetFuncAddr() const - { - return (m_pCallback.get()) ? (generic_fun_type)m_pCallback->GetAddr() : 0; - } - - //------------------------------------------------------------------------------ - /** \biref Get value of the token. - - Only applicable to variable and value tokens. - \throw exception_type if token is no value/variable token. - */ - TBase GetVal() const - { - switch (m_iCode) - { - case cmVAL: return m_fVal; - case cmVAR: return *((TBase*)m_pTok); - default: throw ParserError(ecVAL_EXPECTED); - } - } - - //------------------------------------------------------------------------------ - /** \brief Get address of a variable token. - - Valid only if m_iType==CmdVar. - \throw exception_type if token is no variable token. - */ - TBase* GetVar() const - { - if (m_iCode!=cmVAR) - throw ParserError(ecINTERNAL_ERROR); - - return (TBase*)m_pTok; - } - - //------------------------------------------------------------------------------ - /** \brief Return the number of function arguments. - - Valid only if m_iType==CmdFUNC. - */ - int GetArgCount() const - { - assert(m_pCallback.get()); - - if (!m_pCallback->GetAddr()) - throw ParserError(ecINTERNAL_ERROR); - - return m_pCallback->GetArgc(); - } - - //------------------------------------------------------------------------------ - /** \brief Return the token identifier. - - If #m_iType is cmSTRING the token identifier is the value of the string argument - for a string function. - \return #m_strTok - \throw nothrow - \sa m_strTok - */ - const TString& GetAsString() const - { - return m_strTok; - } - }; -} // namespace mu - -#endif +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_TOKEN_H +#define MU_PARSER_TOKEN_H + +#include <string> +#include <stack> +#include <vector> +#include <memory> + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable : 26812) +#endif + +#include "muParserError.h" +#include "muParserCallback.h" + +/** \file + \brief This file contains the parser token definition. +*/ + +namespace mu +{ + /** \brief Encapsulation of the data for a single formula token. + + Formula token implementation. Part of the Math Parser Package. + Formula tokens can be either one of the following: + <ul> + <li>value</li> + <li>variable</li> + <li>function with numerical arguments</li> + <li>functions with a string as argument</li> + <li>prefix operators</li> + <li>infix operators</li> + <li>binary operator</li> + </ul> + */ + template<typename TBase, typename TString> + class ParserToken final + { + private: + + ECmdCode m_iCode; ///< Type of the token; The token type is a constant of type #ECmdCode. + ETypeCode m_iType; + void* m_pTok; ///< Stores Token pointer; not applicable for all tokens + int m_iIdx; ///< An otional index to an external buffer storing the token data + TString m_strTok; ///< Token string + TString m_strVal; ///< Value for string variables + value_type m_fVal; ///< the value + std::unique_ptr<ParserCallback> m_pCallback; + + public: + + /** \brief Constructor (default). + + Sets token to an neutral state of type cmUNKNOWN. + \throw nothrow + \sa ECmdCode + */ + ParserToken() + :m_iCode(cmUNKNOWN) + , m_iType(tpVOID) + , m_pTok(0) + , m_iIdx(-1) + , m_strTok() + , m_strVal() + , m_fVal(0) + , m_pCallback() + {} + + //------------------------------------------------------------------------------ + /** \brief Create token from another one. + + Implemented by calling Assign(...) + \throw nothrow + \post m_iType==cmUNKNOWN + \sa #Assign + */ + ParserToken(const ParserToken& a_Tok) + { + Assign(a_Tok); + } + + + /** \brief Assignment operator. + + Copy token state from another token and return this. + Implemented by calling Assign(...). + \throw nothrow + */ + ParserToken& operator=(const ParserToken& a_Tok) + { + Assign(a_Tok); + return *this; + } + + + /** \brief Copy token information from argument. + + \throw nothrow + */ + void Assign(const ParserToken& a_Tok) + { + m_iCode = a_Tok.m_iCode; + m_pTok = a_Tok.m_pTok; + m_strTok = a_Tok.m_strTok; + m_iIdx = a_Tok.m_iIdx; + m_strVal = a_Tok.m_strVal; + m_iType = a_Tok.m_iType; + m_fVal = a_Tok.m_fVal; + // create new callback object if a_Tok has one + m_pCallback.reset(a_Tok.m_pCallback.get() ? a_Tok.m_pCallback->Clone() : 0); + } + + //------------------------------------------------------------------------------ + /** \brief Assign a token type. + + Token may not be of type value, variable or function. Those have separate set functions. + + \pre [assert] a_iType!=cmVAR + \pre [assert] a_iType!=cmVAL + \pre [assert] a_iType!=cmFUNC + \post m_fVal = 0 + \post m_pTok = 0 + */ + ParserToken& Set(ECmdCode a_iType, const TString& a_strTok = TString()) + { + // The following types can't be set this way, they have special Set functions + MUP_ASSERT(a_iType != cmVAR); + MUP_ASSERT(a_iType != cmVAL); + MUP_ASSERT(a_iType != cmFUNC); + + m_iCode = a_iType; + m_iType = tpVOID; + m_pTok = 0; + m_strTok = a_strTok; + m_iIdx = -1; + + return *this; + } + + //------------------------------------------------------------------------------ + /** \brief Set Callback type. */ + ParserToken& Set(const ParserCallback& a_pCallback, const TString& a_sTok) + { + MUP_ASSERT(a_pCallback.GetAddr()); + + m_iCode = a_pCallback.GetCode(); + m_iType = tpVOID; + m_strTok = a_sTok; + m_pCallback.reset(new ParserCallback(a_pCallback)); + + m_pTok = 0; + m_iIdx = -1; + + return *this; + } + + //------------------------------------------------------------------------------ + /** \brief Make this token a value token. + + Member variables not necessary for value tokens will be invalidated. + \throw nothrow + */ + ParserToken& SetVal(TBase a_fVal, const TString& a_strTok = TString()) + { + m_iCode = cmVAL; + m_iType = tpDBL; + m_fVal = a_fVal; + m_strTok = a_strTok; + m_iIdx = -1; + + m_pTok = 0; + m_pCallback.reset(0); + + return *this; + } + + //------------------------------------------------------------------------------ + /** \brief make this token a variable token. + + Member variables not necessary for variable tokens will be invalidated. + \throw nothrow + */ + ParserToken& SetVar(TBase* a_pVar, const TString& a_strTok) + { + m_iCode = cmVAR; + m_iType = tpDBL; + m_strTok = a_strTok; + m_iIdx = -1; + m_pTok = (void*)a_pVar; + m_pCallback.reset(0); + return *this; + } + + //------------------------------------------------------------------------------ + /** \brief Make this token a variable token. + + Member variables not necessary for variable tokens will be invalidated. + \throw nothrow + */ + ParserToken& SetString(const TString& a_strTok, std::size_t a_iSize) + { + m_iCode = cmSTRING; + m_iType = tpSTR; + m_strTok = a_strTok; + m_iIdx = static_cast<int>(a_iSize); + + m_pTok = 0; + m_pCallback.reset(0); + return *this; + } + + //------------------------------------------------------------------------------ + /** \brief Set an index associated with the token related data. + + In cmSTRFUNC - This is the index to a string table in the main parser. + \param a_iIdx The index the string function result will take in the bytecode parser. + \throw exception_type if #a_iIdx<0 or #m_iType!=cmSTRING + */ + void SetIdx(int a_iIdx) + { + if (m_iCode != cmSTRING || a_iIdx < 0) + throw ParserError(ecINTERNAL_ERROR); + + m_iIdx = a_iIdx; + } + + //------------------------------------------------------------------------------ + /** \brief Return Index associated with the token related data. + + In cmSTRFUNC - This is the index to a string table in the main parser. + + \throw exception_type if #m_iIdx<0 or #m_iType!=cmSTRING + \return The index the result will take in the Bytecode calculatin array (#m_iIdx). + */ + int GetIdx() const + { + if (m_iIdx < 0 || m_iCode != cmSTRING) + throw ParserError(ecINTERNAL_ERROR); + + return m_iIdx; + } + + //------------------------------------------------------------------------------ + /** \brief Return the token type. + + \return #m_iType + \throw nothrow + */ + ECmdCode GetCode() const + { + if (m_pCallback.get()) + { + return m_pCallback->GetCode(); + } + else + { + return m_iCode; + } + } + + //------------------------------------------------------------------------------ + ETypeCode GetType() const + { + if (m_pCallback.get()) + { + return m_pCallback->GetType(); + } + else + { + return m_iType; + } + } + + //------------------------------------------------------------------------------ + int GetPri() const + { + if (!m_pCallback.get()) + throw ParserError(ecINTERNAL_ERROR); + + if (m_pCallback->GetCode() != cmOPRT_BIN && m_pCallback->GetCode() != cmOPRT_INFIX) + throw ParserError(ecINTERNAL_ERROR); + + return m_pCallback->GetPri(); + } + + //------------------------------------------------------------------------------ + EOprtAssociativity GetAssociativity() const + { + if (m_pCallback.get() == nullptr || m_pCallback->GetCode() != cmOPRT_BIN) + throw ParserError(ecINTERNAL_ERROR); + + return m_pCallback->GetAssociativity(); + } + + //------------------------------------------------------------------------------ + /** \brief Return the address of the callback function assoziated with + function and operator tokens. + + \return The pointer stored in #m_pTok. + \throw exception_type if token type is non of: + <ul> + <li>cmFUNC</li> + <li>cmSTRFUNC</li> + <li>cmPOSTOP</li> + <li>cmINFIXOP</li> + <li>cmOPRT_BIN</li> + </ul> + \sa ECmdCode + */ + generic_fun_type GetFuncAddr() const + { + return (m_pCallback.get()) ? (generic_fun_type)m_pCallback->GetAddr() : 0; + } + + //------------------------------------------------------------------------------ + /** \biref Get value of the token. + + Only applicable to variable and value tokens. + \throw exception_type if token is no value/variable token. + */ + TBase GetVal() const + { + switch (m_iCode) + { + case cmVAL: return m_fVal; + case cmVAR: return *((TBase*)m_pTok); + default: throw ParserError(ecVAL_EXPECTED); + } + } + + //------------------------------------------------------------------------------ + /** \brief Get address of a variable token. + + Valid only if m_iType==CmdVar. + \throw exception_type if token is no variable token. + */ + TBase* GetVar() const + { + if (m_iCode != cmVAR) + throw ParserError(ecINTERNAL_ERROR); + + return (TBase*)m_pTok; + } + + //------------------------------------------------------------------------------ + /** \brief Return the number of function arguments. + + Valid only if m_iType==CmdFUNC. + */ + int GetArgCount() const + { + MUP_ASSERT(m_pCallback.get()); + + if (!m_pCallback->GetAddr()) + throw ParserError(ecINTERNAL_ERROR); + + return m_pCallback->GetArgc(); + } + + //------------------------------------------------------------------------------ + /** \brief Return the token identifier. + + If #m_iType is cmSTRING the token identifier is the value of the string argument + for a string function. + \return #m_strTok + \throw nothrow + \sa m_strTok + */ + const TString& GetAsString() const + { + return m_strTok; + } + }; +} // namespace mu + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif + +#endif diff --git a/3rdParty/MuParser/include/muParserTokenReader.h b/3rdParty/MuParser/include/muParserTokenReader.h index 9d96225d9a64c0c6e36c17dbad6c7624fe0ee1f2..caeb920b85ebba1eecd906d7314a872f2bd26363 100644 --- a/3rdParty/MuParser/include/muParserTokenReader.h +++ b/3rdParty/MuParser/include/muParserTokenReader.h @@ -1,161 +1,160 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2004-2013 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_TOKEN_READER_H -#define MU_PARSER_TOKEN_READER_H - -#include <cassert> -#include <cstdio> -#include <cstring> -#include <list> -#include <map> -#include <memory> -#include <stack> -#include <string> - -#include "muParserDef.h" -#include "muParserToken.h" - -/** \file - \brief This file contains the parser token reader definition. -*/ - - -namespace mu -{ - // Forward declaration - class ParserBase; - - /** \brief Token reader for the ParserBase class. - - */ - class ParserTokenReader - { - private: - - typedef ParserToken<value_type, string_type> token_type; - - public: - - ParserTokenReader(ParserBase *a_pParent); - ParserTokenReader* Clone(ParserBase *a_pParent) const; - - void AddValIdent(identfun_type a_pCallback); - void SetVarCreator(facfun_type a_pFactory, void *pUserData); - void SetFormula(const string_type &a_strFormula); - void SetArgSep(char_type cArgSep); - - int GetPos() const; - const string_type& GetExpr() const; - varmap_type& GetUsedVar(); - char_type GetArgSep() const; - - void IgnoreUndefVar(bool bIgnore); - void ReInit(); - token_type ReadNextToken(); - - private: - - /** \brief Syntax codes. - - The syntax codes control the syntax check done during the first time parsing of - the expression string. They are flags that indicate which tokens are allowed next - if certain tokens are identified. - */ - enum ESynCodes - { - noBO = 1 << 0, ///< to avoid i.e. "cos(7)(" - noBC = 1 << 1, ///< to avoid i.e. "sin)" or "()" - noVAL = 1 << 2, ///< to avoid i.e. "tan 2" or "sin(8)3.14" - noVAR = 1 << 3, ///< to avoid i.e. "sin a" or "sin(8)a" - noARG_SEP = 1 << 4, ///< to avoid i.e. ",," or "+," ... - noFUN = 1 << 5, ///< to avoid i.e. "sqrt cos" or "(1)sin" - noOPT = 1 << 6, ///< to avoid i.e. "(+)" - noPOSTOP = 1 << 7, ///< to avoid i.e. "(5!!)" "sin!" - noINFIXOP = 1 << 8, ///< to avoid i.e. "++4" "!!4" - noEND = 1 << 9, ///< to avoid unexpected end of formula - noSTR = 1 << 10, ///< to block numeric arguments on string functions - noASSIGN = 1 << 11, ///< to block assignement to constant i.e. "4=7" - noIF = 1 << 12, - noELSE = 1 << 13, - sfSTART_OF_LINE = noOPT | noBC | noPOSTOP | noASSIGN | noIF | noELSE | noARG_SEP, - noANY = ~0 ///< All of he above flags set - }; - - ParserTokenReader(const ParserTokenReader &a_Reader); - ParserTokenReader& operator=(const ParserTokenReader &a_Reader); - void Assign(const ParserTokenReader &a_Reader); - - void SetParent(ParserBase *a_pParent); - int ExtractToken(const char_type *a_szCharSet, - string_type &a_strTok, - int a_iPos) const; - int ExtractOperatorToken(string_type &a_sTok, int a_iPos) const; - - bool IsBuiltIn(token_type &a_Tok); - bool IsArgSep(token_type &a_Tok); - bool IsEOF(token_type &a_Tok); - bool IsInfixOpTok(token_type &a_Tok); - bool IsFunTok(token_type &a_Tok); - bool IsPostOpTok(token_type &a_Tok); - bool IsOprt(token_type &a_Tok); - bool IsValTok(token_type &a_Tok); - bool IsVarTok(token_type &a_Tok); - bool IsStrVarTok(token_type &a_Tok); - bool IsUndefVarTok(token_type &a_Tok); - bool IsString(token_type &a_Tok); - void Error(EErrorCodes a_iErrc, - int a_iPos = -1, - const string_type &a_sTok = string_type() ) const; - - token_type& SaveBeforeReturn(const token_type &tok); - - ParserBase *m_pParser; - string_type m_strFormula; - int m_iPos; - int m_iSynFlags; - bool m_bIgnoreUndefVar; - - const funmap_type *m_pFunDef; - const funmap_type *m_pPostOprtDef; - const funmap_type *m_pInfixOprtDef; - const funmap_type *m_pOprtDef; - const valmap_type *m_pConstDef; - const strmap_type *m_pStrVarDef; - varmap_type *m_pVarDef; ///< The only non const pointer to parser internals - facfun_type m_pFactory; - void *m_pFactoryData; - std::list<identfun_type> m_vIdentFun; ///< Value token identification function - varmap_type m_UsedVar; - value_type m_fZero; ///< Dummy value of zero, referenced by undefined variables - int m_iBrackets; - token_type m_lastTok; - char_type m_cArgSep; ///< The character used for separating function arguments - }; -} // namespace mu - -#endif - - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef MU_PARSER_TOKEN_READER_H +#define MU_PARSER_TOKEN_READER_H + +#include <cstdio> +#include <cstring> +#include <list> +#include <map> +#include <memory> +#include <stack> +#include <string> + +#include "muParserDef.h" +#include "muParserToken.h" + +/** \file + \brief This file contains the parser token reader definition. +*/ + + +namespace mu +{ + // Forward declaration + class ParserBase; + + /** \brief Token reader for the ParserBase class. */ + class ParserTokenReader final + { + private: + + typedef ParserToken<value_type, string_type> token_type; + + public: + + ParserTokenReader(ParserBase* a_pParent); + ParserTokenReader* Clone(ParserBase* a_pParent) const; + + void AddValIdent(identfun_type a_pCallback); + void SetVarCreator(facfun_type a_pFactory, void* pUserData); + void SetFormula(const string_type& a_strFormula); + void SetArgSep(char_type cArgSep); + + int GetPos() const; + const string_type& GetExpr() const; + varmap_type& GetUsedVar(); + char_type GetArgSep() const; + + void IgnoreUndefVar(bool bIgnore); + void ReInit(); + token_type ReadNextToken(); + + private: + + /** \brief Syntax codes. + + The syntax codes control the syntax check done during the first time parsing of + the expression string. They are flags that indicate which tokens are allowed next + if certain tokens are identified. + */ + enum ESynCodes + { + noBO = 1 << 0, ///< to avoid i.e. "cos(7)(" + noBC = 1 << 1, ///< to avoid i.e. "sin)" or "()" + noVAL = 1 << 2, ///< to avoid i.e. "tan 2" or "sin(8)3.14" + noVAR = 1 << 3, ///< to avoid i.e. "sin a" or "sin(8)a" + noARG_SEP = 1 << 4, ///< to avoid i.e. ",," or "+," ... + noFUN = 1 << 5, ///< to avoid i.e. "sqrt cos" or "(1)sin" + noOPT = 1 << 6, ///< to avoid i.e. "(+)" + noPOSTOP = 1 << 7, ///< to avoid i.e. "(5!!)" "sin!" + noINFIXOP = 1 << 8, ///< to avoid i.e. "++4" "!!4" + noEND = 1 << 9, ///< to avoid unexpected end of formula + noSTR = 1 << 10, ///< to block numeric arguments on string functions + noASSIGN = 1 << 11, ///< to block assignment to constant i.e. "4=7" + noIF = 1 << 12, + noELSE = 1 << 13, + sfSTART_OF_LINE = noOPT | noBC | noPOSTOP | noASSIGN | noIF | noELSE | noARG_SEP, + noANY = ~0 ///< All of he above flags set + }; + + ParserTokenReader(const ParserTokenReader& a_Reader); + ParserTokenReader& operator=(const ParserTokenReader& a_Reader); + void Assign(const ParserTokenReader& a_Reader); + + void SetParent(ParserBase* a_pParent); + int ExtractToken(const char_type* a_szCharSet, string_type& a_strTok, std::size_t a_iPos) const; + int ExtractOperatorToken(string_type& a_sTok, std::size_t a_iPos) const; + + bool IsBuiltIn(token_type& a_Tok); + bool IsArgSep(token_type& a_Tok); + bool IsEOF(token_type& a_Tok); + bool IsInfixOpTok(token_type& a_Tok); + bool IsFunTok(token_type& a_Tok); + bool IsPostOpTok(token_type& a_Tok); + bool IsOprt(token_type& a_Tok); + bool IsValTok(token_type& a_Tok); + bool IsVarTok(token_type& a_Tok); + bool IsStrVarTok(token_type& a_Tok); + bool IsUndefVarTok(token_type& a_Tok); + bool IsString(token_type& a_Tok); + void Error(EErrorCodes a_iErrc, int a_iPos = -1, const string_type& a_sTok = string_type()) const; + + token_type& SaveBeforeReturn(const token_type& tok); + + ParserBase* m_pParser; + string_type m_strFormula; + int m_iPos; + int m_iSynFlags; + bool m_bIgnoreUndefVar; + + const funmap_type* m_pFunDef; + const funmap_type* m_pPostOprtDef; + const funmap_type* m_pInfixOprtDef; + const funmap_type* m_pOprtDef; + const valmap_type* m_pConstDef; + const strmap_type* m_pStrVarDef; + + varmap_type* m_pVarDef; ///< The only non const pointer to parser internals + facfun_type m_pFactory; + void* m_pFactoryData; + std::list<identfun_type> m_vIdentFun; ///< Value token identification function + varmap_type m_UsedVar; + value_type m_fZero; ///< Dummy value of zero, referenced by undefined variables + + std::stack<int> m_bracketStack; + + token_type m_lastTok; + char_type m_cArgSep; ///< The character used for separating function arguments + }; +} // namespace mu + +#endif + + diff --git a/3rdParty/MuParser/samples/example1/example1.cpp b/3rdParty/MuParser/samples/example1/example1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5505728d54ad7ce671de730d1cb95ff3ea037130 --- /dev/null +++ b/3rdParty/MuParser/samples/example1/example1.cpp @@ -0,0 +1,561 @@ +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParserTest.h" + +#include <cstdlib> +#include <cstring> +#include <cmath> +#include <string> +#include <iostream> +#include <locale> +#include <limits> +#include <ios> +#include <iomanip> +#include <numeric> + +#include "muParser.h" + +using namespace std; +using namespace mu; + + +// Forward declarations +void CalcBulk(); + +// Operator callback functions +static value_type Mega(value_type a_fVal) { return a_fVal * 1e6; } +static value_type Milli(value_type a_fVal) { return a_fVal / (value_type)1e3; } +static value_type Rnd(value_type v) { return v * std::rand() / (value_type)(RAND_MAX + 1.0); } +static value_type Not(value_type v) { return v == 0; } +static value_type Add(value_type v1, value_type v2) { return v1 + v2; } +static value_type Mul(value_type v1, value_type v2) { return v1 * v2; } +static value_type Arg2Of2(value_type /* v1 */, value_type v2) { return v2; } +static value_type Arg1Of2(value_type v1, value_type /* v2 */) { return v1; } + + +static value_type ThrowAnException(value_type) +{ + throw std::runtime_error("This function does throw an exception."); +} + + +static value_type BulkFun1(int nBulkIdx, int nThreadIdx, value_type v1) +{ + // Note: I'm just doing something with all three parameters to shut + // compiler warnings up! + return (value_type)nBulkIdx + nThreadIdx + v1; +} + + +static value_type Ping() +{ + mu::console() << "ping\n"; + return 0; +} + + +static value_type StrFun0(const char_type* szMsg) +{ + if (szMsg) + mu::console() << szMsg << std::endl; + + return 999; +} + + +static value_type StrFun2(const char_type* v1, value_type v2, value_type v3) +{ + mu::console() << v1 << std::endl; + return v2 + v3; +} + + +static value_type Debug(mu::value_type v1, mu::value_type v2) +{ + ParserBase::EnableDebugDump(v1 != 0, v2 != 0); + mu::console() << _T("Bytecode dumping ") << ((v1 != 0) ? _T("active") : _T("inactive")) << _T("\n"); + return 1; +} + + +// Factory function for creating new parser variables +// This could as well be a function performing database queries. +static value_type* AddVariable(const char_type* a_szName, void* a_pUserData) +{ + // I don't want dynamic allocation here, so i used this static buffer + // If you want dynamic allocation you must allocate all variables dynamically + // in order to delete them later on. Or you find other ways to keep track of + // variables that have been created implicitely. + static value_type afValBuf[100]; + static int iVal = -1; + + ++iVal; + + mu::console() + << _T("Generating new variable \"") + << a_szName << std::dec << _T("\" (slots left: ") + << 99 - iVal << _T(")") + << _T(" User data pointer is:") + << std::hex << a_pUserData << endl; + + afValBuf[iVal] = 0; + + if (iVal >= 99) + throw mu::ParserError(_T("Variable buffer overflow.")); + else + return &afValBuf[iVal]; +} + +int IsBinValue(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal) +{ + if (a_szExpr[0] != 0 && a_szExpr[1] != 'b') + return 0; + + unsigned iVal = 0; + unsigned iBits = sizeof(iVal) * 8; + unsigned i = 0; + + for (i = 0; (a_szExpr[i + 2] == '0' || a_szExpr[i + 2] == '1') && i < iBits; ++i) + iVal |= (int)(a_szExpr[i + 2] == '1') << ((iBits - 1) - i); + + if (i == 0) + return 0; + + if (i == iBits) + throw mu::Parser::exception_type(_T("Binary to integer conversion error (overflow).")); + + *a_fVal = (unsigned)(iVal >> (iBits - i)); + *a_iPos += i + 2; + + return 1; +} + +static int IsHexValue(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal) +{ + if (a_szExpr[1] == 0 || (a_szExpr[0] != '0' || a_szExpr[1] != 'x')) + return 0; + + unsigned iVal(0); + + // New code based on streams for UNICODE compliance: + stringstream_type::pos_type nPos(0); + stringstream_type ss(a_szExpr + 2); + ss >> std::hex >> iVal; + nPos = ss.tellg(); + + if (nPos == (stringstream_type::pos_type)0) + return 1; + + *a_iPos += (int)(2 + nPos); + *a_fVal = (value_type)iVal; + + return 1; +} + + +static void Splash() +{ + mu::console() << _T("\n"); + mu::console() << _T(R"( _____ __ _____________ ________ _____ ____________ )") << _T("\n"); + mu::console() << _T(R"( / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ )") << _T("\n"); + mu::console() << _T(R"( | Y Y \ | / |_> > ___ \| | \/\___\\ ___/ | | \/ )") << _T("\n"); + mu::console() << _T(R"( |__|_| /____/| __(____ /___| /___ >\___ >|__| )") << _T("\n"); + mu::console() << _T(R"( \/ |__| \/ \/ \/ )") << _T("\n"); + mu::console() << _T(" Version ") << Parser().GetVersion(pviFULL) << _T("\n"); + mu::console() << _T(" (C) 2004 - 2020 Ingo Berg\n"); + mu::console() << _T("\n"); + mu::console() << _T("-----------------------------------------------------------\n"); + +#if defined(__clang__) + // Note: CLANG also identifies as GCC 4.2.1 + mu::console() << _T(" Compiled with CLANG Version ") << __clang_major__ << _T(".") << __clang_minor__ << _T(".") << __clang_patchlevel__ << _T("\n"); +#elif defined (__GNUC__) + mu::console() << _T(" Compiled with GCC Version ") << __GNUC__ << _T(".") << __GNUC_MINOR__ << _T(".") << __GNUC_PATCHLEVEL__ << _T("\n"); +#elif defined(_MSC_VER) + mu::console() << _T(" Compiled with MSVC Version ") << _MSC_VER << _T("\n"); +#endif + + mu::console() << _T(" IEEE 754 (IEC 559) is ") << ((std::numeric_limits<double>::is_iec559) ? "Available" : " NOT AVAILABLE") << _T("\n"); + mu::console() << _T(" ") << sizeof(void*) * 8 << _T("-bit build\n"); +} + + +static value_type SelfTest() +{ + mu::console() << _T("-----------------------------------------------------------\n"); + mu::console() << _T("Running unit tests:\n\n"); + + // Skip the self test if the value type is set to an integer type. + if (mu::TypeInfo<mu::value_type>::IsInteger()) + { + mu::console() << _T(" Test skipped: integer data type are not compatible with the unit test!\n\n"); + } + else + { + mu::Test::ParserTester pt; + pt.Run(); + } + + return 0; +} + + +static value_type Help() +{ + mu::console() << _T("-----------------------------------------------------------\n"); + mu::console() << _T("Commands:\n\n"); + mu::console() << _T(" list var - list parser variables\n"); + mu::console() << _T(" list exprvar - list expression variables\n"); + mu::console() << _T(" list const - list all numeric parser constants\n"); + mu::console() << _T(" opt on - enable optimizer (default)\n"); + mu::console() << _T(" opt off - disable optimizer\n"); + mu::console() << _T(" locale de - switch to german locale\n"); + mu::console() << _T(" locale en - switch to english locale\n"); + mu::console() << _T(" locale reset - reset locale\n"); + mu::console() << _T(" test bulk - test bulk mode\n"); + mu::console() << _T(" quit - exits the parser\n"); + mu::console() << _T("\nConstants:\n\n"); + mu::console() << _T(" \"_e\" 2.718281828459045235360287\n"); + mu::console() << _T(" \"_pi\" 3.141592653589793238462643\n"); + mu::console() << _T("-----------------------------------------------------------\n"); + return 0; +} + + +static void ListVar(const mu::ParserBase& parser) +{ + // Query the used variables (must be done after calc) + mu::varmap_type variables = parser.GetVar(); + if (!variables.size()) + return; + + cout << "\nParser variables:\n"; + cout << "-----------------\n"; + cout << "Number: " << (int)variables.size() << "\n"; + varmap_type::const_iterator item = variables.begin(); + for (; item != variables.end(); ++item) + mu::console() << _T("Name: ") << item->first << _T(" Address: [0x") << item->second << _T("]\n"); +} + + +static void ListConst(const mu::ParserBase& parser) +{ + mu::console() << _T("\nParser constants:\n"); + mu::console() << _T("-----------------\n"); + + mu::valmap_type cmap = parser.GetConst(); + if (!cmap.size()) + { + mu::console() << _T("Expression does not contain constants\n"); + } + else + { + valmap_type::const_iterator item = cmap.begin(); + for (; item != cmap.end(); ++item) + mu::console() << _T(" ") << item->first << _T(" = ") << item->second << _T("\n"); + } +} + + +static void ListExprVar(const mu::ParserBase& parser) +{ + string_type sExpr = parser.GetExpr(); + if (sExpr.length() == 0) + { + cout << _T("Expression string is empty\n"); + return; + } + + // Query the used variables (must be done after calc) + mu::console() << _T("\nExpression variables:\n"); + mu::console() << _T("---------------------\n"); + mu::console() << _T("Expression: ") << parser.GetExpr() << _T("\n"); + + varmap_type variables = parser.GetUsedVar(); + if (!variables.size()) + { + mu::console() << _T("Expression does not contain variables\n"); + } + else + { + mu::console() << _T("Number: ") << (int)variables.size() << _T("\n"); + mu::varmap_type::const_iterator item = variables.begin(); + for (; item != variables.end(); ++item) + mu::console() << _T("Name: ") << item->first << _T(" Address: [0x") << item->second << _T("]\n"); + } +} + + +/** \brief Check for external keywords. +*/ +static int CheckKeywords(const mu::char_type* a_szLine, mu::Parser& a_Parser) +{ + string_type sLine(a_szLine); + + if (sLine == _T("quit")) + { + return -1; + } + else if (sLine == _T("list var")) + { + ListVar(a_Parser); + return 1; + } + else if (sLine == _T("opt on")) + { + a_Parser.EnableOptimizer(true); + mu::console() << _T("Optimizer enabled\n"); + return 1; + } + else if (sLine == _T("opt off")) + { + a_Parser.EnableOptimizer(false); + mu::console() << _T("Optimizer disabled\n"); + return 1; + } + else if (sLine == _T("list const")) + { + ListConst(a_Parser); + return 1; + } + else if (sLine == _T("list exprvar")) + { + ListExprVar(a_Parser); + return 1; + } + else if (sLine == _T("locale de")) + { + mu::console() << _T("Setting german locale: ArgSep=';' DecSep=',' ThousandsSep='.'\n"); + a_Parser.SetArgSep(';'); + a_Parser.SetDecSep(','); + a_Parser.SetThousandsSep('.'); + return 1; + } + else if (sLine == _T("locale en")) + { + mu::console() << _T("Setting english locale: ArgSep=',' DecSep='.' ThousandsSep=''\n"); + a_Parser.SetArgSep(','); + a_Parser.SetDecSep('.'); + a_Parser.SetThousandsSep(); + return 1; + } + else if (sLine == _T("locale reset")) + { + mu::console() << _T("Resetting locale\n"); + a_Parser.ResetLocale(); + return 1; + } + else if (sLine == _T("test bulk")) + { + mu::console() << _T("Testing bulk mode\n"); + CalcBulk(); + return 1; + } + else if (sLine == _T("dbg")) + { + std::string dbg = R"(6 - 6 ? 4 : "", ? 4 : "", ? 4 : ""), 1)"; + a_Parser.SetExpr(dbg); + mu::console() << dbg; + + int stackSize; + double* v = a_Parser.Eval(stackSize); + mu::console() << *v << std::endl; + return 1; + } + + return 0; +} + + +void CalcBulk() +{ + const int nBulkSize = 200; + value_type* x = new value_type[nBulkSize]; + value_type* y = new value_type[nBulkSize]; + value_type* result = new value_type[nBulkSize]; + + try + { + for (int i = 0; i < nBulkSize; ++i) + { + x[i] = i; + y[i] = (value_type)i / 10; + } + mu::Parser parser; + parser.DefineVar(_T("x"), x); + parser.DefineVar(_T("y"), y); + parser.DefineFun(_T("fun1"), BulkFun1); + parser.SetExpr(_T("fun1(0)+x+y")); + parser.Eval(result, nBulkSize); + + for (int i = 0; i < nBulkSize; ++i) + { + mu::console() << _T("Eqn. ") << i << _T(": x=") << x[i] << _T("; y=") << y[i] << _T("; result=") << result[i] << _T("\n"); + } + } + catch (...) + { + delete[] x; + delete[] y; + delete[] result; + throw; + } + + delete[] x; + delete[] y; + delete[] result; +} + + +static void Calc() +{ + mu::Parser parser; + + // Add some variables + value_type vVarVal[] = { 1, 2 }; // Values of the parser variables + parser.DefineVar(_T("a"), &vVarVal[0]); // Assign Variable names and bind them to the C++ variables + parser.DefineVar(_T("b"), &vVarVal[1]); + parser.DefineVar(_T("ft"), &vVarVal[1]); + parser.DefineStrConst(_T("sVar1"), _T("Sample string 1")); + parser.DefineStrConst(_T("sVar2"), _T("Sample string 2")); + parser.AddValIdent(IsHexValue); + parser.AddValIdent(IsBinValue); + + // Add user defined unary operators + parser.DefinePostfixOprt(_T("M"), Mega); + parser.DefinePostfixOprt(_T("m"), Milli); + parser.DefineInfixOprt(_T("!"), Not); + parser.DefineFun(_T("strfun0"), StrFun0); + parser.DefineFun(_T("strfun2"), StrFun2); + parser.DefineFun(_T("ping"), Ping); + parser.DefineFun(_T("rnd"), Rnd); // Add an unoptimizeable function + parser.DefineFun(_T("throw"), ThrowAnException); + + parser.DefineOprt(_T("add"), Add, 0); + parser.DefineOprt(_T("mul"), Mul, 1); + + // These are service and debug functions + parser.DefineFun(_T("debug"), Debug); + parser.DefineFun(_T("selftest"), SelfTest); + parser.DefineFun(_T("help"), Help); + parser.DefineFun(_T("arg2of2"), Arg2Of2); + parser.DefineFun(_T("arg1of2"), Arg1Of2); + + parser.DefinePostfixOprt(_T("{ft}"), Milli); + parser.DefinePostfixOprt(_T("ft"), Milli); + + // Define the variable factory + parser.SetVarFactory(AddVariable, &parser); + + for (;;) + { + try + { + string_type sLine; + std::getline(mu::console_in(), sLine); + + switch (CheckKeywords(sLine.c_str(), parser)) + { + case 0: break; + case 1: continue; + case -1: return; + } + + if (!sLine.length()) + continue; + + parser.SetExpr(sLine); + mu::console() << std::setprecision(12); + + // There are multiple ways to retrieve the result... + // 1.) If you know there is only a single return value or in case you only need the last + // result of an expression consisting of comma separated subexpressions you can + // simply use: + mu::console() << _T("ans=") << parser.Eval() << _T("\n"); + + // 2.) As an alternative you can also retrieve multiple return values using this API: + int nNum = parser.GetNumResults(); + if (nNum > 1) + { + mu::console() << _T("Multiple return values detected! Complete list:\n"); + + // this is the hard way if you need to retrieve multiple subexpression + // results + value_type* v = parser.Eval(nNum); + mu::console() << std::setprecision(12); + for (int i = 0; i < nNum; ++i) + { + mu::console() << v[i] << _T("\n"); + } + } + } + catch (mu::Parser::exception_type& e) + { + mu::console() << _T("\nError:\n"); + mu::console() << _T("------\n"); + mu::console() << _T("Message: ") << e.GetMsg() << _T("\n"); + mu::console() << _T("Expression: \"") << e.GetExpr() << _T("\"\n"); + mu::console() << _T("Token: \"") << e.GetToken() << _T("\"\n"); + mu::console() << _T("Position: ") << (int)e.GetPos() << _T("\n"); + mu::console() << _T("Errc: ") << std::dec << e.GetCode() << _T("\n"); + } + } // while running +} + + +int main(int, char**) +{ + Splash(); + SelfTest(); + Help(); + + mu::console() << _T("Enter an expression or a command:\n"); + + try + { + Calc(); + } + catch (Parser::exception_type& e) + { + // Only erros raised during the initialization will end up here + // formula related errors are treated in Calc() + console() << _T("Initialization error: ") << e.GetMsg() << endl; + console() << _T("aborting...") << endl; + string_type sBuf; + console_in() >> sBuf; + } + catch (std::exception& /*exc*/) + { + // there is no unicode compliant way to query exc.what() + // i'll leave it for this example. + console() << _T("aborting...\n"); + } + + return 0; +} diff --git a/3rdParty/MuParser/samples/example2/Readme.txt b/3rdParty/MuParser/samples/example2/Readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..312df4810a985971e760538effa91270552b1116 --- /dev/null +++ b/3rdParty/MuParser/samples/example2/Readme.txt @@ -0,0 +1,17 @@ + + __________ + _____ __ __\______ \_____ _______ ______ ____ _______ + / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ + | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ + |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| + \/ \/ \/ \/ + + Copyright (C) 2004-2020 + Ingo Berg + + +This sample demonstrates using muParsers C-interface. The C-Interface +is useful when interfacing muParser from different languages such +as C#. This sample is intended for use with the MS-Windows OS. + +The sample should work with windows and linux. diff --git a/3rdParty/MuParser/samples/example2/example2.c b/3rdParty/MuParser/samples/example2/example2.c new file mode 100644 index 0000000000000000000000000000000000000000..8106c69e5ff7b3c928ae4c5322e240e501e7cf03 --- /dev/null +++ b/3rdParty/MuParser/samples/example2/example2.c @@ -0,0 +1,461 @@ +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <wchar.h> +#include <inttypes.h> + +#include "muParserDLL.h" + +#define PARSER_CONST_PI 3.141592653589793238462643 +#define PARSER_CONST_E 2.718281828459045235360287 +#define PARSER_MAXVARS 10 + +#ifndef _UNICODE + #define _T(x) x + #define myprintf printf + #define mystrlen strlen + #define myfgets fgets + #define mystrcmp strcmp +#else + #define _T(x) L ##x + #define myprintf wprintf + #define mystrlen wcslen + #define myfgets fgetws + #define mystrcmp wcscmp +#endif + +static void CalcBulk(void); + +//--------------------------------------------------------------------------- +// Callbacks for postfix operators +static muFloat_t Mega(muFloat_t a_fVal) +{ + return a_fVal * 1.0e6; +} + +static muFloat_t Milli(muFloat_t a_fVal) +{ + return a_fVal / 1.0e3; +} + +static muFloat_t ZeroArg(void) +{ + myprintf(_T("i'm a function without arguments.\n")); + return 123; +} + +static muFloat_t BulkTest(int nBulkIdx, int nThreadIdx, muFloat_t v1) +{ + myprintf(_T("%d,%2.2f\n"), nBulkIdx, v1); + return v1 / ((muFloat_t)nBulkIdx + 1); +} + +//--------------------------------------------------------------------------- +// Callbacks for infix operators +static muFloat_t Not(muFloat_t v) { return v == 0; } + +//--------------------------------------------------------------------------- +// Function callbacks +static muFloat_t Rnd(muFloat_t v) { return v * rand() / (muFloat_t)(RAND_MAX + 1.0); } + +static muFloat_t Sum(const muFloat_t* a_afArg, int a_iArgc) +{ + muFloat_t fRes = 0; + int i = 0; + + for (i = 0; i < a_iArgc; ++i) + fRes += a_afArg[i]; + + return fRes; +} + +//--------------------------------------------------------------------------- +// Binarty operator callbacks +static muFloat_t Add(muFloat_t v1, muFloat_t v2) +{ + return v1 + v2; +} + +static muFloat_t Mul(muFloat_t v1, muFloat_t v2) +{ + return v1 * v2; +} + +//--------------------------------------------------------------------------- +// Factory function for creating new parser variables +// This could as well be a function performing database queries. +static muFloat_t* AddVariable(const muChar_t* a_szName, void* pUserData) +{ + static muFloat_t afValBuf[PARSER_MAXVARS]; // I don't want dynamic allocation here + static int iVal = 0; // so i used this buffer + + myprintf(_T("Generating new variable \"%s\" (slots left: %d; context pointer: %") _T(PRIxPTR) _T(")\n"), a_szName, PARSER_MAXVARS - iVal, (intptr_t)pUserData); + + afValBuf[iVal] = 0; + if (iVal >= PARSER_MAXVARS - 1) + { + myprintf(_T("Variable buffer overflow.")); + return NULL; + } + + return &afValBuf[iVal++]; +} + +//--------------------------------------------------------------------------- +static void Intro(muParserHandle_t hParser) +{ + myprintf(_T(" __________ \n")); + myprintf(_T(" _____ __ __\\______ \\_____ _______ ______ ____ _______\n")); + myprintf(_T(" / \\ | | \\| ___/\\__ \\ \\_ __ \\/ ___/_/ __ \\\\_ __ \\ \n")); + myprintf(_T(" | Y Y \\| | /| | / __ \\_| | \\/\\___ \\ \\ ___/ | | \\/ \n")); + myprintf(_T(" |__|_| /|____/ |____| (____ /|__| /____ > \\___ >|__| \n")); + myprintf(_T(" \\/ \\/ \\/ \\/ \n")); + myprintf(_T(" Version %s (DLL)\n"), mupGetVersion(hParser)); +#ifdef _UNICODE + myprintf(_T(" Sample build with UNICODE support\n")); +#else + myprintf(_T(" Sample build with ASCII support\n")); +#endif + myprintf(_T(" (C) 2004 - 2020 Ingo Berg\n")); + myprintf(_T("---------------------------------------\n")); + myprintf(_T("Commands:\n")); + myprintf(_T(" list var - list parser variables\n")); + myprintf(_T(" list exprvar - list expression variables\n")); + myprintf(_T(" list const - list all numeric parser constants\n")); + myprintf(_T(" locale de - switch to german locale\n")); + myprintf(_T(" locale en - switch to english locale\n")); + myprintf(_T(" locale reset - reset locale\n")); + myprintf(_T(" test bulk - test bulk mode\n")); + myprintf(_T(" quit - exits the parser\n\n")); + myprintf(_T("---------------------------------------\n")); + myprintf(_T("Constants:\n")); + myprintf(_T(" \"_e\" 2.718281828459045235360287\n")); + myprintf(_T(" \"_pi\" 3.141592653589793238462643\n")); + myprintf(_T("---------------------------------------\n")); + myprintf(_T("Please enter an expression:\n")); +} + +//--------------------------------------------------------------------------- +// Callback function for parser errors +static void OnError(muParserHandle_t hParser) +{ + myprintf(_T("\nError:\n")); + myprintf(_T("------\n")); + myprintf(_T("Message: \"%s\"\n"), mupGetErrorMsg(hParser)); + myprintf(_T("Token: \"%s\"\n"), mupGetErrorToken(hParser)); + myprintf(_T("Position: %d\n"), mupGetErrorPos(hParser)); + myprintf(_T("Errc: %d\n"), mupGetErrorCode(hParser)); +} + +//--------------------------------------------------------------------------- +static void ListVar(muParserHandle_t a_hParser) +{ + int iNumVar = mupGetVarNum(a_hParser); + int i = 0; + + if (iNumVar == 0) + { + myprintf(_T("No variables defined\n")); + return; + } + + myprintf(_T("\nExpression variables:\n")); + myprintf(_T("---------------------\n")); + myprintf(_T("Number: %d\n"), iNumVar); + + for (i = 0; i < iNumVar; ++i) + { + const muChar_t* szName = 0; + muFloat_t* pVar = 0; + + mupGetVar(a_hParser, i, &szName, &pVar); + myprintf(_T("Name: %s Address: [%") _T(PRIxPTR) _T("]\n"), szName, (uintptr_t)pVar); + } +} + +//--------------------------------------------------------------------------- +static void ListExprVar(muParserHandle_t a_hParser) +{ + muInt_t iNumVar = mupGetExprVarNum(a_hParser), + i = 0; + + if (iNumVar == 0) + { + myprintf(_T("Expression dos not contain variables\n")); + return; + } + + myprintf(_T("\nExpression variables:\n")); + myprintf(_T("---------------------\n")); + myprintf(_T("Expression: %s\n"), mupGetExpr(a_hParser)); + myprintf(_T("Number: %d\n"), iNumVar); + + for (i = 0; i < iNumVar; ++i) + { + const muChar_t* szName = 0; + muFloat_t* pVar = 0; + + mupGetExprVar(a_hParser, i, &szName, &pVar); + myprintf(_T("Name: %s Address: [%") _T(PRIxPTR) _T("]\n"), szName, (intptr_t)pVar); + } +} + +//--------------------------------------------------------------------------- +static void ListConst(muParserHandle_t a_hParser) +{ + muInt_t iNumVar = mupGetConstNum(a_hParser), + i = 0; + + if (iNumVar == 0) + { + myprintf(_T("No constants defined\n")); + return; + } + + myprintf(_T("\nParser constants:\n")); + myprintf(_T("---------------------\n")); + myprintf(_T("Number: %d"), iNumVar); + + for (i = 0; i < iNumVar; ++i) + { + const muChar_t* szName = 0; + muFloat_t fVal = 0; + + mupGetConst(a_hParser, i, &szName, &fVal); + myprintf(_T(" %s = %f\n"), szName, fVal); + } +} + +//--------------------------------------------------------------------------- +/** \brief Check for external keywords. +*/ +static int CheckKeywords(const muChar_t* a_szLine, muParserHandle_t a_hParser) +{ + if (!mystrcmp(a_szLine, _T("quit"))) + { + return -1; + } + else if (!mystrcmp(a_szLine, _T("list var"))) + { + ListVar(a_hParser); + return 1; + } + else if (!mystrcmp(a_szLine, _T("list exprvar"))) + { + ListExprVar(a_hParser); + return 1; + } + else if (!mystrcmp(a_szLine, _T("list const"))) + { + ListConst(a_hParser); + return 1; + } + else if (!mystrcmp(a_szLine, _T("locale de"))) + { + myprintf(_T("Setting german locale: ArgSep=';' DecSep=',' ThousandsSep='.'\n")); + mupSetArgSep(a_hParser, ';'); + mupSetDecSep(a_hParser, ','); + mupSetThousandsSep(a_hParser, '.'); + return 1; + } + else if (!mystrcmp(a_szLine, _T("locale en"))) + { + myprintf(_T("Setting english locale: ArgSep=',' DecSep='.' ThousandsSep=''\n")); + mupSetArgSep(a_hParser, ','); + mupSetDecSep(a_hParser, '.'); + mupSetThousandsSep(a_hParser, 0); + return 1; + } + else if (!mystrcmp(a_szLine, _T("locale reset"))) + { + myprintf(_T("Resetting locale\n")); + mupResetLocale(a_hParser); + return 1; + } + else if (!mystrcmp(a_szLine, _T("test bulk"))) + { + myprintf(_T("Testing bulk mode\n")); + CalcBulk(); + return 1; + } + + return 0; +} + +//--------------------------------------------------------------------------- +static void CalcBulk(void) +{ + int nBulkSize = 200, i; + muFloat_t* x = (muFloat_t*)malloc(nBulkSize * sizeof(muFloat_t)); + muFloat_t* y = (muFloat_t*)malloc(nBulkSize * sizeof(muFloat_t)); + muFloat_t* r = (muFloat_t*)malloc(nBulkSize * sizeof(muFloat_t)); + + muParserHandle_t hParser = mupCreate(muBASETYPE_FLOAT); // initialize the parser + + for (i = 0; i < nBulkSize; ++i) + { + x[i] = i; + y[i] = i; + r[i] = 0; + } + + mupDefineVar(hParser, _T("x"), x); + mupDefineVar(hParser, _T("y"), y); + mupDefineBulkFun1(hParser, _T("bulktest"), BulkTest); + mupSetExpr(hParser, _T("bulktest(x+y)")); + mupEvalBulk(hParser, r, nBulkSize); + if (mupError(hParser)) + { + myprintf(_T("\nError:\n")); + myprintf(_T("------\n")); + myprintf(_T("Message: %s\n"), mupGetErrorMsg(hParser)); + myprintf(_T("Token: %s\n"), mupGetErrorToken(hParser)); + myprintf(_T("Position: %d\n"), mupGetErrorPos(hParser)); + myprintf(_T("Errc: %d\n"), mupGetErrorCode(hParser)); + return; + } + + for (i = 0; i < nBulkSize; ++i) + { + myprintf(_T("%d: bulkfun(%2.2f + %2.2f) = %2.2f\n"), i, x[i], y[i], r[i]); + x[i] = i; + y[i] = (muFloat_t)i / 10; + } + + free(x); + free(y); + free(r); +} + +//--------------------------------------------------------------------------- +static void Calc(void) +{ + muChar_t szLine[100]; + muFloat_t fVal = 0, + afVarVal[] = { 1, 2 }; // Values of the parser variables + muParserHandle_t hParser; + + hParser = mupCreate(muBASETYPE_FLOAT); // initialize the parser + Intro(hParser); + + // Set an error handler [optional] + // the only function that does not take a parser instance handle + mupSetErrorHandler(hParser, OnError); + + //#define GERMAN_LOCALS +#ifdef GERMAN_LOCALS + mupSetArgSep(hParser, ';'); + mupSetDecSep(hParser, ','); + mupSetThousandsSep(hParser, '.'); +#else + mupSetArgSep(hParser, ','); + mupSetDecSep(hParser, '.'); +#endif + + // Set a variable factory + mupSetVarFactory(hParser, AddVariable, NULL); + + // Define parser variables and bind them to C++ variables [optional] + mupDefineConst(hParser, _T("const1"), 1); + mupDefineConst(hParser, _T("const2"), 2); + mupDefineStrConst(hParser, _T("strBuf"), _T("Hallo welt")); + + // Define parser variables and bind them to C++ variables [optional] + mupDefineVar(hParser, _T("a"), &afVarVal[0]); + mupDefineVar(hParser, _T("b"), &afVarVal[1]); + + // Define postfix operators [optional] + mupDefinePostfixOprt(hParser, _T("M"), Mega, 0); + mupDefinePostfixOprt(hParser, _T("m"), Milli, 0); + + // Define infix operator [optional] + mupDefineInfixOprt(hParser, _T("!"), Not, 0); + + // Define functions [optional] + // mupDefineStrFun(hParser, "query", SampleQuery, 0); // Add an unoptimizeable function + mupDefineFun0(hParser, _T("zero"), ZeroArg, 0); + mupDefineFun1(hParser, _T("rnd"), Rnd, 0); // Add an unoptimizeable function + mupDefineFun1(hParser, _T("rnd2"), Rnd, 1); + mupDefineMultFun(hParser, _T("_sum"), Sum, 0); // "sum" is already a default function + + // Define binary operators [optional] + mupDefineOprt(hParser, _T("add"), Add, 0, muOPRT_ASCT_LEFT, 0); + mupDefineOprt(hParser, _T("mul"), Mul, 1, muOPRT_ASCT_LEFT, 0); + + while (myfgets(szLine, 99, stdin)) + { + szLine[mystrlen(szLine) - 1] = 0; // overwrite the newline + + switch (CheckKeywords(szLine, hParser)) + { + case 0: break; // no keyword found; parse the line + case 1: continue; // A Keyword was found do not parse the line + case -1: return; // abort the application + } + + mupSetExpr(hParser, szLine); + + fVal = mupEval(hParser); + + + // Without an Error handler function + // you must use this for error treatment: + //if (mupError(hParser)) + //{ + // printf("\nError:\n"); + // printf("------\n"); + // printf("Message: %s\n", mupGetErrorMsg(hParser) ); + // printf("Token: %s\n", mupGetErrorToken(hParser) ); + // printf("Position: %s\n", mupGetErrorPos(hParser) ); + // printf("Errc: %d\n", mupGetErrorCode(hParser) ); + // continue; + //} + + if (!mupError(hParser)) + myprintf(_T("%f\n"), fVal); + + } // while + + // finally free the parser resources + mupRelease(hParser); +} + +//--------------------------------------------------------------------------- +int main(int argc, char* argv[]) +{ + // The next line is just for shutting up the compiler warning + // about unused variables without getting another warning about not + // being able to use type lists in function declarations. + myprintf(_T("Executing \"%s\" (argc=%d)\n"), argv[0], argc); + Calc(); + printf(_T("done...")); +} diff --git a/3rdParty/MuParser/src/muParser.cpp b/3rdParty/MuParser/src/muParser.cpp index 39ea8610c779ea6061ba1fde8f3c4497f56d63e6..d13401533b3c638c04c0c229cd59ab76c419cc17 100644 --- a/3rdParty/MuParser/src/muParser.cpp +++ b/3rdParty/MuParser/src/muParser.cpp @@ -1,397 +1,233 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - - Copyright (C) 2013 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. -*/ -#include "muParser.h" -#include "muParserTemplateMagic.h" - -//--- Standard includes ------------------------------------------------------------------------ -#include <cmath> -#include <algorithm> -#include <numeric> - -/** \brief Pi (what else?). */ -#define PARSER_CONST_PI 3.141592653589793238462643 - -/** \brief The Eulerian number. */ -#define PARSER_CONST_E 2.718281828459045235360287 - -using namespace std; - -/** \file - \brief Implementation of the standard floating point parser. -*/ - - - -/** \brief Namespace for mathematical applications. */ -namespace mu -{ - - - //--------------------------------------------------------------------------- - // Trigonometric function - value_type Parser::Sin(value_type v) { return MathImpl<value_type>::Sin(v); } - value_type Parser::Cos(value_type v) { return MathImpl<value_type>::Cos(v); } - value_type Parser::Tan(value_type v) { return MathImpl<value_type>::Tan(v); } - value_type Parser::ASin(value_type v) { return MathImpl<value_type>::ASin(v); } - value_type Parser::ACos(value_type v) { return MathImpl<value_type>::ACos(v); } - value_type Parser::ATan(value_type v) { return MathImpl<value_type>::ATan(v); } - value_type Parser::ATan2(value_type v1, value_type v2) { return MathImpl<value_type>::ATan2(v1, v2); } - value_type Parser::Sinh(value_type v) { return MathImpl<value_type>::Sinh(v); } - value_type Parser::Cosh(value_type v) { return MathImpl<value_type>::Cosh(v); } - value_type Parser::Tanh(value_type v) { return MathImpl<value_type>::Tanh(v); } - value_type Parser::ASinh(value_type v) { return MathImpl<value_type>::ASinh(v); } - value_type Parser::ACosh(value_type v) { return MathImpl<value_type>::ACosh(v); } - value_type Parser::ATanh(value_type v) { return MathImpl<value_type>::ATanh(v); } - - //--------------------------------------------------------------------------- - // Logarithm functions - - // Logarithm base 2 - value_type Parser::Log2(value_type v) - { - #ifdef MUP_MATH_EXCEPTIONS - if (v<=0) - throw ParserError(ecDOMAIN_ERROR, _T("Log2")); - #endif - - return MathImpl<value_type>::Log2(v); - } - - // Logarithm base 10 - value_type Parser::Log10(value_type v) - { - #ifdef MUP_MATH_EXCEPTIONS - if (v<=0) - throw ParserError(ecDOMAIN_ERROR, _T("Log10")); - #endif - - return MathImpl<value_type>::Log10(v); - } - -// Logarithm base e (natural logarithm) - value_type Parser::Ln(value_type v) - { - #ifdef MUP_MATH_EXCEPTIONS - if (v<=0) - throw ParserError(ecDOMAIN_ERROR, _T("Ln")); - #endif - - return MathImpl<value_type>::Log(v); - } - - //--------------------------------------------------------------------------- - // misc - value_type Parser::Exp(value_type v) { return MathImpl<value_type>::Exp(v); } - value_type Parser::Abs(value_type v) { return MathImpl<value_type>::Abs(v); } - value_type Parser::Sqrt(value_type v) - { - #ifdef MUP_MATH_EXCEPTIONS - if (v<0) - throw ParserError(ecDOMAIN_ERROR, _T("sqrt")); - #endif - - return MathImpl<value_type>::Sqrt(v); - } - value_type Parser::Rint(value_type v) { return MathImpl<value_type>::Rint(v); } - value_type Parser::Sign(value_type v) { return MathImpl<value_type>::Sign(v); } - - //--------------------------------------------------------------------------- - /** \brief Callback for the unary minus operator. - \param v The value to negate - \return -v - */ - value_type Parser::UnaryMinus(value_type v) - { - 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 - \param [in] a_iArgc The size of a_afArg - */ - value_type Parser::Sum(const value_type *a_afArg, int a_iArgc) - { - if (!a_iArgc) - throw exception_type(_T("too few arguments for function sum.")); - - value_type fRes=0; - for (int i=0; i<a_iArgc; ++i) fRes += a_afArg[i]; - return fRes; - } - - //--------------------------------------------------------------------------- - /** \brief Callback for averaging multiple values. - \param [in] a_afArg Vector with the function arguments - \param [in] a_iArgc The size of a_afArg - */ - value_type Parser::Avg(const value_type *a_afArg, int a_iArgc) - { - if (!a_iArgc) - throw exception_type(_T("too few arguments for function sum.")); - - value_type fRes=0; - for (int i=0; i<a_iArgc; ++i) fRes += a_afArg[i]; - return fRes/(value_type)a_iArgc; - } - - - //--------------------------------------------------------------------------- - /** \brief Callback for determining the minimum value out of a vector. - \param [in] a_afArg Vector with the function arguments - \param [in] a_iArgc The size of a_afArg - */ - value_type Parser::Min(const value_type *a_afArg, int a_iArgc) - { - if (!a_iArgc) - throw exception_type(_T("too few arguments for function min.")); - - value_type fRes=a_afArg[0]; - for (int i=0; i<a_iArgc; ++i) - fRes = std::min(fRes, a_afArg[i]); - - return fRes; - } - - - //--------------------------------------------------------------------------- - /** \brief Callback for determining the maximum value out of a vector. - \param [in] a_afArg Vector with the function arguments - \param [in] a_iArgc The size of a_afArg - */ - value_type Parser::Max(const value_type *a_afArg, int a_iArgc) - { - if (!a_iArgc) - throw exception_type(_T("too few arguments for function min.")); - - value_type fRes=a_afArg[0]; - for (int i=0; i<a_iArgc; ++i) fRes = std::max(fRes, a_afArg[i]); - - return fRes; - } - - - //--------------------------------------------------------------------------- - /** \brief Default value recognition callback. - \param [in] a_szExpr Pointer to the expression - \param [in, out] a_iPos Pointer to an index storing the current position within the expression - \param [out] a_fVal Pointer where the value should be stored in case one is found. - \return 1 if a value was found 0 otherwise. - */ - int Parser::IsVal(const char_type* a_szExpr, int *a_iPos, value_type *a_fVal) - { - value_type fVal(0); - - stringstream_type stream(a_szExpr); - stream.seekg(0); // todo: check if this really is necessary - stream.imbue(Parser::s_locale); - stream >> fVal; - stringstream_type::pos_type iEnd = stream.tellg(); // Position after reading - - if (iEnd==(stringstream_type::pos_type)-1) - return 0; - - *a_iPos += (int)iEnd; - *a_fVal = fVal; - return 1; - } - - - //--------------------------------------------------------------------------- - /** \brief Constructor. - - Call ParserBase class constructor and trigger Function, Operator and Constant initialization. - */ - Parser::Parser() - :ParserBase() - { - AddValIdent(IsVal); - - InitCharSets(); - InitFun(); - InitConst(); - InitOprt(); - } - - //--------------------------------------------------------------------------- - /** \brief Define the character sets. - \sa DefineNameChars, DefineOprtChars, DefineInfixOprtChars - - This function is used for initializing the default character sets that define - the characters to be useable in function and variable names and operators. - */ - void Parser::InitCharSets() - { - DefineNameChars( _T("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") ); - DefineOprtChars( _T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*^/?<>=#!$%&|~'_{}") ); - DefineInfixOprtChars( _T("/+-*^?<>=#!$%&|~'_") ); - } - - //--------------------------------------------------------------------------- - /** \brief Initialize the default functions. */ - void Parser::InitFun() - { - if (mu::TypeInfo<mu::value_type>::IsInteger()) - { - // When setting MUP_BASETYPE to an integer type - // Place functions for dealing with integer values here - // ... - // ... - // ... - } - else - { - // trigonometric functions - DefineFun(_T("sin"), Sin); - DefineFun(_T("cos"), Cos); - DefineFun(_T("tan"), Tan); - // arcus functions - DefineFun(_T("asin"), ASin); - DefineFun(_T("acos"), ACos); - DefineFun(_T("atan"), ATan); - DefineFun(_T("atan2"), ATan2); - // hyperbolic functions - DefineFun(_T("sinh"), Sinh); - DefineFun(_T("cosh"), Cosh); - DefineFun(_T("tanh"), Tanh); - // arcus hyperbolic functions - DefineFun(_T("asinh"), ASinh); - DefineFun(_T("acosh"), ACosh); - DefineFun(_T("atanh"), ATanh); - // Logarithm functions - DefineFun(_T("log2"), Log2); - DefineFun(_T("log10"), Log10); - DefineFun(_T("log"), Ln); - DefineFun(_T("ln"), Ln); - // misc - DefineFun(_T("exp"), Exp); - DefineFun(_T("sqrt"), Sqrt); - DefineFun(_T("sign"), Sign); - DefineFun(_T("rint"), Rint); - DefineFun(_T("abs"), Abs); - // Functions with variable number of arguments - DefineFun(_T("sum"), Sum); - DefineFun(_T("avg"), Avg); - DefineFun(_T("min"), Min); - DefineFun(_T("max"), Max); - } - } - - //--------------------------------------------------------------------------- - /** \brief Initialize constants. - - By default the parser recognizes two constants. Pi ("pi") and the Eulerian - number ("_e"). - */ - void Parser::InitConst() - { - DefineConst(_T("_pi"), (value_type)PARSER_CONST_PI); - DefineConst(_T("_e"), (value_type)PARSER_CONST_E); - } - - //--------------------------------------------------------------------------- - /** \brief Initialize operators. - - By default only the unary minus operator is added. - */ - void Parser::InitOprt() - { - DefineInfixOprt(_T("-"), UnaryMinus); - DefineInfixOprt(_T("+"), UnaryPlus); - } - - //--------------------------------------------------------------------------- - void Parser::OnDetectVar(string_type * /*pExpr*/, int & /*nStart*/, int & /*nEnd*/) - { - // this is just sample code to illustrate modifying variable names on the fly. - // I'm not sure anyone really needs such a feature... - /* - - - string sVar(pExpr->begin()+nStart, pExpr->begin()+nEnd); - string sRepl = std::string("_") + sVar + "_"; - - int nOrigVarEnd = nEnd; - cout << "variable detected!\n"; - cout << " Expr: " << *pExpr << "\n"; - cout << " Start: " << nStart << "\n"; - cout << " End: " << nEnd << "\n"; - cout << " Var: \"" << sVar << "\"\n"; - cout << " Repl: \"" << sRepl << "\"\n"; - nEnd = nStart + sRepl.length(); - cout << " End: " << nEnd << "\n"; - pExpr->replace(pExpr->begin()+nStart, pExpr->begin()+nOrigVarEnd, sRepl); - cout << " New expr: " << *pExpr << "\n"; - */ - } - - //--------------------------------------------------------------------------- - /** \brief Numerically differentiate with regard to a variable. - \param [in] a_Var Pointer to the differentiation variable. - \param [in] a_fPos Position at which the differentiation should take place. - \param [in] a_fEpsilon Epsilon used for the numerical differentiation. - - Numerical differentiation uses a 5 point operator yielding a 4th order - formula. The default value for epsilon is 0.00074 which is - numeric_limits<double>::epsilon() ^ (1/5) as suggested in the muparser - forum: - - http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843 - */ - value_type Parser::Diff(value_type *a_Var, - value_type a_fPos, - value_type a_fEpsilon) const - { - value_type fRes(0), - fBuf(*a_Var), - f[4] = {0,0,0,0}, - fEpsilon(a_fEpsilon); - - // Backwards compatible calculation of epsilon inc case the user doesn't provide - // his own epsilon - if (fEpsilon==0) - fEpsilon = (a_fPos==0) ? (value_type)1e-10 : (value_type)1e-7 * a_fPos; - - *a_Var = a_fPos+2 * fEpsilon; f[0] = Eval(); - *a_Var = a_fPos+1 * fEpsilon; f[1] = Eval(); - *a_Var = a_fPos-1 * fEpsilon; f[2] = Eval(); - *a_Var = a_fPos-2 * fEpsilon; f[3] = Eval(); - *a_Var = fBuf; // restore variable - - fRes = (-f[0] + 8*f[1] - 8*f[2] + f[3]) / (12*fEpsilon); - return fRes; - } -} // namespace mu +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParser.h" +#include "muParserTemplateMagic.h" + +//--- Standard includes ------------------------------------------------------------------------ +#include <cmath> +#include <algorithm> +#include <numeric> + +using namespace std; + +/** \file + \brief Implementation of the standard floating point parser. +*/ + + + +/** \brief Namespace for mathematical applications. */ +namespace mu +{ + //--------------------------------------------------------------------------- + /** \brief Default value recognition callback. + \param [in] a_szExpr Pointer to the expression + \param [in, out] a_iPos Pointer to an index storing the current position within the expression + \param [out] a_fVal Pointer where the value should be stored in case one is found. + \return 1 if a value was found 0 otherwise. + */ + int Parser::IsVal(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal) + { + value_type fVal(0); + + stringstream_type stream(a_szExpr); + stream.seekg(0); // todo: check if this really is necessary + stream.imbue(Parser::s_locale); + stream >> fVal; + stringstream_type::pos_type iEnd = stream.tellg(); // Position after reading + + if (iEnd == (stringstream_type::pos_type) - 1) + return 0; + + *a_iPos += (int)iEnd; + *a_fVal = fVal; + return 1; + } + + + //--------------------------------------------------------------------------- + /** \brief Constructor. + + Call ParserBase class constructor and trigger Function, Operator and Constant initialization. + */ + Parser::Parser() + :ParserBase() + { + AddValIdent(IsVal); + + InitCharSets(); + InitFun(); + InitConst(); + InitOprt(); + } + + //--------------------------------------------------------------------------- + /** \brief Define the character sets. + \sa DefineNameChars, DefineOprtChars, DefineInfixOprtChars + + This function is used for initializing the default character sets that define + the characters to be useable in function and variable names and operators. + */ + void Parser::InitCharSets() + { + DefineNameChars(_T("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")); + DefineOprtChars(_T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*^/?<>=#!$%&|~'_{}")); + DefineInfixOprtChars(_T("/+-*^?<>=#!$%&|~'_")); + } + + //--------------------------------------------------------------------------- + /** \brief Initialize the default functions. */ + void Parser::InitFun() + { + if (mu::TypeInfo<mu::value_type>::IsInteger()) + { + // When setting MUP_BASETYPE to an integer type + // Place functions for dealing with integer values here + // ... + // ... + // ... + } + else + { + // trigonometric functions + DefineFun(_T("sin"), MathImpl<value_type>::Sin); + DefineFun(_T("cos"), MathImpl<value_type>::Cos); + DefineFun(_T("tan"), MathImpl<value_type>::Tan); + // arcus functions + DefineFun(_T("asin"), MathImpl<value_type>::ASin); + DefineFun(_T("acos"), MathImpl<value_type>::ACos); + DefineFun(_T("atan"), MathImpl<value_type>::ATan); + DefineFun(_T("atan2"), MathImpl<value_type>::ATan2); + // hyperbolic functions + DefineFun(_T("sinh"), MathImpl<value_type>::Sinh); + DefineFun(_T("cosh"), MathImpl<value_type>::Cosh); + DefineFun(_T("tanh"), MathImpl<value_type>::Tanh); + // arcus hyperbolic functions + DefineFun(_T("asinh"), MathImpl<value_type>::ASinh); + DefineFun(_T("acosh"), MathImpl<value_type>::ACosh); + DefineFun(_T("atanh"), MathImpl<value_type>::ATanh); + // Logarithm functions + DefineFun(_T("log2"), MathImpl<value_type>::Log2); + DefineFun(_T("log10"), MathImpl<value_type>::Log10); + DefineFun(_T("log"), MathImpl<value_type>::Log); + DefineFun(_T("ln"), MathImpl<value_type>::Log); + // misc + DefineFun(_T("exp"), MathImpl<value_type>::Exp); + DefineFun(_T("sqrt"), MathImpl<value_type>::Sqrt); + DefineFun(_T("sign"), MathImpl<value_type>::Sign); + DefineFun(_T("rint"), MathImpl<value_type>::Rint); + DefineFun(_T("abs"), MathImpl<value_type>::Abs); + // Functions with variable number of arguments + DefineFun(_T("sum"), MathImpl<value_type>::Sum); + DefineFun(_T("avg"), MathImpl<value_type>::Avg); + DefineFun(_T("min"), MathImpl<value_type>::Min); + DefineFun(_T("max"), MathImpl<value_type>::Max); + } + } + + //--------------------------------------------------------------------------- + /** \brief Initialize constants. + + By default the parser recognizes two constants. Pi ("pi") and the Eulerian + number ("_e"). + */ + void Parser::InitConst() + { + DefineConst(_T("_pi"), MathImpl<value_type>::CONST_PI); + DefineConst(_T("_e"), MathImpl<value_type>::CONST_E); + } + + //--------------------------------------------------------------------------- + /** \brief Initialize operators. + + By default only the unary minus operator is added. + */ + void Parser::InitOprt() + { + DefineInfixOprt(_T("-"), MathImpl<value_type>::UnaryMinus); + DefineInfixOprt(_T("+"), MathImpl<value_type>::UnaryPlus); + } + + //--------------------------------------------------------------------------- + void Parser::OnDetectVar(string_type* /*pExpr*/, int& /*nStart*/, int& /*nEnd*/) + { + // this is just sample code to illustrate modifying variable names on the fly. + // I'm not sure anyone really needs such a feature... + /* + + + string sVar(pExpr->begin()+nStart, pExpr->begin()+nEnd); + string sRepl = std::string("_") + sVar + "_"; + + int nOrigVarEnd = nEnd; + cout << "variable detected!\n"; + cout << " Expr: " << *pExpr << "\n"; + cout << " Start: " << nStart << "\n"; + cout << " End: " << nEnd << "\n"; + cout << " Var: \"" << sVar << "\"\n"; + cout << " Repl: \"" << sRepl << "\"\n"; + nEnd = nStart + sRepl.length(); + cout << " End: " << nEnd << "\n"; + pExpr->replace(pExpr->begin()+nStart, pExpr->begin()+nOrigVarEnd, sRepl); + cout << " New expr: " << *pExpr << "\n"; + */ + } + + //--------------------------------------------------------------------------- + /** \brief Numerically differentiate with regard to a variable. + \param [in] a_Var Pointer to the differentiation variable. + \param [in] a_fPos Position at which the differentiation should take place. + \param [in] a_fEpsilon Epsilon used for the numerical differentiation. + + Numerical differentiation uses a 5 point operator yielding a 4th order + formula. The default value for epsilon is 0.00074 which is + numeric_limits<double>::epsilon() ^ (1/5). + */ + value_type Parser::Diff(value_type* a_Var, value_type a_fPos, value_type a_fEpsilon) const + { + value_type fRes(0); + value_type fBuf(*a_Var); + value_type f[4] = { 0,0,0,0 }; + value_type fEpsilon(a_fEpsilon); + + // Backwards compatible calculation of epsilon inc case the user doesn't provide + // his own epsilon + if (fEpsilon == 0) + fEpsilon = (a_fPos == 0) ? (value_type)1e-10 : (value_type)1e-7 * a_fPos; + + *a_Var = a_fPos + 2 * fEpsilon; f[0] = Eval(); + *a_Var = a_fPos + 1 * fEpsilon; f[1] = Eval(); + *a_Var = a_fPos - 1 * fEpsilon; f[2] = Eval(); + *a_Var = a_fPos - 2 * fEpsilon; f[3] = Eval(); + *a_Var = fBuf; // restore variable + + fRes = (-f[0] + 8 * f[1] - 8 * f[2] + f[3]) / (12 * fEpsilon); + return fRes; + } +} // namespace mu diff --git a/3rdParty/MuParser/src/muParserBase.cpp b/3rdParty/MuParser/src/muParserBase.cpp index ea3699a12fc02cf7973adc145c1ce5667f4b5715..eac46ca764d6992620f3e2ab986030031b7e70bd 100644 --- a/3rdParty/MuParser/src/muParserBase.cpp +++ b/3rdParty/MuParser/src/muParserBase.cpp @@ -1,1778 +1,1896 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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. -*/ - -#include "muParserBase.h" -#include "muParserTemplateMagic.h" - -//--- Standard includes ------------------------------------------------------------------------ -#include <cassert> -#include <algorithm> -#include <cmath> -#include <memory> -#include <vector> -#include <deque> -#include <sstream> -#include <locale> - -#ifdef MUP_USE_OPENMP - #include <omp.h> -#endif - -using namespace std; - -/** \file - \brief This file contains the basic implementation of the muparser engine. -*/ - -namespace mu -{ - std::locale ParserBase::s_locale = std::locale(std::locale::classic(), new change_dec_sep<char_type>('.')); - - bool ParserBase::g_DbgDumpCmdCode = false; - bool ParserBase::g_DbgDumpStack = false; - - //------------------------------------------------------------------------------ - /** \brief Identifiers for built in binary operators. - - When defining custom binary operators with #AddOprt(...) make sure not to choose - names conflicting with these definitions. - */ - const char_type* ParserBase::c_DefaultOprt[] = - { - _T("<="), _T(">="), _T("!="), - _T("=="), _T("<"), _T(">"), - _T("+"), _T("-"), _T("*"), - _T("/"), _T("^"), _T("&&"), - _T("||"), _T("="), _T("("), - _T(")"), _T("?"), _T(":"), 0 - }; - - //------------------------------------------------------------------------------ - /** \brief Constructor. - \param a_szFormula the formula to interpret. - \throw ParserException if a_szFormula is null. - */ - ParserBase::ParserBase() - :m_pParseFormula(&ParserBase::ParseString) - ,m_vRPN() - ,m_vStringBuf() - ,m_pTokenReader() - ,m_FunDef() - ,m_PostOprtDef() - ,m_InfixOprtDef() - ,m_OprtDef() - ,m_ConstDef() - ,m_StrVarDef() - ,m_VarDef() - ,m_bBuiltInOp(true) - ,m_sNameChars() - ,m_sOprtChars() - ,m_sInfixOprtChars() - ,m_nIfElseCounter(0) - ,m_vStackBuffer() - ,m_nFinalResultIdx(0) - { - InitTokenReader(); - } - - //--------------------------------------------------------------------------- - /** \brief Copy constructor. - - The parser can be safely copy constructed but the bytecode is reset during - copy construction. - */ - ParserBase::ParserBase(const ParserBase &a_Parser) - :m_pParseFormula(&ParserBase::ParseString) - ,m_vRPN() - ,m_vStringBuf() - ,m_pTokenReader() - ,m_FunDef() - ,m_PostOprtDef() - ,m_InfixOprtDef() - ,m_OprtDef() - ,m_ConstDef() - ,m_StrVarDef() - ,m_VarDef() - ,m_bBuiltInOp(true) - ,m_sNameChars() - ,m_sOprtChars() - ,m_sInfixOprtChars() - ,m_nIfElseCounter(0) - { - m_pTokenReader.reset(new token_reader_type(this)); - Assign(a_Parser); - } - - //--------------------------------------------------------------------------- - ParserBase::~ParserBase() - {} - - //--------------------------------------------------------------------------- - /** \brief Assignment operator. - - Implemented by calling Assign(a_Parser). Self assignment is suppressed. - \param a_Parser Object to copy to this. - \return *this - \throw nothrow - */ - ParserBase& ParserBase::operator=(const ParserBase &a_Parser) - { - Assign(a_Parser); - return *this; - } - - //--------------------------------------------------------------------------- - /** \brief Copy state of a parser object to this. - - Clears Variables and Functions of this parser. - Copies the states of all internal variables. - Resets parse function to string parse mode. - - \param a_Parser the source object. - */ - void ParserBase::Assign(const ParserBase &a_Parser) - { - if (&a_Parser==this) - return; - - // Don't copy bytecode instead cause the parser to create new bytecode - // by resetting the parse function. - ReInit(); - - m_ConstDef = a_Parser.m_ConstDef; // Copy user define constants - m_VarDef = a_Parser.m_VarDef; // Copy user defined variables - m_bBuiltInOp = a_Parser.m_bBuiltInOp; - m_vStringBuf = a_Parser.m_vStringBuf; - m_vStackBuffer = a_Parser.m_vStackBuffer; - m_nFinalResultIdx = a_Parser.m_nFinalResultIdx; - m_StrVarDef = a_Parser.m_StrVarDef; - m_vStringVarBuf = a_Parser.m_vStringVarBuf; - m_nIfElseCounter = a_Parser.m_nIfElseCounter; - m_pTokenReader.reset(a_Parser.m_pTokenReader->Clone(this)); - - // Copy function and operator callbacks - m_FunDef = a_Parser.m_FunDef; // Copy function definitions - m_PostOprtDef = a_Parser.m_PostOprtDef; // post value unary operators - m_InfixOprtDef = a_Parser.m_InfixOprtDef; // unary operators for infix notation - m_OprtDef = a_Parser.m_OprtDef; // binary operators - - m_sNameChars = a_Parser.m_sNameChars; - m_sOprtChars = a_Parser.m_sOprtChars; - m_sInfixOprtChars = a_Parser.m_sInfixOprtChars; - } - - //--------------------------------------------------------------------------- - /** \brief Set the decimal separator. - \param cDecSep Decimal separator as a character value. - \sa SetThousandsSep - - By default muparser uses the "C" locale. The decimal separator of this - locale is overwritten by the one provided here. - */ - void ParserBase::SetDecSep(char_type cDecSep) - { - char_type cThousandsSep = std::use_facet< change_dec_sep<char_type> >(s_locale).thousands_sep(); - s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>(cDecSep, cThousandsSep)); - } - - //--------------------------------------------------------------------------- - /** \brief Sets the thousands operator. - \param cThousandsSep The thousands separator as a character - \sa SetDecSep - - By default muparser uses the "C" locale. The thousands separator of this - locale is overwritten by the one provided here. - */ - void ParserBase::SetThousandsSep(char_type cThousandsSep) - { - char_type cDecSep = std::use_facet< change_dec_sep<char_type> >(s_locale).decimal_point(); - s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>(cDecSep, cThousandsSep)); - } - - //--------------------------------------------------------------------------- - /** \brief Resets the locale. - - The default locale used "." as decimal separator, no thousands separator and - "," as function argument separator. - */ - void ParserBase::ResetLocale() - { - s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>('.')); - SetArgSep(','); - } - - //--------------------------------------------------------------------------- - /** \brief Initialize the token reader. - - Create new token reader object and submit pointers to function, operator, - constant and variable definitions. - - \post m_pTokenReader.get()!=0 - \throw nothrow - */ - void ParserBase::InitTokenReader() - { - m_pTokenReader.reset(new token_reader_type(this)); - } - - //--------------------------------------------------------------------------- - /** \brief Reset parser to string parsing mode and clear internal buffers. - - Clear bytecode, reset the token reader. - \throw nothrow - */ - void ParserBase::ReInit() const - { - m_pParseFormula = &ParserBase::ParseString; - m_vStringBuf.clear(); - m_vRPN.clear(); - m_pTokenReader->ReInit(); - m_nIfElseCounter = 0; - } - - //--------------------------------------------------------------------------- - void ParserBase::OnDetectVar(string_type * /*pExpr*/, int & /*nStart*/, int & /*nEnd*/) - {} - - //--------------------------------------------------------------------------- - /** \brief Returns the version of muparser. - \param eInfo A flag indicating whether the full version info should be - returned or not. - - Format is as follows: "MAJOR.MINOR (COMPILER_FLAGS)" The COMPILER_FLAGS - are returned only if eInfo==pviFULL. - */ - string_type ParserBase::GetVersion(EParserVersionInfo eInfo) const - { - stringstream_type ss; - - ss << MUP_VERSION; - - if (eInfo==pviFULL) - { - ss << _T(" (") << MUP_VERSION_DATE; - ss << std::dec << _T("; ") << sizeof(void*)*8 << _T("BIT"); - -#ifdef _DEBUG - ss << _T("; DEBUG"); -#else - ss << _T("; RELEASE"); -#endif - -#ifdef _UNICODE - ss << _T("; UNICODE"); -#else - #ifdef _MBCS - ss << _T("; MBCS"); - #else - ss << _T("; ASCII"); - #endif -#endif - -#ifdef MUP_USE_OPENMP - ss << _T("; OPENMP"); -//#else -// ss << _T("; NO_OPENMP"); -#endif - -#if defined(MUP_MATH_EXCEPTIONS) - ss << _T("; MATHEXC"); -//#else -// ss << _T("; NO_MATHEXC"); -#endif - - ss << _T(")"); - } - - return ss.str(); - } - - //--------------------------------------------------------------------------- - /** \brief Add a value parsing function. - - When parsing an expression muParser tries to detect values in the expression - string using different valident callbacks. Thus it's possible to parse - for hex values, binary values and floating point values. - */ - void ParserBase::AddValIdent(identfun_type a_pCallback) - { - m_pTokenReader->AddValIdent(a_pCallback); - } - - //--------------------------------------------------------------------------- - /** \brief Set a function that can create variable pointer for unknown expression variables. - \param a_pFactory A pointer to the variable factory. - \param pUserData A user defined context pointer. - */ - void ParserBase::SetVarFactory(facfun_type a_pFactory, void *pUserData) - { - m_pTokenReader->SetVarCreator(a_pFactory, pUserData); - } - - //--------------------------------------------------------------------------- - /** \brief Add a function or operator callback to the parser. */ - void ParserBase::AddCallback( const string_type &a_strName, - const ParserCallback &a_Callback, - funmap_type &a_Storage, - const char_type *a_szCharSet ) - { - if (a_Callback.GetAddr()==0) - Error(ecINVALID_FUN_PTR); - - const funmap_type *pFunMap = &a_Storage; - - // Check for conflicting operator or function names - if ( pFunMap!=&m_FunDef && m_FunDef.find(a_strName)!=m_FunDef.end() ) - Error(ecNAME_CONFLICT, -1, a_strName); - - if ( pFunMap!=&m_PostOprtDef && m_PostOprtDef.find(a_strName)!=m_PostOprtDef.end() ) - Error(ecNAME_CONFLICT, -1, a_strName); - - if ( pFunMap!=&m_InfixOprtDef && pFunMap!=&m_OprtDef && m_InfixOprtDef.find(a_strName)!=m_InfixOprtDef.end() ) - Error(ecNAME_CONFLICT, -1, a_strName); - - if ( pFunMap!=&m_InfixOprtDef && pFunMap!=&m_OprtDef && m_OprtDef.find(a_strName)!=m_OprtDef.end() ) - Error(ecNAME_CONFLICT, -1, a_strName); - - CheckOprt(a_strName, a_Callback, a_szCharSet); - a_Storage[a_strName] = a_Callback; - ReInit(); - } - - //--------------------------------------------------------------------------- - /** \brief Check if a name contains invalid characters. - - \throw ParserException if the name contains invalid characters. - */ - void ParserBase::CheckOprt(const string_type &a_sName, - const ParserCallback &a_Callback, - const string_type &a_szCharSet) const - { - if ( !a_sName.length() || - (a_sName.find_first_not_of(a_szCharSet)!=string_type::npos) || - (a_sName[0]>='0' && a_sName[0]<='9')) - { - switch(a_Callback.GetCode()) - { - case cmOPRT_POSTFIX: Error(ecINVALID_POSTFIX_IDENT, -1, a_sName); - case cmOPRT_INFIX: Error(ecINVALID_INFIX_IDENT, -1, a_sName); - default: Error(ecINVALID_NAME, -1, a_sName); - } - } - } - - //--------------------------------------------------------------------------- - /** \brief Check if a name contains invalid characters. - - \throw ParserException if the name contains invalid characters. - */ - void ParserBase::CheckName(const string_type &a_sName, - const string_type &a_szCharSet) const - { - if ( !a_sName.length() || - (a_sName.find_first_not_of(a_szCharSet)!=string_type::npos) || - (a_sName[0]>='0' && a_sName[0]<='9')) - { - Error(ecINVALID_NAME); - } - } - - //--------------------------------------------------------------------------- - /** \brief Set the formula. - \param a_strFormula Formula as string_type - \throw ParserException in case of syntax errors. - - Triggers first time calculation thus the creation of the bytecode and - scanning of used variables. - */ - void ParserBase::SetExpr(const string_type &a_sExpr) - { - // Check locale compatibility - std::locale loc; - if (m_pTokenReader->GetArgSep()==std::use_facet<numpunct<char_type> >(loc).decimal_point()) - Error(ecLOCALE); - - // <ibg> 20060222: Bugfix for Borland-Kylix: - // adding a space to the expression will keep Borlands KYLIX from going wild - // when calling tellg on a stringstream created from the expression after - // reading a value at the end of an expression. (mu::Parser::IsVal function) - // (tellg returns -1 otherwise causing the parser to ignore the value) - string_type sBuf(a_sExpr + _T(" ") ); - m_pTokenReader->SetFormula(sBuf); - ReInit(); - } - - //--------------------------------------------------------------------------- - /** \brief Get the default symbols used for the built in operators. - \sa c_DefaultOprt - */ - const char_type** ParserBase::GetOprtDef() const - { - return (const char_type **)(&c_DefaultOprt[0]); - } - - //--------------------------------------------------------------------------- - /** \brief Define the set of valid characters to be used in names of - functions, variables, constants. - */ - void ParserBase::DefineNameChars(const char_type *a_szCharset) - { - m_sNameChars = a_szCharset; - } - - //--------------------------------------------------------------------------- - /** \brief Define the set of valid characters to be used in names of - binary operators and postfix operators. - */ - void ParserBase::DefineOprtChars(const char_type *a_szCharset) - { - m_sOprtChars = a_szCharset; - } - - //--------------------------------------------------------------------------- - /** \brief Define the set of valid characters to be used in names of - infix operators. - */ - void ParserBase::DefineInfixOprtChars(const char_type *a_szCharset) - { - m_sInfixOprtChars = a_szCharset; - } - - //--------------------------------------------------------------------------- - /** \brief Virtual function that defines the characters allowed in name identifiers. - \sa #ValidOprtChars, #ValidPrefixOprtChars - */ - const char_type* ParserBase::ValidNameChars() const - { - assert(m_sNameChars.size()); - return m_sNameChars.c_str(); - } - - //--------------------------------------------------------------------------- - /** \brief Virtual function that defines the characters allowed in operator definitions. - \sa #ValidNameChars, #ValidPrefixOprtChars - */ - const char_type* ParserBase::ValidOprtChars() const - { - assert(m_sOprtChars.size()); - return m_sOprtChars.c_str(); - } - - //--------------------------------------------------------------------------- - /** \brief Virtual function that defines the characters allowed in infix operator definitions. - \sa #ValidNameChars, #ValidOprtChars - */ - const char_type* ParserBase::ValidInfixOprtChars() const - { - assert(m_sInfixOprtChars.size()); - return m_sInfixOprtChars.c_str(); - } - - //--------------------------------------------------------------------------- - /** \brief Add a user defined operator. - \post Will reset the Parser to string parsing mode. - */ - void ParserBase::DefinePostfixOprt(const string_type &a_sName, - fun_type1 a_pFun, - bool a_bAllowOpt) - { - AddCallback(a_sName, - ParserCallback(a_pFun, a_bAllowOpt, prPOSTFIX, cmOPRT_POSTFIX), - m_PostOprtDef, - ValidOprtChars() ); - } - - //--------------------------------------------------------------------------- - /** \brief Initialize user defined functions. - - Calls the virtual functions InitFun(), InitConst() and InitOprt(). - */ - void ParserBase::Init() - { - InitCharSets(); - InitFun(); - InitConst(); - InitOprt(); - } - - //--------------------------------------------------------------------------- - /** \brief Add a user defined operator. - \post Will reset the Parser to string parsing mode. - \param [in] a_sName operator Identifier - \param [in] a_pFun Operator callback function - \param [in] a_iPrec Operator Precedence (default=prSIGN) - \param [in] a_bAllowOpt True if operator is volatile (default=false) - \sa EPrec - */ - void ParserBase::DefineInfixOprt(const string_type &a_sName, - fun_type1 a_pFun, - int a_iPrec, - bool a_bAllowOpt) - { - AddCallback(a_sName, - ParserCallback(a_pFun, a_bAllowOpt, a_iPrec, cmOPRT_INFIX), - m_InfixOprtDef, - ValidInfixOprtChars() ); - } - - - //--------------------------------------------------------------------------- - /** \brief Define a binary operator. - \param [in] a_sName The identifier of the operator. - \param [in] a_pFun Pointer to the callback function. - \param [in] a_iPrec Precedence of the operator. - \param [in] a_eAssociativity The associativity of the operator. - \param [in] a_bAllowOpt If this is true the operator may be optimized away. - - Adds a new Binary operator the the parser instance. - */ - void ParserBase::DefineOprt( const string_type &a_sName, - fun_type2 a_pFun, - unsigned a_iPrec, - EOprtAssociativity a_eAssociativity, - bool a_bAllowOpt ) - { - // Check for conflicts with built in operator names - for (int i=0; m_bBuiltInOp && i<cmENDIF; ++i) - if (a_sName == string_type(c_DefaultOprt[i])) - Error(ecBUILTIN_OVERLOAD, -1, a_sName); - - AddCallback(a_sName, - ParserCallback(a_pFun, a_bAllowOpt, a_iPrec, a_eAssociativity), - m_OprtDef, - ValidOprtChars() ); - } - - //--------------------------------------------------------------------------- - /** \brief Define a new string constant. - \param [in] a_strName The name of the constant. - \param [in] a_strVal the value of the constant. - */ - void ParserBase::DefineStrConst(const string_type &a_strName, const string_type &a_strVal) - { - // Test if a constant with that names already exists - if (m_StrVarDef.find(a_strName)!=m_StrVarDef.end()) - Error(ecNAME_CONFLICT); - - CheckName(a_strName, ValidNameChars()); - - 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(); - } - - //--------------------------------------------------------------------------- - /** \brief Add a user defined variable. - \param [in] a_sName the variable name - \param [in] a_pVar A pointer to the variable value. - \post Will reset the Parser to string parsing mode. - \throw ParserException in case the name contains invalid signs or a_pVar is NULL. - */ - void ParserBase::DefineVar(const string_type &a_sName, value_type *a_pVar) - { - if (a_pVar==0) - Error(ecINVALID_VAR_PTR); - - // Test if a constant with that names already exists - if (m_ConstDef.find(a_sName)!=m_ConstDef.end()) - Error(ecNAME_CONFLICT); - - CheckName(a_sName, ValidNameChars()); - m_VarDef[a_sName] = a_pVar; - ReInit(); - } - - //--------------------------------------------------------------------------- - /** \brief Add a user defined constant. - \param [in] a_sName The name of the constant. - \param [in] a_fVal the value of the constant. - \post Will reset the Parser to string parsing mode. - \throw ParserException in case the name contains invalid signs. - */ - void ParserBase::DefineConst(const string_type &a_sName, value_type a_fVal) - { - CheckName(a_sName, ValidNameChars()); - m_ConstDef[a_sName] = a_fVal; - ReInit(); - } - - //--------------------------------------------------------------------------- - /** \brief Get operator priority. - \throw ParserException if a_Oprt is no operator code - */ - int ParserBase::GetOprtPrecedence(const token_type &a_Tok) const - { - switch (a_Tok.GetCode()) - { - // built in operators - case cmEND: return -5; - case cmARG_SEP: return -4; - case cmASSIGN: return -1; - case cmELSE: - case cmIF: return 0; - case cmLAND: return prLAND; - case cmLOR: return prLOR; - case cmLT: - case cmGT: - case cmLE: - case cmGE: - case cmNEQ: - case cmEQ: return prCMP; - case cmADD: - case cmSUB: return prADD_SUB; - case cmMUL: - case cmDIV: return prMUL_DIV; - case cmPOW: return prPOW; - - // user defined binary operators - case cmOPRT_INFIX: - case cmOPRT_BIN: return a_Tok.GetPri(); - default: Error(ecINTERNAL_ERROR, 5); - return 999; - } - } - - //--------------------------------------------------------------------------- - /** \brief Get operator priority. - \throw ParserException if a_Oprt is no operator code - */ - EOprtAssociativity ParserBase::GetOprtAssociativity(const token_type &a_Tok) const - { - switch (a_Tok.GetCode()) - { - case cmASSIGN: - case cmLAND: - case cmLOR: - case cmLT: - case cmGT: - case cmLE: - case cmGE: - case cmNEQ: - case cmEQ: - case cmADD: - case cmSUB: - case cmMUL: - case cmDIV: return oaLEFT; - case cmPOW: return oaRIGHT; - case cmOPRT_BIN: return a_Tok.GetAssociativity(); - default: return oaNONE; - } - } - - //--------------------------------------------------------------------------- - /** \brief Return a map containing the used variables only. */ - const varmap_type& ParserBase::GetUsedVar() const - { - try - { - m_pTokenReader->IgnoreUndefVar(true); - CreateRPN(); // try to create bytecode, but don't use it for any further calculations since it - // may contain references to nonexisting variables. - m_pParseFormula = &ParserBase::ParseString; - m_pTokenReader->IgnoreUndefVar(false); - } - 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; - } - - return m_pTokenReader->GetUsedVar(); - } - - //--------------------------------------------------------------------------- - /** \brief Return a map containing the used variables only. */ - const varmap_type& ParserBase::GetVar() const - { - return m_VarDef; - } - - //--------------------------------------------------------------------------- - /** \brief Return a map containing all parser constants. */ - const valmap_type& ParserBase::GetConst() const - { - return m_ConstDef; - } - - //--------------------------------------------------------------------------- - /** \brief Return prototypes of all parser functions. - \return #m_FunDef - \sa FunProt - \throw nothrow - - The return type is a map of the public type #funmap_type containing the prototype - definitions for all numerical parser functions. String functions are not part of - this map. The Prototype definition is encapsulated in objects of the class FunProt - one per parser function each associated with function names via a map construct. - */ - const funmap_type& ParserBase::GetFunDef() const - { - return m_FunDef; - } - - //--------------------------------------------------------------------------- - /** \brief Retrieve the formula. */ - const string_type& ParserBase::GetExpr() const - { - return m_pTokenReader->GetExpr(); - } - - //--------------------------------------------------------------------------- - /** \brief Execute a function that takes a single string argument. - \param a_FunTok Function token. - \throw exception_type If the function token is not a string function - */ - ParserBase::token_type ParserBase::ApplyStrFunc(const token_type &a_FunTok, - const std::vector<token_type> &a_vArg) const - { - if (a_vArg.back().GetCode()!=cmSTRING) - Error(ecSTRING_EXPECTED, m_pTokenReader->GetPos(), a_FunTok.GetAsString()); - - token_type valTok; - generic_fun_type pFunc = a_FunTok.GetFuncAddr(); - assert(pFunc); - - try - { - // Check function arguments; write dummy value into valtok to represent the result - switch(a_FunTok.GetArgCount()) - { - case 0: valTok.SetVal(1); a_vArg[0].GetAsString(); break; - case 1: valTok.SetVal(1); a_vArg[1].GetAsString(); a_vArg[0].GetVal(); break; - case 2: valTok.SetVal(1); a_vArg[2].GetAsString(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break; - default: Error(ecINTERNAL_ERROR); - } - } - catch(ParserError& ) - { - Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), a_FunTok.GetAsString()); - } - - // string functions won't be optimized - m_vRPN.AddStrFun(pFunc, a_FunTok.GetArgCount(), a_vArg.back().GetIdx()); - - // Push dummy value representing the function result to the stack - return valTok; - } - - //--------------------------------------------------------------------------- - /** \brief Apply a function token. - \param iArgCount Number of Arguments actually gathered used only for multiarg functions. - \post The result is pushed to the value stack - \post The function token is removed from the stack - \throw exception_type if Argument count does not match function requirements. - */ - void ParserBase::ApplyFunc( ParserStack<token_type> &a_stOpt, - ParserStack<token_type> &a_stVal, - int a_iArgCount) const - { - assert(m_pTokenReader.get()); - - // Operator stack empty or does not contain tokens with callback functions - if (a_stOpt.empty() || a_stOpt.top().GetFuncAddr()==0 ) - return; - - token_type funTok = a_stOpt.pop(); - assert(funTok.GetFuncAddr()); - - // Binary operators must rely on their internal operator number - // since counting of operators relies on commas for function arguments - // binary operators do not have commas in their expression - int iArgCount = (funTok.GetCode()==cmOPRT_BIN) ? funTok.GetArgCount() : a_iArgCount; - - // determine how many parameters the function needs. To remember iArgCount includes the - // string parameter whilst GetArgCount() counts only numeric parameters. - int iArgRequired = funTok.GetArgCount() + ((funTok.GetType()==tpSTR) ? 1 : 0); - - // Thats the number of numerical parameters - int iArgNumerical = iArgCount - ((funTok.GetType()==tpSTR) ? 1 : 0); - - if (funTok.GetCode()==cmFUNC_STR && iArgCount-iArgNumerical>1) - Error(ecINTERNAL_ERROR); - - if (funTok.GetArgCount()>=0 && iArgCount>iArgRequired) - Error(ecTOO_MANY_PARAMS, m_pTokenReader->GetPos()-1, funTok.GetAsString()); - - if (funTok.GetCode()!=cmOPRT_BIN && iArgCount<iArgRequired ) - Error(ecTOO_FEW_PARAMS, m_pTokenReader->GetPos()-1, funTok.GetAsString()); - - if (funTok.GetCode()==cmFUNC_STR && iArgCount>iArgRequired ) - Error(ecTOO_MANY_PARAMS, m_pTokenReader->GetPos()-1, funTok.GetAsString()); - - // Collect the numeric function arguments from the value stack and store them - // in a vector - std::vector<token_type> stArg; - for (int i=0; i<iArgNumerical; ++i) - { - stArg.push_back( a_stVal.pop() ); - if ( stArg.back().GetType()==tpSTR && funTok.GetType()!=tpSTR ) - Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), funTok.GetAsString()); - } - - switch(funTok.GetCode()) - { - case cmFUNC_STR: - stArg.push_back(a_stVal.pop()); - - if ( stArg.back().GetType()==tpSTR && funTok.GetType()!=tpSTR ) - Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), funTok.GetAsString()); - - ApplyStrFunc(funTok, stArg); - break; - - case cmFUNC_BULK: - m_vRPN.AddBulkFun(funTok.GetFuncAddr(), (int)stArg.size()); - break; - - case cmOPRT_BIN: - case cmOPRT_POSTFIX: - case cmOPRT_INFIX: - case cmFUNC: - if (funTok.GetArgCount()==-1 && iArgCount==0) - Error(ecTOO_FEW_PARAMS, m_pTokenReader->GetPos(), funTok.GetAsString()); - - m_vRPN.AddFun(funTok.GetFuncAddr(), (funTok.GetArgCount()==-1) ? -iArgNumerical : iArgNumerical); - break; - } - - // Push dummy value representing the function result to the stack - token_type token; - token.SetVal(1); - a_stVal.push(token); - } - - //--------------------------------------------------------------------------- - void ParserBase::ApplyIfElse(ParserStack<token_type> &a_stOpt, - ParserStack<token_type> &a_stVal) const - { - // Check if there is an if Else clause to be calculated - while (a_stOpt.size() && a_stOpt.top().GetCode()==cmELSE) - { - token_type opElse = a_stOpt.pop(); - MUP_ASSERT(a_stOpt.size()>0); - - // Take the value associated with the else branch from the value stack - token_type vVal2 = a_stVal.pop(); - - MUP_ASSERT(a_stOpt.size()>0); - MUP_ASSERT(a_stVal.size()>=2); - - // it then else is a ternary operator Pop all three values from the value s - // tack and just return the right value - token_type vVal1 = a_stVal.pop(); - token_type vExpr = a_stVal.pop(); - - a_stVal.push( (vExpr.GetVal()!=0) ? vVal1 : vVal2); - - token_type opIf = a_stOpt.pop(); - MUP_ASSERT(opElse.GetCode()==cmELSE); - MUP_ASSERT(opIf.GetCode()==cmIF); - - m_vRPN.AddIfElse(cmENDIF); - } // while pending if-else-clause found - } - - //--------------------------------------------------------------------------- - /** \brief Performs the necessary steps to write code for - the execution of binary operators into the bytecode. - */ - void ParserBase::ApplyBinOprt(ParserStack<token_type> &a_stOpt, - ParserStack<token_type> &a_stVal) const - { - // is it a user defined binary operator? - if (a_stOpt.top().GetCode()==cmOPRT_BIN) - { - ApplyFunc(a_stOpt, a_stVal, 2); - } - else - { - MUP_ASSERT(a_stVal.size()>=2); - token_type valTok1 = a_stVal.pop(), - valTok2 = a_stVal.pop(), - optTok = a_stOpt.pop(), - resTok; - - if ( valTok1.GetType()!=valTok2.GetType() || - (valTok1.GetType()==tpSTR && valTok2.GetType()==tpSTR) ) - Error(ecOPRT_TYPE_CONFLICT, m_pTokenReader->GetPos(), optTok.GetAsString()); - - if (optTok.GetCode()==cmASSIGN) - { - if (valTok2.GetCode()!=cmVAR) - Error(ecUNEXPECTED_OPERATOR, -1, _T("=")); - - m_vRPN.AddAssignOp(valTok2.GetVar()); - } - else - m_vRPN.AddOp(optTok.GetCode()); - - resTok.SetVal(1); - a_stVal.push(resTok); - } - } - - //--------------------------------------------------------------------------- - /** \brief Apply a binary operator. - \param a_stOpt The operator stack - \param a_stVal The value stack - */ - void ParserBase::ApplyRemainingOprt(ParserStack<token_type> &stOpt, - ParserStack<token_type> &stVal) const - { - while (stOpt.size() && - stOpt.top().GetCode() != cmBO && - stOpt.top().GetCode() != cmIF) - { - token_type tok = stOpt.top(); - switch (tok.GetCode()) - { - case cmOPRT_INFIX: - case cmOPRT_BIN: - case cmLE: - case cmGE: - case cmNEQ: - case cmEQ: - case cmLT: - case cmGT: - case cmADD: - case cmSUB: - case cmMUL: - case cmDIV: - case cmPOW: - case cmLAND: - case cmLOR: - case cmASSIGN: - if (stOpt.top().GetCode()==cmOPRT_INFIX) - ApplyFunc(stOpt, stVal, 1); - else - ApplyBinOprt(stOpt, stVal); - break; - - case cmELSE: - ApplyIfElse(stOpt, stVal); - break; - - default: - Error(ecINTERNAL_ERROR); - } - } - } - - //--------------------------------------------------------------------------- - /** \brief Parse the command code. - \sa ParseString(...) - - Command code contains precalculated stack positions of the values and the - associated operators. The Stack is filled beginning from index one the - value at index zero is not used at all. - */ - value_type ParserBase::ParseCmdCode() const - { - return ParseCmdCodeBulk(0, 0); - } - - //--------------------------------------------------------------------------- - /** \brief Evaluate the RPN. - \param nOffset The offset added to variable addresses (for bulk mode) - \param nThreadID OpenMP Thread id of the calling thread - */ - value_type ParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const - { - assert(nThreadID<=s_MaxNumOpenMPThreads); - - // Note: The check for nOffset==0 and nThreadID here is not necessary but - // brings a minor performance gain when not in bulk mode. - value_type *Stack = ((nOffset==0) && (nThreadID==0)) ? &m_vStackBuffer[0] : &m_vStackBuffer[nThreadID * (m_vStackBuffer.size() / s_MaxNumOpenMPThreads)]; - value_type buf; - int sidx(0); - for (const SToken *pTok = m_vRPN.GetBase(); pTok->Cmd!=cmEND ; ++pTok) - { - switch (pTok->Cmd) - { - // built in binary operators - case cmLE: --sidx; Stack[sidx] = Stack[sidx] <= Stack[sidx+1]; continue; - case cmGE: --sidx; Stack[sidx] = Stack[sidx] >= Stack[sidx+1]; continue; - case cmNEQ: --sidx; Stack[sidx] = Stack[sidx] != Stack[sidx+1]; continue; - case cmEQ: --sidx; Stack[sidx] = Stack[sidx] == Stack[sidx+1]; continue; - case cmLT: --sidx; Stack[sidx] = Stack[sidx] < Stack[sidx+1]; continue; - case cmGT: --sidx; Stack[sidx] = Stack[sidx] > Stack[sidx+1]; continue; - case cmADD: --sidx; Stack[sidx] += Stack[1+sidx]; continue; - case cmSUB: --sidx; Stack[sidx] -= Stack[1+sidx]; continue; - case cmMUL: --sidx; Stack[sidx] *= Stack[1+sidx]; continue; - case cmDIV: --sidx; - - #if defined(MUP_MATH_EXCEPTIONS) - if (Stack[1+sidx]==0) - Error(ecDIV_BY_ZERO); - #endif - Stack[sidx] /= Stack[1+sidx]; - continue; - - case cmPOW: - --sidx; Stack[sidx] = MathImpl<value_type>::Pow(Stack[sidx], Stack[1+sidx]); - continue; - - case cmLAND: --sidx; Stack[sidx] = Stack[sidx] && Stack[sidx+1]; continue; - case cmLOR: --sidx; Stack[sidx] = Stack[sidx] || Stack[sidx+1]; continue; - - case cmASSIGN: - // 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: - // MUP_FAIL(INVALID_CODE_IN_BYTECODE); - // continue; - - case cmIF: - if (Stack[sidx--]==0) - pTok += pTok->Oprt.offset; - continue; - - case cmELSE: - pTok += pTok->Oprt.offset; - continue; - - case cmENDIF: - continue; - - //case cmARG_SEP: - // MUP_FAIL(INVALID_CODE_IN_BYTECODE); - // continue; - - // value and variable tokens - case cmVAR: Stack[++sidx] = *(pTok->Val.ptr + nOffset); continue; - case cmVAL: Stack[++sidx] = pTok->Val.data2; continue; - - case cmVARPOW2: buf = *(pTok->Val.ptr + nOffset); - Stack[++sidx] = buf*buf; - continue; - - case cmVARPOW3: buf = *(pTok->Val.ptr + nOffset); - Stack[++sidx] = buf*buf*buf; - continue; - - case cmVARPOW4: buf = *(pTok->Val.ptr + nOffset); - Stack[++sidx] = buf*buf*buf*buf; - continue; - - 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->Fun.argc; - - // switch according to argument count - switch(iArgCount) - { - 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->Fun.ptr)(&Stack[sidx], -iArgCount); - continue; - } - } - - // Next is treatment of string functions - case cmFUNC_STR: - { - sidx -= pTok->Fun.argc -1; - - // The index of the string argument in the string table - int iIdxStack = pTok->Fun.idx; - MUP_ASSERT( iIdxStack>=0 && iIdxStack<(int)m_vStringBuf.size() ); - - switch(pTok->Fun.argc) // switch according to argument count - { - 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; - } - - case cmFUNC_BULK: - { - int iArgCount = pTok->Fun.argc; - - // switch according to argument count - switch(iArgCount) - { - 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; - } - } - - default: - Error(ecINTERNAL_ERROR, 3); - return 0; - } // switch CmdCode - } // for all bytecode tokens - - return Stack[m_nFinalResultIdx]; - } - - //--------------------------------------------------------------------------- - void ParserBase::CreateRPN() const - { - if (!m_pTokenReader->GetExpr().length()) - Error(ecUNEXPECTED_EOF, 0); - - ParserStack<token_type> stOpt, stVal; - ParserStack<int> stArgCount; - token_type opta, opt; // for storing operators - token_type val, tval; // for storing value - - ReInit(); - - // The outermost counter counts the number of separated items - // such as in "a=10,b=20,c=c+a" - stArgCount.push(1); - - for(;;) - { - opt = m_pTokenReader->ReadNextToken(); - - switch (opt.GetCode()) - { - // - // Next three are different kind of value entries - // - case cmSTRING: - opt.SetIdx((int)m_vStringBuf.size()); // Assign buffer index to token - stVal.push(opt); - m_vStringBuf.push_back(opt.GetAsString()); // Store string in internal buffer - break; - - case cmVAR: - stVal.push(opt); - m_vRPN.AddVar( static_cast<value_type*>(opt.GetVar()) ); - break; - - case cmVAL: - stVal.push(opt); - m_vRPN.AddVal( opt.GetVal() ); - break; - - case cmELSE: - m_nIfElseCounter--; - if (m_nIfElseCounter<0) - Error(ecMISPLACED_COLON, m_pTokenReader->GetPos()); - - ApplyRemainingOprt(stOpt, stVal); - m_vRPN.AddIfElse(cmELSE); - stOpt.push(opt); - break; - - - case cmARG_SEP: - if (stArgCount.empty()) - Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); - - ++stArgCount.top(); - // fallthrough intentional (no break!) - - case cmEND: - ApplyRemainingOprt(stOpt, stVal); - break; - - case cmBC: - { - // The argument count for parameterless functions is zero - // by default an opening bracket sets parameter count to 1 - // in preparation of arguments to come. If the last token - // was an opening bracket we know better... - if (opta.GetCode()==cmBO) - --stArgCount.top(); - - ApplyRemainingOprt(stOpt, stVal); - - // Check if the bracket content has been evaluated completely - if (stOpt.size() && stOpt.top().GetCode()==cmBO) - { - // if opt is ")" and opta is "(" the bracket has been evaluated, now its time to check - // if there is either a function or a sign pending - // neither the opening nor the closing bracket will be pushed back to - // the operator stack - // Check if a function is standing in front of the opening bracket, - // if yes evaluate it afterwards check for infix operators - assert(stArgCount.size()); - int iArgCount = stArgCount.pop(); - - stOpt.pop(); // Take opening bracket from stack - - if (iArgCount>1 && ( stOpt.size()==0 || - (stOpt.top().GetCode()!=cmFUNC && - stOpt.top().GetCode()!=cmFUNC_BULK && - stOpt.top().GetCode()!=cmFUNC_STR) ) ) - Error(ecUNEXPECTED_ARG, m_pTokenReader->GetPos()); - - // The opening bracket was popped from the stack now check if there - // was a function before this bracket - if (stOpt.size() && - stOpt.top().GetCode()!=cmOPRT_INFIX && - stOpt.top().GetCode()!=cmOPRT_BIN && - stOpt.top().GetFuncAddr()!=0) - { - ApplyFunc(stOpt, stVal, iArgCount); - } - } - } // if bracket content is evaluated - break; - - // - // Next are the binary operator entries - // - //case cmAND: // built in binary operators - //case cmOR: - //case cmXOR: - case cmIF: - m_nIfElseCounter++; - // fallthrough intentional (no break!) - - case cmLAND: - case cmLOR: - case cmLT: - case cmGT: - case cmLE: - case cmGE: - case cmNEQ: - case cmEQ: - case cmADD: - case cmSUB: - case cmMUL: - case cmDIV: - case cmPOW: - case cmASSIGN: - case cmOPRT_BIN: - - // A binary operator (user defined or built in) has been found. - while ( stOpt.size() && - stOpt.top().GetCode() != cmBO && - stOpt.top().GetCode() != cmELSE && - stOpt.top().GetCode() != cmIF) - { - int nPrec1 = GetOprtPrecedence(stOpt.top()), - nPrec2 = GetOprtPrecedence(opt); - - if (stOpt.top().GetCode()==opt.GetCode()) - { - - // Deal with operator associativity - EOprtAssociativity eOprtAsct = GetOprtAssociativity(opt); - if ( (eOprtAsct==oaRIGHT && (nPrec1 <= nPrec2)) || - (eOprtAsct==oaLEFT && (nPrec1 < nPrec2)) ) - { - break; - } - } - else if (nPrec1 < nPrec2) - { - // In case the operators are not equal the precedence decides alone... - break; - } - - if (stOpt.top().GetCode()==cmOPRT_INFIX) - ApplyFunc(stOpt, stVal, 1); - else - ApplyBinOprt(stOpt, stVal); - } // while ( ... ) - - if (opt.GetCode()==cmIF) - m_vRPN.AddIfElse(opt.GetCode()); - - // The operator can't be evaluated right now, push back to the operator stack - stOpt.push(opt); - break; - - // - // Last section contains functions and operators implicitly mapped to functions - // - case cmBO: - stArgCount.push(1); - stOpt.push(opt); - break; - - case cmOPRT_INFIX: - case cmFUNC: - case cmFUNC_BULK: - case cmFUNC_STR: - stOpt.push(opt); - break; - - case cmOPRT_POSTFIX: - stOpt.push(opt); - ApplyFunc(stOpt, stVal, 1); // this is the postfix operator - break; - - default: Error(ecINTERNAL_ERROR, 3); - } // end of switch operator-token - - opta = opt; - - if ( opt.GetCode() == cmEND ) - { - m_vRPN.Finalize(); - break; - } - - if (ParserBase::g_DbgDumpStack) - { - StackDump(stVal, stOpt); - m_vRPN.AsciiDump(); - } - } // while (true) - - if (ParserBase::g_DbgDumpCmdCode) - m_vRPN.AsciiDump(); - - if (m_nIfElseCounter>0) - Error(ecMISSING_ELSE_CLAUSE); - - // get the last value (= final result) from the stack - MUP_ASSERT(stArgCount.size()==1); - m_nFinalResultIdx = stArgCount.top(); - if (m_nFinalResultIdx==0) - Error(ecINTERNAL_ERROR, 9); - - if (stVal.size()==0) - Error(ecEMPTY_EXPRESSION); - - if (stVal.top().GetType()!=tpDBL) - Error(ecSTR_RESULT); - - m_vStackBuffer.resize(m_vRPN.GetMaxStackSize() * s_MaxNumOpenMPThreads); - } - - //--------------------------------------------------------------------------- - /** \brief One of the two main parse functions. - \sa ParseCmdCode(...) - - Parse expression from input string. Perform syntax checking and create - bytecode. After parsing the string and creating the bytecode the function - pointer #m_pParseFormula will be changed to the second parse routine the - uses bytecode instead of string parsing. - */ - value_type ParserBase::ParseString() const - { - try - { - CreateRPN(); - m_pParseFormula = &ParserBase::ParseCmdCode; - return (this->*m_pParseFormula)(); - } - catch(ParserError &exc) - { - exc.SetFormula(m_pTokenReader->GetExpr()); - throw; - } - } - - //--------------------------------------------------------------------------- - /** \brief Create an error containing the parse error position. - - This function will create an Parser Exception object containing the error text and - its position. - - \param a_iErrc [in] The error code of type #EErrorCodes. - \param a_iPos [in] The position where the error was detected. - \param a_strTok [in] The token string representation associated with the error. - \throw ParserException always throws thats the only purpose of this function. - */ - void ParserBase::Error(EErrorCodes a_iErrc, int a_iPos, const string_type &a_sTok) const - { - throw exception_type(a_iErrc, a_sTok, m_pTokenReader->GetExpr(), a_iPos); - } - - //------------------------------------------------------------------------------ - /** \brief Clear all user defined variables. - \throw nothrow - - Resets the parser to string parsing mode by calling #ReInit. - */ - void ParserBase::ClearVar() - { - m_VarDef.clear(); - ReInit(); - } - - //------------------------------------------------------------------------------ - /** \brief Remove a variable from internal storage. - \throw nothrow - - Removes a variable if it exists. If the Variable does not exist nothing will be done. - */ - void ParserBase::RemoveVar(const string_type &a_strVarName) - { - varmap_type::iterator item = m_VarDef.find(a_strVarName); - if (item!=m_VarDef.end()) - { - m_VarDef.erase(item); - ReInit(); - } - } - - //------------------------------------------------------------------------------ - /** \brief Clear all functions. - \post Resets the parser to string parsing mode. - \throw nothrow - */ - void ParserBase::ClearFun() - { - m_FunDef.clear(); - ReInit(); - } - - //------------------------------------------------------------------------------ - /** \brief Clear all user defined constants. - - Both numeric and string constants will be removed from the internal storage. - \post Resets the parser to string parsing mode. - \throw nothrow - */ - void ParserBase::ClearConst() - { - m_ConstDef.clear(); - m_StrVarDef.clear(); - ReInit(); - } - - //------------------------------------------------------------------------------ - /** \brief Clear all user defined postfix operators. - \post Resets the parser to string parsing mode. - \throw nothrow - */ - void ParserBase::ClearPostfixOprt() - { - m_PostOprtDef.clear(); - ReInit(); - } - - //------------------------------------------------------------------------------ - /** \brief Clear all user defined binary operators. - \post Resets the parser to string parsing mode. - \throw nothrow - */ - void ParserBase::ClearOprt() - { - m_OprtDef.clear(); - ReInit(); - } - - //------------------------------------------------------------------------------ - /** \brief Clear the user defined Prefix operators. - \post Resets the parser to string parser mode. - \throw nothrow - */ - void ParserBase::ClearInfixOprt() - { - m_InfixOprtDef.clear(); - ReInit(); - } - - //------------------------------------------------------------------------------ - /** \brief Enable or disable the formula optimization feature. - \post Resets the parser to string parser mode. - \throw nothrow - */ - void ParserBase::EnableOptimizer(bool a_bIsOn) - { - m_vRPN.EnableOptimizer(a_bIsOn); - ReInit(); - } - - //--------------------------------------------------------------------------- - /** \brief Enable the dumping of bytecode and stack content on the console. - \param bDumpCmd Flag to enable dumping of the current bytecode to the console. - \param bDumpStack Flag to enable dumping of the stack content is written to the console. - - This function is for debug purposes only! - */ - void ParserBase::EnableDebugDump(bool bDumpCmd, bool bDumpStack) - { - ParserBase::g_DbgDumpCmdCode = bDumpCmd; - ParserBase::g_DbgDumpStack = bDumpStack; - } - - //------------------------------------------------------------------------------ - /** \brief Enable or disable the built in binary operators. - \throw nothrow - \sa m_bBuiltInOp, ReInit() - - If you disable the built in binary operators there will be no binary operators - defined. Thus you must add them manually one by one. It is not possible to - disable built in operators selectively. This function will Reinitialize the - parser by calling ReInit(). - */ - void ParserBase::EnableBuiltInOprt(bool a_bIsOn) - { - m_bBuiltInOp = a_bIsOn; - ReInit(); - } - - //------------------------------------------------------------------------------ - /** \brief Query status of built in variables. - \return #m_bBuiltInOp; true if built in operators are enabled. - \throw nothrow - */ - bool ParserBase::HasBuiltInOprt() const - { - return m_bBuiltInOp; - } - - //------------------------------------------------------------------------------ - /** \brief Get the argument separator character. - */ - char_type ParserBase::GetArgSep() const - { - return m_pTokenReader->GetArgSep(); - } - - //------------------------------------------------------------------------------ - /** \brief Set argument separator. - \param cArgSep the argument separator character. - */ - void ParserBase::SetArgSep(char_type cArgSep) - { - m_pTokenReader->SetArgSep(cArgSep); - } - - //------------------------------------------------------------------------------ - /** \brief Dump stack content. - - This function is used for debugging only. - */ - void ParserBase::StackDump(const ParserStack<token_type> &a_stVal, - const ParserStack<token_type> &a_stOprt) const - { - ParserStack<token_type> stOprt(a_stOprt), - stVal(a_stVal); - - mu::console() << _T("\nValue stack:\n"); - while ( !stVal.empty() ) - { - token_type val = stVal.pop(); - if (val.GetType()==tpSTR) - mu::console() << _T(" \"") << val.GetAsString() << _T("\" "); - else - mu::console() << _T(" ") << val.GetVal() << _T(" "); - } - mu::console() << "\nOperator stack:\n"; - - while ( !stOprt.empty() ) - { - if (stOprt.top().GetCode()<=cmASSIGN) - { - mu::console() << _T("OPRT_INTRNL \"") - << ParserBase::c_DefaultOprt[stOprt.top().GetCode()] - << _T("\" \n"); - } - else - { - switch(stOprt.top().GetCode()) - { - case cmVAR: mu::console() << _T("VAR\n"); break; - case cmVAL: mu::console() << _T("VAL\n"); break; - case cmFUNC: mu::console() << _T("FUNC \"") - << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmFUNC_BULK: mu::console() << _T("FUNC_BULK \"") - << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmOPRT_INFIX: mu::console() << _T("OPRT_INFIX \"") - << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmOPRT_BIN: mu::console() << _T("OPRT_BIN \"") - << stOprt.top().GetAsString() - << _T("\"\n"); break; - case cmFUNC_STR: mu::console() << _T("FUNC_STR\n"); break; - case cmEND: mu::console() << _T("END\n"); break; - case cmUNKNOWN: mu::console() << _T("UNKNOWN\n"); break; - case cmBO: mu::console() << _T("BRACKET \"(\"\n"); break; - case cmBC: mu::console() << _T("BRACKET \")\"\n"); break; - case cmIF: mu::console() << _T("IF\n"); break; - case cmELSE: mu::console() << _T("ELSE\n"); break; - case cmENDIF: mu::console() << _T("ENDIF\n"); break; - default: mu::console() << stOprt.top().GetCode() << _T(" "); break; - } - } - stOprt.pop(); - } - - mu::console() << dec << endl; - } - - //------------------------------------------------------------------------------ - /** \brief Evaluate an expression containing comma separated subexpressions - \param [out] nStackSize The total number of results available - \return Pointer to the array containing all expression results - - This member function can be used to retrieve all results of an expression - made up of multiple comma separated subexpressions (i.e. "x+y,sin(x),cos(y)") - */ - value_type* ParserBase::Eval(int &nStackSize) const - { - (this->*m_pParseFormula)(); - nStackSize = m_nFinalResultIdx; - - // (for historic reasons the stack starts at position 1) - return &m_vStackBuffer[1]; - } - - //--------------------------------------------------------------------------- - /** \brief Return the number of results on the calculation stack. - - If the expression contains comma separated subexpressions (i.e. "sin(y), x+y"). - There may be more than one return value. This function returns the number of - available results. - */ - int ParserBase::GetNumResults() const - { - return m_nFinalResultIdx; - } - - //--------------------------------------------------------------------------- - /** \brief Calculate the result. - - A note on const correctness: - I consider it important that Calc is a const function. - Due to caching operations Calc changes only the state of internal variables with one exception - m_UsedVar this is reset during string parsing and accessible from the outside. Instead of making - Calc non const GetUsedVar is non const because it explicitly calls Eval() forcing this update. - - \pre A formula must be set. - \pre Variables must have been set (if needed) - - \sa #m_pParseFormula - \return The evaluation result - \throw ParseException if no Formula is set or in case of any other error related to the formula. - */ - value_type ParserBase::Eval() const - { - return (this->*m_pParseFormula)(); - } - - //--------------------------------------------------------------------------- - void ParserBase::Eval(value_type *results, int nBulkSize) - { -/* <ibg 2014-09-24/> 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; - -#ifdef MUP_USE_OPENMP -//#define DEBUG_OMP_STUFF - #ifdef DEBUG_OMP_STUFF - int *pThread = new int[nBulkSize]; - int *pIdx = new int[nBulkSize]; - #endif - - int nMaxThreads = std::min(omp_get_max_threads(), s_MaxNumOpenMPThreads); - int nThreadID = 0, ct = 0; - omp_set_num_threads(nMaxThreads); - - #pragma omp parallel for schedule(static, nBulkSize/nMaxThreads) private(nThreadID) - for (i=0; i<nBulkSize; ++i) - { - nThreadID = omp_get_thread_num(); - results[i] = ParseCmdCodeBulk(i, nThreadID); - - #ifdef DEBUG_OMP_STUFF - #pragma omp critical - { - pThread[ct] = nThreadID; - pIdx[ct] = i; - ct++; - } - #endif - } - -#ifdef DEBUG_OMP_STUFF - FILE *pFile = fopen("bulk_dbg.txt", "w"); - for (i=0; i<nBulkSize; ++i) - { - fprintf(pFile, "idx: %d thread: %d \n", pIdx[i], pThread[i]); - } - - delete [] pIdx; - delete [] pThread; - - fclose(pFile); -#endif - -#else - for (i=0; i<nBulkSize; ++i) - { - results[i] = ParseCmdCodeBulk(i, 0); - } -#endif - - } -} // namespace mu +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParserBase.h" +#include "muParserTemplateMagic.h" + +//--- Standard includes ------------------------------------------------------------------------ +#include <algorithm> +#include <cmath> +#include <memory> +#include <vector> +#include <deque> +#include <sstream> +#include <locale> +#include <cassert> +#include <cctype> + +#ifdef MUP_USE_OPENMP +#include <omp.h> +#endif + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable : 26812) +#endif + +using namespace std; + +/** \file + \brief This file contains the basic implementation of the muparser engine. +*/ + +namespace mu +{ + std::locale ParserBase::s_locale = std::locale(std::locale::classic(), new change_dec_sep<char_type>('.')); + + bool ParserBase::g_DbgDumpCmdCode = false; + bool ParserBase::g_DbgDumpStack = false; + + //------------------------------------------------------------------------------ + /** \brief Identifiers for built in binary operators. + + When defining custom binary operators with #AddOprt(...) make sure not to choose + names conflicting with these definitions. + */ + const char_type* ParserBase::c_DefaultOprt[] = + { + _T("<="), _T(">="), _T("!="), + _T("=="), _T("<"), _T(">"), + _T("+"), _T("-"), _T("*"), + _T("/"), _T("^"), _T("&&"), + _T("||"), _T("="), _T("("), + _T(")"), _T("?"), _T(":"), 0 + }; + + const int ParserBase::s_MaxNumOpenMPThreads = 16; + + //------------------------------------------------------------------------------ + /** \brief Constructor. + \param a_szFormula the formula to interpret. + \throw ParserException if a_szFormula is nullptr. + */ + ParserBase::ParserBase() + : m_pParseFormula(&ParserBase::ParseString) + , m_vRPN() + , m_vStringBuf() + , m_pTokenReader() + , m_FunDef() + , m_PostOprtDef() + , m_InfixOprtDef() + , m_OprtDef() + , m_ConstDef() + , m_StrVarDef() + , m_VarDef() + , m_bBuiltInOp(true) + , m_sNameChars() + , m_sOprtChars() + , m_sInfixOprtChars() + , m_vStackBuffer() + , m_nFinalResultIdx(0) + { + InitTokenReader(); + } + + //--------------------------------------------------------------------------- + /** \brief Copy constructor. + + The parser can be safely copy constructed but the bytecode is reset during + copy construction. + */ + ParserBase::ParserBase(const ParserBase& a_Parser) + : m_pParseFormula(&ParserBase::ParseString) + , m_vRPN() + , m_vStringBuf() + , m_pTokenReader() + , m_FunDef() + , m_PostOprtDef() + , m_InfixOprtDef() + , m_OprtDef() + , m_ConstDef() + , m_StrVarDef() + , m_VarDef() + , m_bBuiltInOp(true) + , m_sNameChars() + , m_sOprtChars() + , m_sInfixOprtChars() + { + m_pTokenReader.reset(new token_reader_type(this)); + Assign(a_Parser); + } + + //--------------------------------------------------------------------------- + ParserBase::~ParserBase() + {} + + //--------------------------------------------------------------------------- + /** \brief Assignment operator. + + Implemented by calling Assign(a_Parser). Self assignment is suppressed. + \param a_Parser Object to copy to this. + \return *this + \throw nothrow + */ + ParserBase& ParserBase::operator=(const ParserBase& a_Parser) + { + Assign(a_Parser); + return *this; + } + + //--------------------------------------------------------------------------- + /** \brief Copy state of a parser object to this. + + Clears Variables and Functions of this parser. + Copies the states of all internal variables. + Resets parse function to string parse mode. + + \param a_Parser the source object. + */ + void ParserBase::Assign(const ParserBase& a_Parser) + { + if (&a_Parser == this) + return; + + // Don't copy bytecode instead cause the parser to create new bytecode + // by resetting the parse function. + ReInit(); + + m_ConstDef = a_Parser.m_ConstDef; // Copy user define constants + m_VarDef = a_Parser.m_VarDef; // Copy user defined variables + m_bBuiltInOp = a_Parser.m_bBuiltInOp; + m_vStringBuf = a_Parser.m_vStringBuf; + m_vStackBuffer = a_Parser.m_vStackBuffer; + m_nFinalResultIdx = a_Parser.m_nFinalResultIdx; + m_StrVarDef = a_Parser.m_StrVarDef; + m_vStringVarBuf = a_Parser.m_vStringVarBuf; + m_pTokenReader.reset(a_Parser.m_pTokenReader->Clone(this)); + + // Copy function and operator callbacks + m_FunDef = a_Parser.m_FunDef; // Copy function definitions + m_PostOprtDef = a_Parser.m_PostOprtDef; // post value unary operators + m_InfixOprtDef = a_Parser.m_InfixOprtDef; // unary operators for infix notation + m_OprtDef = a_Parser.m_OprtDef; // binary operators + + m_sNameChars = a_Parser.m_sNameChars; + m_sOprtChars = a_Parser.m_sOprtChars; + m_sInfixOprtChars = a_Parser.m_sInfixOprtChars; + } + + //--------------------------------------------------------------------------- + /** \brief Set the decimal separator. + \param cDecSep Decimal separator as a character value. + \sa SetThousandsSep + + By default muparser uses the "C" locale. The decimal separator of this + locale is overwritten by the one provided here. + */ + void ParserBase::SetDecSep(char_type cDecSep) + { + char_type cThousandsSep = std::use_facet< change_dec_sep<char_type> >(s_locale).thousands_sep(); + s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>(cDecSep, cThousandsSep)); + } + + //--------------------------------------------------------------------------- + /** \brief Sets the thousands operator. + \param cThousandsSep The thousands separator as a character + \sa SetDecSep + + By default muparser uses the "C" locale. The thousands separator of this + locale is overwritten by the one provided here. + */ + void ParserBase::SetThousandsSep(char_type cThousandsSep) + { + char_type cDecSep = std::use_facet< change_dec_sep<char_type> >(s_locale).decimal_point(); + s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>(cDecSep, cThousandsSep)); + } + + //--------------------------------------------------------------------------- + /** \brief Resets the locale. + + The default locale used "." as decimal separator, no thousands separator and + "," as function argument separator. + */ + void ParserBase::ResetLocale() + { + s_locale = std::locale(std::locale("C"), new change_dec_sep<char_type>('.')); + SetArgSep(','); + } + + //--------------------------------------------------------------------------- + /** \brief Initialize the token reader. + + Create new token reader object and submit pointers to function, operator, + constant and variable definitions. + + \post m_pTokenReader.get()!=0 + \throw nothrow + */ + void ParserBase::InitTokenReader() + { + m_pTokenReader.reset(new token_reader_type(this)); + } + + //--------------------------------------------------------------------------- + /** \brief Reset parser to string parsing mode and clear internal buffers. + + Clear bytecode, reset the token reader. + \throw nothrow + */ + void ParserBase::ReInit() const + { + m_pParseFormula = &ParserBase::ParseString; + m_vStringBuf.clear(); + m_vRPN.clear(); + m_pTokenReader->ReInit(); + } + + //--------------------------------------------------------------------------- + void ParserBase::OnDetectVar(string_type* /*pExpr*/, int& /*nStart*/, int& /*nEnd*/) + {} + + //--------------------------------------------------------------------------- + /** \brief Returns the version of muparser. + \param eInfo A flag indicating whether the full version info should be + returned or not. + + Format is as follows: "MAJOR.MINOR (COMPILER_FLAGS)" The COMPILER_FLAGS + are returned only if eInfo==pviFULL. + */ + string_type ParserBase::GetVersion(EParserVersionInfo eInfo) const + { + stringstream_type ss; + + ss << ParserVersion; + + if (eInfo == pviFULL) + { + ss << _T(" (") << ParserVersionDate; + ss << std::dec << _T("; ") << sizeof(void*) * 8 << _T("BIT"); + +#ifdef _DEBUG + ss << _T("; DEBUG"); +#else + ss << _T("; RELEASE"); +#endif + +#ifdef _UNICODE + ss << _T("; UNICODE"); +#else +#ifdef _MBCS + ss << _T("; MBCS"); +#else + ss << _T("; ASCII"); +#endif +#endif + +#ifdef MUP_USE_OPENMP + ss << _T("; OPENMP"); +#endif + + ss << _T(")"); + } + + return ss.str(); + } + + //--------------------------------------------------------------------------- + /** \brief Add a value parsing function. + + When parsing an expression muParser tries to detect values in the expression + string using different valident callbacks. Thus it's possible to parse + for hex values, binary values and floating point values. + */ + void ParserBase::AddValIdent(identfun_type a_pCallback) + { + m_pTokenReader->AddValIdent(a_pCallback); + } + + //--------------------------------------------------------------------------- + /** \brief Set a function that can create variable pointer for unknown expression variables. + \param a_pFactory A pointer to the variable factory. + \param pUserData A user defined context pointer. + */ + void ParserBase::SetVarFactory(facfun_type a_pFactory, void* pUserData) + { + m_pTokenReader->SetVarCreator(a_pFactory, pUserData); + } + + //--------------------------------------------------------------------------- + /** \brief Add a function or operator callback to the parser. */ + void ParserBase::AddCallback(const string_type& a_strName, + const ParserCallback& a_Callback, + funmap_type& a_Storage, + const char_type* a_szCharSet) + { + if (a_Callback.GetAddr() == 0) + Error(ecINVALID_FUN_PTR); + + const funmap_type* pFunMap = &a_Storage; + + // Check for conflicting operator or function names + if (pFunMap != &m_FunDef && m_FunDef.find(a_strName) != m_FunDef.end()) + Error(ecNAME_CONFLICT, -1, a_strName); + + if (pFunMap != &m_PostOprtDef && m_PostOprtDef.find(a_strName) != m_PostOprtDef.end()) + Error(ecNAME_CONFLICT, -1, a_strName); + + if (pFunMap != &m_InfixOprtDef && pFunMap != &m_OprtDef && m_InfixOprtDef.find(a_strName) != m_InfixOprtDef.end()) + Error(ecNAME_CONFLICT, -1, a_strName); + + if (pFunMap != &m_InfixOprtDef && pFunMap != &m_OprtDef && m_OprtDef.find(a_strName) != m_OprtDef.end()) + Error(ecNAME_CONFLICT, -1, a_strName); + + CheckOprt(a_strName, a_Callback, a_szCharSet); + a_Storage[a_strName] = a_Callback; + ReInit(); + } + + //--------------------------------------------------------------------------- + /** \brief Check if a name contains invalid characters. + + \throw ParserException if the name contains invalid characters. + */ + void ParserBase::CheckOprt(const string_type& a_sName, + const ParserCallback& a_Callback, + const string_type& a_szCharSet) const + { + if (!a_sName.length() || + (a_sName.find_first_not_of(a_szCharSet) != string_type::npos) || + (a_sName[0] >= '0' && a_sName[0] <= '9')) + { + switch (a_Callback.GetCode()) + { + case cmOPRT_POSTFIX: Error(ecINVALID_POSTFIX_IDENT, -1, a_sName); break; + case cmOPRT_INFIX: Error(ecINVALID_INFIX_IDENT, -1, a_sName); break; + default: Error(ecINVALID_NAME, -1, a_sName); + } + } + } + + //--------------------------------------------------------------------------- + /** \brief Check if a name contains invalid characters. + + \throw ParserException if the name contains invalid characters. + */ + void ParserBase::CheckName(const string_type& a_sName, + const string_type& a_szCharSet) const + { + if (!a_sName.length() || + (a_sName.find_first_not_of(a_szCharSet) != string_type::npos) || + (a_sName[0] >= '0' && a_sName[0] <= '9')) + { + Error(ecINVALID_NAME); + } + } + + //--------------------------------------------------------------------------- + /** \brief Set the formula. + \param a_strFormula Formula as string_type + \throw ParserException in case of syntax errors. + + Triggers first time calculation thus the creation of the bytecode and + scanning of used variables. + */ + void ParserBase::SetExpr(const string_type& a_sExpr) + { + if (std::all_of(a_sExpr.begin(), a_sExpr.end(), [](char c) { return !std::isgraph(c); })) + { + Error(ecINVALID_CHARACTERS_FOUND); + } + + // Check locale compatibility + if (m_pTokenReader->GetArgSep() == std::use_facet<numpunct<char_type> >(s_locale).decimal_point()) + Error(ecLOCALE); + + // Check maximum allowed expression length. An arbitrary value small enough so i can debug expressions sent to me + if (a_sExpr.length() >= MaxLenExpression) + Error(ecEXPRESSION_TOO_LONG, 0, a_sExpr); + + m_pTokenReader->SetFormula(a_sExpr + _T(" ")); + ReInit(); + } + + //--------------------------------------------------------------------------- + /** \brief Get the default symbols used for the built in operators. + \sa c_DefaultOprt + */ + const char_type** ParserBase::GetOprtDef() const + { + return (const char_type**)(&c_DefaultOprt[0]); + } + + //--------------------------------------------------------------------------- + /** \brief Define the set of valid characters to be used in names of + functions, variables, constants. + */ + void ParserBase::DefineNameChars(const char_type* a_szCharset) + { + m_sNameChars = a_szCharset; + } + + //--------------------------------------------------------------------------- + /** \brief Define the set of valid characters to be used in names of + binary operators and postfix operators. + */ + void ParserBase::DefineOprtChars(const char_type* a_szCharset) + { + m_sOprtChars = a_szCharset; + } + + //--------------------------------------------------------------------------- + /** \brief Define the set of valid characters to be used in names of + infix operators. + */ + void ParserBase::DefineInfixOprtChars(const char_type* a_szCharset) + { + m_sInfixOprtChars = a_szCharset; + } + + //--------------------------------------------------------------------------- + /** \brief Virtual function that defines the characters allowed in name identifiers. + \sa #ValidOprtChars, #ValidPrefixOprtChars + */ + const char_type* ParserBase::ValidNameChars() const + { + MUP_ASSERT(m_sNameChars.size()); + return m_sNameChars.c_str(); + } + + //--------------------------------------------------------------------------- + /** \brief Virtual function that defines the characters allowed in operator definitions. + \sa #ValidNameChars, #ValidPrefixOprtChars + */ + const char_type* ParserBase::ValidOprtChars() const + { + MUP_ASSERT(m_sOprtChars.size()); + return m_sOprtChars.c_str(); + } + + //--------------------------------------------------------------------------- + /** \brief Virtual function that defines the characters allowed in infix operator definitions. + \sa #ValidNameChars, #ValidOprtChars + */ + const char_type* ParserBase::ValidInfixOprtChars() const + { + MUP_ASSERT(m_sInfixOprtChars.size()); + return m_sInfixOprtChars.c_str(); + } + + //--------------------------------------------------------------------------- + /** \brief Add a user defined operator. + \post Will reset the Parser to string parsing mode. + */ + void ParserBase::DefinePostfixOprt(const string_type& a_sName, fun_type1 a_pFun, bool a_bAllowOpt) + { + if (a_sName.length() > MaxLenIdentifier) + Error(ecIDENTIFIER_TOO_LONG); + + AddCallback(a_sName, ParserCallback(a_pFun, a_bAllowOpt, prPOSTFIX, cmOPRT_POSTFIX), m_PostOprtDef, ValidOprtChars()); + } + + //--------------------------------------------------------------------------- + /** \brief Initialize user defined functions. + + Calls the virtual functions InitFun(), InitConst() and InitOprt(). + */ + void ParserBase::Init() + { + InitCharSets(); + InitFun(); + InitConst(); + InitOprt(); + } + + //--------------------------------------------------------------------------- + /** \brief Add a user defined operator. + \post Will reset the Parser to string parsing mode. + \param [in] a_sName operator Identifier + \param [in] a_pFun Operator callback function + \param [in] a_iPrec Operator Precedence (default=prSIGN) + \param [in] a_bAllowOpt True if operator is volatile (default=false) + \sa EPrec + */ + void ParserBase::DefineInfixOprt(const string_type& a_sName, fun_type1 a_pFun, int a_iPrec, bool a_bAllowOpt) + { + if (a_sName.length() > MaxLenIdentifier) + Error(ecIDENTIFIER_TOO_LONG); + + AddCallback(a_sName, ParserCallback(a_pFun, a_bAllowOpt, a_iPrec, cmOPRT_INFIX), m_InfixOprtDef, ValidInfixOprtChars()); + } + + + //--------------------------------------------------------------------------- + /** \brief Define a binary operator. + \param [in] a_sName The identifier of the operator. + \param [in] a_pFun Pointer to the callback function. + \param [in] a_iPrec Precedence of the operator. + \param [in] a_eAssociativity The associativity of the operator. + \param [in] a_bAllowOpt If this is true the operator may be optimized away. + + Adds a new Binary operator the the parser instance. + */ + void ParserBase::DefineOprt(const string_type& a_sName, fun_type2 a_pFun, unsigned a_iPrec, EOprtAssociativity a_eAssociativity, bool a_bAllowOpt) + { + if (a_sName.length() > MaxLenIdentifier) + Error(ecIDENTIFIER_TOO_LONG); + + // Check for conflicts with built in operator names + for (int i = 0; m_bBuiltInOp && i < cmENDIF; ++i) + { + if (a_sName == string_type(c_DefaultOprt[i])) + { + Error(ecBUILTIN_OVERLOAD, -1, a_sName); + } + } + + AddCallback(a_sName, ParserCallback(a_pFun, a_bAllowOpt, a_iPrec, a_eAssociativity), m_OprtDef, ValidOprtChars()); + } + + //--------------------------------------------------------------------------- + /** \brief Define a new string constant. + \param [in] a_strName The name of the constant. + \param [in] a_strVal the value of the constant. + */ + void ParserBase::DefineStrConst(const string_type& a_strName, const string_type& a_strVal) + { + // Test if a constant with that names already exists + if (m_StrVarDef.find(a_strName) != m_StrVarDef.end()) + Error(ecNAME_CONFLICT); + + CheckName(a_strName, ValidNameChars()); + + 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(); + } + + //--------------------------------------------------------------------------- + /** \brief Add a user defined variable. + \param [in] a_sName the variable name + \param [in] a_pVar A pointer to the variable value. + \post Will reset the Parser to string parsing mode. + \throw ParserException in case the name contains invalid signs or a_pVar is nullptr. + */ + void ParserBase::DefineVar(const string_type& a_sName, value_type* a_pVar) + { + if (a_pVar == 0) + Error(ecINVALID_VAR_PTR); + + if (a_sName.length() > MaxLenIdentifier) + Error(ecIDENTIFIER_TOO_LONG); + + // Test if a constant with that names already exists + if (m_ConstDef.find(a_sName) != m_ConstDef.end()) + Error(ecNAME_CONFLICT); + + CheckName(a_sName, ValidNameChars()); + m_VarDef[a_sName] = a_pVar; + ReInit(); + } + + //--------------------------------------------------------------------------- + /** \brief Add a user defined constant. + \param [in] a_sName The name of the constant. + \param [in] a_fVal the value of the constant. + \post Will reset the Parser to string parsing mode. + \throw ParserException in case the name contains invalid signs. + */ + void ParserBase::DefineConst(const string_type& a_sName, value_type a_fVal) + { + if (a_sName.length() > MaxLenIdentifier) + Error(ecIDENTIFIER_TOO_LONG); + + CheckName(a_sName, ValidNameChars()); + m_ConstDef[a_sName] = a_fVal; + ReInit(); + } + + //--------------------------------------------------------------------------- + /** \brief Get operator priority. + \throw ParserException if a_Oprt is no operator code + */ + int ParserBase::GetOprtPrecedence(const token_type& a_Tok) const + { + switch (a_Tok.GetCode()) + { + // built in operators + case cmEND: return -5; + case cmARG_SEP: return -4; + case cmASSIGN: return -1; + case cmELSE: + case cmIF: return 0; + case cmLAND: return prLAND; + case cmLOR: return prLOR; + case cmLT: + case cmGT: + case cmLE: + case cmGE: + case cmNEQ: + case cmEQ: return prCMP; + case cmADD: + case cmSUB: return prADD_SUB; + case cmMUL: + case cmDIV: return prMUL_DIV; + case cmPOW: return prPOW; + + // user defined binary operators + case cmOPRT_INFIX: + case cmOPRT_BIN: return a_Tok.GetPri(); + default: Error(ecINTERNAL_ERROR, 5); + return 999; + } + } + + //--------------------------------------------------------------------------- + /** \brief Get operator priority. + \throw ParserException if a_Oprt is no operator code + */ + EOprtAssociativity ParserBase::GetOprtAssociativity(const token_type& a_Tok) const + { + switch (a_Tok.GetCode()) + { + case cmASSIGN: + case cmLAND: + case cmLOR: + case cmLT: + case cmGT: + case cmLE: + case cmGE: + case cmNEQ: + case cmEQ: + case cmADD: + case cmSUB: + case cmMUL: + case cmDIV: return oaLEFT; + case cmPOW: return oaRIGHT; + case cmOPRT_BIN: return a_Tok.GetAssociativity(); + default: return oaNONE; + } + } + + //--------------------------------------------------------------------------- + /** \brief Return a map containing the used variables only. */ + const varmap_type& ParserBase::GetUsedVar() const + { + try + { + m_pTokenReader->IgnoreUndefVar(true); + CreateRPN(); // try to create bytecode, but don't use it for any further calculations since it + // may contain references to nonexisting variables. + m_pParseFormula = &ParserBase::ParseString; + m_pTokenReader->IgnoreUndefVar(false); + } + catch (exception_type& /*e*/) + { + // Make sure to stay in string parse mode, don't call ReInit() + // because it deletes the array with the used variables + m_pParseFormula = &ParserBase::ParseString; + m_pTokenReader->IgnoreUndefVar(false); + throw; + } + + return m_pTokenReader->GetUsedVar(); + } + + //--------------------------------------------------------------------------- + /** \brief Return a map containing the used variables only. */ + const varmap_type& ParserBase::GetVar() const + { + return m_VarDef; + } + + //--------------------------------------------------------------------------- + /** \brief Return a map containing all parser constants. */ + const valmap_type& ParserBase::GetConst() const + { + return m_ConstDef; + } + + //--------------------------------------------------------------------------- + /** \brief Return prototypes of all parser functions. + \return #m_FunDef + \sa FunProt + \throw nothrow + + The return type is a map of the public type #funmap_type containing the prototype + definitions for all numerical parser functions. String functions are not part of + this map. The Prototype definition is encapsulated in objects of the class FunProt + one per parser function each associated with function names via a map construct. + */ + const funmap_type& ParserBase::GetFunDef() const + { + return m_FunDef; + } + + //--------------------------------------------------------------------------- + /** \brief Retrieve the formula. */ + const string_type& ParserBase::GetExpr() const + { + return m_pTokenReader->GetExpr(); + } + + //--------------------------------------------------------------------------- + /** \brief Execute a function that takes a single string argument. + \param a_FunTok Function token. + \throw exception_type If the function token is not a string function + */ + ParserBase::token_type ParserBase::ApplyStrFunc(const token_type& a_FunTok, + const std::vector<token_type>& a_vArg) const + { + if (a_vArg.back().GetCode() != cmSTRING) + Error(ecSTRING_EXPECTED, m_pTokenReader->GetPos(), a_FunTok.GetAsString()); + + token_type valTok; + generic_fun_type pFunc = a_FunTok.GetFuncAddr(); + MUP_ASSERT(pFunc); + + try + { + // Check function arguments; write dummy value into valtok to represent the result + switch (a_FunTok.GetArgCount()) + { + case 0: valTok.SetVal(1); a_vArg[0].GetAsString(); break; + case 1: valTok.SetVal(1); a_vArg[1].GetAsString(); a_vArg[0].GetVal(); break; + case 2: valTok.SetVal(1); a_vArg[2].GetAsString(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break; + case 3: valTok.SetVal(1); a_vArg[3].GetAsString(); a_vArg[2].GetVal(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break; + case 4: valTok.SetVal(1); a_vArg[4].GetAsString(); a_vArg[3].GetVal(); a_vArg[2].GetVal(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break; + default: Error(ecINTERNAL_ERROR); + } + } + catch (ParserError&) + { + Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), a_FunTok.GetAsString()); + } + + // string functions won't be optimized + m_vRPN.AddStrFun(pFunc, a_FunTok.GetArgCount(), a_vArg.back().GetIdx()); + + // Push dummy value representing the function result to the stack + return valTok; + } + + //--------------------------------------------------------------------------- + /** \brief Apply a function token. + \param iArgCount Number of Arguments actually gathered used only for multiarg functions. + \post The result is pushed to the value stack + \post The function token is removed from the stack + \throw exception_type if Argument count does not match function requirements. + */ + void ParserBase::ApplyFunc(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal, int a_iArgCount) const + { + MUP_ASSERT(m_pTokenReader.get()); + + // Operator stack empty or does not contain tokens with callback functions + if (a_stOpt.empty() || a_stOpt.top().GetFuncAddr() == 0) + return; + + token_type funTok = a_stOpt.top(); + a_stOpt.pop(); + MUP_ASSERT(funTok.GetFuncAddr() != nullptr); + + // Binary operators must rely on their internal operator number + // since counting of operators relies on commas for function arguments + // binary operators do not have commas in their expression + int iArgCount = (funTok.GetCode() == cmOPRT_BIN) ? funTok.GetArgCount() : a_iArgCount; + + // determine how many parameters the function needs. To remember iArgCount includes the + // string parameter whilst GetArgCount() counts only numeric parameters. + int iArgRequired = funTok.GetArgCount() + ((funTok.GetType() == tpSTR) ? 1 : 0); + + // That's the number of numerical parameters + int iArgNumerical = iArgCount - ((funTok.GetType() == tpSTR) ? 1 : 0); + + if (funTok.GetCode() == cmFUNC_STR && iArgCount - iArgNumerical > 1) + Error(ecINTERNAL_ERROR); + + if (funTok.GetArgCount() >= 0 && iArgCount > iArgRequired) + Error(ecTOO_MANY_PARAMS, m_pTokenReader->GetPos() - 1, funTok.GetAsString()); + + if (funTok.GetCode() != cmOPRT_BIN && iArgCount < iArgRequired) + Error(ecTOO_FEW_PARAMS, m_pTokenReader->GetPos() - 1, funTok.GetAsString()); + + if (funTok.GetCode() == cmFUNC_STR && iArgCount > iArgRequired) + Error(ecTOO_MANY_PARAMS, m_pTokenReader->GetPos() - 1, funTok.GetAsString()); + + // Collect the numeric function arguments from the value stack and store them + // in a vector + std::vector<token_type> stArg; + for (int i = 0; i < iArgNumerical; ++i) + { + if (a_stVal.empty()) + Error(ecINTERNAL_ERROR, m_pTokenReader->GetPos(), funTok.GetAsString()); + + stArg.push_back(a_stVal.top()); + a_stVal.pop(); + + if (stArg.back().GetType() == tpSTR && funTok.GetType() != tpSTR) + Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), funTok.GetAsString()); + } + + switch (funTok.GetCode()) + { + case cmFUNC_STR: + if (a_stVal.empty()) + Error(ecINTERNAL_ERROR, m_pTokenReader->GetPos(), funTok.GetAsString()); + + stArg.push_back(a_stVal.top()); + a_stVal.pop(); + + if (stArg.back().GetType() == tpSTR && funTok.GetType() != tpSTR) + Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), funTok.GetAsString()); + + ApplyStrFunc(funTok, stArg); + break; + + case cmFUNC_BULK: + m_vRPN.AddBulkFun(funTok.GetFuncAddr(), (int)stArg.size()); + break; + + case cmOPRT_BIN: + case cmOPRT_POSTFIX: + case cmOPRT_INFIX: + case cmFUNC: + if (funTok.GetArgCount() == -1 && iArgCount == 0) + Error(ecTOO_FEW_PARAMS, m_pTokenReader->GetPos(), funTok.GetAsString()); + + m_vRPN.AddFun(funTok.GetFuncAddr(), (funTok.GetArgCount() == -1) ? -iArgNumerical : iArgNumerical); + break; + default: + break; + } + + // Push dummy value representing the function result to the stack + token_type token; + token.SetVal(1); + a_stVal.push(token); + } + + //--------------------------------------------------------------------------- + void ParserBase::ApplyIfElse(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal) const + { + // Check if there is an if Else clause to be calculated + while (a_stOpt.size() && a_stOpt.top().GetCode() == cmELSE) + { + MUP_ASSERT(!a_stOpt.empty()) + token_type opElse = a_stOpt.top(); + a_stOpt.pop(); + + // Take the value associated with the else branch from the value stack + MUP_ASSERT(!a_stVal.empty()); + token_type vVal2 = a_stVal.top(); + a_stVal.pop(); + + // it then else is a ternary operator Pop all three values from the value s + // tack and just return the right value + MUP_ASSERT(!a_stVal.empty()); + token_type vVal1 = a_stVal.top(); + a_stVal.pop(); + + MUP_ASSERT(!a_stVal.empty()); + token_type vExpr = a_stVal.top(); + a_stVal.pop(); + + a_stVal.push((vExpr.GetVal() != 0) ? vVal1 : vVal2); + + token_type opIf = a_stOpt.top(); + a_stOpt.pop(); + + MUP_ASSERT(opElse.GetCode() == cmELSE); + + if (opIf.GetCode() != cmIF) + Error(ecMISPLACED_COLON, m_pTokenReader->GetPos()); + + m_vRPN.AddIfElse(cmENDIF); + } // while pending if-else-clause found + } + + //--------------------------------------------------------------------------- + /** \brief Performs the necessary steps to write code for + the execution of binary operators into the bytecode. + */ + void ParserBase::ApplyBinOprt(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal) const + { + // is it a user defined binary operator? + if (a_stOpt.top().GetCode() == cmOPRT_BIN) + { + ApplyFunc(a_stOpt, a_stVal, 2); + } + else + { + if (a_stVal.size() < 2) + Error(ecINTERNAL_ERROR, m_pTokenReader->GetPos(), _T("ApplyBinOprt: not enough values in value stack!")); + + token_type valTok1 = a_stVal.top(); + a_stVal.pop(); + + token_type valTok2 = a_stVal.top(); + a_stVal.pop(); + + token_type optTok = a_stOpt.top(); + a_stOpt.pop(); + + token_type resTok; + + if (valTok1.GetType() != valTok2.GetType() || + (valTok1.GetType() == tpSTR && valTok2.GetType() == tpSTR)) + Error(ecOPRT_TYPE_CONFLICT, m_pTokenReader->GetPos(), optTok.GetAsString()); + + if (optTok.GetCode() == cmASSIGN) + { + if (valTok2.GetCode() != cmVAR) + Error(ecUNEXPECTED_OPERATOR, -1, _T("=")); + + m_vRPN.AddAssignOp(valTok2.GetVar()); + } + else + m_vRPN.AddOp(optTok.GetCode()); + + resTok.SetVal(1); + a_stVal.push(resTok); + } + } + + //--------------------------------------------------------------------------- + /** \brief Apply a binary operator. + \param a_stOpt The operator stack + \param a_stVal The value stack + */ + void ParserBase::ApplyRemainingOprt(std::stack<token_type>& stOpt, std::stack<token_type>& stVal) const + { + while (stOpt.size() && + stOpt.top().GetCode() != cmBO && + stOpt.top().GetCode() != cmIF) + { + token_type tok = stOpt.top(); + switch (tok.GetCode()) + { + case cmOPRT_INFIX: + case cmOPRT_BIN: + case cmLE: + case cmGE: + case cmNEQ: + case cmEQ: + case cmLT: + case cmGT: + case cmADD: + case cmSUB: + case cmMUL: + case cmDIV: + case cmPOW: + case cmLAND: + case cmLOR: + case cmASSIGN: + if (stOpt.top().GetCode() == cmOPRT_INFIX) + ApplyFunc(stOpt, stVal, 1); + else + ApplyBinOprt(stOpt, stVal); + break; + + case cmELSE: + ApplyIfElse(stOpt, stVal); + break; + + default: + Error(ecINTERNAL_ERROR); + } + } + } + + //--------------------------------------------------------------------------- + /** \brief Parse the command code. + \sa ParseString(...) + + Command code contains precalculated stack positions of the values and the + associated operators. The Stack is filled beginning from index one the + value at index zero is not used at all. + */ + value_type ParserBase::ParseCmdCode() const + { + return ParseCmdCodeBulk(0, 0); + } + + value_type ParserBase::ParseCmdCodeShort() const + { + const SToken *const tok = m_vRPN.GetBase(); + value_type buf; + + switch (tok->Cmd) + { + case cmVAL: + return tok->Val.data2; + + case cmVAR: + return *tok->Val.ptr; + + case cmVARMUL: + return *tok->Val.ptr * tok->Val.data + tok->Val.data2; + + case cmVARPOW2: + buf = *(tok->Val.ptr); + return buf * buf; + + case cmVARPOW3: + buf = *(tok->Val.ptr); + return buf * buf * buf; + + case cmVARPOW4: + buf = *(tok->Val.ptr); + return buf * buf * buf * buf; + + // numerical function without any argument + case cmFUNC: + return (*(fun_type0)tok->Fun.ptr)(); + + // String function without a numerical argument + case cmFUNC_STR: + return (*(strfun_type1)tok->Fun.ptr)(m_vStringBuf[0].c_str()); + + default: + throw ParserError(ecINTERNAL_ERROR); + } + } + + //--------------------------------------------------------------------------- + /** \brief Evaluate the RPN. + \param nOffset The offset added to variable addresses (for bulk mode) + \param nThreadID OpenMP Thread id of the calling thread + */ + value_type ParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const + { + assert(nThreadID <= s_MaxNumOpenMPThreads); + + // Note: The check for nOffset==0 and nThreadID here is not necessary but + // brings a minor performance gain when not in bulk mode. + value_type* Stack = ((nOffset == 0) && (nThreadID == 0)) ? &m_vStackBuffer[0] : &m_vStackBuffer[nThreadID * (m_vStackBuffer.size() / s_MaxNumOpenMPThreads)]; + value_type buf; + int sidx(0); + for (const SToken* pTok = m_vRPN.GetBase(); pTok->Cmd != cmEND; ++pTok) + { + switch (pTok->Cmd) + { + // built in binary operators + case cmLE: --sidx; Stack[sidx] = Stack[sidx] <= Stack[sidx + 1]; continue; + case cmGE: --sidx; Stack[sidx] = Stack[sidx] >= Stack[sidx + 1]; continue; + case cmNEQ: --sidx; Stack[sidx] = Stack[sidx] != Stack[sidx + 1]; continue; + case cmEQ: --sidx; Stack[sidx] = Stack[sidx] == Stack[sidx + 1]; continue; + case cmLT: --sidx; Stack[sidx] = Stack[sidx] < Stack[sidx + 1]; continue; + case cmGT: --sidx; Stack[sidx] = Stack[sidx] > Stack[sidx + 1]; continue; + case cmADD: --sidx; Stack[sidx] += Stack[1 + sidx]; continue; + case cmSUB: --sidx; Stack[sidx] -= Stack[1 + sidx]; continue; + case cmMUL: --sidx; Stack[sidx] *= Stack[1 + sidx]; continue; + case cmDIV: --sidx; + Stack[sidx] /= Stack[1 + sidx]; + continue; + + case cmPOW: + --sidx; Stack[sidx] = MathImpl<value_type>::Pow(Stack[sidx], Stack[1 + sidx]); + continue; + + case cmLAND: --sidx; Stack[sidx] = Stack[sidx] && Stack[sidx + 1]; continue; + case cmLOR: --sidx; Stack[sidx] = Stack[sidx] || Stack[sidx + 1]; continue; + + case cmASSIGN: + // 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 cmIF: + if (Stack[sidx--] == 0) + { + MUP_ASSERT(sidx >= 0); + pTok += pTok->Oprt.offset; + } + continue; + + case cmELSE: + pTok += pTok->Oprt.offset; + continue; + + case cmENDIF: + continue; + + // value and variable tokens + case cmVAR: Stack[++sidx] = *(pTok->Val.ptr + nOffset); continue; + case cmVAL: Stack[++sidx] = pTok->Val.data2; continue; + + case cmVARPOW2: buf = *(pTok->Val.ptr + nOffset); + Stack[++sidx] = buf * buf; + continue; + + case cmVARPOW3: buf = *(pTok->Val.ptr + nOffset); + Stack[++sidx] = buf * buf * buf; + continue; + + case cmVARPOW4: buf = *(pTok->Val.ptr + nOffset); + Stack[++sidx] = buf * buf * buf * buf; + continue; + + 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->Fun.argc; + + // switch according to argument count + switch (iArgCount) + { + 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: + // function with variable arguments store the number as a negative value + if (iArgCount > 0) + Error(ecINTERNAL_ERROR, -1); + + sidx -= -iArgCount - 1; + + // <ibg 2020-06-08/> From oss-fuzz. Happend when Multiarg functions and if-then-else are used incorrectly "sum(0?1,2,3,4,5:6)" + // The final result normally lieas at position 1. If sixd is smaller there is something wrong. + if (sidx <= 0) + Error(ecINTERNAL_ERROR, -1); + + Stack[sidx] = (*(multfun_type)pTok->Fun.ptr)(&Stack[sidx], -iArgCount); + continue; + } + } + + // Next is treatment of string functions + case cmFUNC_STR: + { + sidx -= pTok->Fun.argc - 1; + + // The index of the string argument in the string table + int iIdxStack = pTok->Fun.idx; + if (iIdxStack < 0 || iIdxStack >= (int)m_vStringBuf.size()) + Error(ecINTERNAL_ERROR, m_pTokenReader->GetPos()); + + switch (pTok->Fun.argc) // switch according to argument count + { + 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; + case 3: Stack[sidx] = (*(strfun_type4)pTok->Fun.ptr)(m_vStringBuf[iIdxStack].c_str(), Stack[sidx], Stack[sidx + 1], Stack[sidx + 2]); continue; + case 4: Stack[sidx] = (*(strfun_type5)pTok->Fun.ptr)(m_vStringBuf[iIdxStack].c_str(), Stack[sidx], Stack[sidx + 1], Stack[sidx + 2], Stack[sidx + 3]); continue; + } + + continue; + } + + case cmFUNC_BULK: + { + int iArgCount = pTok->Fun.argc; + + // switch according to argument count + switch (iArgCount) + { + 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; + } + } + + default: + Error(ecINTERNAL_ERROR, 3); + return 0; + } // switch CmdCode + } // for all bytecode tokens + + return Stack[m_nFinalResultIdx]; + } + + //--------------------------------------------------------------------------- + void ParserBase::CreateRPN() const + { + if (!m_pTokenReader->GetExpr().length()) + Error(ecUNEXPECTED_EOF, 0); + + std::stack<token_type> stOpt, stVal; + std::stack<int> stArgCount; + token_type opta, opt; // for storing operators + token_type val, tval; // for storing value + int ifElseCounter = 0; + + ReInit(); + + // The outermost counter counts the number of separated items + // such as in "a=10,b=20,c=c+a" + stArgCount.push(1); + + for (;;) + { + opt = m_pTokenReader->ReadNextToken(); + + switch (opt.GetCode()) + { + // + // Next three are different kind of value entries + // + case cmSTRING: + if (stOpt.empty()) + Error(ecSTR_RESULT, m_pTokenReader->GetPos(), opt.GetAsString()); + + opt.SetIdx((int)m_vStringBuf.size()); // Assign buffer index to token + stVal.push(opt); + m_vStringBuf.push_back(opt.GetAsString()); // Store string in internal buffer + break; + + case cmVAR: + stVal.push(opt); + m_vRPN.AddVar(static_cast<value_type*>(opt.GetVar())); + break; + + case cmVAL: + stVal.push(opt); + m_vRPN.AddVal(opt.GetVal()); + break; + + case cmELSE: + if (stArgCount.empty()) + Error(ecMISPLACED_COLON, m_pTokenReader->GetPos()); + + if (stArgCount.top() > 1) + Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); + + stArgCount.pop(); + + ifElseCounter--; + if (ifElseCounter < 0) + Error(ecMISPLACED_COLON, m_pTokenReader->GetPos()); + + ApplyRemainingOprt(stOpt, stVal); + m_vRPN.AddIfElse(cmELSE); + stOpt.push(opt); + break; + + case cmARG_SEP: + if (!stOpt.empty() && stOpt.top().GetCode() == cmIF) + Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); + + if (stArgCount.empty()) + Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); + + ++stArgCount.top(); + // Falls through. + // intentional (no break!) + + case cmEND: + ApplyRemainingOprt(stOpt, stVal); + break; + + case cmBC: + { + // The argument count for parameterless functions is zero + // by default an opening bracket sets parameter count to 1 + // in preparation of arguments to come. If the last token + // was an opening bracket we know better... + if (opta.GetCode() == cmBO) + --stArgCount.top(); + + ApplyRemainingOprt(stOpt, stVal); + + // Check if the bracket content has been evaluated completely + if (stOpt.size() && stOpt.top().GetCode() == cmBO) + { + // if opt is ")" and opta is "(" the bracket has been evaluated, now its time to check + // if there is either a function or a sign pending + // neither the opening nor the closing bracket will be pushed back to + // the operator stack + // Check if a function is standing in front of the opening bracket, + // if yes evaluate it afterwards check for infix operators + MUP_ASSERT(stArgCount.size()); + int iArgCount = stArgCount.top(); + stArgCount.pop(); + + stOpt.pop(); // Take opening bracket from stack + + if (iArgCount > 1 && (stOpt.size() == 0 || + (stOpt.top().GetCode() != cmFUNC && + stOpt.top().GetCode() != cmFUNC_BULK && + stOpt.top().GetCode() != cmFUNC_STR))) + Error(ecUNEXPECTED_ARG, m_pTokenReader->GetPos()); + + // The opening bracket was popped from the stack now check if there + // was a function before this bracket + if (stOpt.size() && + stOpt.top().GetCode() != cmOPRT_INFIX && + stOpt.top().GetCode() != cmOPRT_BIN && + stOpt.top().GetFuncAddr() != 0) + { + ApplyFunc(stOpt, stVal, iArgCount); + } + } + } // if bracket content is evaluated + break; + + // + // Next are the binary operator entries + // + case cmIF: + ifElseCounter++; + stArgCount.push(1); + // Falls through. + // intentional (no break!) + + case cmLAND: + case cmLOR: + case cmLT: + case cmGT: + case cmLE: + case cmGE: + case cmNEQ: + case cmEQ: + case cmADD: + case cmSUB: + case cmMUL: + case cmDIV: + case cmPOW: + case cmASSIGN: + case cmOPRT_BIN: + + // A binary operator (user defined or built in) has been found. + while ( + stOpt.size() && + stOpt.top().GetCode() != cmBO && + stOpt.top().GetCode() != cmELSE && + stOpt.top().GetCode() != cmIF) + { + int nPrec1 = GetOprtPrecedence(stOpt.top()), + nPrec2 = GetOprtPrecedence(opt); + + if (stOpt.top().GetCode() == opt.GetCode()) + { + + // Deal with operator associativity + EOprtAssociativity eOprtAsct = GetOprtAssociativity(opt); + if ((eOprtAsct == oaRIGHT && (nPrec1 <= nPrec2)) || + (eOprtAsct == oaLEFT && (nPrec1 < nPrec2))) + { + break; + } + } + else if (nPrec1 < nPrec2) + { + // In case the operators are not equal the precedence decides alone... + break; + } + + if (stOpt.top().GetCode() == cmOPRT_INFIX) + ApplyFunc(stOpt, stVal, 1); + else + ApplyBinOprt(stOpt, stVal); + } // while ( ... ) + + if (opt.GetCode() == cmIF) + m_vRPN.AddIfElse(opt.GetCode()); + + // The operator can't be evaluated right now, push back to the operator stack + stOpt.push(opt); + break; + + // + // Last section contains functions and operators implicitly mapped to functions + // + case cmBO: + stArgCount.push(1); + stOpt.push(opt); + break; + + case cmOPRT_INFIX: + case cmFUNC: + case cmFUNC_BULK: + case cmFUNC_STR: + stOpt.push(opt); + break; + + case cmOPRT_POSTFIX: + stOpt.push(opt); + ApplyFunc(stOpt, stVal, 1); // this is the postfix operator + break; + + default: Error(ecINTERNAL_ERROR, 3); + } // end of switch operator-token + + opta = opt; + + if (opt.GetCode() == cmEND) + { + m_vRPN.Finalize(); + break; + } + + if (ParserBase::g_DbgDumpStack) + { + StackDump(stVal, stOpt); + m_vRPN.AsciiDump(); + } + +// if (ParserBase::g_DbgDumpCmdCode) + //m_vRPN.AsciiDump(); + } // while (true) + + if (ParserBase::g_DbgDumpCmdCode) + m_vRPN.AsciiDump(); + + if (ifElseCounter > 0) + Error(ecMISSING_ELSE_CLAUSE); + + // get the last value (= final result) from the stack + MUP_ASSERT(stArgCount.size() == 1); + m_nFinalResultIdx = stArgCount.top(); + if (m_nFinalResultIdx == 0) + Error(ecINTERNAL_ERROR, 9); + + if (stVal.size() == 0) + Error(ecEMPTY_EXPRESSION); + + if (stVal.top().GetType() != tpDBL) + Error(ecSTR_RESULT); + + m_vStackBuffer.resize(m_vRPN.GetMaxStackSize() * s_MaxNumOpenMPThreads); + } + + //--------------------------------------------------------------------------- + /** \brief One of the two main parse functions. + \sa ParseCmdCode(...) + + Parse expression from input string. Perform syntax checking and create + bytecode. After parsing the string and creating the bytecode the function + pointer #m_pParseFormula will be changed to the second parse routine the + uses bytecode instead of string parsing. + */ + value_type ParserBase::ParseString() const + { + try + { + CreateRPN(); + + if (m_vRPN.GetSize() == 2) + { + m_pParseFormula = &ParserBase::ParseCmdCodeShort; + } + else + { + m_pParseFormula = &ParserBase::ParseCmdCode; + } + + return (this->*m_pParseFormula)(); + } + catch (ParserError& exc) + { + exc.SetFormula(m_pTokenReader->GetExpr()); + throw; + } + } + + //--------------------------------------------------------------------------- + /** \brief Create an error containing the parse error position. + + This function will create an Parser Exception object containing the error text and + its position. + + \param a_iErrc [in] The error code of type #EErrorCodes. + \param a_iPos [in] The position where the error was detected. + \param a_strTok [in] The token string representation associated with the error. + \throw ParserException always throws that's the only purpose of this function. + */ + void ParserBase::Error(EErrorCodes a_iErrc, int a_iPos, const string_type& a_sTok) const + { + throw exception_type(a_iErrc, a_sTok, m_pTokenReader->GetExpr(), a_iPos); + } + + //------------------------------------------------------------------------------ + /** \brief Clear all user defined variables. + \throw nothrow + + Resets the parser to string parsing mode by calling #ReInit. + */ + void ParserBase::ClearVar() + { + m_VarDef.clear(); + ReInit(); + } + + //------------------------------------------------------------------------------ + /** \brief Remove a variable from internal storage. + \throw nothrow + + Removes a variable if it exists. If the Variable does not exist nothing will be done. + */ + void ParserBase::RemoveVar(const string_type& a_strVarName) + { + varmap_type::iterator item = m_VarDef.find(a_strVarName); + if (item != m_VarDef.end()) + { + m_VarDef.erase(item); + ReInit(); + } + } + + //------------------------------------------------------------------------------ + /** \brief Clear all functions. + \post Resets the parser to string parsing mode. + \throw nothrow + */ + void ParserBase::ClearFun() + { + m_FunDef.clear(); + ReInit(); + } + + //------------------------------------------------------------------------------ + /** \brief Clear all user defined constants. + + Both numeric and string constants will be removed from the internal storage. + \post Resets the parser to string parsing mode. + \throw nothrow + */ + void ParserBase::ClearConst() + { + m_ConstDef.clear(); + m_StrVarDef.clear(); + ReInit(); + } + + //------------------------------------------------------------------------------ + /** \brief Clear all user defined postfix operators. + \post Resets the parser to string parsing mode. + \throw nothrow + */ + void ParserBase::ClearPostfixOprt() + { + m_PostOprtDef.clear(); + ReInit(); + } + + //------------------------------------------------------------------------------ + /** \brief Clear all user defined binary operators. + \post Resets the parser to string parsing mode. + \throw nothrow + */ + void ParserBase::ClearOprt() + { + m_OprtDef.clear(); + ReInit(); + } + + //------------------------------------------------------------------------------ + /** \brief Clear the user defined Prefix operators. + \post Resets the parser to string parser mode. + \throw nothrow + */ + void ParserBase::ClearInfixOprt() + { + m_InfixOprtDef.clear(); + ReInit(); + } + + //------------------------------------------------------------------------------ + /** \brief Enable or disable the formula optimization feature. + \post Resets the parser to string parser mode. + \throw nothrow + */ + void ParserBase::EnableOptimizer(bool a_bIsOn) + { + m_vRPN.EnableOptimizer(a_bIsOn); + ReInit(); + } + + //--------------------------------------------------------------------------- + /** \brief Enable the dumping of bytecode and stack content on the console. + \param bDumpCmd Flag to enable dumping of the current bytecode to the console. + \param bDumpStack Flag to enable dumping of the stack content is written to the console. + + This function is for debug purposes only! + */ + void ParserBase::EnableDebugDump(bool bDumpCmd, bool bDumpStack) + { + ParserBase::g_DbgDumpCmdCode = bDumpCmd; + ParserBase::g_DbgDumpStack = bDumpStack; + } + + //------------------------------------------------------------------------------ + /** \brief Enable or disable the built in binary operators. + \throw nothrow + \sa m_bBuiltInOp, ReInit() + + If you disable the built in binary operators there will be no binary operators + defined. Thus you must add them manually one by one. It is not possible to + disable built in operators selectively. This function will Reinitialize the + parser by calling ReInit(). + */ + void ParserBase::EnableBuiltInOprt(bool a_bIsOn) + { + m_bBuiltInOp = a_bIsOn; + ReInit(); + } + + //------------------------------------------------------------------------------ + /** \brief Query status of built in variables. + \return #m_bBuiltInOp; true if built in operators are enabled. + \throw nothrow + */ + bool ParserBase::HasBuiltInOprt() const + { + return m_bBuiltInOp; + } + + //------------------------------------------------------------------------------ + /** \brief Get the argument separator character. + */ + char_type ParserBase::GetArgSep() const + { + return m_pTokenReader->GetArgSep(); + } + + //------------------------------------------------------------------------------ + /** \brief Set argument separator. + \param cArgSep the argument separator character. + */ + void ParserBase::SetArgSep(char_type cArgSep) + { + m_pTokenReader->SetArgSep(cArgSep); + } + + //------------------------------------------------------------------------------ + /** \brief Dump stack content. + + This function is used for debugging only. + */ + void ParserBase::StackDump(const std::stack<token_type>& a_stVal, const std::stack<token_type>& a_stOprt) const + { + std::stack<token_type> stOprt(a_stOprt); + std::stack<token_type> stVal(a_stVal); + + mu::console() << _T("\nValue stack:\n"); + while (!stVal.empty()) + { + token_type val = stVal.top(); + stVal.pop(); + + if (val.GetType() == tpSTR) + mu::console() << _T(" \"") << val.GetAsString() << _T("\" "); + else + mu::console() << _T(" ") << val.GetVal() << _T(" "); + } + mu::console() << "\nOperator stack:\n"; + + while (!stOprt.empty()) + { + if (stOprt.top().GetCode() <= cmASSIGN) + { + mu::console() << _T("OPRT_INTRNL \"") + << ParserBase::c_DefaultOprt[stOprt.top().GetCode()] + << _T("\" \n"); + } + else + { + switch (stOprt.top().GetCode()) + { + case cmVAR: mu::console() << _T("VAR\n"); break; + case cmVAL: mu::console() << _T("VAL\n"); break; + case cmFUNC: + mu::console() + << _T("FUNC \"") + << stOprt.top().GetAsString() + << _T("\"\n"); + break; + + case cmFUNC_BULK: + mu::console() + << _T("FUNC_BULK \"") + << stOprt.top().GetAsString() + << _T("\"\n"); + break; + + case cmOPRT_INFIX: + mu::console() << _T("OPRT_INFIX \"") + << stOprt.top().GetAsString() + << _T("\"\n"); + break; + + case cmOPRT_BIN: + mu::console() << _T("OPRT_BIN \"") + << stOprt.top().GetAsString() + << _T("\"\n"); + break; + + case cmFUNC_STR: mu::console() << _T("FUNC_STR\n"); break; + case cmEND: mu::console() << _T("END\n"); break; + case cmUNKNOWN: mu::console() << _T("UNKNOWN\n"); break; + case cmBO: mu::console() << _T("BRACKET \"(\"\n"); break; + case cmBC: mu::console() << _T("BRACKET \")\"\n"); break; + case cmIF: mu::console() << _T("IF\n"); break; + case cmELSE: mu::console() << _T("ELSE\n"); break; + case cmENDIF: mu::console() << _T("ENDIF\n"); break; + default: mu::console() << stOprt.top().GetCode() << _T(" "); break; + } + } + stOprt.pop(); + } + + mu::console() << dec << endl; + } + + /** \brief Calculate the result. + + A note on const correctness: + I consider it important that Calc is a const function. + Due to caching operations Calc changes only the state of internal variables with one exception + m_UsedVar this is reset during string parsing and accessible from the outside. Instead of making + Calc non const GetUsedVar is non const because it explicitly calls Eval() forcing this update. + + \pre A formula must be set. + \pre Variables must have been set (if needed) + + \sa #m_pParseFormula + \return The evaluation result + \throw ParseException if no Formula is set or in case of any other error related to the formula. + */ + value_type ParserBase::Eval() const + { + return (this->*m_pParseFormula)(); + } + + //------------------------------------------------------------------------------ + /** \brief Evaluate an expression containing comma separated subexpressions + \param [out] nStackSize The total number of results available + \return Pointer to the array containing all expression results + + This member function can be used to retrieve all results of an expression + made up of multiple comma separated subexpressions (i.e. "x+y,sin(x),cos(y)") + */ + value_type* ParserBase::Eval(int& nStackSize) const + { + if (m_vRPN.GetSize() > 0) + { + ParseCmdCode(); + } + else + { + ParseString(); + } + + nStackSize = m_nFinalResultIdx; + + // (for historic reasons the stack starts at position 1) + return &m_vStackBuffer[1]; + } + + //--------------------------------------------------------------------------- + /** \brief Return the number of results on the calculation stack. + + If the expression contains comma separated subexpressions (i.e. "sin(y), x+y"). + There may be more than one return value. This function returns the number of + available results. + */ + int ParserBase::GetNumResults() const + { + return m_nFinalResultIdx; + } + + //--------------------------------------------------------------------------- + void ParserBase::Eval(value_type* results, int nBulkSize) + { + CreateRPN(); + + int i = 0; + +#ifdef MUP_USE_OPENMP + //#define DEBUG_OMP_STUFF +#ifdef DEBUG_OMP_STUFF + int* pThread = new int[nBulkSize]; + int* pIdx = new int[nBulkSize]; +#endif + + int nMaxThreads = std::min(omp_get_max_threads(), s_MaxNumOpenMPThreads); + int nThreadID = 0; + +#ifdef DEBUG_OMP_STUFF + int ct = 0; +#endif + omp_set_num_threads(nMaxThreads); + +#pragma omp parallel for schedule(static, std::max(nBulkSize/nMaxThreads, 1)) private(nThreadID) + for (i = 0; i < nBulkSize; ++i) + { + nThreadID = omp_get_thread_num(); + results[i] = ParseCmdCodeBulk(i, nThreadID); + +#ifdef DEBUG_OMP_STUFF +#pragma omp critical + { + pThread[ct] = nThreadID; + pIdx[ct] = i; + ct++; + } +#endif + } + +#ifdef DEBUG_OMP_STUFF + FILE* pFile = fopen("bulk_dbg.txt", "w"); + for (i = 0; i < nBulkSize; ++i) + { + fprintf(pFile, "idx: %d thread: %d \n", pIdx[i], pThread[i]); + } + + delete[] pIdx; + delete[] pThread; + + fclose(pFile); +#endif + +#else + for (i = 0; i < nBulkSize; ++i) + { + results[i] = ParseCmdCodeBulk(i, 0); + } +#endif + + } +} // namespace mu + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif + diff --git a/3rdParty/MuParser/src/muParserBytecode.cpp b/3rdParty/MuParser/src/muParserBytecode.cpp index 3964998fdd27fa6a4484b3900b16e589298dfa54..ebc603a66ff817bb512e2fc6f80b7a2449743fbc 100644 --- a/3rdParty/MuParser/src/muParserBytecode.cpp +++ b/3rdParty/MuParser/src/muParserBytecode.cpp @@ -1,588 +1,632 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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. -*/ - -#include "muParserBytecode.h" - -#include <algorithm> -#include <cassert> -#include <string> -#include <stack> -#include <vector> -#include <iostream> - -#include "muParserDef.h" -#include "muParserError.h" -#include "muParserToken.h" -#include "muParserStack.h" -#include "muParserTemplateMagic.h" - - -namespace mu -{ - //--------------------------------------------------------------------------- - /** \brief Bytecode default constructor. */ - ParserByteCode::ParserByteCode() - :m_iStackPos(0) - ,m_iMaxStackSize(0) - ,m_vRPN() - ,m_bEnableOptimizer(true) - { - m_vRPN.reserve(50); - } - - //--------------------------------------------------------------------------- - /** \brief Copy constructor. - - Implemented in Terms of Assign(const ParserByteCode &a_ByteCode) - */ - ParserByteCode::ParserByteCode(const ParserByteCode &a_ByteCode) - { - Assign(a_ByteCode); - } - - //--------------------------------------------------------------------------- - /** \brief Assignment operator. - - Implemented in Terms of Assign(const ParserByteCode &a_ByteCode) - */ - ParserByteCode& ParserByteCode::operator=(const ParserByteCode &a_ByteCode) - { - Assign(a_ByteCode); - return *this; - } - - //--------------------------------------------------------------------------- - void ParserByteCode::EnableOptimizer(bool bStat) - { - m_bEnableOptimizer = bStat; - } - - //--------------------------------------------------------------------------- - /** \brief Copy state of another object to this. - - \throw nowthrow - */ - void ParserByteCode::Assign(const ParserByteCode &a_ByteCode) - { - if (this==&a_ByteCode) - return; - - m_iStackPos = a_ByteCode.m_iStackPos; - m_vRPN = a_ByteCode.m_vRPN; - m_iMaxStackSize = a_ByteCode.m_iMaxStackSize; - m_bEnableOptimizer = a_ByteCode.m_bEnableOptimizer; - } - - //--------------------------------------------------------------------------- - /** \brief Add a Variable pointer to bytecode. - \param a_pVar Pointer to be added. - \throw nothrow - */ - void ParserByteCode::AddVar(value_type *a_pVar) - { - ++m_iStackPos; - m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); - - // optimization does not apply - SToken tok; - tok.Cmd = cmVAR; - tok.Val.ptr = a_pVar; - tok.Val.data = 1; - tok.Val.data2 = 0; - m_vRPN.push_back(tok); - } - - //--------------------------------------------------------------------------- - /** \brief Add a Variable pointer to bytecode. - - Value entries in byte code consist of: - <ul> - <li>value array position of the value</li> - <li>the operator code according to ParserToken::cmVAL</li> - <li>the value stored in #mc_iSizeVal number of bytecode entries.</li> - </ul> - - \param a_pVal Value to be added. - \throw nothrow - */ - void ParserByteCode::AddVal(value_type a_fVal) - { - ++m_iStackPos; - m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); - - // If optimization does not apply - SToken tok; - tok.Cmd = cmVAL; - tok.Val.ptr = NULL; - tok.Val.data = 0; - tok.Val.data2 = a_fVal; - m_vRPN.push_back(tok); - } - - //--------------------------------------------------------------------------- - void ParserByteCode::ConstantFolding(ECmdCode a_Oprt) - { - std::size_t sz = m_vRPN.size(); - 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; - case cmLOR: x = (int)x || (int)y; m_vRPN.pop_back(); break; - case cmLT: x = x < y; m_vRPN.pop_back(); break; - case cmGT: x = x > y; m_vRPN.pop_back(); break; - case cmLE: x = x <= y; m_vRPN.pop_back(); break; - case cmGE: x = x >= y; m_vRPN.pop_back(); break; - case cmNEQ: x = x != y; m_vRPN.pop_back(); break; - case cmEQ: x = x == y; m_vRPN.pop_back(); break; - case cmADD: x = x + y; m_vRPN.pop_back(); break; - case cmSUB: x = x - y; m_vRPN.pop_back(); break; - case cmMUL: x = x * y; m_vRPN.pop_back(); break; - case cmDIV: - -#if defined(MUP_MATH_EXCEPTIONS) - if (y==0) - throw ParserError(ecDIV_BY_ZERO, _T("0")); -#endif - - x = x / y; - m_vRPN.pop_back(); - break; - - case cmPOW: x = MathImpl<value_type>::Pow(x, y); - m_vRPN.pop_back(); - break; - - default: - break; - } // switch opcode - } - - //--------------------------------------------------------------------------- - /** \brief Add an operator identifier to bytecode. - - Operator entries in byte code consist of: - <ul> - <li>value array position of the result</li> - <li>the operator code according to ParserToken::ECmdCode</li> - </ul> - - \sa ParserToken::ECmdCode - */ - void ParserByteCode::AddOp(ECmdCode a_Oprt) - { - bool bOptimized = false; - - if (m_bEnableOptimizer) - { - std::size_t sz = m_vRPN.size(); - - // Check for foldable constants like: - // cmVAL cmVAL cmADD - // where cmADD can stand fopr any binary operator applied to - // two constant values. - if (sz>=2 && m_vRPN[sz-2].Cmd == cmVAL && m_vRPN[sz-1].Cmd == cmVAL) - { - ConstantFolding(a_Oprt); - bOptimized = true; - } - else - { - switch(a_Oprt) - { - case cmPOW: - // Optimization for polynomials of low order - if (m_vRPN[sz-2].Cmd == cmVAR && m_vRPN[sz-1].Cmd == cmVAL) - { - if (m_vRPN[sz-1].Val.data2==2) - m_vRPN[sz-2].Cmd = cmVARPOW2; - else if (m_vRPN[sz-1].Val.data2==3) - m_vRPN[sz-2].Cmd = cmVARPOW3; - else if (m_vRPN[sz-1].Val.data2==4) - m_vRPN[sz-2].Cmd = cmVARPOW4; - else - break; - - m_vRPN.pop_back(); - bOptimized = true; - } - break; - - case cmSUB: - case cmADD: - // Simple optimization based on pattern recognition for a shitload of different - // bytecode combinations of addition/subtraction - if ( (m_vRPN[sz-1].Cmd == cmVAR && m_vRPN[sz-2].Cmd == cmVAL) || - (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].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].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].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; // multiplicand - m_vRPN.pop_back(); - bOptimized = true; - } - break; - - case cmMUL: - if ( (m_vRPN[sz-1].Cmd == cmVAR && m_vRPN[sz-2].Cmd == cmVAL) || - (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVAR) ) - { - m_vRPN[sz-2].Cmd = cmVARMUL; - 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; - } - else if ( (m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVARMUL) || - (m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVAL) ) - { - // Optimization: 2*(3*b+1) or (3*b+1)*2 -> 6*b+2 - m_vRPN[sz-2].Cmd = cmVARMUL; - 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].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].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].Val.ptr == m_vRPN[sz-2].Val.ptr) - { - // Optimization: a*a -> a^2 - m_vRPN[sz-2].Cmd = cmVARPOW2; - m_vRPN.pop_back(); - bOptimized = true; - } - break; - - case cmDIV: - 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].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; - } - break; - - } // switch a_Oprt - } - } - - // If optimization can't be applied just write the value - if (!bOptimized) - { - --m_iStackPos; - SToken tok; - tok.Cmd = a_Oprt; - m_vRPN.push_back(tok); - } - } - - //--------------------------------------------------------------------------- - void ParserByteCode::AddIfElse(ECmdCode a_Oprt) - { - SToken tok; - tok.Cmd = a_Oprt; - m_vRPN.push_back(tok); - } - - //--------------------------------------------------------------------------- - /** \brief Add an assignment operator - - Operator entries in byte code consist of: - <ul> - <li>cmASSIGN code</li> - <li>the pointer of the destination variable</li> - </ul> - - \sa ParserToken::ECmdCode - */ - void ParserByteCode::AddAssignOp(value_type *a_pVar) - { - --m_iStackPos; - - SToken tok; - tok.Cmd = cmASSIGN; - tok.Oprt.ptr = a_pVar; - m_vRPN.push_back(tok); - } - - //--------------------------------------------------------------------------- - /** \brief Add function to bytecode. - - \param a_iArgc Number of arguments, negative numbers indicate multiarg functions. - \param a_pFun Pointer to function callback. - */ - void ParserByteCode::AddFun(generic_fun_type a_pFun, int a_iArgc) - { - if (a_iArgc>=0) - { - m_iStackPos = m_iStackPos - a_iArgc + 1; - } - else - { - // function with unlimited number of arguments - m_iStackPos = m_iStackPos + a_iArgc + 1; - } - m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); - - SToken tok; - tok.Cmd = cmFUNC; - tok.Fun.argc = a_iArgc; - tok.Fun.ptr = a_pFun; - m_vRPN.push_back(tok); - } - - //--------------------------------------------------------------------------- - /** \brief Add a bulk function to bytecode. - - \param a_iArgc Number of arguments, negative numbers indicate multiarg functions. - \param a_pFun Pointer to function callback. - */ - void ParserByteCode::AddBulkFun(generic_fun_type a_pFun, int a_iArgc) - { - m_iStackPos = m_iStackPos - a_iArgc + 1; - m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); - - SToken tok; - tok.Cmd = cmFUNC_BULK; - tok.Fun.argc = a_iArgc; - tok.Fun.ptr = a_pFun; - m_vRPN.push_back(tok); - } - - //--------------------------------------------------------------------------- - /** \brief Add Strung function entry to the parser bytecode. - \throw nothrow - - A string function entry consists of the stack position of the return value, - followed by a cmSTRFUNC code, the function pointer and an index into the - string buffer maintained by the parser. - */ - void ParserByteCode::AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx) - { - m_iStackPos = m_iStackPos - a_iArgc + 1; - - SToken tok; - tok.Cmd = cmFUNC_STR; - 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); - } - - //--------------------------------------------------------------------------- - /** \brief Add end marker to bytecode. - - \throw nothrow - */ - void ParserByteCode::Finalize() - { - SToken tok; - tok.Cmd = cmEND; - m_vRPN.push_back(tok); - rpn_type(m_vRPN).swap(m_vRPN); // shrink bytecode vector to fit - - // Determine the if-then-else jump offsets - ParserStack<int> stIf, stElse; - int idx; - for (int i=0; i<(int)m_vRPN.size(); ++i) - { - switch(m_vRPN[i].Cmd) - { - case cmIF: - stIf.push(i); - break; - - case cmELSE: - stElse.push(i); - idx = stIf.pop(); - m_vRPN[idx].Oprt.offset = i - idx; - break; - - case cmENDIF: - idx = stElse.pop(); - m_vRPN[idx].Oprt.offset = i - idx; - break; - - default: - break; - } - } - } - - //--------------------------------------------------------------------------- - const SToken* ParserByteCode::GetBase() const - { - if (m_vRPN.size()==0) - throw ParserError(ecINTERNAL_ERROR); - else - return &m_vRPN[0]; - } - - //--------------------------------------------------------------------------- - std::size_t ParserByteCode::GetMaxStackSize() const - { - return m_iMaxStackSize+1; - } - - //--------------------------------------------------------------------------- - /** \brief Returns the number of entries in the bytecode. */ - std::size_t ParserByteCode::GetSize() const - { - return m_vRPN.size(); - } - - //--------------------------------------------------------------------------- - /** \brief Delete the bytecode. - - \throw nothrow - - The name of this function is a violation of my own coding guidelines - but this way it's more in line with the STL functions thus more - intuitive. - */ - void ParserByteCode::clear() - { - m_vRPN.clear(); - m_iStackPos = 0; - m_iMaxStackSize = 0; - } - - //--------------------------------------------------------------------------- - /** \brief Dump bytecode (for debugging only!). */ - void ParserByteCode::AsciiDump() - { - if (!m_vRPN.size()) - { - mu::console() << _T("No bytecode available\n"); - return; - } - - mu::console() << _T("Number of RPN tokens:") << (int)m_vRPN.size() << _T("\n"); - for (std::size_t i=0; i<m_vRPN.size() && m_vRPN[i].Cmd!=cmEND; ++i) - { - mu::console() << std::dec << i << _T(" : \t"); - switch (m_vRPN[i].Cmd) - { - case cmVAL: mu::console() << _T("VAL \t"); - 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].Val.ptr << _T("]\n"); - break; - - case cmVARPOW2: mu::console() << _T("VARPOW2 \t"); - 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].Val.ptr << _T("]\n"); - break; - - case cmVARPOW4: mu::console() << _T("VARPOW4 \t"); - 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].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].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].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; - case cmGT: mu::console() << _T("GT\n"); break; - case cmLE: mu::console() << _T("LE\n"); break; - case cmGE: mu::console() << _T("GE\n"); break; - case cmEQ: mu::console() << _T("EQ\n"); break; - case cmNEQ: mu::console() << _T("NEQ\n"); break; - case cmADD: mu::console() << _T("ADD\n"); break; - case cmLAND: mu::console() << _T("&&\n"); break; - case cmLOR: mu::console() << _T("||\n"); break; - case cmSUB: mu::console() << _T("SUB\n"); break; - case cmMUL: mu::console() << _T("MUL\n"); break; - case cmDIV: mu::console() << _T("DIV\n"); break; - case cmPOW: mu::console() << _T("POW\n"); break; - - case cmIF: mu::console() << _T("IF\t"); - 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].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].Oprt.ptr << _T("]\n"); - break; - - default: mu::console() << _T("(unknown code: ") << m_vRPN[i].Cmd << _T(")\n"); - break; - } // switch cmdCode - } // while bytecode - - mu::console() << _T("END") << std::endl; - } -} // namespace mu +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParserBytecode.h" + +#include <algorithm> +#include <string> +#include <stack> +#include <vector> +#include <iostream> + +#include "muParserDef.h" +#include "muParserError.h" +#include "muParserToken.h" +#include "muParserTemplateMagic.h" + + +namespace mu +{ + /** \brief Bytecode default constructor. */ + ParserByteCode::ParserByteCode() + :m_iStackPos(0) + , m_iMaxStackSize(0) + , m_vRPN() + , m_bEnableOptimizer(true) + { + m_vRPN.reserve(50); + } + + + /** \brief Copy constructor. + + Implemented in Terms of Assign(const ParserByteCode &a_ByteCode) + */ + ParserByteCode::ParserByteCode(const ParserByteCode& a_ByteCode) + { + Assign(a_ByteCode); + } + + + /** \brief Assignment operator. + + Implemented in Terms of Assign(const ParserByteCode &a_ByteCode) + */ + ParserByteCode& ParserByteCode::operator=(const ParserByteCode& a_ByteCode) + { + Assign(a_ByteCode); + return *this; + } + + + void ParserByteCode::EnableOptimizer(bool bStat) + { + m_bEnableOptimizer = bStat; + } + + + /** \brief Copy state of another object to this. + + \throw nowthrow + */ + void ParserByteCode::Assign(const ParserByteCode& a_ByteCode) + { + if (this == &a_ByteCode) + return; + + m_iStackPos = a_ByteCode.m_iStackPos; + m_vRPN = a_ByteCode.m_vRPN; + m_iMaxStackSize = a_ByteCode.m_iMaxStackSize; + m_bEnableOptimizer = a_ByteCode.m_bEnableOptimizer; + } + + + /** \brief Add a Variable pointer to bytecode. + \param a_pVar Pointer to be added. + \throw nothrow + */ + void ParserByteCode::AddVar(value_type* a_pVar) + { + ++m_iStackPos; + m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); + + // optimization does not apply + SToken tok; + tok.Cmd = cmVAR; + tok.Val.ptr = a_pVar; + tok.Val.data = 1; + tok.Val.data2 = 0; + m_vRPN.push_back(tok); + } + + + /** \brief Add a Variable pointer to bytecode. + + Value entries in byte code consist of: + <ul> + <li>value array position of the value</li> + <li>the operator code according to ParserToken::cmVAL</li> + <li>the value stored in #mc_iSizeVal number of bytecode entries.</li> + </ul> + + \param a_pVal Value to be added. + \throw nothrow + */ + void ParserByteCode::AddVal(value_type a_fVal) + { + ++m_iStackPos; + m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); + + // If optimization does not apply + SToken tok; + tok.Cmd = cmVAL; + tok.Val.ptr = nullptr; + tok.Val.data = 0; + tok.Val.data2 = a_fVal; + m_vRPN.push_back(tok); + } + + + void ParserByteCode::ConstantFolding(ECmdCode a_Oprt) + { + std::size_t sz = m_vRPN.size(); + value_type& x = m_vRPN[sz - 2].Val.data2; + value_type& y = m_vRPN[sz - 1].Val.data2; + + switch (a_Oprt) + { + case cmLAND: x = (int)x && (int)y; m_vRPN.pop_back(); break; + case cmLOR: x = (int)x || (int)y; m_vRPN.pop_back(); break; + case cmLT: x = x < y; m_vRPN.pop_back(); break; + case cmGT: x = x > y; m_vRPN.pop_back(); break; + case cmLE: x = x <= y; m_vRPN.pop_back(); break; + case cmGE: x = x >= y; m_vRPN.pop_back(); break; + case cmNEQ: x = x != y; m_vRPN.pop_back(); break; + case cmEQ: x = x == y; m_vRPN.pop_back(); break; + case cmADD: x = x + y; m_vRPN.pop_back(); break; + case cmSUB: x = x - y; m_vRPN.pop_back(); break; + case cmMUL: x = x * y; m_vRPN.pop_back(); break; + case cmDIV: + x = x / y; + m_vRPN.pop_back(); + break; + + case cmPOW: x = MathImpl<value_type>::Pow(x, y); + m_vRPN.pop_back(); + break; + + default: + break; + } // switch opcode + } + + + /** \brief Add an operator identifier to bytecode. + + Operator entries in byte code consist of: + <ul> + <li>value array position of the result</li> + <li>the operator code according to ParserToken::ECmdCode</li> + </ul> + + \sa ParserToken::ECmdCode + */ + void ParserByteCode::AddOp(ECmdCode a_Oprt) + { + bool bOptimized = false; + + if (m_bEnableOptimizer) + { + std::size_t sz = m_vRPN.size(); + + // Check for foldable constants like: + // cmVAL cmVAL cmADD + // where cmADD can stand fopr any binary operator applied to + // two constant values. + if (sz >= 2 && m_vRPN[sz - 2].Cmd == cmVAL && m_vRPN[sz - 1].Cmd == cmVAL) + { + ConstantFolding(a_Oprt); + bOptimized = true; + } + else + { + switch (a_Oprt) + { + case cmPOW: + // Optimization for polynomials of low order + if (m_vRPN[sz - 2].Cmd == cmVAR && m_vRPN[sz - 1].Cmd == cmVAL) + { + if (m_vRPN[sz - 1].Val.data2 == 0) + { + m_vRPN[sz - 2].Cmd = cmVAL; + m_vRPN[sz - 2].Val.ptr = nullptr; + m_vRPN[sz - 2].Val.data = 0; + m_vRPN[sz - 2].Val.data2 = 1; + } + else if (m_vRPN[sz - 1].Val.data2 == 1) + m_vRPN[sz - 2].Cmd = cmVAR; + else if (m_vRPN[sz - 1].Val.data2 == 2) + m_vRPN[sz - 2].Cmd = cmVARPOW2; + else if (m_vRPN[sz - 1].Val.data2 == 3) + m_vRPN[sz - 2].Cmd = cmVARPOW3; + else if (m_vRPN[sz - 1].Val.data2 == 4) + m_vRPN[sz - 2].Cmd = cmVARPOW4; + else + break; + + m_vRPN.pop_back(); + bOptimized = true; + } + break; + + case cmSUB: + case cmADD: + // Simple optimization based on pattern recognition for a shitload of different + // bytecode combinations of addition/subtraction + if ((m_vRPN[sz - 1].Cmd == cmVAR && m_vRPN[sz - 2].Cmd == cmVAL) || + (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].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)) + { + MUP_ASSERT( + (m_vRPN[sz - 2].Val.ptr == nullptr && m_vRPN[sz - 1].Val.ptr != nullptr) || + (m_vRPN[sz - 2].Val.ptr != nullptr && m_vRPN[sz - 1].Val.ptr == nullptr) || + (m_vRPN[sz - 2].Val.ptr == m_vRPN[sz - 1].Val.ptr)); + + m_vRPN[sz - 2].Cmd = cmVARMUL; + 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; // multiplicand + m_vRPN.pop_back(); + bOptimized = true; + } + break; + + case cmMUL: + if ((m_vRPN[sz - 1].Cmd == cmVAR && m_vRPN[sz - 2].Cmd == cmVAL) || + (m_vRPN[sz - 1].Cmd == cmVAL && m_vRPN[sz - 2].Cmd == cmVAR)) + { + m_vRPN[sz - 2].Cmd = cmVARMUL; + 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; + } + else if ( + (m_vRPN[sz - 1].Cmd == cmVAL && m_vRPN[sz - 2].Cmd == cmVARMUL) || + (m_vRPN[sz - 1].Cmd == cmVARMUL && m_vRPN[sz - 2].Cmd == cmVAL)) + { + // Optimization: 2*(3*b+1) or (3*b+1)*2 -> 6*b+2 + m_vRPN[sz - 2].Cmd = cmVARMUL; + 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].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].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].Val.ptr == m_vRPN[sz - 2].Val.ptr) + { + // Optimization: a*a -> a^2 + m_vRPN[sz - 2].Cmd = cmVARPOW2; + m_vRPN.pop_back(); + bOptimized = true; + } + break; + + case cmDIV: + 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].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; + } + break; + + // no optimization for other opcodes + default: + break; + } // switch a_Oprt + } + } + + // If optimization can't be applied just write the value + if (!bOptimized) + { + --m_iStackPos; + SToken tok; + tok.Cmd = a_Oprt; + m_vRPN.push_back(tok); + } + } + + + void ParserByteCode::AddIfElse(ECmdCode a_Oprt) + { + SToken tok; + tok.Cmd = a_Oprt; + m_vRPN.push_back(tok); + } + + + /** \brief Add an assignment operator + + Operator entries in byte code consist of: + <ul> + <li>cmASSIGN code</li> + <li>the pointer of the destination variable</li> + </ul> + + \sa ParserToken::ECmdCode + */ + void ParserByteCode::AddAssignOp(value_type* a_pVar) + { + --m_iStackPos; + + SToken tok; + tok.Cmd = cmASSIGN; + tok.Oprt.ptr = a_pVar; + m_vRPN.push_back(tok); + } + + + /** \brief Add function to bytecode. + + \param a_iArgc Number of arguments, negative numbers indicate multiarg functions. + \param a_pFun Pointer to function callback. + */ + void ParserByteCode::AddFun(generic_fun_type a_pFun, int a_iArgc) + { + std::size_t sz = m_vRPN.size(); + bool optimize = false; + + // only optimize functions with fixed number of more than a single arguments + if (m_bEnableOptimizer && a_iArgc > 0) + { + // <ibg 2020-06-10/> Unary Plus is a no-op + if ((void*)a_pFun == (void*)&MathImpl<value_type>::UnaryPlus) + return; + + optimize = true; + + for (int i = 0; i < std::abs(a_iArgc); ++i) + { + if (m_vRPN[sz - i - 1].Cmd != cmVAL) + { + optimize = false; + break; + } + } + } + + if (optimize) + { + value_type val = 0; + switch (a_iArgc) + { + case 1: val = (*reinterpret_cast<fun_type1>(a_pFun))(m_vRPN[sz - 1].Val.data2); break; + case 2: val = (*reinterpret_cast<fun_type2>(a_pFun))(m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 3: val = (*reinterpret_cast<fun_type3>(a_pFun))(m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 4: val = (*reinterpret_cast<fun_type4>(a_pFun))(m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 5: val = (*reinterpret_cast<fun_type5>(a_pFun))(m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 6: val = (*reinterpret_cast<fun_type6>(a_pFun))(m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 7: val = (*reinterpret_cast<fun_type7>(a_pFun))(m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 8: val = (*reinterpret_cast<fun_type8>(a_pFun))(m_vRPN[sz - 8].Val.data2, m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 9: val = (*reinterpret_cast<fun_type9>(a_pFun))(m_vRPN[sz - 9].Val.data2, m_vRPN[sz - 8].Val.data2, m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + case 10: val = (*reinterpret_cast<fun_type10>(a_pFun))(m_vRPN[sz - 10].Val.data2, m_vRPN[sz - 9].Val.data2, m_vRPN[sz - 8].Val.data2, m_vRPN[sz - 7].Val.data2, m_vRPN[sz - 6].Val.data2, m_vRPN[sz - 5].Val.data2, m_vRPN[sz - 4].Val.data2, m_vRPN[sz - 3].Val.data2, m_vRPN[sz - 2].Val.data2, m_vRPN[sz - 1].Val.data2); break; + default: + // For now functions with unlimited number of arguments are not optimized + throw ParserError(ecINTERNAL_ERROR); + } + + // remove the folded values + m_vRPN.erase(m_vRPN.end() - a_iArgc, m_vRPN.end()); + + SToken tok; + tok.Cmd = cmVAL; + tok.Val.data = 0; + tok.Val.data2 = val; + tok.Val.ptr = nullptr; + m_vRPN.push_back(tok); + } + else + { + SToken tok; + tok.Cmd = cmFUNC; + tok.Fun.argc = a_iArgc; + tok.Fun.ptr = a_pFun; + m_vRPN.push_back(tok); + } + + m_iStackPos = m_iStackPos - std::abs(a_iArgc) + 1; + m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); + + } + + + /** \brief Add a bulk function to bytecode. + + \param a_iArgc Number of arguments, negative numbers indicate multiarg functions. + \param a_pFun Pointer to function callback. + */ + void ParserByteCode::AddBulkFun(generic_fun_type a_pFun, int a_iArgc) + { + m_iStackPos = m_iStackPos - a_iArgc + 1; + m_iMaxStackSize = std::max(m_iMaxStackSize, (size_t)m_iStackPos); + + SToken tok; + tok.Cmd = cmFUNC_BULK; + tok.Fun.argc = a_iArgc; + tok.Fun.ptr = a_pFun; + m_vRPN.push_back(tok); + } + + + /** \brief Add Strung function entry to the parser bytecode. + \throw nothrow + + A string function entry consists of the stack position of the return value, + followed by a cmSTRFUNC code, the function pointer and an index into the + string buffer maintained by the parser. + */ + void ParserByteCode::AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx) + { + m_iStackPos = m_iStackPos - a_iArgc + 1; + + SToken tok; + tok.Cmd = cmFUNC_STR; + 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); + } + + + /** \brief Add end marker to bytecode. + + \throw nothrow + */ + void ParserByteCode::Finalize() + { + SToken tok; + tok.Cmd = cmEND; + m_vRPN.push_back(tok); + rpn_type(m_vRPN).swap(m_vRPN); // shrink bytecode vector to fit + + // Determine the if-then-else jump offsets + std::stack<int> stIf, stElse; + int idx; + for (int i = 0; i < (int)m_vRPN.size(); ++i) + { + switch (m_vRPN[i].Cmd) + { + case cmIF: + stIf.push(i); + break; + + case cmELSE: + stElse.push(i); + idx = stIf.top(); + stIf.pop(); + m_vRPN[idx].Oprt.offset = i - idx; + break; + + case cmENDIF: + idx = stElse.top(); + stElse.pop(); + m_vRPN[idx].Oprt.offset = i - idx; + break; + + default: + break; + } + } + } + + + std::size_t ParserByteCode::GetMaxStackSize() const + { + return m_iMaxStackSize + 1; + } + + + /** \brief Delete the bytecode. + + \throw nothrow + + The name of this function is a violation of my own coding guidelines + but this way it's more in line with the STL functions thus more + intuitive. + */ + void ParserByteCode::clear() + { + m_vRPN.clear(); + m_iStackPos = 0; + m_iMaxStackSize = 0; + } + + + /** \brief Dump bytecode (for debugging only!). */ + void ParserByteCode::AsciiDump() + { + if (!m_vRPN.size()) + { + mu::console() << _T("No bytecode available\n"); + return; + } + + mu::console() << _T("Number of RPN tokens:") << (int)m_vRPN.size() << _T("\n"); + for (std::size_t i = 0; i < m_vRPN.size() && m_vRPN[i].Cmd != cmEND; ++i) + { + mu::console() << std::dec << i << _T(" : \t"); + switch (m_vRPN[i].Cmd) + { + case cmVAL: mu::console() << _T("VAL \t"); + 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].Val.ptr << _T("]\n"); + break; + + case cmVARPOW2: mu::console() << _T("VARPOW2 \t"); + 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].Val.ptr << _T("]\n"); + break; + + case cmVARPOW4: mu::console() << _T("VARPOW4 \t"); + 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].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].Fun.argc << _T("]"); + mu::console() << _T("[ADDR: 0x") << std::hex << reinterpret_cast<void*>(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].Fun.argc << _T("]"); + mu::console() << _T("[IDX:") << std::dec << m_vRPN[i].Fun.idx << _T("]"); + mu::console() << _T("[ADDR: 0x") << reinterpret_cast<void*>(m_vRPN[i].Fun.ptr) << _T("]\n"); + break; + + case cmLT: mu::console() << _T("LT\n"); break; + case cmGT: mu::console() << _T("GT\n"); break; + case cmLE: mu::console() << _T("LE\n"); break; + case cmGE: mu::console() << _T("GE\n"); break; + case cmEQ: mu::console() << _T("EQ\n"); break; + case cmNEQ: mu::console() << _T("NEQ\n"); break; + case cmADD: mu::console() << _T("ADD\n"); break; + case cmLAND: mu::console() << _T("&&\n"); break; + case cmLOR: mu::console() << _T("||\n"); break; + case cmSUB: mu::console() << _T("SUB\n"); break; + case cmMUL: mu::console() << _T("MUL\n"); break; + case cmDIV: mu::console() << _T("DIV\n"); break; + case cmPOW: mu::console() << _T("POW\n"); break; + + case cmIF: mu::console() << _T("IF\t"); + 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].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].Oprt.ptr << _T("]\n"); + break; + + default: mu::console() << _T("(unknown code: ") << m_vRPN[i].Cmd << _T(")\n"); + break; + } // switch cmdCode + } // while bytecode + + mu::console() << _T("END") << std::endl; + } +} // namespace mu diff --git a/3rdParty/MuParser/src/muParserCallback.cpp b/3rdParty/MuParser/src/muParserCallback.cpp index 2044fe1c38a543bd3513b6fc24789754a9a45227..1f68a65bc72a141fb4d3f1d524d5b50e335e1a8b 100644 --- a/3rdParty/MuParser/src/muParserCallback.cpp +++ b/3rdParty/MuParser/src/muParserCallback.cpp @@ -1,463 +1,498 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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. -*/ - -#include "muParserCallback.h" - -/** \file - \brief Implementation of the parser callback class. -*/ - - -namespace mu -{ - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type0 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(0) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type1 a_pFun, bool a_bAllowOpti, int a_iPrec, ECmdCode a_iCode) - :m_pFun((void*)a_pFun) - ,m_iArgc(1) - ,m_iPri(a_iPrec) - ,m_eOprtAsct(oaNONE) - ,m_iCode(a_iCode) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - /** \brief Constructor for constructing function callbacks taking two arguments. - \throw nothrow - */ - ParserCallback::ParserCallback(fun_type2 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(2) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - /** \brief Constructor for constructing binary operator callbacks. - \param a_pFun Pointer to a static function taking two arguments - \param a_bAllowOpti A flag indicating this function can be optimized - \param a_iPrec The operator precedence - \param a_eOprtAsct The operators associativity - \throw nothrow - */ - ParserCallback::ParserCallback(fun_type2 a_pFun, - bool a_bAllowOpti, - int a_iPrec, - EOprtAssociativity a_eOprtAsct) - :m_pFun((void*)a_pFun) - ,m_iArgc(2) - ,m_iPri(a_iPrec) - ,m_eOprtAsct(a_eOprtAsct) - ,m_iCode(cmOPRT_BIN) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type3 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(3) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type4 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(4) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type5 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(5) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type6 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(6) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type7 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(7) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type8 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(8) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type9 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(9) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(fun_type10 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(10) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type0 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(0) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type1 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(1) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - /** \brief Constructor for constructing function callbacks taking two arguments. - \throw nothrow - */ - ParserCallback::ParserCallback(bulkfun_type2 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(2) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type3 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(3) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type4 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(4) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type5 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(5) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type6 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(6) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type7 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(7) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type8 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(8) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type9 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(9) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(bulkfun_type10 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(10) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_BULK) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(multfun_type a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(-1) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC) - ,m_iType(tpDBL) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(strfun_type1 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(0) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_STR) - ,m_iType(tpSTR) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(strfun_type2 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(1) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_STR) - ,m_iType(tpSTR) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - ParserCallback::ParserCallback(strfun_type3 a_pFun, bool a_bAllowOpti) - :m_pFun((void*)a_pFun) - ,m_iArgc(2) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmFUNC_STR) - ,m_iType(tpSTR) - ,m_bAllowOpti(a_bAllowOpti) - {} - - - //--------------------------------------------------------------------------- - /** \brief Default constructor. - \throw nothrow - */ - ParserCallback::ParserCallback() - :m_pFun(0) - ,m_iArgc(0) - ,m_iPri(-1) - ,m_eOprtAsct(oaNONE) - ,m_iCode(cmUNKNOWN) - ,m_iType(tpVOID) - ,m_bAllowOpti(0) - {} - - - //--------------------------------------------------------------------------- - /** \brief Copy constructor. - \throw nothrow - */ - ParserCallback::ParserCallback(const ParserCallback &ref) - { - m_pFun = ref.m_pFun; - m_iArgc = ref.m_iArgc; - m_bAllowOpti = ref.m_bAllowOpti; - m_iCode = ref.m_iCode; - m_iType = ref.m_iType; - m_iPri = ref.m_iPri; - m_eOprtAsct = ref.m_eOprtAsct; - } - - //--------------------------------------------------------------------------- - /** \brief Clone this instance and return a pointer to the new instance. */ - ParserCallback* ParserCallback::Clone() const - { - return new ParserCallback(*this); - } - - //--------------------------------------------------------------------------- - /** \brief Return tru if the function is conservative. - - Conservative functions return always the same result for the same argument. - \throw nothrow - */ - bool ParserCallback::IsOptimizable() const - { - return m_bAllowOpti; - } - - //--------------------------------------------------------------------------- - /** \brief Get the callback address for the parser function. - - The type of the address is void. It needs to be recasted according to the - argument number to the right type. - - \throw nothrow - \return #pFun - */ - void* ParserCallback::GetAddr() const - { - return m_pFun; - } - - //--------------------------------------------------------------------------- - /** \brief Return the callback code. */ - ECmdCode ParserCallback::GetCode() const - { - return m_iCode; - } - - //--------------------------------------------------------------------------- - ETypeCode ParserCallback::GetType() const - { - return m_iType; - } - - - //--------------------------------------------------------------------------- - /** \brief Return the operator precedence. - \throw nothrown - - Only valid if the callback token is an operator token (binary or infix). - */ - int ParserCallback::GetPri() const - { - return m_iPri; - } - - //--------------------------------------------------------------------------- - /** \brief Return the operators associativity. - \throw nothrown - - Only valid if the callback token is a binary operator token. - */ - EOprtAssociativity ParserCallback::GetAssociativity() const - { - return m_eOprtAsct; - } - - //--------------------------------------------------------------------------- - /** \brief Returns the number of function Arguments. */ - int ParserCallback::GetArgc() const - { - return m_iArgc; - } -} // namespace mu +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParserCallback.h" + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable : 26812) +#endif + +/** \file + \brief Implementation of the parser callback class. +*/ + + +namespace mu +{ + ParserCallback::ParserCallback(fun_type0 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(0) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type1 a_pFun, bool a_bAllowOpti, int a_iPrec, ECmdCode a_iCode) + :m_pFun((void*)a_pFun) + , m_iArgc(1) + , m_iPri(a_iPrec) + , m_eOprtAsct(oaNONE) + , m_iCode(a_iCode) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + + /** \brief Constructor for constructing function callbacks taking two arguments. + \throw nothrow + */ + ParserCallback::ParserCallback(fun_type2 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(2) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + /** \brief Constructor for constructing binary operator callbacks. + \param a_pFun Pointer to a static function taking two arguments + \param a_bAllowOpti A flag indicating this function can be optimized + \param a_iPrec The operator precedence + \param a_eOprtAsct The operators associativity + \throw nothrow + */ + ParserCallback::ParserCallback(fun_type2 a_pFun, + bool a_bAllowOpti, + int a_iPrec, + EOprtAssociativity a_eOprtAsct) + :m_pFun((void*)a_pFun) + , m_iArgc(2) + , m_iPri(a_iPrec) + , m_eOprtAsct(a_eOprtAsct) + , m_iCode(cmOPRT_BIN) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type3 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(3) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type4 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(4) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type5 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(5) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type6 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(6) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type7 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(7) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type8 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(8) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type9 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(9) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(fun_type10 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(10) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type0 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(0) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type1 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(1) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + /** \brief Constructor for constructing function callbacks taking two arguments. + \throw nothrow + */ + ParserCallback::ParserCallback(bulkfun_type2 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(2) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type3 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(3) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type4 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(4) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type5 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(5) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type6 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(6) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type7 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(7) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type8 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(8) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type9 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(9) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(bulkfun_type10 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(10) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_BULK) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(multfun_type a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(-1) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC) + , m_iType(tpDBL) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(strfun_type1 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(0) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_STR) + , m_iType(tpSTR) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(strfun_type2 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(1) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_STR) + , m_iType(tpSTR) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(strfun_type3 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(2) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_STR) + , m_iType(tpSTR) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(strfun_type4 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(3) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_STR) + , m_iType(tpSTR) + , m_bAllowOpti(a_bAllowOpti) + {} + + + ParserCallback::ParserCallback(strfun_type5 a_pFun, bool a_bAllowOpti) + :m_pFun((void*)a_pFun) + , m_iArgc(4) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmFUNC_STR) + , m_iType(tpSTR) + , m_bAllowOpti(a_bAllowOpti) + {} + + + /** \brief Default constructor. + \throw nothrow + */ + ParserCallback::ParserCallback() + :m_pFun(0) + , m_iArgc(0) + , m_iPri(-1) + , m_eOprtAsct(oaNONE) + , m_iCode(cmUNKNOWN) + , m_iType(tpVOID) + , m_bAllowOpti(0) + {} + + + /** \brief Copy constructor. + \throw nothrow + */ + ParserCallback::ParserCallback(const ParserCallback& ref) + { + m_pFun = ref.m_pFun; + m_iArgc = ref.m_iArgc; + m_bAllowOpti = ref.m_bAllowOpti; + m_iCode = ref.m_iCode; + m_iType = ref.m_iType; + m_iPri = ref.m_iPri; + m_eOprtAsct = ref.m_eOprtAsct; + } + + ParserCallback & ParserCallback::operator=(const ParserCallback & ref) + { + if (this != &ref) + { + m_pFun = ref.m_pFun; + m_iArgc = ref.m_iArgc; + m_bAllowOpti = ref.m_bAllowOpti; + m_iCode = ref.m_iCode; + m_iType = ref.m_iType; + m_iPri = ref.m_iPri; + m_eOprtAsct = ref.m_eOprtAsct; + } + return *this; + } + + /** \brief Clone this instance and return a pointer to the new instance. */ + ParserCallback* ParserCallback::Clone() const + { + return new ParserCallback(*this); + } + + + /** \brief Return tru if the function is conservative. + + Conservative functions return always the same result for the same argument. + \throw nothrow + */ + bool ParserCallback::IsOptimizable() const + { + return m_bAllowOpti; + } + + + /** \brief Get the callback address for the parser function. + + The type of the address is void. It needs to be recasted according to the + argument number to the right type. + + \throw nothrow + \return #pFun + */ + void* ParserCallback::GetAddr() const + { + return m_pFun; + } + + + /** \brief Return the callback code. */ + ECmdCode ParserCallback::GetCode() const + { + return m_iCode; + } + + + ETypeCode ParserCallback::GetType() const + { + return m_iType; + } + + + /** \brief Return the operator precedence. + \throw nothrown + + Only valid if the callback token is an operator token (binary or infix). + */ + int ParserCallback::GetPri() const + { + return m_iPri; + } + + + /** \brief Return the operators associativity. + \throw nothrown + + Only valid if the callback token is a binary operator token. + */ + EOprtAssociativity ParserCallback::GetAssociativity() const + { + return m_eOprtAsct; + } + + + /** \brief Returns the number of function Arguments. */ + int ParserCallback::GetArgc() const + { + return m_iArgc; + } +} // namespace mu + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif diff --git a/3rdParty/MuParser/src/muParserDLL.cpp b/3rdParty/MuParser/src/muParserDLL.cpp index 15c88003cb907ad54740145190a48c53776bbbac..ed697190fa01dfb6faa94489bc3c70c7b6a73bf9 100644 --- a/3rdParty/MuParser/src/muParserDLL.cpp +++ b/3rdParty/MuParser/src/muParserDLL.cpp @@ -1,1096 +1,992 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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 <windows.h> -#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<ParserTag*>(a_hParser); \ - pTag->exc = e; \ - pTag->bError = true; \ -if (pTag->errHandler) \ - (pTag->errHandler)(a_hParser); \ - } \ - catch (...) \ - { \ - ParserTag *pTag = static_cast<ParserTag*>(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<ParserTag*>(a_hParser)->pParser; -} - -//--------------------------------------------------------------------------- -ParserTag* AsParserTag(muParserHandle_t a_hParser) -{ - return static_cast<ParserTag*>(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<ParserTag*>(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)); - -#ifndef _UNICODE - sprintf(s_tmpOutBuf, "%s", p->GetVersion().c_str()); -#else - wsprintf(s_tmpOutBuf, _T("%s"), p->GetVersion().c_str()); -#endif - - return s_tmpOutBuf; - MU_CATCH - - return _T(""); -} - -//--------------------------------------------------------------------------- -/** \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. -#ifndef _UNICODE - sprintf(s_tmpOutBuf, "%s", p->GetExpr().c_str()); -#else - wsprintf(s_tmpOutBuf, _T("%s"), p->GetExpr().c_str()); -#endif - - return s_tmpOutBuf; - - MU_CATCH - - return _T(""); -} - -//--------------------------------------------------------------------------- -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; i < a_iVar; ++i) - ++item; - -#ifndef _UNICODE - strncpy(szName, item->first.c_str(), sizeof(szName)); -#else - wcsncpy(szName, item->first.c_str(), sizeof(szName)); -#endif - - 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; i < a_iVar; ++i) - ++item; - -#ifndef _UNICODE - strncpy(szName, item->first.c_str(), sizeof(szName)); -#else - wcsncpy(szName, item->first.c_str(), sizeof(szName)); -#endif - - 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; i < a_iVar; ++i) - ++item; - -#ifndef _UNICODE - strncpy(szName, item->first.c_str(), sizeof(szName)); -#else - wcsncpy(szName, item->first.c_str(), sizeof(szName)); -#endif - - 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 recognition 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 occurred. - - 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. -#ifndef _UNICODE - sprintf(s_tmpOutBuf, "%s", pMsg); -#else - wsprintf(s_tmpOutBuf, _T("%s"), pMsg); -#endif - - 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. -#ifndef _UNICODE - sprintf(s_tmpOutBuf, "%s", pToken); -#else - wsprintf(s_tmpOutBuf, _T("%s"), pToken); -#endif - - 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 position 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 +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#if defined(MUPARSER_DLL) + +#if defined(_WIN32) + #define WIN32_LEAN_AND_MEAN + #define _CRT_SECURE_NO_WARNINGS + #define _CRT_SECURE_NO_DEPRECATE + + #include <windows.h> +#endif + +#include <cassert> + +#include "muParserDLL.h" +#include "muParser.h" +#include "muParserInt.h" +#include "muParserError.h" + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable : 26812) +#endif + +#define MU_TRY \ + try \ + { + +#define MU_CATCH \ + } \ + catch (muError_t &e) \ + { \ + ParserTag *pTag = static_cast<ParserTag*>(a_hParser); \ + pTag->exc = e; \ + pTag->bError = true; \ + if (pTag->errHandler) \ + (pTag->errHandler)(a_hParser); \ + } \ + catch (...) \ + { \ + ParserTag *pTag = static_cast<ParserTag*>(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. +*/ + +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() : nullptr) + , exc() + , errHandler(nullptr) + , 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 +// +// +//--------------------------------------------------------------------------- + + +inline muParser_t* AsParser(muParserHandle_t a_hParser) +{ + return static_cast<ParserTag*>(a_hParser)->pParser; +} + + +inline ParserTag* AsParserTag(muParserHandle_t a_hParser) +{ + return static_cast<ParserTag*>(a_hParser); +} + + +#if defined(_WIN32) + +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 nullptr; + } +} + + +/** \brief Release the parser instance related with a parser handle. */ +API_EXPORT(void) mupRelease(muParserHandle_t a_hParser) +{ + MU_TRY + ParserTag* p = static_cast<ParserTag*>(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)); + +#ifndef _UNICODE + sprintf(s_tmpOutBuf, "%s", p->GetVersion().c_str()); +#else + wsprintf(s_tmpOutBuf, _T("%s"), p->GetVersion().c_str()); +#endif + + return s_tmpOutBuf; + MU_CATCH + return _T(""); +} + + +/** \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 + if (nNum == nullptr) + throw std::runtime_error("Argument is 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. +#ifndef _UNICODE + sprintf(s_tmpOutBuf, "%s", p->GetExpr().c_str()); +#else + wsprintf(s_tmpOutBuf, _T("%s"), p->GetExpr().c_str()); +#endif + + return s_tmpOutBuf; + MU_CATCH + + return _T(""); +} + + +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 can't 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; i < a_iVar; ++i) + ++item; + +#ifndef _UNICODE + strncpy(szName, item->first.c_str(), sizeof(szName)); +#else + wcsncpy(szName, item->first.c_str(), sizeof(szName)); +#endif + + 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 can't 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; i < a_iVar; ++i) + ++item; + +#ifndef _UNICODE + strncpy(szName, item->first.c_str(), sizeof(szName)); +#else + wcsncpy(szName, item->first.c_str(), sizeof(szName)); +#endif + + 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 can't 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; i < a_iVar; ++i) + ++item; + +#ifndef _UNICODE + strncpy(szName, item->first.c_str(), sizeof(szName)); +#else + wcsncpy(szName, item->first.c_str(), sizeof(szName)); +#endif + + 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 recognition 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 occurred. + + 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. +#ifndef _UNICODE + sprintf(s_tmpOutBuf, "%s", pMsg); +#else + wsprintf(s_tmpOutBuf, _T("%s"), pMsg); +#endif + + 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. +#ifndef _UNICODE + sprintf(s_tmpOutBuf, "%s", pToken); +#else + wsprintf(s_tmpOutBuf, _T("%s"), pToken); +#endif + + 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 position associated with the last error. */ +API_EXPORT(int) mupGetErrorPos(muParserHandle_t a_hParser) +{ + return (int)AsParserTag(a_hParser)->exc.GetPos(); +} + + +API_EXPORT(muFloat_t*) mupCreateVar() +{ + return new muFloat_t(0); +} + + +API_EXPORT(void) mupReleaseVar(muFloat_t* ptr) +{ + delete ptr; +} + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif + +#endif // MUPARSER_DLL diff --git a/3rdParty/MuParser/src/muParserError.cpp b/3rdParty/MuParser/src/muParserError.cpp index 6fe4e1d2cca91e2cd8bcc8a25677f52317f72fe4..2a192f8cf2e5b327ef22587b0c1f48e745049b89 100644 --- a/3rdParty/MuParser/src/muParserError.cpp +++ b/3rdParty/MuParser/src/muParserError.cpp @@ -1,337 +1,335 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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. -*/ -#include "muParserError.h" - - -namespace mu -{ - const ParserErrorMsg ParserErrorMsg::m_Instance; - - //------------------------------------------------------------------------------ - const ParserErrorMsg& ParserErrorMsg::Instance() - { - return m_Instance; - } - - //------------------------------------------------------------------------------ - string_type ParserErrorMsg::operator[](unsigned a_iIdx) const - { - return (a_iIdx<m_vErrMsg.size()) ? m_vErrMsg[a_iIdx] : string_type(); - } - - //--------------------------------------------------------------------------- - ParserErrorMsg::~ParserErrorMsg() - {} - - //--------------------------------------------------------------------------- - /** \brief Assignement operator is deactivated. - */ - ParserErrorMsg& ParserErrorMsg::operator=(const ParserErrorMsg& ) - { - assert(false); - return *this; - } - - //--------------------------------------------------------------------------- - ParserErrorMsg::ParserErrorMsg(const ParserErrorMsg&) - {} - - //--------------------------------------------------------------------------- - ParserErrorMsg::ParserErrorMsg() - :m_vErrMsg(0) - { - m_vErrMsg.resize(ecCOUNT); - - m_vErrMsg[ecUNASSIGNABLE_TOKEN] = _T("Unexpected token \"$TOK$\" found at position $POS$."); - m_vErrMsg[ecINTERNAL_ERROR] = _T("Internal error"); - m_vErrMsg[ecINVALID_NAME] = _T("Invalid function-, variable- or constant name: \"$TOK$\"."); - m_vErrMsg[ecINVALID_BINOP_IDENT] = _T("Invalid binary operator identifier: \"$TOK$\"."); - m_vErrMsg[ecINVALID_INFIX_IDENT] = _T("Invalid infix operator identifier: \"$TOK$\"."); - m_vErrMsg[ecINVALID_POSTFIX_IDENT] = _T("Invalid postfix operator identifier: \"$TOK$\"."); - m_vErrMsg[ecINVALID_FUN_PTR] = _T("Invalid pointer to callback function."); - m_vErrMsg[ecEMPTY_EXPRESSION] = _T("Expression is empty."); - m_vErrMsg[ecINVALID_VAR_PTR] = _T("Invalid pointer to variable."); - m_vErrMsg[ecUNEXPECTED_OPERATOR] = _T("Unexpected operator \"$TOK$\" found at position $POS$"); - m_vErrMsg[ecUNEXPECTED_EOF] = _T("Unexpected end of expression at position $POS$"); - m_vErrMsg[ecUNEXPECTED_ARG_SEP] = _T("Unexpected argument separator at position $POS$"); - m_vErrMsg[ecUNEXPECTED_PARENS] = _T("Unexpected parenthesis \"$TOK$\" at position $POS$"); - m_vErrMsg[ecUNEXPECTED_FUN] = _T("Unexpected function \"$TOK$\" at position $POS$"); - m_vErrMsg[ecUNEXPECTED_VAL] = _T("Unexpected value \"$TOK$\" found at position $POS$"); - m_vErrMsg[ecUNEXPECTED_VAR] = _T("Unexpected variable \"$TOK$\" found at position $POS$"); - m_vErrMsg[ecUNEXPECTED_ARG] = _T("Function arguments used without a function (position: $POS$)"); - m_vErrMsg[ecMISSING_PARENS] = _T("Missing parenthesis"); - m_vErrMsg[ecTOO_MANY_PARAMS] = _T("Too many parameters for function \"$TOK$\" at expression position $POS$"); - m_vErrMsg[ecTOO_FEW_PARAMS] = _T("Too few parameters for function \"$TOK$\" at expression position $POS$"); - m_vErrMsg[ecDIV_BY_ZERO] = _T("Divide by zero"); - m_vErrMsg[ecDOMAIN_ERROR] = _T("Domain error"); - m_vErrMsg[ecNAME_CONFLICT] = _T("Name conflict"); - m_vErrMsg[ecOPT_PRI] = _T("Invalid value for operator priority (must be greater or equal to zero)."); - m_vErrMsg[ecBUILTIN_OVERLOAD] = _T("user defined binary operator \"$TOK$\" conflicts with a built in operator."); - m_vErrMsg[ecUNEXPECTED_STR] = _T("Unexpected string token found at position $POS$."); - m_vErrMsg[ecUNTERMINATED_STRING] = _T("Unterminated string starting at position $POS$."); - m_vErrMsg[ecSTRING_EXPECTED] = _T("String function called with a non string type of argument."); - m_vErrMsg[ecVAL_EXPECTED] = _T("String value used where a numerical argument is expected."); - m_vErrMsg[ecOPRT_TYPE_CONFLICT] = _T("No suitable overload for operator \"$TOK$\" at position $POS$."); - m_vErrMsg[ecSTR_RESULT] = _T("Function result is a string."); - m_vErrMsg[ecGENERIC] = _T("Parser error."); - m_vErrMsg[ecLOCALE] = _T("Decimal separator is identic to function argument separator."); - 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; i<ecCOUNT; ++i) - if (!m_vErrMsg[i].length()) - assert(false); - #endif - } - - //--------------------------------------------------------------------------- - // - // ParserError class - // - //--------------------------------------------------------------------------- - - /** \brief Default constructor. */ - ParserError::ParserError() - :m_strMsg() - ,m_strFormula() - ,m_strTok() - ,m_iPos(-1) - ,m_iErrc(ecUNDEFINED) - ,m_ErrMsg(ParserErrorMsg::Instance()) - { - } - - //------------------------------------------------------------------------------ - /** \brief This Constructor is used for internal exceptions only. - - It does not contain any information but the error code. - */ - ParserError::ParserError(EErrorCodes a_iErrc) - :m_strMsg() - ,m_strFormula() - ,m_strTok() - ,m_iPos(-1) - ,m_iErrc(a_iErrc) - ,m_ErrMsg(ParserErrorMsg::Instance()) - { - m_strMsg = m_ErrMsg[m_iErrc]; - stringstream_type stream; - stream << (int)m_iPos; - ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); - ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); - } - - //------------------------------------------------------------------------------ - /** \brief Construct an error from a message text. */ - ParserError::ParserError(const string_type &sMsg) - :m_ErrMsg(ParserErrorMsg::Instance()) - { - Reset(); - m_strMsg = sMsg; - } - - //------------------------------------------------------------------------------ - /** \brief Construct an error object. - \param [in] a_iErrc the error code. - \param [in] sTok The token string related to this error. - \param [in] sExpr The expression related to the error. - \param [in] a_iPos the position in the expression where the error occurred. - */ - ParserError::ParserError( EErrorCodes iErrc, - const string_type &sTok, - const string_type &sExpr, - int iPos ) - :m_strMsg() - ,m_strFormula(sExpr) - ,m_strTok(sTok) - ,m_iPos(iPos) - ,m_iErrc(iErrc) - ,m_ErrMsg(ParserErrorMsg::Instance()) - { - m_strMsg = m_ErrMsg[m_iErrc]; - stringstream_type stream; - stream << (int)m_iPos; - ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); - ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); - } - - //------------------------------------------------------------------------------ - /** \brief Construct an error object. - \param [in] iErrc the error code. - \param [in] iPos the position in the expression where the error occurred. - \param [in] sTok The token string related to this error. - */ - ParserError::ParserError(EErrorCodes iErrc, int iPos, const string_type &sTok) - :m_strMsg() - ,m_strFormula() - ,m_strTok(sTok) - ,m_iPos(iPos) - ,m_iErrc(iErrc) - ,m_ErrMsg(ParserErrorMsg::Instance()) - { - m_strMsg = m_ErrMsg[m_iErrc]; - stringstream_type stream; - stream << (int)m_iPos; - ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); - ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); - } - - //------------------------------------------------------------------------------ - /** \brief Construct an error object. - \param [in] szMsg The error message text. - \param [in] iPos the position related to the error. - \param [in] sTok The token string related to this error. - */ - ParserError::ParserError(const char_type *szMsg, int iPos, const string_type &sTok) - :m_strMsg(szMsg) - ,m_strFormula() - ,m_strTok(sTok) - ,m_iPos(iPos) - ,m_iErrc(ecGENERIC) - ,m_ErrMsg(ParserErrorMsg::Instance()) - { - stringstream_type stream; - stream << (int)m_iPos; - ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); - ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); - } - - //------------------------------------------------------------------------------ - /** \brief Copy constructor. */ - ParserError::ParserError(const ParserError &a_Obj) - :m_strMsg(a_Obj.m_strMsg) - ,m_strFormula(a_Obj.m_strFormula) - ,m_strTok(a_Obj.m_strTok) - ,m_iPos(a_Obj.m_iPos) - ,m_iErrc(a_Obj.m_iErrc) - ,m_ErrMsg(ParserErrorMsg::Instance()) - { - } - - //------------------------------------------------------------------------------ - /** \brief Assignment operator. */ - ParserError& ParserError::operator=(const ParserError &a_Obj) - { - if (this==&a_Obj) - return *this; - - m_strMsg = a_Obj.m_strMsg; - m_strFormula = a_Obj.m_strFormula; - m_strTok = a_Obj.m_strTok; - m_iPos = a_Obj.m_iPos; - m_iErrc = a_Obj.m_iErrc; - return *this; - } - - //------------------------------------------------------------------------------ - ParserError::~ParserError() - {} - - //------------------------------------------------------------------------------ - /** \brief Replace all occurrences of a substring with another string. - \param strFind The string that shall be replaced. - \param strReplaceWith The string that should be inserted instead of strFind - */ - void ParserError::ReplaceSubString( string_type &strSource, - const string_type &strFind, - const string_type &strReplaceWith) - { - string_type strResult; - string_type::size_type iPos(0), iNext(0); - - for(;;) - { - iNext = strSource.find(strFind, iPos); - strResult.append(strSource, iPos, iNext-iPos); - - if( iNext==string_type::npos ) - break; - - strResult.append(strReplaceWith); - iPos = iNext + strFind.length(); - } - - strSource.swap(strResult); - } - - //------------------------------------------------------------------------------ - /** \brief Reset the erro object. */ - void ParserError::Reset() - { - m_strMsg = _T(""); - m_strFormula = _T(""); - m_strTok = _T(""); - m_iPos = -1; - m_iErrc = ecUNDEFINED; - } - - //------------------------------------------------------------------------------ - /** \brief Set the expression related to this error. */ - void ParserError::SetFormula(const string_type &a_strFormula) - { - m_strFormula = a_strFormula; - } - - //------------------------------------------------------------------------------ - /** \brief gets the expression related tp this error.*/ - const string_type& ParserError::GetExpr() const - { - return m_strFormula; - } - - //------------------------------------------------------------------------------ - /** \brief Returns the message string for this error. */ - const string_type& ParserError::GetMsg() const - { - return m_strMsg; - } - - //------------------------------------------------------------------------------ - /** \brief Return the formula position related to the error. - - If the error is not related to a distinct position this will return -1 - */ - int ParserError::GetPos() const - { - return m_iPos; - } - - //------------------------------------------------------------------------------ - /** \brief Return string related with this token (if available). */ - const string_type& ParserError::GetToken() const - { - return m_strTok; - } - - //------------------------------------------------------------------------------ - /** \brief Return the error code. */ - EErrorCodes ParserError::GetCode() const - { - return m_iErrc; - } -} // namespace mu +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParserError.h" +#include <exception> + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable : 26812) // What the fuck is the point of this warning? +#endif + +namespace mu +{ + //------------------------------------------------------------------------------ + const ParserErrorMsg& ParserErrorMsg::Instance() + { + static const ParserErrorMsg instance; + return instance; + } + + //------------------------------------------------------------------------------ + string_type ParserErrorMsg::operator[](unsigned a_iIdx) const + { + return (a_iIdx < m_vErrMsg.size()) ? m_vErrMsg[a_iIdx] : string_type(); + } + + //--------------------------------------------------------------------------- + ParserErrorMsg::ParserErrorMsg() + :m_vErrMsg(0) + { + m_vErrMsg.resize(ecCOUNT); + + m_vErrMsg[ecUNASSIGNABLE_TOKEN] = _T("Unexpected token \"$TOK$\" found at position $POS$."); + m_vErrMsg[ecINTERNAL_ERROR] = _T("Internal error"); + m_vErrMsg[ecINVALID_NAME] = _T("Invalid function-, variable- or constant name: \"$TOK$\"."); + m_vErrMsg[ecINVALID_BINOP_IDENT] = _T("Invalid binary operator identifier: \"$TOK$\"."); + m_vErrMsg[ecINVALID_INFIX_IDENT] = _T("Invalid infix operator identifier: \"$TOK$\"."); + m_vErrMsg[ecINVALID_POSTFIX_IDENT] = _T("Invalid postfix operator identifier: \"$TOK$\"."); + m_vErrMsg[ecINVALID_FUN_PTR] = _T("Invalid pointer to callback function."); + m_vErrMsg[ecEMPTY_EXPRESSION] = _T("Expression is empty."); + m_vErrMsg[ecINVALID_VAR_PTR] = _T("Invalid pointer to variable."); + m_vErrMsg[ecUNEXPECTED_OPERATOR] = _T("Unexpected operator \"$TOK$\" found at position $POS$"); + m_vErrMsg[ecUNEXPECTED_EOF] = _T("Unexpected end of expression at position $POS$"); + m_vErrMsg[ecUNEXPECTED_ARG_SEP] = _T("Unexpected argument separator at position $POS$"); + m_vErrMsg[ecUNEXPECTED_PARENS] = _T("Unexpected parenthesis \"$TOK$\" at position $POS$"); + m_vErrMsg[ecUNEXPECTED_FUN] = _T("Unexpected function \"$TOK$\" at position $POS$"); + m_vErrMsg[ecUNEXPECTED_VAL] = _T("Unexpected value \"$TOK$\" found at position $POS$"); + m_vErrMsg[ecUNEXPECTED_VAR] = _T("Unexpected variable \"$TOK$\" found at position $POS$"); + m_vErrMsg[ecUNEXPECTED_ARG] = _T("Function arguments used without a function (position: $POS$)"); + m_vErrMsg[ecMISSING_PARENS] = _T("Missing parenthesis"); + m_vErrMsg[ecTOO_MANY_PARAMS] = _T("Too many parameters for function \"$TOK$\" at expression position $POS$"); + m_vErrMsg[ecTOO_FEW_PARAMS] = _T("Too few parameters for function \"$TOK$\" at expression position $POS$"); + m_vErrMsg[ecDIV_BY_ZERO] = _T("Divide by zero"); + m_vErrMsg[ecDOMAIN_ERROR] = _T("Domain error"); + m_vErrMsg[ecNAME_CONFLICT] = _T("Name conflict"); + m_vErrMsg[ecOPT_PRI] = _T("Invalid value for operator priority (must be greater or equal to zero)."); + m_vErrMsg[ecBUILTIN_OVERLOAD] = _T("user defined binary operator \"$TOK$\" conflicts with a built in operator."); + m_vErrMsg[ecUNEXPECTED_STR] = _T("Unexpected string token found at position $POS$."); + m_vErrMsg[ecUNTERMINATED_STRING] = _T("Unterminated string starting at position $POS$."); + m_vErrMsg[ecSTRING_EXPECTED] = _T("String function called with a non string type of argument."); + m_vErrMsg[ecVAL_EXPECTED] = _T("String value used where a numerical argument is expected."); + m_vErrMsg[ecOPRT_TYPE_CONFLICT] = _T("No suitable overload for operator \"$TOK$\" at position $POS$."); + m_vErrMsg[ecSTR_RESULT] = _T("Strings must only be used as function arguments!"); + m_vErrMsg[ecGENERIC] = _T("Parser error."); + m_vErrMsg[ecLOCALE] = _T("Decimal separator is identic to function argument separator."); + m_vErrMsg[ecUNEXPECTED_CONDITIONAL] = _T("The \"$TOK$\" operator must be preceded 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)"); + m_vErrMsg[ecIDENTIFIER_TOO_LONG] = _T("Identifier too long."); + m_vErrMsg[ecEXPRESSION_TOO_LONG] = _T("Expression too long."); + m_vErrMsg[ecINVALID_CHARACTERS_FOUND] = _T("Invalid non printable characters found in expression/identifer!"); + + for (int i = 0; i < ecCOUNT; ++i) + { + if (!m_vErrMsg[i].length()) + throw std::runtime_error("Error definitions are incomplete!"); + } + } + + //--------------------------------------------------------------------------- + // + // ParserError class + // + //--------------------------------------------------------------------------- + + /** \brief Default constructor. */ + ParserError::ParserError() + :m_strMsg() + , m_strFormula() + , m_strTok() + , m_iPos(-1) + , m_iErrc(ecUNDEFINED) + , m_ErrMsg(ParserErrorMsg::Instance()) + { + } + + //------------------------------------------------------------------------------ + /** \brief This Constructor is used for internal exceptions only. + + It does not contain any information but the error code. + */ + ParserError::ParserError(EErrorCodes a_iErrc) + :m_strMsg() + , m_strFormula() + , m_strTok() + , m_iPos(-1) + , m_iErrc(a_iErrc) + , m_ErrMsg(ParserErrorMsg::Instance()) + { + m_strMsg = m_ErrMsg[m_iErrc]; + stringstream_type stream; + stream << (int)m_iPos; + ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); + ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); + } + + //------------------------------------------------------------------------------ + /** \brief Construct an error from a message text. */ + ParserError::ParserError(const string_type& sMsg) + :m_ErrMsg(ParserErrorMsg::Instance()) + { + Reset(); + m_strMsg = sMsg; + } + + //------------------------------------------------------------------------------ + /** \brief Construct an error object. + \param [in] a_iErrc the error code. + \param [in] sTok The token string related to this error. + \param [in] sExpr The expression related to the error. + \param [in] a_iPos the position in the expression where the error occurred. + */ + ParserError::ParserError(EErrorCodes iErrc, + const string_type& sTok, + const string_type& sExpr, + int iPos) + :m_strMsg() + , m_strFormula(sExpr) + , m_strTok(sTok) + , m_iPos(iPos) + , m_iErrc(iErrc) + , m_ErrMsg(ParserErrorMsg::Instance()) + { + m_strMsg = m_ErrMsg[m_iErrc]; + stringstream_type stream; + stream << (int)m_iPos; + ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); + ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); + } + + //------------------------------------------------------------------------------ + /** \brief Construct an error object. + \param [in] iErrc the error code. + \param [in] iPos the position in the expression where the error occurred. + \param [in] sTok The token string related to this error. + */ + ParserError::ParserError(EErrorCodes iErrc, int iPos, const string_type& sTok) + :m_strMsg() + , m_strFormula() + , m_strTok(sTok) + , m_iPos(iPos) + , m_iErrc(iErrc) + , m_ErrMsg(ParserErrorMsg::Instance()) + { + m_strMsg = m_ErrMsg[m_iErrc]; + stringstream_type stream; + stream << (int)m_iPos; + ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); + ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); + } + + //------------------------------------------------------------------------------ + /** \brief Construct an error object. + \param [in] szMsg The error message text. + \param [in] iPos the position related to the error. + \param [in] sTok The token string related to this error. + */ + ParserError::ParserError(const char_type* szMsg, int iPos, const string_type& sTok) + :m_strMsg(szMsg) + , m_strFormula() + , m_strTok(sTok) + , m_iPos(iPos) + , m_iErrc(ecGENERIC) + , m_ErrMsg(ParserErrorMsg::Instance()) + { + stringstream_type stream; + stream << (int)m_iPos; + ReplaceSubString(m_strMsg, _T("$POS$"), stream.str()); + ReplaceSubString(m_strMsg, _T("$TOK$"), m_strTok); + } + + //------------------------------------------------------------------------------ + /** \brief Copy constructor. */ + ParserError::ParserError(const ParserError& a_Obj) + :m_strMsg(a_Obj.m_strMsg) + , m_strFormula(a_Obj.m_strFormula) + , m_strTok(a_Obj.m_strTok) + , m_iPos(a_Obj.m_iPos) + , m_iErrc(a_Obj.m_iErrc) + , m_ErrMsg(ParserErrorMsg::Instance()) + { + } + + //------------------------------------------------------------------------------ + /** \brief Assignment operator. */ + ParserError& ParserError::operator=(const ParserError& a_Obj) + { + if (this == &a_Obj) + return *this; + + m_strMsg = a_Obj.m_strMsg; + m_strFormula = a_Obj.m_strFormula; + m_strTok = a_Obj.m_strTok; + m_iPos = a_Obj.m_iPos; + m_iErrc = a_Obj.m_iErrc; + return *this; + } + + //------------------------------------------------------------------------------ + ParserError::~ParserError() + {} + + //------------------------------------------------------------------------------ + /** \brief Replace all occurrences of a substring with another string. + \param strFind The string that shall be replaced. + \param strReplaceWith The string that should be inserted instead of strFind + */ + void ParserError::ReplaceSubString(string_type& strSource, + const string_type& strFind, + const string_type& strReplaceWith) + { + string_type strResult; + string_type::size_type iPos(0), iNext(0); + + for (;;) + { + iNext = strSource.find(strFind, iPos); + strResult.append(strSource, iPos, iNext - iPos); + + if (iNext == string_type::npos) + break; + + strResult.append(strReplaceWith); + iPos = iNext + strFind.length(); + } + + strSource.swap(strResult); + } + + //------------------------------------------------------------------------------ + /** \brief Reset the error object. */ + void ParserError::Reset() + { + m_strMsg = _T(""); + m_strFormula = _T(""); + m_strTok = _T(""); + m_iPos = -1; + m_iErrc = ecUNDEFINED; + } + + //------------------------------------------------------------------------------ + /** \brief Set the expression related to this error. */ + void ParserError::SetFormula(const string_type& a_strFormula) + { + m_strFormula = a_strFormula; + } + + //------------------------------------------------------------------------------ + /** \brief gets the expression related tp this error.*/ + const string_type& ParserError::GetExpr() const + { + return m_strFormula; + } + + //------------------------------------------------------------------------------ + /** \brief Returns the message string for this error. */ + const string_type& ParserError::GetMsg() const + { + return m_strMsg; + } + + //------------------------------------------------------------------------------ + /** \brief Return the formula position related to the error. + + If the error is not related to a distinct position this will return -1 + */ + int ParserError::GetPos() const + { + return m_iPos; + } + + //------------------------------------------------------------------------------ + /** \brief Return string related with this token (if available). */ + const string_type& ParserError::GetToken() const + { + return m_strTok; + } + + //------------------------------------------------------------------------------ + /** \brief Return the error code. */ + EErrorCodes ParserError::GetCode() const + { + return m_iErrc; + } +} // namespace mu + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif diff --git a/3rdParty/MuParser/src/muParserInt.cpp b/3rdParty/MuParser/src/muParserInt.cpp index 8b5aae60346f3e87a3d539282fe1944c0d80f184..f79ba1a3a78262ffbc480a88b6ac257c45746b20 100644 --- a/3rdParty/MuParser/src/muParserInt.cpp +++ b/3rdParty/MuParser/src/muParserInt.cpp @@ -1,280 +1,279 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | 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. -*/ - -#include "muParserInt.h" - -#include <cmath> -#include <algorithm> -#include <numeric> - -using namespace std; - -/** \file - \brief Implementation of a parser using integer value. -*/ - -/** \brief Namespace for mathematical applications. */ -namespace mu -{ -value_type ParserInt::Abs(value_type v) { return (value_type)Round(fabs((double)v)); } -value_type ParserInt::Sign(value_type v) { return (Round(v)<0) ? -1 : (Round(v)>0) ? 1 : 0; } -value_type ParserInt::Ite(value_type v1, - value_type v2, - value_type v3) { return (Round(v1)==1) ? Round(v2) : Round(v3); } -value_type ParserInt::Add(value_type v1, value_type v2) { return Round(v1) + Round(v2); } -value_type ParserInt::Sub(value_type v1, value_type v2) { return Round(v1) - Round(v2); } -value_type ParserInt::Mul(value_type v1, value_type v2) { return Round(v1) * Round(v2); } -value_type ParserInt::Div(value_type v1, value_type v2) { return Round(v1) / Round(v2); } -value_type ParserInt::Mod(value_type v1, value_type v2) { return Round(v1) % Round(v2); } -value_type ParserInt::Shr(value_type v1, value_type v2) { return Round(v1) >> Round(v2); } -value_type ParserInt::Shl(value_type v1, value_type v2) { return Round(v1) << Round(v2); } -value_type ParserInt::LogAnd(value_type v1, value_type v2) { return Round(v1) & Round(v2); } -value_type ParserInt::LogOr(value_type v1, value_type v2) { return Round(v1) | Round(v2); } -value_type ParserInt::And(value_type v1, value_type v2) { return Round(v1) && Round(v2); } -value_type ParserInt::Or(value_type v1, value_type v2) { return Round(v1) || Round(v2); } -value_type ParserInt::Less(value_type v1, value_type v2) { return Round(v1) < Round(v2); } -value_type ParserInt::Greater(value_type v1, value_type v2) { return Round(v1) > Round(v2); } -value_type ParserInt::LessEq(value_type v1, value_type v2) { return Round(v1) <= Round(v2); } -value_type ParserInt::GreaterEq(value_type v1, value_type v2) { return Round(v1) >= Round(v2); } -value_type ParserInt::Equal(value_type v1, value_type v2) { return Round(v1) == Round(v2); } -value_type ParserInt::NotEqual(value_type v1, value_type v2) { return Round(v1) != Round(v2); } -value_type ParserInt::Not(value_type v) { return !Round(v); } - -value_type ParserInt::Pow(value_type v1, value_type v2) -{ - return std::pow((double)Round(v1), (double)Round(v2)); -} - -//--------------------------------------------------------------------------- -// Unary operator Callbacks: Infix operators -value_type ParserInt::UnaryMinus(value_type v) -{ - return -Round(v); -} - -//--------------------------------------------------------------------------- -value_type ParserInt::Sum(const value_type* a_afArg, int a_iArgc) -{ - if (!a_iArgc) - throw ParserError(_T("too few arguments for function sum.")); - - value_type fRes=0; - for (int i=0; i<a_iArgc; ++i) - fRes += a_afArg[i]; - - return fRes; -} - -//--------------------------------------------------------------------------- -value_type ParserInt::Min(const value_type* a_afArg, int a_iArgc) -{ - if (!a_iArgc) - throw ParserError( _T("too few arguments for function min.") ); - - value_type fRes=a_afArg[0]; - for (int i=0; i<a_iArgc; ++i) - fRes = std::min(fRes, a_afArg[i]); - - return fRes; -} - -//--------------------------------------------------------------------------- -value_type ParserInt::Max(const value_type* a_afArg, int a_iArgc) -{ - if (!a_iArgc) - throw ParserError(_T("too few arguments for function min.")); - - value_type fRes=a_afArg[0]; - for (int i=0; i<a_iArgc; ++i) - fRes = std::max(fRes, a_afArg[i]); - - return fRes; -} - -//--------------------------------------------------------------------------- -// Default value recognition callback -int ParserInt::IsVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal) -{ - string_type buf(a_szExpr); - std::size_t pos = buf.find_first_not_of(_T("0123456789")); - - if (pos==std::string::npos) - return 0; - - stringstream_type stream( buf.substr(0, pos ) ); - int iVal(0); - - stream >> iVal; - if (stream.fail()) - return 0; - - stringstream_type::pos_type iEnd = stream.tellg(); // Position after reading - if (stream.fail()) - iEnd = stream.str().length(); - - if (iEnd==(stringstream_type::pos_type)-1) - return 0; - - *a_iPos += (int)iEnd; - *a_fVal = (value_type)iVal; - return 1; -} - -//--------------------------------------------------------------------------- -/** \brief Check a given position in the expression for the presence of - a hex value. - \param a_szExpr Pointer to the expression string - \param [in/out] a_iPos Pointer to an integer value holding the current parsing - position in the expression. - \param [out] a_fVal Pointer to the position where the detected value shall be stored. - - Hey values must be prefixed with "0x" in order to be detected properly. -*/ -int ParserInt::IsHexVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal) -{ - if (a_szExpr[1]==0 || (a_szExpr[0]!='0' || a_szExpr[1]!='x') ) - return 0; - - unsigned iVal(0); - - // New code based on streams for UNICODE compliance: - stringstream_type::pos_type nPos(0); - stringstream_type ss(a_szExpr + 2); - ss >> std::hex >> iVal; - nPos = ss.tellg(); - - if (nPos==(stringstream_type::pos_type)0) - return 1; - - *a_iPos += (int)(2 + nPos); - *a_fVal = (value_type)iVal; - return 1; -} - -//--------------------------------------------------------------------------- -int ParserInt::IsBinVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal) -{ - if (a_szExpr[0]!='#') - return 0; - - unsigned iVal(0), - iBits(sizeof(iVal)*8), - i(0); - - for (i=0; (a_szExpr[i+1]=='0' || a_szExpr[i+1]=='1') && i<iBits; ++i) - iVal |= (int)(a_szExpr[i+1]=='1') << ((iBits-1)-i); - - if (i==0) - return 0; - - if (i==iBits) - throw exception_type(_T("Binary to integer conversion error (overflow).")); - - *a_fVal = (unsigned)(iVal >> (iBits-i) ); - *a_iPos += i+1; - - return 1; -} - -//--------------------------------------------------------------------------- -/** \brief Constructor. - - Call ParserBase class constructor and trigger Function, Operator and Constant initialization. -*/ -ParserInt::ParserInt() - :ParserBase() -{ - AddValIdent(IsVal); // lowest priority - AddValIdent(IsBinVal); - AddValIdent(IsHexVal); // highest priority - - InitCharSets(); - InitFun(); - InitOprt(); -} - -//--------------------------------------------------------------------------- -void ParserInt::InitConst() -{ -} - -//--------------------------------------------------------------------------- -void ParserInt::InitCharSets() -{ - DefineNameChars( _T("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") ); - DefineOprtChars( _T("+-*^/?<>=!%&|~'_") ); - DefineInfixOprtChars( _T("/+-*^?<>=!%&|~'_") ); -} - -//--------------------------------------------------------------------------- -/** \brief Initialize the default functions. */ -void ParserInt::InitFun() -{ - DefineFun( _T("sign"), Sign); - DefineFun( _T("abs"), Abs); - DefineFun( _T("if"), Ite); - DefineFun( _T("sum"), Sum); - DefineFun( _T("min"), Min); - DefineFun( _T("max"), Max); -} - -//--------------------------------------------------------------------------- -/** \brief Initialize operators. */ -void ParserInt::InitOprt() -{ - // disable all built in operators, not all of them useful for integer numbers - // (they don't do rounding of values) - EnableBuiltInOprt(false); - - // Disable all built in operators, they wont work with integer numbers - // since they are designed for floating point numbers - DefineInfixOprt( _T("-"), UnaryMinus); - DefineInfixOprt( _T("!"), Not); - - DefineOprt( _T("&"), LogAnd, prLOGIC); - DefineOprt( _T("|"), LogOr, prLOGIC); - DefineOprt( _T("&&"), And, prLOGIC); - DefineOprt( _T("||"), Or, prLOGIC); - - DefineOprt( _T("<"), Less, prCMP); - DefineOprt( _T(">"), Greater, prCMP); - DefineOprt( _T("<="), LessEq, prCMP); - DefineOprt( _T(">="), GreaterEq, prCMP); - DefineOprt( _T("=="), Equal, prCMP); - DefineOprt( _T("!="), NotEqual, prCMP); - - DefineOprt( _T("+"), Add, prADD_SUB); - DefineOprt( _T("-"), Sub, prADD_SUB); - - DefineOprt( _T("*"), Mul, prMUL_DIV); - DefineOprt( _T("/"), Div, prMUL_DIV); - DefineOprt( _T("%"), Mod, prMUL_DIV); - - DefineOprt( _T("^"), Pow, prPOW, oaRIGHT); - DefineOprt( _T(">>"), Shr, prMUL_DIV+1); - DefineOprt( _T("<<"), Shl, prMUL_DIV+1); -} - -} // namespace mu +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParserInt.h" + +#include <cmath> +#include <algorithm> +#include <numeric> + +using namespace std; + +/** \file + \brief Implementation of a parser using integer value. +*/ + +/** \brief Namespace for mathematical applications. */ +namespace mu +{ + value_type ParserInt::Abs(value_type v) { return (value_type)Round(fabs((double)v)); } + value_type ParserInt::Sign(value_type v) { return (Round(v) < 0) ? -1 : (Round(v) > 0) ? 1 : 0; } + value_type ParserInt::Ite(value_type v1, value_type v2, value_type v3) { return (Round(v1) == 1) ? Round(v2) : Round(v3); } + value_type ParserInt::Add(value_type v1, value_type v2) { return Round(v1) + Round(v2); } + value_type ParserInt::Sub(value_type v1, value_type v2) { return Round(v1) - Round(v2); } + value_type ParserInt::Mul(value_type v1, value_type v2) { return Round(v1) * Round(v2); } + value_type ParserInt::Div(value_type v1, value_type v2) { return Round(v1) / Round(v2); } + value_type ParserInt::Mod(value_type v1, value_type v2) { return Round(v1) % Round(v2); } + value_type ParserInt::Shr(value_type v1, value_type v2) { return Round(v1) >> Round(v2); } + value_type ParserInt::Shl(value_type v1, value_type v2) { return Round(v1) << Round(v2); } + value_type ParserInt::LogAnd(value_type v1, value_type v2) { return Round(v1) & Round(v2); } + value_type ParserInt::LogOr(value_type v1, value_type v2) { return Round(v1) | Round(v2); } + value_type ParserInt::And(value_type v1, value_type v2) { return Round(v1) && Round(v2); } + value_type ParserInt::Or(value_type v1, value_type v2) { return Round(v1) || Round(v2); } + value_type ParserInt::Less(value_type v1, value_type v2) { return Round(v1) < Round(v2); } + value_type ParserInt::Greater(value_type v1, value_type v2) { return Round(v1) > Round(v2); } + value_type ParserInt::LessEq(value_type v1, value_type v2) { return Round(v1) <= Round(v2); } + value_type ParserInt::GreaterEq(value_type v1, value_type v2) { return Round(v1) >= Round(v2); } + value_type ParserInt::Equal(value_type v1, value_type v2) { return Round(v1) == Round(v2); } + value_type ParserInt::NotEqual(value_type v1, value_type v2) { return Round(v1) != Round(v2); } + value_type ParserInt::Not(value_type v) { return !Round(v); } + + value_type ParserInt::Pow(value_type v1, value_type v2) + { + return std::pow((double)Round(v1), (double)Round(v2)); + } + + + value_type ParserInt::UnaryMinus(value_type v) + { + return -Round(v); + } + + + value_type ParserInt::Sum(const value_type* a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw ParserError(_T("too few arguments for function sum.")); + + value_type fRes = 0; + for (int i = 0; i < a_iArgc; ++i) + fRes += a_afArg[i]; + + return fRes; + } + + + value_type ParserInt::Min(const value_type* a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw ParserError(_T("too few arguments for function min.")); + + value_type fRes = a_afArg[0]; + for (int i = 0; i < a_iArgc; ++i) + fRes = std::min(fRes, a_afArg[i]); + + return fRes; + } + + + value_type ParserInt::Max(const value_type* a_afArg, int a_iArgc) + { + if (!a_iArgc) + throw ParserError(_T("too few arguments for function min.")); + + value_type fRes = a_afArg[0]; + for (int i = 0; i < a_iArgc; ++i) + fRes = std::max(fRes, a_afArg[i]); + + return fRes; + } + + + int ParserInt::IsVal(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal) + { + string_type buf(a_szExpr); + std::size_t pos = buf.find_first_not_of(_T("0123456789")); + + if (pos == std::string::npos) + return 0; + + stringstream_type stream(buf.substr(0, pos)); + int iVal(0); + + stream >> iVal; + if (stream.fail()) + return 0; + + stringstream_type::pos_type iEnd = stream.tellg(); // Position after reading + if (stream.fail()) + iEnd = stream.str().length(); + + if (iEnd == (stringstream_type::pos_type) - 1) + return 0; + + *a_iPos += (int)iEnd; + *a_fVal = (value_type)iVal; + return 1; + } + + + /** \brief Check a given position in the expression for the presence of + a hex value. + \param a_szExpr Pointer to the expression string + \param [in/out] a_iPos Pointer to an integer value holding the current parsing + position in the expression. + \param [out] a_fVal Pointer to the position where the detected value shall be stored. + + Hey values must be prefixed with "0x" in order to be detected properly. + */ + int ParserInt::IsHexVal(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal) + { + if (a_szExpr[1] == 0 || (a_szExpr[0] != '0' || a_szExpr[1] != 'x')) + return 0; + + unsigned iVal(0); + + // New code based on streams for UNICODE compliance: + stringstream_type::pos_type nPos(0); + stringstream_type ss(a_szExpr + 2); + ss >> std::hex >> iVal; + nPos = ss.tellg(); + + if (nPos == (stringstream_type::pos_type)0) + return 1; + + *a_iPos += (int)(2 + nPos); + *a_fVal = (value_type)iVal; + return 1; + } + + + int ParserInt::IsBinVal(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal) + { + if (a_szExpr[0] != '#') + return 0; + + unsigned iVal(0), + iBits(sizeof(iVal) * 8), + i(0); + + for (i = 0; (a_szExpr[i + 1] == '0' || a_szExpr[i + 1] == '1') && i < iBits; ++i) + iVal |= (int)(a_szExpr[i + 1] == '1') << ((iBits - 1) - i); + + if (i == 0) + return 0; + + if (i == iBits) + throw exception_type(_T("Binary to integer conversion error (overflow).")); + + *a_fVal = (unsigned)(iVal >> (iBits - i)); + *a_iPos += i + 1; + + return 1; + } + + + /** \brief Constructor. + + Call ParserBase class constructor and trigger Function, Operator and Constant initialization. + */ + ParserInt::ParserInt() + :ParserBase() + { + AddValIdent(IsVal); // lowest priority + AddValIdent(IsBinVal); + AddValIdent(IsHexVal); // highest priority + + InitCharSets(); + InitFun(); + InitOprt(); + } + + + void ParserInt::InitConst() + { + } + + + void ParserInt::InitCharSets() + { + DefineNameChars(_T("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")); + DefineOprtChars(_T("+-*^/?<>=!%&|~'_")); + DefineInfixOprtChars(_T("/+-*^?<>=!%&|~'_")); + } + + + /** \brief Initialize the default functions. */ + void ParserInt::InitFun() + { + DefineFun(_T("sign"), Sign); + DefineFun(_T("abs"), Abs); + DefineFun(_T("if"), Ite); + DefineFun(_T("sum"), Sum); + DefineFun(_T("min"), Min); + DefineFun(_T("max"), Max); + } + + + /** \brief Initialize operators. */ + void ParserInt::InitOprt() + { + // disable all built in operators, not all of them useful for integer numbers + // (they don't do rounding of values) + EnableBuiltInOprt(false); + + // Disable all built in operators, they won't work with integer numbers + // since they are designed for floating point numbers + DefineInfixOprt(_T("-"), UnaryMinus); + DefineInfixOprt(_T("!"), Not); + + DefineOprt(_T("&"), LogAnd, prLOGIC); + DefineOprt(_T("|"), LogOr, prLOGIC); + DefineOprt(_T("&&"), And, prLOGIC); + DefineOprt(_T("||"), Or, prLOGIC); + + DefineOprt(_T("<"), Less, prCMP); + DefineOprt(_T(">"), Greater, prCMP); + DefineOprt(_T("<="), LessEq, prCMP); + DefineOprt(_T(">="), GreaterEq, prCMP); + DefineOprt(_T("=="), Equal, prCMP); + DefineOprt(_T("!="), NotEqual, prCMP); + + DefineOprt(_T("+"), Add, prADD_SUB); + DefineOprt(_T("-"), Sub, prADD_SUB); + + DefineOprt(_T("*"), Mul, prMUL_DIV); + DefineOprt(_T("/"), Div, prMUL_DIV); + DefineOprt(_T("%"), Mod, prMUL_DIV); + + DefineOprt(_T("^"), Pow, prPOW, oaRIGHT); + DefineOprt(_T(">>"), Shr, prMUL_DIV + 1); + DefineOprt(_T("<<"), Shl, prMUL_DIV + 1); + } + +} // namespace mu diff --git a/3rdParty/MuParser/src/muParserTest.cpp b/3rdParty/MuParser/src/muParserTest.cpp index dce8afbabbac0d4a0852ae699851bd8b0ed669d5..75fbdf5f6aa2bf8f32c215d8d0436de457aa62e7 100644 --- a/3rdParty/MuParser/src/muParserTest.cpp +++ b/3rdParty/MuParser/src/muParserTest.cpp @@ -1,1552 +1,1597 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2013 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. -*/ - -#include "muParserTest.h" - -#include <cstdio> -#include <cmath> -#include <iostream> -#include <limits> - -#define PARSER_CONST_PI 3.141592653589793238462643 -#define PARSER_CONST_E 2.718281828459045235360287 - -using namespace std; - -/** \file - \brief This file contains the implementation of parser test cases. -*/ - -namespace mu -{ - namespace Test - { - int ParserTester::c_iCount = 0; - - //--------------------------------------------------------------------------------------------- - ParserTester::ParserTester() - :m_vTestFun() - { - AddTest(&ParserTester::TestNames); - AddTest(&ParserTester::TestSyntax); - AddTest(&ParserTester::TestPostFix); - AddTest(&ParserTester::TestInfixOprt); - AddTest(&ParserTester::TestVarConst); - AddTest(&ParserTester::TestMultiArg); - AddTest(&ParserTester::TestExpression); - AddTest(&ParserTester::TestIfThenElse); - AddTest(&ParserTester::TestInterface); - AddTest(&ParserTester::TestBinOprt); - AddTest(&ParserTester::TestException); - AddTest(&ParserTester::TestStrArg); - AddTest(&ParserTester::TestBulkMode); - - ParserTester::c_iCount = 0; - } - - //--------------------------------------------------------------------------------------------- - int ParserTester::IsHexVal(const char_type *a_szExpr, int *a_iPos, value_type *a_fVal) - { - if (a_szExpr[1]==0 || (a_szExpr[0]!='0' || a_szExpr[1]!='x') ) - return 0; - - unsigned iVal(0); - - // New code based on streams for UNICODE compliance: - stringstream_type::pos_type nPos(0); - stringstream_type ss(a_szExpr + 2); - ss >> std::hex >> iVal; - nPos = ss.tellg(); - - if (nPos==(stringstream_type::pos_type)0) - return 1; - - *a_iPos += (int)(2 + nPos); - *a_fVal = (value_type)iVal; - return 1; - } - - //--------------------------------------------------------------------------------------------- - int ParserTester::TestInterface() - { - int iStat = 0; - mu::console() << _T("testing member functions..."); - - // Test RemoveVar - value_type afVal[3] = {1,2,3}; - Parser p; - - try - { - p.DefineVar( _T("a"), &afVal[0]); - p.DefineVar( _T("b"), &afVal[1]); - p.DefineVar( _T("c"), &afVal[2]); - p.SetExpr( _T("a+b+c") ); - p.Eval(); - } - catch(...) - { - iStat += 1; // this is not supposed to happen - } - - try - { - p.RemoveVar( _T("c") ); - p.Eval(); - iStat += 1; // not supposed to reach this, nonexisting variable "c" deleted... - } - catch(...) - { - // failure is expected... - } - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------------------------- - int ParserTester::TestStrArg() - { - int iStat = 0; - mu::console() << _T("testing string arguments..."); - - iStat += EqnTest(_T("valueof(\"\")"), 123, true); // empty string arguments caused a crash - iStat += EqnTest(_T("valueof(\"aaa\")+valueof(\"bbb\") "), 246, true); - iStat += EqnTest(_T("2*(valueof(\"aaa\")-23)+valueof(\"bbb\")"), 323, true); - // use in expressions with variables - iStat += EqnTest(_T("a*(atof(\"10\")-b)"), 8, true); - iStat += EqnTest(_T("a-(atof(\"10\")*b)"), -19, true); - // string + numeric arguments - iStat += EqnTest(_T("strfun1(\"100\")"), 100, true); - iStat += EqnTest(_T("strfun2(\"100\",1)"), 101, true); - iStat += EqnTest(_T("strfun3(\"99\",1,2)"), 102, true); - // string constants - iStat += EqnTest(_T("atof(str1)+atof(str2)"), 3.33, true); - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------------------------- - int ParserTester::TestBulkMode() - { - int iStat = 0; - mu::console() << _T("testing bulkmode..."); - -#define EQN_TEST_BULK(EXPR, R1, R2, R3, R4, PASS) \ - { \ - double res[] = { R1, R2, R3, R4 }; \ - iStat += EqnTestBulk(_T(EXPR), res, (PASS)); \ - } - - // Bulk Variables for the test: - // a: 1,2,3,4 - // b: 2,2,2,2 - // c: 3,3,3,3 - // d: 5,4,3,2 - EQN_TEST_BULK("a", 1, 1, 1, 1, false) - EQN_TEST_BULK("a", 1, 2, 3, 4, true) - EQN_TEST_BULK("b=a", 1, 2, 3, 4, true) - EQN_TEST_BULK("b=a, b*10", 10, 20, 30, 40, true) - EQN_TEST_BULK("b=a, b*10, a", 1, 2, 3, 4, true) - EQN_TEST_BULK("a+b", 3, 4, 5, 6, true) - EQN_TEST_BULK("c*(a+b)", 9, 12, 15, 18, true) -#undef EQN_TEST_BULK - - if (iStat == 0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------------------------- - int ParserTester::TestBinOprt() - { - int iStat = 0; - mu::console() << _T("testing binary operators..."); - - // built in operators - // xor operator - - iStat += EqnTest(_T("a++b"), 3, true); - iStat += EqnTest(_T("a ++ b"), 3, true); - iStat += EqnTest(_T("1++2"), 3, true); - iStat += EqnTest(_T("1 ++ 2"), 3, true); - iStat += EqnTest(_T("a add b"), 3, true); - iStat += EqnTest(_T("1 add 2"), 3, true); - iStat += EqnTest(_T("a<b"), 1, true); - iStat += EqnTest(_T("b>a"), 1, true); - iStat += EqnTest(_T("a>a"), 0, true); - iStat += EqnTest(_T("a<a"), 0, true); - iStat += EqnTest(_T("a>a"), 0, true); - iStat += EqnTest(_T("a<=a"), 1, true); - iStat += EqnTest(_T("a<=b"), 1, true); - iStat += EqnTest(_T("b<=a"), 0, true); - iStat += EqnTest(_T("a>=a"), 1, true); - iStat += EqnTest(_T("b>=a"), 1, true); - iStat += EqnTest(_T("a>=b"), 0, true); - - // Test logical operators, especially if user defined "&" and the internal "&&" collide - iStat += EqnTest(_T("1 && 1"), 1, true); - iStat += EqnTest(_T("1 && 0"), 0, true); - iStat += EqnTest(_T("(a<b) && (b>a)"), 1, true); - iStat += EqnTest(_T("(a<b) && (a>b)"), 0, true); - //iStat += EqnTest(_T("12 and 255"), 12, true); - //iStat += EqnTest(_T("12 and 0"), 0, true); - iStat += EqnTest(_T("12 & 255"), 12, true); - iStat += EqnTest(_T("12 & 0"), 0, true); - iStat += EqnTest(_T("12&255"), 12, true); - iStat += EqnTest(_T("12&0"), 0, true); - - // Assignment operator - iStat += EqnTest(_T("a = b"), 2, true); - iStat += EqnTest(_T("a = sin(b)"), 0.909297, true); - iStat += EqnTest(_T("a = 1+sin(b)"), 1.909297, true); - iStat += EqnTest(_T("(a=b)*2"), 4, true); - iStat += EqnTest(_T("2*(a=b)"), 4, true); - iStat += EqnTest(_T("2*(a=b+1)"), 6, true); - iStat += EqnTest(_T("(a=b+1)*2"), 6, true); - iStat += EqnTest(_T("a=c, a*10"), 30, true); - - iStat += EqnTest(_T("2^2^3"), 256, true); - iStat += EqnTest(_T("1/2/3"), 1.0/6.0, true); - - // reference: http://www.wolframalpha.com/input/?i=3%2B4*2%2F%281-5%29^2^3 - iStat += EqnTest(_T("3+4*2/(1-5)^2^3"), 3.0001220703125, true); - - // Test user defined binary operators - iStat += EqnTestInt(_T("1 | 2"), 3, true); - iStat += EqnTestInt(_T("1 || 2"), 1, true); - iStat += EqnTestInt(_T("123 & 456"), 72, true); - iStat += EqnTestInt(_T("(123 & 456) % 10"), 2, true); - iStat += EqnTestInt(_T("1 && 0"), 0, true); - iStat += EqnTestInt(_T("123 && 456"), 1, true); - iStat += EqnTestInt(_T("1 << 3"), 8, true); - iStat += EqnTestInt(_T("8 >> 3"), 1, true); - iStat += EqnTestInt(_T("9 / 4"), 2, true); - iStat += EqnTestInt(_T("9 % 4"), 1, true); - iStat += EqnTestInt(_T("if(5%2,1,0)"), 1, true); - iStat += EqnTestInt(_T("if(4%2,1,0)"), 0, true); - iStat += EqnTestInt(_T("-10+1"), -9, true); - iStat += EqnTestInt(_T("1+2*3"), 7, true); - iStat += EqnTestInt(_T("const1 != const2"), 1, true); - iStat += EqnTestInt(_T("const1 != const2"), 0, false); - iStat += EqnTestInt(_T("const1 == const2"), 0, true); - iStat += EqnTestInt(_T("const1 == 1"), 1, true); - iStat += EqnTestInt(_T("10*(const1 == 1)"), 10, true); - iStat += EqnTestInt(_T("2*(const1 | const2)"), 6, true); - iStat += EqnTestInt(_T("2*(const1 | const2)"), 7, false); - iStat += EqnTestInt(_T("const1 < const2"), 1, true); - iStat += EqnTestInt(_T("const2 > const1"), 1, true); - iStat += EqnTestInt(_T("const1 <= 1"), 1, true); - iStat += EqnTestInt(_T("const2 >= 2"), 1, true); - iStat += EqnTestInt(_T("2*(const1 + const2)"), 6, true); - iStat += EqnTestInt(_T("2*(const1 - const2)"), -2, true); - iStat += EqnTestInt(_T("a != b"), 1, true); - iStat += EqnTestInt(_T("a != b"), 0, false); - iStat += EqnTestInt(_T("a == b"), 0, true); - iStat += EqnTestInt(_T("a == 1"), 1, true); - iStat += EqnTestInt(_T("10*(a == 1)"), 10, true); - iStat += EqnTestInt(_T("2*(a | b)"), 6, true); - iStat += EqnTestInt(_T("2*(a | b)"), 7, false); - iStat += EqnTestInt(_T("a < b"), 1, true); - iStat += EqnTestInt(_T("b > a"), 1, true); - iStat += EqnTestInt(_T("a <= 1"), 1, true); - iStat += EqnTestInt(_T("b >= 2"), 1, true); - iStat += EqnTestInt(_T("2*(a + b)"), 6, true); - iStat += EqnTestInt(_T("2*(a - b)"), -2, true); - iStat += EqnTestInt(_T("a + (a << b)"), 5, true); - iStat += EqnTestInt(_T("-2^2"), -4, true); - iStat += EqnTestInt(_T("3--a"), 4, true); - iStat += EqnTestInt(_T("3+-3^2"), -6, true); - - // Test reading of hex values: - iStat += EqnTestInt(_T("0xff"), 255, true); - iStat += EqnTestInt(_T("10+0xff"), 265, true); - iStat += EqnTestInt(_T("0xff+10"), 265, true); - iStat += EqnTestInt(_T("10*0xff"), 2550, true); - iStat += EqnTestInt(_T("0xff*10"), 2550, true); - iStat += EqnTestInt(_T("10+0xff+1"), 266, true); - iStat += EqnTestInt(_T("1+0xff+10"), 266, true); - -// incorrect: '^' is yor here, not power -// iStat += EqnTestInt("-(1+2)^2", -9, true); -// iStat += EqnTestInt("-1^3", -1, true); - - // Test precedence - // a=1, b=2, c=3 - iStat += EqnTestInt(_T("a + b * c"), 7, true); - iStat += EqnTestInt(_T("a * b + c"), 5, true); - iStat += EqnTestInt(_T("a<b && b>10"), 0, true); - iStat += EqnTestInt(_T("a<b && b<10"), 1, true); - - iStat += EqnTestInt(_T("a + b << c"), 17, true); - iStat += EqnTestInt(_T("a << b + c"), 7, true); - iStat += EqnTestInt(_T("c * b < a"), 0, true); - iStat += EqnTestInt(_T("c * b == 6 * a"), 1, true); - iStat += EqnTestInt(_T("2^2^3"), 256, true); - - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------------------------- - /** \brief Check muParser name restriction enforcement. */ - int ParserTester::TestNames() - { - int iStat= 0, - iErr = 0; - - mu::console() << "testing name restriction enforcement..."; - - Parser p; - - #define PARSER_THROWCHECK(DOMAIN, FAIL, EXPR, ARG) \ - iErr = 0; \ - ParserTester::c_iCount++; \ - try \ - { \ - p.Define##DOMAIN(EXPR, ARG); \ - } \ - catch(Parser::exception_type&) \ - { \ - iErr = (FAIL==false) ? 0 : 1; \ - } \ - iStat += iErr; - - // constant names - PARSER_THROWCHECK(Const, false, _T("0a"), 1) - PARSER_THROWCHECK(Const, false, _T("9a"), 1) - PARSER_THROWCHECK(Const, false, _T("+a"), 1) - PARSER_THROWCHECK(Const, false, _T("-a"), 1) - PARSER_THROWCHECK(Const, false, _T("a-"), 1) - PARSER_THROWCHECK(Const, false, _T("a*"), 1) - PARSER_THROWCHECK(Const, false, _T("a?"), 1) - PARSER_THROWCHECK(Const, true, _T("a"), 1) - PARSER_THROWCHECK(Const, true, _T("a_min"), 1) - PARSER_THROWCHECK(Const, true, _T("a_min0"), 1) - PARSER_THROWCHECK(Const, true, _T("a_min9"), 1) - // variable names - value_type a; - p.ClearConst(); - PARSER_THROWCHECK(Var, false, _T("123abc"), &a) - PARSER_THROWCHECK(Var, false, _T("9a"), &a) - PARSER_THROWCHECK(Var, false, _T("0a"), &a) - PARSER_THROWCHECK(Var, false, _T("+a"), &a) - PARSER_THROWCHECK(Var, false, _T("-a"), &a) - PARSER_THROWCHECK(Var, false, _T("?a"), &a) - PARSER_THROWCHECK(Var, false, _T("!a"), &a) - PARSER_THROWCHECK(Var, false, _T("a+"), &a) - PARSER_THROWCHECK(Var, false, _T("a-"), &a) - PARSER_THROWCHECK(Var, false, _T("a*"), &a) - PARSER_THROWCHECK(Var, false, _T("a?"), &a) - PARSER_THROWCHECK(Var, true, _T("a"), &a) - PARSER_THROWCHECK(Var, true, _T("a_min"), &a) - PARSER_THROWCHECK(Var, true, _T("a_min0"), &a) - PARSER_THROWCHECK(Var, true, _T("a_min9"), &a) - PARSER_THROWCHECK(Var, false, _T("a_min9"), 0) - // Postfix operators - // fail - PARSER_THROWCHECK(PostfixOprt, false, _T("(k"), f1of1) - PARSER_THROWCHECK(PostfixOprt, false, _T("9+"), f1of1) - PARSER_THROWCHECK(PostfixOprt, false, _T("+"), 0) - // pass - PARSER_THROWCHECK(PostfixOprt, true, _T("-a"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("?a"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("_"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("#"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("&&"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("||"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("&"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("|"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("++"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("--"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("?>"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("?<"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("**"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("xor"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("and"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("or"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("not"), f1of1) - PARSER_THROWCHECK(PostfixOprt, true, _T("!"), f1of1) - // Binary operator - // The following must fail with builtin operators activated - // p.EnableBuiltInOp(true); -> this is the default - p.ClearPostfixOprt(); - PARSER_THROWCHECK(Oprt, false, _T("+"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("-"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("*"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("/"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("^"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("&&"), f1of2) - PARSER_THROWCHECK(Oprt, false, _T("||"), f1of2) - // without activated built in operators it should work - p.EnableBuiltInOprt(false); - PARSER_THROWCHECK(Oprt, true, _T("+"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("-"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("*"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("/"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("^"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("&&"), f1of2) - PARSER_THROWCHECK(Oprt, true, _T("||"), f1of2) - #undef PARSER_THROWCHECK - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------- - int ParserTester::TestSyntax() - { - int iStat = 0; - mu::console() << _T("testing syntax engine..."); - - iStat += ThrowTest(_T("1,"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("a,"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("sin(8),"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("(sin(8)),"), ecUNEXPECTED_EOF); // incomplete hex definition - iStat += ThrowTest(_T("a{m},"), ecUNEXPECTED_EOF); // incomplete hex definition - - iStat += EqnTest(_T("(1+ 2*a)"), 3, true); // Spaces within formula - iStat += EqnTest(_T("sqrt((4))"), 2, true); // Multiple brackets - iStat += EqnTest(_T("sqrt((2)+2)"), 2, true);// Multiple brackets - iStat += EqnTest(_T("sqrt(2+(2))"), 2, true);// Multiple brackets - iStat += EqnTest(_T("sqrt(a+(3))"), 2, true);// Multiple brackets - iStat += EqnTest(_T("sqrt((3)+a)"), 2, true);// Multiple brackets - iStat += EqnTest(_T("order(1,2)"), 1, true); // May not cause name collision with operator "or" - iStat += EqnTest(_T("(2+"), 0, false); // missing closing bracket - iStat += EqnTest(_T("2++4"), 0, false); // unexpected operator - iStat += EqnTest(_T("2+-4"), 0, false); // unexpected operator - iStat += EqnTest(_T("(2+)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("--2"), 0, false); // double sign - iStat += EqnTest(_T("ksdfj"), 0, false); // unknown token - iStat += EqnTest(_T("()"), 0, false); // empty bracket without a function - iStat += EqnTest(_T("5+()"), 0, false); // empty bracket without a function - iStat += EqnTest(_T("sin(cos)"), 0, false); // unexpected function - iStat += EqnTest(_T("5t6"), 0, false); // unknown token - iStat += EqnTest(_T("5 t 6"), 0, false); // unknown token - iStat += EqnTest(_T("8*"), 0, false); // unexpected end of formula - iStat += EqnTest(_T(",3"), 0, false); // unexpected comma - iStat += EqnTest(_T("3,5"), 0, false); // unexpected comma - iStat += EqnTest(_T("sin(8,8)"), 0, false); // too many function args - iStat += EqnTest(_T("(7,8)"), 0, false); // too many function args - iStat += EqnTest(_T("sin)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("a)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("pi)"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("sin(())"), 0, false); // unexpected closing bracket - iStat += EqnTest(_T("sin()"), 0, false); // unexpected closing bracket - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------- - int ParserTester::TestVarConst() - { - int iStat = 0; - mu::console() << _T("testing variable/constant detection..."); - - // Test if the result changes when a variable changes - iStat += EqnTestWithVarChange( _T("a"), 1, 1, 2, 2 ); - iStat += EqnTestWithVarChange( _T("2*a"), 2, 4, 3, 6 ); - - // distinguish constants with same basename - iStat += EqnTest( _T("const"), 1, true); - iStat += EqnTest( _T("const1"), 2, true); - iStat += EqnTest( _T("const2"), 3, true); - iStat += EqnTest( _T("2*const"), 2, true); - iStat += EqnTest( _T("2*const1"), 4, true); - iStat += EqnTest( _T("2*const2"), 6, true); - iStat += EqnTest( _T("2*const+1"), 3, true); - iStat += EqnTest( _T("2*const1+1"), 5, true); - iStat += EqnTest( _T("2*const2+1"), 7, true); - iStat += EqnTest( _T("const"), 0, false); - iStat += EqnTest( _T("const1"), 0, false); - iStat += EqnTest( _T("const2"), 0, false); - - // distinguish variables with same basename - iStat += EqnTest( _T("a"), 1, true); - iStat += EqnTest( _T("aa"), 2, true); - iStat += EqnTest( _T("2*a"), 2, true); - iStat += EqnTest( _T("2*aa"), 4, true); - iStat += EqnTest( _T("2*a-1"), 1, true); - iStat += EqnTest( _T("2*aa-1"), 3, true); - - // custom value recognition - iStat += EqnTest( _T("0xff"), 255, true); - iStat += EqnTest( _T("0x97 + 0xff"), 406, true); - - // Finally test querying of used variables - try - { - int idx; - mu::Parser p; - mu::value_type vVarVal[] = { 1, 2, 3, 4, 5}; - p.DefineVar( _T("a"), &vVarVal[0]); - p.DefineVar( _T("b"), &vVarVal[1]); - p.DefineVar( _T("c"), &vVarVal[2]); - p.DefineVar( _T("d"), &vVarVal[3]); - p.DefineVar( _T("e"), &vVarVal[4]); - - // Test lookup of defined variables - // 4 used variables - p.SetExpr( _T("a+b+c+d") ); - mu::varmap_type UsedVar = p.GetUsedVar(); - int iCount = (int)UsedVar.size(); - if (iCount!=4) - throw false; - - // the next check will fail if the parser - // erroneously creates new variables internally - if (p.GetVar().size()!=5) - throw false; - - mu::varmap_type::const_iterator item = UsedVar.begin(); - for (idx=0; item!=UsedVar.end(); ++item) - { - if (&vVarVal[idx++]!=item->second) - throw false; - } - - // Test lookup of undefined variables - p.SetExpr( _T("undef1+undef2+undef3") ); - UsedVar = p.GetUsedVar(); - iCount = (int)UsedVar.size(); - if (iCount!=3) - throw false; - - // the next check will fail if the parser - // erroneously creates new variables internally - if (p.GetVar().size()!=5) - throw false; - - for (item = UsedVar.begin(); item!=UsedVar.end(); ++item) - { - if (item->second!=0) - throw false; // all pointers to undefined variables must be null - } - - // 1 used variables - p.SetExpr( _T("a+b") ); - UsedVar = p.GetUsedVar(); - iCount = (int)UsedVar.size(); - if (iCount!=2) throw false; - item = UsedVar.begin(); - for (idx=0; item!=UsedVar.end(); ++item) - if (&vVarVal[idx++]!=item->second) throw false; - - } - catch(...) - { - iStat += 1; - } - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------- - int ParserTester::TestMultiArg() - { - int iStat = 0; - mu::console() << _T("testing multiarg functions..."); - - // Compound expressions - iStat += EqnTest( _T("1,2,3"), 3, true); - iStat += EqnTest( _T("a,b,c"), 3, true); - iStat += EqnTest( _T("a=10,b=20,c=a*b"), 200, true); - iStat += EqnTest( _T("1,\n2,\n3"), 3, true); - iStat += EqnTest( _T("a,\nb,\nc"), 3, true); - iStat += EqnTest( _T("a=10,\nb=20,\nc=a*b"), 200, true); - iStat += EqnTest( _T("1,\r\n2,\r\n3"), 3, true); - iStat += EqnTest( _T("a,\r\nb,\r\nc"), 3, true); - iStat += EqnTest( _T("a=10,\r\nb=20,\r\nc=a*b"), 200, true); - - // picking the right argument - iStat += EqnTest( _T("f1of1(1)"), 1, true); - iStat += EqnTest( _T("f1of2(1, 2)"), 1, true); - iStat += EqnTest( _T("f2of2(1, 2)"), 2, true); - iStat += EqnTest( _T("f1of3(1, 2, 3)"), 1, true); - iStat += EqnTest( _T("f2of3(1, 2, 3)"), 2, true); - iStat += EqnTest( _T("f3of3(1, 2, 3)"), 3, true); - iStat += EqnTest( _T("f1of4(1, 2, 3, 4)"), 1, true); - iStat += EqnTest( _T("f2of4(1, 2, 3, 4)"), 2, true); - iStat += EqnTest( _T("f3of4(1, 2, 3, 4)"), 3, true); - iStat += EqnTest( _T("f4of4(1, 2, 3, 4)"), 4, true); - iStat += EqnTest( _T("f1of5(1, 2, 3, 4, 5)"), 1, true); - iStat += EqnTest( _T("f2of5(1, 2, 3, 4, 5)"), 2, true); - iStat += EqnTest( _T("f3of5(1, 2, 3, 4, 5)"), 3, true); - iStat += EqnTest( _T("f4of5(1, 2, 3, 4, 5)"), 4, true); - iStat += EqnTest( _T("f5of5(1, 2, 3, 4, 5)"), 5, true); - // Too few arguments / Too many arguments - iStat += EqnTest( _T("1+ping()"), 11, true); - iStat += EqnTest( _T("ping()+1"), 11, true); - iStat += EqnTest( _T("2*ping()"), 20, true); - iStat += EqnTest( _T("ping()*2"), 20, true); - iStat += EqnTest( _T("ping(1,2)"), 0, false); - iStat += EqnTest( _T("1+ping(1,2)"), 0, false); - iStat += EqnTest( _T("f1of1(1,2)"), 0, false); - iStat += EqnTest( _T("f1of1()"), 0, false); - iStat += EqnTest( _T("f1of2(1, 2, 3)"), 0, false); - iStat += EqnTest( _T("f1of2(1)"), 0, false); - iStat += EqnTest( _T("f1of3(1, 2, 3, 4)"), 0, false); - iStat += EqnTest( _T("f1of3(1)"), 0, false); - iStat += EqnTest( _T("f1of4(1, 2, 3, 4, 5)"), 0, false); - iStat += EqnTest( _T("f1of4(1)"), 0, false); - iStat += EqnTest( _T("(1,2,3)"), 0, false); - iStat += EqnTest( _T("1,2,3"), 0, false); - iStat += EqnTest( _T("(1*a,2,3)"), 0, false); - iStat += EqnTest( _T("1,2*a,3"), 0, false); - - // correct calculation of arguments - iStat += EqnTest( _T("min(a, 1)"), 1, true); - iStat += EqnTest( _T("min(3*2, 1)"), 1, true); - iStat += EqnTest( _T("min(3*2, 1)"), 6, false); - iStat += EqnTest( _T("firstArg(2,3,4)"), 2, true); - iStat += EqnTest( _T("lastArg(2,3,4)"), 4, true); - iStat += EqnTest( _T("min(3*a+1, 1)"), 1, true); - iStat += EqnTest( _T("max(3*a+1, 1)"), 4, true); - iStat += EqnTest( _T("max(3*a+1, 1)*2"), 8, true); - iStat += EqnTest( _T("2*max(3*a+1, 1)+2"), 10, true); - - // functions with Variable argument count - iStat += EqnTest( _T("sum(a)"), 1, true); - iStat += EqnTest( _T("sum(1,2,3)"), 6, true); - iStat += EqnTest( _T("sum(a,b,c)"), 6, true); - iStat += EqnTest( _T("sum(1,-max(1,2),3)*2"), 4, true); - iStat += EqnTest( _T("2*sum(1,2,3)"), 12, true); - iStat += EqnTest( _T("2*sum(1,2,3)+2"), 14, true); - iStat += EqnTest( _T("2*sum(-1,2,3)+2"), 10, true); - iStat += EqnTest( _T("2*sum(-1,2,-(-a))+2"), 6, true); - iStat += EqnTest( _T("2*sum(-1,10,-a)+2"), 18, true); - iStat += EqnTest( _T("2*sum(1,2,3)*2"), 24, true); - iStat += EqnTest( _T("sum(1,-max(1,2),3)*2"), 4, true); - iStat += EqnTest( _T("sum(1*3, 4, a+2)"), 10, true); - iStat += EqnTest( _T("sum(1*3, 2*sum(1,2,2), a+2)"), 16, true); - iStat += EqnTest( _T("sum(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2)"), 24, true); - - // some failures - iStat += EqnTest( _T("sum()"), 0, false); - iStat += EqnTest( _T("sum(,)"), 0, false); - iStat += EqnTest( _T("sum(1,2,)"), 0, false); - iStat += EqnTest( _T("sum(,1,2)"), 0, false); - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - - //--------------------------------------------------------------------------- - int ParserTester::TestInfixOprt() - { - int iStat(0); - mu::console() << "testing infix operators..."; - - iStat += EqnTest( _T("+1"), +1, true); - iStat += EqnTest( _T("-(+1)"), -1, true); - iStat += EqnTest( _T("-(+1)*2"), -2, true); - iStat += EqnTest( _T("-(+2)*sqrt(4)"), -4, true); - iStat += EqnTest( _T("3-+a"), 2, true); - iStat += EqnTest( _T("+1*3"), 3, true); - - iStat += EqnTest( _T("-1"), -1, true); - iStat += EqnTest( _T("-(-1)"), 1, true); - iStat += EqnTest( _T("-(-1)*2"), 2, true); - iStat += EqnTest( _T("-(-2)*sqrt(4)"), 4, true); - iStat += EqnTest( _T("-_pi"), -PARSER_CONST_PI, true); - iStat += EqnTest( _T("-a"), -1, true); - iStat += EqnTest( _T("-(a)"), -1, true); - iStat += EqnTest( _T("-(-a)"), 1, true); - iStat += EqnTest( _T("-(-a)*2"), 2, true); - iStat += EqnTest( _T("-(8)"), -8, true); - iStat += EqnTest( _T("-8"), -8, true); - iStat += EqnTest( _T("-(2+1)"), -3, true); - iStat += EqnTest( _T("-(f1of1(1+2*3)+1*2)"), -9, true); - iStat += EqnTest( _T("-(-f1of1(1+2*3)+1*2)"), 5, true); - iStat += EqnTest( _T("-sin(8)"), -0.989358, true); - iStat += EqnTest( _T("3-(-a)"), 4, true); - iStat += EqnTest( _T("3--a"), 4, true); - iStat += EqnTest( _T("-1*3"), -3, true); - - // Postfix / infix priorities - iStat += EqnTest( _T("~2#"), 8, true); - iStat += EqnTest( _T("~f1of1(2)#"), 8, true); - iStat += EqnTest( _T("~(b)#"), 8, true); - iStat += EqnTest( _T("(~b)#"), 12, true); - iStat += EqnTest( _T("~(2#)"), 8, true); - iStat += EqnTest( _T("~(f1of1(2)#)"), 8, true); - // - iStat += EqnTest( _T("-2^2"),-4, true); - iStat += EqnTest( _T("-(a+b)^2"),-9, true); - iStat += EqnTest( _T("(-3)^2"),9, true); - iStat += EqnTest( _T("-(-2^2)"),4, true); - iStat += EqnTest( _T("3+-3^2"),-6, true); - // The following assumes use of sqr as postfix operator ("�") together - // with a sign operator of low priority: - iStat += EqnTest( _T("-2'"), -4, true); - iStat += EqnTest( _T("-(1+1)'"),-4, true); - iStat += EqnTest( _T("2+-(1+1)'"),-2, true); - iStat += EqnTest( _T("2+-2'"), -2, true); - // This is the classic behaviour of the infix sign operator (here: "$") which is - // now deprecated: - iStat += EqnTest( _T("$2^2"),4, true); - iStat += EqnTest( _T("$(a+b)^2"),9, true); - iStat += EqnTest( _T("($3)^2"),9, true); - iStat += EqnTest( _T("$($2^2)"),-4, true); - iStat += EqnTest( _T("3+$3^2"),12, true); - - // infix operators sharing the first few characters - iStat += EqnTest( _T("~ 123"), 123+2, true); - iStat += EqnTest( _T("~~ 123"), 123+2, true); - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - - //--------------------------------------------------------------------------- - int ParserTester::TestPostFix() - { - int iStat = 0; - mu::console() << _T("testing postfix operators..."); - - // application - iStat += EqnTest( _T("3{m}+5"), 5.003, true); - iStat += EqnTest( _T("1000{m}"), 1, true); - iStat += EqnTest( _T("1000 {m}"), 1, true); - iStat += EqnTest( _T("(a){m}"), 1e-3, true); - iStat += EqnTest( _T("a{m}"), 1e-3, true); - iStat += EqnTest( _T("a {m}"), 1e-3, true); - iStat += EqnTest( _T("-(a){m}"), -1e-3, true); - iStat += EqnTest( _T("-2{m}"), -2e-3, true); - iStat += EqnTest( _T("-2 {m}"), -2e-3, true); - iStat += EqnTest( _T("f1of1(1000){m}"), 1, true); - iStat += EqnTest( _T("-f1of1(1000){m}"), -1, true); - iStat += EqnTest( _T("-f1of1(-1000){m}"), 1, true); - iStat += EqnTest( _T("f4of4(0,0,0,1000){m}"), 1, true); - iStat += EqnTest( _T("2+(a*1000){m}"), 3, true); - - // can postfix operators "m" und "meg" be told apart properly? - iStat += EqnTest( _T("2*3000meg+2"), 2*3e9+2, true); - - // some incorrect results - iStat += EqnTest( _T("1000{m}"), 0.1, false); - iStat += EqnTest( _T("(a){m}"), 2, false); - // failure due to syntax checking - iStat += ThrowTest(_T("0x"), ecUNASSIGNABLE_TOKEN); // incomplete hex definition - iStat += ThrowTest(_T("3+"), ecUNEXPECTED_EOF); - iStat += ThrowTest( _T("4 + {m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("{m}4"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("sin({m})"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("{m} {m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("{m}(8)"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("4,{m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("-{m}"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest( _T("2(-{m})"), ecUNEXPECTED_PARENS); - iStat += ThrowTest( _T("2({m})"), ecUNEXPECTED_PARENS); - - iStat += ThrowTest( _T("multi*1.0"), ecUNASSIGNABLE_TOKEN); - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------- - int ParserTester::TestExpression() - { - int iStat = 0; - mu::console() << _T("testing expression samples..."); - - value_type b = 2; - - // Optimization - iStat += EqnTest( _T("2*b*5"), 20, true); - iStat += EqnTest( _T("2*b*5 + 4*b"), 28, true); - iStat += EqnTest( _T("2*a/3"), 2.0/3.0, true); - - // Addition auf cmVARMUL - iStat += EqnTest( _T("3+b"), b+3, true); - iStat += EqnTest( _T("b+3"), b+3, true); - iStat += EqnTest( _T("b*3+2"), b*3+2, true); - iStat += EqnTest( _T("3*b+2"), b*3+2, true); - iStat += EqnTest( _T("2+b*3"), b*3+2, true); - iStat += EqnTest( _T("2+3*b"), b*3+2, true); - iStat += EqnTest( _T("b+3*b"), b+3*b, true); - iStat += EqnTest( _T("3*b+b"), b+3*b, true); - - iStat += EqnTest( _T("2+b*3+b"), 2+b*3+b, true); - iStat += EqnTest( _T("b+2+b*3"), b+2+b*3, true); - - iStat += EqnTest( _T("(2*b+1)*4"), (2*b+1)*4, true); - iStat += EqnTest( _T("4*(2*b+1)"), (2*b+1)*4, true); - - // operator precedences - iStat += EqnTest( _T("1+2-3*4/5^6"), 2.99923, true); - iStat += EqnTest( _T("1^2/3*4-5+6"), 2.33333333, true); - iStat += EqnTest( _T("1+2*3"), 7, true); - iStat += EqnTest( _T("1+2*3"), 7, true); - iStat += EqnTest( _T("(1+2)*3"), 9, true); - iStat += EqnTest( _T("(1+2)*(-3)"), -9, true); - iStat += EqnTest( _T("2/4"), 0.5, true); - - iStat += EqnTest( _T("exp(ln(7))"), 7, true); - iStat += EqnTest( _T("e^ln(7)"), 7, true); - iStat += EqnTest( _T("e^(ln(7))"), 7, true); - iStat += EqnTest( _T("(e^(ln(7)))"), 7, true); - iStat += EqnTest( _T("1-(e^(ln(7)))"), -6, true); - iStat += EqnTest( _T("2*(e^(ln(7)))"), 14, true); - iStat += EqnTest( _T("10^log(5)"), pow(10.0, log(5.0)), true); - iStat += EqnTest( _T("10^log10(5)"), 5, true); - iStat += EqnTest( _T("2^log2(4)"), 4, true); - iStat += EqnTest( _T("-(sin(0)+1)"), -1, true); - iStat += EqnTest( _T("-(2^1.1)"), -2.14354692, true); - - iStat += EqnTest( _T("(cos(2.41)/b)"), -0.372056, true); - iStat += EqnTest( _T("(1*(2*(3*(4*(5*(6*(a+b)))))))"), 2160, true); - iStat += EqnTest( _T("(1*(2*(3*(4*(5*(6*(7*(a+b))))))))"), 15120, true); - iStat += EqnTest( _T("(a/((((b+(((e*(((((pi*((((3.45*((pi+a)+pi))+b)+b)*a))+0.68)+e)+a)/a))+a)+b))+b)*a)-pi))"), 0.00377999, true); - - // long formula (Reference: Matlab) - iStat += EqnTest( - _T("(((-9))-e/(((((((pi-(((-7)+(-3)/4/e))))/(((-5))-2)-((pi+(-0))*(sqrt((e+e))*(-8))*(((-pi)+(-pi)-(-9)*(6*5))") - _T("/(-e)-e))/2)/((((sqrt(2/(-e)+6)-(4-2))+((5/(-2))/(1*(-pi)+3))/8)*pi*((pi/((-2)/(-6)*1*(-1))*(-6)+(-e)))))/") - _T("((e+(-2)+(-e)*((((-3)*9+(-e)))+(-9)))))))-((((e-7+(((5/pi-(3/1+pi)))))/e)/(-5))/(sqrt((((((1+(-7))))+((((-") - _T("e)*(-e)))-8))*(-5)/((-e)))*(-6)-((((((-2)-(-9)-(-e)-1)/3))))/(sqrt((8+(e-((-6))+(9*(-9))))*(((3+2-8))*(7+6") - _T("+(-5))+((0/(-e)*(-pi))+7)))+(((((-e)/e/e)+((-6)*5)*e+(3+(-5)/pi))))+pi))/sqrt((((9))+((((pi))-8+2))+pi))/e") - _T("*4)*((-5)/(((-pi))*(sqrt(e)))))-(((((((-e)*(e)-pi))/4+(pi)*(-9)))))))+(-pi)"), -12.23016549, true); - - // long formula (Reference: Matlab) - iStat += EqnTest( - _T("(atan(sin((((((((((((((((pi/cos((a/((((0.53-b)-pi)*e)/b))))+2.51)+a)-0.54)/0.98)+b)*b)+e)/a)+b)+a)+b)+pi)/e") - _T(")+a)))*2.77)"), -2.16995656, true); - - // long formula (Reference: Matlab) - iStat += EqnTest( _T("1+2-3*4/5^6*(2*(1-5+(3*7^9)*(4+6*7-3)))+12"), -7995810.09926, true); - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - - - //--------------------------------------------------------------------------- - int ParserTester::TestIfThenElse() - { - int iStat = 0; - mu::console() << _T("testing if-then-else operator..."); - - // Test error detection - iStat += ThrowTest(_T(":3"), ecUNEXPECTED_CONDITIONAL); - iStat += ThrowTest(_T("? 1 : 2"), ecUNEXPECTED_CONDITIONAL); - iStat += ThrowTest(_T("(a<b) ? (b<c) ? 1 : 2"), ecMISSING_ELSE_CLAUSE); - iStat += ThrowTest(_T("(a<b) ? 1"), ecMISSING_ELSE_CLAUSE); - iStat += ThrowTest(_T("(a<b) ? a"), ecMISSING_ELSE_CLAUSE); - iStat += ThrowTest(_T("(a<b) ? a+b"), ecMISSING_ELSE_CLAUSE); - iStat += ThrowTest(_T("a : b"), ecMISPLACED_COLON); - iStat += ThrowTest(_T("1 : 2"), ecMISPLACED_COLON); - iStat += ThrowTest(_T("(1) ? 1 : 2 : 3"), ecMISPLACED_COLON); - iStat += ThrowTest(_T("(true) ? 1 : 2 : 3"), ecUNASSIGNABLE_TOKEN); - - iStat += EqnTest(_T("1 ? 128 : 255"), 128, true); - iStat += EqnTest(_T("1<2 ? 128 : 255"), 128, true); - iStat += EqnTest(_T("a<b ? 128 : 255"), 128, true); - iStat += EqnTest(_T("(a<b) ? 128 : 255"), 128, true); - iStat += EqnTest(_T("(1) ? 10 : 11"), 10, true); - iStat += EqnTest(_T("(0) ? 10 : 11"), 11, true); - iStat += EqnTest(_T("(1) ? a+b : c+d"), 3, true); - iStat += EqnTest(_T("(0) ? a+b : c+d"), 1, true); - iStat += EqnTest(_T("(1) ? 0 : 1"), 0, true); - iStat += EqnTest(_T("(0) ? 0 : 1"), 1, true); - iStat += EqnTest(_T("(a<b) ? 10 : 11"), 10, true); - iStat += EqnTest(_T("(a>b) ? 10 : 11"), 11, true); - iStat += EqnTest(_T("(a<b) ? c : d"), 3, true); - iStat += EqnTest(_T("(a>b) ? c : d"), -2, true); - - iStat += EqnTest(_T("(a>b) ? 1 : 0"), 0, true); - iStat += EqnTest(_T("((a>b) ? 1 : 0) ? 1 : 2"), 2, true); - iStat += EqnTest(_T("((a>b) ? 1 : 0) ? 1 : sum((a>b) ? 1 : 2)"), 2, true); - iStat += EqnTest(_T("((a>b) ? 0 : 1) ? 1 : sum((a>b) ? 1 : 2)"), 1, true); - - iStat += EqnTest(_T("sum((a>b) ? 1 : 2)"), 2, true); - iStat += EqnTest(_T("sum((1) ? 1 : 2)"), 1, true); - iStat += EqnTest(_T("sum((a>b) ? 1 : 2, 100)"), 102, true); - iStat += EqnTest(_T("sum((1) ? 1 : 2, 100)"), 101, true); - iStat += EqnTest(_T("sum(3, (a>b) ? 3 : 10)"), 13, true); - iStat += EqnTest(_T("sum(3, (a<b) ? 3 : 10)"), 6, true); - iStat += EqnTest(_T("10*sum(3, (a>b) ? 3 : 10)"), 130, true); - iStat += EqnTest(_T("10*sum(3, (a<b) ? 3 : 10)"), 60, true); - iStat += EqnTest(_T("sum(3, (a>b) ? 3 : 10)*10"), 130, true); - iStat += EqnTest(_T("sum(3, (a<b) ? 3 : 10)*10"), 60, true); - iStat += EqnTest(_T("(a<b) ? sum(3, (a<b) ? 3 : 10)*10 : 99"), 60, true); - iStat += EqnTest(_T("(a>b) ? sum(3, (a<b) ? 3 : 10)*10 : 99"), 99, true); - iStat += EqnTest(_T("(a<b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : 99"), 360, true); - iStat += EqnTest(_T("(a>b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : 99"), 99, true); - iStat += EqnTest(_T("(a>b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : sum(3, (a<b) ? 3 : 10)*10"), 60, true); - - // todo: auch fuer muParserX hinzufuegen! - iStat += EqnTest(_T("(a<b)&&(a<b) ? 128 : 255"), 128, true); - iStat += EqnTest(_T("(a>b)&&(a<b) ? 128 : 255"), 255, true); - iStat += EqnTest(_T("(1<2)&&(1<2) ? 128 : 255"), 128, true); - iStat += EqnTest(_T("(1>2)&&(1<2) ? 128 : 255"), 255, true); - iStat += EqnTest(_T("((1<2)&&(1<2)) ? 128 : 255"), 128, true); - iStat += EqnTest(_T("((1>2)&&(1<2)) ? 128 : 255"), 255, true); - iStat += EqnTest(_T("((a<b)&&(a<b)) ? 128 : 255"), 128, true); - iStat += EqnTest(_T("((a>b)&&(a<b)) ? 128 : 255"), 255, true); - - iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 255, true); - iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 :(1>0 ? 32 : 64)"), 255, true); - iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 128, true); - iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 :(1>2 ? 32 : 64)"), 128, true); - iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 32, true); - iStat += EqnTest(_T("1>2 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 64, true); - iStat += EqnTest(_T("1>0 ? 50 : 1>0 ? 128 : 255"), 50, true); - iStat += EqnTest(_T("1>0 ? 50 : (1>0 ? 128 : 255)"), 50, true); - iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 : 50"), 128, true); - iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 1>2 ? 64 : 16"), 32, true); - iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 :(1>2 ? 64 : 16)"), 32, true); - iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 :1>2 ? 64 : 16"), 255, true); - iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : (1>0 ? 32 :1>2 ? 64 : 16)"), 255, true); - iStat += EqnTest(_T("1 ? 0 ? 128 : 255 : 1 ? 32 : 64"), 255, true); - - // assignment operators - iStat += EqnTest(_T("a= 0 ? 128 : 255, a"), 255, true); - iStat += EqnTest(_T("a=((a>b)&&(a<b)) ? 128 : 255, a"), 255, true); - iStat += EqnTest(_T("c=(a<b)&&(a<b) ? 128 : 255, c"), 128, true); - iStat += EqnTest(_T("0 ? a=a+1 : 666, a"), 1, true); - iStat += EqnTest(_T("1?a=10:a=20, a"), 10, true); - iStat += EqnTest(_T("0?a=10:a=20, a"), 20, true); - iStat += EqnTest(_T("0?a=sum(3,4):10, a"), 1, true); // a should not change its value due to lazy calculation - - iStat += EqnTest(_T("a=1?b=1?3:4:5, a"), 3, true); - iStat += EqnTest(_T("a=1?b=1?3:4:5, b"), 3, true); - iStat += EqnTest(_T("a=0?b=1?3:4:5, a"), 5, true); - iStat += EqnTest(_T("a=0?b=1?3:4:5, b"), 2, true); - - iStat += EqnTest(_T("a=1?5:b=1?3:4, a"), 5, true); - iStat += EqnTest(_T("a=1?5:b=1?3:4, b"), 2, true); - iStat += EqnTest(_T("a=0?5:b=1?3:4, a"), 3, true); - iStat += EqnTest(_T("a=0?5:b=1?3:4, b"), 3, true); - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - //--------------------------------------------------------------------------- - int ParserTester::TestException() - { - int iStat = 0; - mu::console() << _T("testing error codes..."); - - iStat += ThrowTest(_T("3+"), ecUNEXPECTED_EOF); - iStat += ThrowTest(_T("3+)"), ecUNEXPECTED_PARENS); - iStat += ThrowTest(_T("()"), ecUNEXPECTED_PARENS); - iStat += ThrowTest(_T("3+()"), ecUNEXPECTED_PARENS); - iStat += ThrowTest(_T("sin(3,4)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest(_T("sin()"), ecTOO_FEW_PARAMS); - iStat += ThrowTest(_T("(1+2"), ecMISSING_PARENS); - iStat += ThrowTest(_T("sin(3)3"), ecUNEXPECTED_VAL); - iStat += ThrowTest(_T("sin(3)xyz"), ecUNASSIGNABLE_TOKEN); - iStat += ThrowTest(_T("sin(3)cos(3)"), ecUNEXPECTED_FUN); - iStat += ThrowTest(_T("a+b+c=10"), ecUNEXPECTED_OPERATOR); - iStat += ThrowTest(_T("a=b=3"), ecUNEXPECTED_OPERATOR); - -#if defined(MUP_MATH_EXCEPTIONS) - // divide by zero whilst constant folding - iStat += ThrowTest(_T("1/0"), ecDIV_BY_ZERO); - // square root of a negative number - iStat += ThrowTest(_T("sqrt(-1)"), ecDOMAIN_ERROR); - // logarithms of zero - iStat += ThrowTest(_T("ln(0)"), ecDOMAIN_ERROR); - iStat += ThrowTest(_T("log2(0)"), ecDOMAIN_ERROR); - iStat += ThrowTest(_T("log10(0)"), ecDOMAIN_ERROR); - iStat += ThrowTest(_T("log(0)"), ecDOMAIN_ERROR); - // logarithms of negative values - iStat += ThrowTest(_T("ln(-1)"), ecDOMAIN_ERROR); - iStat += ThrowTest(_T("log2(-1)"), ecDOMAIN_ERROR); - iStat += ThrowTest(_T("log10(-1)"), ecDOMAIN_ERROR); - iStat += ThrowTest(_T("log(-1)"), ecDOMAIN_ERROR); -#endif - - // functions without parameter - iStat += ThrowTest( _T("3+ping(2)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("3+ping(a+2)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("3+ping(sin(a)+2)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("3+ping(1+sin(a))"), ecTOO_MANY_PARAMS); - - // String function related - iStat += ThrowTest( _T("valueof(\"xxx\")"), 999, false); - iStat += ThrowTest( _T("valueof()"), ecUNEXPECTED_PARENS); - iStat += ThrowTest( _T("1+valueof(\"abc\""), ecMISSING_PARENS); - iStat += ThrowTest( _T("valueof(\"abc\""), ecMISSING_PARENS); - iStat += ThrowTest( _T("valueof(\"abc"), ecUNTERMINATED_STRING); - iStat += ThrowTest( _T("valueof(\"abc\",3)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("valueof(3)"), ecSTRING_EXPECTED); - iStat += ThrowTest( _T("sin(\"abc\")"), ecVAL_EXPECTED); - iStat += ThrowTest( _T("valueof(\"\\\"abc\\\"\")"), 999, false); - iStat += ThrowTest( _T("\"hello world\""), ecSTR_RESULT); - iStat += ThrowTest( _T("(\"hello world\")"), ecSTR_RESULT); - iStat += ThrowTest( _T("\"abcd\"+100"), ecOPRT_TYPE_CONFLICT); - iStat += ThrowTest( _T("\"a\"+\"b\""), ecOPRT_TYPE_CONFLICT); - iStat += ThrowTest( _T("strfun1(\"100\",3)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("strfun2(\"100\",3,5)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("strfun3(\"100\",3,5,6)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("strfun2(\"100\")"), ecTOO_FEW_PARAMS); - iStat += ThrowTest( _T("strfun3(\"100\",6)"), ecTOO_FEW_PARAMS); - iStat += ThrowTest( _T("strfun2(1,1)"), ecSTRING_EXPECTED); - iStat += ThrowTest( _T("strfun2(a,1)"), ecSTRING_EXPECTED); - iStat += ThrowTest( _T("strfun2(1,1,1)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("strfun2(a,1,1)"), ecTOO_MANY_PARAMS); - iStat += ThrowTest( _T("strfun3(1,2,3)"), ecSTRING_EXPECTED); - iStat += ThrowTest( _T("strfun3(1, \"100\",3)"), ecSTRING_EXPECTED); - iStat += ThrowTest( _T("strfun3(\"1\", \"100\",3)"), ecVAL_EXPECTED); - iStat += ThrowTest( _T("strfun3(\"1\", 3, \"100\")"), ecVAL_EXPECTED); - iStat += ThrowTest( _T("strfun3(\"1\", \"100\", \"100\", \"100\")"), ecTOO_MANY_PARAMS); - - // assignment operator - iStat += ThrowTest( _T("3=4"), ecUNEXPECTED_OPERATOR); - iStat += ThrowTest( _T("sin(8)=4"), ecUNEXPECTED_OPERATOR); - iStat += ThrowTest( _T("\"test\"=a"), ecUNEXPECTED_OPERATOR); - - // <ibg 20090529> - // this is now legal, for reference see: - // https://sourceforge.net/forum/message.php?msg_id=7411373 - // iStat += ThrowTest( _T("sin=9"), ecUNEXPECTED_OPERATOR); - // </ibg> - - iStat += ThrowTest( _T("(8)=5"), ecUNEXPECTED_OPERATOR); - iStat += ThrowTest( _T("(a)=5"), ecUNEXPECTED_OPERATOR); - iStat += ThrowTest( _T("a=\"tttt\""), ecOPRT_TYPE_CONFLICT); - - if (iStat==0) - mu::console() << _T("passed") << endl; - else - mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; - - return iStat; - } - - - //--------------------------------------------------------------------------- - void ParserTester::AddTest(testfun_type a_pFun) - { - m_vTestFun.push_back(a_pFun); - } - - //--------------------------------------------------------------------------- - void ParserTester::Run() - { - int iStat = 0; - try - { - for (int i=0; i<(int)m_vTestFun.size(); ++i) - iStat += (this->*m_vTestFun[i])(); - } - catch(Parser::exception_type &e) - { - mu::console() << "\n" << e.GetMsg() << endl; - mu::console() << e.GetToken() << endl; - Abort(); - } - catch(std::exception &e) - { - mu::console() << e.what() << endl; - Abort(); - } - catch(...) - { - mu::console() << "Internal error"; - Abort(); - } - - if (iStat==0) - { - mu::console() << "Test passed (" << ParserTester::c_iCount << " expressions)" << endl; - } - else - { - mu::console() << "Test failed with " << iStat - << " errors (" << ParserTester::c_iCount - << " expressions)" << endl; - } - ParserTester::c_iCount = 0; - } - - - //--------------------------------------------------------------------------- - int ParserTester::ThrowTest(const string_type &a_str, int a_iErrc, bool a_bFail) - { - ParserTester::c_iCount++; - - try - { - value_type fVal[] = {1,1,1}; - Parser p; - - p.DefineVar( _T("a"), &fVal[0]); - p.DefineVar( _T("b"), &fVal[1]); - p.DefineVar( _T("c"), &fVal[2]); - p.DefinePostfixOprt( _T("{m}"), Milli); - p.DefinePostfixOprt( _T("m"), Milli); - p.DefineFun( _T("ping"), Ping); - p.DefineFun( _T("valueof"), ValueOf); - p.DefineFun( _T("strfun1"), StrFun1); - p.DefineFun( _T("strfun2"), StrFun2); - p.DefineFun( _T("strfun3"), StrFun3); - p.SetExpr(a_str); - p.Eval(); - } - catch(ParserError &e) - { - // output the formula in case of an failed test - if (a_bFail==false || (a_bFail==true && a_iErrc!=e.GetCode()) ) - { - mu::console() << _T("\n ") - << _T("Expression: ") << a_str - << _T(" Code:") << e.GetCode() << _T("(") << e.GetMsg() << _T(")") - << _T(" Expected:") << a_iErrc; - } - - return (a_iErrc==e.GetCode()) ? 0 : 1; - } - - // if a_bFail==false no exception is expected - bool bRet((a_bFail==false) ? 0 : 1); - if (bRet==1) - { - mu::console() << _T("\n ") - << _T("Expression: ") << a_str - << _T(" did evaluate; Expected error:") << a_iErrc; - } - - return bRet; - } - - //--------------------------------------------------------------------------- - /** \brief Evaluate a tet expression. - - \return 1 in case of a failure, 0 otherwise. - */ - int ParserTester::EqnTestWithVarChange(const string_type &a_str, - double a_fVar1, - double a_fRes1, - double a_fVar2, - double a_fRes2) - { - ParserTester::c_iCount++; - - try - { - value_type fVal[2] = {-999, -999 }; // should be equal - - Parser p; - value_type var = 0; - - // variable - p.DefineVar( _T("a"), &var); - p.SetExpr(a_str); - - var = a_fVar1; - fVal[0] = p.Eval(); - - var = a_fVar2; - fVal[1] = p.Eval(); - - if ( fabs(a_fRes1-fVal[0]) > 0.0000000001) - throw std::runtime_error("incorrect result (first pass)"); - - if ( fabs(a_fRes2-fVal[1]) > 0.0000000001) - throw std::runtime_error("incorrect result (second pass)"); - } - catch(Parser::exception_type &e) - { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.GetMsg() << _T(")"); - return 1; - } - catch(std::exception &e) - { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.what() << _T(")"); - return 1; // always return a failure since this exception is not expected - } - catch(...) - { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); - return 1; // exceptions other than ParserException are not allowed - } - - return 0; - } - - //--------------------------------------------------------------------------- - /** \brief Evaluate a tet expression. - - \return 1 in case of a failure, 0 otherwise. - */ - int ParserTester::EqnTest(const string_type &a_str, double a_fRes, bool a_fPass) - { - ParserTester::c_iCount++; - int iRet(0); - value_type fVal[5] = {-999, -998, -997, -996, -995}; // initially should be different - - try - { - std::auto_ptr<Parser> p1; - Parser p2, p3; // three parser objects - // they will be used for testing copy and assignment operators - // p1 is a pointer since i'm going to delete it in order to test if - // parsers after copy construction still refer to members of it. - // !! If this is the case this function will crash !! - - p1.reset(new mu::Parser()); - // Add constants - p1->DefineConst( _T("pi"), (value_type)PARSER_CONST_PI); - p1->DefineConst( _T("e"), (value_type)PARSER_CONST_E); - p1->DefineConst( _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]); - p1->DefineVar( _T("aa"), &vVarVal[1]); - p1->DefineVar( _T("b"), &vVarVal[1]); - p1->DefineVar( _T("c"), &vVarVal[2]); - p1->DefineVar( _T("d"), &vVarVal[3]); - - // custom value ident functions - p1->AddValIdent(&ParserTester::IsHexVal); - - // functions - p1->DefineFun( _T("ping"), Ping); - p1->DefineFun( _T("f1of1"), f1of1); // one parameter - p1->DefineFun( _T("f1of2"), f1of2); // two parameter - p1->DefineFun( _T("f2of2"), f2of2); - p1->DefineFun( _T("f1of3"), f1of3); // three parameter - p1->DefineFun( _T("f2of3"), f2of3); - p1->DefineFun( _T("f3of3"), f3of3); - p1->DefineFun( _T("f1of4"), f1of4); // four parameter - p1->DefineFun( _T("f2of4"), f2of4); - p1->DefineFun( _T("f3of4"), f3of4); - p1->DefineFun( _T("f4of4"), f4of4); - p1->DefineFun( _T("f1of5"), f1of5); // five parameter - p1->DefineFun( _T("f2of5"), f2of5); - p1->DefineFun( _T("f3of5"), f3of5); - p1->DefineFun( _T("f4of5"), f4of5); - p1->DefineFun( _T("f5of5"), f5of5); - - // binary operators - p1->DefineOprt( _T("add"), add, 0); - p1->DefineOprt( _T("++"), add, 0); - p1->DefineOprt( _T("&"), land, prLAND); - - // sample functions - p1->DefineFun( _T("min"), Min); - p1->DefineFun( _T("max"), Max); - p1->DefineFun( _T("sum"), Sum); - p1->DefineFun( _T("valueof"), ValueOf); - p1->DefineFun( _T("atof"), StrToFloat); - p1->DefineFun( _T("strfun1"), StrFun1); - p1->DefineFun( _T("strfun2"), StrFun2); - p1->DefineFun( _T("strfun3"), StrFun3); - p1->DefineFun( _T("lastArg"), LastArg); - p1->DefineFun( _T("firstArg"), FirstArg); - p1->DefineFun( _T("order"), FirstArg); - - // infix / postfix operator - // Note: Identifiers used here do not have any meaning - // they are mere placeholders to test certain features. - p1->DefineInfixOprt( _T("$"), sign, prPOW+1); // sign with high priority - p1->DefineInfixOprt( _T("~"), plus2); // high priority - p1->DefineInfixOprt( _T("~~"), plus2); - p1->DefinePostfixOprt( _T("{m}"), Milli); - p1->DefinePostfixOprt( _T("{M}"), Mega); - p1->DefinePostfixOprt( _T("m"), Milli); - p1->DefinePostfixOprt( _T("meg"), Mega); - p1->DefinePostfixOprt( _T("#"), times3); - p1->DefinePostfixOprt( _T("'"), sqr); - p1->SetExpr(a_str); - - // Test bytecode integrity - // String parsing and bytecode parsing must yield the same result - fVal[0] = p1->Eval(); // result from stringparsing - fVal[1] = p1->Eval(); // result from bytecode - if (fVal[0]!=fVal[1]) - throw Parser::exception_type( _T("Bytecode / string parsing mismatch.") ); - - // Test copy and assignment operators - try - { - // Test copy constructor - std::vector<mu::Parser> vParser; - vParser.push_back(*(p1.get())); - mu::Parser p2 = vParser[0]; // take parser from vector - - // destroy the originals from p2 - vParser.clear(); // delete the vector - p1.reset(0); - - fVal[2] = p2.Eval(); - - // Test assignment operator - // additionally disable Optimizer this time - mu::Parser p3; - p3 = p2; - p3.EnableOptimizer(false); - fVal[3] = p3.Eval(); - - // Test Eval function for multiple return values - // use p2 since it has the optimizer enabled! - int nNum; - value_type *v = p2.Eval(nNum); - fVal[4] = v[nNum-1]; - } - catch(std::exception &e) - { - mu::console() << _T("\n ") << e.what() << _T("\n"); - } - - // limited floating point accuracy requires the following test - bool bCloseEnough(true); - for (unsigned i=0; i<sizeof(fVal)/sizeof(value_type); ++i) - { - bCloseEnough &= (fabs(a_fRes-fVal[i]) <= fabs(fVal[i]*0.00001)); - - // The tests equations never result in infinity, if they do thats a bug. - // reference: - // http://sourceforge.net/projects/muparser/forums/forum/462843/topic/5037825 - #pragma warning(push) - #pragma warning(disable:4127) - if (std::numeric_limits<value_type>::has_infinity) - #pragma warning(pop) - { - bCloseEnough &= (fabs(fVal[i]) != numeric_limits<value_type>::infinity()); - } - } - - 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 - << _T(" ;calculated: ") << fVal[0] << _T(",") - << fVal[1] << _T(",") - << fVal[2] << _T(",") - << fVal[3] << _T(",") - << fVal[4] << _T(")."); - } - } - catch(Parser::exception_type &e) - { - if (a_fPass) - { - if (fVal[0]!=fVal[2] && fVal[0]!=-999 && fVal[1]!=-998) - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (copy construction)"); - else - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.GetMsg() << _T(")"); - return 1; - } - } - catch(std::exception &e) - { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.what() << _T(")"); - return 1; // always return a failure since this exception is not expected - } - catch(...) - { - mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); - return 1; // exceptions other than ParserException are not allowed - } - - return iRet; - } - - //--------------------------------------------------------------------------- - int ParserTester::EqnTestInt(const string_type &a_str, double a_fRes, bool a_fPass) - { - ParserTester::c_iCount++; - - value_type vVarVal[] = {1, 2, 3}; // variable values - 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); - p.DefineVar( _T("a"), &vVarVal[0]); - p.DefineVar( _T("b"), &vVarVal[1]); - p.DefineVar( _T("c"), &vVarVal[2]); - - p.SetExpr(a_str); - fVal[0] = p.Eval(); // result from stringparsing - fVal[1] = p.Eval(); // result from bytecode - - if (fVal[0]!=fVal[1]) - throw Parser::exception_type( _T("Bytecode corrupt.") ); - - iRet = ( (a_fRes==fVal[0] && a_fPass) || - (a_fRes!=fVal[0] && !a_fPass) ) ? 0 : 1; - if (iRet==1) - { - mu::console() << _T("\n fail: ") << a_str.c_str() - << _T(" (incorrect result; expected: ") << a_fRes - << _T(" ;calculated: ") << fVal[0]<< _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 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 - { - mu::console() << _T("Test failed (internal error in test class)") << endl; - while (!getchar()); - exit(-1); - } - } // namespace test -} // namespace mu +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "muParserTest.h" + +#include <cstdio> +#include <cmath> +#include <iostream> +#include <limits> + +using namespace std; + +/** \file + \brief This file contains the implementation of parser test cases. +*/ + +namespace mu +{ + namespace Test + { + int ParserTester::c_iCount = 0; + + //--------------------------------------------------------------------------------------------- + ParserTester::ParserTester() + :m_vTestFun() + { + AddTest(&ParserTester::TestNames); + AddTest(&ParserTester::TestSyntax); + AddTest(&ParserTester::TestPostFix); + AddTest(&ParserTester::TestInfixOprt); + AddTest(&ParserTester::TestVarConst); + AddTest(&ParserTester::TestMultiArg); + AddTest(&ParserTester::TestExpression); + AddTest(&ParserTester::TestIfThenElse); + AddTest(&ParserTester::TestInterface); + AddTest(&ParserTester::TestBinOprt); + AddTest(&ParserTester::TestException); + AddTest(&ParserTester::TestStrArg); + AddTest(&ParserTester::TestBulkMode); + + ParserTester::c_iCount = 0; + } + + //--------------------------------------------------------------------------------------------- + int ParserTester::IsHexVal(const char_type* a_szExpr, int* a_iPos, value_type* a_fVal) + { + if (a_szExpr[1] == 0 || (a_szExpr[0] != '0' || a_szExpr[1] != 'x')) + return 0; + + unsigned iVal(0); + + // New code based on streams for UNICODE compliance: + stringstream_type::pos_type nPos(0); + stringstream_type ss(a_szExpr + 2); + ss >> std::hex >> iVal; + nPos = ss.tellg(); + + if (nPos == (stringstream_type::pos_type)0) + return 1; + + *a_iPos += (int)(2 + nPos); + *a_fVal = (value_type)iVal; + return 1; + } + + //--------------------------------------------------------------------------------------------- + int ParserTester::TestInterface() + { + int iStat = 0; + mu::console() << _T("testing member functions..."); + + // Test RemoveVar + value_type afVal[3] = { 1,2,3 }; + Parser p; + + try + { + p.DefineVar(_T("a"), &afVal[0]); + p.DefineVar(_T("b"), &afVal[1]); + p.DefineVar(_T("c"), &afVal[2]); + p.SetExpr(_T("a+b+c")); + p.Eval(); + } + catch (...) + { + iStat += 1; // this is not supposed to happen + } + + try + { + p.RemoveVar(_T("c")); + p.Eval(); + iStat += 1; // not supposed to reach this, nonexisting variable "c" deleted... + } + catch (...) + { + // failure is expected... + } + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------------------------- + int ParserTester::TestStrArg() + { + int iStat = 0; + mu::console() << _T("testing string arguments..."); + + + // from oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23410 + iStat += ThrowTest(_T(R"(6 - 6 ? 4 : "", ? 4 : "", ? 4 : "")"), ecUNEXPECTED_STR, true); + // variations: + iStat += ThrowTest(_T(R"(1 ? 4 : "")"), ecUNEXPECTED_STR, true); + iStat += ThrowTest(_T(R"(1 ? "" : 4)"), ecUNEXPECTED_STR, true); + iStat += ThrowTest(_T(R"(1 ? "" : "")"), ecUNEXPECTED_STR, true); + + // from oss-fuzz: https://oss-fuzz.com/testcase-detail/5106868061208576 + iStat += ThrowTest(_T(R"("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",8)"), ecSTR_RESULT); + // variations: + iStat += ThrowTest(_T(R"("","",9)"), ecSTR_RESULT); + + iStat += EqnTest(_T("valueof(\"\")"), 123, true); // empty string arguments caused a crash + iStat += EqnTest(_T("valueof(\"aaa\")+valueof(\"bbb\") "), 246, true); + iStat += EqnTest(_T("2*(valueof(\"aaa\")-23)+valueof(\"bbb\")"), 323, true); + + // use in expressions with variables + iStat += EqnTest(_T("a*(atof(\"10\")-b)"), 8, true); + iStat += EqnTest(_T("a-(atof(\"10\")*b)"), -19, true); + + // string + numeric arguments + iStat += EqnTest(_T("strfun1(\"100\")"), 100, true); + iStat += EqnTest(_T("strfun2(\"100\",1)"), 101, true); + iStat += EqnTest(_T("strfun3(\"99\",1,2)"), 102, true); + iStat += EqnTest(_T("strfun4(\"99\",1,2,3)"), 105, true); + iStat += EqnTest(_T("strfun5(\"99\",1,2,3,4)"), 109, true); + + // string constants + iStat += EqnTest(_T("atof(str1)+atof(str2)"), 3.33, true); + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------------------------- + int ParserTester::TestBulkMode() + { + int iStat = 0; + mu::console() << _T("testing bulkmode..."); + +#define EQN_TEST_BULK(EXPR, R1, R2, R3, R4, PASS) \ + { \ + double res[] = { R1, R2, R3, R4 }; \ + iStat += EqnTestBulk(_T(EXPR), res, (PASS)); \ + } + + // Bulk Variables for the test: + // a: 1,2,3,4 + // b: 2,2,2,2 + // c: 3,3,3,3 + // d: 5,4,3,2 + EQN_TEST_BULK("a", 1, 1, 1, 1, false) + EQN_TEST_BULK("a", 1, 2, 3, 4, true) + EQN_TEST_BULK("b=a", 1, 2, 3, 4, true) + EQN_TEST_BULK("b=a, b*10", 10, 20, 30, 40, true) + EQN_TEST_BULK("b=a, b*10, a", 1, 2, 3, 4, true) + EQN_TEST_BULK("a+b", 3, 4, 5, 6, true) + EQN_TEST_BULK("c*(a+b)", 9, 12, 15, 18, true) +#undef EQN_TEST_BULK + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------------------------- + int ParserTester::TestBinOprt() + { + int iStat = 0; + mu::console() << _T("testing binary operators..."); + + // built in operators + // xor operator + + iStat += EqnTest(_T("a++b"), 3, true); + iStat += EqnTest(_T("a ++ b"), 3, true); + iStat += EqnTest(_T("1++2"), 3, true); + iStat += EqnTest(_T("1 ++ 2"), 3, true); + iStat += EqnTest(_T("a add b"), 3, true); + iStat += EqnTest(_T("1 add 2"), 3, true); + iStat += EqnTest(_T("a<b"), 1, true); + iStat += EqnTest(_T("b>a"), 1, true); + iStat += EqnTest(_T("a>a"), 0, true); + iStat += EqnTest(_T("a<a"), 0, true); + iStat += EqnTest(_T("a>a"), 0, true); + iStat += EqnTest(_T("a<=a"), 1, true); + iStat += EqnTest(_T("a<=b"), 1, true); + iStat += EqnTest(_T("b<=a"), 0, true); + iStat += EqnTest(_T("a>=a"), 1, true); + iStat += EqnTest(_T("b>=a"), 1, true); + iStat += EqnTest(_T("a>=b"), 0, true); + + // Test logical operators, especially if user defined "&" and the internal "&&" collide + iStat += EqnTest(_T("1 && 1"), 1, true); + iStat += EqnTest(_T("1 && 0"), 0, true); + iStat += EqnTest(_T("(a<b) && (b>a)"), 1, true); + iStat += EqnTest(_T("(a<b) && (a>b)"), 0, true); + //iStat += EqnTest(_T("12 and 255"), 12, true); + //iStat += EqnTest(_T("12 and 0"), 0, true); + iStat += EqnTest(_T("12 & 255"), 12, true); + iStat += EqnTest(_T("12 & 0"), 0, true); + iStat += EqnTest(_T("12&255"), 12, true); + iStat += EqnTest(_T("12&0"), 0, true); + + // Assignment operator + iStat += EqnTest(_T("a = b"), 2, true); + iStat += EqnTest(_T("a = sin(b)"), 0.909297, true); + iStat += EqnTest(_T("a = 1+sin(b)"), 1.909297, true); + iStat += EqnTest(_T("(a=b)*2"), 4, true); + iStat += EqnTest(_T("2*(a=b)"), 4, true); + iStat += EqnTest(_T("2*(a=b+1)"), 6, true); + iStat += EqnTest(_T("(a=b+1)*2"), 6, true); + iStat += EqnTest(_T("a=c, a*10"), 30, true); + + iStat += EqnTest(_T("2^2^3"), 256, true); + iStat += EqnTest(_T("1/2/3"), 1.0 / 6.0, true); + + // reference: http://www.wolframalpha.com/input/?i=3%2B4*2%2F%281-5%29^2^3 + iStat += EqnTest(_T("3+4*2/(1-5)^2^3"), 3.0001220703125, true); + + // Test user defined binary operators + iStat += EqnTestInt(_T("1 | 2"), 3, true); + iStat += EqnTestInt(_T("1 || 2"), 1, true); + iStat += EqnTestInt(_T("123 & 456"), 72, true); + iStat += EqnTestInt(_T("(123 & 456) % 10"), 2, true); + iStat += EqnTestInt(_T("1 && 0"), 0, true); + iStat += EqnTestInt(_T("123 && 456"), 1, true); + iStat += EqnTestInt(_T("1 << 3"), 8, true); + iStat += EqnTestInt(_T("8 >> 3"), 1, true); + iStat += EqnTestInt(_T("9 / 4"), 2, true); + iStat += EqnTestInt(_T("9 % 4"), 1, true); + iStat += EqnTestInt(_T("if(5%2,1,0)"), 1, true); + iStat += EqnTestInt(_T("if(4%2,1,0)"), 0, true); + iStat += EqnTestInt(_T("-10+1"), -9, true); + iStat += EqnTestInt(_T("1+2*3"), 7, true); + iStat += EqnTestInt(_T("const1 != const2"), 1, true); + iStat += EqnTestInt(_T("const1 != const2"), 0, false); + iStat += EqnTestInt(_T("const1 == const2"), 0, true); + iStat += EqnTestInt(_T("const1 == 1"), 1, true); + iStat += EqnTestInt(_T("10*(const1 == 1)"), 10, true); + iStat += EqnTestInt(_T("2*(const1 | const2)"), 6, true); + iStat += EqnTestInt(_T("2*(const1 | const2)"), 7, false); + iStat += EqnTestInt(_T("const1 < const2"), 1, true); + iStat += EqnTestInt(_T("const2 > const1"), 1, true); + iStat += EqnTestInt(_T("const1 <= 1"), 1, true); + iStat += EqnTestInt(_T("const2 >= 2"), 1, true); + iStat += EqnTestInt(_T("2*(const1 + const2)"), 6, true); + iStat += EqnTestInt(_T("2*(const1 - const2)"), -2, true); + iStat += EqnTestInt(_T("a != b"), 1, true); + iStat += EqnTestInt(_T("a != b"), 0, false); + iStat += EqnTestInt(_T("a == b"), 0, true); + iStat += EqnTestInt(_T("a == 1"), 1, true); + iStat += EqnTestInt(_T("10*(a == 1)"), 10, true); + iStat += EqnTestInt(_T("2*(a | b)"), 6, true); + iStat += EqnTestInt(_T("2*(a | b)"), 7, false); + iStat += EqnTestInt(_T("a < b"), 1, true); + iStat += EqnTestInt(_T("b > a"), 1, true); + iStat += EqnTestInt(_T("a <= 1"), 1, true); + iStat += EqnTestInt(_T("b >= 2"), 1, true); + iStat += EqnTestInt(_T("2*(a + b)"), 6, true); + iStat += EqnTestInt(_T("2*(a - b)"), -2, true); + iStat += EqnTestInt(_T("a + (a << b)"), 5, true); + iStat += EqnTestInt(_T("-2^2"), -4, true); + iStat += EqnTestInt(_T("3--a"), 4, true); + iStat += EqnTestInt(_T("3+-3^2"), -6, true); + + // Test reading of hex values: + iStat += EqnTestInt(_T("0xff"), 255, true); + iStat += EqnTestInt(_T("10+0xff"), 265, true); + iStat += EqnTestInt(_T("0xff+10"), 265, true); + iStat += EqnTestInt(_T("10*0xff"), 2550, true); + iStat += EqnTestInt(_T("0xff*10"), 2550, true); + iStat += EqnTestInt(_T("10+0xff+1"), 266, true); + iStat += EqnTestInt(_T("1+0xff+10"), 266, true); + + // incorrect: '^' is yor here, not power + // iStat += EqnTestInt("-(1+2)^2", -9, true); + // iStat += EqnTestInt("-1^3", -1, true); + + // Test precedence + // a=1, b=2, c=3 + iStat += EqnTestInt(_T("a + b * c"), 7, true); + iStat += EqnTestInt(_T("a * b + c"), 5, true); + iStat += EqnTestInt(_T("a<b && b>10"), 0, true); + iStat += EqnTestInt(_T("a<b && b<10"), 1, true); + + iStat += EqnTestInt(_T("a + b << c"), 17, true); + iStat += EqnTestInt(_T("a << b + c"), 7, true); + iStat += EqnTestInt(_T("c * b < a"), 0, true); + iStat += EqnTestInt(_T("c * b == 6 * a"), 1, true); + iStat += EqnTestInt(_T("2^2^3"), 256, true); + + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------------------------- + /** \brief Check muParser name restriction enforcement. */ + int ParserTester::TestNames() + { + int iStat = 0, + iErr = 0; + + mu::console() << "testing name restriction enforcement..."; + + Parser p; + +#define PARSER_THROWCHECK(DOMAIN, FAIL, EXPR, ARG) \ + iErr = 0; \ + ParserTester::c_iCount++; \ + try \ + { \ + p.Define##DOMAIN(EXPR, ARG); \ + iErr = (FAIL) ? 0 : 1; \ + } \ + catch(...) \ + { \ + iErr = (!FAIL) ? 0 : 1; \ + } \ + iStat += iErr; + + // constant names + PARSER_THROWCHECK(Const, false, _T("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), 1) + PARSER_THROWCHECK(Const, false, _T("0a"), 1) + PARSER_THROWCHECK(Const, false, _T("9a"), 1) + PARSER_THROWCHECK(Const, false, _T("+a"), 1) + PARSER_THROWCHECK(Const, false, _T("-a"), 1) + PARSER_THROWCHECK(Const, false, _T("a-"), 1) + PARSER_THROWCHECK(Const, false, _T("a*"), 1) + PARSER_THROWCHECK(Const, false, _T("a?"), 1) + PARSER_THROWCHECK(Const, true, _T("a"), 1) + PARSER_THROWCHECK(Const, true, _T("a_min"), 1) + PARSER_THROWCHECK(Const, true, _T("a_min0"), 1) + PARSER_THROWCHECK(Const, true, _T("a_min9"), 1) + + // variable names + value_type a; + p.ClearConst(); + PARSER_THROWCHECK(Var, false, _T("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), &a); + PARSER_THROWCHECK(Var, false, _T("123abc"), &a) + PARSER_THROWCHECK(Var, false, _T("9a"), &a) + PARSER_THROWCHECK(Var, false, _T("0a"), &a) + PARSER_THROWCHECK(Var, false, _T("+a"), &a) + PARSER_THROWCHECK(Var, false, _T("-a"), &a) + PARSER_THROWCHECK(Var, false, _T("?a"), &a) + PARSER_THROWCHECK(Var, false, _T("!a"), &a) + PARSER_THROWCHECK(Var, false, _T("a+"), &a) + PARSER_THROWCHECK(Var, false, _T("a-"), &a) + PARSER_THROWCHECK(Var, false, _T("a*"), &a) + PARSER_THROWCHECK(Var, false, _T("a?"), &a) + PARSER_THROWCHECK(Var, true, _T("a"), &a) + PARSER_THROWCHECK(Var, true, _T("a_min"), &a) + PARSER_THROWCHECK(Var, true, _T("a_min0"), &a) + PARSER_THROWCHECK(Var, true, _T("a_min9"), &a) + PARSER_THROWCHECK(Var, false, _T("a_min9"), 0) + + // Postfix operators + // fail + PARSER_THROWCHECK(PostfixOprt, false, _T("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), f1of1); + PARSER_THROWCHECK(PostfixOprt, false, _T("(k"), f1of1) + PARSER_THROWCHECK(PostfixOprt, false, _T("9+"), f1of1) + PARSER_THROWCHECK(PostfixOprt, false, _T("+"), 0) + // pass + PARSER_THROWCHECK(PostfixOprt, true, _T("-a"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("?a"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("_"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("#"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("&&"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("||"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("&"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("|"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("++"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("--"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("?>"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("?<"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("**"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("xor"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("and"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("or"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("not"), f1of1) + PARSER_THROWCHECK(PostfixOprt, true, _T("!"), f1of1) + + // Binary operator + // The following must fail with builtin operators activated + // p.EnableBuiltInOp(true); -> this is the default + p.ClearPostfixOprt(); + PARSER_THROWCHECK(Oprt, false, _T("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), f1of2); + PARSER_THROWCHECK(Oprt, false, _T("+"), f1of2) + PARSER_THROWCHECK(Oprt, false, _T("-"), f1of2) + PARSER_THROWCHECK(Oprt, false, _T("*"), f1of2) + PARSER_THROWCHECK(Oprt, false, _T("/"), f1of2) + PARSER_THROWCHECK(Oprt, false, _T("^"), f1of2) + PARSER_THROWCHECK(Oprt, false, _T("&&"), f1of2) + PARSER_THROWCHECK(Oprt, false, _T("||"), f1of2) + + // without activated built in operators it should work + p.EnableBuiltInOprt(false); + PARSER_THROWCHECK(Oprt, true, _T("+"), f1of2) + PARSER_THROWCHECK(Oprt, true, _T("-"), f1of2) + PARSER_THROWCHECK(Oprt, true, _T("*"), f1of2) + PARSER_THROWCHECK(Oprt, true, _T("/"), f1of2) + PARSER_THROWCHECK(Oprt, true, _T("^"), f1of2) + PARSER_THROWCHECK(Oprt, true, _T("&&"), f1of2) + PARSER_THROWCHECK(Oprt, true, _T("||"), f1of2) +#undef PARSER_THROWCHECK + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------- + int ParserTester::TestSyntax() + { + int iStat = 0; + mu::console() << _T("testing syntax engine..."); + + iStat += ThrowTest(_T("1,"), ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest(_T("a,"), ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest(_T("sin(8),"), ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest(_T("(sin(8)),"), ecUNEXPECTED_EOF); // incomplete hex definition + iStat += ThrowTest(_T("a{m},"), ecUNEXPECTED_EOF); // incomplete hex definition + + iStat += EqnTest(_T("(1+ 2*a)"), 3, true); // Spaces within formula + iStat += EqnTest(_T("sqrt((4))"), 2, true); // Multiple brackets + iStat += EqnTest(_T("sqrt((2)+2)"), 2, true);// Multiple brackets + iStat += EqnTest(_T("sqrt(2+(2))"), 2, true);// Multiple brackets + iStat += EqnTest(_T("sqrt(a+(3))"), 2, true);// Multiple brackets + iStat += EqnTest(_T("sqrt((3)+a)"), 2, true);// Multiple brackets + iStat += EqnTest(_T("order(1,2)"), 1, true); // May not cause name collision with operator "or" + iStat += EqnTest(_T("(2+"), 0, false); // missing closing bracket + iStat += EqnTest(_T("2++4"), 0, false); // unexpected operator + iStat += EqnTest(_T("2+-4"), 0, false); // unexpected operator + iStat += EqnTest(_T("(2+)"), 0, false); // unexpected closing bracket + iStat += EqnTest(_T("--2"), 0, false); // double sign + iStat += EqnTest(_T("ksdfj"), 0, false); // unknown token + iStat += EqnTest(_T("()"), 0, false); // empty bracket without a function + iStat += EqnTest(_T("5+()"), 0, false); // empty bracket without a function + iStat += EqnTest(_T("sin(cos)"), 0, false); // unexpected function + iStat += EqnTest(_T("5t6"), 0, false); // unknown token + iStat += EqnTest(_T("5 t 6"), 0, false); // unknown token + iStat += EqnTest(_T("8*"), 0, false); // unexpected end of formula + iStat += EqnTest(_T(",3"), 0, false); // unexpected comma + iStat += EqnTest(_T("3,5"), 0, false); // unexpected comma + iStat += EqnTest(_T("sin(8,8)"), 0, false); // too many function args + iStat += EqnTest(_T("(7,8)"), 0, false); // too many function args + iStat += EqnTest(_T("sin)"), 0, false); // unexpected closing bracket + iStat += EqnTest(_T("a)"), 0, false); // unexpected closing bracket + iStat += EqnTest(_T("pi)"), 0, false); // unexpected closing bracket + iStat += EqnTest(_T("sin(())"), 0, false); // unexpected closing bracket + iStat += EqnTest(_T("sin()"), 0, false); // unexpected closing bracket + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------- + int ParserTester::TestVarConst() + { + int iStat = 0; + mu::console() << _T("testing variable/constant detection..."); + + // Test if the result changes when a variable changes + iStat += EqnTestWithVarChange(_T("a"), 1, 1, 2, 2); + iStat += EqnTestWithVarChange(_T("2*a"), 2, 4, 3, 6); + + // distinguish constants with same basename + iStat += EqnTest(_T("const"), 1, true); + iStat += EqnTest(_T("const1"), 2, true); + iStat += EqnTest(_T("const2"), 3, true); + iStat += EqnTest(_T("2*const"), 2, true); + iStat += EqnTest(_T("2*const1"), 4, true); + iStat += EqnTest(_T("2*const2"), 6, true); + iStat += EqnTest(_T("2*const+1"), 3, true); + iStat += EqnTest(_T("2*const1+1"), 5, true); + iStat += EqnTest(_T("2*const2+1"), 7, true); + iStat += EqnTest(_T("const"), 0, false); + iStat += EqnTest(_T("const1"), 0, false); + iStat += EqnTest(_T("const2"), 0, false); + + // distinguish variables with same basename + iStat += EqnTest(_T("a"), 1, true); + iStat += EqnTest(_T("aa"), 2, true); + iStat += EqnTest(_T("2*a"), 2, true); + iStat += EqnTest(_T("2*aa"), 4, true); + iStat += EqnTest(_T("2*a-1"), 1, true); + iStat += EqnTest(_T("2*aa-1"), 3, true); + + // custom value recognition + iStat += EqnTest(_T("0xff"), 255, true); + iStat += EqnTest(_T("0x97 + 0xff"), 406, true); + + // Finally test querying of used variables + try + { + int idx; + mu::Parser p; + mu::value_type vVarVal[] = { 1, 2, 3, 4, 5 }; + p.DefineVar(_T("a"), &vVarVal[0]); + p.DefineVar(_T("b"), &vVarVal[1]); + p.DefineVar(_T("c"), &vVarVal[2]); + p.DefineVar(_T("d"), &vVarVal[3]); + p.DefineVar(_T("e"), &vVarVal[4]); + + // Test lookup of defined variables + // 4 used variables + p.SetExpr(_T("a+b+c+d")); + mu::varmap_type UsedVar = p.GetUsedVar(); + int iCount = (int)UsedVar.size(); + if (iCount != 4) + throw false; + + // the next check will fail if the parser + // erroneously creates new variables internally + if (p.GetVar().size() != 5) + throw false; + + mu::varmap_type::const_iterator item = UsedVar.begin(); + for (idx = 0; item != UsedVar.end(); ++item) + { + if (&vVarVal[idx++] != item->second) + throw false; + } + + // Test lookup of undefined variables + p.SetExpr(_T("undef1+undef2+undef3")); + UsedVar = p.GetUsedVar(); + iCount = (int)UsedVar.size(); + if (iCount != 3) + throw false; + + // the next check will fail if the parser + // erroneously creates new variables internally + if (p.GetVar().size() != 5) + throw false; + + for (item = UsedVar.begin(); item != UsedVar.end(); ++item) + { + if (item->second != 0) + throw false; // all pointers to undefined variables must be null + } + + // 1 used variables + p.SetExpr(_T("a+b")); + UsedVar = p.GetUsedVar(); + iCount = (int)UsedVar.size(); + if (iCount != 2) throw false; + item = UsedVar.begin(); + for (idx = 0; item != UsedVar.end(); ++item) + if (&vVarVal[idx++] != item->second) throw false; + + } + catch (...) + { + iStat += 1; + } + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------- + int ParserTester::TestMultiArg() + { + int iStat = 0; + mu::console() << _T("testing multiarg functions..."); + + // from oss-fzz.com: UNKNOWN READ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23330#c1 + iStat += ThrowTest(_T("6, +, +, +, +, +, +, +, +, +, +, +, +, +, +, 1, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +, +"), ecUNEXPECTED_ARG_SEP, true); + + // Compound expressions + iStat += EqnTest(_T("1,2,3"), 3, true); + iStat += EqnTest(_T("a,b,c"), 3, true); + iStat += EqnTest(_T("a=10,b=20,c=a*b"), 200, true); + iStat += EqnTest(_T("1,\n2,\n3"), 3, true); + iStat += EqnTest(_T("a,\nb,\nc"), 3, true); + iStat += EqnTest(_T("a=10,\nb=20,\nc=a*b"), 200, true); + iStat += EqnTest(_T("1,\r\n2,\r\n3"), 3, true); + iStat += EqnTest(_T("a,\r\nb,\r\nc"), 3, true); + iStat += EqnTest(_T("a=10,\r\nb=20,\r\nc=a*b"), 200, true); + + // picking the right argument + iStat += EqnTest(_T("f1of1(1)"), 1, true); + iStat += EqnTest(_T("f1of2(1, 2)"), 1, true); + iStat += EqnTest(_T("f2of2(1, 2)"), 2, true); + iStat += EqnTest(_T("f1of3(1, 2, 3)"), 1, true); + iStat += EqnTest(_T("f2of3(1, 2, 3)"), 2, true); + iStat += EqnTest(_T("f3of3(1, 2, 3)"), 3, true); + iStat += EqnTest(_T("f1of4(1, 2, 3, 4)"), 1, true); + iStat += EqnTest(_T("f2of4(1, 2, 3, 4)"), 2, true); + iStat += EqnTest(_T("f3of4(1, 2, 3, 4)"), 3, true); + iStat += EqnTest(_T("f4of4(1, 2, 3, 4)"), 4, true); + iStat += EqnTest(_T("f1of5(1, 2, 3, 4, 5)"), 1, true); + iStat += EqnTest(_T("f2of5(1, 2, 3, 4, 5)"), 2, true); + iStat += EqnTest(_T("f3of5(1, 2, 3, 4, 5)"), 3, true); + iStat += EqnTest(_T("f4of5(1, 2, 3, 4, 5)"), 4, true); + iStat += EqnTest(_T("f5of5(1, 2, 3, 4, 5)"), 5, true); + // Too few arguments / Too many arguments + iStat += EqnTest(_T("1+ping()"), 11, true); + iStat += EqnTest(_T("ping()+1"), 11, true); + iStat += EqnTest(_T("2*ping()"), 20, true); + iStat += EqnTest(_T("ping()*2"), 20, true); + iStat += EqnTest(_T("ping(1,2)"), 0, false); + iStat += EqnTest(_T("1+ping(1,2)"), 0, false); + iStat += EqnTest(_T("f1of1(1,2)"), 0, false); + iStat += EqnTest(_T("f1of1()"), 0, false); + iStat += EqnTest(_T("f1of2(1, 2, 3)"), 0, false); + iStat += EqnTest(_T("f1of2(1)"), 0, false); + iStat += EqnTest(_T("f1of3(1, 2, 3, 4)"), 0, false); + iStat += EqnTest(_T("f1of3(1)"), 0, false); + iStat += EqnTest(_T("f1of4(1, 2, 3, 4, 5)"), 0, false); + iStat += EqnTest(_T("f1of4(1)"), 0, false); + iStat += EqnTest(_T("(1,2,3)"), 0, false); + iStat += EqnTest(_T("1,2,3"), 0, false); + iStat += EqnTest(_T("(1*a,2,3)"), 0, false); + iStat += EqnTest(_T("1,2*a,3"), 0, false); + + // correct calculation of arguments + iStat += EqnTest(_T("min(a, 1)"), 1, true); + iStat += EqnTest(_T("min(3*2, 1)"), 1, true); + iStat += EqnTest(_T("min(3*2, 1)"), 6, false); + iStat += EqnTest(_T("firstArg(2,3,4)"), 2, true); + iStat += EqnTest(_T("lastArg(2,3,4)"), 4, true); + iStat += EqnTest(_T("min(3*a+1, 1)"), 1, true); + iStat += EqnTest(_T("max(3*a+1, 1)"), 4, true); + iStat += EqnTest(_T("max(3*a+1, 1)*2"), 8, true); + iStat += EqnTest(_T("2*max(3*a+1, 1)+2"), 10, true); + + // functions with Variable argument count + iStat += EqnTest(_T("sum(a)"), 1, true); + iStat += EqnTest(_T("sum(1,2,3)"), 6, true); + iStat += EqnTest(_T("sum(a,b,c)"), 6, true); + iStat += EqnTest(_T("sum(1,-max(1,2),3)*2"), 4, true); + iStat += EqnTest(_T("2*sum(1,2,3)"), 12, true); + iStat += EqnTest(_T("2*sum(1,2,3)+2"), 14, true); + iStat += EqnTest(_T("2*sum(-1,2,3)+2"), 10, true); + iStat += EqnTest(_T("2*sum(-1,2,-(-a))+2"), 6, true); + iStat += EqnTest(_T("2*sum(-1,10,-a)+2"), 18, true); + iStat += EqnTest(_T("2*sum(1,2,3)*2"), 24, true); + iStat += EqnTest(_T("sum(1,-max(1,2),3)*2"), 4, true); + iStat += EqnTest(_T("sum(1*3, 4, a+2)"), 10, true); + iStat += EqnTest(_T("sum(1*3, 2*sum(1,2,2), a+2)"), 16, true); + iStat += EqnTest(_T("sum(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2)"), 24, true); + + // some failures + iStat += EqnTest(_T("sum()"), 0, false); + iStat += EqnTest(_T("sum(,)"), 0, false); + iStat += EqnTest(_T("sum(1,2,)"), 0, false); + iStat += EqnTest(_T("sum(,1,2)"), 0, false); + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + + //--------------------------------------------------------------------------- + int ParserTester::TestInfixOprt() + { + int iStat(0); + mu::console() << "testing infix operators..."; + + iStat += EqnTest(_T("+1"), +1, true); + iStat += EqnTest(_T("-(+1)"), -1, true); + iStat += EqnTest(_T("-(+1)*2"), -2, true); + iStat += EqnTest(_T("-(+2)*sqrt(4)"), -4, true); + iStat += EqnTest(_T("3-+a"), 2, true); + iStat += EqnTest(_T("+1*3"), 3, true); + + iStat += EqnTest(_T("-1"), -1, true); + iStat += EqnTest(_T("-(-1)"), 1, true); + iStat += EqnTest(_T("-(-1)*2"), 2, true); + iStat += EqnTest(_T("-(-2)*sqrt(4)"), 4, true); + iStat += EqnTest(_T("-_pi"), -MathImpl<double>::CONST_PI, true); + iStat += EqnTest(_T("-a"), -1, true); + iStat += EqnTest(_T("-(a)"), -1, true); + iStat += EqnTest(_T("-(-a)"), 1, true); + iStat += EqnTest(_T("-(-a)*2"), 2, true); + iStat += EqnTest(_T("-(8)"), -8, true); + iStat += EqnTest(_T("-8"), -8, true); + iStat += EqnTest(_T("-(2+1)"), -3, true); + iStat += EqnTest(_T("-(f1of1(1+2*3)+1*2)"), -9, true); + iStat += EqnTest(_T("-(-f1of1(1+2*3)+1*2)"), 5, true); + iStat += EqnTest(_T("-sin(8)"), -0.989358, true); + iStat += EqnTest(_T("3-(-a)"), 4, true); + iStat += EqnTest(_T("3--a"), 4, true); + iStat += EqnTest(_T("-1*3"), -3, true); + + // Postfix / infix priorities + iStat += EqnTest(_T("~2#"), 8, true); + iStat += EqnTest(_T("~f1of1(2)#"), 8, true); + iStat += EqnTest(_T("~(b)#"), 8, true); + iStat += EqnTest(_T("(~b)#"), 12, true); + iStat += EqnTest(_T("~(2#)"), 8, true); + iStat += EqnTest(_T("~(f1of1(2)#)"), 8, true); + // + iStat += EqnTest(_T("-2^2"), -4, true); + iStat += EqnTest(_T("-(a+b)^2"), -9, true); + iStat += EqnTest(_T("(-3)^2"), 9, true); + iStat += EqnTest(_T("-(-2^2)"), 4, true); + iStat += EqnTest(_T("3+-3^2"), -6, true); + // The following assumes use of sqr as postfix operator together + // with a sign operator of low priority: + iStat += EqnTest(_T("-2'"), -4, true); + iStat += EqnTest(_T("-(1+1)'"), -4, true); + iStat += EqnTest(_T("2+-(1+1)'"), -2, true); + iStat += EqnTest(_T("2+-2'"), -2, true); + // This is the classic behaviour of the infix sign operator (here: "$") which is + // now deprecated: + iStat += EqnTest(_T("$2^2"), 4, true); + iStat += EqnTest(_T("$(a+b)^2"), 9, true); + iStat += EqnTest(_T("($3)^2"), 9, true); + iStat += EqnTest(_T("$($2^2)"), -4, true); + iStat += EqnTest(_T("3+$3^2"), 12, true); + + // infix operators sharing the first few characters + iStat += EqnTest(_T("~ 123"), (value_type)123.0 + 2, true); + iStat += EqnTest(_T("~~ 123"), (value_type)123.0 + 2, true); + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + + //--------------------------------------------------------------------------- + int ParserTester::TestPostFix() + { + int iStat = 0; + mu::console() << _T("testing postfix operators..."); + + // application + iStat += EqnTest(_T("3{m}+5"), 5.003, true); + iStat += EqnTest(_T("1000{m}"), 1, true); + iStat += EqnTest(_T("1000 {m}"), 1, true); + iStat += EqnTest(_T("(a){m}"), 1e-3, true); + iStat += EqnTest(_T("a{m}"), 1e-3, true); + iStat += EqnTest(_T("a {m}"), 1e-3, true); + iStat += EqnTest(_T("-(a){m}"), -1e-3, true); + iStat += EqnTest(_T("-2{m}"), -2e-3, true); + iStat += EqnTest(_T("-2 {m}"), -2e-3, true); + iStat += EqnTest(_T("f1of1(1000){m}"), 1, true); + iStat += EqnTest(_T("-f1of1(1000){m}"), -1, true); + iStat += EqnTest(_T("-f1of1(-1000){m}"), 1, true); + iStat += EqnTest(_T("f4of4(0,0,0,1000){m}"), 1, true); + iStat += EqnTest(_T("2+(a*1000){m}"), 3, true); + + // can postfix operators "m" und "meg" be told apart properly? + iStat += EqnTest(_T("2*3000meg+2"), 2 * 3e9 + 2, true); + + // some incorrect results + iStat += EqnTest(_T("1000{m}"), 0.1, false); + iStat += EqnTest(_T("(a){m}"), 2, false); + // failure due to syntax checking + iStat += ThrowTest(_T("0x"), ecUNASSIGNABLE_TOKEN); // incomplete hex definition + iStat += ThrowTest(_T("3+"), ecUNEXPECTED_EOF); + iStat += ThrowTest(_T("4 + {m}"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("{m}4"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("sin({m})"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("{m} {m}"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("{m}(8)"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("4,{m}"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("-{m}"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("2(-{m})"), ecUNEXPECTED_PARENS); + iStat += ThrowTest(_T("2({m})"), ecUNEXPECTED_PARENS); + + iStat += ThrowTest(_T("multi*1.0"), ecUNASSIGNABLE_TOKEN); + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------- + int ParserTester::TestExpression() + { + int iStat = 0; + mu::console() << _T("testing expression samples..."); + + value_type b = 2; + + iStat += EqnTest(_T("f0()"), 42, true); + iStat += EqnTest(_T("b^2"), 4, true); + iStat += EqnTest(_T("b^1"), 2, true); + iStat += EqnTest(_T("b^0"), 1, true); + iStat += EqnTest(_T("b^-1"), 0.5, true); + + // Optimization + iStat += EqnTest(_T("2*b*5"), 20, true); + iStat += EqnTest(_T("2*b*5 + 4*b"), 28, true); + iStat += EqnTest(_T("2*a/3"), 2.0 / 3.0, true); + + // Addition auf cmVARMUL + iStat += EqnTest(_T("3+b"), b + 3, true); + iStat += EqnTest(_T("b+3"), b + 3, true); + iStat += EqnTest(_T("b*3+2"), b * 3 + 2, true); + iStat += EqnTest(_T("3*b+2"), b * 3 + 2, true); + iStat += EqnTest(_T("2+b*3"), b * 3 + 2, true); + iStat += EqnTest(_T("2+3*b"), b * 3 + 2, true); + iStat += EqnTest(_T("b+3*b"), b + 3 * b, true); + iStat += EqnTest(_T("3*b+b"), b + 3 * b, true); + + iStat += EqnTest(_T("2+b*3+b"), 2 + b * 3 + b, true); + iStat += EqnTest(_T("b+2+b*3"), b + 2 + b * 3, true); + + iStat += EqnTest(_T("(2*b+1)*4"), (2 * b + 1) * 4, true); + iStat += EqnTest(_T("4*(2*b+1)"), (2 * b + 1) * 4, true); + + // operator precedences + iStat += EqnTest(_T("1+2-3*4/5^6"), 2.99923, true); + iStat += EqnTest(_T("1^2/3*4-5+6"), 2.33333333, true); + iStat += EqnTest(_T("1+2*3"), 7, true); + iStat += EqnTest(_T("1+2*3"), 7, true); + iStat += EqnTest(_T("(1+2)*3"), 9, true); + iStat += EqnTest(_T("(1+2)*(-3)"), -9, true); + iStat += EqnTest(_T("2/4"), 0.5, true); + + iStat += EqnTest(_T("exp(ln(7))"), 7, true); + iStat += EqnTest(_T("e^ln(7)"), 7, true); + iStat += EqnTest(_T("e^(ln(7))"), 7, true); + iStat += EqnTest(_T("(e^(ln(7)))"), 7, true); + iStat += EqnTest(_T("1-(e^(ln(7)))"), -6, true); + iStat += EqnTest(_T("2*(e^(ln(7)))"), 14, true); + iStat += EqnTest(_T("10^log(5)"), pow(10.0, log(5.0)), true); + iStat += EqnTest(_T("10^log10(5)"), 5, true); + iStat += EqnTest(_T("2^log2(4)"), 4, true); + iStat += EqnTest(_T("-(sin(0)+1)"), -1, true); + iStat += EqnTest(_T("-(2^1.1)"), -2.14354692, true); + + iStat += EqnTest(_T("(cos(2.41)/b)"), -0.372056, true); + iStat += EqnTest(_T("(1*(2*(3*(4*(5*(6*(a+b)))))))"), 2160, true); + iStat += EqnTest(_T("(1*(2*(3*(4*(5*(6*(7*(a+b))))))))"), 15120, true); + iStat += EqnTest(_T("(a/((((b+(((e*(((((pi*((((3.45*((pi+a)+pi))+b)+b)*a))+0.68)+e)+a)/a))+a)+b))+b)*a)-pi))"), 0.00377999, true); + + // long formula (Reference: Matlab) + iStat += EqnTest( + _T("(((-9))-e/(((((((pi-(((-7)+(-3)/4/e))))/(((-5))-2)-((pi+(-0))*(sqrt((e+e))*(-8))*(((-pi)+(-pi)-(-9)*(6*5))") + _T("/(-e)-e))/2)/((((sqrt(2/(-e)+6)-(4-2))+((5/(-2))/(1*(-pi)+3))/8)*pi*((pi/((-2)/(-6)*1*(-1))*(-6)+(-e)))))/") + _T("((e+(-2)+(-e)*((((-3)*9+(-e)))+(-9)))))))-((((e-7+(((5/pi-(3/1+pi)))))/e)/(-5))/(sqrt((((((1+(-7))))+((((-") + _T("e)*(-e)))-8))*(-5)/((-e)))*(-6)-((((((-2)-(-9)-(-e)-1)/3))))/(sqrt((8+(e-((-6))+(9*(-9))))*(((3+2-8))*(7+6") + _T("+(-5))+((0/(-e)*(-pi))+7)))+(((((-e)/e/e)+((-6)*5)*e+(3+(-5)/pi))))+pi))/sqrt((((9))+((((pi))-8+2))+pi))/e") + _T("*4)*((-5)/(((-pi))*(sqrt(e)))))-(((((((-e)*(e)-pi))/4+(pi)*(-9)))))))+(-pi)"), -12.23016549, true); + + // long formula (Reference: Matlab) + iStat += EqnTest( + _T("(atan(sin((((((((((((((((pi/cos((a/((((0.53-b)-pi)*e)/b))))+2.51)+a)-0.54)/0.98)+b)*b)+e)/a)+b)+a)+b)+pi)/e") + _T(")+a)))*2.77)"), -2.16995656, true); + + // long formula (Reference: Matlab) + iStat += EqnTest(_T("1+2-3*4/5^6*(2*(1-5+(3*7^9)*(4+6*7-3)))+12"), -7995810.09926, true); + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + + + //--------------------------------------------------------------------------- + int ParserTester::TestIfThenElse() + { + int iStat = 0; + mu::console() << _T("testing if-then-else operator..."); + + // from oss-fuzz.com: https://oss-fuzz.com/testcase-detail/4777121158529024 + iStat += ThrowTest(_T("3!=min(0?2>2,2>5,1:6)"), ecUNEXPECTED_ARG_SEP); + + // Test error detection + iStat += ThrowTest(_T(":3"), ecUNEXPECTED_CONDITIONAL); + iStat += ThrowTest(_T("? 1 : 2"), ecUNEXPECTED_CONDITIONAL); + iStat += ThrowTest(_T("(a<b) ? (b<c) ? 1 : 2"), ecMISSING_ELSE_CLAUSE); + iStat += ThrowTest(_T("(a<b) ? 1"), ecMISSING_ELSE_CLAUSE); + iStat += ThrowTest(_T("(a<b) ? a"), ecMISSING_ELSE_CLAUSE); + iStat += ThrowTest(_T("(a<b) ? a+b"), ecMISSING_ELSE_CLAUSE); + iStat += ThrowTest(_T("a : b"), ecMISPLACED_COLON); + iStat += ThrowTest(_T("1 : 2"), ecMISPLACED_COLON); + iStat += ThrowTest(_T("(1) ? 1 : 2 : 3"), ecMISPLACED_COLON); + iStat += ThrowTest(_T("(true) ? 1 : 2 : 3"), ecUNASSIGNABLE_TOKEN); + + // from oss-fzz.com: UNKNOWN READ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22922#c1 + iStat += ThrowTest(_T("1?2:0?(7:1)"), ecMISPLACED_COLON); + + // from oss-fuzz.com: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=22938 + iStat += ThrowTest(_T("sum(0?1,0,0:3)"), ecUNEXPECTED_ARG_SEP); + iStat += ThrowTest(_T("sum(0?(1,0,0):3)"), ecUNEXPECTED_ARG); + iStat += ThrowTest(_T("sum(2>3?2,4,2:4)"), ecUNEXPECTED_ARG_SEP); + iStat += ThrowTest(_T("sum(2>3?2,4,sin(2):4)"), ecUNEXPECTED_ARG_SEP); + iStat += ThrowTest(_T("sum(2>3?sin(2),4,2:4)"), ecUNEXPECTED_ARG_SEP); + iStat += ThrowTest(_T("sum(2>3?sin(a),4,2:4)"), ecUNEXPECTED_ARG_SEP); + iStat += ThrowTest(_T("sum(2>3?sin(2),4,2:4)"), ecUNEXPECTED_ARG_SEP); + + iStat += EqnTest(_T("1 ? 128 : 255"), 128, true); + iStat += EqnTest(_T("1<2 ? 128 : 255"), 128, true); + iStat += EqnTest(_T("a<b ? 128 : 255"), 128, true); + iStat += EqnTest(_T("(a<b) ? 128 : 255"), 128, true); + iStat += EqnTest(_T("(1) ? 10 : 11"), 10, true); + iStat += EqnTest(_T("(0) ? 10 : 11"), 11, true); + iStat += EqnTest(_T("(1) ? a+b : c+d"), 3, true); + iStat += EqnTest(_T("(0) ? a+b : c+d"), 1, true); + iStat += EqnTest(_T("(1) ? 0 : 1"), 0, true); + iStat += EqnTest(_T("(0) ? 0 : 1"), 1, true); + iStat += EqnTest(_T("(a<b) ? 10 : 11"), 10, true); + iStat += EqnTest(_T("(a>b) ? 10 : 11"), 11, true); + iStat += EqnTest(_T("(a<b) ? c : d"), 3, true); + iStat += EqnTest(_T("(a>b) ? c : d"), -2, true); + + iStat += EqnTest(_T("(a>b) ? 1 : 0"), 0, true); + iStat += EqnTest(_T("((a>b) ? 1 : 0) ? 1 : 2"), 2, true); + iStat += EqnTest(_T("((a>b) ? 1 : 0) ? 1 : sum((a>b) ? 1 : 2)"), 2, true); + iStat += EqnTest(_T("((a>b) ? 0 : 1) ? 1 : sum((a>b) ? 1 : 2)"), 1, true); + + iStat += EqnTest(_T("sum((a>b) ? 1 : 2)"), 2, true); + iStat += EqnTest(_T("sum((1) ? 1 : 2)"), 1, true); + iStat += EqnTest(_T("sum((a>b) ? 1 : 2, 100)"), 102, true); + iStat += EqnTest(_T("sum((1) ? 1 : 2, 100)"), 101, true); + iStat += EqnTest(_T("sum(3, (a>b) ? 3 : 10)"), 13, true); + iStat += EqnTest(_T("sum(3, (a<b) ? 3 : 10)"), 6, true); + iStat += EqnTest(_T("10*sum(3, (a>b) ? 3 : 10)"), 130, true); + iStat += EqnTest(_T("10*sum(3, (a<b) ? 3 : 10)"), 60, true); + iStat += EqnTest(_T("sum(3, (a>b) ? 3 : 10)*10"), 130, true); + iStat += EqnTest(_T("sum(3, (a<b) ? 3 : 10)*10"), 60, true); + iStat += EqnTest(_T("(a<b) ? sum(3, (a<b) ? 3 : 10)*10 : 99"), 60, true); + iStat += EqnTest(_T("(a>b) ? sum(3, (a<b) ? 3 : 10)*10 : 99"), 99, true); + iStat += EqnTest(_T("(a<b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : 99"), 360, true); + iStat += EqnTest(_T("(a>b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : 99"), 99, true); + iStat += EqnTest(_T("(a>b) ? sum(3, (a<b) ? 3 : 10,10,20)*10 : sum(3, (a<b) ? 3 : 10)*10"), 60, true); + + // todo: also add for muParserX! + iStat += EqnTest(_T("(a<b)&&(a<b) ? 128 : 255"), 128, true); + iStat += EqnTest(_T("(a>b)&&(a<b) ? 128 : 255"), 255, true); + iStat += EqnTest(_T("(1<2)&&(1<2) ? 128 : 255"), 128, true); + iStat += EqnTest(_T("(1>2)&&(1<2) ? 128 : 255"), 255, true); + iStat += EqnTest(_T("((1<2)&&(1<2)) ? 128 : 255"), 128, true); + iStat += EqnTest(_T("((1>2)&&(1<2)) ? 128 : 255"), 255, true); + iStat += EqnTest(_T("((a<b)&&(a<b)) ? 128 : 255"), 128, true); + iStat += EqnTest(_T("((a>b)&&(a<b)) ? 128 : 255"), 255, true); + + iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 255, true); + iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 :(1>0 ? 32 : 64)"), 255, true); + iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 128, true); + iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 :(1>2 ? 32 : 64)"), 128, true); + iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 64"), 32, true); + iStat += EqnTest(_T("1>2 ? 1>0 ? 128 : 255 : 1>2 ? 32 : 64"), 64, true); + iStat += EqnTest(_T("1>0 ? 50 : 1>0 ? 128 : 255"), 50, true); + iStat += EqnTest(_T("1>0 ? 50 : (1>0 ? 128 : 255)"), 50, true); + iStat += EqnTest(_T("1>0 ? 1>0 ? 128 : 255 : 50"), 128, true); + iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 : 1>2 ? 64 : 16"), 32, true); + iStat += EqnTest(_T("1>2 ? 1>2 ? 128 : 255 : 1>0 ? 32 :(1>2 ? 64 : 16)"), 32, true); + iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : 1>0 ? 32 :1>2 ? 64 : 16"), 255, true); + iStat += EqnTest(_T("1>0 ? 1>2 ? 128 : 255 : (1>0 ? 32 :1>2 ? 64 : 16)"), 255, true); + iStat += EqnTest(_T("1 ? 0 ? 128 : 255 : 1 ? 32 : 64"), 255, true); + + // assignment operators + iStat += EqnTest(_T("a= 0 ? 128 : 255, a"), 255, true); + iStat += EqnTest(_T("a=((a>b)&&(a<b)) ? 128 : 255, a"), 255, true); + iStat += EqnTest(_T("c=(a<b)&&(a<b) ? 128 : 255, c"), 128, true); + iStat += EqnTest(_T("0 ? a=a+1 : 666, a"), 1, true); + iStat += EqnTest(_T("1?a=10:a=20, a"), 10, true); + iStat += EqnTest(_T("0?a=10:a=20, a"), 20, true); + iStat += EqnTest(_T("0?a=sum(3,4):10, a"), 1, true); // a should not change its value due to lazy calculation + + iStat += EqnTest(_T("a=1?b=1?3:4:5, a"), 3, true); + iStat += EqnTest(_T("a=1?b=1?3:4:5, b"), 3, true); + iStat += EqnTest(_T("a=0?b=1?3:4:5, a"), 5, true); + iStat += EqnTest(_T("a=0?b=1?3:4:5, b"), 2, true); + + iStat += EqnTest(_T("a=1?5:b=1?3:4, a"), 5, true); + iStat += EqnTest(_T("a=1?5:b=1?3:4, b"), 2, true); + iStat += EqnTest(_T("a=0?5:b=1?3:4, a"), 3, true); + iStat += EqnTest(_T("a=0?5:b=1?3:4, b"), 3, true); + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + //--------------------------------------------------------------------------- + int ParserTester::TestException() + { + int iStat = 0; + mu::console() << _T("testing error codes..."); + + iStat += ThrowTest(_T("3+"), ecUNEXPECTED_EOF); + iStat += ThrowTest(_T("3+)"), ecUNEXPECTED_PARENS); + iStat += ThrowTest(_T("()"), ecUNEXPECTED_PARENS); + iStat += ThrowTest(_T("3+()"), ecUNEXPECTED_PARENS); + iStat += ThrowTest(_T("sin(3,4)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("sin()"), ecTOO_FEW_PARAMS); + iStat += ThrowTest(_T("(1+2"), ecMISSING_PARENS); + iStat += ThrowTest(_T("sin(3)3"), ecUNEXPECTED_VAL); + iStat += ThrowTest(_T("sin(3)xyz"), ecUNASSIGNABLE_TOKEN); + iStat += ThrowTest(_T("sin(3)cos(3)"), ecUNEXPECTED_FUN); + iStat += ThrowTest(_T("a+b+c=10"), ecUNEXPECTED_OPERATOR); + iStat += ThrowTest(_T("a=b=3"), ecUNEXPECTED_OPERATOR); + + // functions without parameter + iStat += ThrowTest(_T("3+ping(2)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("3+ping(a+2)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("3+ping(sin(a)+2)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("3+ping(1+sin(a))"), ecTOO_MANY_PARAMS); + + // String function related + iStat += ThrowTest(_T("valueof(\"xxx\")"), 999, false); + iStat += ThrowTest(_T("valueof()"), ecUNEXPECTED_PARENS); + iStat += ThrowTest(_T("1+valueof(\"abc\""), ecMISSING_PARENS); + iStat += ThrowTest(_T("valueof(\"abc\""), ecMISSING_PARENS); + iStat += ThrowTest(_T("valueof(\"abc"), ecUNTERMINATED_STRING); + iStat += ThrowTest(_T("valueof(\"abc\",3)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("valueof(3)"), ecSTRING_EXPECTED); + iStat += ThrowTest(_T("sin(\"abc\")"), ecVAL_EXPECTED); + iStat += ThrowTest(_T("valueof(\"\\\"abc\\\"\")"), 999, false); + iStat += ThrowTest(_T("\"hello world\""), ecSTR_RESULT); + iStat += ThrowTest(_T("(\"hello world\")"), ecSTR_RESULT); + iStat += ThrowTest(_T("\"abcd\"+100"), ecSTR_RESULT); + iStat += ThrowTest(_T("\"a\"+\"b\""), ecSTR_RESULT); + iStat += ThrowTest(_T("strfun1(\"100\",3)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("strfun2(\"100\",3,5)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("strfun3(\"100\",3,5,6)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("strfun2(\"100\")"), ecTOO_FEW_PARAMS); + iStat += ThrowTest(_T("strfun3(\"100\",6)"), ecTOO_FEW_PARAMS); + iStat += ThrowTest(_T("strfun2(1,1)"), ecSTRING_EXPECTED); + iStat += ThrowTest(_T("strfun2(a,1)"), ecSTRING_EXPECTED); + iStat += ThrowTest(_T("strfun2(1,1,1)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("strfun2(a,1,1)"), ecTOO_MANY_PARAMS); + iStat += ThrowTest(_T("strfun3(1,2,3)"), ecSTRING_EXPECTED); + iStat += ThrowTest(_T("strfun3(1, \"100\",3)"), ecSTRING_EXPECTED); + iStat += ThrowTest(_T("strfun3(\"1\", \"100\",3)"), ecVAL_EXPECTED); + iStat += ThrowTest(_T("strfun3(\"1\", 3, \"100\")"), ecVAL_EXPECTED); + iStat += ThrowTest(_T("strfun3(\"1\", \"100\", \"100\", \"100\")"), ecTOO_MANY_PARAMS); + + // assignment operator + iStat += ThrowTest(_T("3=4"), ecUNEXPECTED_OPERATOR); + iStat += ThrowTest(_T("sin(8)=4"), ecUNEXPECTED_OPERATOR); + iStat += ThrowTest(_T("\"test\"=a"), ecSTR_RESULT); + + // <ibg 20090529> + // this is now legal, for reference see: + // https://sourceforge.net/forum/message.php?msg_id=7411373 + // iStat += ThrowTest( _T("sin=9"), ecUNEXPECTED_OPERATOR); + // </ibg> + + iStat += ThrowTest(_T("(8)=5"), ecUNEXPECTED_OPERATOR); + iStat += ThrowTest(_T("(a)=5"), ecUNEXPECTED_OPERATOR); + iStat += ThrowTest(_T("a=\"tttt\""), ecOPRT_TYPE_CONFLICT); + + if (iStat == 0) + mu::console() << _T("passed") << endl; + else + mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl; + + return iStat; + } + + + //--------------------------------------------------------------------------- + void ParserTester::AddTest(testfun_type a_pFun) + { + m_vTestFun.push_back(a_pFun); + } + + //--------------------------------------------------------------------------- + int ParserTester::Run() + { + int iStat = 0; + try + { + for (int i = 0; i < (int)m_vTestFun.size(); ++i) + iStat += (this->*m_vTestFun[i])(); + } + catch (Parser::exception_type& e) + { + mu::console() << "\n" << e.GetMsg() << endl; + mu::console() << e.GetToken() << endl; + Abort(); + } + catch (std::exception& e) + { + mu::console() << e.what() << endl; + Abort(); + } + catch (...) + { + mu::console() << "Internal error"; + Abort(); + } + + if (iStat == 0) + { + mu::console() << "Test passed (" << ParserTester::c_iCount << " expressions)" << endl; + } + else + { + mu::console() << "Test failed with " << iStat + << " errors (" << ParserTester::c_iCount + << " expressions)" << endl; + } + ParserTester::c_iCount = 0; + return iStat; + } + + + //--------------------------------------------------------------------------- + int ParserTester::ThrowTest(const string_type& a_str, int a_iErrc, bool a_expectedToFail) + { + ParserTester::c_iCount++; + + try + { + value_type fVal[] = { 1,1,1 }; + Parser p; + + p.DefineVar(_T("a"), &fVal[0]); + p.DefineVar(_T("b"), &fVal[1]); + p.DefineVar(_T("c"), &fVal[2]); + p.DefinePostfixOprt(_T("{m}"), Milli); + p.DefinePostfixOprt(_T("m"), Milli); + p.DefineFun(_T("ping"), Ping); + p.DefineFun(_T("valueof"), ValueOf); + p.DefineFun(_T("strfun1"), StrFun1); + p.DefineFun(_T("strfun2"), StrFun2); + p.DefineFun(_T("strfun3"), StrFun3); + p.DefineFun(_T("strfun4"), StrFun4); + p.DefineFun(_T("strfun5"), StrFun5); + p.SetExpr(a_str); +// p.EnableDebugDump(1, 0); + p.Eval(); + } + catch (ParserError& e) + { + // output the formula in case of an failed test + if (a_expectedToFail == false || (a_expectedToFail == true && a_iErrc != e.GetCode())) + { + mu::console() << _T("\n ") + << _T("Expression: ") << a_str + << _T(" Code:") << e.GetCode() << _T("(") << e.GetMsg() << _T(")") + << _T(" Expected:") << a_iErrc; + } + + return (a_iErrc == e.GetCode()) ? 0 : 1; + } + + // if a_expectedToFail == false no exception is expected + bool bRet((a_expectedToFail == false) ? 0 : 1); + if (bRet == 1) + { + mu::console() << _T("\n ") + << _T("Expression: ") << a_str + << _T(" did evaluate; Expected error:") << a_iErrc; + } + + return bRet; + } + + //--------------------------------------------------------------------------- + /** \brief Evaluate a tet expression. + + \return 1 in case of a failure, 0 otherwise. + */ + int ParserTester::EqnTestWithVarChange(const string_type& a_str, + double a_fVar1, + double a_fRes1, + double a_fVar2, + double a_fRes2) + { + ParserTester::c_iCount++; + + try + { + value_type fVal[2] = { -999, -999 }; // should be equal + + Parser p; + value_type var = 0; + + // variable + p.DefineVar(_T("a"), &var); + p.SetExpr(a_str); + + var = a_fVar1; + fVal[0] = p.Eval(); + + var = a_fVar2; + fVal[1] = p.Eval(); + + if (fabs(a_fRes1 - fVal[0]) > 0.0000000001) + throw std::runtime_error("incorrect result (first pass)"); + + if (fabs(a_fRes2 - fVal[1]) > 0.0000000001) + throw std::runtime_error("incorrect result (second pass)"); + } + catch (Parser::exception_type& e) + { + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.GetMsg() << _T(")"); + return 1; + } + catch (std::exception& e) + { + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.what() << _T(")"); + return 1; // always return a failure since this exception is not expected + } + catch (...) + { + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); + return 1; // exceptions other than ParserException are not allowed + } + + return 0; + } + + //--------------------------------------------------------------------------- + /** \brief Evaluate a tet expression. + + \return 1 in case of a failure, 0 otherwise. + */ + int ParserTester::EqnTest(const string_type& a_str, double a_fRes, bool a_fPass) + { + ParserTester::c_iCount++; + int iRet(0); + value_type fVal[5] = { -999, -998, -997, -996, -995 }; // initially should be different + + try + { + std::unique_ptr<Parser> p1; + Parser p2, p3; // three parser objects + // they will be used for testing copy and assignment operators + // p1 is a pointer since i'm going to delete it in order to test if + // parsers after copy construction still refer to members of it. + // !! If this is the case this function will crash !! + + p1.reset(new mu::Parser()); + // Add constants + p1->DefineConst(_T("pi"), MathImpl<value_type>::CONST_PI); + p1->DefineConst(_T("e"), MathImpl<value_type>::CONST_E); + p1->DefineConst(_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]); + p1->DefineVar(_T("aa"), &vVarVal[1]); + p1->DefineVar(_T("b"), &vVarVal[1]); + p1->DefineVar(_T("c"), &vVarVal[2]); + p1->DefineVar(_T("d"), &vVarVal[3]); + + // custom value ident functions + p1->AddValIdent(&ParserTester::IsHexVal); + + // functions + p1->DefineFun(_T("ping"), Ping); + p1->DefineFun(_T("f0"), f0); // no parameter + p1->DefineFun(_T("f1of1"), f1of1); // one parameter + p1->DefineFun(_T("f1of2"), f1of2); // two parameter + p1->DefineFun(_T("f2of2"), f2of2); + p1->DefineFun(_T("f1of3"), f1of3); // three parameter + p1->DefineFun(_T("f2of3"), f2of3); + p1->DefineFun(_T("f3of3"), f3of3); + p1->DefineFun(_T("f1of4"), f1of4); // four parameter + p1->DefineFun(_T("f2of4"), f2of4); + p1->DefineFun(_T("f3of4"), f3of4); + p1->DefineFun(_T("f4of4"), f4of4); + p1->DefineFun(_T("f1of5"), f1of5); // five parameter + p1->DefineFun(_T("f2of5"), f2of5); + p1->DefineFun(_T("f3of5"), f3of5); + p1->DefineFun(_T("f4of5"), f4of5); + p1->DefineFun(_T("f5of5"), f5of5); + + // binary operators + p1->DefineOprt(_T("add"), add, 0); + p1->DefineOprt(_T("++"), add, 0); + p1->DefineOprt(_T("&"), land, prLAND); + + // sample functions + p1->DefineFun(_T("min"), Min); + p1->DefineFun(_T("max"), Max); + p1->DefineFun(_T("sum"), Sum); + p1->DefineFun(_T("valueof"), ValueOf); + p1->DefineFun(_T("atof"), StrToFloat); + p1->DefineFun(_T("strfun1"), StrFun1); + p1->DefineFun(_T("strfun2"), StrFun2); + p1->DefineFun(_T("strfun3"), StrFun3); + p1->DefineFun(_T("strfun4"), StrFun4); + p1->DefineFun(_T("strfun5"), StrFun5); + p1->DefineFun(_T("lastArg"), LastArg); + p1->DefineFun(_T("firstArg"), FirstArg); + p1->DefineFun(_T("order"), FirstArg); + + // infix / postfix operator + // Note: Identifiers used here do not have any meaning + // they are mere placeholders to test certain features. + p1->DefineInfixOprt(_T("$"), sign, prPOW + 1); // sign with high priority + p1->DefineInfixOprt(_T("~"), plus2); // high priority + p1->DefineInfixOprt(_T("~~"), plus2); + p1->DefinePostfixOprt(_T("{m}"), Milli); + p1->DefinePostfixOprt(_T("{M}"), Mega); + p1->DefinePostfixOprt(_T("m"), Milli); + p1->DefinePostfixOprt(_T("meg"), Mega); + p1->DefinePostfixOprt(_T("#"), times3); + p1->DefinePostfixOprt(_T("'"), sqr); + p1->SetExpr(a_str); + + // Test bytecode integrity + // String parsing and bytecode parsing must yield the same result + fVal[0] = p1->Eval(); // result from stringparsing + fVal[1] = p1->Eval(); // result from bytecode + if (fVal[0] != fVal[1]) + throw Parser::exception_type(_T("Bytecode / string parsing mismatch.")); + + // Test copy and assignment operators + try + { + // Test copy constructor + std::vector<mu::Parser> vParser; + vParser.push_back(*(p1.get())); + mu::Parser p4 = vParser[0]; // take parser from vector + + // destroy the originals from p2 + vParser.clear(); // delete the vector + p1.reset(0); + + fVal[2] = p4.Eval(); + + // Test assignment operator + // additionally disable Optimizer this time + mu::Parser p5; + p5 = p4; + p5.EnableOptimizer(false); + fVal[3] = p5.Eval(); + + // Test Eval function for multiple return values + // use p2 since it has the optimizer enabled! + int nNum; + value_type* v = p4.Eval(nNum); + fVal[4] = v[nNum - 1]; + } + catch (std::exception& e) + { + mu::console() << _T("\n ") << e.what() << _T("\n"); + } + + // limited floating point accuracy requires the following test + bool bCloseEnough(true); + for (unsigned i = 0; i < sizeof(fVal) / sizeof(value_type); ++i) + { + bCloseEnough &= (fabs(a_fRes - fVal[i]) <= fabs(fVal[i] * 0.00001)); + + // The tests equations never result in infinity, if they do thats a bug. + // reference: + // http://sourceforge.net/projects/muparser/forums/forum/462843/topic/5037825 +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4127) +#endif + if (std::numeric_limits<value_type>::has_infinity) +#ifdef _MSC_VER +#pragma warning(pop) +#endif + { + bCloseEnough &= (fabs(fVal[i]) != numeric_limits<value_type>::infinity()); + } + } + + 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 + << _T(" ;calculated: ") << fVal[0] << _T(",") + << fVal[1] << _T(",") + << fVal[2] << _T(",") + << fVal[3] << _T(",") + << fVal[4] << _T(")."); + } + } + catch (Parser::exception_type& e) + { + if (a_fPass) + { + if (fVal[0] != fVal[2] && fVal[0] != -999 && fVal[1] != -998) + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (copy construction)"); + else + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.GetMsg() << _T(")"); + return 1; + } + } + catch (std::exception& e) + { + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (") << e.what() << _T(")"); + return 1; // always return a failure since this exception is not expected + } + catch (...) + { + mu::console() << _T("\n fail: ") << a_str.c_str() << _T(" (unexpected exception)"); + return 1; // exceptions other than ParserException are not allowed + } + + return iRet; + } + + //--------------------------------------------------------------------------- + int ParserTester::EqnTestInt(const string_type& a_str, double a_fRes, bool a_fPass) + { + ParserTester::c_iCount++; + + value_type vVarVal[] = { 1, 2, 3 }; // variable values + 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); + p.DefineVar(_T("a"), &vVarVal[0]); + p.DefineVar(_T("b"), &vVarVal[1]); + p.DefineVar(_T("c"), &vVarVal[2]); + + p.SetExpr(a_str); + fVal[0] = p.Eval(); // result from stringparsing + fVal[1] = p.Eval(); // result from bytecode + + if (fVal[0] != fVal[1]) + throw Parser::exception_type(_T("Bytecode corrupt.")); + + iRet = ((a_fRes == fVal[0] && a_fPass) || + (a_fRes != fVal[0] && !a_fPass)) ? 0 : 1; + if (iRet == 1) + { + mu::console() << _T("\n fail: ") << a_str.c_str() + << _T(" (incorrect result; expected: ") << a_fRes + << _T(" ;calculated: ") << fVal[0] << _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 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 + { + mu::console() << _T("Test failed (internal error in test class)") << endl; + while (!getchar()); + exit(-1); + } + } // namespace test +} // namespace mu diff --git a/3rdParty/MuParser/src/muParserTokenReader.cpp b/3rdParty/MuParser/src/muParserTokenReader.cpp index 7b4a4d6b66d4e4b44756bc8e583a02576efc4612..f478d6a983435bd7880dd5bf1a2b9b091fbc13b7 100644 --- a/3rdParty/MuParser/src/muParserTokenReader.cpp +++ b/3rdParty/MuParser/src/muParserTokenReader.cpp @@ -1,958 +1,993 @@ -/* - __________ - _____ __ __\______ \_____ _______ ______ ____ _______ - / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \ - | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/ - |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__| - \/ \/ \/ \/ - Copyright (C) 2013 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. -*/ -#include <cassert> -#include <cstdio> -#include <cstring> -#include <map> -#include <stack> -#include <string> - -#include "muParserTokenReader.h" -#include "muParserBase.h" - -/** \file - \brief This file contains the parser token reader implementation. -*/ - - -namespace mu -{ - - // Forward declaration - class ParserBase; - - //--------------------------------------------------------------------------- - /** \brief Copy constructor. - - \sa Assign - \throw nothrow - */ - ParserTokenReader::ParserTokenReader(const ParserTokenReader &a_Reader) - { - Assign(a_Reader); - } - - //--------------------------------------------------------------------------- - /** \brief Assignment operator. - - Self assignment will be suppressed otherwise #Assign is called. - - \param a_Reader Object to copy to this token reader. - \throw nothrow - */ - ParserTokenReader& ParserTokenReader::operator=(const ParserTokenReader &a_Reader) - { - if (&a_Reader!=this) - Assign(a_Reader); - - return *this; - } - - //--------------------------------------------------------------------------- - /** \brief Assign state of a token reader to this token reader. - - \param a_Reader Object from which the state should be copied. - \throw nothrow - */ - void ParserTokenReader::Assign(const ParserTokenReader &a_Reader) - { - m_pParser = a_Reader.m_pParser; - m_strFormula = a_Reader.m_strFormula; - m_iPos = a_Reader.m_iPos; - m_iSynFlags = a_Reader.m_iSynFlags; - - m_UsedVar = a_Reader.m_UsedVar; - m_pFunDef = a_Reader.m_pFunDef; - m_pConstDef = a_Reader.m_pConstDef; - m_pVarDef = a_Reader.m_pVarDef; - m_pStrVarDef = a_Reader.m_pStrVarDef; - m_pPostOprtDef = a_Reader.m_pPostOprtDef; - m_pInfixOprtDef = a_Reader.m_pInfixOprtDef; - m_pOprtDef = a_Reader.m_pOprtDef; - m_bIgnoreUndefVar = a_Reader.m_bIgnoreUndefVar; - m_vIdentFun = a_Reader.m_vIdentFun; - m_pFactory = a_Reader.m_pFactory; - 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; - } - - //--------------------------------------------------------------------------- - /** \brief Constructor. - - Create a Token reader and bind it to a parser object. - - \pre [assert] a_pParser may not be NULL - \post #m_pParser==a_pParser - \param a_pParent Parent parser object of the token reader. - */ - ParserTokenReader::ParserTokenReader(ParserBase *a_pParent) - :m_pParser(a_pParent) - ,m_strFormula() - ,m_iPos(0) - ,m_iSynFlags(0) - ,m_bIgnoreUndefVar(false) - ,m_pFunDef(NULL) - ,m_pPostOprtDef(NULL) - ,m_pInfixOprtDef(NULL) - ,m_pOprtDef(NULL) - ,m_pConstDef(NULL) - ,m_pStrVarDef(NULL) - ,m_pVarDef(NULL) - ,m_pFactory(NULL) - ,m_pFactoryData(NULL) - ,m_vIdentFun() - ,m_UsedVar() - ,m_fZero(0) - ,m_iBrackets(0) - ,m_lastTok() - ,m_cArgSep(',') - { - assert(m_pParser); - SetParent(m_pParser); - } - - //--------------------------------------------------------------------------- - /** \brief Create instance of a ParserTokenReader identical with this - and return its pointer. - - This is a factory method the calling function must take care of the object destruction. - - \return A new ParserTokenReader object. - \throw nothrow - */ - ParserTokenReader* ParserTokenReader::Clone(ParserBase *a_pParent) const - { - std::auto_ptr<ParserTokenReader> ptr(new ParserTokenReader(*this)); - ptr->SetParent(a_pParent); - return ptr.release(); - } - - //--------------------------------------------------------------------------- - ParserTokenReader::token_type& ParserTokenReader::SaveBeforeReturn(const token_type &tok) - { - m_lastTok = tok; - return m_lastTok; - } - - //--------------------------------------------------------------------------- - void ParserTokenReader::AddValIdent(identfun_type a_pCallback) - { - // Use push_front is used to give user defined callbacks a higher priority than - // the built in ones. Otherwise reading hex numbers would not work - // since the "0" in "0xff" would always be read first making parsing of - // the rest impossible. - // reference: - // http://sourceforge.net/projects/muparser/forums/forum/462843/topic/4824956 - m_vIdentFun.push_front(a_pCallback); - } - - //--------------------------------------------------------------------------- - void ParserTokenReader::SetVarCreator(facfun_type a_pFactory, void *pUserData) - { - m_pFactory = a_pFactory; - m_pFactoryData = pUserData; - } - - //--------------------------------------------------------------------------- - /** \brief Return the current position of the token reader in the formula string. - - \return #m_iPos - \throw nothrow - */ - int ParserTokenReader::GetPos() const - { - return m_iPos; - } - - //--------------------------------------------------------------------------- - /** \brief Return a reference to the formula. - - \return #m_strFormula - \throw nothrow - */ - const string_type& ParserTokenReader::GetExpr() const - { - return m_strFormula; - } - - //--------------------------------------------------------------------------- - /** \brief Return a map containing the used variables only. */ - varmap_type& ParserTokenReader::GetUsedVar() - { - return m_UsedVar; - } - - //--------------------------------------------------------------------------- - /** \brief Initialize the token Reader. - - Sets the formula position index to zero and set Syntax flags to default for initial formula parsing. - \pre [assert] triggered if a_szFormula==0 - */ - void ParserTokenReader::SetFormula(const string_type &a_strFormula) - { - m_strFormula = a_strFormula; - ReInit(); - } - - //--------------------------------------------------------------------------- - /** \brief Set Flag that controls behaviour in case of undefined variables being found. - - If true, the parser does not throw an exception if an undefined variable is found. - otherwise it does. This variable is used internally only! - It suppresses a "undefined variable" exception in GetUsedVar(). - Those function should return a complete list of variables including - those the are not defined by the time of it's call. - */ - void ParserTokenReader::IgnoreUndefVar(bool bIgnore) - { - m_bIgnoreUndefVar = bIgnore; - } - - //--------------------------------------------------------------------------- - /** \brief Reset the token reader to the start of the formula. - - The syntax flags will be reset to a value appropriate for the - start of a formula. - \post #m_iPos==0, #m_iSynFlags = noOPT | noBC | noPOSTOP | noSTR - \throw nothrow - \sa ESynCodes - */ - void ParserTokenReader::ReInit() - { - m_iPos = 0; - m_iSynFlags = sfSTART_OF_LINE; - m_iBrackets = 0; - m_UsedVar.clear(); - m_lastTok = token_type(); - } - - //--------------------------------------------------------------------------- - /** \brief Read the next token from the string. */ - ParserTokenReader::token_type ParserTokenReader::ReadNextToken() - { - assert(m_pParser); - - const char_type *szFormula = m_strFormula.c_str(); - token_type tok; - - // Ignore all non printable characters when reading the expression - while (szFormula[m_iPos]>0 && szFormula[m_iPos]<=0x20) - ++m_iPos; - - if ( IsEOF(tok) ) return SaveBeforeReturn(tok); // Check for end of formula - if ( IsOprt(tok) ) return SaveBeforeReturn(tok); // Check for user defined binary operator - if ( IsFunTok(tok) ) return SaveBeforeReturn(tok); // Check for function token - if ( IsBuiltIn(tok) ) return SaveBeforeReturn(tok); // Check built in operators / tokens - if ( IsArgSep(tok) ) return SaveBeforeReturn(tok); // Check for function argument separators - if ( IsValTok(tok) ) return SaveBeforeReturn(tok); // Check for values / constant tokens - if ( IsVarTok(tok) ) return SaveBeforeReturn(tok); // Check for variable tokens - if ( IsStrVarTok(tok) ) return SaveBeforeReturn(tok); // Check for string variables - if ( IsString(tok) ) return SaveBeforeReturn(tok); // Check for String tokens - if ( IsInfixOpTok(tok) ) return SaveBeforeReturn(tok); // Check for unary operators - if ( IsPostOpTok(tok) ) return SaveBeforeReturn(tok); // Check for unary operators - - // Check String for undefined variable token. Done only if a - // flag is set indicating to ignore undefined variables. - // This is a way to conditionally avoid an error if - // undefined variables occur. - // (The GetUsedVar function must suppress the error for - // undefined variables in order to collect all variable - // names including the undefined ones.) - if ( (m_bIgnoreUndefVar || m_pFactory) && IsUndefVarTok(tok) ) - return SaveBeforeReturn(tok); - - // Check for unknown token - // - // !!! From this point on there is no exit without an exception possible... - // - string_type strTok; - int iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos); - if (iEnd!=m_iPos) - Error(ecUNASSIGNABLE_TOKEN, m_iPos, strTok); - - Error(ecUNASSIGNABLE_TOKEN, m_iPos, m_strFormula.substr(m_iPos)); - return token_type(); // never reached - } - - //--------------------------------------------------------------------------- - void ParserTokenReader::SetParent(ParserBase *a_pParent) - { - m_pParser = a_pParent; - m_pFunDef = &a_pParent->m_FunDef; - m_pOprtDef = &a_pParent->m_OprtDef; - m_pInfixOprtDef = &a_pParent->m_InfixOprtDef; - m_pPostOprtDef = &a_pParent->m_PostOprtDef; - m_pVarDef = &a_pParent->m_VarDef; - m_pStrVarDef = &a_pParent->m_StrVarDef; - m_pConstDef = &a_pParent->m_ConstDef; - } - - //--------------------------------------------------------------------------- - /** \brief Extract all characters that belong to a certain charset. - - \param a_szCharSet [in] Const char array of the characters allowed in the token. - \param a_strTok [out] The string that consists entirely of characters listed in a_szCharSet. - \param a_iPos [in] Position in the string from where to start reading. - \return The Position of the first character not listed in a_szCharSet. - \throw nothrow - */ - int ParserTokenReader::ExtractToken(const char_type *a_szCharSet, - string_type &a_sTok, - int a_iPos) const - { - int iEnd = (int)m_strFormula.find_first_not_of(a_szCharSet, a_iPos); - - if (iEnd==(int)string_type::npos) - iEnd = (int)m_strFormula.length(); - - // Assign token string if there was something found - if (a_iPos!=iEnd) - a_sTok = string_type( m_strFormula.begin()+a_iPos, m_strFormula.begin()+iEnd); - - return iEnd; - } - - //--------------------------------------------------------------------------- - /** \brief Check Expression for the presence of a binary operator token. - - Userdefined binary operator "++" gives inconsistent parsing result for - the equations "a++b" and "a ++ b" if alphabetic characters are allowed - in operator tokens. To avoid this this function checks specifically - for operator tokens. - */ - int ParserTokenReader::ExtractOperatorToken(string_type &a_sTok, - int a_iPos) const - { - // 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(); - - // Assign token string if there was something found - if (a_iPos!=iEnd) - { - a_sTok = string_type( m_strFormula.begin() + a_iPos, m_strFormula.begin() + iEnd); - return iEnd; - } - else - { - // There is still the chance of having to deal with an operator consisting exclusively - // of alphabetic characters. - return ExtractToken(MUP_CHARS, a_sTok, a_iPos); - } - } - - //--------------------------------------------------------------------------- - /** \brief Check if a built in operator or other token can be found - \param a_Tok [out] Operator token if one is found. This can either be a binary operator or an infix operator token. - \return true if an operator token has been found. - */ - bool ParserTokenReader::IsBuiltIn(token_type &a_Tok) - { - const char_type **const pOprtDef = m_pParser->GetOprtDef(), - *const szFormula = m_strFormula.c_str(); - - // Compare token with function and operator strings - // check string for operator/function - for (int i=0; pOprtDef[i]; i++) - { - std::size_t len( std::char_traits<char_type>::length(pOprtDef[i]) ); - if ( string_type(pOprtDef[i]) == string_type(szFormula + m_iPos, szFormula + m_iPos + len) ) - { - switch(i) - { - //case cmAND: - //case cmOR: - //case cmXOR: - case cmLAND: - case cmLOR: - case cmLT: - case cmGT: - case cmLE: - case cmGE: - case cmNEQ: - case cmEQ: - case cmADD: - case cmSUB: - case cmMUL: - case cmDIV: - case cmPOW: - case cmASSIGN: - //if (len!=sTok.length()) - // continue; - - // The assignment operator need special treatment - if (i==cmASSIGN && m_iSynFlags & noASSIGN) - Error(ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef[i]); - - if (!m_pParser->HasBuiltInOprt()) continue; - if (m_iSynFlags & noOPT) - { - // Maybe its an infix operator not an operator - // Both operator types can share characters in - // their identifiers - if ( IsInfixOpTok(a_Tok) ) - return true; - - Error(ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef[i]); - } - - m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE | noEND; - break; - - case cmBO: - if (m_iSynFlags & noBO) - Error(ecUNEXPECTED_PARENS, m_iPos, pOprtDef[i]); - - if (m_lastTok.GetCode()==cmFUNC) - m_iSynFlags = noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE; - else - m_iSynFlags = noBC | noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN| noIF | noELSE; - - ++m_iBrackets; - break; - - case cmBC: - if (m_iSynFlags & noBC) - Error(ecUNEXPECTED_PARENS, m_iPos, pOprtDef[i]); - - m_iSynFlags = noBO | noVAR | noVAL | noFUN | noINFIXOP | noSTR | noASSIGN; - - if (--m_iBrackets<0) - Error(ecUNEXPECTED_PARENS, m_iPos, pOprtDef[i]); - break; - - case cmELSE: - if (m_iSynFlags & noELSE) - Error(ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef[i]); - - m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE; - break; - - case cmIF: - if (m_iSynFlags & noIF) - Error(ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef[i]); - - m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE; - break; - - default: // The operator is listed in c_DefaultOprt, but not here. This is a bad thing... - Error(ecINTERNAL_ERROR); - } // switch operator id - - m_iPos += (int)len; - a_Tok.Set( (ECmdCode)i, pOprtDef[i] ); - return true; - } // if operator string found - } // end of for all operator strings - - return false; - } - - //--------------------------------------------------------------------------- - bool ParserTokenReader::IsArgSep(token_type &a_Tok) - { - const char_type* szFormula = m_strFormula.c_str(); - - if (szFormula[m_iPos]==m_cArgSep) - { - // copy the separator into null terminated string - char_type szSep[2]; - szSep[0] = m_cArgSep; - szSep[1] = 0; - - if (m_iSynFlags & noARG_SEP) - Error(ecUNEXPECTED_ARG_SEP, m_iPos, szSep); - - m_iSynFlags = noBC | noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN; - m_iPos++; - a_Tok.Set(cmARG_SEP, szSep); - return true; - } - - return false; - } - - //--------------------------------------------------------------------------- - /** \brief Check for End of Formula. - - \return true if an end of formula is found false otherwise. - \param a_Tok [out] If an eof is found the corresponding token will be stored there. - \throw nothrow - \sa IsOprt, IsFunTok, IsStrFunTok, IsValTok, IsVarTok, IsString, IsInfixOpTok, IsPostOpTok - */ - bool ParserTokenReader::IsEOF(token_type &a_Tok) - { - const char_type* szFormula = m_strFormula.c_str(); - - // check for EOF - if ( !szFormula[m_iPos] /*|| szFormula[m_iPos] == '\n'*/) - { - if ( m_iSynFlags & noEND ) - Error(ecUNEXPECTED_EOF, m_iPos); - - if (m_iBrackets>0) - Error(ecMISSING_PARENS, m_iPos, _T(")")); - - m_iSynFlags = 0; - a_Tok.Set(cmEND); - return true; - } - - return false; - } - - //--------------------------------------------------------------------------- - /** \brief Check if a string position contains a unary infix operator. - \return true if a function token has been found false otherwise. - */ - bool ParserTokenReader::IsInfixOpTok(token_type &a_Tok) - { - string_type sTok; - int iEnd = ExtractToken(m_pParser->ValidInfixOprtChars(), sTok, m_iPos); - if (iEnd==m_iPos) - return false; - - // iterate over all postfix operator strings - funmap_type::const_reverse_iterator it = m_pInfixOprtDef->rbegin(); - for ( ; it!=m_pInfixOprtDef->rend(); ++it) - { - if (sTok.find(it->first)!=0) - continue; - - a_Tok.Set(it->second, it->first); - m_iPos += (int)it->first.length(); - - if (m_iSynFlags & noINFIXOP) - Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString()); - - m_iSynFlags = noPOSTOP | noINFIXOP | noOPT | noBC | noSTR | noASSIGN; - return true; - } - - return false; - -/* - a_Tok.Set(item->second, sTok); - m_iPos = (int)iEnd; - - if (m_iSynFlags & noINFIXOP) - Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString()); - - m_iSynFlags = noPOSTOP | noINFIXOP | noOPT | noBC | noSTR | noASSIGN; - return true; -*/ - } - - //--------------------------------------------------------------------------- - /** \brief Check whether the token at a given position is a function token. - \param a_Tok [out] If a value token is found it will be placed here. - \throw ParserException if Syntaxflags do not allow a function at a_iPos - \return true if a function token has been found false otherwise. - \pre [assert] m_pParser!=0 - */ - bool ParserTokenReader::IsFunTok(token_type &a_Tok) - { - string_type strTok; - int iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos); - if (iEnd==m_iPos) - return false; - - funmap_type::const_iterator item = m_pFunDef->find(strTok); - if (item==m_pFunDef->end()) - return false; - - // Check if the next sign is an opening bracket - const char_type *szFormula = m_strFormula.c_str(); - if (szFormula[iEnd]!='(') - return false; - - a_Tok.Set(item->second, strTok); - - m_iPos = (int)iEnd; - if (m_iSynFlags & noFUN) - Error(ecUNEXPECTED_FUN, m_iPos-(int)a_Tok.GetAsString().length(), a_Tok.GetAsString()); - - m_iSynFlags = noANY ^ noBO; - return true; - } - - //--------------------------------------------------------------------------- - /** \brief Check if a string position contains a binary operator. - \param a_Tok [out] Operator token if one is found. This can either be a binary operator or an infix operator token. - \return true if an operator token has been found. - */ - bool ParserTokenReader::IsOprt(token_type &a_Tok) - { - const char_type *const szExpr = m_strFormula.c_str(); - string_type strTok; - - int iEnd = ExtractOperatorToken(strTok, m_iPos); - if (iEnd==m_iPos) - return false; - - // Check if the operator is a built in operator, if so ignore it here - const char_type **const pOprtDef = m_pParser->GetOprtDef(); - for (int i=0; m_pParser->HasBuiltInOprt() && pOprtDef[i]; ++i) - { - if (string_type(pOprtDef[i])==strTok) - return false; - } - - // Note: - // All tokens in oprt_bin_maptype are have been sorted by their length - // Long operators must come first! Otherwise short names (like: "add") that - // are part of long token names (like: "add123") will be found instead - // of the long ones. - // Length sorting is done with ascending length so we use a reverse iterator here. - funmap_type::const_reverse_iterator it = m_pOprtDef->rbegin(); - for ( ; it!=m_pOprtDef->rend(); ++it) - { - const string_type &sID = it->first; - if ( sID == string_type(szExpr + m_iPos, szExpr + m_iPos + sID.length()) ) - { - a_Tok.Set(it->second, strTok); - - // operator was found - if (m_iSynFlags & noOPT) - { - // An operator was found but is not expected to occur at - // this position of the formula, maybe it is an infix - // operator, not a binary operator. Both operator types - // can share characters in their identifiers. - if ( IsInfixOpTok(a_Tok) ) - return true; - else - { - // nope, no infix operator - return false; - //Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString()); - } - - } - - m_iPos += (int)sID.length(); - m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noASSIGN; - return true; - } - } - - return false; - } - - //--------------------------------------------------------------------------- - /** \brief Check if a string position contains a unary post value operator. */ - bool ParserTokenReader::IsPostOpTok(token_type &a_Tok) - { - // <ibg 20110629> Do not check for postfix operators if they are not allowed at - // the current expression index. - // - // This will fix the bug reported here: - // - // http://sourceforge.net/tracker/index.php?func=detail&aid=3343891&group_id=137191&atid=737979 - // - if (m_iSynFlags & noPOSTOP) - return false; - // </ibg> - - // Tricky problem with equations like "3m+5": - // m is a postfix operator, + is a valid sign for postfix operators and - // for binary operators parser detects "m+" as operator string and - // finds no matching postfix operator. - // - // This is a special case so this routine slightly differs from the other - // token readers. - - // Test if there could be a postfix operator - string_type sTok; - int iEnd = ExtractToken(m_pParser->ValidOprtChars(), sTok, m_iPos); - if (iEnd==m_iPos) - return false; - - // iterate over all postfix operator strings - funmap_type::const_reverse_iterator it = m_pPostOprtDef->rbegin(); - for ( ; it!=m_pPostOprtDef->rend(); ++it) - { - if (sTok.find(it->first)!=0) - continue; - - a_Tok.Set(it->second, sTok); - m_iPos += (int)it->first.length(); - - m_iSynFlags = noVAL | noVAR | noFUN | noBO | noPOSTOP | noSTR | noASSIGN; - return true; - } - - return false; - } - - //--------------------------------------------------------------------------- - /** \brief Check whether the token at a given position is a value token. - - Value tokens are either values or constants. - - \param a_Tok [out] If a value token is found it will be placed here. - \return true if a value token has been found. - */ - bool ParserTokenReader::IsValTok(token_type &a_Tok) - { - assert(m_pConstDef); - assert(m_pParser); - - string_type strTok; - value_type fVal(0); - int iEnd(0); - - // 2.) Check for user defined constant - // Read everything that could be a constant name - iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos); - if (iEnd!=m_iPos) - { - valmap_type::const_iterator item = m_pConstDef->find(strTok); - if (item!=m_pConstDef->end()) - { - m_iPos = iEnd; - a_Tok.SetVal(item->second, strTok); - - if (m_iSynFlags & noVAL) - Error(ecUNEXPECTED_VAL, m_iPos - (int)strTok.length(), strTok); - - m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR | noASSIGN; - return true; - } - } - - // 3.call the value recognition functions provided by the user - // Call user defined value recognition functions - std::list<identfun_type>::const_iterator item = m_vIdentFun.begin(); - for (item = m_vIdentFun.begin(); item!=m_vIdentFun.end(); ++item) - { - int iStart = m_iPos; - if ( (*item)(m_strFormula.c_str() + m_iPos, &m_iPos, &fVal)==1 ) - { - // 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); - - a_Tok.SetVal(fVal, strTok); - m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR | noASSIGN; - return true; - } - } - - return false; - } - - //--------------------------------------------------------------------------- - /** \brief Check wheter a token at a given position is a variable token. - \param a_Tok [out] If a variable token has been found it will be placed here. - \return true if a variable token has been found. - */ - bool ParserTokenReader::IsVarTok(token_type &a_Tok) - { - if (m_pVarDef->empty()) - return false; - - string_type strTok; - int iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos); - if (iEnd==m_iPos) - return false; - - varmap_type::const_iterator item = m_pVarDef->find(strTok); - if (item==m_pVarDef->end()) - return false; - - if (m_iSynFlags & noVAR) - Error(ecUNEXPECTED_VAR, m_iPos, strTok); - - m_pParser->OnDetectVar(&m_strFormula, m_iPos, iEnd); - - m_iPos = iEnd; - a_Tok.SetVar(item->second, strTok); - m_UsedVar[item->first] = item->second; // Add variable to used-var-list - - m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR; - -// Zur Info hier die SynFlags von IsVal(): -// m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR | noASSIGN; - return true; - } - - //--------------------------------------------------------------------------- - bool ParserTokenReader::IsStrVarTok(token_type &a_Tok) - { - if (!m_pStrVarDef || m_pStrVarDef->empty()) - return false; - - string_type strTok; - int iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos); - if (iEnd==m_iPos) - return false; - - strmap_type::const_iterator item = m_pStrVarDef->find(strTok); - if (item==m_pStrVarDef->end()) - return false; - - if (m_iSynFlags & noSTR) - Error(ecUNEXPECTED_VAR, m_iPos, strTok); - - m_iPos = iEnd; - if (!m_pParser->m_vStringVarBuf.size()) - Error(ecINTERNAL_ERROR); - - a_Tok.SetString(m_pParser->m_vStringVarBuf[item->second], m_pParser->m_vStringVarBuf.size() ); - - m_iSynFlags = noANY ^ ( noBC | noOPT | noEND | noARG_SEP); - return true; - } - - - //--------------------------------------------------------------------------- - /** \brief Check wheter a token at a given position is an undefined variable. - - \param a_Tok [out] If a variable tom_pParser->m_vStringBufken has been found it will be placed here. - \return true if a variable token has been found. - \throw nothrow - */ - bool ParserTokenReader::IsUndefVarTok(token_type &a_Tok) - { - string_type strTok; - int iEnd( ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos) ); - if ( iEnd==m_iPos ) - return false; - - if (m_iSynFlags & noVAR) - { - // <ibg/> 20061021 added token string strTok instead of a_Tok.GetAsString() as the - // token identifier. - // related bug report: - // http://sourceforge.net/tracker/index.php?func=detail&aid=1578779&group_id=137191&atid=737979 - Error(ecUNEXPECTED_VAR, m_iPos - (int)a_Tok.GetAsString().length(), strTok); - } - - // If a factory is available implicitely create new variables - if (m_pFactory) - { - value_type *fVar = m_pFactory(strTok.c_str(), m_pFactoryData); - a_Tok.SetVar(fVar, strTok ); - - // Do not use m_pParser->DefineVar( strTok, fVar ); - // in order to define the new variable, it will clear the - // m_UsedVar array which will kill previously defined variables - // from the list - // This is safe because the new variable can never override an existing one - // because they are checked first! - (*m_pVarDef)[strTok] = fVar; - m_UsedVar[strTok] = fVar; // Add variable to used-var-list - } - else - { - a_Tok.SetVar((value_type*)&m_fZero, strTok); - m_UsedVar[strTok] = 0; // Add variable to used-var-list - } - - m_iPos = iEnd; - - // Call the variable factory in order to let it define a new parser variable - m_iSynFlags = noVAL | noVAR | noFUN | noBO | noPOSTOP | noINFIXOP | noSTR; - return true; - } - - - //--------------------------------------------------------------------------- - /** \brief Check wheter a token at a given position is a string. - \param a_Tok [out] If a variable token has been found it will be placed here. - \return true if a string token has been found. - \sa IsOprt, IsFunTok, IsStrFunTok, IsValTok, IsVarTok, IsEOF, IsInfixOpTok, IsPostOpTok - \throw nothrow - */ - bool ParserTokenReader::IsString(token_type &a_Tok) - { - if (m_strFormula[m_iPos]!='"') - return false; - - string_type strBuf(&m_strFormula[m_iPos+1]); - std::size_t iEnd(0), iSkip(0); - - // parser over escaped '\"' end replace them with '"' - for(iEnd=(int)strBuf.find( _T("\"") ); iEnd!=0 && iEnd!=string_type::npos; iEnd=(int)strBuf.find( _T("\""), iEnd)) - { - if (strBuf[iEnd-1]!='\\') break; - strBuf.replace(iEnd-1, 2, _T("\"") ); - iSkip++; - } - - if (iEnd==string_type::npos) - Error(ecUNTERMINATED_STRING, m_iPos, _T("\"") ); - - string_type strTok(strBuf.begin(), strBuf.begin()+iEnd); - - if (m_iSynFlags & noSTR) - Error(ecUNEXPECTED_STR, m_iPos, strTok); - - m_pParser->m_vStringBuf.push_back(strTok); // Store string in internal buffer - a_Tok.SetString(strTok, m_pParser->m_vStringBuf.size()); - - m_iPos += (int)strTok.length() + 2 + (int)iSkip; // +2 wg Anfuehrungszeichen; +iSkip fuer entfernte escape zeichen - m_iSynFlags = noANY ^ ( noARG_SEP | noBC | noOPT | noEND ); - - return true; - } - - //--------------------------------------------------------------------------- - /** \brief Create an error containing the parse error position. - - This function will create an Parser Exception object containing the error text and its position. - - \param a_iErrc [in] The error code of type #EErrorCodes. - \param a_iPos [in] The position where the error was detected. - \param a_strTok [in] The token string representation associated with the error. - \throw ParserException always throws thats the only purpose of this function. - */ - void ParserTokenReader::Error( EErrorCodes a_iErrc, - int a_iPos, - const string_type &a_sTok) const - { - m_pParser->Error(a_iErrc, a_iPos, a_sTok); - } - - //--------------------------------------------------------------------------- - void ParserTokenReader::SetArgSep(char_type cArgSep) - { - m_cArgSep = cArgSep; - } - - //--------------------------------------------------------------------------- - char_type ParserTokenReader::GetArgSep() const - { - return m_cArgSep; - } -} // namespace mu - +/* + + _____ __ _____________ _______ ______ ___________ + / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ + | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ + |__|_| /____/| __(____ /__| /____ >\___ >__| + \/ |__| \/ \/ \/ + Copyright (C) 2004 - 2020 Ingo Berg + + Redistribution and use in source and binary forms, with or without modification, are permitted + provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of + conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of + conditions and the following disclaimer in the documentation and/or other materials provided + with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <cstdio> +#include <cstring> +#include <map> +#include <stack> +#include <string> + +#include "muParserTokenReader.h" +#include "muParserBase.h" + +#if defined(_MSC_VER) + #pragma warning(push) + #pragma warning(disable : 26812) +#endif + +/** \file + \brief This file contains the parser token reader implementation. +*/ + + +namespace mu +{ + + // Forward declaration + class ParserBase; + + /** \brief Copy constructor. + + \sa Assign + \throw nothrow + */ + ParserTokenReader::ParserTokenReader(const ParserTokenReader& a_Reader) + { + Assign(a_Reader); + } + + + /** \brief Assignment operator. + + Self assignment will be suppressed otherwise #Assign is called. + + \param a_Reader Object to copy to this token reader. + \throw nothrow + */ + ParserTokenReader& ParserTokenReader::operator=(const ParserTokenReader& a_Reader) + { + if (&a_Reader != this) + Assign(a_Reader); + + return *this; + } + + + /** \brief Assign state of a token reader to this token reader. + + \param a_Reader Object from which the state should be copied. + \throw nothrow + */ + void ParserTokenReader::Assign(const ParserTokenReader& a_Reader) + { + m_pParser = a_Reader.m_pParser; + m_strFormula = a_Reader.m_strFormula; + m_iPos = a_Reader.m_iPos; + m_iSynFlags = a_Reader.m_iSynFlags; + + m_UsedVar = a_Reader.m_UsedVar; + m_pFunDef = a_Reader.m_pFunDef; + m_pConstDef = a_Reader.m_pConstDef; + m_pVarDef = a_Reader.m_pVarDef; + m_pStrVarDef = a_Reader.m_pStrVarDef; + m_pPostOprtDef = a_Reader.m_pPostOprtDef; + m_pInfixOprtDef = a_Reader.m_pInfixOprtDef; + m_pOprtDef = a_Reader.m_pOprtDef; + m_bIgnoreUndefVar = a_Reader.m_bIgnoreUndefVar; + m_vIdentFun = a_Reader.m_vIdentFun; + m_pFactory = a_Reader.m_pFactory; + m_pFactoryData = a_Reader.m_pFactoryData; + m_bracketStack = a_Reader.m_bracketStack; + m_cArgSep = a_Reader.m_cArgSep; + m_fZero = a_Reader.m_fZero; + m_lastTok = a_Reader.m_lastTok; + } + + + /** \brief Constructor. + + Create a Token reader and bind it to a parser object. + + \pre [assert] a_pParser may not be NULL + \post #m_pParser==a_pParser + \param a_pParent Parent parser object of the token reader. + */ + ParserTokenReader::ParserTokenReader(ParserBase* a_pParent) + :m_pParser(a_pParent) + , m_strFormula() + , m_iPos(0) + , m_iSynFlags(0) + , m_bIgnoreUndefVar(false) + , m_pFunDef(nullptr) + , m_pPostOprtDef(nullptr) + , m_pInfixOprtDef(nullptr) + , m_pOprtDef(nullptr) + , m_pConstDef(nullptr) + , m_pStrVarDef(nullptr) + , m_pVarDef(nullptr) + , m_pFactory(nullptr) + , m_pFactoryData(nullptr) + , m_vIdentFun() + , m_UsedVar() + , m_fZero(0) + , m_bracketStack() + , m_lastTok() + , m_cArgSep(',') + { + MUP_ASSERT(m_pParser != nullptr); + SetParent(m_pParser); + } + + + /** \brief Create instance of a ParserTokenReader identical with this + and return its pointer. + + This is a factory method the calling function must take care of the object destruction. + + \return A new ParserTokenReader object. + \throw nothrow + */ + ParserTokenReader* ParserTokenReader::Clone(ParserBase* a_pParent) const + { + std::unique_ptr<ParserTokenReader> ptr(new ParserTokenReader(*this)); + ptr->SetParent(a_pParent); + return ptr.release(); + } + + + ParserTokenReader::token_type& ParserTokenReader::SaveBeforeReturn(const token_type& tok) + { + m_lastTok = tok; + return m_lastTok; + } + + + void ParserTokenReader::AddValIdent(identfun_type a_pCallback) + { + // Use push_front is used to give user defined callbacks a higher priority than + // the built in ones. Otherwise reading hex numbers would not work + // since the "0" in "0xff" would always be read first making parsing of + // the rest impossible. + // reference: + // http://sourceforge.net/projects/muparser/forums/forum/462843/topic/4824956 + m_vIdentFun.push_front(a_pCallback); + } + + + void ParserTokenReader::SetVarCreator(facfun_type a_pFactory, void* pUserData) + { + m_pFactory = a_pFactory; + m_pFactoryData = pUserData; + } + + + /** \brief Return the current position of the token reader in the formula string. + + \return #m_iPos + \throw nothrow + */ + int ParserTokenReader::GetPos() const + { + return m_iPos; + } + + + /** \brief Return a reference to the formula. + + \return #m_strFormula + \throw nothrow + */ + const string_type& ParserTokenReader::GetExpr() const + { + return m_strFormula; + } + + + /** \brief Return a map containing the used variables only. */ + varmap_type& ParserTokenReader::GetUsedVar() + { + return m_UsedVar; + } + + + /** \brief Initialize the token Reader. + + Sets the formula position index to zero and set Syntax flags to default for initial formula parsing. + \pre [assert] triggered if a_szFormula==0 + */ + void ParserTokenReader::SetFormula(const string_type& a_strFormula) + { + m_strFormula = a_strFormula; + ReInit(); + } + + + /** \brief Set Flag that controls behaviour in case of undefined variables being found. + + If true, the parser does not throw an exception if an undefined variable is found. + otherwise it does. This variable is used internally only! + It suppresses a "undefined variable" exception in GetUsedVar(). + Those function should return a complete list of variables including + those the are not defined by the time of it's call. + */ + void ParserTokenReader::IgnoreUndefVar(bool bIgnore) + { + m_bIgnoreUndefVar = bIgnore; + } + + + /** \brief Reset the token reader to the start of the formula. + + The syntax flags will be reset to a value appropriate for the + start of a formula. + \post #m_iPos==0, #m_iSynFlags = noOPT | noBC | noPOSTOP | noSTR + \throw nothrow + \sa ESynCodes + */ + void ParserTokenReader::ReInit() + { + m_iPos = 0; + m_iSynFlags = sfSTART_OF_LINE; + m_bracketStack = std::stack<int>(); + m_UsedVar.clear(); + m_lastTok = token_type(); + } + + + /** \brief Read the next token from the string. */ + ParserTokenReader::token_type ParserTokenReader::ReadNextToken() + { + MUP_ASSERT(m_pParser != nullptr); + + const char_type* szFormula = m_strFormula.c_str(); + token_type tok; + + // Ignore all non printable characters when reading the expression + while (szFormula[m_iPos] > 0 && szFormula[m_iPos] <= 0x20) + ++m_iPos; + + // Check for end of formula + if (IsEOF(tok)) + return SaveBeforeReturn(tok); + + // Check for user defined binary operator + if (IsOprt(tok)) + return SaveBeforeReturn(tok); + + // Check for function token + if (IsFunTok(tok)) + return SaveBeforeReturn(tok); + + // Check built in operators / tokens + if (IsBuiltIn(tok)) + return SaveBeforeReturn(tok); + + // Check for function argument separators + if (IsArgSep(tok)) + return SaveBeforeReturn(tok); + + // Check for values / constant tokens + if (IsValTok(tok)) + return SaveBeforeReturn(tok); + + // Check for variable tokens + if (IsVarTok(tok)) + return SaveBeforeReturn(tok); + + // Check for string variables + if (IsStrVarTok(tok)) + return SaveBeforeReturn(tok); + + // Check for String tokens + if (IsString(tok)) + return SaveBeforeReturn(tok); + + // Check for unary operators + if (IsInfixOpTok(tok)) + return SaveBeforeReturn(tok); + + // Check for unary operators + if (IsPostOpTok(tok)) + return SaveBeforeReturn(tok); + + // Check String for undefined variable token. Done only if a + // flag is set indicating to ignore undefined variables. + // This is a way to conditionally avoid an error if + // undefined variables occur. + // (The GetUsedVar function must suppress the error for + // undefined variables in order to collect all variable + // names including the undefined ones.) + if ((m_bIgnoreUndefVar || m_pFactory) && IsUndefVarTok(tok)) + return SaveBeforeReturn(tok); + + // Check for unknown token + // + // !!! From this point on there is no exit without an exception possible... + // + string_type strTok; + auto iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, (std::size_t)m_iPos); + if (iEnd != m_iPos) + Error(ecUNASSIGNABLE_TOKEN, m_iPos, strTok); + + Error(ecUNASSIGNABLE_TOKEN, m_iPos, m_strFormula.substr(m_iPos)); + return token_type(); // never reached + } + + + void ParserTokenReader::SetParent(ParserBase* a_pParent) + { + m_pParser = a_pParent; + m_pFunDef = &a_pParent->m_FunDef; + m_pOprtDef = &a_pParent->m_OprtDef; + m_pInfixOprtDef = &a_pParent->m_InfixOprtDef; + m_pPostOprtDef = &a_pParent->m_PostOprtDef; + m_pVarDef = &a_pParent->m_VarDef; + m_pStrVarDef = &a_pParent->m_StrVarDef; + m_pConstDef = &a_pParent->m_ConstDef; + } + + + /** \brief Extract all characters that belong to a certain charset. + + \param a_szCharSet [in] Const char array of the characters allowed in the token. + \param a_strTok [out] The string that consists entirely of characters listed in a_szCharSet. + \param a_iPos [in] Position in the string from where to start reading. + \return The Position of the first character not listed in a_szCharSet. + \throw nothrow + */ + int ParserTokenReader::ExtractToken(const char_type* a_szCharSet, string_type& a_sTok, std::size_t a_iPos) const + { + auto iEnd = m_strFormula.find_first_not_of(a_szCharSet, a_iPos); + + if (iEnd == string_type::npos) + iEnd = m_strFormula.length(); + + // Assign token string if there was something found + if (a_iPos != iEnd) + a_sTok = string_type(m_strFormula.begin() + a_iPos, m_strFormula.begin() + iEnd); + + return iEnd; + } + + + /** \brief Check Expression for the presence of a binary operator token. + + Userdefined binary operator "++" gives inconsistent parsing result for + the equations "a++b" and "a ++ b" if alphabetic characters are allowed + in operator tokens. To avoid this this function checks specifically + for operator tokens. + */ + int ParserTokenReader::ExtractOperatorToken(string_type& a_sTok, std::size_t a_iPos) const + { + // Changed as per Issue 6: https://code.google.com/p/muparser/issues/detail?id=6 + auto iEnd = m_strFormula.find_first_not_of(m_pParser->ValidOprtChars(), a_iPos); + if (iEnd == string_type::npos) + iEnd = m_strFormula.length(); + + // Assign token string if there was something found + if (a_iPos != iEnd) + { + a_sTok = string_type(m_strFormula.begin() + a_iPos, m_strFormula.begin() + iEnd); + return iEnd; + } + else + { + // There is still the chance of having to deal with an operator consisting exclusively + // of alphabetic characters. + return ExtractToken("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", a_sTok, (std::size_t)a_iPos); + } + } + + + /** \brief Check if a built in operator or other token can be found + \param a_Tok [out] Operator token if one is found. This can either be a binary operator or an infix operator token. + \return true if an operator token has been found. + */ + bool ParserTokenReader::IsBuiltIn(token_type& a_Tok) + { + const char_type** const pOprtDef = m_pParser->GetOprtDef(), + * const szFormula = m_strFormula.c_str(); + + // Compare token with function and operator strings + // check string for operator/function + for (int i = 0; pOprtDef[i]; i++) + { + std::size_t len(std::char_traits<char_type>::length(pOprtDef[i])); + if (string_type(pOprtDef[i]) == string_type(szFormula + m_iPos, szFormula + m_iPos + len)) + { + switch (i) + { + case cmLAND: + case cmLOR: + case cmLT: + case cmGT: + case cmLE: + case cmGE: + case cmNEQ: + case cmEQ: + case cmADD: + case cmSUB: + case cmMUL: + case cmDIV: + case cmPOW: + case cmASSIGN: + //if (len!=sTok.length()) + // continue; + + // The assignment operator need special treatment + if (i == cmASSIGN && m_iSynFlags & noASSIGN) + Error(ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef[i]); + + if (!m_pParser->HasBuiltInOprt()) continue; + if (m_iSynFlags & noOPT) + { + // Maybe its an infix operator not an operator + // Both operator types can share characters in + // their identifiers + if (IsInfixOpTok(a_Tok)) + return true; + + Error(ecUNEXPECTED_OPERATOR, m_iPos, pOprtDef[i]); + } + + m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE | noEND; + break; + + case cmBO: + if (m_iSynFlags & noBO) + Error(ecUNEXPECTED_PARENS, m_iPos, pOprtDef[i]); + + if (m_lastTok.GetCode() == cmFUNC) + m_iSynFlags = noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE; + else + m_iSynFlags = noBC | noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN | noIF | noELSE; + + m_bracketStack.push(cmBO); + break; + + case cmBC: + if (m_iSynFlags & noBC) + Error(ecUNEXPECTED_PARENS, m_iPos, pOprtDef[i]); + + m_iSynFlags = noBO | noVAR | noVAL | noFUN | noINFIXOP | noSTR | noASSIGN; + + if (!m_bracketStack.empty()) + m_bracketStack.pop(); + else + Error(ecUNEXPECTED_PARENS, m_iPos, pOprtDef[i]); + break; + + case cmELSE: + if (m_iSynFlags & noELSE) + Error(ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef[i]); + + m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE | noSTR; + break; + + case cmIF: + if (m_iSynFlags & noIF) + Error(ecUNEXPECTED_CONDITIONAL, m_iPos, pOprtDef[i]); + + m_iSynFlags = noBC | noPOSTOP | noEND | noOPT | noIF | noELSE | noSTR; + break; + + default: // The operator is listed in c_DefaultOprt, but not here. This is a bad thing... + Error(ecINTERNAL_ERROR); + } // switch operator id + + m_iPos += (int)len; + a_Tok.Set((ECmdCode)i, pOprtDef[i]); + return true; + } // if operator string found + } // end of for all operator strings + + return false; + } + + + bool ParserTokenReader::IsArgSep(token_type& a_Tok) + { + const char_type* szFormula = m_strFormula.c_str(); + + if (szFormula[m_iPos] == m_cArgSep) + { + // copy the separator into null terminated string + char_type szSep[2]; + szSep[0] = m_cArgSep; + szSep[1] = 0; + + if (m_iSynFlags & noARG_SEP) + Error(ecUNEXPECTED_ARG_SEP, m_iPos, szSep); + + m_iSynFlags = noBC | noOPT | noEND | noARG_SEP | noPOSTOP | noASSIGN; + m_iPos++; + a_Tok.Set(cmARG_SEP, szSep); + return true; + } + + return false; + } + + + /** \brief Check for End of Formula. + + \return true if an end of formula is found false otherwise. + \param a_Tok [out] If an eof is found the corresponding token will be stored there. + \throw nothrow + \sa IsOprt, IsFunTok, IsStrFunTok, IsValTok, IsVarTok, IsString, IsInfixOpTok, IsPostOpTok + */ + bool ParserTokenReader::IsEOF(token_type& a_Tok) + { + const char_type* szFormula = m_strFormula.c_str(); + + // check for EOF + if (!szFormula[m_iPos] /*|| szFormula[m_iPos] == '\n'*/) + { + if (m_iSynFlags & noEND) + Error(ecUNEXPECTED_EOF, m_iPos); + + if (!m_bracketStack.empty()) + Error(ecMISSING_PARENS, m_iPos, _T(")")); + + m_iSynFlags = 0; + a_Tok.Set(cmEND); + return true; + } + + return false; + } + + + /** \brief Check if a string position contains a unary infix operator. + \return true if a function token has been found false otherwise. + */ + bool ParserTokenReader::IsInfixOpTok(token_type& a_Tok) + { + string_type sTok; + auto iEnd = ExtractToken(m_pParser->ValidInfixOprtChars(), sTok, (std::size_t)m_iPos); + if (iEnd == m_iPos) + return false; + + // iterate over all postfix operator strings + funmap_type::const_reverse_iterator it = m_pInfixOprtDef->rbegin(); + for (; it != m_pInfixOprtDef->rend(); ++it) + { + if (sTok.find(it->first) != 0) + continue; + + a_Tok.Set(it->second, it->first); + m_iPos += (int)it->first.length(); + + if (m_iSynFlags & noINFIXOP) + Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString()); + + m_iSynFlags = noPOSTOP | noINFIXOP | noOPT | noBC | noSTR | noASSIGN | noARG_SEP; + return true; + } + + return false; + + /* + a_Tok.Set(item->second, sTok); + m_iPos = (int)iEnd; + + if (m_iSynFlags & noINFIXOP) + Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString()); + + m_iSynFlags = noPOSTOP | noINFIXOP | noOPT | noBC | noSTR | noASSIGN; + return true; + */ + } + + + /** \brief Check whether the token at a given position is a function token. + \param a_Tok [out] If a value token is found it will be placed here. + \throw ParserException if Syntaxflags do not allow a function at a_iPos + \return true if a function token has been found false otherwise. + \pre [assert] m_pParser!=0 + */ + bool ParserTokenReader::IsFunTok(token_type& a_Tok) + { + string_type strTok; + auto iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, (std::size_t)m_iPos); + if (iEnd == m_iPos) + return false; + + funmap_type::const_iterator item = m_pFunDef->find(strTok); + if (item == m_pFunDef->end()) + return false; + + // Check if the next sign is an opening bracket + const char_type* szFormula = m_strFormula.c_str(); + if (szFormula[iEnd] != '(') + return false; + + a_Tok.Set(item->second, strTok); + + m_iPos = (int)iEnd; + if (m_iSynFlags & noFUN) + Error(ecUNEXPECTED_FUN, m_iPos - (int)a_Tok.GetAsString().length(), a_Tok.GetAsString()); + + m_iSynFlags = noANY ^ noBO; + return true; + } + + + /** \brief Check if a string position contains a binary operator. + \param a_Tok [out] Operator token if one is found. This can either be a binary operator or an infix operator token. + \return true if an operator token has been found. + */ + bool ParserTokenReader::IsOprt(token_type& a_Tok) + { + const char_type* const szExpr = m_strFormula.c_str(); + string_type strTok; + + auto iEnd = ExtractOperatorToken(strTok, (std::size_t)m_iPos); + if (iEnd == m_iPos) + return false; + + // Check if the operator is a built in operator, if so ignore it here + const char_type** const pOprtDef = m_pParser->GetOprtDef(); + for (int i = 0; m_pParser->HasBuiltInOprt() && pOprtDef[i]; ++i) + { + if (string_type(pOprtDef[i]) == strTok) + return false; + } + + // Note: + // All tokens in oprt_bin_maptype are have been sorted by their length + // Long operators must come first! Otherwise short names (like: "add") that + // are part of long token names (like: "add123") will be found instead + // of the long ones. + // Length sorting is done with ascending length so we use a reverse iterator here. + funmap_type::const_reverse_iterator it = m_pOprtDef->rbegin(); + for (; it != m_pOprtDef->rend(); ++it) + { + const string_type& sID = it->first; + if (sID == string_type(szExpr + m_iPos, szExpr + m_iPos + sID.length())) + { + a_Tok.Set(it->second, strTok); + + // operator was found + if (m_iSynFlags & noOPT) + { + // An operator was found but is not expected to occur at + // this position of the formula, maybe it is an infix + // operator, not a binary operator. Both operator types + // can share characters in their identifiers. + if (IsInfixOpTok(a_Tok)) + return true; + else + { + // nope, no infix operator + return false; + //Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString()); + } + + } + + m_iPos += (int)sID.length(); + m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noASSIGN; + return true; + } + } + + return false; + } + + + /** \brief Check if a string position contains a unary post value operator. */ + bool ParserTokenReader::IsPostOpTok(token_type& a_Tok) + { + // <ibg 20110629> Do not check for postfix operators if they are not allowed at + // the current expression index. + // + // This will fix the bug reported here: + // + // http://sourceforge.net/tracker/index.php?func=detail&aid=3343891&group_id=137191&atid=737979 + // + if (m_iSynFlags & noPOSTOP) + return false; + // </ibg> + + // Tricky problem with equations like "3m+5": + // m is a postfix operator, + is a valid sign for postfix operators and + // for binary operators parser detects "m+" as operator string and + // finds no matching postfix operator. + // + // This is a special case so this routine slightly differs from the other + // token readers. + + // Test if there could be a postfix operator + string_type sTok; + auto iEnd = ExtractToken(m_pParser->ValidOprtChars(), sTok, (std::size_t)m_iPos); + if (iEnd == m_iPos) + return false; + + // iterate over all postfix operator strings + funmap_type::const_reverse_iterator it = m_pPostOprtDef->rbegin(); + for (; it != m_pPostOprtDef->rend(); ++it) + { + if (sTok.find(it->first) != 0) + continue; + + a_Tok.Set(it->second, sTok); + m_iPos += (int)it->first.length(); + + m_iSynFlags = noVAL | noVAR | noFUN | noBO | noPOSTOP | noSTR | noASSIGN; + return true; + } + + return false; + } + + + /** \brief Check whether the token at a given position is a value token. + + Value tokens are either values or constants. + + \param a_Tok [out] If a value token is found it will be placed here. + \return true if a value token has been found. + */ + bool ParserTokenReader::IsValTok(token_type& a_Tok) + { + MUP_ASSERT(m_pConstDef != nullptr); + MUP_ASSERT(m_pParser != nullptr); + + string_type strTok; + value_type fVal(0); + + // 2.) Check for user defined constant + // Read everything that could be a constant name + auto iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, (std::size_t)m_iPos); + if (iEnd != m_iPos) + { + valmap_type::const_iterator item = m_pConstDef->find(strTok); + if (item != m_pConstDef->end()) + { + m_iPos = iEnd; + a_Tok.SetVal(item->second, strTok); + + if (m_iSynFlags & noVAL) + Error(ecUNEXPECTED_VAL, m_iPos - (int)strTok.length(), strTok); + + m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR | noASSIGN; + return true; + } + } + + // 3.call the value recognition functions provided by the user + // Call user defined value recognition functions + std::list<identfun_type>::const_iterator item = m_vIdentFun.begin(); + for (item = m_vIdentFun.begin(); item != m_vIdentFun.end(); ++item) + { + int iStart = m_iPos; + if ((*item)(m_strFormula.c_str() + m_iPos, &m_iPos, &fVal) == 1) + { + // 2013-11-27 Issue 2: https://code.google.com/p/muparser/issues/detail?id=2 + strTok.assign(m_strFormula.c_str(), iStart, (std::size_t)m_iPos - iStart); + + if (m_iSynFlags & noVAL) + Error(ecUNEXPECTED_VAL, m_iPos - (int)strTok.length(), strTok); + + a_Tok.SetVal(fVal, strTok); + m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR | noASSIGN; + return true; + } + } + + return false; + } + + + /** \brief Check wheter a token at a given position is a variable token. + \param a_Tok [out] If a variable token has been found it will be placed here. + \return true if a variable token has been found. + */ + bool ParserTokenReader::IsVarTok(token_type& a_Tok) + { + if (m_pVarDef->empty()) + return false; + + string_type strTok; + auto iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, (std::size_t)m_iPos); + if (iEnd == m_iPos) + return false; + + varmap_type::const_iterator item = m_pVarDef->find(strTok); + if (item == m_pVarDef->end()) + return false; + + if (m_iSynFlags & noVAR) + Error(ecUNEXPECTED_VAR, m_iPos, strTok); + + m_pParser->OnDetectVar(&m_strFormula, m_iPos, iEnd); + + m_iPos = iEnd; + a_Tok.SetVar(item->second, strTok); + m_UsedVar[item->first] = item->second; // Add variable to used-var-list + + m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR; + + // Zur Info hier die SynFlags von IsVal(): + // m_iSynFlags = noVAL | noVAR | noFUN | noBO | noINFIXOP | noSTR | noASSIGN; + return true; + } + + + bool ParserTokenReader::IsStrVarTok(token_type& a_Tok) + { + if (!m_pStrVarDef || m_pStrVarDef->empty()) + return false; + + string_type strTok; + auto iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, (std::size_t)m_iPos); + if (iEnd == m_iPos) + return false; + + strmap_type::const_iterator item = m_pStrVarDef->find(strTok); + if (item == m_pStrVarDef->end()) + return false; + + if (m_iSynFlags & noSTR) + Error(ecUNEXPECTED_VAR, m_iPos, strTok); + + m_iPos = iEnd; + if (!m_pParser->m_vStringVarBuf.size()) + Error(ecINTERNAL_ERROR); + + a_Tok.SetString(m_pParser->m_vStringVarBuf[item->second], m_pParser->m_vStringVarBuf.size()); + + m_iSynFlags = noANY ^ (noBC | noOPT | noEND | noARG_SEP); + return true; + } + + + + /** \brief Check wheter a token at a given position is an undefined variable. + + \param a_Tok [out] If a variable tom_pParser->m_vStringBufken has been found it will be placed here. + \return true if a variable token has been found. + \throw nothrow + */ + bool ParserTokenReader::IsUndefVarTok(token_type& a_Tok) + { + string_type strTok; + auto iEnd(ExtractToken(m_pParser->ValidNameChars(), strTok, (std::size_t)m_iPos)); + if (iEnd == m_iPos) + return false; + + if (m_iSynFlags & noVAR) + { + // <ibg/> 20061021 added token string strTok instead of a_Tok.GetAsString() as the + // token identifier. + // related bug report: + // http://sourceforge.net/tracker/index.php?func=detail&aid=1578779&group_id=137191&atid=737979 + Error(ecUNEXPECTED_VAR, m_iPos - (int)a_Tok.GetAsString().length(), strTok); + } + + // If a factory is available implicitely create new variables + if (m_pFactory) + { + value_type* fVar = m_pFactory(strTok.c_str(), m_pFactoryData); + a_Tok.SetVar(fVar, strTok); + + // Do not use m_pParser->DefineVar( strTok, fVar ); + // in order to define the new variable, it will clear the + // m_UsedVar array which will kill previously defined variables + // from the list + // This is safe because the new variable can never override an existing one + // because they are checked first! + (*m_pVarDef)[strTok] = fVar; + m_UsedVar[strTok] = fVar; // Add variable to used-var-list + } + else + { + a_Tok.SetVar((value_type*)&m_fZero, strTok); + m_UsedVar[strTok] = 0; // Add variable to used-var-list + } + + m_iPos = iEnd; + + // Call the variable factory in order to let it define a new parser variable + m_iSynFlags = noVAL | noVAR | noFUN | noBO | noPOSTOP | noINFIXOP | noSTR; + return true; + } + + + + /** \brief Check wheter a token at a given position is a string. + \param a_Tok [out] If a variable token has been found it will be placed here. + \return true if a string token has been found. + \sa IsOprt, IsFunTok, IsStrFunTok, IsValTok, IsVarTok, IsEOF, IsInfixOpTok, IsPostOpTok + \throw nothrow + */ + bool ParserTokenReader::IsString(token_type& a_Tok) + { + if (m_strFormula[m_iPos] != '"') + return false; + + string_type strBuf(&m_strFormula[(std::size_t)m_iPos + 1]); + std::size_t iEnd(0), iSkip(0); + + // parser over escaped '\"' end replace them with '"' + for (iEnd = (int)strBuf.find(_T('\"')); iEnd != 0 && iEnd != string_type::npos; iEnd = (int)strBuf.find(_T('\"'), iEnd)) + { + if (strBuf[iEnd - 1] != '\\') break; + strBuf.replace(iEnd - 1, 2, _T("\"")); + iSkip++; + } + + if (iEnd == string_type::npos) + Error(ecUNTERMINATED_STRING, m_iPos, _T("\"")); + + string_type strTok(strBuf.begin(), strBuf.begin() + iEnd); + + if (m_iSynFlags & noSTR) + Error(ecUNEXPECTED_STR, m_iPos, strTok); + + m_pParser->m_vStringBuf.push_back(strTok); // Store string in internal buffer + a_Tok.SetString(strTok, m_pParser->m_vStringBuf.size()); + + m_iPos += (int)strTok.length() + 2 + (int)iSkip; // +2 for quotes; +iSkip for escape characters + m_iSynFlags = noANY ^ (noARG_SEP | noBC | noOPT | noEND); + + return true; + } + + + /** \brief Create an error containing the parse error position. + + This function will create an Parser Exception object containing the error text and its position. + + \param a_iErrc [in] The error code of type #EErrorCodes. + \param a_iPos [in] The position where the error was detected. + \param a_strTok [in] The token string representation associated with the error. + \throw ParserException always throws thats the only purpose of this function. + */ + void ParserTokenReader::Error(EErrorCodes a_iErrc, int a_iPos, const string_type& a_sTok) const + { + m_pParser->Error(a_iErrc, a_iPos, a_sTok); + } + + + void ParserTokenReader::SetArgSep(char_type cArgSep) + { + m_cArgSep = cArgSep; + } + + + char_type ParserTokenReader::GetArgSep() const + { + return m_cArgSep; + } +} // namespace mu + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif diff --git a/3rdParty/MuParser/test/t_ParserTest.cpp b/3rdParty/MuParser/test/t_ParserTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d0463afa7d92e1f3d1b3cc9d6f8f05cfad70293 --- /dev/null +++ b/3rdParty/MuParser/test/t_ParserTest.cpp @@ -0,0 +1,9 @@ +#include "muParserTest.h" + +using namespace mu::Test; + +int main(int, char**) +{ + ParserTester tester; + return tester.Run(); +} diff --git a/3rdParty/googletest/version.txt b/3rdParty/googletest/version.txt new file mode 100644 index 0000000000000000000000000000000000000000..b9fa3d3def665fa11b4146282404e6b4f110ab21 --- /dev/null +++ b/3rdParty/googletest/version.txt @@ -0,0 +1,3 @@ +release v1.10.0, 03.10.2019 + +https://github.com/google/googletest/releases/tag/release-1.10.0 diff --git a/CMake/3rd/cuda.cmake b/CMake/3rd/cuda.cmake index f39e4c417134511e4dd8f37cc3a081479d037147..570f4b0c6ff970d3fe603181ac332d6214b1b87e 100644 --- a/CMake/3rd/cuda.cmake +++ b/CMake/3rd/cuda.cmake @@ -10,7 +10,7 @@ function(linkCUDA) ) vf_get_library_name(library_name) - target_include_directories(${library_name} PRIVATE ${CUDA_INCLUDE_DIRS} ${CUDA_CUT_INCLUDE_DIR}) + target_include_directories(${library_name} PRIVATE ${CUDA_CUT_INCLUDE_DIR}) # set the following properties only for specific targets # set_property(TARGET ${targetName} PROPERTY CUDA_SEPARABLE_COMPILATION ON) diff --git a/CMake/3rd/vtk.cmake b/CMake/3rd/vtk.cmake new file mode 100644 index 0000000000000000000000000000000000000000..83cf22e8849298d2b42909664cacd5fd9044903e --- /dev/null +++ b/CMake/3rd/vtk.cmake @@ -0,0 +1,11 @@ + +######################################################################### +# VTK_DIR needs to bet set to the VTK build directory in the config file. +######################################################################### +find_package(VTK REQUIRED) + vf_get_library_name(library_name) + + include(${VTK_USE_FILE}) + target_include_directories(${library_name} PRIVATE ${VTK_INCLUDE_DIRS}) + + target_link_libraries(${library_name} PRIVATE ${VTK_LIBRARIES}) diff --git a/CMake/CMakeCABMacros.cmake b/CMake/CMakeCABMacros.cmake deleted file mode 100644 index 32e8c1e0fba34debf5dddbce3e19788aa9c24d44..0000000000000000000000000000000000000000 --- a/CMake/CMakeCABMacros.cmake +++ /dev/null @@ -1,320 +0,0 @@ -############################################################### -# Aktivieren von IF(ARG)...ELSE()...ENDIF() in CMake -############################################################### -SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS 1) - -############################################################################################################### -## Flags ruecksetzen -############################################################################################################### -SET(CAB_ADDTIONAL_COMPILER_FLAGS) -#because of the fact that CMake does not support COMPILER_FLAGS_<CONFIG> right know we cannot use these options -#SET(CAB_ADDTIONAL_COMPILER_FLAGS_DEBUG) -#SET(CAB_ADDTIONAL_COMPILER_FLAGS_RELEASE) - -SET(CAB_ADDITIONAL_LINK_FLAGS) -SET(CAB_ADDITIONAL_LINK_FLAGS_DEBUG) -SET(CAB_ADDITIONAL_LINK_FLAGS_RELEASE) - -SET(CAB_ADDITIONAL_LINK_LIBRARIES) - - -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -DSOURCE_ROOT=${VF_ROOT_DIR} ) - -############################################################### -# hostename ermitteln -> CAB_MACHINE -############################################################### -IF(NOT CAB_MACHINE) - SET(CAB_MACHINE $ENV{CAB_MACHINE}) - - IF( CAB_MACHINE ) - STRING(TOUPPER "${CAB_MACHINE}" CAB_MACHINE) - ELSE() - EXECUTE_PROCESS( COMMAND hostname OUTPUT_VARIABLE CAB_MACHINE) - STRING(REGEX REPLACE "[ ]*([A-Za-z0-9]+).*[\\\\n]*" "\\1" CAB_MACHINE "${CAB_MACHINE}" ) - STRING(TOUPPER "${CAB_MACHINE}" CAB_MACHINE) - ENDIF() -ENDIF() - - -############################################################### -# WITH_SUBFOLDERS_FOR_SG erstellen, wenn noch nicht vorhanden -# ist diese auf true wird bei SOURCE_GROUP in VS unterordner erzeugt -# dies funzt erst ab CMake-2.5 vernuenftig -############################################################### -IF(NOT WITH_SUBFOLDERS_FOR_SG) - SET(WITH_SUBFOLDERS_FOR_SG FALSE) -ENDIF() - - -############################################################################ -############################################################################ -## M A C R O S ## -## M A C R O S ## -## M A C R O S ## -############################################################################ -############################################################################ -# externe (ACHTUNG: die darin enthaltenen benoetigen teils noch macros die -# hier im Anschluss folgen -INCLUDE("${VF_CMAKE_DIR}/CMakeSetCompilerFlags.cmake") -INCLUDE("${VF_CMAKE_DIR}/CMakeCompilerMacros.cmake") - -################################################################ -### ADD_TARGET_PROPERTIES ### -################################################################ -MACRO(ADD_TARGET_PROPERTIES target property) - - SET(property_values ${ARGN}) - - # vorhandene properties holen - GET_TARGET_PROPERTY(TEMP_VAR ${target} ${property}) - IF(TEMP_VAR) - LIST(APPEND property_values ${TEMP_VAR}) - ENDIF() - - #STRING(REGEX REPLACE ";" " " property_values ${property_values}) - # doppelte Eintraege loeschen - SEPARATE_ARGUMENTS(property_values) - LIST(REMOVE_DUPLICATES property_values) - - #aus Liste wieder einen String basteln (geht nich tmit regex replace...) - SET(new_property_values) - FOREACH(p ${property_values}) - SET(new_property_values "${p} ${new_property_values}") - ENDFOREACH() - - #property setzen - SET_TARGET_PROPERTIES(${target} PROPERTIES ${property} ${new_property_values}) - - #GET_TARGET_PROPERTY(TEMP_VAR ${target} ${property}) - #MESSAGE("danach ${target} ${property} ${TEMP_VAR}") - -ENDMACRO(ADD_TARGET_PROPERTIES target property) - - -################################################################ -### CHECK_FOR_VARIABLE ### -### checks for a variable (also env-variables) -### if not found -> error-message!!! -### always: cache-entry update -################################################################ -MACRO(CHECK_FOR_VARIABLE var) - #check ob evtl enviromentvariable gesetzt - IF(NOT DEFINED ${var}) #true if ${var} NOT: empty, 0, N, NO, OFF, FALSE, NOTFOUND, or <variable>-NOTFOUND - SET(${var} $ENV{${var}}) - ENDIF() - - IF(NOT DEFINED ${var}) - SET(${var} "${var}-NOTFOUND" CACHE STRING "${ARGN}" FORCE) - ENDIF(NOT DEFINED ${var}) - - IF(${var} MATCHES ".*-NOTFOUND") - MESSAGE(FATAL_ERROR "CHECK_FOR_VARIABLE - error - set ${var}") - ENDIF() - - SET(${var} ${${var}} CACHE STRING "${ARGN}" FORCE) -ENDMACRO(CHECK_FOR_VARIABLE var) - - -############################################################### -### CAB_SOURCE_GROUP( sourceGroupName ) ### -### creates a source group for the given folder and files. ### -############################################################### -MACRO(CAB_SOURCE_GROUP sourceGroupName) - SET(tempSourceGroupName ${sourceGroupName}) - IF(WITH_SUBFOLDERS_FOR_SG) - STRING(REGEX REPLACE "/" "\\\\" tempSourceGroupName ${tempSourceGroupName}) - ENDIF() - SOURCE_GROUP(${tempSourceGroupName} FILES ${ARGN}) -ENDMACRO(CAB_SOURCE_GROUP) - -################################################################################# -### COLLECT_PACKAGE_DATA( currentDir sourceGroupName outFiles) ### -### collects header and cpp file of current dir and add them to "outfiles" ### -### all files will be put to the SOURCE_GROUP-folder "sourceGroupName" ### -### and this one will be with subfolders if WITH_SUBFOLDERS_FOR_SG==YES ### -################################################################################# -MACRO(COLLECT_PACKAGE_DATA currentDir sourceGroupName outFiles) - FILE( GLOB _HEADER_FILES ${currentDir}/*.h ) - FILE( GLOB _CPP_FILES ${currentDir}/*.cpp ) - FILE( GLOB _CXX_FILES ${currentDir}/*.cxx ) - FILE( GLOB _HPP_FILES ${currentDir}/*.hpp ) - FILE( GLOB _C_FILES ${currentDir}/*.c ) - - IF(CAB_PACKAGE_DEFINTIONS) - SET_SOURCE_FILES_PROPERTIES( ${CPP_FILES} PROPERTIES COMPILE_FLAGS ${CAB_PACKAGE_DEFINTIONS} ) - ENDIF(CAB_PACKAGE_DEFINTIONS) - - CAB_SOURCE_GROUP( ${sourceGroupName} ${_HEADER_FILES} ${_CPP_FILES} ${_CXX_FILES} ${_HPP_FILES} ${_C_FILES} ) - - #SET( ${outFiles} ${${outFiles}} ${_HEADER_FILES} ${_CPP_FILES} ${_CXX_FILES} ${_HPP_FILES} ${_C_FILES} ) - LIST(APPEND ${outFiles} ${_HEADER_FILES} ${_CPP_FILES} ${_CXX_FILES} ${_HPP_FILES} ${_C_FILES} ) -ENDMACRO(COLLECT_PACKAGE_DATA currentDir sourceGroupName sourceGroupWithSubfolders outFiles) - - -################################################################################################################## -### COLLECT_PACKAGE_DATA_WITH_OPTION( currentDir outFiles [outOption] [outSourceGroupName]) ### -### collects header and cpp file of current dir and add them to "outfiles" ### -### all files will be put to the SOURCE_GROUP-folder "sourceGroupName" ### -### and this one will be with subfolders if WITH_SUBFOLDERS_FOR_SG==YES ### -################################################################################################################## -MACRO(COLLECT_PACKAGE_DATA_WITH_OPTION currentDir outFiles) - STRING(REGEX REPLACE "(.*)/source/(.*)" "\\2" SOURCE_GROUP_NAME "${currentDir}") - STRING(REGEX REPLACE "/" "_" OPTION_LABEL "${SOURCE_GROUP_NAME}") - STRING(REGEX REPLACE ":" "" OPTION_LABEL "${OPTION_LABEL}") - STRING(TOUPPER ${OPTION_LABEL} OPTION_LABEL) - - SET(OPTION_LABEL "BUILD_${OPTION_LABEL}") - OPTION(${OPTION_LABEL} "${currentDir}" ON) - - IF( ${OPTION_LABEL} ) - COLLECT_PACKAGE_DATA( ${currentDir} ${SOURCE_GROUP_NAME} ${outFiles}) - ENDIF(${OPTION_LABEL}) - - IF(${ARGC} GREATER 2) - SET( ${ARGV2} ${OPTION_LABEL} ) - ENDIF() - - IF(${ARGC} GREATER 3) - SET( ${ARGV3} ${SOURCE_GROUP_NAME} ) - ENDIF() - -ENDMACRO(COLLECT_PACKAGE_DATA_WITH_OPTION currentDir outFiles) - - -################################################################# -### GET_DIRECTORY_FROM_ENV( var env_var [CACHE] [STRING]) ### -### if enn_var exists the value with corrected slashes will ### -### be stored in var. ### -### if optional CACHE is activated the var will be stored as ### -### cache variable. optional you can use a status bar string ### -################################################################# -MACRO(GET_DIRECTORY_FROM_ENV var env_var) - SET(${var} $ENV{${env_var}}) - IF(${var}) - STRING(REGEX REPLACE "\\\\" "/" ${var} ${${var}}) # "\" --> "/" - IF(${ARGC} EQUAL 3 AND ${ARGV2} MATCHES "CACHE") - SET(${var} ${${var}} CACHE PATH "" FORCE) - ENDIF(${ARGC} EQUAL 3 AND ${ARGV2} MATCHES "CACHE") - IF(${ARGC} EQUAL 4 AND ${ARGV2} MATCHES "CACHE") - SET(${var} ${${var}} CACHE PATH "${ARGV3}" FORCE) - ENDIF(${ARGC} EQUAL 4 AND ${ARGV2} MATCHES "CACHE") - ENDIF(${var}) -ENDMACRO(GET_DIRECTORY_FROM_ENV var env_var) - -################################################################# -### GET_DIRECTORY_FROM_VAR( var [CACHE] [STRING]) ### -### if optional CACHE is activated the var will be stored as ### -### cache variable. optional you can use a status bar string ### -################################################################# -MACRO(GET_DIRECTORY_FROM_VAR var ) - IF(${var}) - STRING(REGEX REPLACE "\\\\" "/" ${var} ${${var}}) # "\" --> "/" - IF(${ARGC} EQUAL 2 AND ${ARGV1} MATCHES "CACHE") - SET(${var} ${${var}} CACHE PATH "" FORCE) - ENDIF(${ARGC} EQUAL 2 AND ${ARGV1} MATCHES "CACHE") - IF(${ARGC} EQUAL 3 AND ${ARGV1} MATCHES "CACHE") - SET(${var} ${${var}} CACHE PATH "${ARGV2}" FORCE) - ENDIF(${ARGC} EQUAL 3 AND ${ARGV1} MATCHES "CACHE") - ENDIF(${var}) -ENDMACRO(GET_DIRECTORY_FROM_VAR var env_var) - - -################################################################# -### FINAL MACROS TO GENERATE PROJECT FILES ### -### project_name: name of the project ### -### build_type: BINARY | SHARED | STATIC ### -### optinal: prefix -################################################################# -MACRO(CREATE_CAB_PROJECT project_name build_type) - - MESSAGE(STATUS "configuring ${project_name} (type=${build_type})...") - - - ################################################################# - ### OS DEFINES ### - ################################################################# - IF(WIN32) - LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__WIN__) - ELSEIF(APPLE) - LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - ELSEIF(UNIX) - LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) - ENDIF() - - ################################################################# - ### ADDITIONAL_MAKE_CLEAN_FILES ### - ################################################################# - SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${GENERATED_FILES}") - - ################################################################# - ### EXCECUTABLE ### - ################################################################# - IF(${build_type} MATCHES BINARY) - ADD_EXECUTABLE(${project_name} ${ALL_SOURCES} ) - ELSEIF(${build_type} MATCHES SHARED) - ADD_LIBRARY(${project_name} SHARED ${ALL_SOURCES} ) - ELSEIF(${build_type} MATCHES STATIC) - ADD_LIBRARY(${project_name} STATIC ${ALL_SOURCES} ) - ELSE() - MESSAGE(FATAL_ERROR "build_type=${build_type} doesn't match BINARY, SHARED or STATIC") - ENDIF() - - ################################################################# - ### ADDITIONAL LINK LIBRARIES ### - ################################################################# - IF(CAB_ADDITIONAL_LINK_LIBRARIES) - TARGET_LINK_LIBRARIES(${project_name} ${CAB_ADDITIONAL_LINK_LIBRARIES}) - ENDIF() - - ################################################################# - ### COMPILER Flags ### - ################################################################# - ADD_COMPILER_FLAGS_TO_PROJECT(${CAB_COMPILER} ${project_name} "CXX" ${build_type}) - MESSAGE(STATUS "compiler flags for compiler ${CAB_COMPILER} on machine ${CAB_MACHINE} for project ${project_name} (${build_type}) have been configured") - - IF(CAB_ADDTIONAL_COMPILER_FLAGS) - ADD_TARGET_PROPERTIES(${project_name} COMPILE_FLAGS ${CAB_ADDTIONAL_COMPILER_FLAGS}) - ENDIF() - IF(CAB_ADDTIONAL_COMPILER_FLAGS_DEBUG) - MESSAGE(FATAL_ERROR "COMPILE_FLAGS_DEBUG_<CONFIG> not supported by cmake yet :-(") - ADD_TARGET_PROPERTIES(${project_name} COMPILE_FLAGS_DEBUG ${CAB_ADDTIONAL_COMPILER_FLAGS_DEBUG}) - ENDIF() - IF(CAB_ADDTIONAL_COMPILER_FLAGS_RELEASE) - MESSAGE(FATAL_ERROR "COMPILE_FLAGS_<CONFIG> not supported by cmake yet :-(") - ADD_TARGET_PROPERTIES(${project_name} COMPILE_FLAGS_RELEASE ${CAB_ADDTIONAL_COMPILER_FLAGS_RELEASE}) - ENDIF() - - ################################################################# - ### ADDITIONAL LINK PROPERTIES ### - ################################################################# - IF(CAB_ADDITIONAL_LINK_FLAGS) - ADD_TARGET_PROPERTIES(${project_name} LINK_FLAGS ${CAB_ADDITIONAL_LINK_FLAGS}) - ENDIF() - IF(CAB_ADDITIONAL_LINK_FLAGS_DEBUG) - ADD_TARGET_PROPERTIES(${project_name} LINK_FLAGS_DEBUG ${CAB_ADDITIONAL_LINK_FLAGS_DEBUG}) - ENDIF() - IF(CAB_ADDITIONAL_LINK_FLAGS_RELEASE) - ADD_TARGET_PROPERTIES(${project_name} LINK_FLAGS_RELEASE ${CAB_ADDITIONAL_LINK_FLAGS_RELEASE}) - ENDIF() - - SET(project_name ${project_name} CACHE STRING "name of binary") - - MESSAGE(STATUS "configuring ${project_name} (type=${build_type})... done") - -ENDMACRO(CREATE_CAB_PROJECT project_name build_type) - -################################################################# -# ALLGEMEINGUELTIGER STUFF -# CAB_COMPILER setzen und machinespecific configfile laden -############################################################### -SET_CAB_COMPILER() -CHECK_FOR_VARIABLE(CAB_MACHINE "machine name, e.g. ALTIX, ARWEN") -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -DCAB_MACHINE_${CAB_MACHINE}) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -DCAB_MACHINE=${CAB_MACHINE}) -SET(CMAKE_CONFIG_FILE "${VF_CMAKE_DIR}/cmake_config_files/${CAB_MACHINE}.config.cmake") - -IF(NOT EXISTS ${CMAKE_CONFIG_FILE}) - MESSAGE(FATAL_ERROR "${CMAKE_CONFIG_FILE} does not exists... maybe false CAB_MACHINE = ${CAB_MACHINE}") -ELSE() - INCLUDE(${CMAKE_CONFIG_FILE}) -ENDIF() diff --git a/CMake/CMakeCompilerMacros.cmake b/CMake/CMakeCompilerMacros.cmake deleted file mode 100644 index a9aa0558898abf1e56900426f524ebf660ad4f0f..0000000000000000000000000000000000000000 --- a/CMake/CMakeCompilerMacros.cmake +++ /dev/null @@ -1,384 +0,0 @@ -############################################################### -# Aktivieren von ELSIF in CMake -############################################################### -SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS 1) - -############################################################### -# IS_64BIT_SYSTEM (check put if OS is 64 bit compatible) -############################################################### -MACRO(IS_64BIT_SYSTEM is64BitOutVar) - - SET(${is64BitOutVar} FALSE) - - IF(APPLE) - EXEC_PROGRAM( arch - ARGS -x86_64 echo "64bit" - OUTPUT_VARIABLE CAB_SYSTEM_INFO_1 ) - IF(${CAB_SYSTEM_INFO_1} MATCHES "64bit") - SET(${is64BitOutVar} TRUE) - ENDIF() - - ELSEIF(UNIX) - - EXEC_PROGRAM( uname - ARGS -m - OUTPUT_VARIABLE CAB_SYSTEM_INFO_1 ) - - STRING(REGEX MATCH "x86_64" CAB_SYSTEM_INFO_1 ${CAB_SYSTEM_INFO_1}) - - - EXEC_PROGRAM( getconf - ARGS -a | grep -i LONG_BIT - OUTPUT_VARIABLE CAB_SYSTEM_INFO_2 ) - - STRING(REGEX MATCH "64" CAB_SYSTEM_INFO_2 ${CAB_SYSTEM_INFO_2}) - - IF(CAB_SYSTEM_INFO_1 STREQUAL "x86_64" AND CAB_SYSTEM_INFO_2 STREQUAL "64") - SET(${is64BitOutVar} TRUE) - ENDIF() - - ELSEIF(WIN32) - - MESSAGE(STATUS "IS_64BIT_SYSTEM: determining system type (32/64bit)...(this may take a few moments)") - EXEC_PROGRAM( SystemInfo OUTPUT_VARIABLE CAB_SYSTEM_INFO_1 ) - - STRING(REGEX MATCH "x64-based PC" CAB_SYSTEM_INFO_1 ${CAB_SYSTEM_INFO_1}) - - IF(CAB_SYSTEM_INFO_1 MATCHES "x64-based PC") - SET(${is64BitOutVar} TRUE) - MESSAGE(STATUS "IS_64BIT_SYSTEM: determining system type (32/64bit)... done (-> 64 Bit)") - ELSE() - MESSAGE(STATUS "IS_64BIT_SYSTEM: determining system type (32/64bit)... done (-> 32 Bit)") - ENDIF() - - ELSE() - MESSAGE(FATAL_ERROR "IS_64BIT_SYSTEM: unknown OS") - ENDIF() - -ENDMACRO(IS_64BIT_SYSTEM is64BitOutVar) - - -############################################################### -### SET_CAB_COMPILER ### -### Macro sets CAB_COMPILER variable if not set ### -### for msvc: CMake Variables are used ### -### for intel,gcc: --version call is evaluated ### -############################################################### -MACRO(SET_CAB_COMPILER) - IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before SET_CAB_COMPILER-Macro PROJECT-Macro has to be called") - ELSE() - IF(NOT CAB_COMPILER) - IF(MSVC) - IF(CMAKE_CL_64) - SET( CAB_COMPILER "msvc19_64" ) - ELSE() - SET( CAB_COMPILER "msvc19_32" ) - ENDIF() - #ELSEIF(APPLE) - ELSEIF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - SET( CAB_COMPILER "clang" ) - ELSE() - EXEC_PROGRAM( ${CMAKE_CXX_COMPILER} - ARGS --version - OUTPUT_VARIABLE CAB_COMPILER_INFO ) - - STRING(REGEX REPLACE ".* \\((.*)\\) ([0-9]*)\\.([0-9]*)[\\. ]([0-9]*).*" "\\1" CAB_COMPILER_NAME ${CAB_COMPILER_INFO}) - STRING(REGEX REPLACE "[^ ]*[^0-9]*([0-9]*)\\.([0-9]*)[\\. ]([0-9]*)[^0-9]*.*" "\\1" CAB_COMPILER_VERSION_MAJOR ${CAB_COMPILER_INFO}) - STRING(REGEX REPLACE "[^ ]*[^0-9]*([0-9]*)\\.([0-9]*)[\\. ]([0-9]*)[^0-9]*.*" "\\2" CAB_COMPILER_VERSION_MINOR ${CAB_COMPILER_INFO}) - STRING(REGEX REPLACE "[^ ]*[^0-9]*([0-9]*)\\.([0-9]*)[\\. ]([0-9]*)[^0-9]*.*" "\\3" CAB_COMPILER_VERSION_PATCH ${CAB_COMPILER_INFO}) - - STRING(TOLOWER ${CAB_COMPILER_NAME} CAB_COMPILER_NAME) - - IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CAB_COMPILER_NAME "gcc") - SET(USE_GCC ON) - ENDIF() - - SET(CAB_COMPILER "${CAB_COMPILER_NAME}${CAB_COMPILER_VERSION_MAJOR}${CAB_COMPILER_VERSION_MINOR}") - ENDIF() - ENDIF() - - SET(CAB_COMPILER ${CAB_COMPILER} CACHE STRING "compiler") - ENDIF() - -ENDMACRO(SET_CAB_COMPILER) - -################################################################ -### CHECK_FOR_VARIABLE ### -### checks for a variable (also env-variables) -### if not found -> error-message!!! -### always: cache-entry update -################################################################ -MACRO(CHECK_FOR_VARIABLE var) - #check ob evtl enviromentvariable gesetzt - IF(NOT ${var}) #true if ${var} NOT: empty, 0, N, NO, OFF, FALSE, NOTFOUND, or <variable>-NOTFOUND - SET(${var} $ENV{${var}}) - ENDIF() - - IF(NOT DEFINED ${var}) - SET(${var} "${var}-NOTFOUND" CACHE STRING "${ARGN}" FORCE) - ENDIF(NOT DEFINED ${var}) - - IF(NOT ${var}) - MESSAGE(FATAL_ERROR "CHECK_FOR_VARIABLE - error - set ${var}") - ENDIF() - -SET(${var} ${${var}} CACHE STRING "${ARGN}" FORCE) -ENDMACRO(CHECK_FOR_VARIABLE var) - - -################################################################# -### ADD_CXX_FLAGS(flags) ### -### flags will be added to CMAKE_CXX_FLAGS ### -################################################################# -MACRO(ADD_CXX_FLAGS) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - STRING(REGEX REPLACE "${option}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${option}" CACHE STRING "common C++ build flags" FORCE) - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) -ENDMACRO(ADD_CXX_FLAGS) - -################################################################# -### ADD_CXX_FLAGS_IF(option flags) ### -### flags will be added to CMAKE_CXX_FLAGS if option exists ### -################################################################# -MACRO(ADD_CXX_FLAGS_IF condition) - IF(${condition}) - ADD_CXX_FLAGS(${ARGN}) - ENDIF(${condition}) -ENDMACRO(ADD_CXX_FLAGS_IF) - -################################################################# -### REMOVE_CXX_FLAGS(flags) ### -### flags will be removed from CMAKE_CXX_FLAGS ### -################################################################# -MACRO(REMOVE_CXX_FLAGS) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - STRING(REGEX REPLACE "${option}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) -ENDMACRO(REMOVE_CXX_FLAGS) - -##################################################################### -### REMOVE_CXX_FLAGS(option flags) ### -### flags will be removed from CMAKE_CXX_FLAGS if option exists ### -##################################################################### -MACRO(REMOVE_CXX_FLAGS_IF condition) - IF(${condition}) - REMOVE_CXX_FLAGS(${ARGN}) - ENDIF(${condition}) -ENDMACRO(REMOVE_CXX_FLAGS_IF) - -################################################################# -### ADD_CXX_BUILDTYPE_FLAGS(buildtype flags) ### -### flags will be added to CMAKE_CXX_BUILDTYPE_FLAGS ### -################################################################# -MACRO(ADD_CXX_BUILDTYPE_FLAGS buildtype) - IF(CMAKE_CXX_FLAGS_${buildtype}) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_CXX_FLAGS_${buildtype} "${CMAKE_CXX_FLAGS_${buildtype}}") - STRING(REGEX REPLACE "${option}" "" CMAKE_CXX_FLAGS_${buildtype} "${CMAKE_CXX_FLAGS_${buildtype}}") - SET(CMAKE_CXX_FLAGS_${buildtype} "${CMAKE_CXX_FLAGS_${buildtype}} ${option}" CACHE STRING "common C++ build flags for ${buildtype}" FORCE) - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) - ENDIF(CMAKE_CXX_FLAGS_${buildtype}) -ENDMACRO(ADD_CXX_BUILDTYPE_FLAGS) - -######################################################################### -### ADD_CXX_BUILDTYPE_FLAGS(buildtype option flags) ### -### flags will be added to CMAKE_CXX_BUILDTYPE_FLAGS if option exists ### -######################################################################### -MACRO(ADD_CXX_BUILDTYPE_FLAGS_IF buildtype condition) - IF(${condition}) - ADD_CXX_BUILDTYPE_FLAGS(${buildtype} ${ARGN}) - ENDIF(${condition}) -ENDMACRO(ADD_CXX_BUILDTYPE_FLAGS_IF) - -################################################################# -### REMOVE_CXX_BUILDTYPE_FLAGS(buildtype flags) ### -### flags will be removed from CMAKE_CXX_FLAGS ### -################################################################# -MACRO(REMOVE_CXX_BUILDTYPE_FLAGS buildtype) - IF(CMAKE_CXX_FLAGS_${buildtype}) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_CXX_FLAGS_${buildtype} "${CMAKE_CXX_FLAGS_${buildtype}}") - STRING(REGEX REPLACE "${option}" "" CMAKE_CXX_FLAGS_${buildtype} "${CMAKE_CXX_FLAGS_${buildtype}}") - SET(CMAKE_CXX_FLAGS_${buildtype} "${CMAKE_CXX_FLAGS_${buildtype}}" - CACHE STRING "C++ build flags for ${buildtype} configuration" FORCE) - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) - ENDIF(CMAKE_CXX_FLAGS_${buildtype}) -ENDMACRO(REMOVE_CXX_BUILDTYPE_FLAGS) - -##################################################################### -### REMOVE_CXX_BUILDTYPE_FLAGS_IF(buildtype option flags) ### -### flags will be removed from CMAKE_CXX_FLAGS if option exists ### -##################################################################### -MACRO(REMOVE_CXX_BUILDTYPE_FLAGS_IF condition) - IF(${condition}) - REMOVE_CXX_BUILDTYPE_FLAGS(${buildtype} ${ARGN}) - ENDIF(${condition}) -ENDMACRO(REMOVE_CXX_BUILDTYPE_FLAGS_IF) - -##################################################################### -### SET_CXX_COMPILER( compiler) ### -### flags will be removed from CMAKE_CXX_FLAGS if option exists ### -##################################################################### -#MACRO(SET_CXX_COMPILER compiler) -# INCLUDE (CMakeForceCompiler) -# SET(CMAKE_SYSTEM_NAME Generic) -# CMAKE_FORCE_CXX_COMPILER (${compiler} "set by user") -# SET(CMAKE_CXX_COMPILER ${compiler} CACHE STRING "C++ compiler" FORCE) -#ENDMACRO(SET_CXX_COMPILER) - -################################################################# -### ADD_C_FLAGS(flags) ### -### flags will be added to CMAKE_C_FLAGS ### -################################################################# -MACRO(ADD_C_FLAGS) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - STRING(REGEX REPLACE "${option}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${option}" CACHE STRING "common C++ build flags" FORCE) - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) -ENDMACRO(ADD_C_FLAGS) - -################################################################# -### ADD_C_FLAGS(option flags) ### -### flags will be added to CMAKE_C_FLAGS if option exists ### -################################################################# -MACRO(ADD_C_FLAGS_IF condition) - IF(${condition}) - ADD_C_FLAGS(${ARGN}) - ENDIF(${condition}) -ENDMACRO(ADD_C_FLAGS_IF) - -################################################################# -### REMOVE_C_FLAGS(flags) ### -### flags will be removed from CMAKE_C_FLAGS ### -################################################################# -MACRO(REMOVE_C_FLAGS) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - STRING(REGEX REPLACE "${option}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) -ENDMACRO(REMOVE_C_FLAGS) - -##################################################################### -### REMOVE_C_FLAGS(option flags) ### -### flags will be removed from CMAKE_C_FLAGS if option exists ### -##################################################################### -MACRO(REMOVE_C_FLAGS_IF condition) - IF(${condition}) - REMOVE_C_FLAGS(${ARGN}) - ENDIF(${condition}) -ENDMACRO(REMOVE_C_FLAGS_IF) - -################################################################# -### ADD_C_BUILDTYPE_FLAGS(buildtype flags) ### -### flags will be added to CMAKE_C_BUILDTYPE_FLAGS ### -################################################################# -MACRO(ADD_C_BUILDTYPE_FLAGS buildtype) - IF(CMAKE_C_FLAGS_${buildtype}) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_C_FLAGS_${buildtype} "${CMAKE_C_FLAGS_${buildtype}}") - STRING(REGEX REPLACE "${option}" "" CMAKE_C_FLAGS_${buildtype} "${CMAKE_C_FLAGS_${buildtype}}") - SET(CMAKE_C_FLAGS_${buildtype} "${CMAKE_C_FLAGS_${buildtype}} ${option}" CACHE STRING "common C++ build flags for ${buildtype}" FORCE) - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) - ENDIF(CMAKE_C_FLAGS_${buildtype}) -ENDMACRO(ADD_C_BUILDTYPE_FLAGS) - -######################################################################### -### ADD_C_BUILDTYPE_FLAGS(buildtype option flags) ### -### flags will be added to CMAKE_C_BUILDTYPE_FLAGS if option exists ### -######################################################################### -MACRO(ADD_C_BUILDTYPE_FLAGS_IF buildtype condition) - IF(${condition}) - ADD_C_BUILDTYPE_FLAGS(${buildtype} ${ARGN}) - ENDIF(${condition}) -ENDMACRO(ADD_C_BUILDTYPE_FLAGS_IF) - -################################################################# -### REMOVE_C_BUILDTYPE_FLAGS(buildtype flags) ### -### flags will be removed from CMAKE_C_FLAGS ### -################################################################# -MACRO(REMOVE_C_BUILDTYPE_FLAGS buildtype) - IF(CMAKE_C_FLAGS_${buildtype}) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_C_FLAGS_${buildtype} "${CMAKE_C_FLAGS_${buildtype}}") - STRING(REGEX REPLACE "${option}" "" CMAKE_C_FLAGS_${buildtype} "${CMAKE_C_FLAGS_${buildtype}}") - SET(CMAKE_C_FLAGS_${buildtype} "${CMAKE_C_FLAGS_${buildtype}}" - CACHE STRING "C++ build flags for ${buildtype} configuration" FORCE) - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) - ENDIF(CMAKE_C_FLAGS_${buildtype}) -ENDMACRO(REMOVE_C_BUILDTYPE_FLAGS) - -##################################################################### -### REMOVE_C_BUILDTYPE_FLAGS_IF(buildtype option flags) ### -### flags will be removed from CMAKE_C_FLAGS if option exists ### -##################################################################### -MACRO(REMOVE_C_BUILDTYPE_FLAGS_IF condition) - IF(${condition}) - REMOVE_C_BUILDTYPE_FLAGS(${buildtype} ${ARGN}) - ENDIF(${condition}) -ENDMACRO(REMOVE_C_BUILDTYPE_FLAGS_IF) - -##################################################################### -### SET_C_COMPILER( compiler) ### -### flags will be removed from CMAKE_C_FLAGS if option exists ### -##################################################################### -MACRO(SET_C_COMPILER compiler) - INCLUDE (CMakeForceCompiler) - SET(CMAKE_SYSTEM_NAME Generic) - CMAKE_FORCE_C_COMPILER (${compiler} "set by user") - SET(CMAKE_C_COMPILER ${compiler} CACHE STRING "C compiler" FORCE) -ENDMACRO(SET_C_COMPILER) - -################################################################# -### ADD_EXE_LINKER_FLAGS(flags) ### -### flags will be added to CMAKE_EXE_LINKER_FLAGS ### -################################################################# -MACRO(ADD_EXE_LINKER_FLAGS) - FOREACH(arg ${ARGN}) - SET(TMP ${arg}) #elsewise the Seperate command doesn't work) - SEPARATE_ARGUMENTS(TMP) - FOREACH(option ${TMP}) - STRING(REGEX REPLACE " ${option}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") - STRING(REGEX REPLACE "${option}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${option}" CACHE STRING "common C++ build flags" FORCE) - ENDFOREACH(option ${TMP}) - ENDFOREACH(arg ${ARGN}) -ENDMACRO(ADD_EXE_LINKER_FLAGS) - diff --git a/CMake/CMakeMacros_old/Cocoa/Link.cmake b/CMake/CMakeMacros_old/Cocoa/Link.cmake deleted file mode 100644 index de9f2cd8939fbe676a773344a284399ed4ace0ad..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/Cocoa/Link.cmake +++ /dev/null @@ -1,4 +0,0 @@ -macro(linkCocoa targetName) - find_library(COCOA_LIB Cocoa) - target_link_libraries(${targetName} ${COCOA_LIB}) -endmacro(linkCocoa) diff --git a/CMake/CMakeMacros_old/Environment/environment.cmake b/CMake/CMakeMacros_old/Environment/environment.cmake deleted file mode 100644 index 2c33e5cc2cf7315107582f9fbb07bfd407bf610c..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/Environment/environment.cmake +++ /dev/null @@ -1,5 +0,0 @@ -unset(BUILD_computerName) -site_name(BUILD_computerName) -MESSAGE(STATUS "computer name: " ${BUILD_computerName}) - -include(${CMAKE_SOURCE_DIR}/MachineFiles/${BUILD_computerName}) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/GMock/FindGMock.cmake b/CMake/CMakeMacros_old/GMock/FindGMock.cmake deleted file mode 100644 index 4ae3b599cb3d212cc5e43a18a9efdfcd56a5ccbe..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/GMock/FindGMock.cmake +++ /dev/null @@ -1,137 +0,0 @@ -# Locate the Google C++ Mocking Framework. -# (This file is almost an identical copy of the original FindGTest.cmake file, -# feel free to use it as it is or modify it for your own needs.) -# -# -# Defines the following variables: -# -# GMOCK_FOUND - Found the Google Testing framework -# GMOCK_INCLUDE_DIRS - Include directories -# -# Also defines the library variables below as normal -# variables. These contain debug/optimized keywords when -# a debugging library is found. -# -# GMOCK_BOTH_LIBRARIES - Both libgmock & libgmock-main -# GMOCK_LIBRARIES - libgmock -# GMOCK_MAIN_LIBRARIES - libgmock-main -# -# Accepts the following variables as input: -# -# GMOCK_HOME - (as a CMake or environment variable) -# The root directory of the gmock install prefix -# -# GMOCK_MSVC_SEARCH - If compiling with MSVC, this variable can be set to -# "MD" or "MT" to enable searching a gmock build tree -# (defaults: "MD") -# -#----------------------- -# Example Usage: -# -# find_package(GMock REQUIRED) -# include_directories(${GMOCK_INCLUDE_DIRS}) -# -# add_executable(foo foo.cc) -# target_link_libraries(foo ${GMOCK_BOTH_LIBRARIES}) -# -#============================================================================= -# This file is released under the MIT licence: -# -# Copyright (c) 2011 Matej Svec -# -# 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. -#============================================================================= - - -function(_gmock_append_debugs _endvar _library) - if(${_library} AND ${_library}_DEBUG) - set(_output optimized ${${_library}} debug ${${_library}_DEBUG}) - else() - set(_output ${${_library}}) - endif() - set(${_endvar} ${_output} PARENT_SCOPE) -endfunction() - -function(_gmock_find_library _name) - find_library(${_name} - NAMES ${ARGN} - HINTS - $ENV{GMOCK_HOME} - ${GMOCK_LIBRARIES_PATH} - ) - mark_as_advanced(${_name}) -endfunction() - - -if(NOT DEFINED GMOCK_MSVC_SEARCH) - set(GMOCK_MSVC_SEARCH MD) -endif() - -set(_gmock_libpath_suffixes lib) -if(MSVC) - if(GMOCK_MSVC_SEARCH STREQUAL "MD") - list(APPEND _gmock_libpath_suffixes - msvc/googlemock/Debug - msvc/googlemock/Release) - elseif(GMOCK_MSVC_SEARCH STREQUAL "MT") - list(APPEND _gmock_libpath_suffixes - msvc/googlemock/Debug - msvc/googlemock/Release) - endif() -elseif(APPLE) - list(APPEND _gmock_libpath_suffixes - clang/googlemock) -endif() - -find_path(GMOCK_INCLUDE_DIR gmock/gmock.h - HINTS - ${GMOCK_ROOT}/googlemock/include -) - -find_path(GMOCK_GTEST_INCLUDE_DIR gtest/gtest.h - HINTS - ${GMOCK_ROOT}/googletest/include -) - -mark_as_advanced(GMOCK_GTEST_INCLUDE_DIR) -mark_as_advanced(GMOCK_INCLUDE_DIR) - -if(MSVC AND GMOCK_MSVC_SEARCH STREQUAL "MD") - # The provided /MD project files for Google Mock add -md suffixes to the - # library names. - _gmock_find_library(GMOCK_LIBRARY gmock-md gmock) - _gmock_find_library(GMOCK_LIBRARY_DEBUG gmock-mdd gmockd) - _gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main-md gmock_main) - _gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_main-mdd gmock_maind) -else() - _gmock_find_library(GMOCK_LIBRARY gmock) - _gmock_find_library(GMOCK_LIBRARY_DEBUG gmockd) - _gmock_find_library(GMOCK_MAIN_LIBRARY gmock_main) - _gmock_find_library(GMOCK_MAIN_LIBRARY_DEBUG gmock_maind) -endif() - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMock DEFAULT_MSG GMOCK_LIBRARY GMOCK_INCLUDE_DIR GMOCK_MAIN_LIBRARY) - -if(GMOCK_FOUND) - set(GMOCK_INCLUDE_DIRS ${GMOCK_INCLUDE_DIR}) - _gmock_append_debugs(GMOCK_LIBRARIES GMOCK_LIBRARY) - _gmock_append_debugs(GMOCK_MAIN_LIBRARIES GMOCK_MAIN_LIBRARY) - set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES}) -endif() diff --git a/CMake/CMakeMacros_old/GMock/Link.cmake b/CMake/CMakeMacros_old/GMock/Link.cmake deleted file mode 100644 index 14b3300e5d4399ee9ae03e01b71ce5b0da736a93..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/GMock/Link.cmake +++ /dev/null @@ -1,11 +0,0 @@ -macro(linkGMock targetName) - if(BUILD_SHARED_LIBS) - add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY) - endif() - - - target_include_directories(${targetName} PRIVATE ${GMOCK_ROOT}/googlemock/include) - target_include_directories(${targetName} PRIVATE ${GMOCK_ROOT}/googletest/include) - - target_link_libraries(${targetName} gmock gmock_main) -endmacro(linkGMock) diff --git a/CMake/CMakeMacros_old/JsonCpp/FindJsonCpp.cmake b/CMake/CMakeMacros_old/JsonCpp/FindJsonCpp.cmake deleted file mode 100644 index a5ab3088f9698b6856d56ab0583f1ff36c313d04..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/JsonCpp/FindJsonCpp.cmake +++ /dev/null @@ -1,28 +0,0 @@ - -find_path(JSONCPP_INCLUDE_DIRS json/json.h - HINTS ${JSONCPP_ROOT} ENV JSONCPP_ROOT - PATH_SUFFIXES include - DOC "Directory where the JSONCPP header files are located" -) - - - -find_library(JSONCPP_LIBRARIES - NAMES jsoncpp.lib - HINTS ${JSONCPP_LIBRARIES_PATH} - DOC "Directory where the JSONCPP library is located" -) - - -# Standard package handling -include(FindPackageHandleStandardArgs) -if(CMAKE_VERSION VERSION_GREATER 2.8.2) - find_package_handle_standard_args(JSONCPP - REQUIRED_VARS JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES) -else() - find_package_handle_standard_args(JSONCPP - REQUIRED_VARS JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES) -endif() - - -mark_as_advanced(JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/JsonCpp/Link.cmake b/CMake/CMakeMacros_old/JsonCpp/Link.cmake deleted file mode 100644 index 3295ab1e7d13f1610c6443703e925eb4907b9b6b..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/JsonCpp/Link.cmake +++ /dev/null @@ -1,6 +0,0 @@ -macro(linkJsonCpp targetName) - - target_include_directories(${targetName} PUBLIC ${JSONCPP_ROOT}/include) - target_link_libraries(${targetName} jsoncpp) - -endmacro(linkJsonCpp) diff --git a/CMake/CMakeMacros_old/MacOSXBundle/Info.plist b/CMake/CMakeMacros_old/MacOSXBundle/Info.plist deleted file mode 100644 index 51f91e9edb97da29dc3188f939391a81d13c9dab..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/MacOSXBundle/Info.plist +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> -<plist version="1.0"> -<dict> - <key>CFBundlePackageType</key> - <string>APPL</string> - <key>CFBundleExecutable</key> - <string>${targetName}</string> - <key>CFBundleName</key> - <string>${targetName}</string> - <key>NSPrincipalClass</key> - <string>NSApplication</string> -</dict> -</plist> diff --git a/CMake/CMakeMacros_old/MacOSXBundle/MacOSXBundle.cmake b/CMake/CMakeMacros_old/MacOSXBundle/MacOSXBundle.cmake deleted file mode 100644 index 981b8697ad97ffef40642650cdd7d9d3c9da35f1..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/MacOSXBundle/MacOSXBundle.cmake +++ /dev/null @@ -1,6 +0,0 @@ -macro(bundleTargetForMacOSX targetName) - - set_target_properties(${targetName} PROPERTIES MACOSX_BUNDLE ON) - set_target_properties(${targetName} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/MacOSXBundle/Info.plist) - -endmacro(bundleTargetForMacOSX) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/MathLink/Link.cmake b/CMake/CMakeMacros_old/MathLink/Link.cmake deleted file mode 100644 index ca929fe98b1311866266b3ebca5f965e8e7d9a65..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/MathLink/Link.cmake +++ /dev/null @@ -1,7 +0,0 @@ - -macro(linkMathLink targetName) - - include_directories(${MATHLINK_ROOT}) - target_link_libraries(${targetName} ${MATHLINK_ROOT}\\wstp64i4.lib) - -endmacro(linkMathLink) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/Metis/FindMetis.cmake b/CMake/CMakeMacros_old/Metis/FindMetis.cmake deleted file mode 100644 index b6c539da2d29316b94a45062d861fa45a03725b7..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/Metis/FindMetis.cmake +++ /dev/null @@ -1,102 +0,0 @@ -# - Try to find METIS -# Once done this will define -# -# METIS_FOUND - system has METIS -# METIS_INCLUDE_DIRS - include directories for METIS -# METIS_LIBRARIES - libraries for METIS -# -# Variables used by this module. They can change the default behaviour and -# need to be set before calling find_package: -# -# METIS_DIR - Prefix directory of the METIS installation -# METIS_INCLUDE_DIR - Include directory of the METIS installation -# (set only if different from ${METIS_DIR}/include) -# METIS_LIB_DIR - Library directory of the METIS installation -# (set only if different from ${METIS_DIR}/lib) -# METIS_TEST_RUNS - Skip tests building and running a test -# executable linked against METIS libraries -# METIS_LIB_SUFFIX - Also search for non-standard library names with the -# given suffix appended -# -# NOTE: This file was modified from a ParMETIS detection script - -#============================================================================= -# Copyright (C) 2015 Jack Poulson. All rights reserved. -# -# Copyright (C) 2010-2012 Garth N. Wells, Anders Logg, Johannes Ring -# and Florian Rathgeber. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -#============================================================================= - -if(NOT METIS_INCLUDE_DIR) - find_path(METIS_INCLUDE_DIR metis.h - HINTS ${METIS_ROOT} ENV METIS_ROOT - PATH_SUFFIXES include - DOC "Directory where the METIS header files are located" - ) -endif() - -if(NOT METIS_LIBRARY) - find_library(METIS_LIBRARY - NAMES metis metis${METIS_LIB_SUFFIX} - HINTS ${METIS_LIBRARIES_PATH} - DOC "Directory where the METIS library is located" - ) -endif() - -# Get METIS version -if(NOT METIS_VERSION_STRING AND METIS_INCLUDE_DIR AND EXISTS "${METIS_INCLUDE_DIR}/metis.h") - set(version_pattern "^#define[\t ]+METIS_(MAJOR|MINOR)_VERSION[\t ]+([0-9\\.]+)$") - file(STRINGS "${METIS_INCLUDE_DIR}/metis.h" metis_version REGEX ${version_pattern}) - - foreach(match ${metis_version}) - if(METIS_VERSION_STRING) - set(METIS_VERSION_STRING "${METIS_VERSION_STRING}.") - endif() - string(REGEX REPLACE ${version_pattern} "${METIS_VERSION_STRING}\\2" METIS_VERSION_STRING ${match}) - set(METIS_VERSION_${CMAKE_MATCH_1} ${CMAKE_MATCH_2}) - endforeach() - unset(metis_version) - unset(version_pattern) -endif() - -# Standard package handling -include(FindPackageHandleStandardArgs) -if(CMAKE_VERSION VERSION_GREATER 2.8.2) - find_package_handle_standard_args(METIS - REQUIRED_VARS METIS_LIBRARY METIS_INCLUDE_DIR - VERSION_VAR METIS_VERSION_STRING) -else() - find_package_handle_standard_args(METIS - REQUIRED_VARS METIS_LIBRARY METIS_INCLUDE_DIR) -endif() - -if(METIS_FOUND) - set(METIS_LIBRARIES ${METIS_LIBRARY}) - set(METIS_INCLUDE_DIRS ${METIS_INCLUDE_DIR}) -endif() - -mark_as_advanced(METIS_INCLUDE_DIR METIS_LIBRARY) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/Metis/Link.cmake b/CMake/CMakeMacros_old/Metis/Link.cmake deleted file mode 100644 index fefa255699dd03672fa6e52a0cb6969664e5160f..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/Metis/Link.cmake +++ /dev/null @@ -1,6 +0,0 @@ -macro(linkMetis targetName) - - include_directories(${METIS_ROOT}/include) - target_link_libraries(${targetName} metis) - -endmacro(linkMetis) diff --git a/CMake/CMakeMacros_old/Qt/Link.cmake b/CMake/CMakeMacros_old/Qt/Link.cmake deleted file mode 100644 index d7104456382b6f19a1a2210525fc0dafc0a03eb7..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/Qt/Link.cmake +++ /dev/null @@ -1,24 +0,0 @@ -macro(linkQt targetName) - - find_package(Qt5Core) - find_package(Qt5Widgets) - find_package(Qt5Gui) - find_package(Qt5PrintSupport) - find_package(Qt5Charts) - - include_directories(${QT5Widgets_INCLUDES}) - include_directories(${QT5Core_INCLUDES}) - include_directories(${QT5Gui_INCLUDES}) - include_directories(${QT5PrintSupport_INCLUDES}) - - add_definitions(${Qt5Widgets_DEFINITIONS}) - add_definitions(${Qt5Core_DEFINITIONS}) - add_definitions(${Qt5Gui_DEFINITIONS}) - add_definitions(${Qt5PrintSupport_DEFINITIONS}) - - target_link_libraries(${targetName} Qt5::Widgets) - target_link_libraries(${targetName} Qt5::Core) - target_link_libraries(${targetName} Qt5::PrintSupport) - target_link_libraries(${targetName} Qt5::Charts) - -endmacro(linkQt) diff --git a/CMake/CMakeMacros_old/README.md b/CMake/CMakeMacros_old/README.md deleted file mode 100644 index 6d5da0578cec2da781912debff5f5c02a2f5db40..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# CMake Macros - -The cmake macros provide the functionalities for creating targets (executables and libraries), finding files and linking against common libraries. - -This repository provides only the macros, which can be integrated in your cmake project as (e.g.) git subtree or just downloaded and copied into the project folder. An usage of this macros with a lot of examples can be found here: [CMake Template on Github](https://github.com/ClubOfDigitalEngineering/CMakeTemplate "CMake Template on Github"). - -To make it work: -- copy the file 'Machinefiles/Isildur' -- rename it to your pc-name (e.g. 'Foos Computer') -- set the paths to the existing libaries - -### The CMake Macros provide macros to link: -- Boost -- Cocoa -- Cuda -- GoogleMock -- JsonCpp -- MPI -- Metis -- OpenMP -- Qt -- VTK diff --git a/CMake/CMakeMacros_old/VTK/Link.cmake b/CMake/CMakeMacros_old/VTK/Link.cmake deleted file mode 100644 index c1fb103c395a72b7f7a557e8e053f8f28e98401c..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/VTK/Link.cmake +++ /dev/null @@ -1,8 +0,0 @@ -macro(linkVTK targetName) - find_package(VTK REQUIRED) - - include(${VTK_USE_FILE}) - include_directories(${VTK_INCLUDE_DIRS}) - - target_link_libraries(${targetName} ${VTK_LIBRARIES}) -endmacro(linkVTK) diff --git a/CMake/CMakeMacros_old/fftw/FindFftw.cmake b/CMake/CMakeMacros_old/fftw/FindFftw.cmake deleted file mode 100644 index ce84cc9c4ceee0abed886cc127ffb17f2227d939..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/fftw/FindFftw.cmake +++ /dev/null @@ -1,29 +0,0 @@ - -find_path(FFTW_INCLUDE_DIRS fftw3.h - HINTS ${FFTW_ROOT} ENV FFTW_ROOT - PATH_SUFFIXES include - DOC "Directory where the FFTW header files are located" -) - - - -find_library(FFTW_LIBRARIES - NAMES libfftw3-3.lib libfftw3f-3.lib libfftw3l-3.lib - HINTS ${FFTW_LIBRARIES_PATH} - DOC "Directory where the FFTW library is located" -) - - -# Standard package handling -include(FindPackageHandleStandardArgs) -if(CMAKE_VERSION VERSION_GREATER 2.8.2) - find_package_handle_standard_args(FFTW - REQUIRED_VARS FFTW_INCLUDE_DIRS FFTW_LIBRARIES) -else() - find_package_handle_standard_args(FFTW - REQUIRED_VARS FFTW_INCLUDE_DIRS FFTW_LIBRARIES) -endif() - - -mark_as_advanced(FFTW_INCLUDE_DIRS FFTW_LIBRARIES) - diff --git a/CMake/CMakeMacros_old/fftw/Link.cmake b/CMake/CMakeMacros_old/fftw/Link.cmake deleted file mode 100644 index 773c45bdf88eab9c090149bce38a211e14235804..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/fftw/Link.cmake +++ /dev/null @@ -1,7 +0,0 @@ - -macro(linkFftw targetName) - - include_directories(${FFTW_ROOT}/api) - target_link_libraries(${targetName} fftw3) - -endmacro(linkFftw) diff --git a/CMake/CMakeMacros_old/general/BuildTarget.cmake b/CMake/CMakeMacros_old/general/BuildTarget.cmake deleted file mode 100644 index a0ca7bd19b0328b91139d8892780d8cebc165c5a..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/general/BuildTarget.cmake +++ /dev/null @@ -1,56 +0,0 @@ -macro(buildExe targetName sourceFiles linkDirs libsToLink includeDirs) - setLinkDirectories("${linkDirs}") - - message(STATUS "build target: " ${targetName}) - add_executable(${targetName} "${sourceFiles}") - - linkLibraries(${targetName} "${libsToLink}") - setIncludeDirectories(${targetName} "${includeDirs}") - -endmacro(buildExe) - -macro(buildLib targetName sourceFiles linkDirs libsToLink includeDirs) - setLinkDirectories("${linkDirs}") - - message(STATUS "build target: " ${targetName}) - add_library(${targetName} ${LIB_TYPE} ${sourceFiles}) - - linkLibraries(${targetName} "${libsToLink}") - setIncludeDirectories(${targetName} "${includeDirs}") - -endmacro(buildLib) - - -macro(setLinkDirectories linkDirs) - foreach(dir ${linkDirs}) - link_directories(${dir}) - endforeach() -endmacro(setLinkDirectories) - -macro(linkLibraries targetName libsToLink) - foreach(lib ${libsToLink}) - target_link_libraries(${targetName} ${lib}) - endforeach() -endmacro(linkLibraries) - -macro(setIncludeDirectories targetName includeDirs) - foreach(dir ${includeDirs}) - target_include_directories(${targetName} PRIVATE ${dir}) - endforeach() -endmacro(setIncludeDirectories) - -include (GenerateExportHeader) -macro(generateExportHeader libName path) - if(${BUILD_SHARED_LIBS}) - GENERATE_EXPORT_HEADER (${libName} - BASE_NAME ${libName} - EXPORT_MACRO_NAME ${libName}_EXPORT - EXPORT_FILE_NAME ${path}/${libName}_EXPORT.h - STATIC_DEFINE ${libName}_BUILT_AS_STATIC - ) - endif() -endmacro(generateExportHeader) - -macro(groupTarget targetName folderName) - set_property( TARGET ${targetName} PROPERTY FOLDER ${folderName} ) -endmacro(groupTarget) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/general/BuildTargetUtilities.cmake b/CMake/CMakeMacros_old/general/BuildTargetUtilities.cmake deleted file mode 100644 index 1a30805c4eb487686ced003a7e6cf616e0950d9b..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/general/BuildTargetUtilities.cmake +++ /dev/null @@ -1,54 +0,0 @@ -macro(sharedLibs) - if(${BUILD_SHARED_LIBS}) - set(LIB_TYPE SHARED) - else() - set(LIB_TYPE STATIC) - - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() - - set(CompilerFlagsCuda - CMAKE_CUDA_FLAGS - CMAKE_CUDA_FLAGS_DEBUG - CMAKE_CUDA_FLAGS_MINSIZEREL - CMAKE_CUDA_FLAGS_RELEASE - CMAKE_CUDA_FLAGS_RELWITHDEBINFO - ) - foreach(CompilerFlag ${CompilerFlagsCuda}) - string(REPLACE "-MD" "-MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() - endif() -endmacro(sharedLibs) - - - -######################################################################## -# AllTest Option # -######################################################################## - -macro(activateAllTestOption) - set(isAllTestSuite ON) -endmacro(activateAllTestOption) - - -macro(deactivateAllTestOption) - set(isAllTestSuite OFF) -endmacro(deactivateAllTestOption) - - -######################################################################## -# target name # -######################################################################## - -macro(setTargetNameToFolderName path) - get_filename_component(targetName "${path}" NAME) -endmacro(setTargetNameToFolderName) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/general/EndingsToCollect.cmake b/CMake/CMakeMacros_old/general/EndingsToCollect.cmake deleted file mode 100644 index f4ca6725f1eab64314ff01df1f247f13a0dcefe0..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/general/EndingsToCollect.cmake +++ /dev/null @@ -1,36 +0,0 @@ -macro(addFileEndingToCollect file_ending) - #input: file_ending --> appends it to the list of files to collect - - list (FIND FILES_TO_COLLECT ${file_ending} index) - if (${index} EQUAL -1) - set(FILES_TO_COLLECT ${FILES_TO_COLLECT} ${file_ending}) - endif() - - #output: files_to_collect -endmacro(addFileEndingToCollect) - - - -macro(resetFileEndingsToCollect) - unset(FILES_TO_COLLECT) -endmacro(resetFileEndingsToCollect) - - - - -macro(addCAndCPPFileTypes) - addFileEndingToCollect("*.h") - addFileEndingToCollect("*.c") - addFileEndingToCollect("*.cpp") - addFileEndingToCollect("*.cxx") - addFileEndingToCollect("*.hpp") - addFileEndingToCollect("*.cu") - addFileEndingToCollect("*.cuh") -endmacro(addCAndCPPFileTypes) - - -macro(addObjCAndObjCPPFileTypesToCollect) - addFileEndingToCollect("*.m") - addFileEndingToCollect("*.mm") - addFileEndingToCollect("*.h") -endmacro(addObjCAndObjCPPFileTypesToCollect) diff --git a/CMake/CMakeMacros_old/general/FileUtilities.cmake b/CMake/CMakeMacros_old/general/FileUtilities.cmake deleted file mode 100644 index 4e9b35370ba22103e87df2a709d9721275270e37..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/general/FileUtilities.cmake +++ /dev/null @@ -1,109 +0,0 @@ -macro(includeRecursiveAllFilesFrom targetName path) - set(collectTestFiles ON) - set(collectProductionFiles ON) - - includeRecursiveFilesFrom(${targetName} ${path}) -endmacro(includeRecursiveAllFilesFrom) - - - -macro(includeRecursiveProductionFilesFrom targetName path) - set(collectTestFiles OFF) - set(collectProductionFiles ON) - - includeRecursiveFilesFrom(${targetName} ${path}) -endmacro(includeRecursiveProductionFilesFrom) - - - -macro(includeRecursiveTestFilesFrom targetName path) - set(collectTestFiles ON) - set(collectProductionFiles OFF) - - includeRecursiveFilesFrom(${targetName} ${path}) -endmacro(includeRecursiveTestFilesFrom) - - - - -macro(includeRecursiveFilesFrom targetName path) - file(GLOB_RECURSE includeSourcePaths ${path}/package.include) - - foreach(package ${includeSourcePaths}) - get_filename_component(package_dir ${package} DIRECTORY) - collectFilesFrom(${package_dir} "${FILES_TO_COLLECT}") - setSourceGroupForFilesIn(${package_dir} ${targetName}) - endforeach() -endmacro(includeRecursiveFilesFrom) - - - -macro(collectFilesFrom path file_endings) - #input: path from files to collect - unset(COLLECTED_FILES_IN_PATH) - unset(ALL_FILES_IN_PATH) - - foreach(_ending ${file_endings}) - FILE(GLOB filesWithEnding ${path}/${_ending}) - set(ALL_FILES_IN_PATH ${ALL_FILES_IN_PATH} ${filesWithEnding}) - endforeach() - - foreach(_file ${ALL_FILES_IN_PATH}) - get_filename_component(fileName ${_file} NAME) - if(collectTestFiles) - if(${fileName} MATCHES "Test" OR ${fileName} MATCHES "Mock") - set(COLLECTED_FILES_IN_PATH ${COLLECTED_FILES_IN_PATH} ${_file}) - endif() - endif() - if(collectProductionFiles) - if(NOT ${fileName} MATCHES "Test" AND NOT ${fileName} MATCHES "Mock") - set(COLLECTED_FILES_IN_PATH ${COLLECTED_FILES_IN_PATH} ${_file}) - endif() - endif() - endforeach() - set(MY_SRCS ${MY_SRCS} ${COLLECTED_FILES_IN_PATH}) - - #output: MY_SRCS -endmacro(collectFilesFrom) - - - - -macro(setSourceGroupForFilesIn package_dir targetName) -#input: target_name PACKAGE_SRCS - buildSourceGroup(${targetName} ${package_dir}) - - if(isAllTestSuite) - source_group(${targetName}\\${SOURCE_GROUP} FILES ${COLLECTED_FILES_IN_PATH}) - else() - source_group(${SOURCE_GROUP} FILES ${COLLECTED_FILES_IN_PATH}) - endif() -#output: - -endmacro(setSourceGroupForFilesIn) - - - - -macro(buildSourceGroup targetName path) -#input: targetName (e.g. lib name, exe name) - - unset(SOURCE_GROUP) - string(REPLACE "/" ";" folderListFromPath ${path}) - set(findTargetName 0) - - foreach(folder ${folderListFromPath}) - if(findTargetName) - set(SOURCE_GROUP ${SOURCE_GROUP}\\${folder}) - endif() - - if(${folder} STREQUAL ${targetName}) - SET(findTargetName 1) - endif() - endforeach() - - if(NOT SOURCE_GROUP) - set(SOURCE_GROUP "general") - endif() - -#output: SOURCE_GROUP -endmacro(buildSourceGroup) \ No newline at end of file diff --git a/CMake/CMakeMacros_old/general/FindCompiler.cmake b/CMake/CMakeMacros_old/general/FindCompiler.cmake deleted file mode 100644 index a878b377a03c99a676d842d60595d079439000f8..0000000000000000000000000000000000000000 --- a/CMake/CMakeMacros_old/general/FindCompiler.cmake +++ /dev/null @@ -1,92 +0,0 @@ -############################################################# -### COMPILER DETECTION ### -############################################################# -# Check for intel compiler -if( CMAKE_CXX_COMPILER MATCHES "icpc" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "icpc" ) - option ( VF_CXX_COMPILER_IS_INTEL "Use Intel compiler" ON ) - # Intel(R) Compiler has its own library archiver, - # if you build libraries and do not use xiar, - # the Intel compiler will complain about invalid - # archives at the link phase. - # The Intel(R) archiver is "xiar" usually - # located in the same folder as the compiler, - FIND_PROGRAM(XIAR xiar) - IF(XIAR) - SET(CMAKE_AR "${XIAR}") - ENDIF(XIAR) - MARK_AS_ADVANCED(XIAR) - - # Intel(R) Compiler also comes with its own linker - # which provides a number of additional benefits when - # linking code compiled with the Intel(R) compiler. - # Again, usually in the same place as icc itself, - FIND_PROGRAM(XILD xild) - IF(XILD) - SET(CMAKE_LINKER "${XILD}") - ENDIF(XILD) - MARK_AS_ADVANCED(XILD) -else() - option ( VF_CXX_COMPILER_IS_INTEL "Use Intel compiler" OFF ) -endif() -mark_as_advanced ( VF_CXX_COMPILER_IS_INTEL ) - -# Check for Gnu compiler -if ( CMAKE_COMPILER_IS_GNUCXX AND NOT VF_CXX_COMPILER_IS_INTEL ) - option ( VF_CXX_COMPILER_IS_GNU "Use gnu compiler" ON ) -else() - option ( VF_CXX_COMPILER_IS_GNU "Use gnu compiler" OFF ) -endif() -mark_as_advanced ( VF_CXX_COMPILER_IS_GNU ) - -# Check for Visual Studio -if(MSVC) - option (VF_CXX_COMPILER_IS_MSVC "Use Visual Studio compiler" ON) -else() - option (VF_CXX_COMPILER_IS_MSVC "Use Visual Studio compiler" OFF) -endif() -mark_as_advanced(VF_CXX_COMPILER_IS_MSVC) - -# Check for IBM compiler -if( CMAKE_CXX_COMPILER MATCHES "xlc" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "xlc" ) - option ( VF_CXX_COMPILER_IS_IBM "Use IBM compiler" ON ) -else() - option ( VF_CXX_COMPILER_IS_IBM "Use IBM compiler" OFF ) -endif() -mark_as_advanced ( VF_CXX_COMPILER_IS_IBM ) - -# Check for NEC SX compiler -if( CMAKE_CXX_COMPILER MATCHES "sxc" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "sxc" OR CMAKE_CXX_COMPILER MATCHES "sxmpic" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "sxmpic" ) - option ( VF_CXX_COMPILER_IS_NEC "Use NEC compiler" ON ) -else() - option ( VF_CXX_COMPILER_IS_NEC "Use NEC compiler" OFF ) -endif() -mark_as_advanced ( VF_CXX_COMPILER_IS_NEC ) - -# Check for Clang compiler -if( CMAKE_CXX_COMPILER MATCHES "clang" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" ) - option ( VF_CXX_COMPILER_IS_CLANG "Use clang compiler" ON ) -else() - option ( VF_CXX_COMPILER_IS_CLANG "Use clang compiler" OFF ) -endif() -mark_as_advanced ( VF_CXX_COMPILER_IS_CLANG ) - -if( CMAKE_CXX_COMPILER_ID MATCHES Cray ) - option ( VF_CXX_COMPILER_IS_CRAY "Use Cray compiler" ON ) - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.4) - message( FATAL_ERROR "Insufficient Cray Compiler Environment version" ) - endif() -else() - option ( VF_CXX_COMPILER_IS_CRAY "Use Cray compiler" OFF ) -endif() -mark_as_advanced ( VF_CXX_COMPILER_IS_CRAY ) - -# Check for MPI wrapper -get_filename_component( CXX_COMPILER_WITHOUT_PATH ${CMAKE_CXX_COMPILER} NAME ) -if( CXX_COMPILER_WITHOUT_PATH MATCHES "mpi" OR CMAKE_CXX_COMPILER_ARG1 MATCHES "mpi" ) - option ( VF_CXX_COMPILER_IS_MPI_WRAPPER "Compiler is MPI wrapper" ON ) -else() - option ( VF_CXX_COMPILER_IS_MPI_WRAPPER "Compiler is MPI wrapper" OFF ) -endif() -mark_as_advanced ( VF_CXX_COMPILER_IS_MPI_WRAPPER ) - -############################################################################################################################ diff --git a/CMake/CMakeSetCompilerFlags.cmake b/CMake/CMakeSetCompilerFlags.cmake index 7197caaa64838edbcfbd421af334dd29fe4362ba..9ecf187011e5ddd2564ee8ffb25ef77c53ded423 100644 --- a/CMake/CMakeSetCompilerFlags.cmake +++ b/CMake/CMakeSetCompilerFlags.cmake @@ -1,154 +1,89 @@ + +############################################################### +# set hostname -> CAB_MACHINE and load an optional config file +############################################################### +macro(loadMachineFile) + + IF(NOT CAB_MACHINE) + SET(CAB_MACHINE $ENV{CAB_MACHINE}) + + IF( CAB_MACHINE ) + STRING(TOUPPER "${CAB_MACHINE}" CAB_MACHINE) + ELSE() + EXECUTE_PROCESS( COMMAND hostname OUTPUT_VARIABLE CAB_MACHINE) + STRING(REGEX REPLACE "[ ]*([A-Za-z0-9]+).*[\\\\n]*" "\\1" CAB_MACHINE "${CAB_MACHINE}" ) + STRING(TOUPPER "${CAB_MACHINE}" CAB_MACHINE) + ENDIF() + ENDIF() + + LIST(APPEND VF_COMPILER_DEFINITION CAB_MACHINE=${CAB_MACHINE}) + SET(CMAKE_CONFIG_FILE "${VF_CMAKE_DIR}/cmake_config_files/${CAB_MACHINE}.config.cmake") + + IF(NOT EXISTS ${CMAKE_CONFIG_FILE}) + status("No configuration file found.") + ELSE() + status("Load configuration file ${CAB_MACHINE}.config.cmake") + include(${CMAKE_CONFIG_FILE}) + ENDIF() + +endmacro() + + ################################################################ ### SET_COMPILER_SPECIFIC_FLAGS ### -### determines compiler flags variabels ### -### compiler_type: e.g. msvc9_x64 ### -### build_type : BINARY, STATIC, SHARED ### +### determines compiler flags variables ### ################################################################ -MACRO(SET_COMPILER_SPECIFIC_FLAGS compiler_type build_type) - IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before SET_CAB_COMPILER-Macro PROJECT-Macro has to be called") - ENDIF() - - OPTION(USE_OPENMP "activate open" ON) - - IF(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - SET(USE_OPENMP OFF) - ENDIF() - - ############################################################################################################### - ## Flags ruecksetzen - ############################################################################################################### - SET(CAB_COMPILER_ADDITIONAL_LINK_PROPS "") - SET(CAB_COMPILER_ADDITIONAL_LINK_PROPS_DEBUG "") - SET(CAB_COMPILER_ADDITIONAL_LINK_PROPS_RELEASE "") - +macro(loadCompilerFlags) + SET(CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "") SET(CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "") SET(CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "") - SET(CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "") - SET(CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS_DEBUG "") - SET(CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS_RELEASE "") + # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_<LANG>_COMPILER_ID - ############################################################################################################### - ## ggf. spezielles compiler flag file lesen - ############################################################################################################### IF( SPECIFIC_COMPILER_FLAG_FILE ) - INCLUDE( ${SPECIFIC_COMPILER_FLAG_FILE}) - ############################################################################################################### - ## standard compiler flags - ############################################################################################################### - ELSEIF( EXISTS "${VF_CMAKE_DIR}/compilerflags/${CAB_COMPILER}.cmake" ) - INCLUDE( ${VF_CMAKE_DIR}/compilerflags/${CAB_COMPILER}.cmake) - ############################################################################################################### - ## unknown compiler - ############################################################################################################### + include( ${SPECIFIC_COMPILER_FLAG_FILE}) + ELSEIF( EXISTS "${VF_CMAKE_DIR}/compilerflags/${CMAKE_CXX_COMPILER_ID}.cmake" ) + status("Load compiler file: ${CMAKE_CXX_COMPILER_ID}.cmake") + include(${VF_CMAKE_DIR}/compilerflags/${CMAKE_CXX_COMPILER_ID}.cmake) ELSE() - #MESSAGE(FATAL_ERROR "CAB_COMPILER=${CAB_COMPILER} seems to be a not supported compiler") - #MESSAGE(WARNING "CAB_COMPILER=${CAB_COMPILER} seems to be a not supported compiler; set to generic") - SET(CAB_COMPILER "gccGeneric") - INCLUDE( ${VF_CMAKE_DIR}/compilerflags/${CAB_COMPILER}.cmake) + MESSAGE(FATAL_ERROR "compiler=${CMAKE_CXX_COMPILER_ID} seems to be a not supported compiler") ENDIF() - - - ############################################################################################################### - #64 Bit compilation?? - ############################################################################################################### - IF(NOT DEFINED USE_64BIT_COMPILER_OPTIONS) - IF(MSVC AND NOT CMAKE_CL_64) - SET(OPTION64 OFF) - ELSEIF(MSVC AND CMAKE_CL_64) - SET(OPTION64 ON) - ELSE() - IS_64BIT_SYSTEM( IS64BITSYSTEM ) - IF(IS64BITSYSTEM STREQUAL "TRUE") - SET(OPTION64 ON) - ELSE() - SET(OPTION64 OFF) - ENDIF() - ENDIF() - ENDIF() - - OPTION(USE_64BIT_COMPILER_OPTIONS "set 64 bit compiler flags" ${OPTION64}) - - ############################################################################################################### - # set flags - ############################################################################################################### -IF(USE_64BIT_COMPILER_OPTIONS) - SET_COMPILER_SPECIFIC_FLAGS_INTERN( ${build_type} 1) -else() - SET_COMPILER_SPECIFIC_FLAGS_INTERN( ${build_type} 0) -endif() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS compiler_type build_type) + +endmacro() ################################################################ ### ADD_COMPILER_FLAGS_TO_PROJECT ### -### adds COMPILER_FLGAS TO project ### -### project_language: CXX , C ### ################################################################ -MACRO(ADD_COMPILER_FLAGS_TO_PROJECT compiler_type project_name project_language build_type) - - IF(NOT ${project_language} MATCHES "C") - IF(NOT ${project_language} MATCHES "CXX") - MESSAGE(FATAL_ERROR "project_language must be CXX or C") - ENDIF() - ENDIF() - - ################################################################ - # SET_COMPILER_SPECIFIC_FLAGS - ################################################################ - SET_COMPILER_SPECIFIC_FLAGS( ${compiler_type} ${build_type} ) - - #workaround fuer itanium processoren - IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ia64") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS -D_M_IA64) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS -D_M_IA64) - ENDIF() - - ################################################################ - # LINKER PROPS - ################################################################ - status("additional linker probs: ${CAB_COMPILER_ADDITIONAL_LINK_PROPS}") - - IF(CAB_COMPILER_ADDITIONAL_LINK_PROPS) - ADD_TARGET_PROPERTIES(${project_name} LINK_FLAGS ${CAB_COMPILER_ADDITIONAL_LINK_PROPS}) - ENDIF() - IF(CAB_COMPILER_ADDITIONAL_LINK_PROPS_DEBUG) - ADD_TARGET_PROPERTIES(${project_name} LINK_FLAGS ${CAB_COMPILER_ADDITIONAL_LINK_PROPS_DEBUG}) - ENDIF() - IF(CAB_COMPILER_ADDITIONAL_LINK_PROPS_RELEASE) - ADD_TARGET_PROPERTIES(${project_name} LINK_FLAGS ${CAB_COMPILER_ADDITIONAL_LINK_PROPS_RELEASE}) - ENDIF() - - ################################################################ - # COMPILER FLAGS - ################################################################ - #message (COMPILE FLAGS INTERN: ${CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS}) - - # TODO: Clean this up!! - IF(CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS) - #message (COMPILE FLAGS INTERN: ${CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS}) - foreach(flag IN LISTS CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS) - #message(compiler option: ${flag}) - target_compile_options(${project_name} PRIVATE "$<$<COMPILE_LANGUAGE:${project_language}>:${flag}>") - endforeach() - #get_target_property(var ${project_name} COMPILE_OPTIONS) - #message(set compile options: ${var}) - - #add_custom_command(TARGET ${project_name} POST_BUILD COMMAND echo built with the flags: ${var}) - #ADD_TARGET_PROPERTIES(${project_name} COMPILE_FLAGS ${CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS}) - #target_compile_options (${project_name} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS}>) - ENDIF() - IF(CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS_DEBUG) - MESSAGE(STATUS "ADD_COMPILER_FLAGS_TO_PROJECT: sorry, a long as CMake has no support for COMPILE_FLAGS_<CONFIG> -> DEBUG flags are neglected") - #ADD_TARGET_PROPERTIES(${project_name} COMPILE_FLAGS_DEBUG ${CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS_DEBUG}) - ENDIF() - IF(CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS_RELEASE) - MESSAGE(STATUS "ADD_COMPILER_FLAGS_TO_PROJECT: sorry, a long as CMake has no support for COMPILE_FLAGS_<CONFIG> -> RELEASE flags are set for RELEASE AND DEBUG") - ADD_TARGET_PROPERTIES(${project_name} COMPILE_FLAGS ${CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS_RELEASE}) - #ADD_TARGET_PROPERTIES(${project_name} COMPILE_FLAGS_RELEASE ${CAB_COMPILER_ADDTIONAL_${project_language}_COMPILER_FLAGS_RELEASE}) - ENDIF() - - -ENDMACRO(ADD_COMPILER_FLAGS_TO_PROJECT compiler_type project_name project_language build_type) \ No newline at end of file +function(addAdditionalFlags project_name) + + status_lib("additional compiler flags CXX: ${CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS}") + status_lib("additional compiler flags CXX debug: ${CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG}") + status_lib("additional compiler flags CXX release: ${CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE}") + status_lib("additional compiler definitions: ${VF_COMPILER_DEFINITION}") + status_lib("additional linker flags: ${VF_LINK_OPTIONS}") + + # compile definitions + foreach(flag IN LISTS VF_COMPILER_DEFINITION) + target_compile_definitions(${library_name} PRIVATE ${flag}) + endforeach() + + # link options + foreach(flag IN LISTS VF_LINK_OPTIONS) #TODO: check what happens when lib is static + target_link_options(${library_name} PRIVATE ${flag}) + endforeach() + + # compile options + foreach(flag IN LISTS CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS) + target_compile_options(${project_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${flag}>") + endforeach() + + foreach(flag IN LISTS CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG) + target_compile_options(${project_name} PRIVATE "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:DEBUG>>:${flag}>") + endforeach() + + foreach(flag IN LISTS CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE) + target_compile_options(${project_name} PRIVATE "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:RELEASE>>:${flag}>") + endforeach() + +endfunction() \ No newline at end of file diff --git a/CMake/VirtualFluidsMacros.cmake b/CMake/VirtualFluidsMacros.cmake index 83274c2fb21a54d8aead43e1215c3f1c53cea4f3..676353ea2c2e03f2f55e096948643f85f8b87ec0 100644 --- a/CMake/VirtualFluidsMacros.cmake +++ b/CMake/VirtualFluidsMacros.cmake @@ -8,9 +8,49 @@ ################################################################################# function(status msg) - message(STATUS " VF - ${msg}") + message(STATUS " VF: ${msg}") endfunction() +function(status_lib msg) + message(STATUS " ${msg}") +endfunction() + +################################################################################# +## include intern macros +################################################################################# +include(${VF_CMAKE_DIR}/CMakeSetCompilerFlags.cmake) +include(${VF_CMAKE_DIR}/FileUtilities.cmake) +include(${VF_CMAKE_DIR}/3rd.cmake) + +############################################################################################################### +# Reset the compiler and linker flags +############################################################################################################### +SET(VF_COMPILER_DEFINITION) +SET(VF_LINK_OPTIONS) +SET(CAB_ADDITIONAL_LINK_LIBRARIES) +LIST(APPEND VF_COMPILER_DEFINITION SOURCE_ROOT=${VF_ROOT_DIR} ) + +################################################################# +### OS DEFINES ### +################################################################# +IF(WIN32) + list(APPEND VF_COMPILER_DEFINITION __WIN__) +ELSEIF(UNIX) + list(APPEND VF_COMPILER_DEFINITION __unix__) +ENDIF() + +IF(APPLE) + list(APPEND VF_COMPILER_DEFINITION __APPLE__) +endif() + +list(APPEND VF_COMPILER_DEFINITION ${CMAKE_CXX_COMPILER_ID}) + +################################################################# +### load compiler and machine file ### +################################################################# +loadMachineFile() +loadCompilerFlags() + ################################################################################# ## set global project file endings ################################################################################# @@ -46,9 +86,9 @@ endfunction() ################################################################################# ## Add a target, link the libraries and add the compiler flags to the target -## The name of the target is vf_get_library_name(). ## ## parameter: +## NAME - Name of the target. If not passed the name is vf_get_library_name(). ## BUILDTYPE - STATIC; SHARED; EXECUTABLE ## DEPENDS - libraries to link ## FILES - adds these files to the target @@ -63,10 +103,14 @@ function(vf_add_library) set( options ) set( oneValueArgs ) - set( multiValueArgs BUILDTYPE DEPENDS FILES FOLDER EXCLUDE) + set( multiValueArgs NAME BUILDTYPE DEPENDS FILES FOLDER EXCLUDE) cmake_parse_arguments( ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - vf_get_library_name (library_name) + if(${ARG_NAME}) + set(library_name ${ARG_NAME}) + else() + vf_get_library_name (library_name) + endif() status("Configuring the target: ${library_name} (type=${ARG_BUILDTYPE})...") @@ -75,23 +119,6 @@ function(vf_add_library) includeProductionFiles (${library_name} "${sourceFiles}") - - ################################################################# - ### OS DEFINES ### - ################################################################# - IF(WIN32) - LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__WIN__) - ELSEIF(APPLE) - LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - ELSEIF(UNIX) - LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) - ENDIF() - - ################################################################# - ### ADDITIONAL_MAKE_CLEAN_FILES ### - ################################################################# - #SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${GENERATED_FILES}") - ################################################################# ### EXCECUTABLE ### ################################################################# @@ -119,7 +146,7 @@ function(vf_add_library) ################################################################# ### ADDITIONAL LINK LIBRARIES ### ################################################################# - status("Link Depending Libraries: ${ARG_DEPENDS}") + status_lib("Link Depending Libraries: ${ARG_DEPENDS}") if (ARG_DEPENDS) target_link_libraries(${library_name} PRIVATE ${ARG_DEPENDS}) endif() @@ -127,38 +154,7 @@ function(vf_add_library) ################################################################# ### COMPILER Flags ### ################################################################# - ADD_COMPILER_FLAGS_TO_PROJECT(${CAB_COMPILER} ${library_name} "CXX" ${ARG_BUILDTYPE}) - status("compiler flags for compiler ${CAB_COMPILER} on machine ${CAB_MACHINE} for project ${project_name} (${ARG_BUILDTYPE}) have been configured") - status("compiler flags: ${CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS}") - status("additional compiler flags: ${CAB_ADDTIONAL_COMPILER_FLAGS}") - - #MESSAGE (COMPILE FLAGS: ${CAB_ADDTIONAL_COMPILER_FLAGS}) - IF(CAB_ADDTIONAL_COMPILER_FLAGS) - ADD_TARGET_PROPERTIES(${library_name} COMPILE_FLAGS ${CAB_ADDTIONAL_COMPILER_FLAGS}) - ENDIF() - IF(CAB_ADDTIONAL_COMPILER_FLAGS_DEBUG) - MESSAGE(FATAL_ERROR "COMPILE_FLAGS_DEBUG_<CONFIG> not supported by cmake yet :-(") - ADD_TARGET_PROPERTIES(${library_name} COMPILE_FLAGS_DEBUG ${CAB_ADDTIONAL_COMPILER_FLAGS_DEBUG}) - ENDIF() - IF(CAB_ADDTIONAL_COMPILER_FLAGS_RELEASE) - MESSAGE(FATAL_ERROR "COMPILE_FLAGS_<CONFIG> not supported by cmake yet :-(") - ADD_TARGET_PROPERTIES(${library_name} COMPILE_FLAGS_RELEASE ${CAB_ADDTIONAL_COMPILER_FLAGS_RELEASE}) - ENDIF() - - ################################################################# - ### ADDITIONAL LINK PROPERTIES ### - ################################################################# - status("additional linker flags: ${CAB_ADDITIONAL_LINK_FLAGS}") - - IF(CAB_ADDITIONAL_LINK_FLAGS) - ADD_TARGET_PROPERTIES(${library_name} LINK_FLAGS ${CAB_ADDITIONAL_LINK_FLAGS}) - ENDIF() - IF(CAB_ADDITIONAL_LINK_FLAGS_DEBUG) - ADD_TARGET_PROPERTIES(${library_name} LINK_FLAGS_DEBUG ${CAB_ADDITIONAL_LINK_FLAGS_DEBUG}) - ENDIF() - IF(CAB_ADDITIONAL_LINK_FLAGS_RELEASE) - ADD_TARGET_PROPERTIES(${library_name} LINK_FLAGS_RELEASE ${CAB_ADDITIONAL_LINK_FLAGS_RELEASE}) - ENDIF() + addAdditionalFlags(${library_name}) if (NOT ${ARG_BUILDTYPE} MATCHES binary) @@ -172,7 +168,7 @@ function(vf_add_library) target_include_directories(${library_name} PRIVATE ${VF_SRC_DIR}/cpu) - #status("... configuring target: ${library_name} (type=${ARG_BUILDTYPE}) done") + status("... configuring target: ${library_name} (type=${ARG_BUILDTYPE}) done") endfunction() diff --git a/CMake/cmake_config_files/ALATAR.config.cmake b/CMake/cmake_config_files/ALATAR.config.cmake deleted file mode 100644 index e6d45e580866c963a43c0db09614c859e5ceaf90..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ALATAR.config.cmake +++ /dev/null @@ -1,67 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost: 1.50.0 -SET(BOOST_VERSION "1.51.0" CACHE STRING "std: 1.51.0") - -#SET(MPI_DIR "/hpc3lustre/software/lib/openmpi-1.4.1-gcc41") - -SET(USE_MPI_CXX_SYNTAX OFF) -#SET(MPI_COMPILER "/hpc3lustre/software/lib/openmpi-1.4.1-gcc41/bin/mpicxx") - -IF(CAB_COMPILER MATCHES "gcc41") - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -gcc41) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.51.0" ) - SET(BOOST_INCLUDEDIR "/hpc3lustre/software/irmb/boost/boost_1_51_0") - SET(BOOST_LIBRARYDIR "/hpc3lustre/software/irmb/boost/boost_1_51_0/stageGCC/lib") - - ENDIF() -ENDIF() - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() - -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Source/packages/zoltan/src/include") - SET(ZOLTAN_DEBUG_LIBRARY "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Build/packages/zoltan/src/libzoltan.a") - SET(ZOLTAN_RELEASE_LIBRARY "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Build/packages/zoltan/src/libzoltan.a") -ENDIF() - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/hpc3lustre/software/irmb/metis/include") - SET(METIS_DEBUG_LIBRARY "/hpc3lustre/software/irmb/metis/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/hpc3lustre/software/irmb/metis/lib/libmetis.a") -ENDIF() - -################################################################################# -# YAML -################################################################################# -IF(${USE_YAML}) - SET(YAML_INCLUDEDIR "/hpc3lustre/software/irmb/yaml/yaml-cpp/include") - SET(YAML_DEBUG_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") - SET(YAML_RELEASE_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") -ENDIF() - -################################################################################## -# Bond -################################################################################## -IF(${USE_BOND}) - SET(BOND_INCLUDEDIR "/hpc3lustre/home/koskuche/projects/bond/bond_src/cpp/bond/fetol") - SET(BOND_DEBUG_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") - SET(BOND_RELEASE_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") -ENDIF() - diff --git a/CMake/cmake_config_files/ALTIX.config.cmake b/CMake/cmake_config_files/ALTIX.config.cmake deleted file mode 100644 index 387da3bdb7069019545afa809d005a339e1ec170..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ALTIX.config.cmake +++ /dev/null @@ -1,53 +0,0 @@ -OPTION(CAB_COMPILER_64BIT "64BIT COMPILATION" ON) - -################################################################################# -# COMPILER -################################################################################# -SET( ALTIX_CXX_COMPILER "mpiCC" ) -SET( ALTIX_C_COMPILER "mpicc" ) - -################################################################################# -# COMPILER FLAG VAR -################################################################################# -IF(NOT CAB_COMPILER}) - IF(NOT DEFINED CAB_COMPILER) - SET( CAB_COMPILER "intel9" ) - ENDIF() -ENDIF() - -SET(BOOST_DIR "/home/hlrb2/h005x/h005xac/boost/include/boost-1_34_1") -SET(USE_BOOST_STATIC_LIBS TRUE) - -################################################################################# -# MPI -################################################################################# - - -################################################################################# -# BOOST -################################################################################# -IF(NEED_BOOST) - SET(BOOST_USE_MULTITHREAD ON) - SET(BOOST_USE_STATIC_LIBS ON) - - #IF(BOOST_VERSION MATCHES "1.35.0" ) - # - # SET(BOOST_INCLUDEDIR "E:/3rdPartyLibs/boost/boost_1_35") - # - # IF(CMAKE_CL_64) - # SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_64bit") - # ELSE() - # SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_32bit") - # ENDIF() - - #ELSE - IF(BOOST_VERSION MATCHES "1.34.1" ) - SET(BOOST_INCLUDEDIR "/home/hlrb2/h005x/h005xac/boost/include/boost-1_34_1") - SET(BOOST_LIBRARYDIR "/home/hlrb2/h005x/h005xac/boost/include/boost-1_34_1/lib") - ENDIF() - - IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") - ENDIF() -ENDIF() - diff --git a/CMake/cmake_config_files/AMAN.config.cmake b/CMake/cmake_config_files/AMAN.config.cmake deleted file mode 100644 index 49694f481dfcb9ab194f75bf55b10a8351931861..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/AMAN.config.cmake +++ /dev/null @@ -1,83 +0,0 @@ -######################################################################################## -## CPU ## -######################################################################################## -SET(CPU_TYPE "Opteron") - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost: 1.37.0 -SET(BOOST_VERSION "1.37.0" CACHE STRING "std: 1.37.0") - -######################################################################################## -## gcc42 ## -######################################################################################## -IF(CAB_COMPILER MATCHES "gcc42") - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -gcc42) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - SET(BOOST_INCLUDEDIR "/opt/boost/gcc-4.2/include/boost-1_37") - SET(BOOST_LIBRARYDIR "/opt/boost/gcc-4.2/lib") - ENDIF() - - SET(MPI_DIR "/opt/mpich-gm/gcc-4.2") - -######################################################################################## -## gcc41 ## -######################################################################################## -ELSEIF(CAB_COMPILER MATCHES "gcc41") - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -gcc41) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - SET(BOOST_INCLUDEDIR "/opt/boost/gcc-4.1/include/boost-1_37") - SET(BOOST_LIBRARYDIR "/opt/boost/gcc-4.1/lib") - ENDIF() - - SET(MPI_DIR "/opt/mpich-gm/gcc-4.1") - -######################################################################################## -## gcc34 ## -######################################################################################## -ELSEIF(CAB_COMPILER MATCHES "gcc34") - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -gcc34) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - SET(BOOST_INCLUDEDIR "/opt/boost/gcc-3.4/include/boost-1_37") - SET(BOOST_LIBRARYDIR "/opt/boost/gcc-3.4/lib") - ENDIF() - - SET(MPI_DIR "/opt/mpich-gm/gcc-3.4") - -######################################################################################## -## intel10.1 ## -######################################################################################## -ELSEIF(CAB_COMPILER MATCHES "intel10" ) - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -il) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - #SET(BOOST_INCLUDEDIR "/opt/boost/intel-10.1/include/boost-1_37") - #SET(BOOST_LIBRARYDIR "/opt/boost/intel-10.1/lib") - ENDIF() - - #SET(MPI_DIR "/opt/mpich/intel-10.1") -ENDIF() - - -IF(NEED_BOOST AND BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() - - - diff --git a/CMake/cmake_config_files/AMATERASU.config.cmake b/CMake/cmake_config_files/AMATERASU.config.cmake index a3bba0249a40dc116a986324e5ac6368ae3e7ef2..4cf53d794e743b61aa18a0565f97f6eb5fbf723b 100644 --- a/CMake/cmake_config_files/AMATERASU.config.cmake +++ b/CMake/cmake_config_files/AMATERASU.config.cmake @@ -1,8 +1,14 @@ +################################################################################# +# VirtualFluids MACHINE FILE +# Responsible: Martin Geier +# OS: Windows 10 +################################################################################# + + + ################################################################################# # METIS ################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "C:/Users/geier/Documents/metis-5.1.0/include") - SET(METIS_DEBUG_LIBRARY "C:/Users/geier/Documents/metis-5.1.0/build/libmetis/Debug/metis.lib") - SET(METIS_RELEASE_LIBRARY "C:/Users/geier/Documents/metis-5.1.0/build/libmetis/Release/metis.lib") -ENDIF() \ No newline at end of file +SET(METIS_INCLUDEDIR "C:/Users/geier/Documents/metis-5.1.0/include") +SET(METIS_DEBUG_LIBRARY "C:/Users/geier/Documents/metis-5.1.0/build/libmetis/Debug/metis.lib") +SET(METIS_RELEASE_LIBRARY "C:/Users/geier/Documents/metis-5.1.0/build/libmetis/Release/metis.lib") diff --git a/CMake/cmake_config_files/ARAGORN.config.cmake b/CMake/cmake_config_files/ARAGORN.config.cmake deleted file mode 100644 index 26d71771a5f895f76e05fccd53e6b1165efce4d7..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ARAGORN.config.cmake +++ /dev/null @@ -1,53 +0,0 @@ -################################################################################# -# COMPILER FLAG VAR -################################################################################# -IF(NOT CAB_COMPILER}) - IF( ${MSVC_VERSION} MATCHES "1400" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1400" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_32" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_32" ) - ELSE() - MESSAGE(ERROR, "unknown ms studio version MSVC_VERSION = "${MSVC_VERSION}) - ENDIF() -ENDIF() - -################################################################################# -# MPI -################################################################################# -SET(MPI_DIR "c:/programme/mpich2") - -################################################################################# -# BOOST -################################################################################# -IF(NEED_BOOST) - - SET(BOOST_USE_MULTITHREAD ON) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.35.0" ) - - SET(BOOST_INCLUDEDIR "c:/cpp/boost/boost_1_35_0") - - IF(CMAKE_CL_64) - # SET(BOOST_LIBRARYDIR "c:/cpp/boost/boost_1_35_0/lib/x86_64bit") - ELSE() - SET(BOOST_LIBRARYDIR "c:/cpp/boost/boost_1_35_0/lib") - ENDIF() - - ELSEIF(BOOST_VERSION MATCHES "1.38.0" ) - SET(BOOST_INCLUDEDIR "e:/cpp/boost/boost_1_38") - SET(BOOST_LIBRARYDIR "e:/cpp/boost/boost_1_38/lib") - - ENDIF() - - IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") - ENDIF() -ENDIF() - - - diff --git a/CMake/cmake_config_files/ARWEN.config.cmake b/CMake/cmake_config_files/ARWEN.config.cmake deleted file mode 100644 index d932fbf064157d0dcc141d80279ba7c6899028ce..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ARWEN.config.cmake +++ /dev/null @@ -1,17 +0,0 @@ -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.60.0") -SET(BOOST_ROOT "d:/boost/boost_1_60_0") -SET(BOOST_DIR ${BOOST_ROOT}) -SET(BOOST_LIBRARYDIR ${BOOST_ROOT}"/stageMSVC64/lib") -################################################################################# - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "d:/metis-5.1.0/include") - SET(METIS_DEBUG_LIBRARY "d:/metis-5.1.0/build/libmetis/Debug/metis.lib") - SET(METIS_RELEASE_LIBRARY "d:/metis-5.1.0/build/libmetis/Release/metis.lib") -ENDIF() \ No newline at end of file diff --git a/CMake/cmake_config_files/BAUMBART.config.cmake b/CMake/cmake_config_files/BAUMBART.config.cmake index 6b0aece2c2e47e713ed7cf8cfd99967a5c9bf047..ba0412c88fb9b1982c73c1256ae17eec2901d54c 100644 --- a/CMake/cmake_config_files/BAUMBART.config.cmake +++ b/CMake/cmake_config_files/BAUMBART.config.cmake @@ -1,3 +1,8 @@ +################################################################################# +# VirtualFluids MACHINE FILE +# Responsible: Martin Schoenherr +# OS: Windows 10 +################################################################################# #Don't change: SET(METIS_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/metis/metis-5.1.0 CACHE PATH "METIS ROOT") SET(GMOCK_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/googletest CACHE PATH "GMOCK ROOT") diff --git a/CMake/cmake_config_files/BILBO.config.cmake b/CMake/cmake_config_files/BILBO.config.cmake index ead4ef15bcfe529d4b6a5a2d9d5e6f5211f04a66..3c7f0f728ddad36d22ff1d65d83aa7927c14ed48 100644 --- a/CMake/cmake_config_files/BILBO.config.cmake +++ b/CMake/cmake_config_files/BILBO.config.cmake @@ -1,41 +1,13 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - -################################################################################# -# MPI -################################################################################# -#SET(MPI_DIR "C:/Program Files (x86)/mpich2") -#SET(MPI_DIR "C:/Program Files/mpich2") -#SET(USE_MPI_CXX_SYNTAX OFF) -#SET(MPI_COMPILER "C:/Program Files/mpich2/bin/mpicxx") -#SET(MPI_INCLUDE_PATH "C:/Program Files (x86)/mpich2/include") -#SET(MPI_LIBRARY "C:/Program Files/mpich2/lib/libmpi.a") -#SET(MPI_CXX_LIBRARY "C:/Program Files/MPICH2/lib/cxx.lib") -################################################################################# -# BOOST ################################################################################# -#SET(BOOST_VERSION "1.47") -#SET(BOOST_USE_MULTITHREAD ON) -#SET(BOOST_USE_STATIC_LIBS ON) -# -#IF(BOOST_VERSION MATCHES "1.47" ) -# SET(BOOST_ROOT "/host/tools/boost/boost_1_47_0") -# SET(BOOST_LIBRARYDIR "/host/tools/boost/boost_1_47_0/stageLinux/lib") -#ENDIF() +# VirtualFluids MACHINE FILE +# Responsible: Soeren Peters +# OS: MacOS X ################################################################################# -# ZOLTAN -################################################################################# -#IF(${USE_ZOLTAN}) -# SET(ZOLTAN_INCLUDEDIR "/home/kostja/tools/Zoltan_v3.5/bin/include") -# SET(ZOLTAN_DEBUG_LIBRARY "/home/kostja/tools/Zoltan_v3.5/bin/lib/libzoltan.a") -# SET(ZOLTAN_RELEASE_LIBRARY "/home/kostja/tools/Zoltan_v3.5/bin/lib/libzoltan.a") -#ENDIF() + ################################################################################# # METIS ################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/usr/local/include") - SET(METIS_DEBUG_LIBRARY "/usr/local/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/usr/local/lib/libmetis.a") -ENDIF() +SET(METIS_INCLUDEDIR "/usr/local/include") +SET(METIS_DEBUG_LIBRARY "/usr/local/lib/libmetis.a") +SET(METIS_RELEASE_LIBRARY "/usr/local/lib/libmetis.a") + diff --git a/CMake/cmake_config_files/BLOGIN.config.cmake b/CMake/cmake_config_files/BLOGIN.config.cmake deleted file mode 100644 index 45102e380198cd9e4e22efba5403d2bb8dea726d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/BLOGIN.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/KONRAD.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/BLOGIN1.config.cmake b/CMake/cmake_config_files/BLOGIN1.config.cmake deleted file mode 100644 index 45102e380198cd9e4e22efba5403d2bb8dea726d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/BLOGIN1.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/KONRAD.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/BLOGIN2.config.cmake b/CMake/cmake_config_files/BLOGIN2.config.cmake deleted file mode 100644 index 45102e380198cd9e4e22efba5403d2bb8dea726d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/BLOGIN2.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/KONRAD.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/BOMBADIL.config.cmake b/CMake/cmake_config_files/BOMBADIL.config.cmake index a1415455f7b8d789e2a9e667e9871c1623013596..7838e2f52b35deae8c114c57968f4b71e0b5b2e4 100644 --- a/CMake/cmake_config_files/BOMBADIL.config.cmake +++ b/CMake/cmake_config_files/BOMBADIL.config.cmake @@ -1,11 +1,9 @@ -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) +################################################################################# +# VirtualFluids MACHINE FILE +# Responsible: Konstantin Kutscher +# OS: Windows 10 +################################################################################# -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - ################################################################################# # MPI ################################################################################# @@ -27,14 +25,6 @@ SET(BOOST_LIBRARYDIR ${BOOST_ROOT}"/stageMSVC64/lib") # VTK ################################################################################# set(VTK_DIR "d:/Tools/VTK/build/VTK-8.0.0") -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "d:/Tools/zoltan/include") - SET(ZOLTAN_DEBUG_LIBRARY "d:/Tools/zoltan/lib/Debug/zoltan.lib") - SET(ZOLTAN_RELEASE_LIBRARY "d:/Tools/zoltan/lib/Release/zoltan.lib") -ENDIF() ################################################################################# # METIS diff --git a/CMake/cmake_config_files/CCSMASTER.config.cmake b/CMake/cmake_config_files/CCSMASTER.config.cmake deleted file mode 100644 index 1a7be411b4754573cd992c363930879df80aae89..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/CCSMASTER.config.cmake +++ /dev/null @@ -1,57 +0,0 @@ -################################################################################# -# COMPILER FLAG VAR -################################################################################# -IF(NOT CAB_COMPILER}) - IF( ${MSVC_VERSION} MATCHES "1400" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1400" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_32" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_32" ) - ELSE() - MESSAGE(ERROR, "unknown ms studio version MSVC_VERSION = "${MSVC_VERSION}) - ENDIF() -ENDIF() - -################################################################################# -# MPI -################################################################################# -IF(CMAKE_CL_64) - SET(MPI_DIR "c:/Program Files/MPICH2") -ELSE() - SET(MPI_DIR "c:/Program Files (x86)/MPICH2") -ENDIF() - -################################################################################# -# BOOST -################################################################################# -IF(NEED_BOOST) - SET(BOOST_USE_MULTITHREAD ON) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.35.0" ) - - SET(BOOST_INCLUDEDIR "Y:/boost_1_35_0") - - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "Y:/boost_1_35_0/lib/x86_64bit") - ELSE() - SET(BOOST_LIBRARYDIR "Y:/boost_1_35_0/lib/x86_32bit") - ENDIF() - - ELSEIF(BOOST_VERSION MATCHES "1.34.1" ) - SET(BOOST_INCLUDEDIR "H:/boost1.34.1") - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "H:/boost1.34.1/stage64/lib") - ELSE() - SET(BOOST_LIBRARYDIR "H:/boost1.34.1/lib") - ENDIF() - ENDIF() - - IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") - ENDIF() -ENDIF() - diff --git a/CMake/cmake_config_files/CCS_ERLANGEN.config.cmake b/CMake/cmake_config_files/CCS_ERLANGEN.config.cmake deleted file mode 100644 index 933862768f6ef130cc367e16486bff36a6cc6d6c..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/CCS_ERLANGEN.config.cmake +++ /dev/null @@ -1,57 +0,0 @@ -################################################################################# -# COMPILER FLAG VAR -################################################################################# -IF(NOT CAB_COMPILER}) - IF( ${MSVC_VERSION} MATCHES "1400" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1400" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_32" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_32" ) - ELSE() - MESSAGE(ERROR, "unknown ms studio version MSVC_VERSION = "${MSVC_VERSION}) - ENDIF() -ENDIF() - -################################################################################# -# MPI -################################################################################# -IF(CMAKE_CL_64) - SET(MPI_DIR "c:/Program Files/MPICH2") -ELSE() - SET(MPI_DIR "c:/Program Files (x86)/MPICH2") -ENDIF() - -################################################################################# -# BOOST -################################################################################# -IF(NEED_BOOST) - SET(BOOST_USE_MULTITHREAD ON) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.35.0" ) - - SET(BOOST_INCLUDEDIR "E:/3rdPartyLibs/boost/boost_1_35") - - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_64bit") - ELSE() - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_32bit") - ENDIF() - - ELSEIF(BOOST_VERSION MATCHES "1.34.1" ) - SET(BOOST_INCLUDEDIR "H:/boost1.34.1") - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "H:/boost1.34.1/stage64/lib") - ELSE() - SET(BOOST_LIBRARYDIR "H:/boost1.34.1//lib") - ENDIF() - ENDIF() - - IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") - ENDIF() -ENDIF() - diff --git a/CMake/cmake_config_files/COAST.config.cmake b/CMake/cmake_config_files/COAST.config.cmake deleted file mode 100644 index 70b61016587b95c4587cd2928fea2e820a62aa19..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/COAST.config.cmake +++ /dev/null @@ -1,63 +0,0 @@ - -#SET(CAB_COMPILER gcc41 CACHE STRING "gcc41" FORCE) -CHECK_FOR_VARIABLE(CAB_COMPILER "gcc41, geller_gcc41") - -################################################################################# -# COMPILER FLAG VAR -################################################################################# -IF(NOT CAB_COMPILER}) - IF(NOT DEFINED CAB_COMPILER) - SET(CAB_COMPILER "CAB_COMPILER-NOTFOUND") - MESSAGE("CHECK_FOR_VARIABLE - error - set CAB_COMPILER") - ENDIF() -ENDIF() - -SET(CPU_TYPE "Opteron") - -#standard boost: 1.37.0 -SET(BOOST_VERSION "1.37.0" CACHE STRING "std: 1.37.0") - -######################################################################################## -## gcc41 ## -######################################################################################## -IF(CAB_COMPILER MATCHES "gcc41") - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -gcc41) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - SET(BOOST_INCLUDEDIR "/home/hegewald/bin/boost/boost_1_37_0") - SET(BOOST_LIBRARYDIR "/home/hegewald/bin/boost/boost_1_37_0/lib") - ENDIF() - - #SET(MPI_DIR "/opt/mpich-gm/gcc-4.1") - - SET_CXX_COMPILER("/usr/bin/g++-4.1") - SET_C_COMPILER("/usr/bin/gcc-4.1") - -ELSEIF(CAB_COMPILER MATCHES "geller_gcc41") - - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -gcc41) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - SET(BOOST_INCLUDEDIR "/home/hegewald/bin/boost/boost_1_37_0") - SET(BOOST_LIBRARYDIR "/home/hegewald/bin/boost/boost_1_37_0/lib") - ENDIF() - - SET(MPI_DIR "/home/geller/bin/mpich2-1.0.8") - - SET_CXX_COMPILER("/usr/bin/g++-4.2") - SET_C_COMPILER("/usr/bin/gcc-4.2") -ENDIF() - - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() - - - diff --git a/CMake/cmake_config_files/CSE01.config.cmake b/CMake/cmake_config_files/CSE01.config.cmake index f68bdf54619860f167fccd1f0a99d8524bfe361e..baa0f94981c2e9f9ac05b62468311f4bead32ff3 100644 --- a/CMake/cmake_config_files/CSE01.config.cmake +++ b/CMake/cmake_config_files/CSE01.config.cmake @@ -1,3 +1,4 @@ +# Alena ################################################################################# # BOOST ################################################################################# diff --git a/CMake/cmake_config_files/DESKTOP-U072UFM.config.cmake b/CMake/cmake_config_files/DESKTOP-U072UFM.config.cmake deleted file mode 100644 index 7fe89b566616d56ac15811092228323b102e4e2a..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/DESKTOP-U072UFM.config.cmake +++ /dev/null @@ -1,14 +0,0 @@ -#Don't change: -SET(METIS_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/metis/metis-5.1.0 CACHE PATH "METIS ROOT") -SET(GMOCK_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/googletest CACHE PATH "GMOCK ROOT") -SET(JSONCPP_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/jsoncpp CACHE PATH "JSONCPP ROOT") -SET(FFTW_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/fftw/fftw-3.3.7 CACHE PATH "JSONCPP ROOT") - - -#SET(BOOST_ROOT "C:/lib/boost_1_65_1" CACHE PATH "BOOST_ROOT") -#SET(BOOST_LIBRARYDIR "C:/lib/boost_1_65_1/stageMSVC64/lib" CACHE PATH "BOOST_LIBRARYDIR") - -SET(BOOST_ROOT "C:/lib/boost_1_71_0" CACHE PATH "BOOST_ROOT") -SET(BOOST_LIBRARYDIR "C:/lib/boost_1_71_0/stageMSVC64/lib" CACHE PATH "BOOST_LIBRARYDIR") - -SET(VTK_DIR "C:/lib/VTK-8.2.0./build" CACHE PATH "VTK directory override" FORCE) diff --git a/CMake/cmake_config_files/ELENDUR.config.cmake b/CMake/cmake_config_files/ELENDUR.config.cmake index 0ec17a47aff4255d69dbe8fd85c40144225f9414..5ef9d62dd8dbd7d352dfa812c05327b652ee83df 100644 --- a/CMake/cmake_config_files/ELENDUR.config.cmake +++ b/CMake/cmake_config_files/ELENDUR.config.cmake @@ -1,3 +1,4 @@ +# Hiwi Rechner Olli ################################################################################# # BOOST ################################################################################# @@ -11,8 +12,7 @@ SET(BOOST_LIBRARYDIR ${BOOST_ROOT}"/stage/lib") ################################################################################# # METIS ################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "c:/Libraries/metis/metis-5.1.0/include") - SET(METIS_DEBUG_LIBRARY "c:/Libraries/metis/metis-5.1.0/MSVC2015/libmetis/Debug/metis.lib") - SET(METIS_RELEASE_LIBRARY "c:/Libraries/metis/metis-5.1.0/MSVC2015/libmetis/Release/metis.lib") -ENDIF() \ No newline at end of file +SET(METIS_INCLUDEDIR "c:/Libraries/metis/metis-5.1.0/include") +SET(METIS_DEBUG_LIBRARY "c:/Libraries/metis/metis-5.1.0/MSVC2015/libmetis/Debug/metis.lib") +SET(METIS_RELEASE_LIBRARY "c:/Libraries/metis/metis-5.1.0/MSVC2015/libmetis/Release/metis.lib") + diff --git a/CMake/cmake_config_files/ELLADAN.config.cmake b/CMake/cmake_config_files/ELLADAN.config.cmake index 7896929276a2969029937ab819b7a59b8132a7c6..80291455e6db49f542b847640ec187620d7eacca 100644 --- a/CMake/cmake_config_files/ELLADAN.config.cmake +++ b/CMake/cmake_config_files/ELLADAN.config.cmake @@ -1,44 +1,14 @@ -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - -################################################################################# -# MPI -################################################################################# -#SET(MPI_DIR "C:/Program Files (x86)/mpich2") -#SET(MPI_DIR "C:/Program Files/mpich2") -#SET(USE_MPI_CXX_SYNTAX OFF) -#SET(MPI_COMPILER "C:/Program Files/mpich2/bin/mpicxx") -#SET(MPI_INCLUDE_PATH "C:/Program Files (x86)/mpich2/include") -#SET(MPI_LIBRARY "C:/Program Files/mpich2/lib/libmpi.a") -#SET(MPI_CXX_LIBRARY "C:/Program Files/MPICH2/lib/cxx.lib") -################################################################################# -# BOOST ################################################################################# -#SET(BOOST_VERSION "1.47") -#SET(BOOST_USE_MULTITHREAD ON) -#SET(BOOST_USE_STATIC_LIBS ON) -# -#IF(BOOST_VERSION MATCHES "1.47" ) -# SET(BOOST_ROOT "/host/tools/boost/boost_1_47_0") -# SET(BOOST_LIBRARYDIR "/host/tools/boost/boost_1_47_0/stageLinux/lib") -#ENDIF() +# VirtualFluids MACHINE FILE +# Responsible: Soeren Peters +# OS: Ubuntu 20.04 ################################################################################# -# ZOLTAN -################################################################################# -#IF(${USE_ZOLTAN}) -# SET(ZOLTAN_INCLUDEDIR "/home/kostja/tools/Zoltan_v3.5/bin/include") -# SET(ZOLTAN_DEBUG_LIBRARY "/home/kostja/tools/Zoltan_v3.5/bin/lib/libzoltan.a") -# SET(ZOLTAN_RELEASE_LIBRARY "/home/kostja/tools/Zoltan_v3.5/bin/lib/libzoltan.a") -#ENDIF() + +set(NVCUDASAMPLES_ROOT "~/cuda-samples/Common") ################################################################################# # METIS ################################################################################# -set (NVCUDASAMPLES_ROOT "~/cuda-samples/Common") - +set(METIS_INCLUDEDIR "/usr/include") +set(METIS_DEBUG_LIBRARY "/usr/lib/x86_64-linux-gnu/libmetis.so") +set(METIS_RELEASE_LIBRARY "/usr/lib/x86_64-linux-gnu/libmetis.so") -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/usr/include") - SET(METIS_DEBUG_LIBRARY "/usr/lib/x86_64-linux-gnu/libmetis.so") - SET(METIS_RELEASE_LIBRARY "/usr/lib/x86_64-linux-gnu/libmetis.so") -ENDIF() diff --git a/CMake/cmake_config_files/ESLOGIN001.config.cmake b/CMake/cmake_config_files/ESLOGIN001.config.cmake deleted file mode 100644 index 210df3d6c98d28535e00a1c0856763a3da25103d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ESLOGIN001.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/HERMIT.config.cmake") diff --git a/CMake/cmake_config_files/ESLOGIN002.config.cmake b/CMake/cmake_config_files/ESLOGIN002.config.cmake deleted file mode 100644 index 210df3d6c98d28535e00a1c0856763a3da25103d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ESLOGIN002.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/HERMIT.config.cmake") diff --git a/CMake/cmake_config_files/ESLOGIN003.config.cmake b/CMake/cmake_config_files/ESLOGIN003.config.cmake deleted file mode 100644 index 210df3d6c98d28535e00a1c0856763a3da25103d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ESLOGIN003.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/HERMIT.config.cmake") diff --git a/CMake/cmake_config_files/ESLOGIN008.config.cmake b/CMake/cmake_config_files/ESLOGIN008.config.cmake deleted file mode 100644 index 210df3d6c98d28535e00a1c0856763a3da25103d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/ESLOGIN008.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/HERMIT.config.cmake") diff --git a/CMake/cmake_config_files/FRWAB.config.cmake b/CMake/cmake_config_files/FRWAB.config.cmake deleted file mode 100644 index 6b93153e5df17a8558e4a6d409c04c1a323a42e8..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/FRWAB.config.cmake +++ /dev/null @@ -1,54 +0,0 @@ -OPTION(CAB_COMPILER_64BIT "64BIT COMPILATION" ON) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost: 1.38.0 -SET(BOOST_VERSION "1.38.0" CACHE STRING "std: 1.38.0") - -######################################################################################## -## gcc41 ## -######################################################################################## -IF(CAB_COMPILER MATCHES "gcc41") - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -gcc41) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.38.0" ) - SET(BOOST_INCLUDEDIR "/nfs/HOME/HLRS/iws/iwsirmb/boost/gcc41/boost_1_38_0/include/boost-1_38") - SET(BOOST_LIBRARYDIR "/nfs/HOME/HLRS/iws/iwsirmb/boost/gcc41/boost_1_38_0/lib") - ENDIF() - - SET(MPI_DIR "/opt/bwgrid/mpi/openmpi/1.3-gnu-4.1") - SET(MPI_CXX_LIBRARY libmpi_cxx.so) - SET(MPI_C_LIBRARY libmpi.so) - -######################################################################################## -## intel10.1 ## -######################################################################################## -ELSEIF(CAB_COMPILER MATCHES "intel10" ) - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -il) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - SET(BOOST_INCLUDEDIR "/nfs/HOME/HLRS/iws/iwsirmb/boost/intel101/boost_1_38_0/include/boost-1_38") - SET(BOOST_LIBRARYDIR "/nfs/HOME/HLRS/iws/iwsirmb/boost/intel101/boost_1_38_0/lib") - ENDIF() - - #SET(MPI_DIR "/opt/mpich/intel-10.1") - SET(MPI_DIR "/opt/bwgrid/mpi/openmpi/1.3-intel-10.1") - - SET_CXX_COMPILER("/opt/intel/vve/10.1.018/bin/icpc") - SET_C_COMPILER("/opt/intel/vve/10.1.018/bin/icc") -ENDIF() - - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() - - - diff --git a/CMake/cmake_config_files/FRY29.config.cmake b/CMake/cmake_config_files/FRY29.config.cmake deleted file mode 100644 index 27b63654bb7eba4e8909c9dbaa416419e7f018f4..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/FRY29.config.cmake +++ /dev/null @@ -1,29 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -SET(BOOST_VERSION "1.60.0" CACHE STRING "std: 1.60.0") - - -SET(USE_MPI_CXX_SYNTAX OFF) -SET(BOOST_INCLUDEDIR "/home/irmb/kutscher/boost_1_60_0/boost") -SET(BOOST_LIBRARYDIR "/home/irmb/kutscher/boost_1_60_0/stage/lib") -SET(Boost_INCLUDE_DIR "/home/irmb/kutscher/boost_1_60_0") - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/home/irmb/kutscher/metis-5.1.0/include") - SET(METIS_DEBUG_LIBRARY "/home/irmb/kutscher/metis-5.1.0/build/Linux-x86_64/libmetis/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/home/irmb/kutscher/metis-5.1.0/build/Linux-x86_64/libmetis/libmetis.a") -ENDIF() - - - diff --git a/CMake/cmake_config_files/GAMLING.config.cmake b/CMake/cmake_config_files/GAMLING.config.cmake deleted file mode 100644 index b3a52ae0fcdccd83ab688a5ca5757899f793f39d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/GAMLING.config.cmake +++ /dev/null @@ -1,10 +0,0 @@ -#Don't change: -SET(METIS_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/metis/metis-5.1.0 CACHE PATH "METIS ROOT") -SET(GMOCK_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/googletest CACHE PATH "GMOCK ROOT") -SET(JSONCPP_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/jsoncpp CACHE PATH "JSONCPP ROOT") -SET(FFTW_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/fftw/fftw-3.3.7 CACHE PATH "JSONCPP ROOT") - - -#SET TO CORRECT PATH: -SET(BOOST_ROOT "C:\\lib\\boost_1_65_1" CACHE PATH "BOOST_ROOT") -SET(BOOST_LIBRARYDIR "C:\\lib\\boost_1_65_1\\stageMSVC64\\lib" CACHE PATH "BOOST_LIBRARYDIR") diff --git a/CMake/cmake_config_files/GENIUS1.config.cmake b/CMake/cmake_config_files/GENIUS1.config.cmake deleted file mode 100644 index 675a542085e90458b700c59a0b7ed95c1e9e2144..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/GENIUS1.config.cmake +++ /dev/null @@ -1,33 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - -################################################################################# -# MPI -################################################################################# -SET(USE_MPI_CXX_SYNTAX OFF) - -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.44") -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.44" ) - SET(BOOST_INCLUDEDIR "/u/lrz102bk/soft/boost_1_44_0/build/include") - SET(BOOST_LIBRARYDIR "/u/lrz102bk/soft/boost_1_44_0/build/lib") -ENDIF() - -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "/u/lrz102bk/BlueGene/soft/Zoltan_v3.1/bin/include") - SET(ZOLTAN_DEBUG_LIBRARY "/u/lrz102bk/BlueGene/soft/Zoltan_v3.1/bin/lib/libzoltan.a") - SET(ZOLTAN_RELEASE_LIBRARY "/u/lrz102bk/BlueGene/soft/Zoltan_v3.1/bin/lib/libzoltan.a") -ENDIF() - -set(SOURCE_ROOT "/u/lrz102bk/BlueGene/projects/pFluid/source") - - diff --git a/CMake/cmake_config_files/GIMLI.config.cmake b/CMake/cmake_config_files/GIMLI.config.cmake deleted file mode 100644 index 753957d6d8583f5e114b9cfb78e8cde89f1b2f57..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/GIMLI.config.cmake +++ /dev/null @@ -1,63 +0,0 @@ -################################################################################# -# COMPILER FLAG VAR -################################################################################# -IF(NOT CAB_COMPILER}) - IF( ${MSVC_VERSION} MATCHES "1400" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1400" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_32" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_32" ) - ELSE() - MESSAGE(ERROR, "unknown ms studio version MSVC_VERSION = "${MSVC_VERSION}) - ENDIF() -ENDIF() - -################################################################################# -# MPI -################################################################################# -IF(CMAKE_CL_64) - SET(MPI_DIR "c:/Program Files/MPICH2") -ELSE() - SET(MPI_DIR "c:/Program Files (x86)/MPICH2") -ENDIF() - -################################################################################# -# BOOST -################################################################################# -IF(NEED_BOOST) - SET(BOOST_USE_MULTITHREAD ON) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.35.0.svn" ) - - SET(BOOST_INCLUDEDIR "E:/3rdPartyLibs/boost/boost_1_35") - - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_64bit") - ELSE() - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_32bit") - ENDIF() - - ELSEIF(BOOST_VERSION MATCHES "1.35.0" ) - - SET(BOOST_INCLUDEDIR "E:/3rdPartyLibs/boost/boost_1_35_0") - - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35_0/lib/x86_64bit") - ELSE() - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35_0/lib/x86_32bit") - ENDIF() - - ELSEIF(BOOST_VERSION MATCHES "1.34.1" ) - SET(BOOST_INCLUDEDIR "C:/Program Files (x86)/boost/boost_1_34_1") - SET(BOOST_LIBRARYDIR "C:/Program Files (x86)/boost/boost_1_34_1/lib") - ENDIF() - - IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") - ENDIF() -ENDIF() - diff --git a/CMake/cmake_config_files/GLOGIN1.config.cmake b/CMake/cmake_config_files/GLOGIN1.config.cmake deleted file mode 100644 index 31c781a0a2e8d555e2ef1b2a5c7e6085fd0f23e7..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/GLOGIN1.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/HLRNG.config.cmake") diff --git a/CMake/cmake_config_files/GOTTFRIED.config.cmake b/CMake/cmake_config_files/GOTTFRIED.config.cmake deleted file mode 100644 index 2144d13c18a6a6dfa2e466d09224549381404d8c..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/GOTTFRIED.config.cmake +++ /dev/null @@ -1,55 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost -SET(BOOST_VERSION "1.54.0" CACHE STRING "std: 1.54.0") - -#SET(USE_MPI_CXX_SYNTAX OFF) - -#IF(CAB_COMPILER MATCHES "gcc41") -# SET(BOOST_USE_MULTITHREAD ON) - - #SET(BOOST_COMPILER_SUFFIX -gcc41) -# SET(BOOST_USE_STATIC_LIBS ON) - -# IF(BOOST_VERSION MATCHES "1.54.0" ) -# SET(BOOST_INCLUDEDIR "/gfs1/work/niivfcpu/tools/boost_1_54_0") -# SET(BOOST_LIBRARYDIR "/gfs1/work/niivfcpu/tools/boost_1_54_0/stageGCC/lib") -# ENDIF() -#ENDIF() - -#IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) -# MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -#ENDIF() - - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/gfs1/work/niikonst/libs/metis/include") - SET(METIS_DEBUG_LIBRARY "/gfs1/work/niikonst/libs/metis/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/gfs1/work/niikonst/libs/metis/lib/libmetis.a") -ENDIF() - -# ################################################################################# -# # YAML -# ################################################################################# -# IF(${USE_YAML}) -# SET(YAML_INCLUDEDIR "/hpc3lustre/software/irmb/yaml/yaml-cpp/include") -# SET(YAML_DEBUG_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") -# SET(YAML_RELEASE_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") -# ENDIF() -# -# ################################################################################## -# # Bond -# ################################################################################## -# IF(${USE_BOND}) -# SET(BOND_INCLUDEDIR "/hpc3lustre/home/koskuche/projects/bond/bond_src/cpp/bond/fetol") -# SET(BOND_DEBUG_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") -# SET(BOND_RELEASE_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") -# ENDIF() - diff --git a/CMake/cmake_config_files/HELM.config.cmake b/CMake/cmake_config_files/HELM.config.cmake deleted file mode 100644 index 341d045f60e0a505f9abbc8b6c3e6b780af0762e..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HELM.config.cmake +++ /dev/null @@ -1,54 +0,0 @@ -################################################################################# -# COMPILER FLAG VAR -################################################################################# - -SET(CAB_COMPILER "gcc41" CACHE STRING "gcc41, gcc43, intel9" FORCE) -# on MacOS X __APPLE__ is defined but not __unix__ -add_definitions(-D__unix__) -SET(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING "ppc;i386;ppc64;x86_64" FORCE) - -#ADD_CXX_FLAGS(-arch x86_64 -L/usr/local/lib/x86_64)# -Wall -ansi) -#ADD_CXX_BUILDTYPE_FLAGS(DEBUG -DDEBUG -D_DEBUG -gdwarf-2 -arch x86_64 -L/usr/local/lib/x86_64 -Wall -ansi) -#ADD_CXX_BUILDTYPE_FLAGS(RELEASE -O3 -DNDEBUG -fomit-frame-pointer -finline-functions -funroll-all-loops -arch x86_64 -L/usr/local/lib/x86_64 -Wall -ansi) -ADD_CXX_BUILDTYPE_FLAGS(DEBUG -DDEBUG -D_DEBUG -gdwarf-2 -Wall -ansi) -ADD_CXX_BUILDTYPE_FLAGS(RELEASE -O3 -DNDEBUG -fomit-frame-pointer -finline-functions -funroll-all-loops -Wall -ansi) - -#ADD_C_FLAGS(-arch x86_64 -L/usr/local/lib/x86_64)# -Wall -ansi) - - -SET(BOOST_VERSION "1.47.0") -#IF(CAB_COMPILER MATCHES "gcc41") -# SET(BOOST_USE_MULTITHREAD ON) -# SET(BOOST_USE_STATIC_LIBS ON) -# -# SET(BOOST_COMPILER_SUFFIX -xgcc40) -# -# IF(BOOST_VERSION MATCHES "1.37.0" ) -# SET(BOOST_INCLUDEDIR "/Users/hg/bin/boost/boost_1_37_0") -# SET(BOOST_LIBRARYDIR "/Users/hg/bin/boost/boost_1_37_0/lib") -# ENDIF() -## IF(BOOST_VERSION MATCHES "1.37.0" ) -## SET(BOOST_INCLUDEDIR "/opt/local/include") -## SET(BOOST_LIBRARYDIR "/opt/local/lib") -## ENDIF() -#ENDIF() -#IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) -# MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -#ENDIF() - -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.47.0" ) - SET(BOOST_INCLUDEDIR "/Users/hg/bin/boost/boost_1_47_0_bin/include") - SET(BOOST_LIBRARYDIR "/Users/hg/bin/boost/boost_1_47_0_bin/lib") -ENDIF() -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "/Users/hg/bin/zoltan_distrib_v3.501_bin/include") - SET(ZOLTAN_DEBUG_LIBRARY "/Users/hg/bin/zoltan_distrib_v3.501_bin/lib/libzoltan.a") - SET(ZOLTAN_RELEASE_LIBRARY "/Users/hg/bin/zoltan_distrib_v3.501_bin/lib/libzoltan.a") -ENDIF() -set(SOURCE_ROOT "/Users/hg/hg+/Konstantin_Kucher/Patchcode/src") \ No newline at end of file diff --git a/CMake/cmake_config_files/HERMIT.config.cmake b/CMake/cmake_config_files/HERMIT.config.cmake deleted file mode 100644 index 559bbb6deab44320693ac527a35e215b935e2743..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HERMIT.config.cmake +++ /dev/null @@ -1,28 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## - -SET(BOOST_VERSION "1.54.0" CACHE STRING "std: 1.54.0") - -# IF(BOOST_VERSION MATCHES "1.51.0" ) -# SET(BOOST_INCLUDEDIR "/zhome/academic/HLRS/xrm/xrmkuchr/tools/boost_1_51_0") -# SET(BOOST_LIBRARYDIR "/zhome/academic/HLRS/xrm/xrmkuchr/tools/boost_1_51_0/stageGCC/lib") -# -# ENDIF() -# -# IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) -# MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -# ENDIF() - - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/zhome/academic/HLRS/xrm/xrmkuchr/tools/metis-5.0.2/include") - SET(METIS_DEBUG_LIBRARY "/zhome/academic/HLRS/xrm/xrmkuchr/tools/metis-5.0.2/build/Linux-x86_64/libmetis/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/zhome/academic/HLRS/xrm/xrmkuchr/tools/metis-5.0.2/build/Linux-x86_64/libmetis/libmetis.a") -ENDIF() diff --git a/CMake/cmake_config_files/HICEGATE0.config.cmake b/CMake/cmake_config_files/HICEGATE0.config.cmake deleted file mode 100644 index efee9adbee829914f678e284a5473f5917866f88..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HICEGATE0.config.cmake +++ /dev/null @@ -1,63 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost -SET(BOOST_VERSION "1.54.0" CACHE STRING "std: 1.54.0") - -SET(USE_MPI_CXX_SYNTAX OFF) - -#IF(CAB_COMPILER MATCHES "gcc41") -# SET(BOOST_USE_MULTITHREAD ON) - - #SET(BOOST_COMPILER_SUFFIX -gcc41) -# SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.54.0" ) - SET(BOOST_INCLUDEDIR "/gfs1/work/niivfcpu/tools/boost_1_54_0") - SET(BOOST_LIBRARYDIR "/gfs1/work/niivfcpu/tools/boost_1_54_0/stageGCC/lib") - ENDIF() -#ENDIF() - -#IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) -# MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -#ENDIF() - -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Source/packages/zoltan/src/include") - SET(ZOLTAN_DEBUG_LIBRARY "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Build/packages/zoltan/src/libzoltan.a") - SET(ZOLTAN_RELEASE_LIBRARY "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Build/packages/zoltan/src/libzoltan.a") -ENDIF() - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/gfs1/work/niivfcpu/tools/metis/include") - SET(METIS_DEBUG_LIBRARY "/gfs1/work/niivfcpu/tools/metis/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/gfs1/work/niivfcpu/tools/metis/lib/libmetis.a") -ENDIF() - -################################################################################# -# YAML -################################################################################# -IF(${USE_YAML}) - SET(YAML_INCLUDEDIR "/gfs1/work/niivfcpu/tools/yaml-cpp/include") - SET(YAML_DEBUG_LIBRARY "/gfs1/work/niivfcpu/tools/yaml-cpp/build/libyaml-cpp.a") - SET(YAML_RELEASE_LIBRARY "/gfs1/work/niivfcpu/tools/yaml-cpp/build/libyaml-cpp.a") -ENDIF() - -################################################################################## -# Bond -################################################################################## -IF(${USE_BOND}) - SET(BOND_INCLUDEDIR "/gfs1/work/niivfcpu/tools/bond/bond_src/cpp/bond/fetol") - SET(BOND_DEBUG_LIBRARY "/gfs1/work/niivfcpu/tools/bond/bin/lib/libbond.a") - SET(BOND_RELEASE_LIBRARY "/gfs1/work/niivfcpu/tools/bond/bin/lib/libbond.a") -ENDIF() - diff --git a/CMake/cmake_config_files/HLOGIN.config.cmake b/CMake/cmake_config_files/HLOGIN.config.cmake deleted file mode 100644 index a88e4fa4cd56dcd3f74835e9bfe00a402eb21530..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HLOGIN.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/GOTTFRIED.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/HLOGIN1.config.cmake b/CMake/cmake_config_files/HLOGIN1.config.cmake deleted file mode 100644 index a88e4fa4cd56dcd3f74835e9bfe00a402eb21530..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HLOGIN1.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/GOTTFRIED.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/HLOGIN2.config.cmake b/CMake/cmake_config_files/HLOGIN2.config.cmake deleted file mode 100644 index a88e4fa4cd56dcd3f74835e9bfe00a402eb21530..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HLOGIN2.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/GOTTFRIED.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/HLOGIN3.config.cmake b/CMake/cmake_config_files/HLOGIN3.config.cmake deleted file mode 100644 index a88e4fa4cd56dcd3f74835e9bfe00a402eb21530..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HLOGIN3.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/GOTTFRIED.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/HLOGIN4.config.cmake b/CMake/cmake_config_files/HLOGIN4.config.cmake deleted file mode 100644 index a88e4fa4cd56dcd3f74835e9bfe00a402eb21530..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HLOGIN4.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/GOTTFRIED.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/HLRNG.config.cmake b/CMake/cmake_config_files/HLRNG.config.cmake deleted file mode 100644 index faa8bde39c0e49e5108b403ff34a31afcefcbdd9..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/HLRNG.config.cmake +++ /dev/null @@ -1,13 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/home/niikonst/libs/metis-5.1.0/include") - SET(METIS_DEBUG_LIBRARY "/home/niikonst/libs/metis-5.1.0/build/Linux-x86_64/libmetis/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/home/niikonst/libs/metis-5.1.0/build/Linux-x86_64/libmetis/libmetis.a") -ENDIF() - - diff --git a/CMake/cmake_config_files/HOST2.config.cmake b/CMake/cmake_config_files/HOST2.config.cmake index defe7bf92ad2089e4fa8f080a90514110cbdf83f..caba4aed96df0145ca919a760ed38a401193b8fe 100644 --- a/CMake/cmake_config_files/HOST2.config.cmake +++ b/CMake/cmake_config_files/HOST2.config.cmake @@ -1,21 +1,9 @@ -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - ################################################################################# -# MPI +# VirtualFluids MACHINE FILE +# Responsible: Konstantin Kutscher +# OS: ??? ################################################################################# -#SET(MPI_DIR "C:/Program Files (x86)/mpich2") -#SET(MPI_DIR "C:/Program Files/mpich2") -#SET(USE_MPI_CXX_SYNTAX OFF) -#SET(MPI_COMPILER "C:/Program Files/mpich2/bin/mpicxx") -#SET(MPI_INCLUDE_PATH "C:/Program Files (x86)/mpich2/include") -#SET(MPI_LIBRARY "C:/Program Files/mpich2/lib/libmpi.a") -#SET(MPI_CXX_LIBRARY "C:/Program Files/MPICH2/lib/cxx.lib") + ################################################################################# # BOOST ################################################################################# @@ -23,24 +11,12 @@ SET(BOOST_VERSION "1.47") SET(BOOST_USE_MULTITHREAD ON) SET(BOOST_USE_STATIC_LIBS ON) -#IF(BOOST_VERSION MATCHES "1.47" ) - SET(BOOST_ROOT "/host/tools/boost/boost_1_47_0") - SET(BOOST_LIBRARYDIR "/host/tools/boost/boost_1_47_0/stageLinux/lib") -#ENDIF() -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "c:/Tools/zoltan/include") - SET(ZOLTAN_DEBUG_LIBRARY "c:/Tools/zoltan/lib/Debug/zoltan.lib") - SET(ZOLTAN_RELEASE_LIBRARY "c:/Tools/zoltan/lib/Release/zoltan.lib") -ENDIF() +SET(BOOST_ROOT "/host/tools/boost/boost_1_47_0") +SET(BOOST_LIBRARYDIR "/host/tools/boost/boost_1_47_0/stageLinux/lib") + ################################################################################# # METIS ################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "c:/Tools/metis-5.0.1/include") - SET(METIS_DEBUG_LIBRARY "c:/Tools/metis-5.0.1/build/libmetis/Debug/metis.lib") - SET(METIS_RELEASE_LIBRARY "c:/Tools/metis-5.0.1/build/libmetis/Release/metis.lib") -ENDIF() -set(SOURCE_ROOT "/host/Projects/pFluid/source") \ No newline at end of file +SET(METIS_INCLUDEDIR "c:/Tools/metis-5.0.1/include") +SET(METIS_DEBUG_LIBRARY "c:/Tools/metis-5.0.1/build/libmetis/Debug/metis.lib") +SET(METIS_RELEASE_LIBRARY "c:/Tools/metis-5.0.1/build/libmetis/Release/metis.lib") diff --git a/CMake/cmake_config_files/KONRAD.config.cmake b/CMake/cmake_config_files/KONRAD.config.cmake deleted file mode 100644 index 2144d13c18a6a6dfa2e466d09224549381404d8c..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/KONRAD.config.cmake +++ /dev/null @@ -1,55 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost -SET(BOOST_VERSION "1.54.0" CACHE STRING "std: 1.54.0") - -#SET(USE_MPI_CXX_SYNTAX OFF) - -#IF(CAB_COMPILER MATCHES "gcc41") -# SET(BOOST_USE_MULTITHREAD ON) - - #SET(BOOST_COMPILER_SUFFIX -gcc41) -# SET(BOOST_USE_STATIC_LIBS ON) - -# IF(BOOST_VERSION MATCHES "1.54.0" ) -# SET(BOOST_INCLUDEDIR "/gfs1/work/niivfcpu/tools/boost_1_54_0") -# SET(BOOST_LIBRARYDIR "/gfs1/work/niivfcpu/tools/boost_1_54_0/stageGCC/lib") -# ENDIF() -#ENDIF() - -#IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) -# MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -#ENDIF() - - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/gfs1/work/niikonst/libs/metis/include") - SET(METIS_DEBUG_LIBRARY "/gfs1/work/niikonst/libs/metis/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/gfs1/work/niikonst/libs/metis/lib/libmetis.a") -ENDIF() - -# ################################################################################# -# # YAML -# ################################################################################# -# IF(${USE_YAML}) -# SET(YAML_INCLUDEDIR "/hpc3lustre/software/irmb/yaml/yaml-cpp/include") -# SET(YAML_DEBUG_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") -# SET(YAML_RELEASE_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") -# ENDIF() -# -# ################################################################################## -# # Bond -# ################################################################################## -# IF(${USE_BOND}) -# SET(BOND_INCLUDEDIR "/hpc3lustre/home/koskuche/projects/bond/bond_src/cpp/bond/fetol") -# SET(BOND_DEBUG_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") -# SET(BOND_RELEASE_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") -# ENDIF() - diff --git a/CMake/cmake_config_files/KUBUNTU64.config.cmake b/CMake/cmake_config_files/KUBUNTU64.config.cmake deleted file mode 100644 index 4d7a3091c40f90de1484a1cbc875956de5587526..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/KUBUNTU64.config.cmake +++ /dev/null @@ -1,28 +0,0 @@ -################################################################################# -# COMPILER FLAG VAR -################################################################################# -SET(CAB_COMPILER "gcc43" FORCE) -SET(BOOST_VERSION "1.37.0") - -################################################################################# -# BOOST AND MPI -################################################################################# -IF(CAB_COMPILER MATCHES "gcc43") - IF(NEED_BOOST) - SET(BOOST_USE_MULTITHREAD ON) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - - SET(USER_DEFINED_BOOST_COMPILER -gcc43) - SET(BOOST_INCLUDEDIR "/opt/boost_1_37_0/gcc4.3.1/include/boost-1_37") - SET(BOOST_LIBRARYDIR "/opt/boost_1_37_0/gcc4.3.1/lib") - SET(BOOST_COMPILER_SUFFIX -gcc43) - - ENDIF() - ENDIF() -ENDIF() - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() diff --git a/CMake/cmake_config_files/LOGIN07.config.cmake b/CMake/cmake_config_files/LOGIN07.config.cmake deleted file mode 100644 index e19a785b2c96964fb9dc02e7ef6e84b37985be4b..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/LOGIN07.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/SUPERMUC.config.cmake") diff --git a/CMake/cmake_config_files/LOGIN22.config.cmake b/CMake/cmake_config_files/LOGIN22.config.cmake deleted file mode 100644 index e19a785b2c96964fb9dc02e7ef6e84b37985be4b..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/LOGIN22.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/SUPERMUC.config.cmake") diff --git a/CMake/cmake_config_files/LRR_OPTERON.config.cmake b/CMake/cmake_config_files/LRR_OPTERON.config.cmake deleted file mode 100644 index dce597c90d151a4f8a08a35ed28fb7b736fe89a5..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/LRR_OPTERON.config.cmake +++ /dev/null @@ -1,41 +0,0 @@ -OPTION(CAB_COMPILER_64BIT "64BIT COMPILATION" ON) - -IF(NOT CAB_COMPILER}) - SET(BOOST_VERSION "1.37.0") -ENDIF() - -IF(NOT CAB_COMPILER}) - SET(CAB_COMPILER "intel10") -ENDIF() - -SET(CAB_COMPILER ${CAB_COMPILER} CACHE STRING "intel10" FORCE) -SET(CPU_TYPE "Opteron") - -################################################################################# -# BOOST AND MPI -################################################################################# -IF(CAB_COMPILER MATCHES "intel10" ) -######################################################################################## -## intel10 ## -######################################################################################## - SET(BOOST_USE_MULTITHREAD ON) - - IF(BOOST_VERSION MATCHES "1.37.0" ) - - SET(BOOST_USE_STATIC_LIBS ON) - - SET(BOOST_INCLUDEDIR "/home/freudigx/sw/boost/intel/boost_1_37_0") - SET(BOOST_LIBRARYDIR "/home/freudigx/sw/boost/intel/boost_1_37_0/lib") - - SET( BOOST_COMPILER_SUFFIX "-il" ) - ENDIF() - - SET(MPI_DIR "/sw/mpi/mvapich-1.0-intel101") - - SET_CXX_COMPILER("icpc") - SET_C_COMPILER("icc") -ENDIF() - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on "${CAB_MACHINE}" for specified compiler") -ENDIF() diff --git a/CMake/cmake_config_files/LUDWIG.config.cmake b/CMake/cmake_config_files/LUDWIG.config.cmake deleted file mode 100644 index c25c581297138278bb789fc4bc1d5533116f98df..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/LUDWIG.config.cmake +++ /dev/null @@ -1,66 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost: 1.50.0 -SET(BOOST_VERSION "1.54.0" CACHE STRING "std: 1.54.0") - -#SET(MPI_DIR "/hpc3lustre/software/lib/openmpi-1.4.1-gcc41") - -SET(USE_MPI_CXX_SYNTAX OFF) -#SET(MPI_COMPILER "/hpc3lustre/software/lib/openmpi-1.4.1-gcc41/bin/mpicxx") - -#IF(CAB_COMPILER MATCHES "gcc41") - #SET(BOOST_USE_MULTITHREAD ON) - - #SET(BOOST_COMPILER_SUFFIX -gcc41) - #SET(BOOST_USE_STATIC_LIBS ON) - - #IF(BOOST_VERSION MATCHES "1.54.0" ) - SET(BOOST_INCLUDEDIR "/hpc3lustre/software/irmb/boost/boost_1_54_0") - SET(BOOST_LIBRARYDIR "/hpc3lustre/software/irmb/boost/boost_1_54_0/stageINTEL/lib") - #ENDIF() -#ENDIF() - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() - -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Source/packages/zoltan/src/include") - SET(ZOLTAN_DEBUG_LIBRARY "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Build/packages/zoltan/src/libzoltan.a") - SET(ZOLTAN_RELEASE_LIBRARY "/hpc3lustre/software/irmb/Trilinos/trilinos-10.6.4-Build/packages/zoltan/src/libzoltan.a") -ENDIF() - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/hpc3lustre/software/irmb/metis/include") - SET(METIS_DEBUG_LIBRARY "/hpc3lustre/software/irmb/metis/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/hpc3lustre/software/irmb/metis/lib/libmetis.a") -ENDIF() - -################################################################################# -# YAML -################################################################################# -IF(${USE_YAML}) - SET(YAML_INCLUDEDIR "/hpc3lustre/software/irmb/yaml/yaml-cpp/include") - SET(YAML_DEBUG_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") - SET(YAML_RELEASE_LIBRARY "/hpc3lustre/software/irmb/yaml/yaml-cpp/build/libyaml-cpp.a") -ENDIF() - -################################################################################## -# Bond -################################################################################## -IF(${USE_BOND}) - SET(BOND_INCLUDEDIR "/hpc3lustre/home/koskuche/projects/bond/bond_src/cpp/bond/fetol") - SET(BOND_DEBUG_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") - SET(BOND_RELEASE_LIBRARY "/hpc3lustre/home/koskuche/projects/bond/bin/lib/libbond.a") -ENDIF() - diff --git a/CMake/cmake_config_files/M01.config.cmake b/CMake/cmake_config_files/M01.config.cmake deleted file mode 100644 index 3553a2a9282a752c3ed96c644aa8003e90fb0b36..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/M01.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/LUDWIG.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/M02.config.cmake b/CMake/cmake_config_files/M02.config.cmake deleted file mode 100644 index 3553a2a9282a752c3ed96c644aa8003e90fb0b36..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/M02.config.cmake +++ /dev/null @@ -1 +0,0 @@ -INCLUDE("CMake/cmake_config_files/LUDWIG.config.cmake") \ No newline at end of file diff --git a/CMake/cmake_config_files/MAFALDA.config.cmake b/CMake/cmake_config_files/MAFALDA.config.cmake deleted file mode 100644 index cfc0d659a30f82d79e54df76637050e35a10b87d..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/MAFALDA.config.cmake +++ /dev/null @@ -1,68 +0,0 @@ -################################################################################# -# COMPILER FLAG VAR -################################################################################# -IF(NOT CAB_COMPILER}) - IF( ${MSVC_VERSION} MATCHES "1400" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1400" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc8_32" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_64" ) - ELSEIF( ${MSVC_VERSION} MATCHES "1500" AND NOT CMAKE_CL_64) - SET( CAB_COMPILER "msvc9_32" ) - ELSE() - MESSAGE(ERROR, "unknown ms studio version MSVC_VERSION = "${MSVC_VERSION}) - ENDIF() -ENDIF() - -################################################################################# -# MPI -################################################################################# -IF(CMAKE_CL_64) - SET(MPI_DIR "c:/Program Files/MPICH2") -ELSE() - SET(MPI_DIR "c:/Program Files (x86)/MPICH2") -ENDIF() - -################################################################################# -# BOOST -################################################################################# -IF(NEED_BOOST) - SET(BOOST_USE_MULTITHREAD ON) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.35.0.svn" ) - - SET(BOOST_INCLUDEDIR "E:/3rdPartyLibs/boost/boost_1_35") - - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_64bit") - ELSE() - SET(BOOST_LIBRARYDIR "E:/3rdPartyLibs/boost/boost_1_35/lib/x86_32bit") - ENDIF() - - ELSEIF(BOOST_VERSION MATCHES "1.35.0" ) - - SET(BOOST_INCLUDEDIR "D:/code/3rdParty/PhysicsEngine/boost") - - IF(CMAKE_CL_64) - SET(BOOST_LIBRARYDIR "D:/code/3rdParty/PhysicsEngine/boost") - ELSE() - SET(BOOST_LIBRARYDIR "D:/code/3rdParty/PhysicsEngine/boost") - ENDIF() - - ELSEIF(BOOST_VERSION MATCHES "1.34.1" ) - SET(BOOST_INCLUDEDIR "D:/code/boost_1_34_1") - SET(BOOST_LIBRARYDIR "D:/code/boost_1_34_1") - - ELSEIF(BOOST_VERSION MATCHES "1.36.0" ) - SET(BOOST_INCLUDEDIR "D:/code/boost_1_36_0") - SET(BOOST_LIBRARYDIR "D:/code/boost_1_36_0") - - ENDIF() - - IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") - ENDIF() -ENDIF() - diff --git a/CMake/cmake_config_files/PHOENIX.config.cmake b/CMake/cmake_config_files/PHOENIX.config.cmake index 48bb20259a7bc6c1fdd93531131cb25c403a3164..1d69df88bc174c206fb3639b7d67e703dd41d5eb 100644 --- a/CMake/cmake_config_files/PHOENIX.config.cmake +++ b/CMake/cmake_config_files/PHOENIX.config.cmake @@ -1,16 +1,18 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) +################################################################################# +# VirtualFluids MACHINE FILE +# Responsible: Konstantin Kutscher +# OS: CentOS 7.3 +################################################################################# SET(BOOST_VERSION "1.63.0" CACHE STRING "std: 1.63.0") ################################################################################# # METIS ################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/cluster/lib/metis/5.1.0/gcc/include") - SET(METIS_DEBUG_LIBRARY "/cluster/lib/metis/5.1.0/gcc/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/cluster/lib/metis/5.1.0/gcc/lib/libmetis.a") -ENDIF() +SET(METIS_INCLUDEDIR "/cluster/lib/metis/5.1.0/gcc/include") +SET(METIS_DEBUG_LIBRARY "/cluster/lib/metis/5.1.0/gcc/lib/libmetis.a") +SET(METIS_RELEASE_LIBRARY "/cluster/lib/metis/5.1.0/gcc/lib/libmetis.a") + ################################################################################# # PE @@ -33,11 +35,6 @@ IF(${USE_DEM_COUPLING}) ENDIF() -SET(METIS_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/metis/metis-5.1.0 CACHE PATH "METIS ROOT") -SET(GMOCK_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/googletest CACHE PATH "GMOCK ROOT") -SET(JSONCPP_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/jsoncpp CACHE PATH "JSONCPP ROOT") -SET(FFTW_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/fftw/fftw-3.3.7 CACHE PATH "JSONCPP ROOT") - SET(BOOST_ROOT "/cluster/lib/boost/1.63.0/gcc" CACHE PATH "BOOST_ROOT") SET(BOOST_LIBRARYDIR "/cluster/lib/boost/1.63.0/gcc/lib" CACHE PATH "BOOST_LIBRARYDIR") @@ -46,6 +43,4 @@ SET(BOOST_LIBRARYDIR "/cluster/lib/boost/1.63.0/gcc/lib" CACHE PATH "BOOST_LIB #SET(VTK_DIR "/home/irmb/tools/VTK/build/VTK-8.2.0" CACHE PATH "VTK directory override" FORCE) #SET(VTK_DIR "/home/stelenz/software/vtk/VTK-8.1.0/build" CACHE PATH "VTK directory override" FORCE) -SET(CUDA_CUT_INCLUDE_DIR "/cluster/cuda/9.0/include;/cluster/cuda/9.0/samples/common/inc" CACHE PATH "CUDA_CUT_INCLUDE_DIR") - -SET(CUDA_SAMPLE_INCLUDE_DIR "/cluster/cuda/9.0/samples/common/inc" CACHE PATH "CUDA_CUT_INCLUDE_DIR") +set(NVCUDASAMPLES_ROOT "/cluster/cuda/11.0/samples") diff --git a/CMake/cmake_config_files/PIPPIN.config.cmake b/CMake/cmake_config_files/PIPPIN.config.cmake deleted file mode 100644 index 8c548b2f1c8bfdf816894cbc4b6b48fa2fa05034..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/PIPPIN.config.cmake +++ /dev/null @@ -1,25 +0,0 @@ -################################################################################# -# MPI -################################################################################# -IF(CMAKE_CL_64) - IF(NEED_MPI) - MESSAGE(FATAL_ERROR "kein 64 bit mpi installiert") - ENDIF() - #SET(MPI_DIR "c:/Program Files/MPICH2") -ELSE() - SET(MPI_DIR "c:/Program Files (x86)/MPICH2") -ENDIF() - -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION 1.38.0) -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(CMAKE_CL_64) - MESSAGE(FATAL_ERROR "kein 64 bit boost ${BOOST_VERSION} installiert") -ELSE() - SET(BOOST_INCLUDEDIR "C:/Program Files (x86)/boost/boost_1_38") - SET(BOOST_LIBRARYDIR "C:/Program Files (x86)/boost/boost_1_38/lib") -ENDIF() diff --git a/CMake/cmake_config_files/SAMWEIS.config.cmake b/CMake/cmake_config_files/SAMWEIS.config.cmake index 68fa413d8d85dc14687fa5e8b7d11f4e3c13c0ea..5b08c08610c37e1a38947d8842ca744622ffa524 100644 --- a/CMake/cmake_config_files/SAMWEIS.config.cmake +++ b/CMake/cmake_config_files/SAMWEIS.config.cmake @@ -1,21 +1,9 @@ -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - ################################################################################# -# MPI +# VirtualFluids MACHINE FILE +# Responsible: Lennard Lux +# OS: Windows 10 ################################################################################# -#SET(MPI_DIR "C:/Program Files (x86)/mpich2") -#SET(MPI_DIR "C:/Program Files/mpich2") -#SET(USE_MPI_CXX_SYNTAX OFF) -#SET(MPI_COMPILER "C:/Program Files/mpich2/bin/mpicxx") -#SET(MPI_INCLUDE_PATH "C:/Program Files (x86)/mpich2/include") -#SET(MPI_LIBRARY "C:/Program Files/mpich2/lib/libmpi.a") -#SET(MPI_CXX_LIBRARY "C:/Program Files/MPICH2/lib/cxx.lib") + ################################################################################# # BOOST ################################################################################# @@ -27,46 +15,10 @@ SET(BOOST_LIBRARYDIR ${BOOST_ROOT}"/stageMSVC64/lib") # VTK ################################################################################# set(VTK_DIR "E:/Tools/VTK-8.1.2-build") -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "d:/Tools/zoltan/include") - SET(ZOLTAN_DEBUG_LIBRARY "d:/Tools/zoltan/lib/Debug/zoltan.lib") - SET(ZOLTAN_RELEASE_LIBRARY "d:/Tools/zoltan/lib/Release/zoltan.lib") -ENDIF() ################################################################################# # METIS ################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "c:/Tools/metis-5.1.0/include") - SET(METIS_DEBUG_LIBRARY "c:/Tools/metis-5.1.0/build/libmetis/Debug/metis.lib") - SET(METIS_RELEASE_LIBRARY "c:/Tools/metis-5.1.0/build/libmetis/Release/metis.lib") -ENDIF() - -################################################################################## -# FETOL -################################################################################## -IF(${USE_FETOL}) - SET(FETOL_INCLUDEDIR "d:/Projects/FETOL/dev/CppFETOLlib") - SET(FETOL_DEBUG_LIBRARY "d:/Projects/FETOL/dev/CppFETOLlib/build/Debug/fetol.lib") - SET(FETOL_RELEASE_LIBRARY "d:/Projects/FETOL/dev/CppFETOLlib/build/Release/fetol.lib") - - SET(YAML_INCLUDEDIR "d:/Tools/yaml-cpp/include") - SET(YAML_DEBUG_LIBRARY "d:/Tools/yaml-cpp/buildVS11/Debug/libyaml-cppmdd.lib") - SET(YAML_RELEASE_LIBRARY "d:/Tools/yaml-cpp/buildVS11/Release/libyaml-cppmd.lib") - - SET(BOND_INCLUDEDIR "d:/Projects/FETOL/dev/bond_src/cpp/bond/fetol") - SET(BOND_DEBUG_LIBRARY "d:/Projects/FETOL/dev/bond_lib/Debug/bond.lib") - SET(BOND_RELEASE_LIBRARY "d:/Projects/FETOL/dev/bond_lib/Release/bond.lib") -ENDIF() - -################################################################################## -# Java -############################################################################## -### FindJNI.cmake -#find_package(JNI REQUIRED) -#SET(JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2} ${JAVA_AWT_INCLUDE_PATH}) -#SET(JNI_LIBRARIES ${JAVA_AWT_LIBRARY} ${JAVA_JVM_LIBRARY}) -#SET(JNI_FOUND 1) \ No newline at end of file +SET(METIS_INCLUDEDIR "c:/Tools/metis-5.1.0/include") +SET(METIS_DEBUG_LIBRARY "c:/Tools/metis-5.1.0/build/libmetis/Debug/metis.lib") +SET(METIS_RELEASE_LIBRARY "c:/Tools/metis-5.1.0/build/libmetis/Release/metis.lib") diff --git a/CMake/cmake_config_files/SHELOB.config.cmake b/CMake/cmake_config_files/SHELOB.config.cmake deleted file mode 100644 index f2f62ad9dd1c710ca881653d56a4c1c2a422a348..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/SHELOB.config.cmake +++ /dev/null @@ -1,49 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - -################################################################################# -# RUBY -################################################################################# -#IF(CMAKE_CL_64) -# SET(RUBY_EXECUTABLE "C:/ruby191/bin/ruby.exe") -# SET(RUBY_LIBRARY "C:/ruby191/lib/msvcr90-ruby191.lib") -#ELSE() -# SET(RUBY_EXECUTABLE "C:/ruby186/bin/ruby.exe") -# SET(RUBY_LIBRARY "C:/ruby186/lib/msvcrt-ruby18.lib") -#ENDIF() - -################################################################################# -# SWIG -################################################################################# -SET(SWIG_EXECUTABLE "/Users/freud/dev/swig/bin/swig") - - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost: 1.41.0 -SET(BOOST_VERSION "1.41.0" CACHE STRING "std: 1.41.0") - -SET(MPI_DIR "/usr/local/mpich2/gcc401") - -IF(CAB_COMPILER MATCHES "gcc42") - SET(BOOST_USE_MULTITHREAD ON) - - SET(BOOST_COMPILER_SUFFIX -xgcc40) - SET(BOOST_USE_STATIC_LIBS ON) - - IF(BOOST_VERSION MATCHES "1.41.0" ) - SET(BOOST_INCLUDEDIR "/scratch/shared/boost_1_41_0/include") - SET(BOOST_LIBRARYDIR "/scratch/shared/boost_1_41_0/lib") - ELSEIF(BOOST_VERSION MATCHES "1.39.0" ) - SET(BOOST_INCLUDEDIR "/usr/local/boost/gcc401/boost_1_39_0/include/boost-1_39") - SET(BOOST_LIBRARYDIR "/usr/local/boost/gcc401/boost_1_39_0/lib") - ENDIF() -ENDIF() - -IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) - MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -ENDIF() - - diff --git a/CMake/cmake_config_files/SMAUG.config.cmake b/CMake/cmake_config_files/SMAUG.config.cmake deleted file mode 100644 index 09c9f4420ea26d937e5dacbe2573022f318c2989..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/SMAUG.config.cmake +++ /dev/null @@ -1,27 +0,0 @@ -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - - -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.44") -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.44" ) - SET(BOOST_INCLUDEDIR "C:/boost/boost_1_44_0") - SET(BOOST_LIBRARYDIR "C:/boost/boost_1_44_0/stage64/lib") -ENDIF() -################################################################################# -# ZOLTAN -################################################################################# - SET(ZOLTAN_INCLUDEDIR "c:/zoltan/include") - SET(ZOLTAN_LIBRARY "c:/zoltan/lib/Debug/zoltan.lib") - -set(SOURCE_ROOT "g:/Kostja/pFluid/source") - - - - diff --git a/CMake/cmake_config_files/SP0201.config.cmake b/CMake/cmake_config_files/SP0201.config.cmake deleted file mode 100644 index bf28750def2e59a571e64af3c62ef9149041e616..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/SP0201.config.cmake +++ /dev/null @@ -1,27 +0,0 @@ -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__AIX__) - - -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - -################################################################################# -# MPI -################################################################################# -SET(USE_MPI_CXX_SYNTAX OFF) -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.44") -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.44" ) - SET(BOOST_INCLUDEDIR "/sp6/userdeisa/lrz102bk/tools/boost_1_44_0") - SET(BOOST_LIBRARYDIR "/sp6/userdeisa/lrz102bk/tools/boost_1_44_0/stage/lib") -ENDIF() - -set(SOURCE_ROOT "/sp6/userdeisa/lrz102bk/projects/pFluid/source") -set(pFluid_ROOT "/sp6/userdeisa/lrz102bk/projects/pFluid") \ No newline at end of file diff --git a/CMake/cmake_config_files/SUPERMUC.config.cmake b/CMake/cmake_config_files/SUPERMUC.config.cmake deleted file mode 100644 index 91316ea69f2aa2e33abe4cc6e4b62552d0b0247e..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/SUPERMUC.config.cmake +++ /dev/null @@ -1,23 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) - -######################################################################################## -## BOOST ALLGMEINGUELTIG ## -######################################################################################## -#standard boost -SET(BOOST_VERSION "1.61.0" CACHE STRING "std: 1.61.0") -SET(BOOST_INCLUDEDIR "/lrz/sys/libraries/boost/1.61_icc/include") -SET(BOOST_LIBRARYDIR "/lrz/sys/libraries/boost/1.61_icc/lib") - -#IF(BOOST_VERSION AND NOT BOOST_INCLUDEDIR) -# MESSAGE("${BOOST_VERSION} not found on ${CAB_MACHINE} for specified compiler") -#ENDIF() - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/lrz/sys/libraries/metis/5.1.0/i4r4/include") - SET(METIS_DEBUG_LIBRARY "/lrz/sys/libraries/metis/5.1.0/i4r4/lib/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/lrz/sys/libraries/metis/5.1.0/i4r4/lib/libmetis.a") -ENDIF() diff --git a/CMake/cmake_config_files/TESLA01.config.cmake b/CMake/cmake_config_files/TESLA01.config.cmake index adebd6af01a6fbe44952cdf39f398aa9d7abb49d..c92603b3508a2cac51019cc80d99083e2a400a58 100644 --- a/CMake/cmake_config_files/TESLA01.config.cmake +++ b/CMake/cmake_config_files/TESLA01.config.cmake @@ -1,18 +1,17 @@ -#Don't change: -SET(METIS_ROOT ${VF_THIRD_DIR}/metis/metis-5.1.0 CACHE PATH "METIS ROOT") -SET(GMOCK_ROOT ${VF_THIRD_DIR}/googletest CACHE PATH "GMOCK ROOT") -SET(JSONCPP_ROOT ${VF_THIRD_DIR}/jsoncpp CACHE PATH "JSONCPP ROOT") -SET(FFTW_ROOT ${VF_THIRD_DIR}/fftw/fftw-3.3.7 CACHE PATH "JSONCPP ROOT") +################################################################################# +# VirtualFluids MACHINE FILE +# Responsible: Soeren Peters +# OS: Windows 10 +################################################################################# - -#SET TO CORRECT PATH: SET(BOOST_ROOT "C:\\Libraries\\boost_1_65_1" CACHE PATH "BOOST_ROOT") SET(BOOST_LIBRARYDIR "C:\\Libraries\\boost_1_65_1\\lib" CACHE PATH "BOOST_LIBRARYDIR") -#SET(VTK_DIR "F:/Libraries/vtk/VTK-8.2.0/build" CACHE PATH "VTK directory override" FORCE) +SET(VTK_DIR "C:/Libraries/VTK-8.0.1/build") -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "C:/Libraries/metis-5.1.0//include") - SET(METIS_DEBUG_LIBRARY "C:/Libraries/metis-5.1.0/build/libmetis/Debug/metis.lib") - SET(METIS_RELEASE_LIBRARY "C:/Libraries/metis-5.1.0/build/libmetis/Release/metis.lib") -ENDIF() \ No newline at end of file +################################################################################# +# METIS +################################################################################# +SET(METIS_INCLUDEDIR "C:/Libraries/metis-5.1.0//include") +SET(METIS_DEBUG_LIBRARY "C:/Libraries/metis-5.1.0/build/libmetis/Debug/metis.lib") +SET(METIS_RELEASE_LIBRARY "C:/Libraries/metis-5.1.0/build/libmetis/Release/metis.lib") diff --git a/CMake/cmake_config_files/TESLA03.config.cmake b/CMake/cmake_config_files/TESLA03.config.cmake index ac45019eb659c4559e7b1e4d0b3437fbc8c2cd8a..110c78ebcecb7c3d8393da4494d9a677c679b611 100644 --- a/CMake/cmake_config_files/TESLA03.config.cmake +++ b/CMake/cmake_config_files/TESLA03.config.cmake @@ -1,3 +1,9 @@ +################################################################################# +# VirtualFluids MACHINE FILE +# Responsible: Martin Schoenherr +# OS: Windows 10 +################################################################################# + #Don't change: SET(METIS_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/metis/metis-5.1.0 CACHE PATH "METIS ROOT") SET(GMOCK_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/googletest CACHE PATH "GMOCK ROOT") diff --git a/CMake/cmake_config_files/TOLKIEN.config.cmake b/CMake/cmake_config_files/TOLKIEN.config.cmake deleted file mode 100644 index 5ad8d989c1d5f26368190237f1ea89d8898595bd..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/TOLKIEN.config.cmake +++ /dev/null @@ -1,22 +0,0 @@ -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - -################################################################################# -# MPI -################################################################################# -SET(MPI_DIR "C:/Program Files/mpich2") - -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.38") -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.38" ) - SET(BOOST_INCLUDEDIR "C:/Program Files/boost/boost_1_38") - SET(BOOST_LIBRARYDIR "C:/Program Files/boost/boost_1_38/lib") -ENDIF() - - diff --git a/CMake/cmake_config_files/TOLKIEN2.config.cmake b/CMake/cmake_config_files/TOLKIEN2.config.cmake deleted file mode 100644 index 5ad8d989c1d5f26368190237f1ea89d8898595bd..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/TOLKIEN2.config.cmake +++ /dev/null @@ -1,22 +0,0 @@ -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - -################################################################################# -# MPI -################################################################################# -SET(MPI_DIR "C:/Program Files/mpich2") - -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.38") -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.38" ) - SET(BOOST_INCLUDEDIR "C:/Program Files/boost/boost_1_38") - SET(BOOST_LIBRARYDIR "C:/Program Files/boost/boost_1_38/lib") -ENDIF() - - diff --git a/CMake/cmake_config_files/UBUNTU.config.cmake b/CMake/cmake_config_files/UBUNTU.config.cmake deleted file mode 100644 index b266286f44fe98575f932128080c22a57b1535d2..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/UBUNTU.config.cmake +++ /dev/null @@ -1,46 +0,0 @@ -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__unix__) -LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__UNIX__) -#LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D__APPLE__) - -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - -################################################################################# -# MPI -################################################################################# -#SET(MPI_DIR "C:/Program Files (x86)/mpich2") -#SET(MPI_DIR "C:/Program Files/mpich2") -#SET(USE_MPI_CXX_SYNTAX OFF) -#SET(MPI_COMPILER "C:/Program Files/mpich2/bin/mpicxx") -#SET(MPI_INCLUDE_PATH "C:/Program Files (x86)/mpich2/include") -#SET(MPI_LIBRARY "C:/Program Files/mpich2/lib/libmpi.a") -#SET(MPI_CXX_LIBRARY "C:/Program Files/MPICH2/lib/cxx.lib") -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.47") -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.47" ) - SET(BOOST_ROOT "/host/tools/boost/boost_1_47_0") - SET(BOOST_LIBRARYDIR "/host/tools/boost/boost_1_47_0/stageLinux/lib") -ENDIF() -################################################################################# -# ZOLTAN -################################################################################# -IF(${USE_ZOLTAN}) - SET(ZOLTAN_INCLUDEDIR "/home/kostja/tools/Zoltan_v3.5/bin/include") - SET(ZOLTAN_DEBUG_LIBRARY "/home/kostja/tools/Zoltan_v3.5/bin/lib/libzoltan.a") - SET(ZOLTAN_RELEASE_LIBRARY "/home/kostja/tools/Zoltan_v3.5/bin/lib/libzoltan.a") -ENDIF() -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "/home/kostja/tools/metis-5.0.1/include") - SET(METIS_DEBUG_LIBRARY "/home/kostja/tools/metis-5.0.1/build/Linux-x86_64/libmetis/libmetis.a") - SET(METIS_RELEASE_LIBRARY "/home/kostja/tools/metis-5.0.1/build/Linux-x86_64/libmetis/libmetis.a") -ENDIF() -set(SOURCE_ROOT "/host/Projects/pFluid/source") \ No newline at end of file diff --git a/CMake/cmake_config_files/YWANG.config.cmake b/CMake/cmake_config_files/YWANG.config.cmake deleted file mode 100644 index 9e802e4840926ccbd1ff24df77e6ef8752c46fb6..0000000000000000000000000000000000000000 --- a/CMake/cmake_config_files/YWANG.config.cmake +++ /dev/null @@ -1,24 +0,0 @@ -IF(NOT CMAKE_CXX_COMPILER) - MESSAGE(FATAL_ERROR "before cmake-config-file can be included -> project must be extecuted") -ENDIF() - -################################################################################# -# BOOST -################################################################################# -SET(BOOST_VERSION "1.49") -SET(BOOST_USE_MULTITHREAD ON) -SET(BOOST_USE_STATIC_LIBS ON) - -IF(BOOST_VERSION MATCHES "1.49" ) - SET(BOOST_ROOT "C:/boost/boost_1_49_0") - SET(BOOST_LIBRARYDIR "c:/boost/boost_1_49_0/stageMSVC64/lib") -ENDIF() - -################################################################################# -# METIS -################################################################################# -IF(${USE_METIS}) - SET(METIS_INCLUDEDIR "c:/metis-5.1.0/include") - SET(METIS_DEBUG_LIBRARY "c:/metis-5.1.0/build/libmetis/Debug/metis.lib") - SET(METIS_RELEASE_LIBRARY "c:/metis-5.1.0/build/libmetis/Release/metis.lib") -ENDIF() diff --git a/CMake/compilerflags/AppleClang.cmake b/CMake/compilerflags/AppleClang.cmake new file mode 100644 index 0000000000000000000000000000000000000000..ef97a54a4ebe17bde5e016e04a40a187371172e9 --- /dev/null +++ b/CMake/compilerflags/AppleClang.cmake @@ -0,0 +1,42 @@ +############################################################################################################### +## +## apple clang +## +############################################################################################################### + +############################################################################################################# +# Flags +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3;-fomit-frame-pointer;-finline-functions;-fPIC;-Wbackslash-newline-escape") + +############################################################################################################# +# mt support +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") + +############################################################################################################# +# c++ 11 support +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") + + +# test +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "-Wall") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "-Werror") + +############################################################################################################# +# disable warning +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wbackslash-newline-escape") #backslash and newline separated by space +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wcomment") #'/*' within block comment + +############################################################################################################# +# c++ 17 support +############################################################################################################# +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++17") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++17") + +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fext-numeric-literals") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wregister") diff --git a/CMake/compilerflags/GNU.cmake b/CMake/compilerflags/GNU.cmake new file mode 100644 index 0000000000000000000000000000000000000000..08dc75adc01375fc35ddd46bc00ae539dce4c96c --- /dev/null +++ b/CMake/compilerflags/GNU.cmake @@ -0,0 +1,30 @@ + +############################################################################################################# +# Flags +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3;-fomit-frame-pointer;-finline-functions;-funroll-all-loops;-fPIC") +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) + +############################################################################################################# +# mt support +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") + +############################################################################################################# +# c++ 11 support +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") + +############################################################################################################# +# c++ 17 support +############################################################################################################# +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++17") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++17") + +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fext-numeric-literals") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wregister") + + +list(APPEND VF_LINK_OPTIONS -lgomp) +list(APPEND VF_LINK_OPTIONS -lrt) diff --git a/CMake/compilerflags/Intel.cmake b/CMake/compilerflags/Intel.cmake new file mode 100644 index 0000000000000000000000000000000000000000..4f4c7bb3ed2dad45a6f91e644fa0d74e5b4d98be --- /dev/null +++ b/CMake/compilerflags/Intel.cmake @@ -0,0 +1,37 @@ +############################################################################################################### +## intel +############################################################################################################### + +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") +#~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") +#~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended +#~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header +#~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor +#~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor +#~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor +#~ +#~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -ipo -fno-alias -mcmodel=medium -qopt-streaming-stores=always") + +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1478") #auto_ptr warning from mu::Parser +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST;-O3;-ip;-fno-alias;-mcmodel=medium;-qopt-streaming-stores=always;-xCORE-AVX512;-qopt-zmm-usage=high") + +#Debug +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-g -traceback") + +############################################################################################################### +## mt support +############################################################################################################### +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") + +############################################################################################################# +# c++ 11 support +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") + +list(APPEND VF_LINK_OPTIONS -parallel) +list(APPEND VF_LINK_OPTIONS -irc) + + +# LIST(APPEND VF_COMPILER_DEFINITION MPICH_IGNORE_CXX_SEEK) +# LIST(APPEND VF_COMPILER_DEFINITION MPICH_SKIP_MPICXX) diff --git a/CMake/compilerflags/MSVC.cmake b/CMake/compilerflags/MSVC.cmake new file mode 100644 index 0000000000000000000000000000000000000000..0a279571cc9aa2cba70476316068f52463246b03 --- /dev/null +++ b/CMake/compilerflags/MSVC.cmake @@ -0,0 +1,27 @@ +############################################################################################################### +## MSVC +############################################################################################################### + +############################################################################################################### +## USE_UNSECURE_STL_VECTORS_RELEASE ? +############################################################################################################### +OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) +IF(USE_UNSECURE_STL_VECTORS_RELEASE) + # More MSVC specific compilation flags + LIST(APPEND VF_COMPILER_DEFINITION _SECURE_SCL=0) + LIST(APPEND VF_COMPILER_DEFINITION _SCL_SECURE_NO_WARNINGS) +ENDIF() + +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/W1") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/Wall") + +############################################################################################################### +## Flags +############################################################################################################### +LIST(APPEND VF_COMPILER_DEFINITION _CRT_SECURE_NO_DEPRECATE) # disable warnings promoting Microsoft's security enhanced CRT +LIST(APPEND VF_COMPILER_DEFINITION _SCL_SECURE_NO_WARNINGS) # disable warnings triggered by Microsoft's checked iterators +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") # deprecated strcpy... +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") # forcing value to bool 'true' or 'false' (performance warning) +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") # ansonsten funzt mit boost das compilieren unter windows nimmer + +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-MP") # enable multi-threaded compiling \ No newline at end of file diff --git a/CMake/compilerflags/clang.cmake b/CMake/compilerflags/clang.cmake index af6fd3b16255a64dd12bd3c5fd27a40e2f12c2f5..4e79d520c0b91a41d62f658092489941926bda05 100644 --- a/CMake/compilerflags/clang.cmake +++ b/CMake/compilerflags/clang.cmake @@ -1,68 +1,40 @@ ############################################################################################################### -## +## ## clang ## ############################################################################################################### -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3;-fomit-frame-pointer;-finline-functions;-fPIC;-Wbackslash-newline-escape") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3;-fomit-frame-pointer;-finline-functions;-fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() +############################################################################################################# +# Flags +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3;-fomit-frame-pointer;-finline-functions;-fPIC;-Wbackslash-newline-escape") - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") +############################################################################################################# +# mt support +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") +############################################################################################################# +# c++ 11 support +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - ############################################################################################################# - # disable warning - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wbackslash-newline-escape") #backslash and newline separated by space - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wcomment") #'/*' within block comment +############################################################################################################# +# disable warning +############################################################################################################# +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wbackslash-newline-escape") #backslash and newline separated by space +LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wcomment") #'/*' within block comment - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-Wbackslash-newline-escape") #backslash and newline separated by space - - ############################################################################################################# - # c++ 17 support - ############################################################################################################# - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++17") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++17") - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fext-numeric-literals") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wregister") +############################################################################################################# +# c++ 17 support +############################################################################################################# +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++17") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++17") - +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fext-numeric-literals") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") +#LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wregister") - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) +LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") \ No newline at end of file diff --git a/CMake/compilerflags/gcc33.cmake b/CMake/compilerflags/gcc33.cmake deleted file mode 100644 index 88e52224110fa5177048e4aa40737fc846d9cb29..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc33.cmake +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################################################### -## -## gcc33 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -ffast-math -Wall -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - IF(CPU_TYPE MATCHES "Opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-march=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-march=opteron" ) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-march=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-march=opteron" ) - ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - MESSAGE(STATUS "gcc33 has no OpenMP support -> OpenMP deactivated") - SET(USE_OPENMP "OFF") - ENDIF() - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) - diff --git a/CMake/compilerflags/gcc34.cmake b/CMake/compilerflags/gcc34.cmake deleted file mode 100644 index f052bf9fe2dabc36b72afdbf5424fafb7410676b..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc34.cmake +++ /dev/null @@ -1,44 +0,0 @@ -############################################################################################################### -## -## gcc34 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -ffast-math -Wall -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - IF(CPU_TYPE MATCHES "Opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - MESSAGE(STATUS "gcc34 has no OpenMP support -> OpenMP deactivated") - SET(USE_OPENMP "OFF") - ENDIF() - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - diff --git a/CMake/compilerflags/gcc40.cmake b/CMake/compilerflags/gcc40.cmake deleted file mode 100644 index e16bc3504dd436253d05ce24e56ba297f3ef6760..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc40.cmake +++ /dev/null @@ -1,54 +0,0 @@ -############################################################################################################### -## -## gcc40 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - IF(CPU_TYPE MATCHES "Opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - ENDIF() - - - ############################################################################################################### - ## 64Bit support - ############################################################################################################### - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - MESSAGE(STATUS "gcc40 has no OpenMP support -> OpenMP deactivated") - SET(USE_OPENMP "OFF") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc41.cmake b/CMake/compilerflags/gcc41.cmake deleted file mode 100644 index 34f54b74c2bb6030fea770d0599cb9545550b17e..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc41.cmake +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################################################### -## -## gcc41 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - IF(CPU_TYPE MATCHES "Opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - ENDIF() - - ############################################################################################################### - ## 64Bit support - ############################################################################################################### - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - MESSAGE(STATUS "gcc41 has no OpenMP support -> OpenMP deactivated") - SET(USE_OPENMP "OFF") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc42.cmake b/CMake/compilerflags/gcc42.cmake deleted file mode 100644 index a81e7ff0f3e8234944e11bdb0f7716785e86862b..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc42.cmake +++ /dev/null @@ -1,57 +0,0 @@ -############################################################################################################### -## -## gcc42 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - ############################################################################################################### - ## Flags - ############################################################################################################### - #Anmerkung: bei O3 oder "O2 mit finline-function" gibt es Probleme beim MuParser. bug im gcc? - #Bug kann durch "test" in MuParser/examples ueberprueft werden - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O2 -fomit-frame-pointer -funroll-all-loops -fPIC") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O2 -fomit-frame-pointer -finline-functions -funroll-all-loops") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - IF(CPU_TYPE MATCHES "Opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - ENDIF() - - - ############################################################################################################### - ## 64Bit support - ############################################################################################################### - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc43.cmake b/CMake/compilerflags/gcc43.cmake deleted file mode 100644 index bc7deed357ea326e258c7ee3f110fd38a0ce917b..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc43.cmake +++ /dev/null @@ -1,49 +0,0 @@ -############################################################################################################### -## -## gcc43 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - IF(CPU_TYPE MATCHES "Opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - ENDIF() - - - ############################################################################################################### - ## 64Bit support - ############################################################################################################### - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc44.cmake b/CMake/compilerflags/gcc44.cmake deleted file mode 100644 index 10b8f71f7693789d79f298fedebb5e03d89ddc07..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc44.cmake +++ /dev/null @@ -1,54 +0,0 @@ -############################################################################################################### -## -## gcc44 -## -############################################################################################################### - -#MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) -#ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - IF(CPU_TYPE MATCHES "Opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - ENDIF() - - - ############################################################################################################### - ## 64Bit support - ############################################################################################################### - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc45.cmake b/CMake/compilerflags/gcc45.cmake deleted file mode 100644 index 5c4d597e2ebef788272bb7cc48941797ee20d779..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc45.cmake +++ /dev/null @@ -1,54 +0,0 @@ -############################################################################################################### -## -## gcc45 -## -############################################################################################################### - -#MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) -#ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################### - ## Flags - ############################################################################################################### - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - # IF(CPU_TYPE MATCHES "Opteron") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - # ENDIF() - - - # ############################################################################################################### - # ## 64Bit support - # ############################################################################################################### - # IF( ${use64BitOptions} ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - # ENDIF() - - - # ############################################################################################################### - # ## OpenMP support - # ############################################################################################################### - # IF(USE_OPENMP) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - # ENDIF() - - - # ############################################################################################################### - # ## mt support - # ############################################################################################################### - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - # IF(NOT APPLE) - # LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - # ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc46.cmake b/CMake/compilerflags/gcc46.cmake deleted file mode 100644 index 2f56fac857cf3a63f2c9eb3ef8e857c94941ac4e..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc46.cmake +++ /dev/null @@ -1,54 +0,0 @@ -############################################################################################################### -## -## gcc46 -## -############################################################################################################### - -#MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) -#ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type) - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################### - ## Flags - ############################################################################################################### - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - # IF(CPU_TYPE MATCHES "Opteron") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mtune=opteron") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-mcpu=opteron" ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mtune=opteron") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-mcpu=opteron" ) - # ENDIF() - - - # ############################################################################################################### - # ## 64Bit support - # ############################################################################################################### - # IF( ${use64BitOptions} ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - # ENDIF() - - - # ############################################################################################################### - # ## OpenMP support - # ############################################################################################################### - # IF(USE_OPENMP) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - # ENDIF() - - - # ############################################################################################################### - # ## mt support - # ############################################################################################################### - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - # IF(NOT APPLE) - # LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - # ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc47.cmake b/CMake/compilerflags/gcc47.cmake deleted file mode 100644 index 2a6b91042c55e3bb0159030676310b541a952a2f..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc47.cmake +++ /dev/null @@ -1,42 +0,0 @@ -############################################################################################################### -## -## gcc47 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - MESSAGE(STATUS "gcc41 has no OpenMP support -> OpenMP deactivated") - SET(USE_OPENMP "OFF") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc48.cmake b/CMake/compilerflags/gcc48.cmake deleted file mode 100644 index 989afcc3e886ef1a92921982bdda4e720f7df436..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc48.cmake +++ /dev/null @@ -1,42 +0,0 @@ -############################################################################################################### -## -## gcc48 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - MESSAGE(STATUS "gcc48 has no OpenMP support -> OpenMP deactivated") - SET(USE_OPENMP "OFF") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc49.cmake b/CMake/compilerflags/gcc49.cmake deleted file mode 100644 index 26f641ae19d9d0270f17e234ee37b3c5e0496f20..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc49.cmake +++ /dev/null @@ -1,42 +0,0 @@ -############################################################################################################### -## -## gcc49 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - MESSAGE(STATUS "gcc49 has no OpenMP support -> OpenMP deactivated") - SET(USE_OPENMP "OFF") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc51.cmake b/CMake/compilerflags/gcc51.cmake deleted file mode 100644 index 1c4df2a693a8104ef4204715f4910d576a777336..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc51.cmake +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################################################### -## -## gcc51 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - - - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc52.cmake b/CMake/compilerflags/gcc52.cmake deleted file mode 100644 index 41649c34a3b94c3703878554309c1c3cf032876e..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc52.cmake +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################################################### -## -## gcc52 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - - - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc54.cmake b/CMake/compilerflags/gcc54.cmake deleted file mode 100644 index 234797337a662621e76c23e621ecbe4e0c84c319..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc54.cmake +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################################################### -## -## gcc54 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - - - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc62.cmake b/CMake/compilerflags/gcc62.cmake deleted file mode 100644 index 5e80808ac777bf091434e1df1e43cff7a930c5f4..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc62.cmake +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################################################### -## -## gcc62 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - - - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc63.cmake b/CMake/compilerflags/gcc63.cmake deleted file mode 100644 index c624265fa66e7c73bc9e7ad980f1ac5e9b6a670a..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc63.cmake +++ /dev/null @@ -1,52 +0,0 @@ -############################################################################################################### -## -## gcc63 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 17 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++17") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++17") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fext-numeric-literals") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") - - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gcc82.cmake b/CMake/compilerflags/gcc82.cmake deleted file mode 100644 index 13857f5ceb6f882ae21d2235df15e60c0cbf5fbe..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gcc82.cmake +++ /dev/null @@ -1,60 +0,0 @@ -############################################################################################################### -## -## gcc82 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops -fPIC") - - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - - ############################################################################################################# - # c++ 17 support - ############################################################################################################# - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++17") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++17") - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fext-numeric-literals") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wregister") - - - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/gccGeneric.cmake b/CMake/compilerflags/gccGeneric.cmake deleted file mode 100644 index d658afe73f2a7c1991018553b4488ed028e9d787..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/gccGeneric.cmake +++ /dev/null @@ -1,62 +0,0 @@ -############################################################################################################### -## -## gcc generic -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - ############################################################################################################# - # Flags - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3;-fomit-frame-pointer;-finline-functions;-funroll-all-loops;-fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wno-unused-result") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3;-fomit-frame-pointer;-finline-functions;-funroll-all-loops;-fPIC") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-Wno-deprecated") #deprecated header warning (jarl benutzt sstream weil schneller und so) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-Wno-unused-result") - ############################################################################################################# - # 64Bit support - ############################################################################################################# - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-m64" ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-m64" ) - ENDIF() - - ############################################################################################################# - # OpenMP support - ############################################################################################################# - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fopenmp") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fopenmp") - ENDIF() - - ############################################################################################################# - # mt support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - - ############################################################################################################# - # c++ 17 support - ############################################################################################################# - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++17") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++17") - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fext-numeric-literals") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-Wregister") - - - - IF(NOT APPLE) - LIST(APPEND CAB_ADDITIONAL_LINK_PROPS "-lrt") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc101.cmake b/CMake/compilerflags/icc101.cmake deleted file mode 100644 index 3cd6b535e82ca27b02b055428d1103ef363e8e0a..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc101.cmake +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################################################### -## -## intel10 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - ENDIF() - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops") - - IF(CPU_TYPE MATCHES "Opteron") - IF(WIN32) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-QxO") #Enables SSE3, SSE2 and SSE instruction sets optimizations for non-Intel CPUs - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-QxO") #Enables SSE3, SSE2 and SSE instruction sets optimizations for non-Intel CPUs - ELSE() - #auf unserem cluster gibt es kein ss3 SET( CAB_CXX_FLAGS "${CAB_CXX_FLAGS} -xO") #Enables SSE3, SSE2 and SSE instruction sets optimizations for non-Intel CPUs - #gibt teils probleme beim ausfuehren: SET( CAB_C_FLAGS "${CAB_C_FLAGS} -xO") #Enables SSE3, SSE2 and SSE instruction sets optimizations for non-Intel CPUs - ENDIF() - ELSE() - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-fast") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-fast") - ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-openmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc130.cmake b/CMake/compilerflags/icc130.cmake deleted file mode 100644 index 346b9c25768f93df7d48e9c499aa712b502e11c9..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc130.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## intel10 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - #~ IF( ${use64BitOptions} ) - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - #~ ENDIF() - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor -#~ - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops") - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-openmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc140.cmake b/CMake/compilerflags/icc140.cmake deleted file mode 100644 index 120a25c38432410ae002b5fda8ae61d3555f6eb1..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc140.cmake +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################################################### -## -## intel140 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - #~ IF( ${use64BitOptions} ) - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - #~ ENDIF() - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor -#~ - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -fno-alias -mcmodel=medium") - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-openmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc150.cmake b/CMake/compilerflags/icc150.cmake deleted file mode 100644 index 7c5abc3a0fe053af90fd171a12432130afe34eef..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc150.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## intel150 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - #~ IF( ${use64BitOptions} ) - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - #~ ENDIF() - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor -#~ - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fomit-frame-pointer -finline-functions -funroll-all-loops") - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-openmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc160.cmake b/CMake/compilerflags/icc160.cmake deleted file mode 100644 index 88b25faa5e84154c0b2106ca18a9131ccfbec513..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc160.cmake +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################################################### -## -## intel160 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - #~ IF( ${use64BitOptions} ) - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - #~ ENDIF() - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor -#~ - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -ipo -fno-alias -mcmodel=medium -qopt-streaming-stores=always") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -fno-alias -mcmodel=medium -qopt-streaming-stores=always") - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-openmp") - ENDIF() - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11" - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc170.cmake b/CMake/compilerflags/icc170.cmake deleted file mode 100644 index c0607f7aa48322150c50932f3f9618023efd89fe..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc170.cmake +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################################################### -## -## intel170 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - #~ IF( ${use64BitOptions} ) - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - #~ ENDIF() - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor -#~ - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -ipo -fno-alias -mcmodel=medium -qopt-streaming-stores=always") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1478") #auto_ptr warning from mu::Parser - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -fno-alias -mcmodel=medium -qopt-streaming-stores=always") - - #Debug - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-g -traceback") - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-qopenmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc180.cmake b/CMake/compilerflags/icc180.cmake deleted file mode 100644 index db9f3a70e299eae5eee2fbc71bdf248fbca35b64..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc180.cmake +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################################################### -## -## intel180 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - #~ IF( ${use64BitOptions} ) - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - #~ ENDIF() - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor -#~ - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -ipo -fno-alias -mcmodel=medium -qopt-streaming-stores=always") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1478") #auto_ptr warning from mu::Parser - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -fno-alias -mcmodel=medium -qopt-streaming-stores=always -xCORE-AVX512 -qopt-zmm-usage=high") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -fno-alias -mcmodel=medium -qopt-streaming-stores=always -xCORE-AVX512 -qopt-zmm-usage=high") - - #Debug - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-g -traceback") - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-qopenmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc190.cmake b/CMake/compilerflags/icc190.cmake deleted file mode 100644 index ff7aafd6da9a9c1e5e922acf21ad59dbb65457ba..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc190.cmake +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################################################### -## -## intel190 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - #~ IF( ${use64BitOptions} ) - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - #~ ENDIF() - - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor -#~ - #~ LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -ipo -fno-alias -mcmodel=medium -qopt-streaming-stores=always") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1478") #auto_ptr warning from mu::Parser - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -fno-alias -mcmodel=medium -qopt-streaming-stores=always -xCORE-AVX512 -qopt-zmm-usage=high") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-xHOST -O3 -ip -fno-alias -mcmodel=medium -qopt-streaming-stores=always -xCORE-AVX512 -qopt-zmm-usage=high") - - #Debug - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-g -traceback") - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-qopenmp") - ENDIF() - - - ############################################################################################################### - ## mt support - ############################################################################################################### - #LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - #LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - - ############################################################################################################# - # c++ 11 support - ############################################################################################################# - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-std=c++11") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-std=c++11") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/icc91.cmake b/CMake/compilerflags/icc91.cmake deleted file mode 100644 index a77f20ff8e98de88ac3379269240c1fd2420a6fa..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/icc91.cmake +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################################################### -## -## intel9 -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF( ${use64BitOptions} ) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D__amd64" ) - ENDIF() - - #IF( ${compiler} MATCHES "INTEL_91_IPO") - # LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-ipo" ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-ipo" ) - # LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-opt-mem-bandwidth2" ) - #ENDIF( ${compiler} MATCHES "INTEL_91_IPO") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-O3 -fast -fomit-frame-pointer -finline-functions") - - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd68" ) #integer conversion resulted in a change of sign - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd186") # pointless comparison of unsigned integer with zero - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd654") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1125") #virtual function override intended - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd1224") #warning directive: This file includes at least one deprecated or antiquated header - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd377") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-wd327") #class "std::auto_ptr<RCF::I_ClientTransport>" has no suitable copy constructor - - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-wd266") #function "__GKfree" declared implicitly - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-O3 -fast -fomit-frame-pointer -finline-functions") - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-openmp") - ENDIF() - - ############################################################################################################### - ## mt support - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-pthread") - LIST(APPEND CAB_COMPILER_ADDTIONAL_C_COMPILER_FLAGS "-pthread") - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc10_32.cmake b/CMake/compilerflags/msvc10_32.cmake deleted file mode 100644 index 60f733c7ed5faf3bd7d1f6e1d563201ebdf1fd62..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc10_32.cmake +++ /dev/null @@ -1,59 +0,0 @@ -############################################################################################################### -## -## MSVC 2010 (Version 10.0) 32bit (msvc10_32) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be OFF for msvc10_32") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - -#foreach(flag_var -# CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE -# CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) -# if(${flag_var} MATCHES "/MD") -# string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") -# endif(${flag_var} MATCHES "/MD") -#endforeach(flag_var) - -# IF(${build_type} MATCHES BINARY) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES STATIC) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES SHARED) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MDd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MD" ) -# ELSE() -# MESSAGE(FATAL_ERROR "build_type=${build_type} doesn't match BINARY, SHARED or STATIC") -# ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc10_64.cmake b/CMake/compilerflags/msvc10_64.cmake deleted file mode 100644 index 5db3a092d55f22eca2acdd271198d6ed48fa3c3e..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc10_64.cmake +++ /dev/null @@ -1,78 +0,0 @@ -############################################################################################################### -## -## MSVC 2010 (Version 10.0) 64bit (msvc10_64) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(NOT ${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be ON for msvc10_64") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - -#folgendes kann man mittlerweile weglassen.. -#unser project kompilert einwandfrei durch! - -#hack (solange CMAke OMPILER_FLAGS_<CONFIG> nicht supported -#foreach(flag_var -# CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE -# CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) -# if(${flag_var} MATCHES "/MD") -# string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") -# endif(${flag_var} MATCHES "/MD") -#endforeach(flag_var) - -# IF(${build_type} MATCHES BINARY) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES STATIC) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES SHARED) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MDd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MD" ) -# ELSE() -# MESSAGE(FATAL_ERROR "build_type=${build_type} doesn't match BINARY, SHARED or STATIC") -# ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() - - ############################################################################################################### - ## boost + rcf extensions - ############################################################################################################### - IF(NEED_BOOST) - IF(BOOST_VERSION) - STRING(REGEX REPLACE "(.*)\\.(.*)\\.(.*)" "\\2" BoostMinorVersion "${BOOST_VERSION}") - IF(NOT BoostMinorVersion LESS 35 ) - - #IF(NOT ${build_type} MATCHES SHARED) - #LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS "/NODEFAULTLIB:\"MSVCRT\"" ) - #ENDIF() - ENDIF() - ENDIF() - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc11_32.cmake b/CMake/compilerflags/msvc11_32.cmake deleted file mode 100644 index 67c463f99d09861742a1c973258e90351da33b54..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc11_32.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## MSVC 2012 (Version 11.0) 32bit (msvc11_32) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be OFF for msvc11_32") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc11_64.cmake b/CMake/compilerflags/msvc11_64.cmake deleted file mode 100644 index 53a667bc930a42239cd88c65550062e92d01f6c7..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc11_64.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## MSVC 2012 (Version 11.0) 64bit (msvc11_64) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(NOT ${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be ON for msvc11_64") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc12_32.cmake b/CMake/compilerflags/msvc12_32.cmake deleted file mode 100644 index 997764d8526f42a0668122e9c2312973942968d5..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc12_32.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## MSVC 2013 (Version 12.0) 32bit (msvc12_32) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be OFF for msvc11_32") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc12_64.cmake b/CMake/compilerflags/msvc12_64.cmake deleted file mode 100644 index bd1796b5418c5e16ebad4213e530a76e799f8e8f..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc12_64.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## MSVC 2013 (Version 12.0) 64bit (msvc12_64) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(NOT ${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be ON for msvc11_64") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc14_32.cmake b/CMake/compilerflags/msvc14_32.cmake deleted file mode 100644 index 180d879356b8579b1c5b62795ca63537b7dcf0be..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc14_32.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## MSVC 2015 (Version 14.0) 32bit (msvc14_32) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be OFF for msvc11_32") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc14_64.cmake b/CMake/compilerflags/msvc14_64.cmake deleted file mode 100644 index 1fc3ef188d31b7d7e9c4230d061e09b0966eab23..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc14_64.cmake +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################################################### -## -## MSVC 2015 (Version 14.0) 64bit (msvc14_64) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(NOT ${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be ON for msvc11_64") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc19_64.cmake b/CMake/compilerflags/msvc19_64.cmake deleted file mode 100644 index 57f1155613ad4bfad55469b23c5658ba472fa29e..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc19_64.cmake +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################################################### -## -## MSVC 2019 (Version 16.0) 64bit (msvc16_64) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(NOT ${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be ON for msvc11_64") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - diff --git a/CMake/compilerflags/msvc8_32.cmake b/CMake/compilerflags/msvc8_32.cmake deleted file mode 100644 index cebc116464760924ba4214e645c2b54b16d988df..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc8_32.cmake +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################################################### -## -## MSVC 2005 (Version 8.0) 32bit (msvc8_32) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be OFF for msvc10_32") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - -# IF(${build_type} MATCHES BINARY) -# LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES STATIC) -# LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES SHARED) -# LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS_DEBUG "/MDd" ) -# LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS_RELEASE "/MD" ) -# ELSE() -# MESSAGE(FATAL_ERROR "build_type=${build_type} doesn't match BINARY, SHARED or STATIC") -# ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc8_64.cmake b/CMake/compilerflags/msvc8_64.cmake deleted file mode 100644 index b5cd87c5ccd29abfaa7388f44e7ead2f572079f8..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc8_64.cmake +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################################################### -## -## MSVC 2005 (Version 8.0) 32bit (msvc8_64) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(NOT ${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be ON for msvc8_64") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_ADDTIONAL_COMPILER_FLAGS -D_CRT_SECURE_NO_WARNINGS) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - -# IF(${build_type} MATCHES BINARY) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES STATIC) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES SHARED) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MDd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MD" ) -# ELSE() -# MESSAGE(FATAL_ERROR "build_type=${build_type} doesn't match BINARY, SHARED or STATIC") -# ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc9_32.cmake b/CMake/compilerflags/msvc9_32.cmake deleted file mode 100644 index b3792c099669323bc537a9291a8cccda37e18eb6..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc9_32.cmake +++ /dev/null @@ -1,59 +0,0 @@ -############################################################################################################### -## -## MSVC 2008 (Version 9.0) 32bit (msvc9_32) -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be OFF for msvc9_32") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_WARNINGS") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - -#foreach(flag_var -# CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE -# CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) -# if(${flag_var} MATCHES "/MD") -# string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") -# endif(${flag_var} MATCHES "/MD") -#endforeach(flag_var) - -# IF(${build_type} MATCHES BINARY) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES STATIC) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES SHARED) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MDd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MD" ) -# ELSE() -# MESSAGE(FATAL_ERROR "build_type=${build_type} doesn't match BINARY, SHARED or STATIC") -# ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMake/compilerflags/msvc9_64.cmake b/CMake/compilerflags/msvc9_64.cmake deleted file mode 100644 index 1bedf31255862982bcb1cb6630a2ede438a15995..0000000000000000000000000000000000000000 --- a/CMake/compilerflags/msvc9_64.cmake +++ /dev/null @@ -1,80 +0,0 @@ -############################################################################################################### -## -## MSVC 2008 (Version 9.0) 64bit (msvc9_64) -## -## -## -############################################################################################################### - -MACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) - - IF(NOT ${use64BitOptions}) - MESSAGE(FATAL_ERROR "SET_COMPILER_SPECIFIC_FLAGS: use64BitOptions must be ON for msvc10_64") - ENDIF() - - ############################################################################################################### - ## USE_UNSECURE_STL_VECTORS_RELEASE ? - ############################################################################################################### - OPTION(USE_UNSECURE_STL_VECTORS_RELEASE "_SECURE_SCL=0" OFF) - IF(USE_UNSECURE_STL_VECTORS_RELEASE) - # More MSVC specific compilation flags - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SECURE_SCL=0") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_SCL_SECURE_NO_WARNINGS") - ENDIF() - - ############################################################################################################### - ## Flags - ############################################################################################################### - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "-D_CRT_SECURE_NO_DEPRECATE") - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4996") #deprecated strcpy... - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/wd4800") #forcing value to bool 'true' or 'false' (performance warning) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/bigobj") #ansonsten funzt mit boost das compilieren unter windows nimmer - -#folgendes kann man mittlerweile weglassen.. -#unser project kompilert einwandfrei durch! - -#hack (solange CMAke OMPILER_FLAGS_<CONFIG> nicht supported -#foreach(flag_var -# CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE -# CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) -# if(${flag_var} MATCHES "/MD") -# string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") -# endif(${flag_var} MATCHES "/MD") -#endforeach(flag_var) - -# IF(${build_type} MATCHES BINARY) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES STATIC) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MTd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MT" ) -# ELSEIF(${build_type} MATCHES SHARED) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_DEBUG "/MDd" ) -# LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS_RELEASE "/MD" ) -# ELSE() -# MESSAGE(FATAL_ERROR "build_type=${build_type} doesn't match BINARY, SHARED or STATIC") -# ENDIF() - - ############################################################################################################### - ## OpenMP support - ############################################################################################################### - IF(USE_OPENMP) - LIST(APPEND CAB_COMPILER_ADDTIONAL_CXX_COMPILER_FLAGS "/openmp") - ENDIF() - - ############################################################################################################### - ## boost + rcf extensions - ############################################################################################################### - IF(NEED_BOOST) - IF(BOOST_VERSION) - STRING(REGEX REPLACE "(.*)\\.(.*)\\.(.*)" "\\2" BoostMinorVersion "${BOOST_VERSION}") - IF(NOT BoostMinorVersion LESS 35 ) - - #IF(NOT ${build_type} MATCHES SHARED) - #LIST(APPEND CAB_COMPILER_ADDITIONAL_LINK_PROPS "/NODEFAULTLIB:\"MSVCRT\"" ) - #ENDIF() - ENDIF() - ENDIF() - ENDIF() - -ENDMACRO(SET_COMPILER_SPECIFIC_FLAGS_INTERN build_type use64BitOptions) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9faf348c02c77cb89a2e0a2c985cb09b528d3132..01f46ac17ebe0a821ee6ba80489985591e604495 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,8 @@ cmake_minimum_required(VERSION 3.13..3.18 FATAL_ERROR) project(VirtualFluids CXX) -set (CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER ".cmake") @@ -50,13 +51,7 @@ endif() # MACROS ################################################################################# include(CMakePrintHelpers) -include(${VF_CMAKE_DIR}/CMakeCABMacros.cmake) -include(${VF_CMAKE_DIR}/FileUtilities.cmake) include(${VF_CMAKE_DIR}/VirtualFluidsMacros.cmake) -include(${VF_CMAKE_DIR}/3rd.cmake) - -include(${VF_CMAKE_DIR}/CMakeMacros_old/general/FindCompiler.cmake) -configure_file(src/basics/VirtualFluidsDefinitions.in.h ${CMAKE_BINARY_DIR}/VirtualFluidsDefinitions.h) ################################################################################# # COMMON LIBRARIES diff --git a/apps/cpu/Applications.cmake b/apps/cpu/Applications.cmake index 3517b53324c4d3daf7c5f65cfc67cbe32a721617..4baa53860f20cc7fa6239b115fdfaaf9ce20d6c1 100644 --- a/apps/cpu/Applications.cmake +++ b/apps/cpu/Applications.cmake @@ -1,3 +1,3 @@ -add_subdirectory(${APPS_ROOT_CPU}/LidDrivenCavityCPU) +add_subdirectory(${APPS_ROOT_CPU}/LidDrivenCavity) diff --git a/apps/cpu/LidDrivenCavity/CMakeLists.txt b/apps/cpu/LidDrivenCavity/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9527e73eab5b2bcfe7f874f640bb3cada7edc016 --- /dev/null +++ b/apps/cpu/LidDrivenCavity/CMakeLists.txt @@ -0,0 +1,4 @@ + +PROJECT(LidDrivenCavity) + +vf_add_library(NAME LidDrivenCavityCPU BUILDTYPE binary DEPENDS VirtualFluidsCore basics muparser FILES LidDrivenCavity.cpp) diff --git a/apps/cpu/LidDrivenCavityCPU/LidDrivenCavity.cpp b/apps/cpu/LidDrivenCavity/LidDrivenCavity.cpp similarity index 99% rename from apps/cpu/LidDrivenCavityCPU/LidDrivenCavity.cpp rename to apps/cpu/LidDrivenCavity/LidDrivenCavity.cpp index 618410d2064c577b9d22dd74a53297edaba47d32..daaa670abf35095babd770c50cdaecafd4c75493 100644 --- a/apps/cpu/LidDrivenCavityCPU/LidDrivenCavity.cpp +++ b/apps/cpu/LidDrivenCavity/LidDrivenCavity.cpp @@ -115,8 +115,12 @@ int main(int argc, char* argv[]) ppblocks.reset(); // Create LBM kernel + SPtr<LBMKernel> kernel = SPtr<LBMKernel>(new CumulantK17LBMKernel()); + //SPtr<LBMKernel> kernel = SPtr<LBMKernel>(new LBMKernelETD3Q27BGK()); + + ////////////////////////////////////////////////////////////////////////// // Create boundary conditions (BC) ////////////////////////////////////////////////////////////////////////// diff --git a/apps/cpu/LidDrivenCavityCPU/CMakeLists.txt b/apps/cpu/LidDrivenCavityCPU/CMakeLists.txt deleted file mode 100644 index dbcc5519841fc61e1ae5b454134aa352be4ba9a0..0000000000000000000000000000000000000000 --- a/apps/cpu/LidDrivenCavityCPU/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ - - -PROJECT(LidDrivenCavity) - -vf_add_library(BUILDTYPE binary DEPENDS VirtualFluidsCore basics FILES LidDrivenCavity.cpp) - -vf_get_library_name (library_name) -target_include_directories(${library_name} PRIVATE ${APPS_ROOT_CPU}) \ No newline at end of file diff --git a/cpu.cmake b/cpu.cmake index 050be2699bfa6a5a840d2946156f0efdf9f943d4..d829a720cfe384898a9122a85a5dc159166c825b 100644 --- a/cpu.cmake +++ b/cpu.cmake @@ -1,12 +1,4 @@ - -SET(USE_INTEL OFF CACHE BOOL "include Intel compiler support") -SET(USE_GCC OFF CACHE BOOL "include gcc compiler support") - - -#CAB -include("CMake/CMakeCABMacros.cmake") #TODO: Currently we have to include the CABMacros also here, so that the USE_* are defined in the config files for the cpu version - add_subdirectory(${VF_THIRD_DIR}/MuParser) add_subdirectory(src/cpu/VirtualFluidsCore) diff --git a/gpu.cmake b/gpu.cmake index 1d6ab6f2db516931d74f1fdc2718fd49d6560591..3aca8b9e407cb55fe2e8f6b86495e363a84fdead 100644 --- a/gpu.cmake +++ b/gpu.cmake @@ -1,30 +1,6 @@ -cmake_minimum_required(VERSION 3.9 FATAL_ERROR) - -if(POLICY CMP0042) - CMAKE_POLICY(SET CMP0042 NEW) -endif() -if(POLICY CMP0020) - CMAKE_POLICY(SET CMP0020 NEW) -endif() -if(POLICY CMP0028) - CMAKE_POLICY(SET CMP0028 NEW) -endif() -if(POLICY CMP0037) - CMAKE_POLICY(SET CMP0037 NEW) -endif() -if(POLICY CMP0047) - CMAKE_POLICY(SET CMP0047 NEW) -endif() -if(POLICY CMP0053) - CMAKE_POLICY(SET CMP0053 NEW) -endif() -if(POLICY CMP0054) - CMAKE_POLICY(SET CMP0054 NEW) -endif() - if(UNIX) - set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD 14) endif() ############################################################# @@ -41,32 +17,10 @@ endif() project(VirtualFluidsGPU) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -include_directories(${CMAKE_BINARY_DIR}/gpu) -# -#set(libraryFolder "libs") -#set(gksLibraryFolder "libs/GKS") -# -#set(testFolder "tests") -# -#set(appFolder "apps") -#set(lbmAppFolder "apps/LBM") -#set(gksAppFolder "apps/GKS") -# -#set(thirdPartyFolder "3rdParty") - -IF(MSVC) - ADD_DEFINITIONS ( "-DNOMINMAX" ) # Disable Min/Max-Macros - ADD_DEFINITIONS ( "-D_CRT_SECURE_NO_WARNINGS" ) # disable warnings promoting Microsoft's security enhanced CRT - ADD_DEFINITIONS ( "-D_SCL_SECURE_NO_WARNINGS" ) # disable warnings triggered by Microsoft's checked iterators - SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP" ) # enable multi-threaded compiling - SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj" ) # enable big object files (fatal error C1128) -ENDIF(MSVC) ############################################################# ### OPTIONS ### ############################################################# -option(BUILD_SHARED_LIBS "Build shared libraries" ON ) option(VF_DOUBLE_ACCURACY "Use double accuracy" ON ) @@ -75,8 +29,6 @@ option(VF_DOUBLE_ACCURACY "Use double accuracy" ON ) enable_language(CUDA) -#sharedLibs() - ############################################################# diff --git a/src/basics/CMakeLists.txt b/src/basics/CMakeLists.txt index 30fc6e9d17a76fae3626533d1d0238e99eb422ac..ff6c0c122ee9d2fc738e0fe67bba48ba621a95e1 100644 --- a/src/basics/CMakeLists.txt +++ b/src/basics/CMakeLists.txt @@ -1,18 +1,22 @@ include(Core/buildInfo.cmake) -vf_add_library(BUILDTYPE static EXCLUDE buildInfo.in.cpp) +vf_add_library(BUILDTYPE static EXCLUDE buildInfo.in.cpp VirtualFluidsDefinitions.in.h) vf_get_library_name (library_name) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Core) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/geometry3d) -target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics) +target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/geometry3d/KdTree) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics/container) +target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics/memory) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics/objects) +target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics/parallel) +target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics/transmitter) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics/utilities) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/basics/writer) + IF(MSVC) target_compile_definitions(${library_name} PUBLIC NOMINMAX) # Disable Min/Max-Macros ENDIF(MSVC) diff --git a/src/basics/VirtualFluidsDefinitions.in.h b/src/basics/VirtualFluidsDefinitions.in.h deleted file mode 100644 index 587a0a215d3d7e8886e1809f05568671f18f29d6..0000000000000000000000000000000000000000 --- a/src/basics/VirtualFluidsDefinitions.in.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef VIRTUAL_FLUIDS_DEFINITIONS_H -#define VIRTUAL_FLUIDS_DEFINITIONS_H - -#cmakedefine BUILD_SHARED_LIBS - -// disable warnings -#pragma warning(disable: 4251)// occurs normally while exporting standard library: "needs to have dll-interface to be" -#pragma warning(disable: 4275) // on dll-interface class <classname> used as base for dll-interface class <classname> - - -// double or single precision -#cmakedefine VF_DOUBLE_ACCURACY - -// External libraries -#cmakedefine VF_BUILD_WITH_MPI -#cmakedefine VF_BUILD_WITH_METIS -#cmakedefine VF_BUILD_WITH_CUDA - -// Compiler -#cmakedefine VF_CXX_COMPILER_IS_GNU -#cmakedefine VF_CXX_COMPILER_IS_INTEL -#cmakedefine VF_CXX_COMPILER_IS_IBM -#cmakedefine VF_CXX_COMPILER_IS_MSVC -#cmakedefine VF_CXX_COMPILER_IS_CLANG - -#endif diff --git a/src/basics/basics/utilities/UbMath.h b/src/basics/basics/utilities/UbMath.h index bf0466eee44ab9653e9070056fbe2dc9c4481829..659b66cc5d12dab588034e3f7997fe448f769a46 100644 --- a/src/basics/basics/utilities/UbMath.h +++ b/src/basics/basics/utilities/UbMath.h @@ -475,6 +475,26 @@ namespace UbMath static const double c56 = 56.0; static const double c152 = 152.0; static const double c130 = 130.0; + static const double one = 1.0; + static const double two = 2.0; + static const double three = 3.0; + static const double four = 4.0; + static const double five = 5.0; + static const double six = 6.0; + static const double seven = 7.0; + static const double eight = 8.0; + static const double nine = 9.0; + static const double fourteen = 14.0; + static const double fiveteen = 15.0; + static const double sixteen = 16.0; + static const double twentyone = 21.0; + static const double twentyfour = 24.0; + static const double twentyeight = 28.0; + static const double twentynine = 29.0; + static const double fourtyeight = 48.0; + static const double fifty = 50.0; + static const double fiftysix = 56.0; + } #endif diff --git a/src/basics/geometry3d/CoordinateTransformation3D.h b/src/basics/geometry3d/CoordinateTransformation3D.h index 9e7448fb9967d1a024b788eb43a4a459c13fb012..112f78789d2dda0f5db279a1ca83d82ff6d844d6 100644 --- a/src/basics/geometry3d/CoordinateTransformation3D.h +++ b/src/basics/geometry3d/CoordinateTransformation3D.h @@ -120,6 +120,13 @@ private: bool active; bool transformation; + friend class MPIIOCoProcessor; + friend class MPIIORestartCoProcessor; + friend class MPIIOMigrationCoProcessor; + friend class MPIIOMigrationBECoProcessor; + friend class CheckpointConverter; + + }; #endif //COORDINATETRANSFORMATION3D_H diff --git a/apps/cpu/VirtualFluids.h b/src/cpu/VirtualFluids.h similarity index 98% rename from apps/cpu/VirtualFluids.h rename to src/cpu/VirtualFluids.h index 360e0ec1d2a4141eabe7694ada015fe156be0468..84f2f35176d15eecbd3773fc9e5253311a68c94f 100644 --- a/apps/cpu/VirtualFluids.h +++ b/src/cpu/VirtualFluids.h @@ -40,9 +40,9 @@ #include <omp.h> #endif -#include <PointerDefinitions.h> +#include <basics/PointerDefinitions.h> -#include <MuParser/include/muParser.h> +#include <muParser.h> #include <basics/container/CbArray2D.h> #include <basics/container/CbArray3D.h> diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h index 241d935a072dc4e846f2dad5f0180a2ac9ebe929..a34f899ae53df3fe4f48cd9b252a9c63bc4ff9a7 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h @@ -89,4 +89,4 @@ protected: }; -#endif +#endif //D3Q27BOUNDARYCONDITIONADAPTER_H diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h index 8dd8712f159b91d5153ae74d252fdf3ee78cf85a..af9a63031803ab964ffa7c63c161e479170b2ea4 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h @@ -36,7 +36,7 @@ #include <basics/utilities/UbInfinity.h> -#include <MuParser/include/muParser.h> +#include <muParser.h> //! A class implements function parcer for boundary conditions class BCFunction diff --git a/src/cpu/VirtualFluidsCore/CMakeLists.txt b/src/cpu/VirtualFluidsCore/CMakeLists.txt index 3bdae4630a004d4fa858f48a5ced701fd83799df..c17c6fba35e864b44f99c80e6be99bdc18e4919d 100644 --- a/src/cpu/VirtualFluidsCore/CMakeLists.txt +++ b/src/cpu/VirtualFluidsCore/CMakeLists.txt @@ -10,7 +10,7 @@ IF(${USE_INTEL}) ENDIF() -vf_add_library(BUILDTYPE static DEPENDS basics MuParser ${CAB_ADDITIONAL_LINK_LIBRARIES}) +vf_add_library(BUILDTYPE static DEPENDS basics muparser ${CAB_ADDITIONAL_LINK_LIBRARIES}) vf_get_library_name(library_name) @@ -24,7 +24,3 @@ target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Gr target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Visitors) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/CoProcessors) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Utilities) - - -target_include_directories(${library_name} PUBLIC ${VF_THIRD_DIR}) - diff --git a/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h b/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h index ba32e1280c901fe667cc087377d69fe422d934ee..ba7b5d9ccd7d6b831c39f964b6f8c6ca354ab579 100644 --- a/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h +++ b/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h @@ -39,7 +39,7 @@ #include "ILBMKernel.h" #include <array> #include <limits> -#include <MuParser/include/muParser.h> +#include <muParser.h> class BCProcessor; class DataSet3D; diff --git a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h index 789953e294c5c3b4e8bb49e0181fcd16c14803da..1e7425796e7502b9caf7049141ffc37af051ae62 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h @@ -39,7 +39,7 @@ #include "Block3DVisitor.h" #include "D3Q27System.h" -#include <MuParser/include/muParser.h> +#include <muParser.h> class Grid3D; class Block3D;