31#include <boost/algorithm/string/case_conv.hpp>
32#include <boost/algorithm/string/predicate.hpp>
34#include <pegtl/contrib/parse_tree.hpp>
63 const std::string& aSpiceCode )
65 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
66 std::unique_ptr<tao::pegtl::parse_tree::node> root;
76 catch(
const tao::pegtl::parse_error& e )
79 return SIM_MODEL::TYPE::NONE;
82 for(
const auto& node : root->children )
86 std::string
modelName = node->children.at( 0 )->string();
87 std::string akoName = node->children.at( 1 )->string();
93 _(
"Could not find model '%s' to copy for \"A Kind Of\" model '%s'" ),
102 std::string paramName;
103 std::string typeString;
107 for(
const auto& subnode : node->children )
115 typeString = subnode->string();
118 if( type != SIM_MODEL::TYPE::RAWSPICE )
123 paramName = subnode->string();
127 wxASSERT( paramName !=
"" );
129 if( paramName ==
"level" )
130 level = subnode->string();
131 else if( paramName ==
"version" )
132 version = subnode->string();
136 wxFAIL_MSG(
"Unhandled parse tree subnode" );
137 return SIM_MODEL::TYPE::NONE;
149 return SIM_MODEL::TYPE::SUBCKT;
153 wxFAIL_MSG(
"Unhandled parse tree node" );
154 return SIM_MODEL::TYPE::NONE;
158 wxFAIL_MSG(
"Could not derive type from SPICE code" );
159 return SIM_MODEL::TYPE::NONE;
164 const std::string& aSpiceCode )
169 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
170 std::unique_ptr<tao::pegtl::parse_tree::node> root;
180 catch( tao::pegtl::parse_error& e )
185 for(
const auto& node : root->children )
189 std::string
modelName = node->children.at( 0 )->string();
190 std::string akoName = node->children.at( 1 )->string();
197 _(
"Could not find model '%s' to copy for \"A Kind Of\" model '%s'" ),
202 for(
int i = 0; i < static_cast<int>( sourceModel->
GetParamCount() ); ++i )
205 std::string paramName;
207 for(
const auto& subnode : node->children )
219 paramName = subnode->string();
223 wxASSERT( paramName !=
"" );
229 wxFAIL_MSG(
"Unhandled parse tree subnode" );
236 std::string paramName;
238 for(
const auto& subnode : node->children )
250 paramName = subnode->string();
254 wxASSERT( paramName !=
"" );
260 wxFAIL_MSG(
"Unhandled parse tree subnode" );
266 wxFAIL_MSG(
"Unhandled parse tree node" );
275 const std::string& aLevel,
276 const std::string& aVersion,
277 bool aSkipDefaultLevel )
279 wxString input_level = wxString( aLevel ).BeforeFirst(
'.' );
280 wxString input_type( aTypeString );
284 input_type.UpperCase();
286 if( input_type.StartsWith( wxS(
"VDMOS" ) ) )
289 pchan = input_type.Contains( wxS(
"PCHAN" ) );
292 for( SIM_MODEL::TYPE candidate : SIM_MODEL::TYPE_ITERATOR() )
299 if( candidate_type.IsEmpty() )
302 if( candidate_type.StartsWith( wxS(
"VDMOS" ) ) && vdmos )
304 if( vdmos && pchan && candidate_type.EndsWith( wxS(
"PCHAN" ) ) )
306 else if( vdmos && !pchan && candidate_type.EndsWith( wxS(
"NCHAN" ) ) )
309 else if( input_type.StartsWith( candidate_type ) )
311 if( candidate_version != aVersion )
314 if( candidate_level == input_level )
317 if( aSkipDefaultLevel )
320 if( candidate_isDefaultLevel && aLevel ==
"" )
327 return SIM_MODEL::TYPE::RAWSPICE;
SIM_MODEL * FindModel(const std::string &aModelName) const
virtual void SetParamFromSpiceCode(const std::string &aParamName, const std::string &aParamValue, SIM_VALUE_GRAMMAR::NOTATION aNotation=SIM_VALUE_GRAMMAR::NOTATION::SPICE)
static SPICE_INFO SpiceInfo(TYPE aType)
virtual const PARAM & GetParam(unsigned aParamIndex) const
int GetParamCount() const
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
virtual void ReadModel(const SIM_LIBRARY_SPICE &aLibrary, const std::string &aSpiceCode)
static SIM_MODEL::TYPE ReadTypeFromSpiceStrings(const std::string &aTypeString, const std::string &aLevel="", const std::string &aVersion="", bool aSkipDefaultLevel=true)
SIM_MODEL_SPICE & m_model
static SIM_MODEL::TYPE ReadType(const SIM_LIBRARY_SPICE &aLibrary, const std::string &aSpiceCode)
static const wxChar traceSpiceModelParser[]
Flag to enable SPICE model parser debugging output.
#define THROW_IO_ERROR(msg)
must_if< error >::control< Rule > control