From f14d961d2c294d3d7bcc820dc27bd32b3e3a5197 Mon Sep 17 00:00:00 2001 From: qykth-git <14939671+qykth-git@users.noreply.github.com> Date: Tue, 24 Aug 2021 03:27:05 +0900 Subject: [PATCH] Compiler warnings fix (#64) * Enable warnings * Work without "-fpermissive" option * Cosmetic fix * Add "const" to fix warnings These strings are not needs to modify. * No need to use "#pragma once" in main C++ source file * Cosmetic fix Add newline to end * Return nullptr if error * delete() not works for "void*" Cast specific type to use delete() * Disable VC++ specific pragmas for other C++ compilers * Fix warning * Fix warning * Use pipeline for compiler * Enable code optimization * Add "default:" to fix "switch" syntax warning * Use "nullptr" for null pointer * Use nullptr instead of NULL * Use nullptr instead of NULL * Use "L" notation for wide character * Use C++ header instead of raw C header --- Makefile | 3 +- api/combination.cpp | 6 +-- api/generator.h | 10 ++-- api/model.cpp | 6 +-- api/pictapi.cpp | 6 +-- api/pictapi.h | 18 ++++---- api/task.cpp | 18 ++++---- api/trie.h | 14 +++--- cli/ccommon.cpp | 12 +++-- cli/ccommon.h | 109 +++++++++++++++++++++++++++----------------- cli/cmdline.cpp | 2 +- cli/common.cpp | 6 +-- cli/common.h | 8 ++-- cli/cparser.cpp | 23 ++++++---- cli/ctokenizer.cpp | 18 ++++---- cli/gcdexcl.cpp | 8 ++-- cli/gcdmodel.cpp | 2 - cli/model.cpp | 2 +- cli/model.h | 2 +- cli/mparser.cpp | 2 +- cli/pict.cpp | 4 +- cli/strings.cpp | 6 +-- cli/strings.h | 2 +- 23 files changed, 162 insertions(+), 125 deletions(-) diff --git a/Makefile b/Makefile index 5a140e2..f720a2d 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,7 @@ # variables used to generate a source snapshot of the GIT repo COMMIT=$(shell git log --pretty=format:'%H' -n 1) SHORT_COMMIT=$(shell git log --pretty=format:'%h' -n 1) -# suppress all warnings :-( -CXXFLAGS=-fPIC -std=c++11 -Iapi -w -fpermissive +CXXFLAGS=-fPIC -pipe -std=c++11 -O2 -Iapi TARGET=pict TARGET_LIB_SO=libpict.so TEST_OUTPUT = test/rel.log test/rel.log.failures test/dbg.log diff --git a/api/combination.cpp b/api/combination.cpp index 9c109f1..45e09fb 100644 --- a/api/combination.cpp +++ b/api/combination.cpp @@ -259,7 +259,7 @@ void Combination::SetOpen( int index ) // // Combination::Combination( Model *M ) : - m_bitvec( NULL ), m_openCount( 0 ), m_boundCount( 0 ), m_range( 0 ), m_model( M ) + m_bitvec( nullptr ), m_openCount( 0 ), m_boundCount( 0 ), m_range( 0 ), m_model( M ) { m_id = ++m_lastUsedId; DOUT( L"Combination created: " << m_id << endl ); @@ -271,7 +271,7 @@ Combination::Combination( Model *M ) : Combination::~Combination() { DOUT( L"Combination deleted: " << m_id << endl ); - if( NULL != m_bitvec ) delete[] m_bitvec; + if( nullptr != m_bitvec ) delete[] m_bitvec; } // @@ -290,4 +290,4 @@ void Combination::Print() DOUT( L"\n" ); } -} \ No newline at end of file +} diff --git a/api/generator.h b/api/generator.h index 6219c4c..aa9d122 100644 --- a/api/generator.h +++ b/api/generator.h @@ -1,7 +1,9 @@ #pragma once +#ifdef _MSC_VER #pragma warning(disable:4511) #pragma warning(disable:4512) #pragma warning(disable:4239) +#endif #include #include @@ -447,8 +449,8 @@ public: size_t GetLast() { return m_currentValue; } ParamResult& GetTempResults() { return m_result; } - virtual Model* GetModel() { return NULL; } - virtual ParamCollection* GetComponents() { return NULL; } + virtual Model* GetModel() { return nullptr; } + virtual ParamCollection* GetComponents() { return nullptr; } void CleanUp(); @@ -696,7 +698,7 @@ public: ExclusionCollection& GetExclusions() { return( m_exclusions ); } RowSeedCollection& GetRowSeeds() { return( m_rowSeeds ); } - bool AbortGeneration() { return( ( NULL == m_abortCallback ) ? false : m_abortCallback() ); } + bool AbortGeneration() { return( ( nullptr == m_abortCallback ) ? false : m_abortCallback() ); } void SetGenerationMode( GenerationMode mode ) { m_generationMode = mode; } GenerationMode GetGenerationMode() { return( m_generationMode ); } @@ -728,7 +730,7 @@ private: void deriveExclusions(); // a global workspace shared by multiple objects - int* m_workbuf = NULL; + int* m_workbuf = nullptr; // result row pointer allows C-style API to implement GetNextResultRow function // i.e. get one result row at a time diff --git a/api/model.cpp b/api/model.cpp index 1104330..b01942d 100644 --- a/api/model.cpp +++ b/api/model.cpp @@ -598,13 +598,13 @@ bool Model::excludeConflictingParamValues() { Parameter* s1 = GetParameters()[ pseudo1 ]; assert( s1 ); - if( NULL == s1 || NULL == s1->GetComponents() ) continue; + if( nullptr == s1 || nullptr == s1->GetComponents() ) continue; for( size_t pseudo2 = pseudo1 + 1; pseudo2 < GetParameters().size(); ++pseudo2 ) { Parameter* s2 = GetParameters()[ pseudo2 ]; assert( s2 ); - if( NULL == s2 || NULL == s2->GetComponents() ) continue; + if( nullptr == s2 || nullptr == s2->GetComponents() ) continue; // for each param p1 in s1 ParamCollection::iterator p1; @@ -1464,4 +1464,4 @@ Model::~Model() } } -} \ No newline at end of file +} diff --git a/api/pictapi.cpp b/api/pictapi.cpp index 4274f4d..b0611b5 100644 --- a/api/pictapi.cpp +++ b/api/pictapi.cpp @@ -271,9 +271,9 @@ PictAddParameter false ); try { - if( NULL != param ) + if( nullptr != param ) { - if( NULL != valueWeights ) + if( nullptr != valueWeights ) { std::vector weights; weights.reserve( valueCount ); @@ -286,7 +286,7 @@ PictAddParameter } catch( ... ) { - param = NULL; + param = nullptr; } return( param ); diff --git a/api/pictapi.h b/api/pictapi.h index 0fc7acb..30f6cec 100644 --- a/api/pictapi.h +++ b/api/pictapi.h @@ -73,8 +73,8 @@ typedef struct _PICT_SEED_ITEM // None // // Returns: -// Non-NULL Allocation succeeded (a handle is returned) -// NULL Allocation failed +// Non-nullptr Allocation succeeded (a handle is returned) +// nullptr Allocation failed // // //////////////////////////////////////////////////////////////////////////// @@ -189,8 +189,8 @@ PictGenerate // task Valid handle to a task // // Returns: -// Non-NULL Allocation succeeded (a handle is returned) -// NULL Allocation failed +// Non-nullptr Allocation succeeded (a handle is returned) +// nullptr Allocation failed // // //////////////////////////////////////////////////////////////////////////// @@ -297,8 +297,8 @@ PictDeleteTask // randomSeed A seed used to randomize the engine // // Returns: -// Non-NULL Allocation succeeded (a handle is returned) -// NULL Allocation failed +// Non-nullptr Allocation succeeded (a handle is returned) +// nullptr Allocation failed // // //////////////////////////////////////////////////////////////////////////// @@ -320,8 +320,8 @@ PictCreateModel // valueWeights Array of weights, one per value, must be of ValueCount size // // Returns: -// Non-NULL Allocation succeeded (a handle is returned) -// NULL Allocation failed +// Non-nullptr Allocation succeeded (a handle is returned) +// nullptr Allocation failed // // //////////////////////////////////////////////////////////////////////////// @@ -332,7 +332,7 @@ PictAddParameter IN const PICT_HANDLE model, IN size_t valueCount, IN OPT unsigned int order = PICT_PAIRWISE_GENERATION, - IN OPT unsigned int valueWeights[] = NULL + IN OPT unsigned int valueWeights[] = nullptr ); // diff --git a/api/task.cpp b/api/task.cpp index 73ecf38..5b2343f 100644 --- a/api/task.cpp +++ b/api/task.cpp @@ -10,11 +10,11 @@ const size_t DefaultMaxRandomTries = 1000; // // Task::Task() : - m_rootModel (NULL), - m_abortCallback (NULL), + m_rootModel (nullptr), + m_abortCallback (nullptr), m_generationMode(Regular), m_maxRandomTries(DefaultMaxRandomTries), - m_workbuf (NULL) + m_workbuf (nullptr) { Combination::ResetId(); @@ -53,10 +53,10 @@ void Task::AllocWorkbuf( int size ) // void Task::DeallocWorkbuf() { - if( NULL != m_workbuf ) + if( nullptr != m_workbuf ) { delete[] m_workbuf; - m_workbuf = NULL; + m_workbuf = nullptr; } } @@ -80,7 +80,7 @@ void Task::PrepareForGeneration() for ( auto & excl : m_exclusions ) { Model* found = findMatchingNode(const_cast( excl ), m_rootModel); - assert( NULL != found ); + assert( nullptr != found ); found->AddExclusion( const_cast( excl )); } @@ -120,7 +120,7 @@ Model* Task::findMatchingNode( Exclusion& exclusion, Model* root ) for( auto & submodel : root->GetSubmodels() ) { Model* foundNode = findMatchingNode( exclusion, submodel ); - if ( NULL != foundNode ) return( foundNode ); + if ( nullptr != foundNode ) return( foundNode ); } // none of the subnodes matches the exclusion so let's try the current one @@ -136,7 +136,7 @@ Model* Task::findMatchingNode( Exclusion& exclusion, Model* root ) } else { - return( NULL ); + return( nullptr ); } } @@ -187,4 +187,4 @@ void Task::deriveExclusions() __insert( m_exclusions, deriver.GetExclusions().begin(), deriver.GetExclusions().end() ); } -} \ No newline at end of file +} diff --git a/api/trie.h b/api/trie.h index 35416b7..535fb24 100644 --- a/api/trie.h +++ b/api/trie.h @@ -70,7 +70,7 @@ public: found = current->children.find( *ic ); if( found == current->children.end() ) { - trienode< typename Col::value_type > *node = NULL; + trienode< typename Col::value_type > *node = nullptr; try { @@ -101,7 +101,7 @@ public: void erase( Col& t ) { trienode* node = pfind( t ); - if( NULL == node ) return; + if( nullptr == node ) return; node->valid = false; } @@ -110,7 +110,7 @@ public: // bool find_prefix( Col &t ) { - return( pfind_prefix( t ) != NULL ); + return( pfind_prefix( t ) != nullptr ); } private: @@ -125,11 +125,11 @@ private: for( typename Col::iterator ic = t.begin(); ic != t.end(); ++ic ) { typename TNodeCol::iterator found = current->children.find( *ic ); - if( found == current->children.end() ) return( NULL ); + if( found == current->children.end() ) return( nullptr ); current = found->second; } - return( current->valid ? current : NULL ); + return( current->valid ? current : nullptr ); } // @@ -141,14 +141,14 @@ private: for( typename Col::iterator ic = t.begin(); ic != t.end(); ++ic ) { typename TNodeCol::iterator found = current->children.find( *ic ); - if( found == current->children.end() ) return( NULL ); + if( found == current->children.end() ) return( nullptr ); current = found->second; if( current->valid ) return( current ); } - return( current->valid ? current : NULL ); + return( current->valid ? current : nullptr ); } }; diff --git a/cli/ccommon.cpp b/cli/ccommon.cpp index 2ff570d..fc8e9ed 100644 --- a/cli/ccommon.cpp +++ b/cli/ccommon.cpp @@ -64,6 +64,8 @@ void CTerm::Print() case Relation_NOT_LIKE: wcerr << L"{not like}"; break; + default: + break; } wcerr << L" "; @@ -144,6 +146,8 @@ void CTokenList::Print() wcerr << L"\n"; break; } + default: + break; } } } @@ -191,8 +195,8 @@ void CSyntaxTreeItem::Print( unsigned int indent ) break; } - if( NULL != node->LLink ) node->LLink->Print( indent + 1 ); - if( NULL != node->RLink ) node->RLink->Print( indent + 1 ); + if( nullptr != node->LLink ) node->LLink->Print( indent + 1 ); + if( nullptr != node->RLink ) node->RLink->Print( indent + 1 ); } } @@ -202,7 +206,7 @@ void CSyntaxTreeItem::Print( unsigned int indent ) void CConstraint::Print() const { wcerr << L"Condition:\n"; - if( NULL == Condition ) + if( nullptr == Condition ) { wcerr << L" -\n"; } @@ -212,7 +216,7 @@ void CConstraint::Print() const } wcerr << L"Term:\n"; - if( NULL == Term ) + if( nullptr == Term ) { wcerr << L" -\n"; } diff --git a/cli/ccommon.h b/cli/ccommon.h index ac45882..7b9e28c 100644 --- a/cli/ccommon.h +++ b/cli/ccommon.h @@ -2,7 +2,7 @@ #include #include -#include +#include #include "strings.h" namespace pictcli_constraints @@ -100,9 +100,9 @@ public: CValue( IN std::wstring text ) : DataType( DataType_String ), Text( text ) {} CValue( IN double number ) : DataType( DataType_Number ), Number( number ) {} - DataType DataType; - std::wstring Text; - double Number; + pictcli_constraints::DataType DataType; + std::wstring Text; + double Number; }; typedef std::list CValueSet; @@ -146,11 +146,11 @@ class CTerm public: CTerm ( - IN CParameter* parameter, // what parameter the term relates to - IN Relation relation, // what is the relation - IN TermDataType dataType, // type of the right side of the relation - IN void* data, // data of the right side of the relation - IN std::wstring rawText // raw text of the term, useful for warnings + IN CParameter* parameter, // what parameter the term relates to + IN pictcli_constraints::Relation relation, // what is the relation + IN TermDataType dataType, // type of the right side of the relation + IN void* data, // data of the right side of the relation + IN std::wstring rawText // raw text of the term, useful for warnings ) : Parameter( parameter ), Relation ( relation ), @@ -196,17 +196,27 @@ public: ~CTerm() { - if( SyntaxTermDataType_ParameterName != DataType ) + switch( DataType ) { - delete( Data ); + case SyntaxTermDataType_ParameterName: + break; + case SyntaxTermDataType_Value: + delete( reinterpret_cast(Data) ); + break; + case SyntaxTermDataType_ValueSet: + delete( reinterpret_cast(Data) ); + break; + default: + assert(false); + break; } } - CParameter* Parameter; - TermDataType DataType; - Relation Relation; - void* Data; - std::wstring RawText; + CParameter* Parameter; + TermDataType DataType; + pictcli_constraints::Relation Relation; + void* Data; + std::wstring RawText; }; // @@ -261,9 +271,13 @@ public: { // we don't have to delete Data for FunctionDataType_Parameter // as it's merely a pointer to an existing data set - if( FunctionDataType_Parameter != DataType ) + switch( DataType ) { - delete( Data ); + case FunctionDataType_Parameter: + break; + default: + assert(false); + break; } } @@ -320,41 +334,41 @@ public: Type ( type ), PositionInText( positionInText ), LogicalOper ( LogicalOper_Unknown ), - Term ( NULL ), - Function ( NULL ) {} + Term ( nullptr ), + Function ( nullptr ) {} - CToken( IN LogicalOper logicalOper, IN std::wstring::iterator positionInText ) : + CToken( IN pictcli_constraints::LogicalOper logicalOper, IN std::wstring::iterator positionInText ) : Type ( TokenType_LogicalOper ), PositionInText( positionInText ), LogicalOper ( logicalOper ), - Term ( NULL ), - Function ( NULL ) {} + Term ( nullptr ), + Function ( nullptr ) {} CToken( IN CTerm *term, IN std::wstring::iterator positionInText ) : Type ( TokenType_Term ), PositionInText( positionInText ), LogicalOper ( LogicalOper_Unknown ), Term ( term ), - Function ( NULL ) {} + Function ( nullptr ) {} CToken( IN CFunction *function, IN std::wstring::iterator positionInText ) : Type ( TokenType_Function ), PositionInText( positionInText ), LogicalOper ( LogicalOper_Unknown ), - Term ( NULL ), + Term ( nullptr ), Function ( function ) {} ~CToken() { - if( NULL != Term ) delete( Term ); - if( NULL != Function ) delete( Function ); + if( nullptr != Term ) delete( Term ); + if( nullptr != Function ) delete( Function ); } - TokenType Type; - std::wstring::iterator PositionInText; - LogicalOper LogicalOper; - CTerm* Term; - CFunction* Function; + TokenType Type; + std::wstring::iterator PositionInText; + pictcli_constraints::LogicalOper LogicalOper; + CTerm* Term; + CFunction* Function; }; // @@ -422,11 +436,24 @@ public: ~CSyntaxTreeItem() { - if( NULL != Data ) delete( Data ); + switch( Type ) + { + case ItemType_Term: + delete( reinterpret_cast(Data) ); + break; + case ItemType_Function: + delete( reinterpret_cast(Data) ); + break; + case ItemType_Node: + break; + default: + assert(false); + break; + } } SyntaxTreeItemType Type; - void* Data = NULL; + void* Data = nullptr; }; // @@ -435,16 +462,16 @@ public: class CSyntaxTreeNode { public: - LogicalOper Oper; - CSyntaxTreeItem* LLink; - CSyntaxTreeItem* RLink; + pictcli_constraints::LogicalOper Oper; + CSyntaxTreeItem* LLink; + CSyntaxTreeItem* RLink; - CSyntaxTreeNode() : Oper( LogicalOper_Unknown ), LLink( NULL ), RLink( NULL ) {} + CSyntaxTreeNode() : Oper( LogicalOper_Unknown ), LLink( nullptr ), RLink( nullptr ) {} ~CSyntaxTreeNode() { - if( NULL != LLink ) delete( (CSyntaxTreeItem*) LLink ); - if( NULL != RLink ) delete( RLink ); + if( nullptr != LLink ) delete( (CSyntaxTreeItem*) LLink ); + if( nullptr != RLink ) delete( RLink ); } }; @@ -457,7 +484,7 @@ public: class CConstraint { public: - CConstraint() : Condition( NULL ), Term( NULL ) {} + CConstraint() : Condition( nullptr ), Term( nullptr ) {} CSyntaxTreeItem* Condition; CSyntaxTreeItem* Term; diff --git a/cli/cmdline.cpp b/cli/cmdline.cpp index 3a6fa70..c961a2b 100644 --- a/cli/cmdline.cpp +++ b/cli/cmdline.cpp @@ -175,7 +175,7 @@ bool parseArg( wchar_t* text, CModelData& modelData ) // /r if( wcslen( text ) == 2 ) { - modelData.RandSeed = (unsigned short) ( time( NULL ) ); + modelData.RandSeed = (unsigned short) ( time( nullptr ) ); } // /r: else if( wcslen( text ) == 3 ) diff --git a/cli/common.cpp b/cli/common.cpp index c75c9f0..5f616a5 100644 --- a/cli/common.cpp +++ b/cli/common.cpp @@ -10,9 +10,9 @@ using namespace std; void PrintMessage ( IN MsgType type, - IN wchar_t* text1, - IN wchar_t* text2, - IN wchar_t* text3 + IN const wchar_t* text1, + IN const wchar_t* text2, + IN const wchar_t* text3 ) { switch ( type ) diff --git a/cli/common.h b/cli/common.h index e9d22ef..472c2a7 100644 --- a/cli/common.h +++ b/cli/common.h @@ -14,7 +14,7 @@ // TODO: move these two somewhere else #define TEXT_TokenConstraintEnd L";" -const wchar_t RESULT_DELIMITER = '\t'; +const wchar_t RESULT_DELIMITER = L'\t'; // // Types of messages @@ -36,9 +36,9 @@ enum MsgType void PrintMessage ( IN MsgType type, - IN wchar_t* text1, - IN wchar_t* text2 = 0, - IN wchar_t* text3 = 0 + IN const wchar_t* text1, + IN const wchar_t* text2 = nullptr, + IN const wchar_t* text3 = nullptr ); // diff --git a/cli/cparser.cpp b/cli/cparser.cpp index 3d05177..29fd727 100644 --- a/cli/cparser.cpp +++ b/cli/cparser.cpp @@ -199,6 +199,8 @@ CSyntaxTreeItem* ConstraintsParser::constructSyntaxTreeItem case TokenType_ParenthesisClose: --parenthesesCount; break; + default: + break; } ++token; @@ -208,6 +210,8 @@ CSyntaxTreeItem* ConstraintsParser::constructSyntaxTreeItem operands.push( constructSyntaxTreeItem( tokenBegin, token, false )); break; } + default: + break; } } @@ -254,6 +258,7 @@ CSyntaxTreeItem* ConstraintsParser::constructSyntaxTreeItem delete( (CSyntaxTreeItem*) operands.top() ); operands.pop(); } + return nullptr; } } @@ -280,7 +285,7 @@ CSyntaxTreeItem* ConstraintsParser::processOneLogicalOper( IN COperators& operat break; case LogicalOper_NOT: node->LLink = operands.top(); - // the right node remains NULL + // the right node remains "nullptr" operands.pop(); break; default: @@ -338,7 +343,7 @@ void ConstraintsParser::removeNOTs() // void ConstraintsParser::removeBranchNOTs( IN CSyntaxTreeItem* item, IN bool carryOver ) { - if ( NULL == item) return; + if ( nullptr == item) return; switch( item->Type ) { @@ -394,7 +399,7 @@ void ConstraintsParser::removeBranchNOTs( IN CSyntaxTreeItem* item, IN bool carr // zero out the data pointer of LLink so during clean-up we don't // delete the data that was just assigned to current item - node->LLink->Data = NULL; + node->LLink->Data = nullptr; delete( node ); break; default: @@ -463,7 +468,7 @@ void ConstraintsParser::verifyConstraint( CConstraint& constraint ) // void ConstraintsParser::verifySyntaxTreeItem( CSyntaxTreeItem* item ) { - if ( NULL == item ) return; + if ( nullptr == item ) return; if ( ItemType_Term == item->Type ) { @@ -488,7 +493,7 @@ void ConstraintsParser::verifySyntaxTreeItem( CSyntaxTreeItem* item ) void ConstraintsParser::verifyTerm( CTerm* term ) { // Is Parameter defined in the model? - if ( term->Parameter == NULL ) + if ( term->Parameter == nullptr ) { throw CSemanticWarning( ValidationWarnType_UnknownParameter ); } @@ -521,7 +526,7 @@ void ConstraintsParser::verifyTerm( CTerm* term ) // Is second parameter defined? if ( term->DataType == SyntaxTermDataType_ParameterName ) { - if ( term->Data == NULL ) + if ( term->Data == nullptr ) { throw CSemanticWarning( ValidationWarnType_UnknownParameter ); } @@ -569,13 +574,15 @@ void ConstraintsParser::verifyFunction( CFunction *function ) case FunctionTypeIsNegativeParam: case FunctionTypeIsPositiveParam: { - if ( function->Data == NULL && ! function->DataText.empty() ) + if ( function->Data == nullptr && ! function->DataText.empty() ) { throw CSemanticWarning( ValidationWarnType_UnknownParameter ); } break; } + default: + break; } } -} \ No newline at end of file +} diff --git a/cli/ctokenizer.cpp b/cli/ctokenizer.cpp index 758544b..eafe8a9 100644 --- a/cli/ctokenizer.cpp +++ b/cli/ctokenizer.cpp @@ -261,7 +261,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens ) // check whether it's one of the functions CFunction *function = getFunction(); - if( NULL != function ) + if( nullptr != function ) { CToken* token; try @@ -282,7 +282,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens ) wstring paramName = getParameterName(); CParameters::iterator found = _model.findParamByName( paramName ); - CParameter* param = NULL; + CParameter* param = nullptr; if ( found != _model.Parameters.end() ) { param = &*found; @@ -293,7 +293,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens ) skipWhiteChars(); - CTerm* term = NULL; + CTerm* term = nullptr; switch( relation ) { case Relation_IN: @@ -350,7 +350,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens ) // // look up parameters by their names and return references // - CParameter *param2 = NULL; + CParameter *param2 = nullptr; found = _model.findParamByName( paramName2 ); if ( found != _model.Parameters.end() ) { @@ -405,7 +405,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens ) // ::= IsNegative() // // Returns a CFunction object if in fact a function was parsed -// or NULL otherwise +// or "nullptr" otherwise // CFunction *ConstraintsTokenizer::getFunction() { @@ -424,7 +424,7 @@ CFunction *ConstraintsTokenizer::getFunction() } else { - return NULL; + return nullptr; } // opening bracket @@ -438,7 +438,7 @@ CFunction *ConstraintsTokenizer::getFunction() wstring paramName = getString( charArrToStr( TEXT_TokenParenthesisClose )); CParameters::iterator found = _model.findParamByName( paramName ); - CParameter* param = NULL; + CParameter* param = nullptr; if ( found != _model.Parameters.end() ) { param = &*found; @@ -759,8 +759,8 @@ void ConstraintsTokenizer::doPostParseExpansions( IN OUT CTokenList& tokens ) && function->DataText.empty() ) { // deallocate the current token - // we don't have to deallocate Data because in this case it is always NULL - assert( function->Data == NULL ); + // we don't have to deallocate Data because in this case it is always "nullptr" + assert( function->Data == nullptr ); // save positionInText and rawText and reuse it in all new tokens wstring::iterator oldPosInText = (*i_token)->PositionInText; diff --git a/cli/gcdexcl.cpp b/cli/gcdexcl.cpp index bbd8293..e53b3ae 100644 --- a/cli/gcdexcl.cpp +++ b/cli/gcdexcl.cpp @@ -288,8 +288,8 @@ void ConstraintsInterpreter::interpretFunction( IN CFunction* function, IN OUT C for( unsigned int idx = 0; idx < modelParam.Values.size(); ++idx ) { bool positive = modelParam.Values[ idx ].IsPositive(); - if( function->Type == FunctionTypeIsNegativeParam && ! positive - || function->Type == FunctionTypeIsPositiveParam && positive ) + if( (function->Type == FunctionTypeIsNegativeParam && ! positive) + || (function->Type == FunctionTypeIsPositiveParam && positive) ) { Exclusion newExcl; newExcl.insert( make_pair( _gcdParameters[ paramIdx ], idx )); @@ -311,7 +311,7 @@ void ConstraintsInterpreter::interpretFunction( IN CFunction* function, IN OUT C // void ConstraintsInterpreter::interpretSyntaxTreeItem( IN CSyntaxTreeItem* item, IN OUT CGcdExclusions& gcdExclusions ) { - if ( NULL == item ) return; + if ( nullptr == item ) return; // a case where where there is no condition if ( ItemType_Term == item->Type ) @@ -368,7 +368,7 @@ void ConstraintsInterpreter::interpretSyntaxTreeItem( IN CSyntaxTreeItem* item, void ConstraintsInterpreter::interpretConstraint( IN const CConstraint& constraint, IN OUT CGcdExclusions& gcdExclusions ) { // if there's no condition, look at the term only - if ( NULL == constraint.Condition ) + if ( nullptr == constraint.Condition ) { interpretSyntaxTreeItem( constraint.Term, gcdExclusions ); } diff --git a/cli/gcdmodel.cpp b/cli/gcdmodel.cpp index d4f9174..4e2bd0b 100644 --- a/cli/gcdmodel.cpp +++ b/cli/gcdmodel.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "cmdline.h" #include "gcdexcl.h" #include "gcdmodel.h" diff --git a/cli/model.cpp b/cli/model.cpp index ecf85b1..f4c737b 100644 --- a/cli/model.cpp +++ b/cli/model.cpp @@ -278,7 +278,7 @@ void CModelData::PrintModelContents( wstring title ) for( auto & param : Parameters ) { wcerr << L" " << param.Name << L":\t" << (unsigned int) param.Values.size() << L" values, order: "; - if( NULL == param.GcdPointer ) + if( nullptr == param.GcdPointer ) wcerr << L"?" << endl; else wcerr << param.Order << L" : " << param.GcdPointer->GetOrder() << endl; diff --git a/cli/model.h b/cli/model.h index 20a2cde..018ac3f 100644 --- a/cli/model.h +++ b/cli/model.h @@ -59,7 +59,7 @@ public: CModelParameter() : IsResultParameter( false ), - GcdPointer( NULL ) {} + GcdPointer( nullptr ) {} int GetValueOrdinal( IN std::wstring& name, IN bool caseSensitive ); bool ValueNamesUnique( IN bool CaseSensitive ); diff --git a/cli/mparser.cpp b/cli/mparser.cpp index 4e12245..3536f33 100644 --- a/cli/mparser.cpp +++ b/cli/mparser.cpp @@ -193,7 +193,7 @@ bool CModelData::readParameter( wstring& line ) size_t weightEnd = i_val->find_last_of( WEIGHT_END ); // '(' must exist, ')' must be the last character - if ( weightBegin != -1 && weightEnd == i_val->length() - 1 ) + if ( weightBegin != wstring::npos && weightEnd == i_val->length() - 1 ) { wstring weightStr = trim( i_val->substr( weightBegin + 1, weightEnd - weightBegin - 1 )); double weightDbl = 0; diff --git a/cli/pict.cpp b/cli/pict.cpp index 0573652..eb46013 100644 --- a/cli/pict.cpp +++ b/cli/pict.cpp @@ -46,7 +46,7 @@ int __cdecl execute IN OUT wstring& output ) { - time_t start = time( NULL ); + time_t start = time( nullptr ); CModelData modelData; @@ -73,7 +73,7 @@ int __cdecl execute return err; } - time_t end = time( NULL ); + time_t end = time( nullptr ); // if r has been provided then print out the seed // TODO: change to not use SWITCH_RANDOMIZE const diff --git a/cli/strings.cpp b/cli/strings.cpp index 6c87562..bff2cc7 100644 --- a/cli/strings.cpp +++ b/cli/strings.cpp @@ -3,8 +3,8 @@ #include #include #include -#include -#include +#include +#include #include "strings.h" using namespace std; @@ -224,7 +224,7 @@ wstring charToStr( wchar_t c ) // // // -wstring charArrToStr( wchar_t* c ) +wstring charArrToStr( const wchar_t* c ) { return( wstring( c ) ); } diff --git a/cli/strings.h b/cli/strings.h index 3833994..b4ff617 100644 --- a/cli/strings.h +++ b/cli/strings.h @@ -110,7 +110,7 @@ std::wstring charToStr // std::wstring charArrToStr ( - IN wchar_t* c + IN const wchar_t* c ); //