1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-22 06:04:05 +02:00

The mechanism for selecting points for measurements reaches its limits when

using frames to encapsulate building blocks, e.g., like macros or functions in
a programming language. Since measurements only know about the frame containing
a vector but not the frames containing that frame, invocations of this frame
from different places can only be distinguished within the min/next/max scheme.
(See the example in README.)

To eliminate this limitation, one needs a way to tell fped to consider a point
only if it has been instantiated through a certain path, e.g., by requiring
some other frames to be visited in its instantiation. This increases the number
of distinct points available for measurements.

The mechanism chosen is to qualify a measurement point with frames that lead to
it. This list of outer frames does not have to include all frames. Without
qualifying, the old behaviour results.

Note that this doesn't cover all possible ways in which a point can appear in
different roles. Multiple frame references can also result from repeating the
same frame reference in the same parent frame. The current qualification
mechanism does not allow such paths to be distinguished. However, one can 
always introduce intermediate frames for this purpose.

Furthermore, repetitions create multiple instances of a point, although in what
should be considered the same role.

- fpd.l: make scanner support free-format a little better by switching back to
  keyword mode after frame braces. This way, one can write a simple frame in a
  single line, which is useful for regression tests.
- fpd.l, fpd.y, README, test/dbg_meas: added %meas directive to print the 
  result of a measurement
- fpd.y, README: measurements can now be labeled. Note that, due to limitations
  of the grammar, the first measurement cannot be labeled.
- error.h, error.c (yywarn): new function for non-fatal diagnostics that always
  get reported to standard error
- bitset.h, bitset.c: functions to manipulate variable-size bit sets
- meas.h, fpd.y, README, test/meas_qual: added the means to specify qualifiers
  for points used in measurements
- dump.c (print_meas_base, print_meas): dump qualifiers
- delete.c (delete_references, test/del_frame): delete measurements that
  reference a frame being deleted in their qualifiers
- obj.h, obj.c (enumerate_frames, instantiate): enumerate all frames so that we
  have an index into the bit vector of visited frames
- meas.h, meas.c (reset_samples, meas_post), obj.c (generate_vecs,
  generate_frame, instantiate): record the set of frames visited for each
  sample
- meas.c (meas_post): only treat two instances of a point as equivalent if the
  set of frames visited of one of them is a superset of set of the other. In
  this case, keep the union of the two sets.
- meas.h, meas.c (meas_find_min, meas_find_next, meas_find_max),
  test/meas_qual: instantiate_meas_pkg only select points for which all frames
  in the qualification have been visited
- gui_meas.c (is_min, is_next, is_max, is_a_next): updated for above change
- inst.h, inst.c (curr_frame, propagate_bbox, add_inst, inst_begin_frame,
  inst_end_frame, inst_start): renamed curr_frame to frame_instantiating to
  avoid clash with curr_frame in fpd.y
- inst.h, inst.c (find_meas_hint): make global
- test/structure, test/del_vec, test/del_frame: fped now warns if a measurement
  is in an unlinked frame. Changed regressions tests to avoid this warning.
- test/Common: new function expect_grep to compare only part of the output



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5967 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2010-05-29 21:13:48 +00:00
parent 8e60952ba1
commit c9af8cd0fe
23 changed files with 934 additions and 93 deletions

View File

@ -16,7 +16,7 @@ UPLOAD = werner@sita.openmoko.org:public_html/fped/
OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \ OBJS = fped.o expr.o coord.o obj.o delete.o inst.o util.o error.o \
unparse.o file.o dump.o kicad.o postscript.o meas.o \ unparse.o file.o dump.o kicad.o postscript.o meas.o \
layer.o overlap.o hole.o tsort.o \ layer.o overlap.o hole.o tsort.o bitset.o \
cpp.o lex.yy.o y.tab.o \ cpp.o lex.yy.o y.tab.o \
gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \ gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \
gui_tool.o gui_over.o gui_meas.o gui_frame.o gui_frame_drag.o gui_tool.o gui_over.o gui_meas.o gui_frame.o gui_frame_drag.o

59
README
View File

@ -582,6 +582,60 @@ measx "width = " a >> b 0mm
would print "width = 1mm" would print "width = 1mm"
Additional qualifiers
- - - - - - - - - - -
When using frames as reusable building blocks, similar to functions or
macros in many programming languages, one may need finer control over
the points that are selected for measurements.
For example, let us consider a frame "square" that draws a square
centered at the frame's origin and with a side length given by the
variable "size". This variable be set in the frame referencing
"square".
frame square {
a: vec @(-size/2, -size/2)
b: vec @(size/2, size/2)
rect a b
}
frame small {
set size = 2mm
frame square @
}
frame big {
set size = 5mm
frame square @
}
frame small @
vec @(5mm, 0mm)
frame big .
If we want to measure the size of each square, we could use
measx square.a -> square.b
Unfortunately, this only measures the small square. To reach the
big frame, we need to tell fped to use only those points in "square"
that have been placed when "square" was invoked from the big frame.
This is accomplished by prefixing the points in question with the
name(s) of the frames that need to be visited. The frame names are
separated by slashes (/).
measx big/square.a -> square.b
For clarity, it's better to qualify both points, e.g.,
measx big/square.a -> big/square.b
If multiple frame names are given, they must be in the order in
which they are invoked.
Experimental: debugging directives Experimental: debugging directives
---------------------------------- ----------------------------------
@ -592,6 +646,7 @@ most of which mimick the effect of GUI operations:
%move <identifier> [<number>] <identifier> %move <identifier> [<number>] <identifier>
%frame <identifier> <qualified-base> %frame <identifier> <qualified-base>
%print <expression> %print <expression>
%meas <identifier>
%dump %dump
%exit %exit
%tsort { -<id> | +<id> | <id-before> <id-after> [<number>] ... } %tsort { -<id> | +<id> | <id-before> <id-after> [<number>] ... }
@ -622,6 +677,10 @@ parent frame's origin can be references as "@".
%dump writes the footprint definition in the fped language to standard %dump writes the footprint definition in the fped language to standard
output. %exit immediately exits fped, without invoking the GUI. output. %exit immediately exits fped, without invoking the GUI.
%print evaluates the expression and prints the result to standard output.
%meas performs an instantiation and prints the value of the labeled
measurement.
%tsort is used to test-drive the topological sort algorithm. The items %tsort is used to test-drive the topological sort algorithm. The items
in the curly braces are declarations of nodes with (-<id>) or without in the curly braces are declarations of nodes with (-<id>) or without
(+<id>) decay or edges in the partial order. The optional number is (+<id>) decay or edges in the partial order. The optional number is

133
bitset.c Normal file
View File

@ -0,0 +1,133 @@
/*
* bitset.c - Arbitrary-length bit sets
*
* Written 2010 by Werner Almesberger
* Copyright 2010 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#include "util.h"
#include "bitset.h"
struct bitset {
int v_n;
unsigned *v;
};
#define BITS (sizeof(unsigned)*8)
struct bitset *bitset_new(int n)
{
struct bitset *new;
new = alloc_type(struct bitset);
new->v_n = (n+BITS-1) & ~(BITS-1);
new->v = zalloc_size(sizeof(unsigned)*new->v_n);
return new;
}
struct bitset *bitset_clone(const struct bitset *old)
{
struct bitset *new;
size_t bytes;
new = alloc_type(struct bitset);
bytes = sizeof(unsigned)*old->v_n;
new->v_n = old->v_n;
new->v = alloc_size(bytes);
memcpy(new->v, old->v, bytes);
return new;
}
void bitset_free(struct bitset *set)
{
free(set->v);
free(set);
}
void bitset_set(struct bitset *set, int n)
{
assert(n < set->v_n*BITS);
set->v[n/BITS] |= 1U << (n % BITS);
}
void bitset_clear(struct bitset *set, int n)
{
assert(n < set->v_n*BITS);
set->v[n/BITS] &= ~(1U << (n % BITS));
}
int bitset_pick(const struct bitset *set, int n)
{
assert(n < set->v_n*BITS);
return !!(set->v[n/BITS] & (1U << (n % BITS)));
}
int bitset_is_empty(const struct bitset *set)
{
int i;
for (i = 0; i != set->v_n; i++)
if (set->v[i])
return 0;
return 1;
}
void bitset_zero(struct bitset *a)
{
int i;
for (i = 0; i != a->v_n; i++)
a->v[i] = 0;
}
void bitset_and(struct bitset *a, const struct bitset *b)
{
int i;
assert(a->v_n == b->v_n);
for (i = 0; i != a->v_n; i++)
a->v[i] &= b->v[i];
}
void bitset_or(struct bitset *a, const struct bitset *b)
{
int i;
assert(a->v_n == b->v_n);
for (i = 0; i != a->v_n; i++)
a->v[i] |= b->v[i];
}
int bitset_ge(const struct bitset *a, const struct bitset *b)
{
int i;
assert(a->v_n == b->v_n);
for (i = 0; i != a->v_n; i++)
if (~a->v[i] & b->v[i])
return 0;
return 1;
}

34
bitset.h Normal file
View File

@ -0,0 +1,34 @@
/*
* bitset.h - Arbitrary-length bit sets
*
* Written 2010 by Werner Almesberger
* Copyright 2010 by Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef BITSET_H
#define BITSET_H
struct bitset;
struct bitset *bitset_new(int n);
struct bitset *bitset_clone(const struct bitset *old);
void bitset_free(struct bitset *set);
void bitset_set(struct bitset *set, int n);
void bitset_clear(struct bitset *set, int n);
int bitset_pick(const struct bitset *set, int n);
int bitset_is_empty(const struct bitset *set);
void bitset_zero(struct bitset *a);
void bitset_and(struct bitset *a, const struct bitset *b);
void bitset_or(struct bitset *a, const struct bitset *b);
int bitset_ge(const struct bitset *a, const struct bitset *b);
#endif /* !BITSET_H */

View File

@ -521,6 +521,17 @@ static void destroy_frame(struct frame *frame)
} }
static int qual_ref(const struct frame_qual *qual, const struct frame *ref)
{
while (qual) {
if (qual->frame == ref)
return 1;
qual = qual->next;
}
return 0;
}
static void delete_references(const struct frame *ref) static void delete_references(const struct frame *ref)
{ {
struct frame *frame; struct frame *frame;
@ -535,7 +546,9 @@ static void delete_references(const struct frame *ref)
break; break;
case ot_meas: case ot_meas:
if (obj->base->frame == ref || if (obj->base->frame == ref ||
obj->u.meas.high->frame == ref) obj->u.meas.high->frame == ref ||
qual_ref(obj->u.meas.low_qual, ref) ||
qual_ref(obj->u.meas.high_qual, ref))
do_delete_obj(obj); do_delete_obj(obj);
break; break;
default: default:

35
dump.c
View File

@ -13,6 +13,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "util.h" #include "util.h"
#include "unparse.h" #include "unparse.h"
@ -389,14 +391,35 @@ static const char *meas_type_name[mt_n] = {
static char *print_meas_base(struct vec *base) static char *print_meas_base(struct vec *base, const struct frame_qual *qual)
{ {
const char *name; const char *name;
size_t n;
const struct frame_qual *walk;
char *s, *p;
name = base_name(base, NULL); name = base_name(base, NULL);
if (base->frame == frames) n = strlen(name)+1; /* vec\0 */
return stralloc(name); for (walk = qual; walk; walk = walk->next)
return stralloc_printf("%s.%s", base->frame->name, name); n += strlen(walk->frame->name)+1; /* frame/ */
if (base->frame != frames)
n += strlen(base->frame->name)+1; /* frame. */
s = p = alloc_size(n);
for (walk = qual; walk; walk = walk->next) {
n = strlen(walk->frame->name);
memcpy(p, walk->frame->name, n);
p[n] = '/';
p += n+1;
}
if (base->frame != frames) {
n = strlen(base->frame->name);
memcpy(p, base->frame->name, n);
p[n] = '.';
p += n+1;
}
strcpy(p, name);
return s;
} }
@ -413,11 +436,11 @@ char *print_meas(const struct obj *obj)
free(s); free(s);
s = t; s = t;
} }
s1 = print_meas_base(obj->base); s1 = print_meas_base(obj->base, obj->u.meas.low_qual);
s2 = stralloc_printf(" %s ", s2 = stralloc_printf(" %s ",
obj->u.meas.type < 3 ? obj->u.meas.inverted ? "<-" : "->" : obj->u.meas.type < 3 ? obj->u.meas.inverted ? "<-" : "->" :
obj->u.meas.inverted ? "<<" : ">>"); obj->u.meas.inverted ? "<<" : ">>");
s3 = print_meas_base(obj->u.meas.high); s3 = print_meas_base(obj->u.meas.high, obj->u.meas.high_qual);
t = stralloc_printf("%s%s%s%s", s, s1, s2, s3); t = stralloc_printf("%s%s%s%s", s, s1, s2, s3);
free(s); free(s);
free(s1); free(s1);

11
error.c
View File

@ -1,8 +1,8 @@
/* /*
* error.c - Error reporting * error.c - Error reporting
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -25,6 +25,13 @@ int lineno = 1;
void (*reporter)(const char *s) = report_to_stderr; void (*reporter)(const char *s) = report_to_stderr;
void yywarn(const char *s)
{
/* we use yywarn only when starting */
fprintf(stderr, "%d: warning: %s near \"%s\"\n", lineno, s, yytext);
}
void yyerrorf(const char *fmt, ...) void yyerrorf(const char *fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -1,8 +1,8 @@
/* /*
* error.h - Error reporting * error.h - Error reporting
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,6 +20,8 @@ extern int lineno;
extern void (*reporter)(const char *s); extern void (*reporter)(const char *s);
void yywarn(const char *s);
void yyerrorf(const char *fmt, ...) void yyerrorf(const char *fmt, ...)
__attribute__((format(printf, 1, 2))); __attribute__((format(printf, 1, 2)));
void yyerror(const char *s); void yyerror(const char *s);

8
fpd.l
View File

@ -131,6 +131,8 @@ SP [\t ]*
return TOK_DBG_FRAME; } return TOK_DBG_FRAME; }
<INITIAL>"%print" { BEGIN(NOKEYWORD); <INITIAL>"%print" { BEGIN(NOKEYWORD);
return TOK_DBG_PRINT; } return TOK_DBG_PRINT; }
<INITIAL>"%meas" { BEGIN(NOKEYWORD);
return TOK_DBG_MEAS; }
<INITIAL>"%dump" { BEGIN(NOKEYWORD); <INITIAL>"%dump" { BEGIN(NOKEYWORD);
return TOK_DBG_DUMP; } return TOK_DBG_DUMP; }
<INITIAL>"%exit" { BEGIN(NOKEYWORD); <INITIAL>"%exit" { BEGIN(NOKEYWORD);
@ -173,10 +175,12 @@ SP [\t ]*
; BEGIN(INITIAL); ; BEGIN(INITIAL);
"{" { BEGIN(NOKEYWORD); "{" { disable_keywords = is_table;
disable_keywords = is_table; BEGIN(disable_keywords ?
NOKEYWORD : INITIAL);
return '{'; } return '{'; }
"}" { disable_keywords = 0; "}" { disable_keywords = 0;
BEGIN(INITIAL);
return '}'; } return '}'; }
^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n { ^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {

182
fpd.y
View File

@ -17,14 +17,18 @@
#include "util.h" #include "util.h"
#include "error.h" #include "error.h"
#include "coord.h"
#include "expr.h" #include "expr.h"
#include "obj.h" #include "obj.h"
#include "meas.h" #include "meas.h"
#include "gui_status.h" #include "gui_status.h"
#include "gui_inst.h" /* for %meas */
#include "dump.h" #include "dump.h"
#include "tsort.h" #include "tsort.h"
#include "fpd.h" #include "fpd.h"
#include "y.tab.h"
struct expr *expr_result; struct expr *expr_result;
const char *var_id; const char *var_id;
@ -49,6 +53,9 @@ static const char *id_sin, *id_cos, *id_sqrt;
static struct tsort *tsort; static struct tsort *tsort;
/* ----- lookup functions -------------------------------------------------- */
static struct frame *find_frame(const char *name) static struct frame *find_frame(const char *name)
{ {
struct frame *f; struct frame *f;
@ -109,6 +116,9 @@ static struct var *find_var(const struct frame *frame, const char *name)
} }
/* ----- item creation ----------------------------------------------------- */
static void set_frame(struct frame *frame) static void set_frame(struct frame *frame)
{ {
curr_frame = frame; curr_frame = frame;
@ -177,6 +187,65 @@ static struct obj *new_obj(enum obj_type type)
} }
/* ---- frame qualifiers --------------------------------------------------- */
static int duplicate_qualifier(const struct frame_qual *a,
const struct frame_qual *b)
{
if (!b)
return 0;
if (a != b && a->frame == b->frame) {
yyerrorf("duplicate qualifier \"%s\"", a->frame->name);
return 1;
}
if (b && duplicate_qualifier(a, b->next))
return 1;
return duplicate_qualifier(a->next, a->next);
}
static int can_reach(const struct frame *curr, const struct frame_qual *qual,
const struct frame *end)
{
const struct obj *obj;
if (curr == end)
return !qual;
/*
* Don't recurse for removing the qualifier alone. We require a frame
* reference step as well, so that things like foo.foo.foo.bar.vec
* aren't allowed.
*
* Since a duplicate qualifier can never work, we test for this error
* explicitly in "duplicate_qualifier".
*/
if (qual && curr == qual->frame)
qual = qual->next;
for (obj = curr->objs; obj; obj = obj->next)
if (obj->type == ot_frame)
if (can_reach(obj->u.frame.ref, qual, end))
return 1;
return 0;
}
static int check_qbase(struct qbase *qbase)
{
if (duplicate_qualifier(qbase->qualifiers, qbase->qualifiers))
return 0;
if (!can_reach(frames, qbase->qualifiers, qbase->vec->frame))
yywarn("not all qualifiers can be reached");
return 1;
}
/* ----- debugging directives ---------------------------------------------- */
static int dbg_delete(const char *frame_name, const char *name) static int dbg_delete(const char *frame_name, const char *name)
{ {
struct vec *vec; struct vec *vec;
@ -314,6 +383,43 @@ static int dbg_print(const struct expr *expr)
} }
static int dbg_meas(const char *name)
{
const struct obj *obj;
const struct inst *inst;
struct coord a1, b1;
char *s;
obj = find_obj(frames, name);
if (!obj) {
yyerrorf("unknown object \"%s\"", name);
return 0;
}
/* from fped.c:main */
if (!pkg_name)
pkg_name = stralloc("_");
reporter = report_to_stderr;
if (!instantiate())
return 0;
inst = find_meas_hint(obj);
if (!inst) {
yyerrorf("measurement \"%s\" was not instantiated", name);
return 0;
}
project_meas(inst, &a1, &b1);
s = format_len(obj->u.meas.label ? obj->u.meas.label : "",
dist_point(a1, b1), curr_unit);
printf("%s\n", s);
free(s);
return 1;
}
%} %}
@ -339,6 +445,10 @@ static int dbg_print(const struct expr *expr)
struct frame *frame; struct frame *frame;
struct vec *vec; struct vec *vec;
} qvec; } qvec;
struct qbase {
struct vec *vec;
struct frame_qual *qualifiers;
} qbase;
}; };
@ -348,7 +458,7 @@ static int dbg_print(const struct expr *expr)
%token TOK_MEAS TOK_MEASX TOK_MEASY TOK_UNIT %token TOK_MEAS TOK_MEASX TOK_MEASY TOK_UNIT
%token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED %token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED
%token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_FRAME TOK_DBG_PRINT %token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_FRAME TOK_DBG_PRINT
%token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT %token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT TOK_DBG_MEAS
%token <num> NUMBER %token <num> NUMBER
%token <str> STRING %token <str> STRING
@ -358,8 +468,8 @@ static int dbg_print(const struct expr *expr)
%type <var> vars var %type <var> vars var
%type <row> rows %type <row> rows
%type <value> row value opt_value_list %type <value> row value opt_value_list
%type <vec> vec base qbase %type <vec> vec base
%type <obj> object obj meas %type <obj> object obj meas unlabeled_meas
%type <expr> expr opt_expr add_expr mult_expr unary_expr primary_expr %type <expr> expr opt_expr add_expr mult_expr unary_expr primary_expr
%type <num> opt_num %type <num> opt_num
%type <frame> frame_qualifier %type <frame> frame_qualifier
@ -368,6 +478,7 @@ static int dbg_print(const struct expr *expr)
%type <mt> meas_type %type <mt> meas_type
%type <mo> meas_op %type <mo> meas_op
%type <qvec> qualified_base %type <qvec> qualified_base
%type <qbase> qbase qbase_unchecked
%% %%
@ -538,6 +649,11 @@ debug_item:
if (!dbg_print($2)) if (!dbg_print($2))
YYABORT; YYABORT;
} }
| TOK_DBG_MEAS ID
{
if (!dbg_meas($2))
YYABORT;
}
| TOK_DBG_DUMP | TOK_DBG_DUMP
{ {
if (!dump(stdout)) { if (!dump(stdout)) {
@ -867,7 +983,7 @@ opt_measurements:
; ;
measurements: measurements:
meas unlabeled_meas /* @@@ hack */
{ {
*next_obj = $1; *next_obj = $1;
next_obj = &$1->next; next_obj = &$1->next;
@ -881,6 +997,22 @@ measurements:
; ;
meas: meas:
unlabeled_meas
{
$$ = $1;
}
| LABEL unlabeled_meas
{
$$ = $2;
if (find_label(curr_frame, $1)) {
yyerrorf("duplicate label \"%s\"", $1);
YYABORT;
}
$$->name = $1;
}
;
unlabeled_meas:
meas_type opt_string qbase meas_op qbase opt_expr meas_type opt_string qbase meas_op qbase opt_expr
{ {
struct meas *meas; struct meas *meas;
@ -889,33 +1021,63 @@ meas:
meas = &$$->u.meas; meas = &$$->u.meas;
meas->type = $4.max ? $1+3 : $1; meas->type = $4.max ? $1+3 : $1;
meas->label = $2; meas->label = $2;
$$->base = $3; $$->base = $3.vec;
meas->low_qual = $3.qualifiers;
meas->inverted = $4.inverted; meas->inverted = $4.inverted;
meas->high = $5; meas->high = $5.vec;
meas->high_qual = $5.qualifiers;
meas->offset = $6; meas->offset = $6;
$$->next = NULL; $$->next = NULL;
} }
; ;
qbase: qbase:
qbase_unchecked
{
$$ = $1;
if (!check_qbase(&$$))
YYABORT;
}
;
qbase_unchecked:
ID ID
{ {
$$ = find_vec(frames, $1); $$.vec = find_vec(frames, $1);
if (!$$) { if (!$$.vec) {
yyerrorf("unknown vector \"%s\"", $1); yyerrorf("unknown vector \"%s\"", $1);
YYABORT; YYABORT;
} }
$$.qualifiers = NULL;
} }
| ID '.' ID | ID '.' ID
{ {
const struct frame *frame; const struct frame *frame;
frame = find_frame($1); frame = find_frame($1);
$$ = frame ? find_vec(frame, $3) : NULL; $$.vec = frame ? find_vec(frame, $3) : NULL;
if (!$$) { if (!$$.vec) {
yyerrorf("unknown vector \"%s.%s\"", $1, $3); yyerrorf("unknown vector \"%s.%s\"", $1, $3);
YYABORT; YYABORT;
} }
$$.qualifiers = NULL;
}
| ID '/' qbase
{
const struct frame *frame;
struct frame_qual *qual;
$$ = $3;
frame = find_frame($1);
if (!frame) {
yyerrorf("unknown frame \"%s\"", $1);
YYABORT;
} else {
qual = alloc_type(struct frame_qual);
qual->frame = frame;
qual->next = $$.qualifiers;
$$.qualifiers = qual;
}
} }
; ;

View File

@ -1,8 +1,8 @@
/* /*
* gui_meas.c - GUI, measurements * gui_meas.c - GUI, measurements
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -61,43 +61,43 @@ static struct meas_dsc meas_dsc_y = {
static int is_min(lt_op_type lt, const struct inst *inst) static int is_min(lt_op_type lt, const struct inst *inst)
{ {
struct coord min; const struct sample *min;
min = meas_find_min(lt, active_pkg->samples[inst->vec->n]); min = meas_find_min(lt, active_pkg->samples[inst->vec->n], NULL);
return coord_eq(inst->u.vec.end, min); return coord_eq(inst->u.vec.end, min->pos);
} }
static int is_next(lt_op_type lt, static int is_next(lt_op_type lt,
const struct inst *inst, const struct inst *ref) const struct inst *inst, const struct inst *ref)
{ {
struct coord next; const struct sample *next;
next = meas_find_next(lt, active_pkg->samples[inst->vec->n], next = meas_find_next(lt, active_pkg->samples[inst->vec->n],
ref->u.vec.end); ref->u.vec.end, NULL);
return coord_eq(inst->u.vec.end, next); return coord_eq(inst->u.vec.end, next->pos);
} }
static int is_max(lt_op_type lt, const struct inst *inst) static int is_max(lt_op_type lt, const struct inst *inst)
{ {
struct coord max; const struct sample *max;
max = meas_find_max(lt, active_pkg->samples[inst->vec->n]); max = meas_find_max(lt, active_pkg->samples[inst->vec->n], NULL);
return coord_eq(inst->u.vec.end, max); return coord_eq(inst->u.vec.end, max->pos);
} }
static int is_a_next(lt_op_type lt, struct inst *inst) static int is_a_next(lt_op_type lt, struct inst *inst)
{ {
struct inst *a; struct inst *a;
struct coord min, next; const struct sample *min, *next;
for (a = insts_ip_vec(); a; a = a->next) { for (a = insts_ip_vec(); a; a = a->next) {
min = meas_find_min(lt, active_pkg->samples[a->vec->n]); min = meas_find_min(lt, active_pkg->samples[a->vec->n], NULL);
next = meas_find_next(lt, active_pkg->samples[inst->vec->n], next = meas_find_next(lt, active_pkg->samples[inst->vec->n],
min); min->pos, NULL);
if (coord_eq(next, inst->u.vec.end)) if (coord_eq(next->pos, inst->u.vec.end))
return 1; return 1;
} }
return 0; return 0;
@ -309,6 +309,9 @@ static int end_new_meas(struct inst *from, struct inst *to)
(mode == min_to_next_or_max); (mode == min_to_next_or_max);
meas->offset = NULL; meas->offset = NULL;
meas_dsc = NULL; meas_dsc = NULL;
/* we don't support qualifiers through the GUI yet */
meas->low_qual = NULL;
meas->high_qual = NULL;
return 1; return 1;
} }

20
inst.c
View File

@ -35,7 +35,7 @@
struct inst *selected_inst = NULL; struct inst *selected_inst = NULL;
struct bbox active_frame_bbox; struct bbox active_frame_bbox;
struct pkg *pkgs, *active_pkg, *curr_pkg; struct pkg *pkgs, *active_pkg, *curr_pkg;
struct inst *curr_frame = NULL; struct inst *frame_instantiating = NULL;
static struct pkg *prev_pkgs; static struct pkg *prev_pkgs;
@ -574,8 +574,8 @@ static void update_bbox(struct bbox *bbox, struct coord coord)
static void propagate_bbox(const struct inst *inst) static void propagate_bbox(const struct inst *inst)
{ {
struct inst *frame = struct inst *frame = frame_instantiating ?
curr_frame ? curr_frame : curr_pkg->insts[ip_frame]; frame_instantiating : curr_pkg->insts[ip_frame];
update_bbox(&frame->bbox, inst->bbox.min); update_bbox(&frame->bbox, inst->bbox.min);
update_bbox(&frame->bbox, inst->bbox.max); update_bbox(&frame->bbox, inst->bbox.max);
@ -602,7 +602,7 @@ static struct inst *add_inst(const struct inst_ops *ops, enum inst_prio prio,
inst->vec = NULL; inst->vec = NULL;
inst->obj = NULL; inst->obj = NULL;
inst->base = inst->bbox.min = inst->bbox.max = base; inst->base = inst->bbox.min = inst->bbox.max = base;
inst->outer = curr_frame; inst->outer = frame_instantiating;
inst->active = IS_ACTIVE; inst->active = IS_ACTIVE;
inst->next = NULL; inst->next = NULL;
*curr_pkg->next_inst[prio] = inst; *curr_pkg->next_inst[prio] = inst;
@ -1030,7 +1030,7 @@ static struct inst_ops meas_ops = {
}; };
static struct inst *find_meas_hint(const struct obj *obj) struct inst *find_meas_hint(const struct obj *obj)
{ {
struct inst *inst; struct inst *inst;
@ -1151,16 +1151,16 @@ void inst_begin_frame(struct obj *obj, struct frame *frame,
inst->u.frame.active = is_active_frame; inst->u.frame.active = is_active_frame;
inst->active = active; inst->active = active;
find_inst(inst); find_inst(inst);
curr_frame = inst; frame_instantiating = inst;
} }
void inst_end_frame(const struct frame *frame) void inst_end_frame(const struct frame *frame)
{ {
struct inst *inst = curr_frame; struct inst *inst = frame_instantiating;
curr_frame = curr_frame->outer; frame_instantiating = frame_instantiating->outer;
if (curr_frame) if (frame_instantiating)
propagate_bbox(inst); propagate_bbox(inst);
if (inst->u.frame.active && frame == active_frame) if (inst->u.frame.active && frame == active_frame)
active_frame_bbox = inst->bbox; active_frame_bbox = inst->bbox;
@ -1245,7 +1245,7 @@ void inst_start(void)
pkgs = NULL; pkgs = NULL;
inst_select_pkg(NULL); inst_select_pkg(NULL);
curr_pkg = pkgs; curr_pkg = pkgs;
curr_frame = NULL; frame_instantiating = NULL;
} }

3
inst.h
View File

@ -139,7 +139,7 @@ extern struct bbox active_frame_bbox;
* frame being instantiated - we need to export this one for meas.c, so that * frame being instantiated - we need to export this one for meas.c, so that
* measurements can update the root frame's bounding box. * measurements can update the root frame's bounding box.
*/ */
extern struct inst *curr_frame; extern struct inst *frame_instantiating;
/* /*
* @@@ Note that we over-generalize a bit here: the only item that ever ends up * @@@ Note that we over-generalize a bit here: the only item that ever ends up
@ -183,6 +183,7 @@ int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b);
int inst_hole(struct obj *obj, struct coord a, struct coord b); int inst_hole(struct obj *obj, struct coord a, struct coord b);
int inst_arc(struct obj *obj, struct coord center, struct coord start, int inst_arc(struct obj *obj, struct coord center, struct coord start,
struct coord stop, unit_type width); struct coord stop, unit_type width);
struct inst *find_meas_hint(const struct obj *obj);
int inst_meas(struct obj *obj, struct coord from, struct coord to); int inst_meas(struct obj *obj, struct coord from, struct coord to);
void inst_meas_hint(struct obj *obj, unit_type offset); void inst_meas_hint(struct obj *obj, unit_type offset);

100
meas.c
View File

@ -1,8 +1,8 @@
/* /*
* meas.c - Measurements * meas.c - Measurements
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -35,6 +35,7 @@ void reset_samples(struct sample **samples, int n)
for (i = 0; i != n; i++) for (i = 0; i != n; i++)
while (samples[i]) { while (samples[i]) {
next = samples[i]->next; next = samples[i]->next;
bitset_free(samples[i]->frame_set);
free(samples[i]); free(samples[i]);
samples[i] = next; samples[i] = next;
} }
@ -53,7 +54,8 @@ void meas_start(void)
} }
void meas_post(const struct vec *vec, struct coord pos) void meas_post(const struct vec *vec, struct coord pos,
const struct bitset *frame_set)
{ {
struct sample **walk, *new; struct sample **walk, *new;
@ -64,11 +66,18 @@ void meas_post(const struct vec *vec, struct coord pos)
continue; continue;
if (pos.x < (*walk)->pos.x) if (pos.x < (*walk)->pos.x)
break; break;
if (pos.x == (*walk)->pos.x) if (pos.x != (*walk)->pos.x)
continue;
if (bitset_ge((*walk)->frame_set, frame_set))
return; return;
if (bitset_ge(frame_set, (*walk)->frame_set)) {
bitset_or((*walk)->frame_set, frame_set);
return;
}
} }
new = alloc_type(struct sample); new = alloc_type(struct sample);
new->pos = pos; new->pos = pos;
new->frame_set = bitset_clone(frame_set);
new->next = *walk; new->next = *walk;
*walk = new; *walk = new;
} }
@ -177,45 +186,47 @@ static int better_next(lt_op_type lt,
* else if (*a == a0 && *a <xy a0) use *a * else if (*a == a0 && *a <xy a0) use *a
*/ */
struct coord meas_find_min(lt_op_type lt, const struct sample *s) const struct sample *meas_find_min(lt_op_type lt, const struct sample *s,
const struct bitset *qual)
{ {
struct coord min; const struct sample *min = NULL;
min = s->pos;
while (s) { while (s) {
if (lt(s->pos, min) || if (!qual || bitset_ge(s->frame_set, qual))
(!lt(min, s->pos) && lt_xy(s->pos, min))) if (!min || lt(s->pos, min->pos) ||
min = s->pos; (!lt(min->pos, s->pos) && lt_xy(s->pos, min->pos)))
min = s;
s = s->next; s = s->next;
} }
return min; return min;
} }
struct coord meas_find_next(lt_op_type lt, const struct sample *s, const struct sample *meas_find_next(lt_op_type lt, const struct sample *s,
struct coord ref) struct coord ref, const struct bitset *qual)
{ {
struct coord next; const struct sample *next = NULL;
next = s->pos;
while (s) { while (s) {
if (better_next(lt, ref, next, s->pos)) if (!qual || bitset_ge(s->frame_set, qual))
next = s->pos; if (!next || better_next(lt, ref, next->pos, s->pos))
next = s;
s = s->next; s = s->next;
} }
return next; return next;
} }
struct coord meas_find_max(lt_op_type lt, const struct sample *s) const struct sample *meas_find_max(lt_op_type lt, const struct sample *s,
const struct bitset *qual)
{ {
struct coord max; const struct sample *max = NULL;
max = s->pos;
while (s) { while (s) {
if (lt(max, s->pos) || if (!qual || bitset_ge(s->frame_set, qual))
(!lt(s->pos, max) && lt_xy(max, s->pos))) if (!max || lt(max->pos, s->pos) ||
max = s->pos; (!lt(s->pos, max->pos) && lt_xy(max->pos, s->pos)))
max = s;
s = s->next; s = s->next;
} }
return max; return max;
@ -225,46 +236,73 @@ struct coord meas_find_max(lt_op_type lt, const struct sample *s)
/* ----- instantiation ----------------------------------------------------- */ /* ----- instantiation ----------------------------------------------------- */
static int instantiate_meas_pkg(void) static struct bitset *make_frame_set(struct frame_qual *qual, int n_frames)
{
struct bitset *set;
set = bitset_new(n_frames);
while (qual) {
bitset_set(set, qual->frame->n);
qual = qual->next;
}
return set;
}
static int instantiate_meas_pkg(int n_frames)
{ {
struct obj *obj; struct obj *obj;
const struct meas *meas; const struct meas *meas;
struct coord a0, b0; struct bitset *set;
const struct sample *a0, *b0;
lt_op_type lt; lt_op_type lt;
for (obj = frames->objs; obj; obj = obj->next) { for (obj = frames->objs; obj; obj = obj->next) {
if (obj->type != ot_meas) if (obj->type != ot_meas)
continue; continue;
meas = &obj->u.meas; meas = &obj->u.meas;
/* optimization. not really needed anymore. */
if (!curr_pkg->samples[obj->base->n] || if (!curr_pkg->samples[obj->base->n] ||
!curr_pkg->samples[meas->high->n]) !curr_pkg->samples[meas->high->n])
continue; continue;
lt = lt_op[meas->type]; lt = lt_op[meas->type];
a0 = meas_find_min(lt, curr_pkg->samples[obj->base->n]);
set = make_frame_set(meas->low_qual, n_frames);
a0 = meas_find_min(lt, curr_pkg->samples[obj->base->n], set);
bitset_free(set);
if (!a0)
continue;
set = make_frame_set(meas->high_qual, n_frames);
if (is_next[meas->type]) if (is_next[meas->type])
b0 = meas_find_next(lt, b0 = meas_find_next(lt,
curr_pkg->samples[meas->high->n], a0); curr_pkg->samples[meas->high->n], a0->pos, set);
else else
b0 = meas_find_max(lt, b0 = meas_find_max(lt,
curr_pkg->samples[meas->high->n]); curr_pkg->samples[meas->high->n], set);
bitset_free(set);
if (!b0)
continue;
inst_meas(obj, inst_meas(obj,
meas->inverted ? b0 : a0, meas->inverted ? a0 : b0); meas->inverted ? b0->pos : a0->pos,
meas->inverted ? a0->pos : b0->pos);
} }
return 1; return 1;
} }
int instantiate_meas(void) int instantiate_meas(int n_frames)
{ {
struct pkg *pkg; struct pkg *pkg;
curr_frame = pkgs->insts[ip_frame]; frame_instantiating = pkgs->insts[ip_frame];
for (pkg = pkgs; pkg; pkg = pkg->next) for (pkg = pkgs; pkg; pkg = pkg->next)
if (pkg->name) { if (pkg->name) {
inst_select_pkg(pkg->name); inst_select_pkg(pkg->name);
if (!instantiate_meas_pkg()) if (!instantiate_meas_pkg(n_frames))
return 0; return 0;
} }
return 1; return 1;

30
meas.h
View File

@ -1,8 +1,8 @@
/* /*
* meas.h - Measurements * meas.h - Measurements
* *
* Written 2009 by Werner Almesberger * Written 2009, 2010 by Werner Almesberger
* Copyright 2009 by Werner Almesberger * Copyright 2009, 2010 by Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -17,6 +17,7 @@
#include "coord.h" #include "coord.h"
#include "expr.h" #include "expr.h"
#include "bitset.h"
typedef int (*lt_op_type)(struct coord a, struct coord b); typedef int (*lt_op_type)(struct coord a, struct coord b);
@ -24,6 +25,11 @@ typedef int (*lt_op_type)(struct coord a, struct coord b);
struct vec; struct vec;
struct obj; struct obj;
struct frame_qual {
const struct frame *frame;
struct frame_qual *next;
};
struct meas { struct meas {
enum meas_type { enum meas_type {
mt_xy_next, mt_xy_next,
@ -39,10 +45,15 @@ struct meas {
/* low is obj->base */ /* low is obj->base */
struct vec *high; struct vec *high;
struct expr *offset; struct expr *offset;
/* frame qualifiers */
struct frame_qual *low_qual;
struct frame_qual *high_qual;
}; };
struct sample { struct sample {
struct coord pos; struct coord pos;
struct bitset *frame_set;
struct sample *next; struct sample *next;
}; };
@ -54,15 +65,18 @@ int lt_x(struct coord a, struct coord b);
int lt_y(struct coord a, struct coord b); int lt_y(struct coord a, struct coord b);
int lt_xy(struct coord a, struct coord b); int lt_xy(struct coord a, struct coord b);
struct coord meas_find_min(lt_op_type lt, const struct sample *s); const struct sample *meas_find_min(lt_op_type lt, const struct sample *s,
struct coord meas_find_next(lt_op_type lt, const struct sample *s, const struct bitset *qual);
struct coord ref); const struct sample *meas_find_next(lt_op_type lt, const struct sample *s,
struct coord meas_find_max(lt_op_type lt, const struct sample *s); struct coord ref, const struct bitset *qual);
const struct sample *meas_find_max(lt_op_type lt, const struct sample *s,
const struct bitset *qual);
void reset_samples(struct sample **samples, int n); void reset_samples(struct sample **samples, int n);
void meas_start(void); void meas_start(void);
void meas_post(const struct vec *vec, struct coord pos); void meas_post(const struct vec *vec, struct coord pos,
int instantiate_meas(void); const struct bitset *frame_set);
int instantiate_meas(int n_frames);
#endif /* !MEAS_H */ #endif /* !MEAS_H */

25
obj.c
View File

@ -18,6 +18,7 @@
#include "util.h" #include "util.h"
#include "error.h" #include "error.h"
#include "expr.h" #include "expr.h"
#include "bitset.h"
#include "meas.h" #include "meas.h"
#include "inst.h" #include "inst.h"
#include "hole.h" #include "hole.h"
@ -38,6 +39,9 @@ struct frame *active_frame = NULL;
void *instantiation_error = NULL; void *instantiation_error = NULL;
static struct bitset *frame_set; /* frames visited in "call chain" */
/* ----- Searching --------------------------------------------------------- */ /* ----- Searching --------------------------------------------------------- */
@ -181,7 +185,7 @@ static int generate_vecs(struct frame *frame, struct coord base)
vec->pos.y += y.n; vec->pos.y += y.n;
if (!inst_vec(vec, vec_base)) if (!inst_vec(vec, vec_base))
goto error; goto error;
meas_post(vec, vec->pos); meas_post(vec, vec->pos, frame_set);
} }
return 1; return 1;
@ -399,9 +403,11 @@ static int generate_frame(struct frame *frame, struct coord base,
inst_begin_frame(frame_ref, frame, base, inst_begin_frame(frame_ref, frame, base,
active && parent == active_frame, active && parent == active_frame,
active && frame == active_frame); active && frame == active_frame);
bitset_set(frame_set, frame->n);
frame->curr_parent = parent; frame->curr_parent = parent;
ok = iterate_tables(frame, frame->tables, base, active); ok = iterate_tables(frame, frame->tables, base, active);
inst_end_frame(frame); inst_end_frame(frame);
bitset_clear(frame_set, frame->n);
frame->curr_parent = NULL; frame->curr_parent = NULL;
return ok; return ok;
} }
@ -458,13 +464,27 @@ static void activate_found(void)
} }
static int enumerate_frames(void)
{
struct frame *frame;
int n = 0;
for (frame = frames; frame; frame = frame->next)
frame->n = n++;
return n;
}
int instantiate(void) int instantiate(void)
{ {
struct coord zero = { 0, 0 }; struct coord zero = { 0, 0 };
int n_frames;
int ok; int ok;
meas_start(); meas_start();
inst_start(); inst_start();
n_frames = enumerate_frames();
frame_set = bitset_new(n_frames);
instantiation_error = NULL; instantiation_error = NULL;
reset_all_loops(); reset_all_loops();
reset_found(); reset_found();
@ -480,11 +500,12 @@ int instantiate(void)
if (ok) if (ok)
ok = refine_layers(); ok = refine_layers();
if (ok) if (ok)
ok = instantiate_meas(); ok = instantiate_meas(n_frames);
if (ok) if (ok)
inst_commit(); inst_commit();
else else
inst_revert(); inst_revert();
bitset_free(frame_set);
return ok; return ok;
} }

5
obj.h
View File

@ -163,9 +163,12 @@ struct frame {
/* generating and editing */ /* generating and editing */
struct obj *active_ref; struct obj *active_ref;
/* For searching */ /* for searching */
struct obj *found_ref; /* NULL if not found yet */ struct obj *found_ref; /* NULL if not found yet */
/* index into bit vector in samples */
int n;
/* for dumping */ /* for dumping */
int dumped; int dumped;

View File

@ -62,6 +62,15 @@ expect()
} }
expect_grep()
{
grep "$1" <_out >_tmp || exit 1
mv _tmp _out
shift
expect "$@"
}
if [ ! -z "$CWD_PREFIX" -a ! -z "$FPED" -a "$FPED" = "${FPED#/}" ]; then if [ ! -z "$CWD_PREFIX" -a ! -z "$FPED" -a "$FPED" = "${FPED#/}" ]; then
FPED="$CWD_PREFIX/$FPED" FPED="$CWD_PREFIX/$FPED"
fi fi

54
test/dbg_meas Executable file
View File

@ -0,0 +1,54 @@
#!/bin/sh
. ./Common
###############################################################################
fped "%meas: print mm (default)" <<EOF
a: vec @(0mm, 0mm)
b: vec @(3mm, 4mm)
meas a >> b /* work-around to simplify grammar */
m: meas a >> b
%meas m
EOF
expect <<EOF
5
EOF
#------------------------------------------------------------------------------
fped "%meas: print mil" <<EOF
unit mil
a: vec @(0mm, 0mm)
b: vec @(2.54mm, 0mm)
meas a >> b /* work-around to simplify grammar */
m: meas a >> b
%meas m
EOF
expect <<EOF
100
EOF
#------------------------------------------------------------------------------
fped_fail "%meas: invalid ID" <<EOF
%meas m
EOF
expect <<EOF
1: unknown object "m" near "m"
EOF
#------------------------------------------------------------------------------
fped_fail "%meas: measurement not instantiated" <<EOF
a: vec @(0mm, 0mm)
loop i = 1, 0
b: vec @(i*1mm, 0mm)
meas a >> b /* work-around to simplify grammar */
m: meas a >> b
%meas m
EOF
expect <<EOF
measurement "m" was not instantiated
EOF
###############################################################################

View File

@ -53,6 +53,7 @@ frame f {
v: vec @(0mm, 0mm) v: vec @(0mm, 0mm)
} }
frame f @
meas f.v -> f.v meas f.v -> f.v
%del f %del f
@ -64,4 +65,29 @@ package "_"
unit mm unit mm
EOF EOF
#------------------------------------------------------------------------------
fped_dump "delete frame: measurements with qualifiers disappear" <<EOF
frame f {
v: vec @(0mm, 0mm)
}
frame g { frame f @ }
frame g @
meas g/f.v -> f.v
%del g
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame f {
v: vec @(0mm, 0mm)
}
package "_"
unit mm
EOF
############################################################################### ###############################################################################

View File

@ -48,6 +48,7 @@ fped_dump "delete vector: measurements disappear (other frame)" <<EOF
frame f { frame f {
v: vec @(0mm, 0mm) v: vec @(0mm, 0mm)
} }
frame f @
meas f.v -> f.v meas f.v -> f.v
%del f.v %del f.v
EOF EOF
@ -59,6 +60,7 @@ frame f {
package "_" package "_"
unit mm unit mm
frame f @
EOF EOF
############################################################################### ###############################################################################

231
test/meas_qual Executable file
View File

@ -0,0 +1,231 @@
#!/bin/sh
. ./Common
###############################################################################
fped_dump "qualified measurements: no qualifier" <<EOF
frame c { v: vec @(0mm, 0mm) }
frame b { frame c @ }
frame a { frame b @ }
frame a @
meas c.v >> c.v
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame c {
v: vec @(0mm, 0mm)
}
frame b {
frame c @
}
frame a {
frame b @
}
package "_"
unit mm
frame a @
meas c.v >> c.v
EOF
#------------------------------------------------------------------------------
fped_dump "qualified measurements: fully qualified" <<EOF
frame c { v: vec @(0mm, 0mm) }
frame b { frame c @ }
frame a { frame b @ }
frame a @
meas a/b/c.v >> c.v
EOF
expect_grep '^meas' <<EOF
meas a/b/c.v >> c.v
EOF
#------------------------------------------------------------------------------
fped_dump "qualified measurements: partially qualified" <<EOF
frame c { v: vec @(0mm, 0mm) }
frame b { frame c @ }
frame a { frame b @ }
frame a @
meas a/c.v >> c.v
EOF
expect_grep '^meas' <<EOF
meas a/c.v >> c.v
EOF
#------------------------------------------------------------------------------
fped_dump "qualified measurements: wrong order" <<EOF
frame c { v: vec @(0mm, 0mm) }
frame b { frame c @ }
frame a { frame b @ }
frame a @
meas b/a/c.v >> c.v
EOF
expect_grep 'warning' <<EOF
5: warning: not all qualifiers can be reached near "v"
EOF
#------------------------------------------------------------------------------
fped_dump "qualified measurements: unlinked frame" <<EOF
frame c { v: vec @(0mm, 0mm) }
frame b { frame c @ }
frame a { frame b @ }
frame x {}
frame a @
frame x @
meas a/c.v >> x/c.v
EOF
expect_grep 'warning' <<EOF
7: warning: not all qualifiers can be reached near "v"
EOF
#------------------------------------------------------------------------------
fped_fail "qualified measurements: duplicate qualifier" <<EOF
frame c { v: vec @(0mm, 0mm) }
frame b { frame c @ }
frame a { frame b @ }
frame a @
meas b/b/c.v >> c.v
EOF
expect <<EOF
5: duplicate qualifier "b" near "v"
EOF
#------------------------------------------------------------------------------
fped "qualified measurements: \"macro\" unqualified" <<EOF
frame x {
a: vec @(0mm, 0mm)
b: vec .(d, 0mm)
}
frame a {
set d = 2mm
frame x @
}
frame b {
set d = 3mm
frame x @
}
frame a @
vec @(1mm, 0mm)
frame b .
meas x.a >> x.b /* dummy */
m: meas x.a >> x.b
%meas m
EOF
expect <<EOF
4
EOF
#------------------------------------------------------------------------------
fped "qualified measurements: \"macro\" qualified (a)" <<EOF
frame x {
a: vec @(0mm, 0mm)
b: vec .(d, 0mm)
}
frame a {
set d = 2mm
frame x @
}
frame b {
set d = 3mm
frame x @
}
frame a @
vec @(1mm, 0mm)
frame b .
meas x.a >> x.b /* dummy */
m: meas a/x.a >> a/x.b
%meas m
EOF
expect <<EOF
2
EOF
#------------------------------------------------------------------------------
fped "qualified measurements: \"macro\" qualified (b)" <<EOF
frame x {
a: vec @(0mm, 0mm)
b: vec .(d, 0mm)
}
frame a {
set d = 2mm
frame x @
}
frame b {
set d = 3mm
frame x @
}
frame a @
vec @(1mm, 0mm)
frame b .
meas x.a >> x.b /* dummy */
m: meas b/x.a >> b/x.b
%meas m
EOF
expect <<EOF
3
EOF
#------------------------------------------------------------------------------
fped "qualified measurements: \"macro\" qualified (a/b)" <<EOF
frame x {
a: vec @(0mm, 0mm)
b: vec .(d, 0mm)
}
frame a {
set d = 2mm
frame x @
}
frame b {
set d = 3mm
frame x @
}
frame a @
vec @(1mm, 0mm)
frame b .
meas x.a >> x.b /* dummy */
m: meas a/x.a >> b/x.b
%meas m
EOF
expect <<EOF
4
EOF
#------------------------------------------------------------------------------
fped "qualified measurements: \"macro\" qualified (b/a)" <<EOF
frame x {
a: vec @(0mm, 0mm)
b: vec .(d, 0mm)
}
frame a {
set d = 2mm
frame x @
}
frame b {
set d = 3mm
frame x @
}
frame a @
vec @(1mm, 0mm)
frame b .
meas x.a >> x.b /* dummy */
m: meas b/x.a >> a/x.b
%meas m
EOF
expect <<EOF
1
EOF
###############################################################################

View File

@ -72,6 +72,7 @@ frame f {
a: vec @(0mm, 0mm) a: vec @(0mm, 0mm)
b: vec @(1mm, 1mm) b: vec @(1mm, 1mm)
} }
frame f @
meas f.a -> f.b meas f.a -> f.b
EOF EOF
expect <<EOF expect <<EOF
@ -84,6 +85,7 @@ frame f {
package "_" package "_"
unit mm unit mm
frame f @
meas f.a -> f.b meas f.a -> f.b
EOF EOF