Commit 5634bc33 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

move PCB_PARSER into PCB_IO as a member

parent 484eb55a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -204,12 +204,14 @@ public:
     *
     * @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount.  This
     *  token table need not contain the lexer separators such as '(' ')', etc.
     *
     * @param aKeywordCount is the count of tokens in aKeywordTable.
     *
     * @param aLineReader is any subclassed instance of LINE_READER, such as
     *  STRING_LINE_READER or FILE_LINE_READER.
     *  STRING_LINE_READER or FILE_LINE_READER.  No ownership is taken.
     */
    DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
              LINE_READER* aLineReader );
              LINE_READER* aLineReader = NULL );

    virtual ~DSNLEXER();

+14 −8
Original line number Diff line number Diff line
@@ -241,11 +241,12 @@ void FP_CACHE::Load()

        // reader now owns fp, will close on exception or return
        FILE_LINE_READER    reader( fp, fpFileName );
        PCB_PARSER          parser( &reader );

        m_owner->m_parser->SetLineReader( &reader );

        std::string name = TO_UTF8( fpFileName );

        m_modules.insert( name, new FP_CACHE_ITEM( (MODULE*) parser.Parse(), fpFileName ) );
        m_modules.insert( name, new FP_CACHE_ITEM( (MODULE*) m_owner->m_parser->Parse(), fpFileName ) );

    } while( dir.GetNext( &fpFileName ) );

@@ -339,9 +340,9 @@ BOARD_ITEM* PCB_IO::Parse( const wxString& aClipboardSourceInput ) throw( IO_ERR

    STRING_LINE_READER  reader( input, wxT( "clipboard" ) );

    PCB_PARSER  parser( &reader );
    m_parser->SetLineReader( &reader );

    return parser.Parse();
    return m_parser->Parse();
}


@@ -1466,7 +1467,8 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const

PCB_IO::PCB_IO() :
    m_cache( 0 ),
    m_ctl( 0 )
    m_ctl( 0 ),
    m_parser( new PCB_PARSER() )
{
    init( 0 );
    m_out = &m_sf;
@@ -1475,7 +1477,8 @@ PCB_IO::PCB_IO() :

PCB_IO::PCB_IO( int aControlFlags ) :
    m_cache( 0 ),
    m_ctl( aControlFlags )
    m_ctl( aControlFlags ),
    m_parser( new PCB_PARSER() )
{
    init( 0 );
    m_out = &m_sf;
@@ -1485,6 +1488,7 @@ PCB_IO::PCB_IO( int aControlFlags ) :
PCB_IO::~PCB_IO()
{
    delete m_cache;
    delete m_parser;
}


@@ -1499,9 +1503,11 @@ BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES*
    }

    FILE_LINE_READER    reader( file.fp(), aFileName );
    PCB_PARSER          parser( &reader, aAppendToMe );

    BOARD* board = dynamic_cast<BOARD*>( parser.Parse() );
    m_parser->SetLineReader( &reader );
    m_parser->SetBoard( aAppendToMe );

    BOARD* board = dynamic_cast<BOARD*>( m_parser->Parse() );
    wxASSERT( board );

    // Give the filename to the board if it's new
+4 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
class BOARD;
class BOARD_ITEM;
class FP_CACHE;
class PCB_PARSER;


/** Current s-expression file format version.  2 was the last legacy format version. */
@@ -47,6 +48,8 @@ class FP_CACHE;
 */
class PCB_IO : public PLUGIN
{
    friend class FP_CACHE;


public:

@@ -133,6 +136,7 @@ protected:
    STRING_FORMATTER    m_sf;
    OUTPUTFORMATTER*    m_out;      ///< output any Format()s to this, no ownership
    int                 m_ctl;
    PCB_PARSER*         m_parser;


private:
+9 −0
Original line number Diff line number Diff line
@@ -51,6 +51,15 @@

using namespace std;


void PCB_PARSER::init()
{
    m_layerMap.clear();

    // @todo add default layernames here.
}


double PCB_PARSER::parseDouble() throw( IO_ERROR )
{
    char* tmp;
+33 −2
Original line number Diff line number Diff line
@@ -66,6 +66,15 @@ class PCB_PARSER : public PCB_LEXER
    BOARD*          m_board;
    LAYER_HASH_MAP  m_layerMap;  //< Map layer name to it's index saved in BOARD::m_Layer.


    /**
     * Function init
     * clears and re-establishes m_layerMap with the default layer names.
     * m_layerMap will have some of its entries overwritten whenever a (new) board
     * is encountered.
     */
    void init();

    void parseHeader() throw( IO_ERROR, PARSE_ERROR );
    void parseGeneralSection() throw( IO_ERROR, PARSE_ERROR );
    void parsePAGE_INFO() throw( IO_ERROR, PARSE_ERROR );
@@ -204,11 +213,33 @@ class PCB_PARSER : public PCB_LEXER

    bool parseBool() throw( PARSE_ERROR );


public:
    PCB_PARSER( LINE_READER* aReader, BOARD* aBoard = NULL ) :

    PCB_PARSER( LINE_READER* aReader = NULL ) :
        PCB_LEXER( aReader ),
        m_board( aBoard )
        m_board( 0 )
    {
    }


    /**
     * Functoin SetLineReader
     * sets @a aLineReader into the parser, and returns the previous one, if any.
     * @param aReader is what to read from for tokens, no ownership is received.
     * @return LINE_READER* - previous LINE_READER or NULL if none.
     */
    LINE_READER* SetLineReader( LINE_READER* aReader )
    {
        LINE_READER* ret = PopReader();
        PushReader( aReader );
        return ret;
    }

    void SetBoard( BOARD* aBoard )
    {
        init();
        m_board = aBoard;
    }

    BOARD_ITEM* Parse() throw( IO_ERROR, PARSE_ERROR );