Skip to content

Commit

Permalink
Pass const references as suggested by cppcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
mungre committed Jun 11, 2024
1 parent 8111b99 commit 7752058
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/asmexception.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AsmException_FileError : public AsmException
class AsmException_FileError_##a : public AsmException_FileError \
{ \
public: \
explicit AsmException_FileError_##a( const std::string filename ) \
explicit AsmException_FileError_##a( const std::string& filename ) \
: AsmException_FileError( filename ) {} \
\
virtual ~AsmException_FileError_##a() {} \
Expand Down Expand Up @@ -120,13 +120,13 @@ class AsmException_SyntaxError : public AsmException
{
}

AsmException_SyntaxError( std::string line, int column )
AsmException_SyntaxError( const std::string& line, int column )
: m_line( line ),
m_column( column )
{
}

AsmException_SyntaxError( std::string line, int column, std::string extra )
AsmException_SyntaxError( const std::string& line, int column, const std::string& extra )
: m_line( line ),
m_column( column ),
m_extra( extra )
Expand Down Expand Up @@ -161,7 +161,7 @@ class AsmException_SyntaxError : public AsmException
class AsmException_SyntaxError_##a : public AsmException_SyntaxError \
{ \
public: \
AsmException_SyntaxError_##a( std::string line, int column ) \
AsmException_SyntaxError_##a( const std::string& line, int column ) \
: AsmException_SyntaxError( line, column ) {} \
\
virtual ~AsmException_SyntaxError_##a() {} \
Expand All @@ -174,7 +174,7 @@ public: \
class AsmException_SyntaxError_##a : public AsmException_SyntaxError \
{ \
public: \
AsmException_SyntaxError_##a( std::string line, int column, std::string extra ) \
AsmException_SyntaxError_##a( const std::string& line, int column, const std::string& extra ) \
: AsmException_SyntaxError( line, column, extra ) {} \
\
virtual ~AsmException_SyntaxError_##a() {} \
Expand Down Expand Up @@ -270,7 +270,7 @@ class AsmException_AssembleError : public AsmException_SyntaxError

virtual ~AsmException_AssembleError() {}

void SetString( std::string line ) { m_line = line; }
void SetString( const std::string& line ) { m_line = line; }
void SetColumn( int column ) { m_column = column; }

virtual const char* Message() const
Expand Down Expand Up @@ -309,7 +309,7 @@ class AsmException_UserError : public AsmException_SyntaxError
{
public:

AsmException_UserError( std::string line, int column, std::string message )
AsmException_UserError( const std::string& line, int column, const std::string& message )
: AsmException_SyntaxError( line, column ),
m_message( message )
{
Expand Down
16 changes: 6 additions & 10 deletions src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,17 @@ template<class T> class Argument
// No value was available (i.e. the end of the parameters)
StateMissing
};
Argument(string line, int column, State state) :
Argument(const string& line, int column, State state) :
m_line(line), m_column(column), m_state(state)
{
}
Argument(string line, int column, T value) :
Argument(const string& line, int column, const T& value) :
m_line(line), m_column(column), m_state(StateFound), m_value(value)
{
}
Argument(const Argument<T>& that) :
m_line(that.m_line), m_column(that.m_column), m_state(that.m_state), m_value(that.m_value)
{
m_line = that.m_line;
m_column = that.m_column;
m_state = that.m_state;
m_value = that.m_value;
}
// Is a value available?
bool Found() const
Expand Down Expand Up @@ -226,7 +222,7 @@ template<class T> class Argument
}
// Set a default value for optional parameters.
// This is overloaded for strings below.
Argument<T>& Default(T value)
Argument<T>& Default(const T& value)
{
if ( !Found() )
{
Expand Down Expand Up @@ -265,7 +261,7 @@ typedef Argument<double> DoubleArg;
typedef Argument<string> StringArg;
typedef Argument<Value> ValueArg;

template<> StringArg& StringArg::Default(string value)
template<> StringArg& StringArg::Default(const string& value)
{
if ( !Found() )
{
Expand Down Expand Up @@ -1218,12 +1214,12 @@ void LineParser::HandleSave()

if ( !objFile )
{
throw AsmException_FileError_OpenObj( saveFile.c_str() );
throw AsmException_FileError_OpenObj( saveFile );
}

if ( !objFile.write( reinterpret_cast< const char* >( ObjectCode::Instance().GetAddr( start ) ), end - start ) )
{
throw AsmException_FileError_WriteObj( saveFile.c_str() );
throw AsmException_FileError_WriteObj( saveFile );
}

objFile.close();
Expand Down
4 changes: 2 additions & 2 deletions src/lineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using namespace std;
Constructor for LineParser
*/
/*************************************************************************************************/
LineParser::LineParser( SourceCode* sourceCode, string line )
LineParser::LineParser( SourceCode* sourceCode, const string& line )
: m_sourceCode( sourceCode ),
m_line( line ),
m_column( 0 )
Expand Down Expand Up @@ -76,7 +76,7 @@ LineParser::~LineParser()
Process one line of the file
*/
/*************************************************************************************************/
void LineParser::Process( string line )
void LineParser::Process( const string& line )
{
m_line = line;
m_column = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/lineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class LineParser

// Constructor/destructor

LineParser( SourceCode* sourceCode, std::string line );
LineParser( SourceCode* sourceCode, const std::string& line );
LineParser( SourceCode* sourceCode );
~LineParser();

// Process the given line

void Process( std::string line );
void Process( const std::string& line );

// Accessors

Expand Down
2 changes: 1 addition & 1 deletion src/sourcecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ bool SourceCode::IsRealForLevel( int level ) const
Search up the stack for a value for a symbol. N.B. This is dynamic scoping.
*/
/*************************************************************************************************/
bool SourceCode::GetSymbolValue(std::string name, Value& value)
bool SourceCode::GetSymbolValue(const std::string& name, Value& value)
{
for ( int forLevel = GetForLevel(); forLevel >= 0; forLevel-- )
{
Expand Down
2 changes: 1 addition & 1 deletion src/sourcecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class SourceCode
inline int GetInitialForStackPtr() const { return m_initialForStackPtr; }
inline Macro* GetCurrentMacro() { return m_currentMacro; }

bool GetSymbolValue(std::string name, Value& value);
bool GetSymbolValue(const std::string& name, Value& value);
ScopedSymbolName GetScopedSymbolName( const std::string& symbolName, int level = -1 ) const;

bool ShouldOutputAsm();
Expand Down
2 changes: 1 addition & 1 deletion src/sourcefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using namespace std;
The supplied file will be opened. If there is a problem, an AsmException will be thrown.
*/
/*************************************************************************************************/
static string ReadFile( string filename )
static string ReadFile( const string& filename )
{
// we have to open in binary, due to a bug in MinGW which means that calling
// tellg() on a text-mode file ruins the file pointer!
Expand Down

0 comments on commit 7752058

Please sign in to comment.