Compile layer test into CONSTRAINT_WITH_CONDITIONS.

Also processes constraints in correct order for priority (reversed)
and removes multiple-expression-conditions for a single constraint
(which is not supported in the grammar).
This commit is contained in:
Jeff Young 2020-09-13 00:38:35 +01:00
parent 8420fcc33b
commit d47d119d5f
2 changed files with 25 additions and 35 deletions

View File

@ -293,7 +293,7 @@ static wxString formatConstraint( const DRC_CONSTRAINT& constraint )
} }
bool DRC_ENGINE::LoadRules( wxFileName aPath ) bool DRC_ENGINE::LoadRules( const wxFileName& aPath )
{ {
NULL_REPORTER nullReporter; NULL_REPORTER nullReporter;
REPORTER* reporter = m_reporter ? m_reporter : &nullReporter; REPORTER* reporter = m_reporter ? m_reporter : &nullReporter;
@ -374,8 +374,8 @@ bool DRC_ENGINE::CompileRules()
CONSTRAINT_WITH_CONDITIONS* rcons = new CONSTRAINT_WITH_CONDITIONS; CONSTRAINT_WITH_CONDITIONS* rcons = new CONSTRAINT_WITH_CONDITIONS;
if( condition ) rcons->layerTest = rule->m_LayerCondition;
rcons->conditions.push_back( condition ); rcons->condition = condition;
matchingConstraints.push_back( constraint ); matchingConstraints.push_back( constraint );
@ -410,7 +410,7 @@ bool DRC_ENGINE::CompileRules()
} }
void DRC_ENGINE::InitEngine( wxFileName aRulePath ) void DRC_ENGINE::InitEngine( const wxFileName& aRulePath )
{ {
m_testProviders = DRC_TEST_PROVIDER_REGISTRY::Instance().GetTestProviders(); m_testProviders = DRC_TEST_PROVIDER_REGISTRY::Instance().GetTestProviders();
@ -520,37 +520,29 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI
} }
} }
auto ruleset = m_constraintMap[ aConstraintId ]; CONSTRAINT_SET* ruleset = m_constraintMap[ aConstraintId ];
for( const CONSTRAINT_WITH_CONDITIONS* rcond : ruleset->sortedConstraints ) for( int ii = ruleset->sortedConstraints.size() - 1; ii >= 0; --ii )
{ {
DRC_RULE* rule = rcond->parentRule; const CONSTRAINT_WITH_CONDITIONS* rcons = ruleset->sortedConstraints[ ii ];
REPORT( wxString::Format( _( "Checking rule \"%s\"." ), rule->m_Name ) ); REPORT( wxString::Format( _( "Checking rule \"%s\"." ),
rcons->parentRule->m_Name ) );
if( aLayer != UNDEFINED_LAYER && !rule->m_LayerCondition.test( aLayer ) ) if( aLayer != UNDEFINED_LAYER && !rcons->layerTest.test( aLayer ) )
{ {
REPORT( wxString::Format( _( "Rule layer \"%s\" not matched." ), REPORT( wxString::Format( _( "Rule layer \"%s\" not matched." ),
rule->m_LayerSource ) ); rcons->parentRule->m_LayerSource ) );
REPORT( "Rule not applied." ); REPORT( "Rule not applied." );
continue; continue;
} }
if( rcond->conditions.size() == 0 ) // uconditional bool result = rcons->condition->EvaluateFor( a, b, aLayer, aReporter );
{
REPORT( _( "Unconditional constraint; rule applied." ) );
return rcond->constraint;
}
for( DRC_RULE_CONDITION* condition : rcond->conditions )
{
bool result = condition->EvaluateFor( a, b, aLayer, aReporter );
if( result ) if( result )
{ {
REPORT( _( "Rule applied." ) ); REPORT( _( "Rule applied." ) );
return rcond->constraint; return rcons->constraint;
} }
else else
{ {
@ -558,7 +550,6 @@ DRC_CONSTRAINT DRC_ENGINE::EvalRulesForItems( DRC_CONSTRAINT_TYPE_T aConstraintI
REPORT( "" ); REPORT( "" );
} }
} }
}
// fixme: return optional<drc_constraint>, let the particular test decide what to do if no matching constraint // fixme: return optional<drc_constraint>, let the particular test decide what to do if no matching constraint
// is found // is found

View File

@ -131,14 +131,12 @@ public:
void SetLogReporter( REPORTER* aReporter ) { m_reporter = aReporter; } void SetLogReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
bool LoadRules( wxFileName aPath ); bool LoadRules( const wxFileName& aPath );
void InitEngine( wxFileName aRulePath ); void InitEngine( const wxFileName& aRulePath );
void RunTests(); void RunTests();
void SetErrorLimit( int aLimit );
BOARD_DESIGN_SETTINGS* GetDesignSettings() const { return m_designSettings; } BOARD_DESIGN_SETTINGS* GetDesignSettings() const { return m_designSettings; }
BOARD* GetBoard() const { return m_board; } BOARD* GetBoard() const { return m_board; }
@ -193,7 +191,8 @@ private:
struct CONSTRAINT_WITH_CONDITIONS struct CONSTRAINT_WITH_CONDITIONS
{ {
std::vector<DRC_RULE_CONDITION*> conditions; LSET layerTest;
DRC_RULE_CONDITION* condition;
DRC_RULE* parentRule; DRC_RULE* parentRule;
DRC_CONSTRAINT constraint; DRC_CONSTRAINT constraint;
}; };