33#include <boost/algorithm/string/case_conv.hpp>
34#include <boost/algorithm/string/predicate.hpp>
36#include <pegtl/contrib/parse_tree.hpp>
65 SIM_MODEL::TYPE* aType,
bool aFirstPass )
67 *aType = SIM_MODEL::TYPE::NONE;
69 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
70 std::unique_ptr<tao::pegtl::parse_tree::node> root;
80 catch(
const tao::pegtl::parse_error& e )
86 for(
const auto& node : root->children )
95 std::string
modelName = node->children.at( 0 )->string();
96 std::string akoName = node->children.at( 1 )->string();
101 THROW_IO_ERROR( wxString::Format(
_(
"Could not find parent model '%s' for \"A Kind Of\" model '%s'" ),
106 *aType = sourceModel->
GetType();
111 std::string paramName;
112 std::string typeString;
116 for(
const auto& subnode : node->children )
124 typeString = subnode->string();
127 if( type != SIM_MODEL::TYPE::RAWSPICE )
135 paramName = subnode->string();
139 wxASSERT( paramName !=
"" );
141 if( paramName ==
"level" )
142 level = subnode->string();
143 else if( paramName ==
"version" )
144 version = subnode->string();
148 wxFAIL_MSG(
"Unhandled parse tree subnode" );
167 *aType = SIM_MODEL::TYPE::SUBCKT;
172 wxFAIL_MSG(
"Unhandled parse tree node" );
177 wxFAIL_MSG(
"Could not derive type from SPICE code" );
183 const std::string& aSpiceCode )
188 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
189 std::unique_ptr<tao::pegtl::parse_tree::node> root;
199 catch( tao::pegtl::parse_error& e )
204 for(
const auto& node : root->children )
208 std::string
modelName = node->children.at( 0 )->string();
209 std::string akoName = node->children.at( 1 )->string();
215 THROW_IO_ERROR( wxString::Format(
_(
"Could not find parent model '%s' for \"A Kind Of\" model '%s'" ),
220 for(
int i = 0; i < static_cast<int>( sourceModel->
GetParamCount() ); ++i )
223 std::string paramName;
225 for(
const auto& subnode : node->children )
237 paramName = subnode->string();
241 wxASSERT( paramName !=
"" );
247 wxFAIL_MSG(
"Unhandled parse tree subnode" );
254 std::string paramName;
256 for(
const auto& subnode : node->children )
268 paramName = subnode->string();
272 wxASSERT( paramName !=
"" );
278 wxFAIL_MSG(
"Unhandled parse tree subnode" );
284 wxFAIL_MSG(
"Unhandled parse tree node" );
293 const std::string& aLevel,
294 const std::string& aVersion,
295 bool aSkipDefaultLevel )
297 wxString input_level = wxString( aLevel ).BeforeFirst(
'.' );
298 wxString input_type( aTypeString );
302 input_type.UpperCase();
304 if( input_type.StartsWith( wxS(
"VDMOS" ) ) )
307 pchan = input_type.Contains( wxS(
"PCHAN" ) );
310 for( SIM_MODEL::TYPE candidate : SIM_MODEL::TYPE_ITERATOR() )
314 if( candidate_type.IsEmpty() )
317 if( candidate_type.StartsWith( wxS(
"VDMOS" ) ) && vdmos )
319 if( vdmos && pchan && candidate_type.EndsWith( wxS(
"PCHAN" ) ) )
321 else if( vdmos && !pchan && candidate_type.EndsWith( wxS(
"NCHAN" ) ) )
324 else if( input_type.StartsWith( candidate_type ) )
332 if( aSkipDefaultLevel )
342 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 bool ReadType(const SIM_LIBRARY_SPICE &aLibrary, const std::string &aSpiceCode, SIM_MODEL::TYPE *aType, bool aFirstPass)
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 const wxChar traceSpiceModelParser[]
Flag to enable SPICE model parser debugging output.
#define THROW_IO_ERROR(msg)
must_if< error >::control< Rule > control