CppCheck.

--HG--
branch : feature
This commit is contained in:
dismine 2014-05-02 11:09:10 +03:00
parent 362638066a
commit 79ef0e914e
13 changed files with 86 additions and 40 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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),

View File

@ -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<char_type> >(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<char_type> >(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<char_type>('.'));
@ -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<token_type> stOpt, stVal;
QStack<int> 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)

View File

@ -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);

View File

@ -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();

View File

@ -80,25 +80,6 @@ struct SToken
*/
class QmuParserByteCode
{
private:
/** @brief Token type for internal use only. */
typedef QmuParserToken<qreal, string_type> token_type;
/** @brief Token vector for storing the RPN. */
typedef QVector<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:
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<qreal, string_type> token_type;
/** @brief Token vector for storing the RPN. */
typedef QVector<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);
};
} // namespace qmu
#endif

View File

@ -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;

View File

@ -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();

View File

@ -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();
};

View File

@ -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);

View File

@ -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

View File

@ -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();