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_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.
 
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)
 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.
 

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 456 of file drc_rules_downgrade.h.

Referenced by FilterDrcRulesForTarget().

◆ DrcRuleUnsupportedByTarget()

◆ 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 61 of file drc_rules_downgrade.h.

Referenced by DrcRuleUnsupportedByTarget().

◆ FilterDrcRulesForTarget()

◆ 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 41 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 135 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 97 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_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 54 of file drc_rules_downgrade.h.

Referenced by BOOST_AUTO_TEST_CASE(), and DrcRuleUnsupportedByTarget().