Sim: Don't crash when parsing unknown model in a Spice file
This commit is contained in:
parent
f2fb734e06
commit
bbcb0c04fc
|
@ -22,8 +22,6 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <confirm.h>
|
||||
|
||||
// Include simulator headers after wxWidgets headers to avoid conflicts with Windows headers
|
||||
// (especially on msys2 + wxWidgets 3.0.x)
|
||||
#include <sim/sim_model_spice.h>
|
||||
|
@ -59,18 +57,13 @@ std::string SPICE_GENERATOR_SPICE::Preview( const SPICE_ITEM& aItem ) const
|
|||
std::unique_ptr<SIM_MODEL_SPICE> SIM_MODEL_SPICE::Create( const SIM_LIBRARY_SPICE& aLibrary,
|
||||
const std::string& aSpiceCode )
|
||||
{
|
||||
auto model = static_cast<SIM_MODEL_SPICE*>(
|
||||
auto model = dynamic_cast<SIM_MODEL_SPICE*>(
|
||||
SIM_MODEL::Create( SPICE_MODEL_PARSER::ReadType( aLibrary, aSpiceCode ) ).release() );
|
||||
|
||||
try
|
||||
{
|
||||
model->m_spiceModelParser->ReadModel( aLibrary, aSpiceCode );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
DisplayErrorMessage( nullptr, e.What() );
|
||||
}
|
||||
if( !model )
|
||||
THROW_IO_ERROR( "Could not determine Spice model type" );
|
||||
|
||||
model->m_spiceModelParser->ReadModel( aLibrary, aSpiceCode );
|
||||
return std::unique_ptr<SIM_MODEL_SPICE>( model );
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <sim/spice_grammar.h>
|
||||
#include <sim/sim_model_spice.h>
|
||||
#include <ki_exception.h>
|
||||
#include <confirm.h>
|
||||
|
||||
#include <pegtl.hpp>
|
||||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
@ -67,7 +68,15 @@ void SPICE_LIBRARY_PARSER::ReadFile( const std::string& aFilePath )
|
|||
{
|
||||
if( node->is_type<SIM_LIBRARY_SPICE_PARSER::modelUnit>() )
|
||||
{
|
||||
m_library.m_models.push_back( SIM_MODEL_SPICE::Create( m_library, node->string() ) );
|
||||
try
|
||||
{
|
||||
m_library.m_models.push_back( SIM_MODEL_SPICE::Create( m_library, node->string() ) );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
DisplayErrorMessage( nullptr, e.What() );
|
||||
}
|
||||
|
||||
m_library.m_modelNames.emplace_back( node->children.at( 0 )->string() );
|
||||
}
|
||||
else if( node->is_type<SIM_LIBRARY_SPICE_PARSER::unknownLine>() )
|
||||
|
|
Loading…
Reference in New Issue