1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-22 16:01:54 +02:00

b2/: add parameter conversion

This commit is contained in:
Werner Almesberger 2012-04-28 22:50:15 -03:00
parent b172117a1c
commit 331fbdda6a
4 changed files with 81 additions and 2 deletions

View File

@ -1,2 +1,2 @@
FOO R101X FP=0603 R=100R TOL=5%
FOO R102Y FP=0603 R=1k TOL=1%
FOO R101X T=R FP=0603 R=100R TOL=5% GAGA=1
FOO R102Y T=R FP=0603 R=1k TOL=1%

72
b2/db.c
View File

@ -10,9 +10,12 @@
*/
#include <stdlib.h>
#include <glib.h>
#include "util.h"
#include "lang.h"
#include "chr.h"
#include "db.h"
@ -80,3 +83,72 @@ void part_alias(struct part *a, struct part *b)
b->prev = a;
tmp->prev = tmp2;
}
static void convert_params(struct param **params,
const struct field *f, struct param ***res)
{
struct param **p, *prm;
const struct selector *sel;
const struct condition *cond;
while (f) {
for (p = params; *p; p = &(*p)->next)
if ((*p)->u.name == f->name)
break;
if (!*p) {
f = f->next;
continue;
}
/* remove from list */
prm = *p;
*p = prm->next;
/* convert parameter */
prm->u.field = f;
if (!evaluate(f->fmt, prm->value.u.name, &prm->value))
yyerrorf("invalid value for %s", f->name);
/* add to result list */
**res = prm;
*res = &prm->next;
prm->next = NULL;
/* process selections */
for (sel = f->sel; sel; sel = sel->next) {
for (cond = sel->cond; cond; cond = cond->next)
if (compare(f->fmt, &prm->value, cond->relop,
&cond->value))
break;
if (cond) {
convert_params(params, sel->act.fields, res);
convert_params(params, sel->act.rules, res);
break;
}
}
if (!sel) {
convert_params(params, f->any.fields, res);
convert_params(params, f->any.rules, res);
}
f = f->next;
}
}
void part_finalize(struct part *part, const struct field *field)
{
struct param *param = part->param;
struct param **res = &part->param;
struct param *next;
part->param = NULL;
convert_params(&param, field, &res);
while (param) {
yywarnf("extra parameter: %s", param->u.name);
next = param->next;
free(param);
param = next;
}
}

View File

@ -62,5 +62,6 @@ struct part {
struct part *part_lookup(const char *domain, const char *name);
struct part *part_add(const char *domain, const char *name);
void part_alias(struct part *a, struct part *b);
void part_finalize(struct part *part, const struct field *field);
#endif /* !DB_H */

View File

@ -23,6 +23,8 @@
#include "y.tab.h"
static const struct field *hierarchy;
static struct field_stack {
const struct field *field;
struct field_stack *next;
@ -101,6 +103,7 @@ hierarchy:
nameset hierarchy
| rule
{
hierarchy = $1;
field_dump(stderr, $1);
}
;
@ -348,6 +351,9 @@ format:
characteristics:
| TOK_NL
| part characteristics
{
part_finalize($1, hierarchy);
}
;
part: