* 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
This commit is contained in:
qykth-git 2021-08-24 03:27:05 +09:00 коммит произвёл GitHub
Родитель f94399f684
Коммит f14d961d2c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
23 изменённых файлов: 162 добавлений и 125 удалений

Просмотреть файл

@ -3,8 +3,7 @@
# variables used to generate a source snapshot of the GIT repo # variables used to generate a source snapshot of the GIT repo
COMMIT=$(shell git log --pretty=format:'%H' -n 1) COMMIT=$(shell git log --pretty=format:'%H' -n 1)
SHORT_COMMIT=$(shell git log --pretty=format:'%h' -n 1) SHORT_COMMIT=$(shell git log --pretty=format:'%h' -n 1)
# suppress all warnings :-( CXXFLAGS=-fPIC -pipe -std=c++11 -O2 -Iapi
CXXFLAGS=-fPIC -std=c++11 -Iapi -w -fpermissive
TARGET=pict TARGET=pict
TARGET_LIB_SO=libpict.so TARGET_LIB_SO=libpict.so
TEST_OUTPUT = test/rel.log test/rel.log.failures test/dbg.log TEST_OUTPUT = test/rel.log test/rel.log.failures test/dbg.log

Просмотреть файл

@ -259,7 +259,7 @@ void Combination::SetOpen( int index )
// //
// //
Combination::Combination( Model *M ) : 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; m_id = ++m_lastUsedId;
DOUT( L"Combination created: " << m_id << endl ); DOUT( L"Combination created: " << m_id << endl );
@ -271,7 +271,7 @@ Combination::Combination( Model *M ) :
Combination::~Combination() Combination::~Combination()
{ {
DOUT( L"Combination deleted: " << m_id << endl ); 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" ); DOUT( L"\n" );
} }
} }

Просмотреть файл

@ -1,7 +1,9 @@
#pragma once #pragma once
#ifdef _MSC_VER
#pragma warning(disable:4511) #pragma warning(disable:4511)
#pragma warning(disable:4512) #pragma warning(disable:4512)
#pragma warning(disable:4239) #pragma warning(disable:4239)
#endif
#include <vector> #include <vector>
#include <string> #include <string>
@ -447,8 +449,8 @@ public:
size_t GetLast() { return m_currentValue; } size_t GetLast() { return m_currentValue; }
ParamResult& GetTempResults() { return m_result; } ParamResult& GetTempResults() { return m_result; }
virtual Model* GetModel() { return NULL; } virtual Model* GetModel() { return nullptr; }
virtual ParamCollection* GetComponents() { return NULL; } virtual ParamCollection* GetComponents() { return nullptr; }
void CleanUp(); void CleanUp();
@ -696,7 +698,7 @@ public:
ExclusionCollection& GetExclusions() { return( m_exclusions ); } ExclusionCollection& GetExclusions() { return( m_exclusions ); }
RowSeedCollection& GetRowSeeds() { return( m_rowSeeds ); } 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; } void SetGenerationMode( GenerationMode mode ) { m_generationMode = mode; }
GenerationMode GetGenerationMode() { return( m_generationMode ); } GenerationMode GetGenerationMode() { return( m_generationMode ); }
@ -728,7 +730,7 @@ private:
void deriveExclusions(); void deriveExclusions();
// a global workspace shared by multiple objects // 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 // result row pointer allows C-style API to implement GetNextResultRow function
// i.e. get one result row at a time // i.e. get one result row at a time

Просмотреть файл

@ -598,13 +598,13 @@ bool Model::excludeConflictingParamValues()
{ {
Parameter* s1 = GetParameters()[ pseudo1 ]; Parameter* s1 = GetParameters()[ pseudo1 ];
assert( s1 ); 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 ) for( size_t pseudo2 = pseudo1 + 1; pseudo2 < GetParameters().size(); ++pseudo2 )
{ {
Parameter* s2 = GetParameters()[ pseudo2 ]; Parameter* s2 = GetParameters()[ pseudo2 ];
assert( s2 ); assert( s2 );
if( NULL == s2 || NULL == s2->GetComponents() ) continue; if( nullptr == s2 || nullptr == s2->GetComponents() ) continue;
// for each param p1 in s1 // for each param p1 in s1
ParamCollection::iterator p1; ParamCollection::iterator p1;
@ -1464,4 +1464,4 @@ Model::~Model()
} }
} }
} }

Просмотреть файл

@ -271,9 +271,9 @@ PictAddParameter
false ); false );
try try
{ {
if( NULL != param ) if( nullptr != param )
{ {
if( NULL != valueWeights ) if( nullptr != valueWeights )
{ {
std::vector<int> weights; std::vector<int> weights;
weights.reserve( valueCount ); weights.reserve( valueCount );
@ -286,7 +286,7 @@ PictAddParameter
} }
catch( ... ) catch( ... )
{ {
param = NULL; param = nullptr;
} }
return( param ); return( param );

Просмотреть файл

@ -73,8 +73,8 @@ typedef struct _PICT_SEED_ITEM
// None // None
// //
// Returns: // Returns:
// Non-NULL Allocation succeeded (a handle is returned) // Non-nullptr Allocation succeeded (a handle is returned)
// NULL Allocation failed // nullptr Allocation failed
// //
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
@ -189,8 +189,8 @@ PictGenerate
// task Valid handle to a task // task Valid handle to a task
// //
// Returns: // Returns:
// Non-NULL Allocation succeeded (a handle is returned) // Non-nullptr Allocation succeeded (a handle is returned)
// NULL Allocation failed // nullptr Allocation failed
// //
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
@ -297,8 +297,8 @@ PictDeleteTask
// randomSeed A seed used to randomize the engine // randomSeed A seed used to randomize the engine
// //
// Returns: // Returns:
// Non-NULL Allocation succeeded (a handle is returned) // Non-nullptr Allocation succeeded (a handle is returned)
// NULL Allocation failed // nullptr Allocation failed
// //
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
@ -320,8 +320,8 @@ PictCreateModel
// valueWeights Array of weights, one per value, must be of ValueCount size // valueWeights Array of weights, one per value, must be of ValueCount size
// //
// Returns: // Returns:
// Non-NULL Allocation succeeded (a handle is returned) // Non-nullptr Allocation succeeded (a handle is returned)
// NULL Allocation failed // nullptr Allocation failed
// //
// //////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////
@ -332,7 +332,7 @@ PictAddParameter
IN const PICT_HANDLE model, IN const PICT_HANDLE model,
IN size_t valueCount, IN size_t valueCount,
IN OPT unsigned int order = PICT_PAIRWISE_GENERATION, IN OPT unsigned int order = PICT_PAIRWISE_GENERATION,
IN OPT unsigned int valueWeights[] = NULL IN OPT unsigned int valueWeights[] = nullptr
); );
// //

Просмотреть файл

@ -10,11 +10,11 @@ const size_t DefaultMaxRandomTries = 1000;
// //
// //
Task::Task() : Task::Task() :
m_rootModel (NULL), m_rootModel (nullptr),
m_abortCallback (NULL), m_abortCallback (nullptr),
m_generationMode(Regular), m_generationMode(Regular),
m_maxRandomTries(DefaultMaxRandomTries), m_maxRandomTries(DefaultMaxRandomTries),
m_workbuf (NULL) m_workbuf (nullptr)
{ {
Combination::ResetId(); Combination::ResetId();
@ -53,10 +53,10 @@ void Task::AllocWorkbuf( int size )
// //
void Task::DeallocWorkbuf() void Task::DeallocWorkbuf()
{ {
if( NULL != m_workbuf ) if( nullptr != m_workbuf )
{ {
delete[] m_workbuf; delete[] m_workbuf;
m_workbuf = NULL; m_workbuf = nullptr;
} }
} }
@ -80,7 +80,7 @@ void Task::PrepareForGeneration()
for ( auto & excl : m_exclusions ) for ( auto & excl : m_exclusions )
{ {
Model* found = findMatchingNode(const_cast<Exclusion&>( excl ), m_rootModel); Model* found = findMatchingNode(const_cast<Exclusion&>( excl ), m_rootModel);
assert( NULL != found ); assert( nullptr != found );
found->AddExclusion( const_cast<Exclusion&>( excl )); found->AddExclusion( const_cast<Exclusion&>( excl ));
} }
@ -120,7 +120,7 @@ Model* Task::findMatchingNode( Exclusion& exclusion, Model* root )
for( auto & submodel : root->GetSubmodels() ) for( auto & submodel : root->GetSubmodels() )
{ {
Model* foundNode = findMatchingNode( exclusion, submodel ); 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 // 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 else
{ {
return( NULL ); return( nullptr );
} }
} }
@ -187,4 +187,4 @@ void Task::deriveExclusions()
__insert( m_exclusions, deriver.GetExclusions().begin(), deriver.GetExclusions().end() ); __insert( m_exclusions, deriver.GetExclusions().begin(), deriver.GetExclusions().end() );
} }
} }

Просмотреть файл

@ -70,7 +70,7 @@ public:
found = current->children.find( *ic ); found = current->children.find( *ic );
if( found == current->children.end() ) if( found == current->children.end() )
{ {
trienode< typename Col::value_type > *node = NULL; trienode< typename Col::value_type > *node = nullptr;
try try
{ {
@ -101,7 +101,7 @@ public:
void erase( Col& t ) void erase( Col& t )
{ {
trienode<typename Col::value_type>* node = pfind( t ); trienode<typename Col::value_type>* node = pfind( t );
if( NULL == node ) return; if( nullptr == node ) return;
node->valid = false; node->valid = false;
} }
@ -110,7 +110,7 @@ public:
// //
bool find_prefix( Col &t ) bool find_prefix( Col &t )
{ {
return( pfind_prefix( t ) != NULL ); return( pfind_prefix( t ) != nullptr );
} }
private: private:
@ -125,11 +125,11 @@ private:
for( typename Col::iterator ic = t.begin(); ic != t.end(); ++ic ) for( typename Col::iterator ic = t.begin(); ic != t.end(); ++ic )
{ {
typename TNodeCol::iterator found = current->children.find( *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; 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 ) for( typename Col::iterator ic = t.begin(); ic != t.end(); ++ic )
{ {
typename TNodeCol::iterator found = current->children.find( *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; current = found->second;
if( current->valid ) return( current ); if( current->valid ) return( current );
} }
return( current->valid ? current : NULL ); return( current->valid ? current : nullptr );
} }
}; };

Просмотреть файл

@ -64,6 +64,8 @@ void CTerm::Print()
case Relation_NOT_LIKE: case Relation_NOT_LIKE:
wcerr << L"{not like}"; wcerr << L"{not like}";
break; break;
default:
break;
} }
wcerr << L" "; wcerr << L" ";
@ -144,6 +146,8 @@ void CTokenList::Print()
wcerr << L"\n"; wcerr << L"\n";
break; break;
} }
default:
break;
} }
} }
} }
@ -191,8 +195,8 @@ void CSyntaxTreeItem::Print( unsigned int indent )
break; break;
} }
if( NULL != node->LLink ) node->LLink->Print( indent + 1 ); if( nullptr != node->LLink ) node->LLink->Print( indent + 1 );
if( NULL != node->RLink ) node->RLink->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 void CConstraint::Print() const
{ {
wcerr << L"Condition:\n"; wcerr << L"Condition:\n";
if( NULL == Condition ) if( nullptr == Condition )
{ {
wcerr << L" -\n"; wcerr << L" -\n";
} }
@ -212,7 +216,7 @@ void CConstraint::Print() const
} }
wcerr << L"Term:\n"; wcerr << L"Term:\n";
if( NULL == Term ) if( nullptr == Term )
{ {
wcerr << L" -\n"; wcerr << L" -\n";
} }

Просмотреть файл

@ -2,7 +2,7 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <assert.h> #include <cassert>
#include "strings.h" #include "strings.h"
namespace pictcli_constraints namespace pictcli_constraints
@ -100,9 +100,9 @@ public:
CValue( IN std::wstring text ) : DataType( DataType_String ), Text( text ) {} CValue( IN std::wstring text ) : DataType( DataType_String ), Text( text ) {}
CValue( IN double number ) : DataType( DataType_Number ), Number( number ) {} CValue( IN double number ) : DataType( DataType_Number ), Number( number ) {}
DataType DataType; pictcli_constraints::DataType DataType;
std::wstring Text; std::wstring Text;
double Number; double Number;
}; };
typedef std::list<CValue> CValueSet; typedef std::list<CValue> CValueSet;
@ -146,11 +146,11 @@ class CTerm
public: public:
CTerm CTerm
( (
IN CParameter* parameter, // what parameter the term relates to IN CParameter* parameter, // what parameter the term relates to
IN Relation relation, // what is the relation IN pictcli_constraints::Relation relation, // what is the relation
IN TermDataType dataType, // type of the right side of 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 void* data, // data of the right side of the relation
IN std::wstring rawText // raw text of the term, useful for warnings IN std::wstring rawText // raw text of the term, useful for warnings
) : ) :
Parameter( parameter ), Parameter( parameter ),
Relation ( relation ), Relation ( relation ),
@ -196,17 +196,27 @@ public:
~CTerm() ~CTerm()
{ {
if( SyntaxTermDataType_ParameterName != DataType ) switch( DataType )
{ {
delete( Data ); case SyntaxTermDataType_ParameterName:
break;
case SyntaxTermDataType_Value:
delete( reinterpret_cast<CValue*>(Data) );
break;
case SyntaxTermDataType_ValueSet:
delete( reinterpret_cast<CValueSet*>(Data) );
break;
default:
assert(false);
break;
} }
} }
CParameter* Parameter; CParameter* Parameter;
TermDataType DataType; TermDataType DataType;
Relation Relation; pictcli_constraints::Relation Relation;
void* Data; void* Data;
std::wstring RawText; std::wstring RawText;
}; };
// //
@ -261,9 +271,13 @@ public:
{ {
// we don't have to delete Data for FunctionDataType_Parameter // we don't have to delete Data for FunctionDataType_Parameter
// as it's merely a pointer to an existing data set // 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 ), Type ( type ),
PositionInText( positionInText ), PositionInText( positionInText ),
LogicalOper ( LogicalOper_Unknown ), LogicalOper ( LogicalOper_Unknown ),
Term ( NULL ), Term ( nullptr ),
Function ( NULL ) {} 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 ), Type ( TokenType_LogicalOper ),
PositionInText( positionInText ), PositionInText( positionInText ),
LogicalOper ( logicalOper ), LogicalOper ( logicalOper ),
Term ( NULL ), Term ( nullptr ),
Function ( NULL ) {} Function ( nullptr ) {}
CToken( IN CTerm *term, IN std::wstring::iterator positionInText ) : CToken( IN CTerm *term, IN std::wstring::iterator positionInText ) :
Type ( TokenType_Term ), Type ( TokenType_Term ),
PositionInText( positionInText ), PositionInText( positionInText ),
LogicalOper ( LogicalOper_Unknown ), LogicalOper ( LogicalOper_Unknown ),
Term ( term ), Term ( term ),
Function ( NULL ) {} Function ( nullptr ) {}
CToken( IN CFunction *function, IN std::wstring::iterator positionInText ) : CToken( IN CFunction *function, IN std::wstring::iterator positionInText ) :
Type ( TokenType_Function ), Type ( TokenType_Function ),
PositionInText( positionInText ), PositionInText( positionInText ),
LogicalOper ( LogicalOper_Unknown ), LogicalOper ( LogicalOper_Unknown ),
Term ( NULL ), Term ( nullptr ),
Function ( function ) {} Function ( function ) {}
~CToken() ~CToken()
{ {
if( NULL != Term ) delete( Term ); if( nullptr != Term ) delete( Term );
if( NULL != Function ) delete( Function ); if( nullptr != Function ) delete( Function );
} }
TokenType Type; TokenType Type;
std::wstring::iterator PositionInText; std::wstring::iterator PositionInText;
LogicalOper LogicalOper; pictcli_constraints::LogicalOper LogicalOper;
CTerm* Term; CTerm* Term;
CFunction* Function; CFunction* Function;
}; };
// //
@ -422,11 +436,24 @@ public:
~CSyntaxTreeItem() ~CSyntaxTreeItem()
{ {
if( NULL != Data ) delete( Data ); switch( Type )
{
case ItemType_Term:
delete( reinterpret_cast<CTerm*>(Data) );
break;
case ItemType_Function:
delete( reinterpret_cast<CFunction*>(Data) );
break;
case ItemType_Node:
break;
default:
assert(false);
break;
}
} }
SyntaxTreeItemType Type; SyntaxTreeItemType Type;
void* Data = NULL; void* Data = nullptr;
}; };
// //
@ -435,16 +462,16 @@ public:
class CSyntaxTreeNode class CSyntaxTreeNode
{ {
public: public:
LogicalOper Oper; pictcli_constraints::LogicalOper Oper;
CSyntaxTreeItem* LLink; CSyntaxTreeItem* LLink;
CSyntaxTreeItem* RLink; CSyntaxTreeItem* RLink;
CSyntaxTreeNode() : Oper( LogicalOper_Unknown ), LLink( NULL ), RLink( NULL ) {} CSyntaxTreeNode() : Oper( LogicalOper_Unknown ), LLink( nullptr ), RLink( nullptr ) {}
~CSyntaxTreeNode() ~CSyntaxTreeNode()
{ {
if( NULL != LLink ) delete( (CSyntaxTreeItem*) LLink ); if( nullptr != LLink ) delete( (CSyntaxTreeItem*) LLink );
if( NULL != RLink ) delete( RLink ); if( nullptr != RLink ) delete( RLink );
} }
}; };
@ -457,7 +484,7 @@ public:
class CConstraint class CConstraint
{ {
public: public:
CConstraint() : Condition( NULL ), Term( NULL ) {} CConstraint() : Condition( nullptr ), Term( nullptr ) {}
CSyntaxTreeItem* Condition; CSyntaxTreeItem* Condition;
CSyntaxTreeItem* Term; CSyntaxTreeItem* Term;

Просмотреть файл

@ -175,7 +175,7 @@ bool parseArg( wchar_t* text, CModelData& modelData )
// /r // /r
if( wcslen( text ) == 2 ) if( wcslen( text ) == 2 )
{ {
modelData.RandSeed = (unsigned short) ( time( NULL ) ); modelData.RandSeed = (unsigned short) ( time( nullptr ) );
} }
// /r: // /r:
else if( wcslen( text ) == 3 ) else if( wcslen( text ) == 3 )

Просмотреть файл

@ -10,9 +10,9 @@ using namespace std;
void PrintMessage void PrintMessage
( (
IN MsgType type, IN MsgType type,
IN wchar_t* text1, IN const wchar_t* text1,
IN wchar_t* text2, IN const wchar_t* text2,
IN wchar_t* text3 IN const wchar_t* text3
) )
{ {
switch ( type ) switch ( type )

Просмотреть файл

@ -14,7 +14,7 @@
// TODO: move these two somewhere else // TODO: move these two somewhere else
#define TEXT_TokenConstraintEnd L";" #define TEXT_TokenConstraintEnd L";"
const wchar_t RESULT_DELIMITER = '\t'; const wchar_t RESULT_DELIMITER = L'\t';
// //
// Types of messages // Types of messages
@ -36,9 +36,9 @@ enum MsgType
void PrintMessage void PrintMessage
( (
IN MsgType type, IN MsgType type,
IN wchar_t* text1, IN const wchar_t* text1,
IN wchar_t* text2 = 0, IN const wchar_t* text2 = nullptr,
IN wchar_t* text3 = 0 IN const wchar_t* text3 = nullptr
); );
// //

Просмотреть файл

@ -199,6 +199,8 @@ CSyntaxTreeItem* ConstraintsParser::constructSyntaxTreeItem
case TokenType_ParenthesisClose: case TokenType_ParenthesisClose:
--parenthesesCount; --parenthesesCount;
break; break;
default:
break;
} }
++token; ++token;
@ -208,6 +210,8 @@ CSyntaxTreeItem* ConstraintsParser::constructSyntaxTreeItem
operands.push( constructSyntaxTreeItem( tokenBegin, token, false )); operands.push( constructSyntaxTreeItem( tokenBegin, token, false ));
break; break;
} }
default:
break;
} }
} }
@ -254,6 +258,7 @@ CSyntaxTreeItem* ConstraintsParser::constructSyntaxTreeItem
delete( (CSyntaxTreeItem*) operands.top() ); delete( (CSyntaxTreeItem*) operands.top() );
operands.pop(); operands.pop();
} }
return nullptr;
} }
} }
@ -280,7 +285,7 @@ CSyntaxTreeItem* ConstraintsParser::processOneLogicalOper( IN COperators& operat
break; break;
case LogicalOper_NOT: case LogicalOper_NOT:
node->LLink = operands.top(); node->LLink = operands.top();
// the right node remains NULL // the right node remains "nullptr"
operands.pop(); operands.pop();
break; break;
default: default:
@ -338,7 +343,7 @@ void ConstraintsParser::removeNOTs()
// //
void ConstraintsParser::removeBranchNOTs( IN CSyntaxTreeItem* item, IN bool carryOver ) void ConstraintsParser::removeBranchNOTs( IN CSyntaxTreeItem* item, IN bool carryOver )
{ {
if ( NULL == item) return; if ( nullptr == item) return;
switch( item->Type ) 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 // zero out the data pointer of LLink so during clean-up we don't
// delete the data that was just assigned to current item // delete the data that was just assigned to current item
node->LLink->Data = NULL; node->LLink->Data = nullptr;
delete( node ); delete( node );
break; break;
default: default:
@ -463,7 +468,7 @@ void ConstraintsParser::verifyConstraint( CConstraint& constraint )
// //
void ConstraintsParser::verifySyntaxTreeItem( CSyntaxTreeItem* item ) void ConstraintsParser::verifySyntaxTreeItem( CSyntaxTreeItem* item )
{ {
if ( NULL == item ) return; if ( nullptr == item ) return;
if ( ItemType_Term == item->Type ) if ( ItemType_Term == item->Type )
{ {
@ -488,7 +493,7 @@ void ConstraintsParser::verifySyntaxTreeItem( CSyntaxTreeItem* item )
void ConstraintsParser::verifyTerm( CTerm* term ) void ConstraintsParser::verifyTerm( CTerm* term )
{ {
// Is Parameter defined in the model? // Is Parameter defined in the model?
if ( term->Parameter == NULL ) if ( term->Parameter == nullptr )
{ {
throw CSemanticWarning( ValidationWarnType_UnknownParameter ); throw CSemanticWarning( ValidationWarnType_UnknownParameter );
} }
@ -521,7 +526,7 @@ void ConstraintsParser::verifyTerm( CTerm* term )
// Is second parameter defined? // Is second parameter defined?
if ( term->DataType == SyntaxTermDataType_ParameterName ) if ( term->DataType == SyntaxTermDataType_ParameterName )
{ {
if ( term->Data == NULL ) if ( term->Data == nullptr )
{ {
throw CSemanticWarning( ValidationWarnType_UnknownParameter ); throw CSemanticWarning( ValidationWarnType_UnknownParameter );
} }
@ -569,13 +574,15 @@ void ConstraintsParser::verifyFunction( CFunction *function )
case FunctionTypeIsNegativeParam: case FunctionTypeIsNegativeParam:
case FunctionTypeIsPositiveParam: case FunctionTypeIsPositiveParam:
{ {
if ( function->Data == NULL && ! function->DataText.empty() ) if ( function->Data == nullptr && ! function->DataText.empty() )
{ {
throw CSemanticWarning( ValidationWarnType_UnknownParameter ); throw CSemanticWarning( ValidationWarnType_UnknownParameter );
} }
break; break;
} }
default:
break;
} }
} }
} }

Просмотреть файл

@ -261,7 +261,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens )
// check whether it's one of the functions // check whether it's one of the functions
CFunction *function = getFunction(); CFunction *function = getFunction();
if( NULL != function ) if( nullptr != function )
{ {
CToken* token; CToken* token;
try try
@ -282,7 +282,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens )
wstring paramName = getParameterName(); wstring paramName = getParameterName();
CParameters::iterator found = _model.findParamByName( paramName ); CParameters::iterator found = _model.findParamByName( paramName );
CParameter* param = NULL; CParameter* param = nullptr;
if ( found != _model.Parameters.end() ) if ( found != _model.Parameters.end() )
{ {
param = &*found; param = &*found;
@ -293,7 +293,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens )
skipWhiteChars(); skipWhiteChars();
CTerm* term = NULL; CTerm* term = nullptr;
switch( relation ) switch( relation )
{ {
case Relation_IN: case Relation_IN:
@ -350,7 +350,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens )
// //
// look up parameters by their names and return references // look up parameters by their names and return references
// //
CParameter *param2 = NULL; CParameter *param2 = nullptr;
found = _model.findParamByName( paramName2 ); found = _model.findParamByName( paramName2 );
if ( found != _model.Parameters.end() ) if ( found != _model.Parameters.end() )
{ {
@ -405,7 +405,7 @@ void ConstraintsTokenizer::parseTerm( IN OUT CTokenList& tokens )
// <term> ::= IsNegative(<parameter_name>) // <term> ::= IsNegative(<parameter_name>)
// //
// Returns a CFunction object if in fact a function was parsed // Returns a CFunction object if in fact a function was parsed
// or NULL otherwise // or "nullptr" otherwise
// //
CFunction *ConstraintsTokenizer::getFunction() CFunction *ConstraintsTokenizer::getFunction()
{ {
@ -424,7 +424,7 @@ CFunction *ConstraintsTokenizer::getFunction()
} }
else else
{ {
return NULL; return nullptr;
} }
// opening bracket // opening bracket
@ -438,7 +438,7 @@ CFunction *ConstraintsTokenizer::getFunction()
wstring paramName = getString( charArrToStr( TEXT_TokenParenthesisClose )); wstring paramName = getString( charArrToStr( TEXT_TokenParenthesisClose ));
CParameters::iterator found = _model.findParamByName( paramName ); CParameters::iterator found = _model.findParamByName( paramName );
CParameter* param = NULL; CParameter* param = nullptr;
if ( found != _model.Parameters.end() ) if ( found != _model.Parameters.end() )
{ {
param = &*found; param = &*found;
@ -759,8 +759,8 @@ void ConstraintsTokenizer::doPostParseExpansions( IN OUT CTokenList& tokens )
&& function->DataText.empty() ) && function->DataText.empty() )
{ {
// deallocate the current token // deallocate the current token
// we don't have to deallocate Data because in this case it is always NULL // we don't have to deallocate Data because in this case it is always "nullptr"
assert( function->Data == NULL ); assert( function->Data == nullptr );
// save positionInText and rawText and reuse it in all new tokens // save positionInText and rawText and reuse it in all new tokens
wstring::iterator oldPosInText = (*i_token)->PositionInText; wstring::iterator oldPosInText = (*i_token)->PositionInText;

Просмотреть файл

@ -288,8 +288,8 @@ void ConstraintsInterpreter::interpretFunction( IN CFunction* function, IN OUT C
for( unsigned int idx = 0; idx < modelParam.Values.size(); ++idx ) for( unsigned int idx = 0; idx < modelParam.Values.size(); ++idx )
{ {
bool positive = modelParam.Values[ idx ].IsPositive(); bool positive = modelParam.Values[ idx ].IsPositive();
if( function->Type == FunctionTypeIsNegativeParam && ! positive if( (function->Type == FunctionTypeIsNegativeParam && ! positive)
|| function->Type == FunctionTypeIsPositiveParam && positive ) || (function->Type == FunctionTypeIsPositiveParam && positive) )
{ {
Exclusion newExcl; Exclusion newExcl;
newExcl.insert( make_pair( _gcdParameters[ paramIdx ], idx )); 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 ) 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 // a case where where there is no condition
if ( ItemType_Term == item->Type ) 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 ) void ConstraintsInterpreter::interpretConstraint( IN const CConstraint& constraint, IN OUT CGcdExclusions& gcdExclusions )
{ {
// if there's no condition, look at the term only // if there's no condition, look at the term only
if ( NULL == constraint.Condition ) if ( nullptr == constraint.Condition )
{ {
interpretSyntaxTreeItem( constraint.Term, gcdExclusions ); interpretSyntaxTreeItem( constraint.Term, gcdExclusions );
} }

Просмотреть файл

@ -1,5 +1,3 @@
#pragma once
#include "cmdline.h" #include "cmdline.h"
#include "gcdexcl.h" #include "gcdexcl.h"
#include "gcdmodel.h" #include "gcdmodel.h"

Просмотреть файл

@ -278,7 +278,7 @@ void CModelData::PrintModelContents( wstring title )
for( auto & param : Parameters ) for( auto & param : Parameters )
{ {
wcerr << L" " << param.Name << L":\t" << (unsigned int) param.Values.size() << L" values, order: "; 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; wcerr << L"?" << endl;
else else
wcerr << param.Order << L" : " << param.GcdPointer->GetOrder() << endl; wcerr << param.Order << L" : " << param.GcdPointer->GetOrder() << endl;

Просмотреть файл

@ -59,7 +59,7 @@ public:
CModelParameter() : CModelParameter() :
IsResultParameter( false ), IsResultParameter( false ),
GcdPointer( NULL ) {} GcdPointer( nullptr ) {}
int GetValueOrdinal( IN std::wstring& name, IN bool caseSensitive ); int GetValueOrdinal( IN std::wstring& name, IN bool caseSensitive );
bool ValueNamesUnique( IN bool CaseSensitive ); bool ValueNamesUnique( IN bool CaseSensitive );

Просмотреть файл

@ -193,7 +193,7 @@ bool CModelData::readParameter( wstring& line )
size_t weightEnd = i_val->find_last_of( WEIGHT_END ); size_t weightEnd = i_val->find_last_of( WEIGHT_END );
// '(' must exist, ')' must be the last character // '(' 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 )); wstring weightStr = trim( i_val->substr( weightBegin + 1, weightEnd - weightBegin - 1 ));
double weightDbl = 0; double weightDbl = 0;

Просмотреть файл

@ -46,7 +46,7 @@ int __cdecl execute
IN OUT wstring& output IN OUT wstring& output
) )
{ {
time_t start = time( NULL ); time_t start = time( nullptr );
CModelData modelData; CModelData modelData;
@ -73,7 +73,7 @@ int __cdecl execute
return err; return err;
} }
time_t end = time( NULL ); time_t end = time( nullptr );
// if r has been provided then print out the seed // if r has been provided then print out the seed
// TODO: change to not use SWITCH_RANDOMIZE const // TODO: change to not use SWITCH_RANDOMIZE const

Просмотреть файл

@ -3,8 +3,8 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <cctype> #include <cctype>
#include <wchar.h> #include <cwchar>
#include <assert.h> #include <cassert>
#include "strings.h" #include "strings.h"
using namespace std; 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 ) ); return( wstring( c ) );
} }

Просмотреть файл

@ -110,7 +110,7 @@ std::wstring charToStr
// //
std::wstring charArrToStr std::wstring charArrToStr
( (
IN wchar_t* c IN const wchar_t* c
); );
// //