Fix error reporting from function pre-flighting.
This commit is contained in:
parent
a97f2fb22a
commit
050bbcdb4f
|
@ -605,7 +605,7 @@ void CONTEXT::ReportError( const wxString& aErrorMsg )
|
||||||
m_errorStatus.stage = CST_RUNTIME;
|
m_errorStatus.stage = CST_RUNTIME;
|
||||||
|
|
||||||
if( m_errorCallback )
|
if( m_errorCallback )
|
||||||
m_errorCallback( m_errorStatus );
|
m_errorCallback( m_errorStatus.message, m_errorStatus.srcPos );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -779,7 +779,7 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
|
||||||
// leaf[0]: function name
|
// leaf[0]: function name
|
||||||
// leaf[1]: parameter
|
// leaf[1]: parameter
|
||||||
|
|
||||||
wxString itemName = *node->leaf[0]->value.str;
|
wxString itemName = *node->leaf[0]->value.str;
|
||||||
std::unique_ptr<VAR_REF> vref = aCode->CreateVarRef( itemName, "" );
|
std::unique_ptr<VAR_REF> vref = aCode->CreateVarRef( itemName, "" );
|
||||||
|
|
||||||
if( !vref )
|
if( !vref )
|
||||||
|
@ -802,15 +802,19 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
|
||||||
if( func )
|
if( func )
|
||||||
{
|
{
|
||||||
// Preflight the function call
|
// Preflight the function call
|
||||||
wxString paramStr;
|
wxString paramStr = *node->leaf[1]->leaf[1]->value.str;
|
||||||
|
VALUE* param = aPreflightContext->AllocValue();
|
||||||
|
|
||||||
if( node->value.str )
|
|
||||||
paramStr = *node->value.str;
|
|
||||||
|
|
||||||
VALUE* param = aPreflightContext->AllocValue();
|
|
||||||
param->Set( paramStr );
|
param->Set( paramStr );
|
||||||
aPreflightContext->Push( param );
|
aPreflightContext->Push( param );
|
||||||
|
|
||||||
|
aPreflightContext->SetErrorCallback(
|
||||||
|
[&]( const wxString& aMessage, int aOffset )
|
||||||
|
{
|
||||||
|
size_t loc = node->leaf[1]->leaf[1]->srcPos- paramStr.Length();
|
||||||
|
reportError( CST_CODEGEN, aMessage, (int) loc - 1 );
|
||||||
|
} );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
func( aPreflightContext, vref.get() );
|
func( aPreflightContext, vref.get() );
|
||||||
|
@ -819,13 +823,6 @@ bool COMPILER::generateUCode( UCODE* aCode, CONTEXT* aPreflightContext )
|
||||||
catch( ... )
|
catch( ... )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !aPreflightContext->IsErrorPending() )
|
|
||||||
{
|
|
||||||
size_t loc = node->leaf[1]->leaf[1]->srcPos - paramStr.Length();
|
|
||||||
reportError( CST_CODEGEN, aPreflightContext->GetError().message,
|
|
||||||
(int) loc - 1 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node->leaf[0]->isVisited = true;
|
node->leaf[0]->isVisited = true;
|
||||||
|
|
|
@ -285,7 +285,11 @@ public:
|
||||||
return m_stack.size();
|
return m_stack.size();
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetErrorCallback( std::function<void(const ERROR_STATUS&)> aCallback );
|
void SetErrorCallback( std::function<void( const wxString& aMessage, int aOffset )> aCallback )
|
||||||
|
{
|
||||||
|
m_errorCallback = std::move( aCallback );
|
||||||
|
}
|
||||||
|
|
||||||
void ReportError( const wxString& aErrorMsg );
|
void ReportError( const wxString& aErrorMsg );
|
||||||
bool IsErrorPending() const { return m_errorStatus.pendingError; }
|
bool IsErrorPending() const { return m_errorStatus.pendingError; }
|
||||||
const ERROR_STATUS& GetError() const { return m_errorStatus; }
|
const ERROR_STATUS& GetError() const { return m_errorStatus; }
|
||||||
|
@ -294,7 +298,8 @@ private:
|
||||||
std::vector<VALUE*> m_ownedValues;
|
std::vector<VALUE*> m_ownedValues;
|
||||||
std::stack<VALUE*> m_stack;
|
std::stack<VALUE*> m_stack;
|
||||||
ERROR_STATUS m_errorStatus;
|
ERROR_STATUS m_errorStatus;
|
||||||
std::function<void(const ERROR_STATUS&)> m_errorCallback;
|
|
||||||
|
std::function<void( const wxString& aMessage, int aOffset )> m_errorCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue