31#include <boost/algorithm/string/case_conv.hpp>
32#include <boost/algorithm/string/predicate.hpp>
34#include <pegtl/contrib/parse_tree.hpp>
63 SIM_MODEL::TYPE* aType,
bool aFirstPass )
65 *aType = SIM_MODEL::TYPE::NONE;
67 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
68 std::unique_ptr<tao::pegtl::parse_tree::node> root;
78 catch(
const tao::pegtl::parse_error& e )
84 for(
const auto& node : root->children )
93 std::string
modelName = node->children.at( 0 )->string();
94 std::string akoName = node->children.at( 1 )->string();
100 _(
"Could not find model '%s' to copy for \"A Kind Of\" model '%s'" ),
105 *aType = sourceModel->
GetType();
110 std::string paramName;
111 std::string typeString;
115 for(
const auto& subnode : node->children )
123 typeString = subnode->string();
126 if( type != SIM_MODEL::TYPE::RAWSPICE )
134 paramName = subnode->string();
138 wxASSERT( paramName !=
"" );
140 if( paramName ==
"level" )
141 level = subnode->string();
142 else if( paramName ==
"version" )
143 version = subnode->string();
147 wxFAIL_MSG(
"Unhandled parse tree subnode" );
166 *aType = SIM_MODEL::TYPE::SUBCKT;
171 wxFAIL_MSG(
"Unhandled parse tree node" );
176 wxFAIL_MSG(
"Could not derive type from SPICE code" );
182 const std::string& aSpiceCode )
187 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
188 std::unique_ptr<tao::pegtl::parse_tree::node> root;
198 catch( tao::pegtl::parse_error& e )
203 for(
const auto& node : root->children )
207 std::string
modelName = node->children.at( 0 )->string();
208 std::string akoName = node->children.at( 1 )->string();
215 _(
"Could not find model '%s' to copy 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