From: wolf Date: Thu, 30 Jun 2005 15:12:48 +0000 (+0000) Subject: Import version 2.71 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cd72c980b976176cd949a87584367a198d2c714;p=dealii-svn.git Import version 2.71 git-svn-id: https://svn.dealii.org/trunk@10988 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/contrib/functionparser/fparser.cc b/deal.II/contrib/functionparser/fparser.cc index 65c815cd2b..ddc27ed576 100644 --- a/deal.II/contrib/functionparser/fparser.cc +++ b/deal.II/contrib/functionparser/fparser.cc @@ -1,6 +1,6 @@ -//============================== -// Function parser v2.7 by Warp -//============================== +//=============================== +// Function parser v2.71 by Warp +//=============================== // Comment out the following line if your compiler supports the (non-standard) // asinh, acosh and atanh functions and you want them to be supported. If @@ -18,7 +18,9 @@ // but it will not do anything. // If you are unsure, just leave it. It won't slow down the other parts of // the library. +#ifndef NO_SUPPORT_OPTIMIZER #define SUPPORT_OPTIMIZER +#endif //============================================================================ @@ -31,7 +33,6 @@ #include using namespace std; -using namespace fparser; #ifndef M_PI #define M_PI 3.1415926535897932384626433832795 @@ -1398,6 +1399,10 @@ public: compres(char v) : state(v) {} // is it? operator bool() const { return state != 0; } + // is it not? + bool operator! () const { return state != 1; } + bool operator==(bool b) const { return state != !b; } + bool operator!=(bool b) const { return state != b; } private: char state; }; @@ -1502,8 +1507,10 @@ public: UpdateValue(); } + bool IsOriginal() const { return !(IsInverted() || IsNegated()); } bool IsInverted() const { return inverted; } bool IsNegated() const { return negated; } + bool IsInvertedOriginal() const { return IsInverted() && !IsNegated(); } bool IsNegatedOriginal() const { return !IsInverted() && IsNegated(); } private: @@ -1559,7 +1566,9 @@ public: return *this; } const CodeTreeData *operator-> () const { return &p->first; } + const CodeTreeData &operator* () const { return p->first; } CodeTreeData *operator-> () { PrepareForWrite(); return &p->first; } + CodeTreeData &operator* () { PrepareForWrite(); return p->first; } void Shock(); }; @@ -1597,6 +1606,7 @@ public: SubTree& getp0() { /*chk<1>();*/pit tmp=GetBegin(); return *tmp; } SubTree& getp1() { /*chk<2>();*/pit tmp=GetBegin(); ++tmp; return *tmp; } + SubTree& getp2() { /*chk<3>();*/pit tmp=GetBegin(); ++tmp; ++tmp; return *tmp; } // set void SetImmed(double v) { data->SetImmed(v); } @@ -1616,6 +1626,8 @@ public: compres NonZero() const { if(!IsImmed()) return maybe; return GetImmed() != 0.0; } + compres IsPositive() const { if(!IsImmed()) return maybe; + return GetImmed() > 0.0; } private: struct ConstList @@ -3161,7 +3173,7 @@ void FunctionParser::Optimize() #else /* !SUPPORT_OPTIMIZER */ /* keep the linker happy */ -void FunctionParser::MakeTree(CodeTree *) const {} +void FunctionParser::MakeTree(void *) const {} void FunctionParser::Optimize() { // Do nothing if no optimizations are supported. diff --git a/deal.II/contrib/functionparser/fparser.h b/deal.II/contrib/functionparser/fparser.h index b3a2988b0d..9506bfaa59 100644 --- a/deal.II/contrib/functionparser/fparser.h +++ b/deal.II/contrib/functionparser/fparser.h @@ -1,6 +1,6 @@ /***************************************************************************\ -|* Function parser v2.7 by Warp *| -|* ---------------------------- *| +|* Function parser v2.71 by Warp *| +|* ----------------------------- *| |* Parses and evaluates the given function with the given variable values. *| |* *| \***************************************************************************/ @@ -16,68 +16,64 @@ #include #endif -namespace fparser { - class FunctionParser +class FunctionParser +{ +public: + enum ParseErrorType { - public: - enum ParseErrorType - { - SYNTAX_ERROR=0, MISM_PARENTH, MISSING_PARENTH, EMPTY_PARENTH, - EXPECT_OPERATOR, OUT_OF_MEMORY, UNEXPECTED_ERROR, INVALID_VARS, - ILL_PARAMS_AMOUNT, PREMATURE_EOS, EXPECT_PARENTH_FUNC, - FP_NO_ERROR - }; + SYNTAX_ERROR=0, MISM_PARENTH, MISSING_PARENTH, EMPTY_PARENTH, + EXPECT_OPERATOR, OUT_OF_MEMORY, UNEXPECTED_ERROR, INVALID_VARS, + ILL_PARAMS_AMOUNT, PREMATURE_EOS, EXPECT_PARENTH_FUNC, + FP_NO_ERROR + }; - int Parse(const std::string& Function, const std::string& Vars, - bool useDegrees = false); - const char* ErrorMsg() const; - inline ParseErrorType GetParseErrorType() const { return parseErrorType; } + int Parse(const std::string& Function, const std::string& Vars, + bool useDegrees = false); + const char* ErrorMsg() const; + inline ParseErrorType GetParseErrorType() const { return parseErrorType; } - double Eval(const double* Vars); - inline int EvalError() const { return evalErrorType; } + double Eval(const double* Vars); + inline int EvalError() const { return evalErrorType; } - bool AddConstant(const std::string& name, double value); + bool AddConstant(const std::string& name, double value); - typedef double (*FunctionPtr)(const double*); + typedef double (*FunctionPtr)(const double*); - bool AddFunction(const std::string& name, - FunctionPtr, unsigned paramsAmount); - bool AddFunction(const std::string& name, FunctionParser&); + bool AddFunction(const std::string& name, + FunctionPtr, unsigned paramsAmount); + bool AddFunction(const std::string& name, FunctionParser&); - void Optimize(); + void Optimize(); - FunctionParser(); - ~FunctionParser(); + FunctionParser(); + ~FunctionParser(); - // Copy constructor and assignment operator (implemented using the - // copy-on-write technique for efficiency): - FunctionParser(const FunctionParser&); - FunctionParser& operator=(const FunctionParser&); + // Copy constructor and assignment operator (implemented using the + // copy-on-write technique for efficiency): + FunctionParser(const FunctionParser&); + FunctionParser& operator=(const FunctionParser&); #ifdef FUNCTIONPARSER_SUPPORT_DEBUG_OUTPUT - // For debugging purposes only: - void PrintByteCode(std::ostream& dest) const; + // For debugging purposes only: + void PrintByteCode(std::ostream& dest) const; #endif - // Added by Luca Heltai. For consistency checking. - unsigned int NVars() { - return data->varAmount; - }; - //======================================================================== - private: - //======================================================================== - // Private data: - // ------------ - ParseErrorType parseErrorType; - int evalErrorType; +//======================================================================== +private: +//======================================================================== + +// Private data: +// ------------ + ParseErrorType parseErrorType; + int evalErrorType; - struct Data - { + struct Data + { unsigned referenceCounter; int varAmount; @@ -92,8 +88,8 @@ namespace fparser { VarMap_t FuncPtrNames; struct FuncPtrData { - FunctionPtr ptr; unsigned params; - FuncPtrData(FunctionPtr p, unsigned par): ptr(p), params(par) {} + FunctionPtr ptr; unsigned params; + FuncPtrData(FunctionPtr p, unsigned par): ptr(p), params(par) {} }; std::vector FuncPtrs; @@ -112,51 +108,48 @@ namespace fparser { Data(const Data&); Data& operator=(const Data&); // not implemented on purpose - }; - - Data* data; - - // Temp data needed in Compile(): - unsigned StackPtr; - std::vector* tempByteCode; - std::vector* tempImmed; - - - // Private methods: - // --------------- - inline void copyOnWrite(); - - - bool checkRecursiveLinking(const FunctionParser*) const; - - bool isValidName(const std::string&) const; - inline - Data::VarMap_t::const_iterator FindVariable(const char*, - const Data::VarMap_t&) const; - inline - Data::ConstMap_t::const_iterator FindConstant(const char*) const; - int CheckSyntax(const char*); - bool Compile(const char*); - bool IsVariable(int); - void AddCompiledByte(unsigned); - void AddImmediate(double); - void AddFunctionOpcode(unsigned); - inline void incStackPtr(); - int CompileIf(const char*, int); - int CompileFunctionParams(const char*, int, unsigned); - int CompileElement(const char*, int); - int CompilePow(const char*, int); - int CompileUnaryMinus(const char*, int); - int CompileMult(const char*, int); - int CompileAddition(const char*, int); - int CompileComparison(const char*, int); - int CompileAnd(const char*, int); - int CompileOr(const char*, int); - int CompileExpression(const char*, int, bool=false); - - - void MakeTree(void*) const; }; -} + + Data* data; + + // Temp data needed in Compile(): + unsigned StackPtr; + std::vector* tempByteCode; + std::vector* tempImmed; + + +// Private methods: +// --------------- + inline void copyOnWrite(); + + + bool checkRecursiveLinking(const FunctionParser*) const; + + bool isValidName(const std::string&) const; + Data::VarMap_t::const_iterator FindVariable(const char*, + const Data::VarMap_t&) const; + Data::ConstMap_t::const_iterator FindConstant(const char*) const; + int CheckSyntax(const char*); + bool Compile(const char*); + bool IsVariable(int); + void AddCompiledByte(unsigned); + void AddImmediate(double); + void AddFunctionOpcode(unsigned); + inline void incStackPtr(); + int CompileIf(const char*, int); + int CompileFunctionParams(const char*, int, unsigned); + int CompileElement(const char*, int); + int CompilePow(const char*, int); + int CompileUnaryMinus(const char*, int); + int CompileMult(const char*, int); + int CompileAddition(const char*, int); + int CompileComparison(const char*, int); + int CompileAnd(const char*, int); + int CompileOr(const char*, int); + int CompileExpression(const char*, int, bool=false); + + + void MakeTree(void*) const; +}; #endif diff --git a/deal.II/contrib/functionparser/fparser.txt b/deal.II/contrib/functionparser/fparser.txt index cd2263a2fa..d54e5ec260 100644 --- a/deal.II/contrib/functionparser/fparser.txt +++ b/deal.II/contrib/functionparser/fparser.txt @@ -1,5 +1,5 @@ - Function parser for C++ v2.7 by Warp. - ===================================== + Function parser for C++ v2.71 by Warp. + ====================================== Optimization code contributed by Bisqwit (http://iki.fi/bisqwit/) @@ -8,6 +8,14 @@ + What's new in v2.71 + ------------------- + - Fixed a couple of syntax errors which slipped through in the v2.7 + distribution version: + * non-standard semicolons at the end of namespace blocks + * a compilation error which happens if SUPPORT_OPTIMIZER is disabled + - Included a simple example program. + What's new in v2.7 ------------------ - Changed precedence rules for unary minus and the power operator (^) to