From 79ef0e914e28127a03f4adcf16347997733a8c77 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 2 May 2014 11:09:10 +0300 Subject: [PATCH] CppCheck. --HG-- branch : feature --- src/app/container/vcontainer.cpp | 1 + src/app/tools/drawTools/vabstractspline.cpp | 2 ++ src/libs/qmuparser/qmuparser.cpp | 1 + src/libs/qmuparser/qmuparserbase.cpp | 32 ++++++++++++----- src/libs/qmuparser/qmuparserbase.h | 6 ++-- src/libs/qmuparser/qmuparserbytecode.cpp | 5 +++ src/libs/qmuparser/qmuparserbytecode.h | 38 ++++++++++----------- src/libs/qmuparser/qmuparsercallback.cpp | 3 +- src/libs/qmuparser/qmuparsererror.cpp | 6 ++-- src/libs/qmuparser/qmuparsererror.h | 2 +- src/libs/qmuparser/qmuparsertest.cpp | 4 ++- src/libs/qmuparser/qmuparsertest.h | 21 +++++++++--- src/libs/qmuparser/qmuparsertokenreader.cpp | 5 ++- 13 files changed, 86 insertions(+), 40 deletions(-) diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index e3d954f42..d8c0f4ca8 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -106,6 +106,7 @@ void VContainer::setData(const VContainer &data) details = *data.DataDetails(); } +// cppcheck-suppress unusedFunction const VGObject *VContainer::GetGObject(quint32 id)const { return GetObject(gObjects, id); diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index 3f4ce2cdc..9ca601d57 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -73,12 +73,14 @@ void VAbstractSpline::SetFactor(qreal factor) RefreshGeometry(); } +// cppcheck-suppress unusedFunction void VAbstractSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor)); } +// cppcheck-suppress unusedFunction void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); diff --git a/src/libs/qmuparser/qmuparser.cpp b/src/libs/qmuparser/qmuparser.cpp index 09919f9c4..96fc7b9c7 100644 --- a/src/libs/qmuparser/qmuparser.cpp +++ b/src/libs/qmuparser/qmuparser.cpp @@ -372,6 +372,7 @@ void QmuParser::OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) * * http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843 */ +// cppcheck-suppress unusedFunction qreal QmuParser::Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon) const { qreal fRes(0), diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index 3b29c6396..14b3487f7 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -153,6 +153,7 @@ void QmuParserBase::Assign(const QmuParserBase &a_Parser) * By default muparser uses the "C" locale. The decimal separator of this * locale is overwritten by the one provided here. */ +// cppcheck-suppress unusedFunction void QmuParserBase::SetDecSep(char_type cDecSep) { char_type cThousandsSep = std::use_facet< change_dec_sep >(s_locale).thousands_sep(); @@ -168,6 +169,7 @@ void QmuParserBase::SetDecSep(char_type cDecSep) * By default muparser uses the "C" locale. The thousands separator of this * locale is overwritten by the one provided here. */ +// cppcheck-suppress unusedFunction void QmuParserBase::SetThousandsSep(char_type cThousandsSep) { char_type cDecSep = std::use_facet< change_dec_sep >(s_locale).decimal_point(); @@ -180,6 +182,7 @@ void QmuParserBase::SetThousandsSep(char_type cThousandsSep) * * The default locale used "." as decimal separator, no thousands separator and "," as function argument separator. */ +// cppcheck-suppress unusedFunction void QmuParserBase::ResetLocale() { s_locale = std::locale(std::locale("C"), new change_dec_sep('.')); @@ -231,7 +234,8 @@ void QmuParserBase::OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) * * Format is as follows: "MAJOR.MINOR (COMPILER_FLAGS)" The COMPILER_FLAGS are returned only if eInfo==pviFULL. */ -QString QmuParserBase::GetVersion(EParserVersionInfo eInfo) const +// cppcheck-suppress unusedFunction +QString QmuParserBase::GetVersion(EParserVersionInfo eInfo) { QString versionInfo; QTextStream ss(&versionInfo); @@ -294,6 +298,7 @@ void QmuParserBase::AddValIdent(identfun_type a_pCallback) * @param a_pFactory A pointer to the variable factory. * @param pUserData A user defined context pointer. */ +// cppcheck-suppress unusedFunction void QmuParserBase::SetVarFactory(facfun_type a_pFactory, void *pUserData) { m_pTokenReader->SetVarCreator(a_pFactory, pUserData); @@ -529,7 +534,7 @@ void QmuParserBase::SetExpr(const QString &a_sExpr) * @brief Get the default symbols used for the built in operators. * @sa c_DefaultOprt */ -const QStringList &QmuParserBase::GetOprtDef() const +const QStringList &QmuParserBase::GetOprtDef() { return c_DefaultOprt; } @@ -611,6 +616,7 @@ void QmuParserBase::DefinePostfixOprt(const QString &a_sName, fun_type1 a_pFun, * * Calls the virtual functions InitFun(), InitConst() and InitOprt(). */ +// cppcheck-suppress unusedFunction void QmuParserBase::Init() { InitCharSets(); @@ -668,6 +674,7 @@ void QmuParserBase::DefineOprt( const QString &a_sName, fun_type2 a_pFun, unsign * @param [in] a_strName The name of the constant. * @param [in] a_strVal the value of the constant. */ +// cppcheck-suppress unusedFunction void QmuParserBase::DefineStrConst(const QString &a_strName, const QString &a_strVal) { // Test if a constant with that names already exists @@ -930,13 +937,13 @@ const varmap_type& QmuParserBase::GetUsedVar() const m_pParseFormula = &QmuParserBase::ParseString; m_pTokenReader->IgnoreUndefVar(false); } - catch (exception_type &e) + catch (const 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 = &QmuParserBase::ParseString; m_pTokenReader->IgnoreUndefVar(false); - throw e; + throw; } return m_pTokenReader->GetUsedVar(); } @@ -1780,8 +1787,8 @@ void QmuParserBase::CreateRPN() const QStack stOpt, stVal; QStack stArgCount; token_type opta, opt; // for storing operators - token_type val, tval; // for storing value - string_type strBuf; // buffer for string function arguments + //token_type val, tval; // for storing value + //string_type strBuf; // buffer for string function arguments ReInit(); @@ -2074,6 +2081,7 @@ void Q_NORETURN QmuParserBase::Error(EErrorCodes a_iErrc, int a_iPos, const QStr * * Resets the parser to string parsing mode by calling #ReInit. */ +// cppcheck-suppress unusedFunction void QmuParserBase::ClearVar() { m_VarDef.clear(); @@ -2103,6 +2111,7 @@ void QmuParserBase::RemoveVar(const QString &a_strVarName) * @post Resets the parser to string parsing mode. * @throw nothrow */ +// cppcheck-suppress unusedFunction void QmuParserBase::ClearFun() { m_FunDef.clear(); @@ -2142,6 +2151,7 @@ void QmuParserBase::ClearPostfixOprt() * @post Resets the parser to string parsing mode. * @throw nothrow */ +// cppcheck-suppress unusedFunction void QmuParserBase::ClearOprt() { m_OprtDef.clear(); @@ -2154,6 +2164,7 @@ void QmuParserBase::ClearOprt() * @post Resets the parser to string parser mode. * @throw nothrow */ +// cppcheck-suppress unusedFunction void QmuParserBase::ClearInfixOprt() { m_InfixOprtDef.clear(); @@ -2180,6 +2191,7 @@ void QmuParserBase::EnableOptimizer(bool a_bIsOn) * * This function is for debug purposes only! */ +// cppcheck-suppress unusedFunction void QmuParserBase::EnableDebugDump(bool bDumpCmd, bool bDumpStack) { QmuParserBase::g_DbgDumpCmdCode = bDumpCmd; @@ -2410,6 +2422,7 @@ qreal* QmuParserBase::Eval(int &nStackSize) const * If the expression contains comma seperated subexpressions (i.e. "sin(y), x+y"). There mey be more than one return * value. This function returns the number of available results. */ +// cppcheck-suppress unusedFunction int QmuParserBase::GetNumResults() const { return m_nFinalResultIdx; @@ -2438,7 +2451,7 @@ qreal QmuParserBase::Eval() const } //--------------------------------------------------------------------------------------------------------------------- -void QmuParserBase::Eval(qreal *results, int nBulkSize) +void QmuParserBase::Eval(qreal *results, int nBulkSize) const { CreateRPN(); @@ -2452,7 +2465,10 @@ void QmuParserBase::Eval(qreal *results, int nBulkSize) #endif int nMaxThreads = qMin(omp_get_max_threads(), s_MaxNumOpenMPThreads); - int nThreadID, ct=0; + // cppcheck-suppress variableScope + int nThreadID; + // cppcheck-suppress unreadVariable + int ct=0; omp_set_num_threads(nMaxThreads); #pragma omp parallel for schedule(static, nBulkSize/nMaxThreads) private(nThreadID) diff --git a/src/libs/qmuparser/qmuparserbase.h b/src/libs/qmuparser/qmuparserbase.h index 7b7ac88ca..dd6721892 100644 --- a/src/libs/qmuparser/qmuparserbase.h +++ b/src/libs/qmuparser/qmuparserbase.h @@ -70,7 +70,7 @@ public: static void EnableDebugDump(bool bDumpCmd, bool bDumpStack); qreal Eval() const; qreal* Eval(int &nStackSize) const; - void Eval(qreal *results, int nBulkSize); + void Eval(qreal *results, int nBulkSize) const; int GetNumResults() const; void SetExpr(const QString &a_sExpr); void SetVarFactory(facfun_type a_pFactory, void *pUserData = NULL); @@ -102,8 +102,8 @@ public: const valmap_type& GetConst() const; const QString& GetExpr() const; const funmap_type& GetFunDef() const; - QString GetVersion(EParserVersionInfo eInfo = pviFULL) const; - const QStringList& GetOprtDef() const; + static QString GetVersion(EParserVersionInfo eInfo = pviFULL); + static const QStringList& GetOprtDef(); void DefineNameChars(const QString &a_szCharset); void DefineOprtChars(const QString &a_szCharset); void DefineInfixOprtChars(const QString &a_szCharset); diff --git a/src/libs/qmuparser/qmuparserbytecode.cpp b/src/libs/qmuparser/qmuparserbytecode.cpp index 296d89c53..1a0e79dda 100644 --- a/src/libs/qmuparser/qmuparserbytecode.cpp +++ b/src/libs/qmuparser/qmuparserbytecode.cpp @@ -39,6 +39,7 @@ namespace qmu /** * @brief Bytecode default constructor. */ +// cppcheck-suppress uninitMemberVar QmuParserByteCode::QmuParserByteCode() :m_iStackPos(0), m_iMaxStackSize(0), m_vRPN(), m_bEnableOptimizer(true) { @@ -51,6 +52,7 @@ QmuParserByteCode::QmuParserByteCode() * * Implemented in Terms of Assign(const QParserByteCode &a_ByteCode) */ +// cppcheck-suppress uninitMemberVar QmuParserByteCode::QmuParserByteCode(const QmuParserByteCode &a_ByteCode) :m_iStackPos(a_ByteCode.m_iStackPos), m_iMaxStackSize(a_ByteCode.m_iMaxStackSize), m_vRPN(a_ByteCode.m_vRPN), m_bEnableOptimizer(true) @@ -64,6 +66,7 @@ QmuParserByteCode::QmuParserByteCode(const QmuParserByteCode &a_ByteCode) * * Implemented in Terms of Assign(const QParserByteCode &a_ByteCode) */ +// cppcheck-suppress operatorEqVarError QmuParserByteCode& QmuParserByteCode::operator=(const QmuParserByteCode &a_ByteCode) { Assign(a_ByteCode); @@ -92,6 +95,7 @@ void QmuParserByteCode::Assign(const QmuParserByteCode &a_ByteCode) m_iStackPos = a_ByteCode.m_iStackPos; m_vRPN = a_ByteCode.m_vRPN; m_iMaxStackSize = a_ByteCode.m_iMaxStackSize; + m_bEnableOptimizer = a_ByteCode.m_bEnableOptimizer; } //--------------------------------------------------------------------------------------------------------------------- @@ -793,6 +797,7 @@ std::size_t QmuParserByteCode::GetMaxStackSize() const /** * @brief Returns the number of entries in the bytecode. */ +// cppcheck-suppress unusedFunction std::size_t QmuParserByteCode::GetSize() const { return m_vRPN.size(); diff --git a/src/libs/qmuparser/qmuparserbytecode.h b/src/libs/qmuparser/qmuparserbytecode.h index 51c4f518d..032c41108 100644 --- a/src/libs/qmuparser/qmuparserbytecode.h +++ b/src/libs/qmuparser/qmuparserbytecode.h @@ -80,25 +80,6 @@ struct SToken */ class QmuParserByteCode { -private: - /** @brief Token type for internal use only. */ - typedef QmuParserToken token_type; - - /** @brief Token vector for storing the RPN. */ - typedef QVector 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: QmuParserByteCode(); QmuParserByteCode(const QmuParserByteCode &a_ByteCode); @@ -119,6 +100,25 @@ public: std::size_t GetSize() const; const SToken* GetBase() const; void AsciiDump(); +private: + /** @brief Token type for internal use only. */ + typedef QmuParserToken token_type; + + /** @brief Token vector for storing the RPN. */ + typedef QVector 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); }; } // namespace qmu #endif diff --git a/src/libs/qmuparser/qmuparsercallback.cpp b/src/libs/qmuparser/qmuparsercallback.cpp index 139d91092..bb3ea9b94 100644 --- a/src/libs/qmuparser/qmuparsercallback.cpp +++ b/src/libs/qmuparser/qmuparsercallback.cpp @@ -332,11 +332,12 @@ QmuParserCallback* QmuParserCallback::Clone() const //--------------------------------------------------------------------------------------------------------------------- /** - * @brief Return tru if the function is conservative. + * @brief Return true if the function is conservative. * * Conservative functions return always the same result for the same argument. * @throw nothrow */ +// cppcheck-suppress unusedFunction bool QmuParserCallback::IsOptimizable() const { return m_bAllowOpti; diff --git a/src/libs/qmuparser/qmuparsererror.cpp b/src/libs/qmuparser/qmuparsererror.cpp index ab5c237cb..9fd28bb5c 100644 --- a/src/libs/qmuparser/qmuparsererror.cpp +++ b/src/libs/qmuparser/qmuparsererror.cpp @@ -29,6 +29,7 @@ namespace qmu const QmuParserErrorMsg QmuParserErrorMsg::m_Instance; //--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction const QmuParserErrorMsg& QmuParserErrorMsg::Instance() { return m_Instance; @@ -225,11 +226,11 @@ QmuParserError::~QmuParserError() void QmuParserError::ReplaceSubString ( QString &strSource, const QString &strFind, const QString &strReplaceWith ) { QString strResult; - int iPos ( 0 ), iNext ( 0 ); + int iPos ( 0 ); for ( ;; ) { - iNext = strSource.indexOf ( strFind, iPos ); + int iNext = strSource.indexOf ( strFind, iPos ); strResult.append ( strSource.mid ( iPos, iNext - iPos ) ); if ( iNext == -1 ) @@ -248,6 +249,7 @@ void QmuParserError::ReplaceSubString ( QString &strSource, const QString &strFi /** * @brief Reset the erro object. */ +// cppcheck-suppress unusedFunction void QmuParserError::Reset() { m_strMsg.clear(); diff --git a/src/libs/qmuparser/qmuparsererror.h b/src/libs/qmuparser/qmuparsererror.h index 645fba258..2a86e2829 100644 --- a/src/libs/qmuparser/qmuparsererror.h +++ b/src/libs/qmuparser/qmuparsererror.h @@ -148,7 +148,7 @@ private: /** * @brief Replace all ocuurences of a substring with another string. */ - void ReplaceSubString ( QString &strSource, const QString &strFind, const QString &strReplaceWith ); + static void ReplaceSubString ( QString &strSource, const QString &strFind, const QString &strReplaceWith ); void Reset(); }; diff --git a/src/libs/qmuparser/qmuparsertest.cpp b/src/libs/qmuparser/qmuparsertest.cpp index 95305cdc5..cd9644cde 100644 --- a/src/libs/qmuparser/qmuparsertest.cpp +++ b/src/libs/qmuparser/qmuparsertest.cpp @@ -1065,6 +1065,7 @@ void QmuParserTester::AddTest ( testfun_type a_pFun ) } //--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction void QmuParserTester::Run() { int iStat = 0; @@ -1179,6 +1180,7 @@ int QmuParserTester::EqnTestWithVarChange ( const QString &a_str, double a_fVar1 var = a_fVar1; fVal[0] = p.Eval(); + // cppcheck-suppress redundantAssignment var = a_fVar2; fVal[1] = p.Eval(); @@ -1404,7 +1406,7 @@ int QmuParserTester::EqnTest ( const QString &a_str, double a_fRes, bool a_fPass /** * @brief Internal error in test class Test is going to be aborted. */ -void Q_NORETURN QmuParserTester::Abort() const +void Q_NORETURN QmuParserTester::Abort() { qDebug() << "Test failed (internal error in test class)"; while ( getchar() == false); diff --git a/src/libs/qmuparser/qmuparsertest.h b/src/libs/qmuparser/qmuparsertest.h index 648e6fb9c..ffa838ed8 100644 --- a/src/libs/qmuparser/qmuparsertest.h +++ b/src/libs/qmuparser/qmuparsertest.h @@ -61,9 +61,10 @@ private: void AddTest ( testfun_type a_pFun ); // Test Double Parser - int EqnTest ( const QString &a_str, double a_fRes, bool a_fPass ); - int EqnTestWithVarChange ( const QString &a_str, double a_fRes1, double a_fVar1, double a_fRes2, double a_fVar2 ); - int ThrowTest ( const QString &a_str, int a_iErrc, bool a_bFail = true ); + static int EqnTest ( const QString &a_str, double a_fRes, bool a_fPass ); + static int EqnTestWithVarChange ( const QString &a_str, double a_fRes1, double a_fVar1, double a_fRes2, + double a_fVar2 ); + static int ThrowTest ( const QString &a_str, int a_iErrc, bool a_bFail = true ); // Multiarg callbacks static qreal f1of1 ( qreal v ) @@ -279,20 +280,32 @@ private: // Custom value recognition static int IsHexVal ( const QString &a_szExpr, int *a_iPos, qreal *a_fVal ); + // cppcheck-suppress functionStatic int TestNames(); + // cppcheck-suppress functionStatic int TestSyntax(); + // cppcheck-suppress functionStatic int TestMultiArg(); + // cppcheck-suppress functionStatic int TestPostFix(); + // cppcheck-suppress functionStatic int TestExpression(); + // cppcheck-suppress functionStatic int TestInfixOprt(); + // cppcheck-suppress functionStatic int TestBinOprt(); + // cppcheck-suppress functionStatic int TestVarConst(); + // cppcheck-suppress functionStatic int TestInterface(); + // cppcheck-suppress functionStatic int TestException(); + // cppcheck-suppress functionStatic int TestStrArg(); + // cppcheck-suppress functionStatic int TestIfThenElse(); - void Abort() const; + static void Abort(); }; } // namespace Test } // namespace qmu diff --git a/src/libs/qmuparser/qmuparsertokenreader.cpp b/src/libs/qmuparser/qmuparsertokenreader.cpp index 485bdbda0..074621d53 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.cpp +++ b/src/libs/qmuparser/qmuparsertokenreader.cpp @@ -101,6 +101,9 @@ void QmuParserTokenReader::Assign ( const QmuParserTokenReader &a_Reader ) m_pFactoryData = a_Reader.m_pFactoryData; m_iBrackets = a_Reader.m_iBrackets; m_cArgSep = a_Reader.m_cArgSep; + + m_fZero = 0; + m_lastTok = token_type(); } //--------------------------------------------------------------------------------------------------------------------- @@ -363,7 +366,7 @@ int QmuParserTokenReader::ExtractToken ( const QString &a_szCharSet, QString &a_ { #if defined(_UNICODE) const std::wstring m_strFormulaStd = m_strFormula.toStdWString(); - const std::wstring a_szCharSetstd = a_szCharSet.toStdWString(); + const std::wstring a_szCharSetStd = a_szCharSet.toStdWString(); #else const std::string m_strFormulaStd = m_strFormula.toStdString(); const std::string a_szCharSetStd = a_szCharSet.toStdString();