mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-24 23:05:56 +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:
parent
8e60952ba1
commit
c9af8cd0fe
2
Makefile
2
Makefile
@ -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 \
|
||||
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 \
|
||||
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
|
||||
|
59
README
59
README
@ -582,6 +582,60 @@ measx "width = " a >> b 0mm
|
||||
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
|
||||
----------------------------------
|
||||
|
||||
@ -592,6 +646,7 @@ most of which mimick the effect of GUI operations:
|
||||
%move <identifier> [<number>] <identifier>
|
||||
%frame <identifier> <qualified-base>
|
||||
%print <expression>
|
||||
%meas <identifier>
|
||||
%dump
|
||||
%exit
|
||||
%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
|
||||
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
|
||||
in the curly braces are declarations of nodes with (-<id>) or without
|
||||
(+<id>) decay or edges in the partial order. The optional number is
|
||||
|
133
bitset.c
Normal file
133
bitset.c
Normal 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
34
bitset.h
Normal 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 */
|
15
delete.c
15
delete.c
@ -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)
|
||||
{
|
||||
struct frame *frame;
|
||||
@ -535,7 +546,9 @@ static void delete_references(const struct frame *ref)
|
||||
break;
|
||||
case ot_meas:
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
|
35
dump.c
35
dump.c
@ -13,6 +13,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "util.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;
|
||||
size_t n;
|
||||
const struct frame_qual *walk;
|
||||
char *s, *p;
|
||||
|
||||
name = base_name(base, NULL);
|
||||
if (base->frame == frames)
|
||||
return stralloc(name);
|
||||
return stralloc_printf("%s.%s", base->frame->name, name);
|
||||
n = strlen(name)+1; /* vec\0 */
|
||||
for (walk = qual; walk; walk = walk->next)
|
||||
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);
|
||||
s = t;
|
||||
}
|
||||
s1 = print_meas_base(obj->base);
|
||||
s1 = print_meas_base(obj->base, obj->u.meas.low_qual);
|
||||
s2 = stralloc_printf(" %s ",
|
||||
obj->u.meas.type < 3 ? 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);
|
||||
free(s);
|
||||
free(s1);
|
||||
|
11
error.c
11
error.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* error.c - Error reporting
|
||||
*
|
||||
* Written 2009 by Werner Almesberger
|
||||
* Copyright 2009 by Werner Almesberger
|
||||
* Written 2009, 2010 by Werner Almesberger
|
||||
* Copyright 2009, 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
|
||||
@ -25,6 +25,13 @@ int lineno = 1;
|
||||
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, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
6
error.h
6
error.h
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* error.h - Error reporting
|
||||
*
|
||||
* Written 2009 by Werner Almesberger
|
||||
* Copyright 2009 by Werner Almesberger
|
||||
* Written 2009, 2010 by Werner Almesberger
|
||||
* Copyright 2009, 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
|
||||
@ -20,6 +20,8 @@ extern int lineno;
|
||||
extern void (*reporter)(const char *s);
|
||||
|
||||
|
||||
void yywarn(const char *s);
|
||||
|
||||
void yyerrorf(const char *fmt, ...)
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
void yyerror(const char *s);
|
||||
|
8
fpd.l
8
fpd.l
@ -131,6 +131,8 @@ SP [\t ]*
|
||||
return TOK_DBG_FRAME; }
|
||||
<INITIAL>"%print" { BEGIN(NOKEYWORD);
|
||||
return TOK_DBG_PRINT; }
|
||||
<INITIAL>"%meas" { BEGIN(NOKEYWORD);
|
||||
return TOK_DBG_MEAS; }
|
||||
<INITIAL>"%dump" { BEGIN(NOKEYWORD);
|
||||
return TOK_DBG_DUMP; }
|
||||
<INITIAL>"%exit" { BEGIN(NOKEYWORD);
|
||||
@ -173,10 +175,12 @@ SP [\t ]*
|
||||
|
||||
; BEGIN(INITIAL);
|
||||
|
||||
"{" { BEGIN(NOKEYWORD);
|
||||
disable_keywords = is_table;
|
||||
"{" { disable_keywords = is_table;
|
||||
BEGIN(disable_keywords ?
|
||||
NOKEYWORD : INITIAL);
|
||||
return '{'; }
|
||||
"}" { disable_keywords = 0;
|
||||
BEGIN(INITIAL);
|
||||
return '}'; }
|
||||
|
||||
^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
|
||||
|
182
fpd.y
182
fpd.y
@ -17,14 +17,18 @@
|
||||
|
||||
#include "util.h"
|
||||
#include "error.h"
|
||||
#include "coord.h"
|
||||
#include "expr.h"
|
||||
#include "obj.h"
|
||||
#include "meas.h"
|
||||
#include "gui_status.h"
|
||||
#include "gui_inst.h" /* for %meas */
|
||||
#include "dump.h"
|
||||
#include "tsort.h"
|
||||
#include "fpd.h"
|
||||
|
||||
#include "y.tab.h"
|
||||
|
||||
|
||||
struct expr *expr_result;
|
||||
const char *var_id;
|
||||
@ -49,6 +53,9 @@ static const char *id_sin, *id_cos, *id_sqrt;
|
||||
static struct tsort *tsort;
|
||||
|
||||
|
||||
/* ----- lookup functions -------------------------------------------------- */
|
||||
|
||||
|
||||
static struct frame *find_frame(const char *name)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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 vec *vec;
|
||||
} 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_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_DUMP TOK_DBG_EXIT TOK_DBG_TSORT
|
||||
%token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT TOK_DBG_MEAS
|
||||
|
||||
%token <num> NUMBER
|
||||
%token <str> STRING
|
||||
@ -358,8 +468,8 @@ static int dbg_print(const struct expr *expr)
|
||||
%type <var> vars var
|
||||
%type <row> rows
|
||||
%type <value> row value opt_value_list
|
||||
%type <vec> vec base qbase
|
||||
%type <obj> object obj meas
|
||||
%type <vec> vec base
|
||||
%type <obj> object obj meas unlabeled_meas
|
||||
%type <expr> expr opt_expr add_expr mult_expr unary_expr primary_expr
|
||||
%type <num> opt_num
|
||||
%type <frame> frame_qualifier
|
||||
@ -368,6 +478,7 @@ static int dbg_print(const struct expr *expr)
|
||||
%type <mt> meas_type
|
||||
%type <mo> meas_op
|
||||
%type <qvec> qualified_base
|
||||
%type <qbase> qbase qbase_unchecked
|
||||
|
||||
%%
|
||||
|
||||
@ -538,6 +649,11 @@ debug_item:
|
||||
if (!dbg_print($2))
|
||||
YYABORT;
|
||||
}
|
||||
| TOK_DBG_MEAS ID
|
||||
{
|
||||
if (!dbg_meas($2))
|
||||
YYABORT;
|
||||
}
|
||||
| TOK_DBG_DUMP
|
||||
{
|
||||
if (!dump(stdout)) {
|
||||
@ -867,7 +983,7 @@ opt_measurements:
|
||||
;
|
||||
|
||||
measurements:
|
||||
meas
|
||||
unlabeled_meas /* @@@ hack */
|
||||
{
|
||||
*next_obj = $1;
|
||||
next_obj = &$1->next;
|
||||
@ -881,6 +997,22 @@ measurements:
|
||||
;
|
||||
|
||||
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
|
||||
{
|
||||
struct meas *meas;
|
||||
@ -889,33 +1021,63 @@ meas:
|
||||
meas = &$$->u.meas;
|
||||
meas->type = $4.max ? $1+3 : $1;
|
||||
meas->label = $2;
|
||||
$$->base = $3;
|
||||
$$->base = $3.vec;
|
||||
meas->low_qual = $3.qualifiers;
|
||||
meas->inverted = $4.inverted;
|
||||
meas->high = $5;
|
||||
meas->high = $5.vec;
|
||||
meas->high_qual = $5.qualifiers;
|
||||
meas->offset = $6;
|
||||
$$->next = NULL;
|
||||
}
|
||||
;
|
||||
|
||||
qbase:
|
||||
qbase_unchecked
|
||||
{
|
||||
$$ = $1;
|
||||
if (!check_qbase(&$$))
|
||||
YYABORT;
|
||||
}
|
||||
;
|
||||
|
||||
qbase_unchecked:
|
||||
ID
|
||||
{
|
||||
$$ = find_vec(frames, $1);
|
||||
if (!$$) {
|
||||
$$.vec = find_vec(frames, $1);
|
||||
if (!$$.vec) {
|
||||
yyerrorf("unknown vector \"%s\"", $1);
|
||||
YYABORT;
|
||||
}
|
||||
$$.qualifiers = NULL;
|
||||
}
|
||||
| ID '.' ID
|
||||
{
|
||||
const struct frame *frame;
|
||||
|
||||
frame = find_frame($1);
|
||||
$$ = frame ? find_vec(frame, $3) : NULL;
|
||||
if (!$$) {
|
||||
$$.vec = frame ? find_vec(frame, $3) : NULL;
|
||||
if (!$$.vec) {
|
||||
yyerrorf("unknown vector \"%s.%s\"", $1, $3);
|
||||
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;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
|
33
gui_meas.c
33
gui_meas.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* gui_meas.c - GUI, measurements
|
||||
*
|
||||
* Written 2009 by Werner Almesberger
|
||||
* Copyright 2009 by Werner Almesberger
|
||||
* Written 2009, 2010 by Werner Almesberger
|
||||
* Copyright 2009, 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
|
||||
@ -61,43 +61,43 @@ static struct meas_dsc meas_dsc_y = {
|
||||
|
||||
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]);
|
||||
return coord_eq(inst->u.vec.end, min);
|
||||
min = meas_find_min(lt, active_pkg->samples[inst->vec->n], NULL);
|
||||
return coord_eq(inst->u.vec.end, min->pos);
|
||||
}
|
||||
|
||||
|
||||
static int is_next(lt_op_type lt,
|
||||
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],
|
||||
ref->u.vec.end);
|
||||
return coord_eq(inst->u.vec.end, next);
|
||||
ref->u.vec.end, NULL);
|
||||
return coord_eq(inst->u.vec.end, next->pos);
|
||||
}
|
||||
|
||||
|
||||
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]);
|
||||
return coord_eq(inst->u.vec.end, max);
|
||||
max = meas_find_max(lt, active_pkg->samples[inst->vec->n], NULL);
|
||||
return coord_eq(inst->u.vec.end, max->pos);
|
||||
}
|
||||
|
||||
|
||||
static int is_a_next(lt_op_type lt, struct inst *inst)
|
||||
{
|
||||
struct inst *a;
|
||||
struct coord min, next;
|
||||
const struct sample *min, *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],
|
||||
min);
|
||||
if (coord_eq(next, inst->u.vec.end))
|
||||
min->pos, NULL);
|
||||
if (coord_eq(next->pos, inst->u.vec.end))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@ -309,6 +309,9 @@ static int end_new_meas(struct inst *from, struct inst *to)
|
||||
(mode == min_to_next_or_max);
|
||||
meas->offset = NULL;
|
||||
meas_dsc = NULL;
|
||||
/* we don't support qualifiers through the GUI yet */
|
||||
meas->low_qual = NULL;
|
||||
meas->high_qual = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
20
inst.c
20
inst.c
@ -35,7 +35,7 @@
|
||||
struct inst *selected_inst = NULL;
|
||||
struct bbox active_frame_bbox;
|
||||
struct pkg *pkgs, *active_pkg, *curr_pkg;
|
||||
struct inst *curr_frame = NULL;
|
||||
struct inst *frame_instantiating = NULL;
|
||||
|
||||
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)
|
||||
{
|
||||
struct inst *frame =
|
||||
curr_frame ? curr_frame : curr_pkg->insts[ip_frame];
|
||||
struct inst *frame = frame_instantiating ?
|
||||
frame_instantiating : curr_pkg->insts[ip_frame];
|
||||
|
||||
update_bbox(&frame->bbox, inst->bbox.min);
|
||||
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->obj = NULL;
|
||||
inst->base = inst->bbox.min = inst->bbox.max = base;
|
||||
inst->outer = curr_frame;
|
||||
inst->outer = frame_instantiating;
|
||||
inst->active = IS_ACTIVE;
|
||||
inst->next = NULL;
|
||||
*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;
|
||||
|
||||
@ -1151,16 +1151,16 @@ void inst_begin_frame(struct obj *obj, struct frame *frame,
|
||||
inst->u.frame.active = is_active_frame;
|
||||
inst->active = active;
|
||||
find_inst(inst);
|
||||
curr_frame = inst;
|
||||
frame_instantiating = inst;
|
||||
}
|
||||
|
||||
|
||||
void inst_end_frame(const struct frame *frame)
|
||||
{
|
||||
struct inst *inst = curr_frame;
|
||||
struct inst *inst = frame_instantiating;
|
||||
|
||||
curr_frame = curr_frame->outer;
|
||||
if (curr_frame)
|
||||
frame_instantiating = frame_instantiating->outer;
|
||||
if (frame_instantiating)
|
||||
propagate_bbox(inst);
|
||||
if (inst->u.frame.active && frame == active_frame)
|
||||
active_frame_bbox = inst->bbox;
|
||||
@ -1245,7 +1245,7 @@ void inst_start(void)
|
||||
pkgs = NULL;
|
||||
inst_select_pkg(NULL);
|
||||
curr_pkg = pkgs;
|
||||
curr_frame = NULL;
|
||||
frame_instantiating = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
5
inst.h
5
inst.h
@ -137,9 +137,9 @@ extern struct bbox active_frame_bbox;
|
||||
|
||||
/*
|
||||
* frame being instantiated - we need to export this one for meas.c, so that
|
||||
* measurement scan 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
|
||||
@ -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_arc(struct obj *obj, struct coord center, struct coord start,
|
||||
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);
|
||||
void inst_meas_hint(struct obj *obj, unit_type offset);
|
||||
|
||||
|
100
meas.c
100
meas.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* meas.c - Measurements
|
||||
*
|
||||
* Written 2009 by Werner Almesberger
|
||||
* Copyright 2009 by Werner Almesberger
|
||||
* Written 2009, 2010 by Werner Almesberger
|
||||
* Copyright 2009, 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
|
||||
@ -35,6 +35,7 @@ void reset_samples(struct sample **samples, int n)
|
||||
for (i = 0; i != n; i++)
|
||||
while (samples[i]) {
|
||||
next = samples[i]->next;
|
||||
bitset_free(samples[i]->frame_set);
|
||||
free(samples[i]);
|
||||
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;
|
||||
|
||||
@ -64,11 +66,18 @@ void meas_post(const struct vec *vec, struct coord pos)
|
||||
continue;
|
||||
if (pos.x < (*walk)->pos.x)
|
||||
break;
|
||||
if (pos.x == (*walk)->pos.x)
|
||||
if (pos.x != (*walk)->pos.x)
|
||||
continue;
|
||||
if (bitset_ge((*walk)->frame_set, frame_set))
|
||||
return;
|
||||
if (bitset_ge(frame_set, (*walk)->frame_set)) {
|
||||
bitset_or((*walk)->frame_set, frame_set);
|
||||
return;
|
||||
}
|
||||
}
|
||||
new = alloc_type(struct sample);
|
||||
new->pos = pos;
|
||||
new->frame_set = bitset_clone(frame_set);
|
||||
new->next = *walk;
|
||||
*walk = new;
|
||||
}
|
||||
@ -177,45 +186,47 @@ static int better_next(lt_op_type lt,
|
||||
* 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) {
|
||||
if (lt(s->pos, min) ||
|
||||
(!lt(min, s->pos) && lt_xy(s->pos, min)))
|
||||
min = s->pos;
|
||||
if (!qual || bitset_ge(s->frame_set, qual))
|
||||
if (!min || lt(s->pos, min->pos) ||
|
||||
(!lt(min->pos, s->pos) && lt_xy(s->pos, min->pos)))
|
||||
min = s;
|
||||
s = s->next;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
|
||||
struct coord meas_find_next(lt_op_type lt, const struct sample *s,
|
||||
struct coord ref)
|
||||
const struct sample *meas_find_next(lt_op_type lt, const struct sample *s,
|
||||
struct coord ref, const struct bitset *qual)
|
||||
{
|
||||
struct coord next;
|
||||
const struct sample *next = NULL;
|
||||
|
||||
next = s->pos;
|
||||
while (s) {
|
||||
if (better_next(lt, ref, next, s->pos))
|
||||
next = s->pos;
|
||||
if (!qual || bitset_ge(s->frame_set, qual))
|
||||
if (!next || better_next(lt, ref, next->pos, s->pos))
|
||||
next = s;
|
||||
s = s->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) {
|
||||
if (lt(max, s->pos) ||
|
||||
(!lt(s->pos, max) && lt_xy(max, s->pos)))
|
||||
max = s->pos;
|
||||
if (!qual || bitset_ge(s->frame_set, qual))
|
||||
if (!max || lt(max->pos, s->pos) ||
|
||||
(!lt(s->pos, max->pos) && lt_xy(max->pos, s->pos)))
|
||||
max = s;
|
||||
s = s->next;
|
||||
}
|
||||
return max;
|
||||
@ -225,46 +236,73 @@ struct coord meas_find_max(lt_op_type lt, const struct sample *s)
|
||||
/* ----- 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;
|
||||
const struct meas *meas;
|
||||
struct coord a0, b0;
|
||||
struct bitset *set;
|
||||
const struct sample *a0, *b0;
|
||||
lt_op_type lt;
|
||||
|
||||
for (obj = frames->objs; obj; obj = obj->next) {
|
||||
if (obj->type != ot_meas)
|
||||
continue;
|
||||
meas = &obj->u.meas;
|
||||
|
||||
/* optimization. not really needed anymore. */
|
||||
if (!curr_pkg->samples[obj->base->n] ||
|
||||
!curr_pkg->samples[meas->high->n])
|
||||
continue;
|
||||
|
||||
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])
|
||||
b0 = meas_find_next(lt,
|
||||
curr_pkg->samples[meas->high->n], a0);
|
||||
curr_pkg->samples[meas->high->n], a0->pos, set);
|
||||
else
|
||||
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,
|
||||
meas->inverted ? b0 : a0, meas->inverted ? a0 : b0);
|
||||
meas->inverted ? b0->pos : a0->pos,
|
||||
meas->inverted ? a0->pos : b0->pos);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int instantiate_meas(void)
|
||||
int instantiate_meas(int n_frames)
|
||||
{
|
||||
struct pkg *pkg;
|
||||
|
||||
curr_frame = pkgs->insts[ip_frame];
|
||||
frame_instantiating = pkgs->insts[ip_frame];
|
||||
for (pkg = pkgs; pkg; pkg = pkg->next)
|
||||
if (pkg->name) {
|
||||
inst_select_pkg(pkg->name);
|
||||
if (!instantiate_meas_pkg())
|
||||
if (!instantiate_meas_pkg(n_frames))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
30
meas.h
30
meas.h
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* meas.h - Measurements
|
||||
*
|
||||
* Written 2009 by Werner Almesberger
|
||||
* Copyright 2009 by Werner Almesberger
|
||||
* Written 2009, 2010 by Werner Almesberger
|
||||
* Copyright 2009, 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
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
#include "coord.h"
|
||||
#include "expr.h"
|
||||
#include "bitset.h"
|
||||
|
||||
|
||||
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 obj;
|
||||
|
||||
struct frame_qual {
|
||||
const struct frame *frame;
|
||||
struct frame_qual *next;
|
||||
};
|
||||
|
||||
struct meas {
|
||||
enum meas_type {
|
||||
mt_xy_next,
|
||||
@ -39,10 +45,15 @@ struct meas {
|
||||
/* low is obj->base */
|
||||
struct vec *high;
|
||||
struct expr *offset;
|
||||
|
||||
/* frame qualifiers */
|
||||
struct frame_qual *low_qual;
|
||||
struct frame_qual *high_qual;
|
||||
};
|
||||
|
||||
struct sample {
|
||||
struct coord pos;
|
||||
struct bitset *frame_set;
|
||||
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_xy(struct coord a, struct coord b);
|
||||
|
||||
struct coord meas_find_min(lt_op_type lt, const struct sample *s);
|
||||
struct coord meas_find_next(lt_op_type lt, const struct sample *s,
|
||||
struct coord ref);
|
||||
struct coord meas_find_max(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);
|
||||
const struct sample *meas_find_next(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 meas_start(void);
|
||||
void meas_post(const struct vec *vec, struct coord pos);
|
||||
int instantiate_meas(void);
|
||||
void meas_post(const struct vec *vec, struct coord pos,
|
||||
const struct bitset *frame_set);
|
||||
int instantiate_meas(int n_frames);
|
||||
|
||||
#endif /* !MEAS_H */
|
||||
|
25
obj.c
25
obj.c
@ -18,6 +18,7 @@
|
||||
#include "util.h"
|
||||
#include "error.h"
|
||||
#include "expr.h"
|
||||
#include "bitset.h"
|
||||
#include "meas.h"
|
||||
#include "inst.h"
|
||||
#include "hole.h"
|
||||
@ -38,6 +39,9 @@ struct frame *active_frame = NULL;
|
||||
void *instantiation_error = NULL;
|
||||
|
||||
|
||||
static struct bitset *frame_set; /* frames visited in "call chain" */
|
||||
|
||||
|
||||
/* ----- Searching --------------------------------------------------------- */
|
||||
|
||||
|
||||
@ -181,7 +185,7 @@ static int generate_vecs(struct frame *frame, struct coord base)
|
||||
vec->pos.y += y.n;
|
||||
if (!inst_vec(vec, vec_base))
|
||||
goto error;
|
||||
meas_post(vec, vec->pos);
|
||||
meas_post(vec, vec->pos, frame_set);
|
||||
}
|
||||
return 1;
|
||||
|
||||
@ -399,9 +403,11 @@ static int generate_frame(struct frame *frame, struct coord base,
|
||||
inst_begin_frame(frame_ref, frame, base,
|
||||
active && parent == active_frame,
|
||||
active && frame == active_frame);
|
||||
bitset_set(frame_set, frame->n);
|
||||
frame->curr_parent = parent;
|
||||
ok = iterate_tables(frame, frame->tables, base, active);
|
||||
inst_end_frame(frame);
|
||||
bitset_clear(frame_set, frame->n);
|
||||
frame->curr_parent = NULL;
|
||||
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)
|
||||
{
|
||||
struct coord zero = { 0, 0 };
|
||||
int n_frames;
|
||||
int ok;
|
||||
|
||||
meas_start();
|
||||
inst_start();
|
||||
n_frames = enumerate_frames();
|
||||
frame_set = bitset_new(n_frames);
|
||||
instantiation_error = NULL;
|
||||
reset_all_loops();
|
||||
reset_found();
|
||||
@ -480,11 +500,12 @@ int instantiate(void)
|
||||
if (ok)
|
||||
ok = refine_layers();
|
||||
if (ok)
|
||||
ok = instantiate_meas();
|
||||
ok = instantiate_meas(n_frames);
|
||||
if (ok)
|
||||
inst_commit();
|
||||
else
|
||||
inst_revert();
|
||||
bitset_free(frame_set);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
5
obj.h
5
obj.h
@ -163,9 +163,12 @@ struct frame {
|
||||
/* generating and editing */
|
||||
struct obj *active_ref;
|
||||
|
||||
/* For searching */
|
||||
/* for searching */
|
||||
struct obj *found_ref; /* NULL if not found yet */
|
||||
|
||||
/* index into bit vector in samples */
|
||||
int n;
|
||||
|
||||
/* for dumping */
|
||||
int dumped;
|
||||
|
||||
|
@ -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
|
||||
FPED="$CWD_PREFIX/$FPED"
|
||||
fi
|
||||
|
54
test/dbg_meas
Executable file
54
test/dbg_meas
Executable 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
|
||||
|
||||
###############################################################################
|
@ -53,6 +53,7 @@ frame f {
|
||||
v: vec @(0mm, 0mm)
|
||||
}
|
||||
|
||||
frame f @
|
||||
meas f.v -> f.v
|
||||
|
||||
%del f
|
||||
@ -64,4 +65,29 @@ package "_"
|
||||
unit mm
|
||||
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
|
||||
|
||||
###############################################################################
|
||||
|
@ -48,6 +48,7 @@ fped_dump "delete vector: measurements disappear (other frame)" <<EOF
|
||||
frame f {
|
||||
v: vec @(0mm, 0mm)
|
||||
}
|
||||
frame f @
|
||||
meas f.v -> f.v
|
||||
%del f.v
|
||||
EOF
|
||||
@ -59,6 +60,7 @@ frame f {
|
||||
|
||||
package "_"
|
||||
unit mm
|
||||
frame f @
|
||||
EOF
|
||||
|
||||
###############################################################################
|
||||
|
231
test/meas_qual
Executable file
231
test/meas_qual
Executable 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
|
||||
|
||||
###############################################################################
|
@ -72,6 +72,7 @@ frame f {
|
||||
a: vec @(0mm, 0mm)
|
||||
b: vec @(1mm, 1mm)
|
||||
}
|
||||
frame f @
|
||||
meas f.a -> f.b
|
||||
EOF
|
||||
expect <<EOF
|
||||
@ -84,6 +85,7 @@ frame f {
|
||||
|
||||
package "_"
|
||||
unit mm
|
||||
frame f @
|
||||
meas f.a -> f.b
|
||||
EOF
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user