47 using namespace qucs::eqn;
69 if (def != NULL && action == def->
action)
return def;
80 if (!strcmp (pp->
key, key))
114 if (!strcmp (def->type, type) && !strcmp (def->instance, instance))
134 if (!strcmp (def->type, type))
136 for (pair = def->pairs; pair != NULL; pair = pair->
next)
138 if (!strcmp (pair->
key, key))
139 if (pair->
value->
ident != NULL && ident != NULL &&
156 for (pair = def->
pairs; pair != NULL; pair = pair->
next)
158 if (!strcmp (pair->
key, key))
172 for (pair = def->
pairs; pair != NULL; pair = pair->
next)
174 if (!strcmp (pair->
key, key))
217 if (ident != NULL && !strcmp (val->
ident, ident))
226 char *
var,
int type,
bool pass)
228 variable *
v =
new variable (var);
229 eqn::constant *
c =
new eqn::constant (type);
240 env->addVariable (v, pass);
252 if (value->
ident != NULL)
259 if (!strcmp (def->
type,
"SW") && !strcmp (pair->
key,
"Param"))
327 char * txt = (
char *)
328 malloc (strlen (def->
instance) + 1 + strlen (value->
ident) + 1);
330 char * ref = (
char *)
331 malloc (strlen (def->
instance) + 5 + strlen (value->
ident) + 1);
336 value->
ident = strdup (ref);
346 root->
env->
getChecker()->addReference (
"#propref", ref, txt);
359 "used in a `%s:%s' property\n", def->
line, value->
ident,
372 double val = value->
value, factor = 1.0;
374 if (value->
scale != NULL)
376 scale = value->
scale;
454 else if (*scale ==
'u')
480 value->
unit = strdup (scale);
485 value->
value = val * factor;
497 if (def->action == action)
501 else if (!strcmp (def->type, type))
515 if (n != NULL && !strcmp (def->
instance, n))
return def;
542 if (def->nonlinear != 0) count++;
546 if (!strcmp (def->type,
"Sub"))
565 if (def->action == 1 && !strcmp (def->instance, instance))
583 if (def->action == 1 && !strcmp (def->instance, instance))
586 if (deps->contains (instance))
589 "detected, involves: %s\n", instance, deps->toString ());
592 deps->append (instance);
594 if (!strcmp (def->type,
"SW"))
616 if (def->action == 1 && !strcmp (def->type,
"SW"))
626 if (!strcmp (def->instance, val->
ident))
629 "refers to itself\n", def->line, def->type, def->instance);
636 "found as referred in `%s:%s'\n", def->line, val->
ident,
637 def->type, def->instance);
641 strlist * deps =
new strlist ();
672 const char * prop =
"Num";
685 if (p == (
int) val->
value)
688 "with duplicate `%s=%d' property found: `%s:%s' and "
714 if (def->action == 1 && (!strcmp (def->type,
"SW") ||
715 !strcmp (def->type,
"AC") ||
716 !strcmp (def->type,
"SP")))
721 if (type && (!strcmp (type,
"const") || !strcmp (type,
"list")))
726 if (!strcmp (type,
"const"))
736 "`%s' not found in `%s:%s'\n", def->line,
"Values",
737 def->type, def->instance);
743 if (!strcmp (type,
"const"))
746 if (val->
next != NULL)
749 "needs to be a single constant value in `%s:%s', no "
750 "lists possible\n", def->line,
"Values",
751 def->type, def->instance);
756 if (!strcmp (type,
"list"))
761 for (; val != NULL; val = val->
next)
771 "`%s' is invalid in `%s:%s'\n", def->line,
"Start",
772 def->type, def->instance);
779 "`%s' is invalid in `%s:%s'\n", def->line,
"Stop",
780 def->type, def->instance);
787 "`%s' is invalid in `%s:%s'\n", def->line,
"Points",
788 def->type, def->instance);
793 else if (type && (!strcmp (type,
"lin") || !strcmp (type,
"log")))
799 "`%s' not found in `%s:%s'\n", def->line,
"Start",
800 def->type, def->instance);
807 "`%s' not found in `%s:%s'\n", def->line,
"Stop",
808 def->type, def->instance);
815 "`%s' not found in `%s:%s'\n", def->line,
"Points",
816 def->type, def->instance);
823 "`%s' is invalid in `%s:%s'\n", def->line,
"Values",
824 def->type, def->instance);
837 int a,
c,
n, errors = 0;
851 "least 1 required\n", n);
863 "single or none required\n", n);
866 if (a >= 1 && c >= 1 && n < 1)
869 "circuit definition (accounted %d non-linearities)\n", c);
903 "`%s' found as specified in `%s:%s'\n", def->line,
904 val->
ident, def->type, def->instance);
929 if (!def->action && !def->nodeset)
931 for (node = def->nodes; node != NULL; node = node->
next)
932 if (!strcmp (node->
node, n)) count++;
945 if (def->nodeset && !def->duplicate)
948 if (!strcmp (node, n))
950 if (++count > 1) def->duplicate = 1;
971 "as referenced by `%s:%s'\n", def->line, node, def->type,
978 "uniquely defined by `%s:%s'\n", def->line, node, def->type,
996 strlist * eqnvars = env->getChecker()->variables ();
997 strlist * instances =
new strlist ();
998 strlist * vars =
new strlist ();
999 strlist * refs =
new strlist ();
1004 if (def->action == 1 && !strcmp (def->type,
"SW"))
1008 if (para != NULL && ref != NULL)
1011 if (eqnvars && eqnvars->contains (para->
ident))
1014 "already defined by `%s:%s'\n", para->
ident,
1015 def->type, def->instance);
1020 if ((pos = vars->index (para->
ident)) != -1)
1022 if (strcmp (ref->
ident, refs->get (pos)))
1025 "already defined by `%s:%s'\n", para->
ident, def->type,
1026 def->instance, def->type, instances->get (pos));
1032 if ((pos = refs->index (ref->
ident)) != -1)
1034 if (strcmp (para->
ident, vars->get (pos)))
1037 "in `%s:%s' and `%s' in `%s:%s' for `%s'\n",
1038 para->
ident, def->type, def->instance,
1039 vars->get (pos), def->type, instances->get (pos),
1045 instances->add (def->instance);
1046 vars->add (para->
ident);
1047 refs->add (ref->
ident);
1082 "checker error, value of `%s' needs to be "
1083 "a single value in `%s:%s', no lists possible\n",
1084 pp->
key, def->
type, instance);
1094 for (; val != NULL; val = val->
next)
1108 "checker notice, value of `%s' (variable `%s') could be "
1109 "out of range `%c%g,%g%c' in `%s:%s'\n",
1114 for (; val != NULL; val = val->
next)
1128 "checker error, value of `%s' (%g) is out of "
1129 "range `%c%g,%g%c' in `%s:%s'\n",
1143 "checker error, value of `%s' (%g) needs to be "
1144 "an integer in `%s:%s'\n",
1157 "checker error, value of `%s' (%g) needs to be "
1158 "an identifier in `%s:%s'\n",
1169 sprintf (range,
"[");
1172 strcat (range, prop->
range.
str[i]);
1173 strcat (range,
",");
1178 range[strlen (range) - 1] =
']';
1180 "checker error, value of `%s' (%s) needs to be "
1181 "in %s in `%s:%s'\n",
1217 return errors ? 0 : 1;
1228 for (prev = NULL, def = root; def != NULL; def =
next)
1231 if (!strcmp (def->
type,
"Def"))
1279 struct node_t *
n, * ninst, * ntype;
1282 for (i = 1, ntype = type->
nodes, ninst = inst->
nodes; ntype != NULL;
1283 ntype = ntype->
next, ninst = ninst->
next, i++)
1285 for (n = sub->
nodes; n != NULL; n = n->
next)
1289 if (!strcmp (n->
node, ntype->
node))
1304 char * txt = (
char *)
1305 calloc (1, strlen (type) + strlen (instance) + strlen (node) +
1306 (instances ? strlen (instances) : 0) + 4);
1308 sprintf (txt,
"%s.%s.%s.%s", type, instances, instance, node);
1310 sprintf (txt,
"%s.%s.%s", type, instance, node);
1319 for (root = NULL; nodes != NULL; nodes =
next)
1339 struct node_t *
n, * ncopy, * root = NULL;
1342 for (n = sub->
nodes; n != NULL; n = n->
next)
1346 ncopy = (
struct node_t *) calloc (
sizeof (
struct node_t), 1);
1350 if (instances == NULL)
1355 else if (!strcmp (n->
node,
"gnd"))
1359 else if (n->
node[strlen (n->
node) - 1] ==
'!')
1381 for (
int i = 1;
i <
n;
i++)
1384 assert (root != NULL);
1394 if (
n->xlate)
free (
n->xlate);
1417 for (ncopy = copy->
nodes; ncopy != NULL; ncopy = ncopy->
next)
1420 if (ncopy->
node == NULL)
1428 if (instances == NULL)
1434 else if (!strcmp (n->
node,
"gnd"))
1438 else if (n->
node[strlen (n->
node) - 1] ==
'!')
1457 if (def->next == NULL)
return def;
1465 if (instances && instances->length () > 0)
1466 return instances->toString (
".");
1476 char * txt = (
char *)
1477 calloc (1, strlen (type) + strlen (instance) + strlen (base) +
1478 (instances ? strlen (instances) : 0) + 4);
1480 sprintf (txt,
"%s.%s.%s.%s", type, instances, instance, base);
1482 sprintf (txt,
"%s.%s.%s", type, instance, base);
1502 environment * child =
new environment (*(type->
env));
1503 parent->addChild (child);
1506 for (
struct pair_t * pair = inst->
pairs; pair != NULL; pair = pair->
next)
1509 if (strcmp (pair->key,
"Type"))
1511 if (pair->value->ident == NULL)
1514 child->setDoubleConstant (pair->key, pair->value->value);
1515 child->setDouble (pair->key, pair->value->value);
1520 child->setDoubleReference (pair->key, pair->value->ident);
1526 for (def = type->
sub; def != NULL; def = def->
next)
1533 if (!strcmp (def->
type,
"Sub"))
1538 if ((*instances) == NULL) (*instances) =
new strlist ();
1539 instcopy =
new strlist (*(*instances));
1541 (*instances)->append (inst->
instance);
1559 *instances = instcopy;
1585 strlist * icopy =
new strlist ();
1587 icopy->append (*(instances));
1589 child->setName (icopy->toString (
"."));
1604 int errors = 0, error;
1609 if ((*deps)->contains (type))
1612 "detected, involves: %s\n",
1613 type, instance, (*deps)->toString ());
1616 (*deps)->append (type);
1619 strlist * checked =
new strlist ();
1624 if (!strcmp (def->type,
"Sub"))
1629 if (!checked->contains (val->
ident))
1632 checked->append (val->
ident);
1634 strlist *
copy =
new strlist (*(*deps));
1676 for (o = r = 0, p = def->
pairs; p != NULL; p = p->
next)
1678 if (p->
value == NULL)
1689 for (o = r = 0, p = def->
pairs; p != NULL; p = p->
next)
1691 if (p->
value == NULL)
1739 for (i = 0, p = d->
required; p[i].
key != NULL; i++)
1745 for (i = 0, p = d->
optional; p[i].
key != NULL; i++)
1761 int i,
n, errors = 0;
1770 "`%s' occurred %dx in `%s:%s'\n", def->
line,
1782 "`%s' occurred %dx in `%s:%s'\n", def->
line,
1789 for (pair = def->
pairs; pair != NULL; pair = pair->
next)
1795 if (strcmp (def->
type,
"Def"))
1798 "line %d: checker error, extraneous property `%s' is "
1799 "invalid in `%s:%s'\n", def->
line,
1805 if (pair->
value != NULL)
1833 if (!strcmp (def->type,
"Sub"))
1848 "`%s' found as referred in `%s:%s'\n", def->line,
1849 val->
ident, def->type, def->instance);
1860 "`%s' requires %d nodes in `%s:%s', found %d\n",
1862 def->type, def->instance, n1);
1870 strlist * deps =
new strlist ();
1872 def->instance, &deps);
1887 for (; node != NULL; node =
n)
1908 for (; pp != NULL; pp = np)
1912 for (value = pp->
value; value != NULL; value = nv)
1948 for (prev = root; prev != NULL && prev->
next != cand; prev = prev->
next) ;
1965 strlist * instances = NULL;
1968 for (prev = NULL, def = root; def != NULL; def =
next)
1972 if (!strcmp (def->
type,
"Sub"))
1998 if (!prev) prev = last;
2022 for (def = root; def != NULL; def = def->
next)
2027 if (available == NULL)
2036 def->
nodeset = !strcmp (def->
type,
"NodeSet") ? 1 : 0;
2051 "line %d: checker error, at least 1 node required in "
2052 "`%s:%s', found %d\n", def->
line, def->
type,
2057 else if (available->
nodes != n)
2060 "line %d: checker error, %d node(s) required in `%s:%s', "
2061 "found %d\n", def->
line,
2066 if (strcmp (def->
type,
"Sub"))
2095 else if (value->
ident)
2097 else if (value->
next)
2100 for (; value != NULL; value = value->
next)
2120 for (def = root; def != NULL; def = def->
next)
2123 for (node = def->
nodes; node != NULL; node = node->
next)
2127 for (pair = def->
pairs; pair != NULL; pair = pair->
next)
2159 hashiterator<module> it;
2162 def = it.currentVal()->definition;
2165 if (!strcmp (def->
type, cir->
type)) count++;
2184 for (prev = NULL, def = root; def != NULL; def =
next)
2187 if (!strcmp (def->
type,
"Eqn"))
2217 eqn::checker * checkee =
new eqn::checker ();
2219 checkee->setEquations (eqns);
2221 checkee->constants ();
2223 env->setChecker (checkee);
2225 eqn::solver * solvee =
new eqn::solver (checkee);
2227 env->setSolver (solvee);
2229 if (root) root->
env =
env;
2237 for (
struct pair_t * pair = def->
pairs; pair != NULL; pair = pair->
next)
2240 if (strcmp (pair->
key,
"Type"))
2243 env->getChecker()->addDouble (
"#subcircuit",
2261 env_root =
new environment (env->getName ());
2273 env_root->setDefinitions (definition_root);
2274 errors +=
env_root->equationChecker (0);
2283 environment * subenv =
new environment (def->
instance);
2292 subenv->setDefinitions (def->
sub);
2293 errors += subenv->equationChecker (0);
2294 subenv->setDefinitions (NULL);
2308 return errors ? -1 : 0;
2315 for (def = root; def != NULL; def =
next)
static int checker_validate_para(struct definition_t *root)
static char * checker_subcircuit_node(char *type, char *instances, char *instance, char *node)
static int checker_count_definition(struct definition_t *root, const char *type, char *instance)
static void netlist_free_pairs(struct pair_t *pp)
static void netlist_free_definition(struct definition_t *def)
int netlist_checker_variables(environment *env)
nr_complex_t pow(const nr_complex_t z, const nr_double_t d)
Compute power function with real exponent.
static int checker_evaluate_scale(struct value_t *value)
static struct value_t * checker_find_variable(struct definition_t *root, const char *type, const char *key, char *ident)
eqn::checker * getChecker(void)
Global physical constants header file.
static int checker_value_in_prop_range(char *instance, struct define_t *def, struct pair_t *pp, struct property_t *prop)
static int checker_validate_properties(struct definition_t *root, struct definition_t *def, struct define_t *available)
static int checker_resolve_variable(struct definition_t *root, struct definition_t *def, struct pair_t *pair, int type)
static struct definition_t * checker_find_port(struct definition_t *root)
static char * checker_subcircuit_instance(char *type, char *instances, char *instance, char *base)
static int checker_validate_nodesets(struct definition_t *root)
static void checker_subcircuit_args(struct definition_t *def, environment *env)
int netlist_checker(environment *env)
static node * lastEquation(node *)
struct definition_t * sub
struct definition_t * subcircuit_root
static struct definition_t * checker_get_subcircuit(struct definition_t *def)
static struct value_t * checker_find_prop_value(struct definition_t *def, const char *key)
struct property_t * required
static int checker_find_property(const char *key, struct pair_t *pp)
static int checker_validate_actions(struct definition_t *root)
struct property_t::@6 defaultval
void netlist_destroy(void)
static void netlist_free_define(struct define_t *d)
static struct value_t * checker_find_reference(struct definition_t *def, const char *key)
static int checker_value_in_range(char *instance, struct define_t *def, struct pair_t *pp)
static struct definition_t * checker_copy_subcircuits(struct definition_t *type, struct definition_t *inst, strlist **instances, environment *parent)
static int checker_validate_strips(struct definition_t *root)
static struct definition_t * checker_find_subcircuit(char *n)
static int netlist_checker_intern(struct definition_t *root)
static int checker_validate_subcircuits(struct definition_t *root)
#define PROP_HAS_STR(prop)
static int checker_is_property(struct define_t *available, const char *key)
struct node_t * netlist_reverse_nodes(struct node_t *nodes)
#define PROP_IS_LST(prop)
static void checker_xlat_subcircuit_nodes(struct definition_t *type, struct definition_t *inst, struct definition_t *sub)
static struct define_t * getModule(char *)
static int checker_validate_lists(struct definition_t *root)
static qucs::hash< module > modules
static struct define_t * netlist_create_define(struct definition_t *def)
static void checker_copy_circuit_nodes(struct definition_t *type, struct definition_t *inst, struct definition_t *sub, struct definition_t *copy, char *instances)
struct property_t::@7 range
#define PROP_IS_PROP(prop)
static void netlist_free_nodes(struct node_t *node)
static struct definition_t * checker_find_last_definition(struct definition_t *root)
static int netlist_checker_variables_intern(struct definition_t *root, environment *env)
static int checker_count_nodes(struct definition_t *def)
#define PROP_IS_VAL(prop)
int netlist_lex_destroy(void)
static int checker_count_action(struct definition_t *root, char *instance)
void netlist_status(void)
static void checker_setup_env(struct definition_t *root, environment *env, eqn::node *eqns)
static int checker_validate_para_cycles(struct definition_t *root, char *instance, strlist *deps)
struct definition_t * definition_root
#define PROP_IS_INT(prop)
static struct definition_t * checker_build_subcircuits(struct definition_t *root)
struct property_t * optional
void netlist_destroy_env(void)
The environment class definition.
static void checker_copy_subcircuit_nodes(struct definition_t *type, struct definition_t *inst, struct definition_t *sub, struct definition_t *copy, char *instances)
static void netlist_free_value(struct value_t *value)
static struct definition_t * checker_copy_subcircuit(struct definition_t *sub)
static void netlist_destroy_intern(struct definition_t *root)
static int checker_count_nonlinearities(struct definition_t *root)
static struct define_t * checker_find_definition(char *type, int action)
static int checker_validate_ports(struct definition_t *root)
#define PROP_HAS_RANGE(prop)
static variable * checker_add_variable(environment *env, char *var, int type, bool pass)
static struct value_t * checker_validate_reference(struct definition_t *def, const char *key)
static int checker_count_nodesets(struct definition_t *root, char *n)
variable * getVariable(char *)
struct definition_t * netlist_unchain_definition(struct definition_t *root, struct definition_t *cand)
static struct definition_t * checker_build_equations(struct definition_t *root, eqn::node **eroot)
static struct definition_t * checker_expand_subcircuits(struct definition_t *root, environment *parent)
static void checker_cleanup_xlat_nodes(struct definition_t *sub)
void logprint(int level, const char *format,...)
static char * checker_subcircuit_instance_list(strlist *instances)
static void netlist_lister(struct definition_t *root, const char *prefix)
static struct node_t * checker_get_circuit_node(struct node_t *root, int n)
struct definition_t * next
static int checker_validate_sub_cycles(struct definition_t *root, char *type, char *instance, strlist **deps)
static int checker_sub_cycles
static void netlist_list_value(struct value_t *value)
static int checker_count_definitions(struct definition_t *root, const char *type, int action)
static struct value_t * checker_find_substrate(struct definition_t *def, char *ident)