Replace error reporting in DRC rule compiler.

This commit is contained in:
Jeff Young 2020-08-13 18:47:41 +01:00
parent 0b17dbd123
commit 519bc80394
5 changed files with 46 additions and 22 deletions

View File

@ -615,25 +615,13 @@ void COMPILER::reportError( COMPILATION_STAGE stage, const wxString& aErrorMsg,
if( aPos == -1 )
aPos = m_sourcePos;
// fixme: no HTML or anything UI-related here.
#if 0
wxString rest;
wxString first = aErrorMsg.BeforeFirst( '|', &rest );
wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
m_originLine,
m_originOffset + aPos,
first,
rest );
#endif
m_errorStatus.pendingError = true;
m_errorStatus.stage = stage;
m_errorStatus.message = aErrorMsg;
m_errorStatus.srcPos = aPos;
if( m_errorCallback )
m_errorCallback( m_errorStatus );
m_errorCallback( aErrorMsg, aPos );
}

View File

@ -429,7 +429,11 @@ public:
bool Compile( const wxString& aString, UCODE* aCode, CONTEXT* aPreflightContext );
void SetErrorCallback( std::function<void(const ERROR_STATUS&)> aCallback );
void SetErrorCallback( std::function<void( const wxString& aMessage, int aOffset )> aCallback )
{
m_errorCallback = aCallback;
}
bool IsErrorPending() const { return m_errorStatus.pendingError; }
const ERROR_STATUS& GetError() const { return m_errorStatus; }
@ -454,8 +458,8 @@ protected:
/* Tokenizer: Next token/value taken from input string. */
T_TOKEN getToken();
bool lexDefault( T_TOKEN& aToken );
bool lexString( T_TOKEN& aToken );
bool lexDefault( T_TOKEN& aToken );
bool lexString( T_TOKEN& aToken );
int resolveUnits();
@ -474,7 +478,7 @@ protected:
ERROR_STATUS m_errorStatus;
std::vector<TREE_NODE*> m_gcItems;
std::vector<wxString*> m_gcStrings;
std::function<void(const ERROR_STATUS&)> m_errorCallback;
std::function<void( const wxString& aMessage, int aOffset )> m_errorCallback;
};

View File

@ -25,7 +25,7 @@
#include <fctsys.h>
#include <class_board.h>
#include <class_board_item.h>
#include <reporter.h>
#include <drc/drc_rule.h>
#include <pcb_expr_evaluator.h>
@ -119,7 +119,21 @@ bool DRC_RULE_CONDITION::EvaluateFor( const BOARD_ITEM* aItemA, const BOARD_ITEM
bool DRC_RULE_CONDITION::Compile( REPORTER* aReporter, int aSourceLine, int aSourceOffset )
{
auto errorHandler = [&]( const wxString& aMessage, int aOffset )
{
wxString rest;
wxString first = aMessage.BeforeFirst( '|', &rest );
wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
aSourceLine,
aSourceOffset + aOffset,
first,
rest );
aReporter->Report( msg, RPT_SEVERITY_ERROR );
};
PCB_EXPR_COMPILER compiler;
compiler.SetErrorCallback( errorHandler );
if (!m_ucode)
m_ucode = new PCB_EXPR_UCODE;

View File

@ -376,10 +376,22 @@ void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule )
void DRC_RULES_PARSER::parseValueWithUnits( const wxString& aExpr, int& aResult )
{
PCB_EXPR_EVALUATOR evaluator;
// m_reporter, CurLineNumber(), CurOffset() );
auto errorHandler = [&]( const wxString& aMessage, int aOffset )
{
wxString rest;
wxString first = aMessage.BeforeFirst( '|', &rest );
wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
CurLineNumber(),
CurOffset() + aOffset,
first,
rest );
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
};
PCB_EXPR_EVALUATOR evaluator;
evaluator.SetErrorCallback( errorHandler );
evaluator.Evaluate( aExpr );
aResult = evaluator.Result();
}

View File

@ -75,7 +75,7 @@ public:
}
private:
BOARD_ITEM* m_items[2];
BOARD_ITEM* m_items[2];
PCB_LAYER_ID m_layer;
};
@ -159,6 +159,12 @@ public:
bool Evaluate( const wxString& aExpr );
int Result() const { return m_result; }
void SetErrorCallback( std::function<void( const wxString& aMessage, int aOffset )> aCallback )
{
m_compiler.SetErrorCallback( aCallback );
}
bool IsErrorPending() const { return m_errorStatus.pendingError; }
const LIBEVAL::ERROR_STATUS& GetError() const { return m_errorStatus; }