I thought there was a bug in frame ordering, but it turns out that it works

fine. Anyway, here's a new debug construct (%frame) and a bunch of new 
regression tests.

- fpd.y, fpd.l, README: added new directive %frame to link frames also to other
  frames than the current one (like in the GUI)
- gui_tool.h, gui_tool.c: export is_parent_of
- test/frame_ref: regression tests to ensure that frame order remains valid,
  even if we reference late from early frames



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5945 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2010-04-27 01:02:24 +00:00
parent 39fef16d1c
commit 82a12023cd
6 changed files with 233 additions and 3 deletions

6
README
View File

@ -590,6 +590,7 @@ most of which mimick the effect of GUI operations:
%del <identifier>
%move <identifier> [<number>] <identifier>
%frame <identifier> <qualified-base>
%print <expression>
%dump
%exit
@ -610,6 +611,11 @@ anchor index vec/frame line/rect/pad arc measurement
1 - second point end of arc high point
2 - - start of arc -
%frame creates a frame reference. Unlike "frame", the destination frame
can be different from the current frame. E.g., "%frame foo bar.a" would
add a reference to frame "foo" in frame "bar", rooted at vector "a". The
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.

2
fpd.l
View File

@ -127,6 +127,8 @@ SP [\t ]*
return TOK_DBG_DEL; }
<INITIAL>"%move" { BEGIN(NOKEYWORD);
return TOK_DBG_MOVE; }
<INITIAL>"%frame" { BEGIN(NOKEYWORD);
return TOK_DBG_FRAME; }
<INITIAL>"%print" { BEGIN(NOKEYWORD);
return TOK_DBG_PRINT; }
<INITIAL>"%dump" { BEGIN(NOKEYWORD);

81
fpd.y
View File

@ -234,6 +234,38 @@ static int dbg_move(const char *name, int anchor, const char *dest)
}
/*
* @@@ This is very similar to what we do in rule "obj". Consider merging.
*/
static int dbg_link_frame(const char *frame_name,
struct frame *base_frame, struct vec *base_vec)
{
struct frame *frame;
struct obj *obj;
frame = find_frame(frame_name);
if (!frame) {
yyerrorf("unknown frame \"%s\"", frame_name);
return 0;
}
/* this can only fail in %frame */
if (is_parent_of(frame, base_frame)) {
yyerrorf("frame \"%s\" is a parent of \"%s\"",
frame->name, base_frame->name);
return 0;
}
obj = new_obj(ot_frame);
obj->base = base_vec;
obj->frame = base_frame;
obj->u.frame.ref = frame;
connect_obj(base_frame, obj);
if (!frame->active_ref)
frame->active_ref = obj;
return 1;
}
static int dbg_print(const struct expr *expr)
{
const char *s;
@ -283,6 +315,10 @@ static void append_root_frame(void)
int inverted;
int max;
} mo;
struct {
struct frame *frame;
struct vec *vec;
} qvec;
};
@ -291,8 +327,8 @@ static void append_root_frame(void)
%token TOK_PAD TOK_RPAD TOK_HOLE TOK_RECT TOK_LINE TOK_CIRC TOK_ARC
%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_PRINT TOK_DBG_DUMP
%token TOK_DBG_EXIT TOK_DBG_TSORT
%token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_FRAME TOK_DBG_PRINT
%token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT
%token <num> NUMBER
%token <str> STRING
@ -306,10 +342,12 @@ static void append_root_frame(void)
%type <obj> object obj meas
%type <expr> expr opt_expr add_expr mult_expr unary_expr primary_expr
%type <num> opt_num
%type <frame> frame_qualifier
%type <str> opt_string
%type <pt> pad_type
%type <mt> meas_type
%type <mo> meas_op
%type <qvec> qualified_base
%%
@ -468,6 +506,11 @@ frame_item:
if (!dbg_move($2, $3.n, $4))
YYABORT;
}
| TOK_DBG_FRAME ID qualified_base
{
if (!dbg_link_frame($2, $3.frame, $3.vec))
YYABORT;
}
| TOK_DBG_PRINT expr
{
if (!dbg_print($2))
@ -672,6 +715,40 @@ base:
}
;
qualified_base:
base
{
$$.frame = curr_frame;
$$.vec = $1;
}
| frame_qualifier '@'
{
$$.frame = $1;
$$.vec = NULL;
}
| frame_qualifier ID
{
$$.frame = $1;
$$.vec = find_vec($1, $2);
if (!$$.vec) {
yyerrorf("unknown vector \"%s.%s\"",
$1->name, $2);
YYABORT;
}
}
;
frame_qualifier:
ID '.'
{
$$ = find_frame($1);
if (!$$) {
yyerrorf("unknown frame \"%s\"", $1);
YYABORT;
}
}
;
object:
obj
{

View File

@ -603,7 +603,7 @@ static struct tool_ops circ_ops = {
/* ----- frame helper ------------------------------------------------------ */
static int is_parent_of(const struct frame *p, const struct frame *c)
int is_parent_of(const struct frame *p, const struct frame *c)
{
const struct obj *obj;

View File

@ -62,6 +62,8 @@ void tool_redraw(void);
struct obj *new_obj_unconnected(enum obj_type type, struct inst *base);
void connect_obj(struct frame *frame, struct obj *obj);
int is_parent_of(const struct frame *p, const struct frame *c);
struct pix_buf *draw_move_line_common(struct inst *inst,
struct coord end, struct coord pos, int i);
struct pix_buf *drag_new_line(struct inst *from, struct coord to);

143
test/frame_ref Executable file
View File

@ -0,0 +1,143 @@
#!/bin/sh
. ./Common
###############################################################################
fped_dump "frame reference: with \"frame\" (origin)" <<EOF
frame f {}
frame f @
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame f {
}
package "_"
unit mm
frame f @
EOF
#------------------------------------------------------------------------------
fped_dump "frame reference: with \"%frame\" (current frame origin)" <<EOF
frame f {}
%frame f @
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame f {
}
package "_"
unit mm
frame f @
EOF
#------------------------------------------------------------------------------
fped_dump "frame reference: with \"%frame\" (current frame vector)" <<EOF
frame f {}
v: vec @(0mm, 0mm)
%frame f v
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame f {
}
package "_"
unit mm
v: vec @(0mm, 0mm)
frame f .
EOF
#------------------------------------------------------------------------------
fped_dump "frame reference: with \"%frame\" (other frame origin)" <<EOF
frame f {}
frame g {}
%frame f g.@
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame f {
}
frame g {
frame f @
}
package "_"
unit mm
EOF
#------------------------------------------------------------------------------
fped_dump "frame reference: with \"%frame\" (other frame base)" <<EOF
frame f {}
frame g {
v: vec @(0mm, 0mm)
}
%frame f g.v
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame f {
}
frame g {
v: vec @(0mm, 0mm)
frame f .
}
package "_"
unit mm
EOF
#------------------------------------------------------------------------------
fped_fail "frame reference: with \"%frame\" (cycle)" <<EOF
frame f {
}
frame g {
frame f @
}
%frame g f.@
EOF
expect <<EOF
8: frame "g" is a parent of "f" near "@"
EOF
#------------------------------------------------------------------------------
fped_dump "frame reference: with \"%frame\" (out-of-order)" <<EOF
frame f {
}
frame g {
}
%frame g f.@
EOF
expect <<EOF
/* MACHINE-GENERATED ! */
frame g {
}
frame f {
frame g @
}
package "_"
unit mm
EOF
###############################################################################