1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-22 19:11:10 +02:00

b2/: introduce dimensionless values (field syntax: name=##)

This commit is contained in:
Werner Almesberger 2012-06-01 00:20:31 -03:00
parent 4fb5f26043
commit d48a9030e0
7 changed files with 72 additions and 14 deletions

View File

@ -141,9 +141,11 @@ static void dump_field_decl(FILE *file, const struct field *field)
else if (field->fmt->ops == &param_ops_set)
dump_set_decl(file, field->fmt->u.set);
else if (field->fmt->ops == &param_ops_abs)
fprintf(file, "#%s", field->fmt->u.abs);
fprintf(file, "#%s",
field->fmt->u.abs ? field->fmt->u.abs : "#");
else if (field->fmt->ops == &param_ops_rel)
fprintf(file, "%%%s", field->fmt->u.rel->u.abs);
fprintf(file, "%%%s",
field->fmt->u.rel->u.abs ? field->fmt->u.rel->u.abs : "#");
else
abort();
}

View File

@ -43,7 +43,7 @@ void dump_set(FILE *file, const struct format *fmt, const struct value *v)
void dump_abs(FILE *file, const struct format *fmt, const struct value *v)
{
fprintf(file, "%g%s", v->u.abs, fmt->u.abs);
fprintf(file, "%g%s", v->u.abs, fmt->u.abs ? fmt->u.abs : "");
}
@ -54,7 +54,8 @@ void dump_rel(FILE *file, const struct format *fmt, const struct value *v)
v->u.rel.minus*100, v->u.rel.plus*100);
else
fprintf(file, "-%g/+%g%s",
v->u.rel.minus, v->u.rel.plus, fmt->u.rel->u.abs);
v->u.rel.minus, v->u.rel.plus,
fmt->u.rel->u.abs ? fmt->u.rel->u.abs : "");
}

View File

@ -92,11 +92,13 @@ static int strip_unit(const char *s, const char **stop, const char *unit,
{
int n;
n = strlen(unit);
if (*stop-n < s)
return 0;
if (!strcmp(*stop-n, unit))
*stop -= n;
if (unit) {
n = strlen(unit);
if (*stop-n < s)
return 0;
if (!strcmp(*stop-n, unit))
*stop -= n;
}
if (*stop > s) {
if (decode_mult((*stop)[-1], mult))
(*stop)--;

View File

@ -393,6 +393,12 @@ format:
$$->ops = &param_ops_abs;
$$->u.abs = $2;
}
| '#' '#'
{
$$ = alloc_type(struct format);
$$->ops = &param_ops_abs;
$$->u.abs = NULL;
}
| '%' WORD
{
$$ = alloc_type(struct format);

View File

@ -45,7 +45,7 @@ struct format {
const struct param_ops *ops;
union {
const struct names *set;
const char *abs; /* unit name */
const char *abs; /* unit name; NULL if dimensionless */
const struct format *rel;
} u;
};

View File

@ -41,7 +41,7 @@ EOF
#------------------------------------------------------------------------------
tst "hierarchy: absolute value field" <<EOF
tst "hierarchy: absolute value field (with unit)" <<EOF
{ X=#foo };
EOF
@ -51,7 +51,17 @@ EOF
#------------------------------------------------------------------------------
tst_fail "hierarchy: absolute value field (omit type name)" <<EOF
tst "hierarchy: absolute value field (without unit)" <<EOF
{ X=## };
EOF
expect <<EOF
{ X=## }
EOF
#------------------------------------------------------------------------------
tst_fail "hierarchy: absolute value field (omit unit name)" <<EOF
{ X=# };
EOF

View File

@ -79,7 +79,7 @@ EOF
#------------------------------------------------------------------------------
tst "hierarchy: absolute value rule" <<EOF
tst "hierarchy: absolute value rule (with unit)" <<EOF
<predation> = mouse<cat<dog;
N=#R {
10R: { X=* };
@ -98,6 +98,25 @@ EOF
#------------------------------------------------------------------------------
tst "hierarchy: absolute value rule (without unit)" <<EOF
<predation> = mouse<cat<dog;
N=## {
2: { X=* };
5k: { Y=* };
3.1: { Z=* };
};
EOF
expect <<EOF
N=## {
2: { X=* }
5000: { Y=* }
3.1: { Z=* }
}
EOF
#------------------------------------------------------------------------------
tst_fail "hierarchy: absolute value rule (different unit)" <<EOF
<predation> = mouse<cat<dog;
N=#R {
@ -142,7 +161,7 @@ EOF
#------------------------------------------------------------------------------
tst "hierarchy: relative value rule (absolute)" <<EOF
tst "hierarchy: relative value rule (absolute, with unit)" <<EOF
{ V=#R }
TOL=%V {
1R: { X=* };
@ -160,6 +179,24 @@ EOF
#------------------------------------------------------------------------------
tst "hierarchy: relative value rule (absolute, without unit)" <<EOF
{ V=## }
TOL=%V {
1: { X=* };
1k: { Y=* };
};
EOF
expect <<EOF
{ V=## }
TOL=%# {
-1/+1: { X=* }
-1000/+1000: { Y=* }
}
EOF
#------------------------------------------------------------------------------
tst "hierarchy: relative value rule (plus/minus percent)" <<EOF
{ V=#R }
TOL=%V {