2020-05-15 23:25:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-13 16:09:06 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see change_log.txt for contributors.
|
2020-05-15 23:25:33 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-08-08 13:37:14 +00:00
|
|
|
#include <zones.h>
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <drc/drc_rule_parser.h>
|
2020-09-12 23:05:32 +00:00
|
|
|
#include <drc/drc_rule_condition.h>
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <drc_rules_lexer.h>
|
2020-07-21 15:49:55 +00:00
|
|
|
#include <pcb_expr_evaluator.h>
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <reporter.h>
|
2020-05-15 23:25:33 +00:00
|
|
|
|
|
|
|
using namespace DRCRULE_T;
|
|
|
|
|
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
DRC_RULES_PARSER::DRC_RULES_PARSER( const wxString& aSource, const wxString& aSourceDescr ) :
|
2020-06-10 12:41:45 +00:00
|
|
|
DRC_RULES_LEXER( aSource.ToStdString(), aSourceDescr ),
|
2020-06-10 10:57:35 +00:00
|
|
|
m_requiredVersion( 0 ),
|
2020-07-30 11:24:29 +00:00
|
|
|
m_tooRecent( false ),
|
|
|
|
m_reporter( nullptr )
|
2020-06-10 10:57:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
DRC_RULES_PARSER::DRC_RULES_PARSER( FILE* aFile, const wxString& aFilename ) :
|
2020-05-15 23:25:33 +00:00
|
|
|
DRC_RULES_LEXER( aFile, aFilename ),
|
|
|
|
m_requiredVersion( 0 ),
|
2020-07-30 11:24:29 +00:00
|
|
|
m_tooRecent( false ),
|
|
|
|
m_reporter( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC_RULES_PARSER::reportError( const wxString& aMessage )
|
|
|
|
{
|
|
|
|
wxString rest;
|
|
|
|
wxString first = aMessage.BeforeFirst( '|', &rest );
|
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ), CurLineNumber(),
|
|
|
|
CurOffset(), first, rest );
|
2020-09-16 20:38:23 +00:00
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
wxString msg = wxString::Format( _( "ERROR: %s%s" ), first, rest );
|
2020-09-16 20:38:23 +00:00
|
|
|
|
|
|
|
THROW_PARSE_ERROR( msg, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
|
|
|
|
}
|
2020-07-30 11:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
void DRC_RULES_PARSER::reportDeprecation( const wxString& oldToken, const wxString newToken )
|
|
|
|
{
|
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "The '%s' keyword has been deprecated. "
|
|
|
|
"Please use '%s' instead." ),
|
|
|
|
oldToken,
|
|
|
|
newToken);
|
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_WARNING );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
void DRC_RULES_PARSER::parseUnknown()
|
2020-06-10 10:57:35 +00:00
|
|
|
{
|
2020-07-30 11:24:29 +00:00
|
|
|
int depth = 1;
|
|
|
|
|
|
|
|
for( T token = NextTok(); token != T_EOF; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( token == T_LEFT )
|
|
|
|
depth++;
|
|
|
|
|
|
|
|
if( token == T_RIGHT )
|
|
|
|
{
|
|
|
|
if( --depth == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-10 21:05:14 +00:00
|
|
|
void DRC_RULES_PARSER::Parse( std::vector<std::shared_ptr<DRC_RULE>>& aRules, REPORTER* aReporter )
|
2020-05-15 23:25:33 +00:00
|
|
|
{
|
2020-07-30 11:24:29 +00:00
|
|
|
bool haveVersion = false;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
m_reporter = aReporter;
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
for( T token = NextTok(); token != T_EOF; token = NextTok() )
|
2020-05-15 23:25:33 +00:00
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( _( "Missing '('." ) );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
2020-05-17 14:44:44 +00:00
|
|
|
if( !haveVersion && token != T_version )
|
2020-07-30 11:24:29 +00:00
|
|
|
{
|
|
|
|
reportError( _( "Missing version statement." ) );
|
|
|
|
haveVersion = true; // don't keep on reporting it
|
|
|
|
}
|
2020-05-17 14:44:44 +00:00
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
switch( token )
|
|
|
|
{
|
2020-05-17 14:44:44 +00:00
|
|
|
case T_version:
|
|
|
|
haveVersion = true;
|
2020-07-30 11:24:29 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_RIGHT )
|
|
|
|
{
|
|
|
|
reportError( _( "Missing version number." ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (int) token == DSN_NUMBER )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
m_requiredVersion = (int)strtol( CurText(), nullptr, 10 );
|
2020-07-30 11:24:29 +00:00
|
|
|
m_tooRecent = ( m_requiredVersion > DRC_RULE_FILE_VERSION );
|
|
|
|
token = NextTok();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected version number." ),
|
2020-09-16 20:38:23 +00:00
|
|
|
FromUTF8() );
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (int) token != DSN_RIGHT )
|
|
|
|
{
|
2020-09-16 20:38:23 +00:00
|
|
|
msg.Printf( _( "Unrecognized item '%s'." ),
|
|
|
|
FromUTF8() );
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( msg );
|
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
2020-05-17 14:44:44 +00:00
|
|
|
break;
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
case T_rule:
|
2022-01-10 21:05:14 +00:00
|
|
|
aRules.emplace_back( parseDRC_RULE() );
|
2020-05-15 23:25:33 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-14 19:42:21 +00:00
|
|
|
case T_EOF:
|
|
|
|
reportError( _( "Incomplete statement." ) );
|
|
|
|
break;
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
default:
|
2021-07-19 23:56:05 +00:00
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
|
2022-03-13 16:09:06 +00:00
|
|
|
wxT( "rule or version" ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( msg );
|
|
|
|
parseUnknown();
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-30 11:24:29 +00:00
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
if( m_reporter && !m_reporter->HasMessage() )
|
2020-08-06 11:54:15 +00:00
|
|
|
m_reporter->Report( _( "No errors found." ), RPT_SEVERITY_INFO );
|
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
m_reporter = nullptr;
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-10 21:05:14 +00:00
|
|
|
std::shared_ptr<DRC_RULE> DRC_RULES_PARSER::parseDRC_RULE()
|
2020-05-15 23:25:33 +00:00
|
|
|
{
|
2022-01-10 21:05:14 +00:00
|
|
|
std::shared_ptr<DRC_RULE> rule = std::make_shared<DRC_RULE>();
|
|
|
|
|
|
|
|
T token = NextTok();
|
|
|
|
wxString msg;
|
2020-05-25 00:15:08 +00:00
|
|
|
|
|
|
|
if( !IsSymbol( token ) )
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( _( "Missing rule name." ) );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
|
|
|
rule->m_Name = FromUTF8();
|
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
|
2020-05-15 23:25:33 +00:00
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( _( "Missing '('." ) );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
2020-05-23 21:48:24 +00:00
|
|
|
case T_constraint:
|
2022-01-10 21:05:14 +00:00
|
|
|
parseConstraint( rule.get() );
|
2020-05-23 21:48:24 +00:00
|
|
|
break;
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-05-23 21:48:24 +00:00
|
|
|
case T_condition:
|
2020-07-30 11:24:29 +00:00
|
|
|
token = NextTok();
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
if( (int) token == DSN_RIGHT )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( _( "Missing condition expression." ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( IsSymbol( token ) )
|
|
|
|
{
|
2020-09-11 23:25:10 +00:00
|
|
|
rule->m_Condition = new DRC_RULE_CONDITION( FromUTF8() );
|
2020-09-11 15:04:11 +00:00
|
|
|
rule->m_Condition->Compile( m_reporter, CurLineNumber(), CurOffset() );
|
2020-07-30 11:24:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected quoted expression." ),
|
|
|
|
FromUTF8() );
|
|
|
|
reportError( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
parseUnknown();
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
break;
|
|
|
|
|
2020-07-29 11:26:27 +00:00
|
|
|
case T_layer:
|
2020-09-10 19:58:05 +00:00
|
|
|
rule->m_LayerSource = FromUTF8();
|
2020-07-29 11:26:27 +00:00
|
|
|
rule->m_LayerCondition = parseLayer();
|
|
|
|
break;
|
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
case T_severity:
|
|
|
|
rule->m_Severity = parseSeverity();
|
|
|
|
break;
|
|
|
|
|
2020-08-14 19:42:21 +00:00
|
|
|
case T_EOF:
|
|
|
|
reportError( _( "Incomplete statement." ) );
|
|
|
|
return rule;
|
|
|
|
|
2020-05-23 21:48:24 +00:00
|
|
|
default:
|
2021-07-19 23:56:05 +00:00
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
|
2022-03-13 16:09:06 +00:00
|
|
|
wxT( "constraint, condition, or disallow" ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( msg );
|
|
|
|
parseUnknown();
|
2020-05-23 21:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-14 19:42:21 +00:00
|
|
|
if( (int) CurTok() != DSN_RIGHT )
|
|
|
|
reportError( _( "Missing ')'." ) );
|
|
|
|
|
2020-05-23 21:48:24 +00:00
|
|
|
return rule;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule )
|
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
DRC_CONSTRAINT c;
|
|
|
|
int value;
|
|
|
|
wxString msg;
|
2020-07-30 11:24:29 +00:00
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
T token = NextTok();
|
2020-07-30 11:24:29 +00:00
|
|
|
|
2022-05-06 13:46:24 +00:00
|
|
|
if( token == T_mechanical_clearance )
|
|
|
|
{
|
|
|
|
reportDeprecation( wxT( "mechanical_clearance" ), wxT( "physical_clearance" ) );
|
|
|
|
token = T_physical_clearance;
|
|
|
|
}
|
|
|
|
else if( token == T_mechanical_hole_clearance )
|
|
|
|
{
|
|
|
|
reportDeprecation( wxT( "mechanical_hole_clearance" ), wxT( "physical_hole_clearance" ) );
|
|
|
|
token = T_physical_hole_clearance;
|
|
|
|
}
|
|
|
|
else if( token == T_hole )
|
|
|
|
{
|
|
|
|
reportDeprecation( wxT( "hole" ), wxT( "hole_size" ) );
|
|
|
|
token = T_hole_size;
|
|
|
|
}
|
|
|
|
else if( (int) token == DSN_RIGHT || token == T_EOF )
|
2020-07-30 11:24:29 +00:00
|
|
|
{
|
2020-08-09 18:38:25 +00:00
|
|
|
msg.Printf( _( "Missing constraint type.| Expected %s." ),
|
2022-03-13 16:09:06 +00:00
|
|
|
wxT( "assertion, clearance, hole_clearance, edge_clearance, "
|
2022-05-06 13:46:24 +00:00
|
|
|
"physical_clearance, physical_hole_clearance, courtyard_clearance, "
|
2022-03-13 16:09:06 +00:00
|
|
|
"silk_clearance, hole_size, hole_to_hole, track_width, annular_width, "
|
|
|
|
"via_diameter, disallow, zone_connection, thermal_relief_gap, "
|
|
|
|
"thermal_spoke_width, min_resolved_spokes, length, skew, via_count, "
|
|
|
|
"diff_pair_gap or diff_pair_uncoupled" ) );
|
2020-08-09 18:38:25 +00:00
|
|
|
reportError( msg );
|
2020-07-30 11:24:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-23 21:48:24 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
switch( token )
|
2020-05-23 21:48:24 +00:00
|
|
|
{
|
2021-09-22 21:20:18 +00:00
|
|
|
case T_assertion: c.m_Type = ASSERTION_CONSTRAINT; break;
|
2021-08-16 09:53:27 +00:00
|
|
|
case T_clearance: c.m_Type = CLEARANCE_CONSTRAINT; break;
|
|
|
|
case T_hole_clearance: c.m_Type = HOLE_CLEARANCE_CONSTRAINT; break;
|
|
|
|
case T_edge_clearance: c.m_Type = EDGE_CLEARANCE_CONSTRAINT; break;
|
|
|
|
case T_hole_size: c.m_Type = HOLE_SIZE_CONSTRAINT; break;
|
|
|
|
case T_hole_to_hole: c.m_Type = HOLE_TO_HOLE_CONSTRAINT; break;
|
|
|
|
case T_courtyard_clearance: c.m_Type = COURTYARD_CLEARANCE_CONSTRAINT; break;
|
|
|
|
case T_silk_clearance: c.m_Type = SILK_CLEARANCE_CONSTRAINT; break;
|
2021-07-11 15:12:28 +00:00
|
|
|
case T_text_height: c.m_Type = TEXT_HEIGHT_CONSTRAINT; break;
|
|
|
|
case T_text_thickness: c.m_Type = TEXT_THICKNESS_CONSTRAINT; break;
|
2021-08-16 09:53:27 +00:00
|
|
|
case T_track_width: c.m_Type = TRACK_WIDTH_CONSTRAINT; break;
|
2022-07-31 15:02:04 +00:00
|
|
|
case T_connection_width: c.m_Type = CONNECTION_WIDTH_CONSTRAINT; break;
|
2021-08-16 09:53:27 +00:00
|
|
|
case T_annular_width: c.m_Type = ANNULAR_WIDTH_CONSTRAINT; break;
|
2021-08-26 23:43:11 +00:00
|
|
|
case T_via_diameter: c.m_Type = VIA_DIAMETER_CONSTRAINT; break;
|
2021-08-08 13:37:14 +00:00
|
|
|
case T_zone_connection: c.m_Type = ZONE_CONNECTION_CONSTRAINT; break;
|
|
|
|
case T_thermal_relief_gap: c.m_Type = THERMAL_RELIEF_GAP_CONSTRAINT; break;
|
|
|
|
case T_thermal_spoke_width: c.m_Type = THERMAL_SPOKE_WIDTH_CONSTRAINT; break;
|
2021-08-09 10:10:09 +00:00
|
|
|
case T_min_resolved_spokes: c.m_Type = MIN_RESOLVED_SPOKES_CONSTRAINT; break;
|
2021-08-16 09:53:27 +00:00
|
|
|
case T_disallow: c.m_Type = DISALLOW_CONSTRAINT; break;
|
|
|
|
case T_length: c.m_Type = LENGTH_CONSTRAINT; break;
|
|
|
|
case T_skew: c.m_Type = SKEW_CONSTRAINT; break;
|
|
|
|
case T_via_count: c.m_Type = VIA_COUNT_CONSTRAINT; break;
|
|
|
|
case T_diff_pair_gap: c.m_Type = DIFF_PAIR_GAP_CONSTRAINT; break;
|
|
|
|
case T_diff_pair_uncoupled: c.m_Type = DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT; break;
|
2022-05-06 13:46:24 +00:00
|
|
|
case T_physical_clearance: c.m_Type = PHYSICAL_CLEARANCE_CONSTRAINT; break;
|
|
|
|
case T_physical_hole_clearance: c.m_Type = PHYSICAL_HOLE_CLEARANCE_CONSTRAINT; break;
|
2020-07-30 11:24:29 +00:00
|
|
|
default:
|
2021-07-19 23:56:05 +00:00
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
|
2022-03-13 16:09:06 +00:00
|
|
|
wxT( "assertion, clearance, hole_clearance, edge_clearance, "
|
2022-05-06 13:46:24 +00:00
|
|
|
"physical_clearance, physical_hole_clearance, courtyard_clearance, "
|
2022-03-13 16:09:06 +00:00
|
|
|
"silk_clearance, hole_size, hole_to_hole, track_width, annular_width, "
|
|
|
|
"disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
|
|
|
|
"min_resolved_spokes, length, skew, via_count, via_diameter, "
|
|
|
|
"diff_pair_gap or diff_pair_uncoupled" ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( msg );
|
2020-05-23 21:48:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
if( aRule->FindConstraint( c.m_Type ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Rule already has a '%s' constraint." ), FromUTF8() );
|
|
|
|
reportError( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( c.m_Type == DISALLOW_CONSTRAINT )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
|
|
|
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
|
|
|
|
{
|
|
|
|
if( (int) token == DSN_STRING )
|
|
|
|
token = GetCurStrAsToken();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
case T_track: c.m_DisallowFlags |= DRC_DISALLOW_TRACKS; break;
|
|
|
|
case T_via: c.m_DisallowFlags |= DRC_DISALLOW_VIAS; break;
|
|
|
|
case T_micro_via: c.m_DisallowFlags |= DRC_DISALLOW_MICRO_VIAS; break;
|
|
|
|
case T_buried_via: c.m_DisallowFlags |= DRC_DISALLOW_BB_VIAS; break;
|
|
|
|
case T_pad: c.m_DisallowFlags |= DRC_DISALLOW_PADS; break;
|
|
|
|
case T_zone: c.m_DisallowFlags |= DRC_DISALLOW_ZONES; break;
|
|
|
|
case T_text: c.m_DisallowFlags |= DRC_DISALLOW_TEXTS; break;
|
|
|
|
case T_graphic: c.m_DisallowFlags |= DRC_DISALLOW_GRAPHICS; break;
|
|
|
|
case T_hole: c.m_DisallowFlags |= DRC_DISALLOW_HOLES; break;
|
|
|
|
case T_footprint: c.m_DisallowFlags |= DRC_DISALLOW_FOOTPRINTS; break;
|
2020-08-14 19:42:21 +00:00
|
|
|
|
|
|
|
case T_EOF:
|
|
|
|
reportError( _( "Missing ')'." ) );
|
|
|
|
return;
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
default:
|
2021-07-19 23:56:05 +00:00
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
|
2022-03-13 16:09:06 +00:00
|
|
|
wxT( "track, via, micro_via, buried_via, pad, zone, text, graphic, "
|
|
|
|
"hole, or footprint." ) );
|
2020-08-07 20:18:33 +00:00
|
|
|
reportError( msg );
|
2020-08-14 19:42:21 +00:00
|
|
|
break;
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-14 19:42:21 +00:00
|
|
|
if( (int) CurTok() != DSN_RIGHT )
|
|
|
|
reportError( _( "Missing ')'." ) );
|
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
aRule->AddConstraint( c );
|
2020-08-07 20:18:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-08-08 13:37:14 +00:00
|
|
|
else if( c.m_Type == ZONE_CONNECTION_CONSTRAINT )
|
|
|
|
{
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_STRING )
|
|
|
|
token = GetCurStrAsToken();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_solid: c.m_ZoneConnection = ZONE_CONNECTION::FULL; break;
|
|
|
|
case T_thermal_reliefs: c.m_ZoneConnection = ZONE_CONNECTION::THERMAL; break;
|
|
|
|
case T_none: c.m_ZoneConnection = ZONE_CONNECTION::NONE; break;
|
|
|
|
|
|
|
|
case T_EOF:
|
|
|
|
reportError( _( "Missing ')'." ) );
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
|
2021-08-13 19:10:30 +00:00
|
|
|
"solid, thermal_reliefs or none." );
|
2021-08-08 13:37:14 +00:00
|
|
|
reportError( msg );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
reportError( _( "Missing ')'." ) );
|
|
|
|
|
|
|
|
aRule->AddConstraint( c );
|
|
|
|
return;
|
|
|
|
}
|
2021-08-09 10:10:09 +00:00
|
|
|
else if( c.m_Type == MIN_RESOLVED_SPOKES_CONSTRAINT )
|
|
|
|
{
|
|
|
|
// We don't use a min/max/opt structure here for two reasons:
|
|
|
|
//
|
|
|
|
// 1) The min/max/opt parser can't handle unitless numbers, and if we make it handle
|
|
|
|
// them then it will no longer catch the more common case of forgetting to add a unit
|
|
|
|
// and getting an ineffective rule because the distances are in nanometers.
|
|
|
|
//
|
|
|
|
// 2) Min/max/opt gives a strong implication that you could specify the optimal number
|
|
|
|
// of spokes. We don't want to open that door because the spoke generator is highly
|
|
|
|
// optimized around being able to "cheat" off of a cartesian coordinate system.
|
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_NUMBER )
|
|
|
|
{
|
|
|
|
value = (int) strtol( CurText(), nullptr, 10 );
|
|
|
|
c.m_Value.SetMin( value );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reportError( _( "Expecting number." ) );
|
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
reportError( _( "Missing ')'." ) );
|
|
|
|
|
|
|
|
aRule->AddConstraint( c );
|
|
|
|
return;
|
|
|
|
}
|
2021-09-22 21:20:18 +00:00
|
|
|
else if( c.m_Type == ASSERTION_CONSTRAINT )
|
|
|
|
{
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_RIGHT )
|
|
|
|
reportError( _( "Missing assertion expression." ) );
|
|
|
|
|
|
|
|
if( IsSymbol( token ) )
|
|
|
|
{
|
|
|
|
c.m_Test = new DRC_RULE_CONDITION( FromUTF8() );
|
|
|
|
c.m_Test->Compile( m_reporter, CurLineNumber(), CurOffset() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected quoted expression." ), FromUTF8() );
|
|
|
|
reportError( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
{
|
|
|
|
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
aRule->AddConstraint( c );
|
|
|
|
return;
|
|
|
|
}
|
2020-05-25 17:46:06 +00:00
|
|
|
|
2020-09-11 15:04:11 +00:00
|
|
|
for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
|
2020-05-23 21:48:24 +00:00
|
|
|
{
|
|
|
|
if( token != T_LEFT )
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( _( "Missing '('." ) );
|
2020-05-23 21:48:24 +00:00
|
|
|
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_min:
|
2020-07-30 11:24:29 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_RIGHT )
|
|
|
|
{
|
|
|
|
reportError( _( "Missing min value." ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-21 15:49:55 +00:00
|
|
|
parseValueWithUnits( FromUTF8(), value );
|
2021-08-16 09:53:27 +00:00
|
|
|
c.m_Value.SetMin( value );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
break;
|
|
|
|
|
2020-05-23 21:48:24 +00:00
|
|
|
case T_max:
|
2020-07-30 11:24:29 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_RIGHT )
|
|
|
|
{
|
|
|
|
reportError( _( "Missing max value." ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-21 15:49:55 +00:00
|
|
|
parseValueWithUnits( FromUTF8(), value );
|
2021-08-16 09:53:27 +00:00
|
|
|
c.m_Value.SetMax( value );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
break;
|
|
|
|
|
2020-05-23 21:48:24 +00:00
|
|
|
case T_opt:
|
2020-07-30 11:24:29 +00:00
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_RIGHT )
|
|
|
|
{
|
|
|
|
reportError( _( "Missing opt value." ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-21 15:49:55 +00:00
|
|
|
parseValueWithUnits( FromUTF8(), value );
|
2021-08-16 09:53:27 +00:00
|
|
|
c.m_Value.SetOpt( value );
|
2020-05-15 23:25:33 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-14 19:42:21 +00:00
|
|
|
case T_EOF:
|
|
|
|
reportError( _( "Incomplete statement." ) );
|
|
|
|
return;
|
|
|
|
|
2020-05-15 23:25:33 +00:00
|
|
|
default:
|
2020-08-09 18:38:25 +00:00
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ),
|
2020-09-16 20:38:23 +00:00
|
|
|
FromUTF8(),
|
2022-03-13 16:09:06 +00:00
|
|
|
wxT( "min, max, or opt" ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
reportError( msg );
|
|
|
|
parseUnknown();
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-14 19:42:21 +00:00
|
|
|
|
|
|
|
if( (int) CurTok() != DSN_RIGHT )
|
|
|
|
reportError( _( "Missing ')'." ) );
|
2020-09-11 15:04:11 +00:00
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
aRule->AddConstraint( c );
|
2020-05-15 23:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-21 15:49:55 +00:00
|
|
|
void DRC_RULES_PARSER::parseValueWithUnits( const wxString& aExpr, int& aResult )
|
2020-05-15 23:25:33 +00:00
|
|
|
{
|
2020-08-13 17:47:41 +00:00
|
|
|
auto errorHandler = [&]( const wxString& aMessage, int aOffset )
|
|
|
|
{
|
|
|
|
wxString rest;
|
|
|
|
wxString first = aMessage.BeforeFirst( '|', &rest );
|
|
|
|
|
2020-09-16 20:38:23 +00:00
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "ERROR: <a href='%d:%d'>%s</a>%s" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
CurLineNumber(), CurOffset() + aOffset, first, rest );
|
2020-09-16 20:38:23 +00:00
|
|
|
|
|
|
|
m_reporter->Report( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
wxString msg = wxString::Format( _( "ERROR: %s%s" ), first, rest );
|
2020-09-16 20:38:23 +00:00
|
|
|
|
2020-10-15 15:58:35 +00:00
|
|
|
THROW_PARSE_ERROR( msg, CurSource(), CurLine(), CurLineNumber(),
|
|
|
|
CurOffset() + aOffset );
|
2020-09-16 20:38:23 +00:00
|
|
|
}
|
2020-08-13 17:47:41 +00:00
|
|
|
};
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
PCB_EXPR_EVALUATOR evaluator;
|
2020-08-13 17:47:41 +00:00
|
|
|
evaluator.SetErrorCallback( errorHandler );
|
2020-09-11 15:04:11 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
evaluator.Evaluate( aExpr );
|
2020-07-21 15:49:55 +00:00
|
|
|
aResult = evaluator.Result();
|
2020-07-29 11:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET DRC_RULES_PARSER::parseLayer()
|
|
|
|
{
|
|
|
|
LSET retVal;
|
2020-07-30 11:24:29 +00:00
|
|
|
int token = NextTok();
|
2020-07-29 11:26:27 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
if( (int) token == DSN_RIGHT )
|
|
|
|
{
|
|
|
|
reportError( _( "Missing layer name or type." ) );
|
|
|
|
return LSET::AllCuMask();
|
|
|
|
}
|
|
|
|
else if( token == T_outer )
|
2020-07-29 11:26:27 +00:00
|
|
|
{
|
|
|
|
retVal = LSET::ExternalCuMask();
|
|
|
|
}
|
2020-07-30 11:24:29 +00:00
|
|
|
else if( token == T_inner )
|
2020-07-29 11:26:27 +00:00
|
|
|
{
|
|
|
|
retVal = LSET::InternalCuMask();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString layerName = FromUTF8();
|
2020-09-05 16:00:29 +00:00
|
|
|
wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
|
2020-07-29 11:26:27 +00:00
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
wxPGChoiceEntry& entry = layerMap[ii];
|
2020-07-29 11:26:27 +00:00
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
if( entry.GetText().Matches( layerName ) )
|
|
|
|
retVal.set( ToLAYER_ID( entry.GetValue() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !retVal.any() )
|
2020-09-16 20:38:23 +00:00
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
reportError( wxString::Format( _( "Unrecognized layer '%s'." ), layerName ) );
|
2021-02-04 00:55:37 +00:00
|
|
|
retVal.set( Rescue );
|
2020-09-16 20:38:23 +00:00
|
|
|
}
|
2020-07-29 11:26:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
2020-07-30 11:24:29 +00:00
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
2020-07-29 11:26:27 +00:00
|
|
|
return retVal;
|
|
|
|
}
|
2021-09-05 15:06:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
SEVERITY DRC_RULES_PARSER::parseSeverity()
|
|
|
|
{
|
|
|
|
SEVERITY retVal = RPT_SEVERITY_UNDEFINED;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
T token = NextTok();
|
|
|
|
|
|
|
|
if( (int) token == DSN_RIGHT || token == T_EOF )
|
|
|
|
{
|
|
|
|
reportError( _( "Missing severity name." ) );
|
|
|
|
return RPT_SEVERITY_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_ignore: retVal = RPT_SEVERITY_IGNORE; break;
|
|
|
|
case T_warning: retVal = RPT_SEVERITY_WARNING; break;
|
|
|
|
case T_error: retVal = RPT_SEVERITY_ERROR; break;
|
|
|
|
case T_exclusion: retVal = RPT_SEVERITY_EXCLUSION; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg.Printf( _( "Unrecognized item '%s'.| Expected %s." ),
|
|
|
|
FromUTF8(),
|
2022-03-13 16:09:06 +00:00
|
|
|
wxT( "ignore, warning, error, or exclusion" ) );
|
2021-09-05 15:06:12 +00:00
|
|
|
reportError( msg );
|
|
|
|
parseUnknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (int) NextTok() != DSN_RIGHT )
|
|
|
|
reportError( _( "Missing ')'." ) );
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|