KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_rules_downgrade.h File Reference
#include <algorithm>
#include <cctype>
#include <string>
#include <vector>
#include <wx/intl.h>
#include <dsnlexer.h>
#include <ki_exception.h>
#include <downgrade_target.h>
#include <drc_rules_release_vocabulary.h>

Go to the source code of this file.

Classes

struct  DRC_CONSTRAINT_RENAME
 A constraint kind renamed after a release. The release reads the same check by its old name. More...
 
struct  DRC_RULES_FILTER_RESULT
 
struct  DRC_RULE_TOKEN
 
struct  DRC_RULE_BLOCK
 A top-level block of the rules file, as byte span and token range. More...
 

Functions

const DRC_RULE_VOCABULARY * FindDrcRuleVocabulary (const DOWNGRADE_TARGET &aTarget)
 The vocabulary a target release could parse, generated from its release tags by tools/generate_drc_rules_vocabulary.py.
 
bool DrcVocabularyHas (const char *const *aWords, size_t aCount, const std::string &aWord)
 The generated arrays are sorted, so membership is a binary search.
 
std::string DrcConstraintKindForTarget (const std::string &aKind, const DRC_RULE_VOCABULARY &aVocabulary)
 The name the target reads a constraint kind by.
 
bool TokenizeDrcRules (const std::string &aText, std::vector< DRC_RULE_TOKEN > &aTokens, wxString &aError)
 Tokenize with the lexer the rule readers use, so comments, strings and symbols end exactly where they end for the readers.
 
bool SplitDrcRuleBlocks (const std::vector< DRC_RULE_TOKEN > &aTokens, std::vector< DRC_RULE_BLOCK > &aBlocks, wxString &aError)
 Group the tokens into top-level blocks.
 
bool DrcRuleUnsupportedByTarget (const std::vector< DRC_RULE_TOKEN > &aTokens, const DRC_RULE_BLOCK &aBlock, const DRC_RULE_VOCABULARY &aVocabulary, std::vector< size_t > *aRenamed=nullptr)
 True if the rule uses something the target's parser or evaluator cannot handle.
 
std::string CommentOutDrcBlock (const std::string &aBlock)
 Prefix every line, so the target reads the whole block as comments.
 
DRC_RULES_FILTER_RESULT FilterDrcRulesForTarget (const wxString &aRulesText, const DOWNGRADE_TARGET &aTarget)
 Filter a .kicad_dru file for the target.
 

Variables

constexpr const char * DRC_RULE_SEMANTIC_BREAKS []
 A function a release parses but answers differently, which the vocabulary cannot say.
 
constexpr DRC_CONSTRAINT_RENAME DRC_CONSTRAINT_RENAMES []
 

Function Documentation

◆ CommentOutDrcBlock()

std::string CommentOutDrcBlock ( const std::string & aBlock)
inline

Prefix every line, so the target reads the whole block as comments.

Definition at line 495 of file drc_rules_downgrade.h.

Referenced by FilterDrcRulesForTarget().

◆ DrcConstraintKindForTarget()

std::string DrcConstraintKindForTarget ( const std::string & aKind,
const DRC_RULE_VOCABULARY & aVocabulary )
inline

The name the target reads a constraint kind by.

Definition at line 83 of file drc_rules_downgrade.h.

References DRC_CONSTRAINT_RENAMES, DrcVocabularyHas(), DRC_RULE_VOCABULARY::m_tokenCount, and DRC_RULE_VOCABULARY::m_tokens.

Referenced by DrcRuleUnsupportedByTarget(), and FilterDrcRulesForTarget().

◆ DrcRuleUnsupportedByTarget()

bool DrcRuleUnsupportedByTarget ( const std::vector< DRC_RULE_TOKEN > & aTokens,
const DRC_RULE_BLOCK & aBlock,
const DRC_RULE_VOCABULARY & aVocabulary,
std::vector< size_t > * aRenamed = nullptr )
inline

◆ DrcVocabularyHas()

bool DrcVocabularyHas ( const char *const * aWords,
size_t aCount,
const std::string & aWord )
inline

The generated arrays are sorted, so membership is a binary search.

Definition at line 62 of file drc_rules_downgrade.h.

Referenced by DrcConstraintKindForTarget(), and DrcRuleUnsupportedByTarget().

◆ FilterDrcRulesForTarget()

DRC_RULES_FILTER_RESULT FilterDrcRulesForTarget ( const wxString & aRulesText,
const DOWNGRADE_TARGET & aTarget )
inline

◆ FindDrcRuleVocabulary()

const DRC_RULE_VOCABULARY * FindDrcRuleVocabulary ( const DOWNGRADE_TARGET & aTarget)
inline

The vocabulary a target release could parse, generated from its release tags by tools/generate_drc_rules_vocabulary.py.

A release without one cannot be exported to.

Definition at line 42 of file drc_rules_downgrade.h.

References DRC_RULE_VOCABULARIES, and DOWNGRADE_TARGET::m_id.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and FilterDrcRulesForTarget().

◆ SplitDrcRuleBlocks()

bool SplitDrcRuleBlocks ( const std::vector< DRC_RULE_TOKEN > & aTokens,
std::vector< DRC_RULE_BLOCK > & aBlocks,
wxString & aError )
inline

Group the tokens into top-level blocks.

Anything but a comment outside a block is invalid for the readers, and so is a comment that does not start its line.

Definition at line 166 of file drc_rules_downgrade.h.

References _, DSN_COMMENT, DSN_LEFT, DSN_RIGHT, DSN_SYMBOL, DRC_RULE_BLOCK::m_first, DRC_RULE_BLOCK::m_head, DRC_RULE_BLOCK::m_name, DRC_RULE_TOKEN::m_offset, DRC_RULE_BLOCK::m_start, DRC_RULE_TOKEN::m_text, DRC_RULE_TOKEN::m_type, and name.

Referenced by FilterDrcRulesForTarget().

◆ TokenizeDrcRules()

bool TokenizeDrcRules ( const std::string & aText,
std::vector< DRC_RULE_TOKEN > & aTokens,
wxString & aError )
inline

Tokenize with the lexer the rule readers use, so comments, strings and symbols end exactly where they end for the readers.

Comments stay as tokens so every byte of the source is placed.

Definition at line 128 of file drc_rules_downgrade.h.

References DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurText(), DSN_EOF, DSN_STRING, DSNLEXER::NextTok(), IO_ERROR::Problem(), and DSNLEXER::SetCommentsAreTokens().

Referenced by FilterDrcRulesForTarget().

Variable Documentation

◆ DRC_CONSTRAINT_RENAMES

DRC_CONSTRAINT_RENAME DRC_CONSTRAINT_RENAMES[]
inlineconstexpr
Initial value:
= {
{ "line_width", "text_thickness" },
}

Definition at line 76 of file drc_rules_downgrade.h.

Referenced by DrcConstraintKindForTarget().

◆ DRC_RULE_SEMANTIC_BREAKS

const char* DRC_RULE_SEMANTIC_BREAKS[]
inlineconstexpr
Initial value:
= {
"intersectsarea",
}

A function a release parses but answers differently, which the vocabulary cannot say.

Definition at line 55 of file drc_rules_downgrade.h.

Referenced by BOOST_AUTO_TEST_CASE(), and DrcRuleUnsupportedByTarget().