Fix up some Coverity and CLion warnings.
This commit is contained in:
parent
2b0b7a5153
commit
edda024285
|
@ -166,7 +166,7 @@ wxString UCODE::Dump() const
|
|||
};
|
||||
|
||||
|
||||
wxString TOKENIZER::GetChars( std::function<bool( wxUniChar )> cond ) const
|
||||
wxString TOKENIZER::GetChars( const std::function<bool( wxUniChar )>& cond ) const
|
||||
{
|
||||
wxString rv;
|
||||
size_t p = m_pos;
|
||||
|
@ -180,9 +180,10 @@ wxString TOKENIZER::GetChars( std::function<bool( wxUniChar )> cond ) const
|
|||
return rv;
|
||||
}
|
||||
|
||||
bool TOKENIZER::MatchAhead( const wxString& match, std::function<bool( wxUniChar )> stopCond ) const
|
||||
bool TOKENIZER::MatchAhead( const wxString& match,
|
||||
const std::function<bool( wxUniChar )>& stopCond ) const
|
||||
{
|
||||
int remaining = m_str.Length() - m_pos;
|
||||
int remaining = (int) m_str.Length() - m_pos;
|
||||
|
||||
if( remaining < (int) match.length() )
|
||||
return false;
|
||||
|
@ -266,9 +267,7 @@ bool COMPILER::Compile( const wxString& aString, UCODE* aCode, CONTEXT* aPreflig
|
|||
|
||||
m_tree = nullptr;
|
||||
m_parseFinished = false;
|
||||
T_TOKEN tok;
|
||||
|
||||
tok.value.str = nullptr;
|
||||
T_TOKEN tok( defaultToken );
|
||||
|
||||
libeval_dbg(0, "str: '%s' empty: %d\n", aString.c_str(), !!aString.empty() );
|
||||
|
||||
|
@ -639,48 +638,44 @@ void COMPILER::freeTree( LIBEVAL::TREE_NODE *tree )
|
|||
if ( tree->leaf[1] )
|
||||
freeTree( tree->leaf[1] );
|
||||
|
||||
if( tree->uop )
|
||||
{
|
||||
delete tree->uop;
|
||||
}
|
||||
delete tree->uop;
|
||||
}
|
||||
|
||||
|
||||
void TREE_NODE::SetUop( int aOp, double aValue )
|
||||
{
|
||||
if( uop )
|
||||
delete uop;
|
||||
delete uop;
|
||||
|
||||
std::unique_ptr<VALUE> val( new VALUE( aValue ) );
|
||||
uop = new UOP( aOp, std::move( val ) );
|
||||
}
|
||||
|
||||
|
||||
void TREE_NODE::SetUop( int aOp, const wxString& aValue )
|
||||
{
|
||||
if( uop )
|
||||
delete uop;
|
||||
delete uop;
|
||||
|
||||
std::unique_ptr<VALUE> val( new VALUE( aValue ) );
|
||||
uop = new UOP( aOp, std::move( val ) );
|
||||
}
|
||||
|
||||
|
||||
void TREE_NODE::SetUop( int aOp, std::unique_ptr<VAR_REF> aRef )
|
||||
{
|
||||
if( uop )
|
||||
delete uop;
|
||||
delete uop;
|
||||
|
||||
uop = new UOP( aOp, std::move( aRef ) );
|
||||
}
|
||||
|
||||
|
||||
void TREE_NODE::SetUop( int aOp, FUNC_CALL_REF aFunc, std::unique_ptr<VAR_REF> aRef )
|
||||
{
|
||||
if( uop )
|
||||
delete uop;
|
||||
delete uop;
|
||||
|
||||
uop = new UOP( aOp, std::move( aFunc ), std::move( aRef ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void prepareTree( LIBEVAL::TREE_NODE *node )
|
||||
{
|
||||
node->isVisited = false;
|
||||
|
@ -828,7 +823,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
|
|||
|
||||
if( !aPreflightContext->IsErrorPending() )
|
||||
{
|
||||
size_t loc = node->leaf[1]->leaf[1]->srcPos - node->value.str->Length();
|
||||
size_t loc = node->leaf[1]->leaf[1]->srcPos - paramStr.Length();
|
||||
reportError( CST_CODEGEN, aPreflightContext->GetError().message,
|
||||
(int) loc - 1 );
|
||||
}
|
||||
|
|
|
@ -67,10 +67,9 @@ struct ERROR_STATUS
|
|||
{
|
||||
bool pendingError = false;
|
||||
|
||||
|
||||
COMPILATION_STAGE stage;
|
||||
wxString message; // Note: use wxString for GUI-related strings
|
||||
int srcPos;
|
||||
COMPILATION_STAGE stage;
|
||||
wxString message;
|
||||
int srcPos;
|
||||
};
|
||||
|
||||
|
||||
|
@ -84,6 +83,7 @@ enum VAR_TYPE_T
|
|||
|
||||
enum TOKEN_TYPE_T
|
||||
{
|
||||
TR_UNDEFINED = 0,
|
||||
TR_NUMBER = 1,
|
||||
TR_IDENTIFIER = 2,
|
||||
TR_ASSIGN = 3,
|
||||
|
@ -101,19 +101,25 @@ typedef std::function<void( CONTEXT*, void* )> FUNC_CALL_REF;
|
|||
|
||||
struct T_TOKEN_VALUE
|
||||
{
|
||||
wxString *str;
|
||||
double num;
|
||||
int idx;
|
||||
wxString* str;
|
||||
double num;
|
||||
int idx;
|
||||
};
|
||||
|
||||
// Lemon can't handle c'tors and d'tors, so we provide a poor-man's version.
|
||||
constexpr T_TOKEN_VALUE defaultTokenValue = { nullptr, 0.0, 0 };
|
||||
|
||||
|
||||
struct T_TOKEN
|
||||
{
|
||||
int token;
|
||||
int token;
|
||||
T_TOKEN_VALUE value;
|
||||
};
|
||||
|
||||
// Lemon can't handle c'tors and d'tors, so we provide a poor-man's version.
|
||||
constexpr T_TOKEN defaultToken = { TR_UNDEFINED, defaultTokenValue };
|
||||
|
||||
|
||||
class TREE_NODE
|
||||
{
|
||||
public:
|
||||
|
@ -134,7 +140,8 @@ public:
|
|||
};
|
||||
|
||||
|
||||
TREE_NODE* newNode( LIBEVAL::COMPILER* compiler, int op, const T_TOKEN_VALUE& value = defaultTokenValue);
|
||||
TREE_NODE* newNode( LIBEVAL::COMPILER* compiler, int op,
|
||||
const T_TOKEN_VALUE& value = defaultTokenValue );
|
||||
|
||||
class UNIT_RESOLVER
|
||||
{
|
||||
|
@ -351,9 +358,9 @@ public:
|
|||
wxString Format() const;
|
||||
|
||||
private:
|
||||
int m_op;
|
||||
int m_op;
|
||||
|
||||
FUNC_CALL_REF m_func;
|
||||
FUNC_CALL_REF m_func;
|
||||
std::unique_ptr<VAR_REF> m_ref;
|
||||
std::unique_ptr<VALUE> m_value;
|
||||
};
|
||||
|
@ -396,13 +403,14 @@ public:
|
|||
return m_pos;
|
||||
}
|
||||
|
||||
wxString GetChars( std::function<bool( wxUniChar )> cond ) const;
|
||||
wxString GetChars( const std::function<bool( wxUniChar )>& cond ) const;
|
||||
|
||||
bool MatchAhead( const wxString& match, std::function<bool( wxUniChar )> stopCond ) const;
|
||||
bool MatchAhead( const wxString& match,
|
||||
const std::function<bool( wxUniChar )>& stopCond ) const;
|
||||
|
||||
private:
|
||||
wxString m_str;
|
||||
size_t m_pos;
|
||||
size_t m_pos = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -431,7 +439,7 @@ public:
|
|||
|
||||
void SetErrorCallback( std::function<void( const wxString& aMessage, int aOffset )> aCallback )
|
||||
{
|
||||
m_errorCallback = aCallback;
|
||||
m_errorCallback = std::move( aCallback );
|
||||
}
|
||||
|
||||
bool IsErrorPending() const { return m_errorStatus.pendingError; }
|
||||
|
@ -473,12 +481,14 @@ protected:
|
|||
|
||||
int m_sourcePos;
|
||||
bool m_parseFinished;
|
||||
ERROR_STATUS m_errorStatus;
|
||||
|
||||
std::function<void( const wxString& aMessage, int aOffset )> m_errorCallback;
|
||||
|
||||
TREE_NODE* m_tree;
|
||||
ERROR_STATUS m_errorStatus;
|
||||
|
||||
std::vector<TREE_NODE*> m_gcItems;
|
||||
std::vector<wxString*> m_gcStrings;
|
||||
std::function<void( const wxString& aMessage, int aOffset )> m_errorCallback;
|
||||
std::vector<wxString*> m_gcStrings;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue