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();
102 _(
"Could not find model '%s' to copy for \"A Kind Of\" model '%s'" ),
107 *aType = sourceModel->
GetType();
112 std::string paramName;
113 std::string typeString;
117 for(
const auto& subnode : node->children )
125 typeString = subnode->string();
128 if( type != SIM_MODEL::TYPE::RAWSPICE )
136 paramName = subnode->string();
140 wxASSERT( paramName !=
"" );
142 if( paramName ==
"level" )
143 level = subnode->string();
144 else if( paramName ==
"version" )
145 version = subnode->string();
149 wxFAIL_MSG(
"Unhandled parse tree subnode" );
168 *aType = SIM_MODEL::TYPE::SUBCKT;
173 wxFAIL_MSG(
"Unhandled parse tree node" );
178 wxFAIL_MSG(
"Could not derive type from SPICE code" );
184 const std::string& aSpiceCode )
189 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
190 std::unique_ptr<tao::pegtl::parse_tree::node> root;
200 catch( tao::pegtl::parse_error& e )
205 for(
const auto& node : root->children )
209 std::string
modelName = node->children.at( 0 )->string();
210 std::string akoName = node->children.at( 1 )->string();
217 _(
"Could not find model '%s' to copy for \"A Kind Of\" model '%s'" ),
222 for(
int i = 0; i < static_cast<int>( sourceModel->
GetParamCount() ); ++i )
225 std::string paramName;
227 for(
const auto& subnode : node->children )
239 paramName = subnode->string();
243 wxASSERT( paramName !=
"" );
249 wxFAIL_MSG(
"Unhandled parse tree subnode" );
256 std::string paramName;
258 for(
const auto& subnode : node->children )
270 paramName = subnode->string();
274 wxASSERT( paramName !=
"" );
280 wxFAIL_MSG(
"Unhandled parse tree subnode" );
286 wxFAIL_MSG(
"Unhandled parse tree node" );
295 const std::string& aLevel,
296 const std::string& aVersion,
297 bool aSkipDefaultLevel )
299 wxString input_level = wxString( aLevel ).BeforeFirst(
'.' );
300 wxString input_type( aTypeString );
304 input_type.UpperCase();
306 if( input_type.StartsWith( wxS(
"VDMOS" ) ) )
309 pchan = input_type.Contains( wxS(
"PCHAN" ) );
312 for( SIM_MODEL::TYPE candidate : SIM_MODEL::TYPE_ITERATOR() )
316 if( candidate_type.IsEmpty() )
319 if( candidate_type.StartsWith( wxS(
"VDMOS" ) ) && vdmos )
321 if( vdmos && pchan && candidate_type.EndsWith( wxS(
"PCHAN" ) ) )
323 else if( vdmos && !pchan && candidate_type.EndsWith( wxS(
"NCHAN" ) ) )
326 else if( input_type.StartsWith( candidate_type ) )
334 if( aSkipDefaultLevel )
344 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