mirror of
git://projects.qi-hardware.com/fped.git
synced 2024-11-18 07:16:15 +02:00
Cleaned up the disgusting mess that was the list of frames. The changes:
- removed root_frame. "frames" now takes its place. - removed frame->prev. In those few cases where we need the previous frame (for deletion and dumping), we walk the list or recurse. - the list of frames is now in GUI order, not file order. - when reading the .fpd file, put the root frame first and leave it there. - instead of walking the frames list and excluding the root frame by testing frame->name, just start at frames->next - likewise, instead of testing !frame->name just use frame == frames git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5948 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
parent
ac535d6e03
commit
dbace0b2fa
23
delete.c
23
delete.c
@ -177,7 +177,12 @@ static void do_delete_vec(struct vec *vec)
|
|||||||
|
|
||||||
delete_vecs_by_ref(vec->frame->vecs, vec);
|
delete_vecs_by_ref(vec->frame->vecs, vec);
|
||||||
delete_objs_by_ref(&vec->frame->objs, vec);
|
delete_objs_by_ref(&vec->frame->objs, vec);
|
||||||
delete_objs_by_ref(&root_frame->objs, vec); /* catch measurements */
|
/*
|
||||||
|
* Catch measurements. During final cleanup, we may operate on an empty
|
||||||
|
* list of frames, hence the test.
|
||||||
|
*/
|
||||||
|
if (frames)
|
||||||
|
delete_objs_by_ref(&frames->objs, vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -546,19 +551,18 @@ static void delete_references(const struct frame *ref)
|
|||||||
void delete_frame(struct frame *frame)
|
void delete_frame(struct frame *frame)
|
||||||
{
|
{
|
||||||
struct deletion *del;
|
struct deletion *del;
|
||||||
|
struct frame *walk;
|
||||||
groups++;
|
groups++;
|
||||||
|
|
||||||
del = new_deletion(dt_frame);
|
del = new_deletion(dt_frame);
|
||||||
del->u.frame.ref = frame;
|
del->u.frame.ref = frame;
|
||||||
del->u.frame.prev = frame->prev;
|
del->u.frame.prev = NULL;
|
||||||
|
for (walk = frames; walk != frame; walk = walk->next)
|
||||||
if (frame->next)
|
del->u.frame.prev = walk;
|
||||||
frame->next->prev = frame->prev;
|
if (del->u.frame.prev)
|
||||||
if (frame->prev)
|
del->u.frame.prev->next = frame->next;
|
||||||
frame->prev->next = frame->next;
|
|
||||||
else
|
else
|
||||||
frames = frame->next;
|
frames = frame->next; /* hmm, deleting the root frame ? */
|
||||||
|
|
||||||
delete_references(frame);
|
delete_references(frame);
|
||||||
}
|
}
|
||||||
@ -573,7 +577,6 @@ static void undelete_frame(struct frame *frame, struct frame *prev)
|
|||||||
assert(frame->next == frames);
|
assert(frame->next == frames);
|
||||||
frames = frame;
|
frames = frame;
|
||||||
}
|
}
|
||||||
frame->next->prev = frame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
22
dump.c
22
dump.c
@ -394,7 +394,7 @@ static char *print_meas_base(struct vec *base)
|
|||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
name = base_name(base, NULL);
|
name = base_name(base, NULL);
|
||||||
if (base->frame == root_frame)
|
if (base->frame == frames)
|
||||||
return stralloc(name);
|
return stralloc(name);
|
||||||
return stralloc_printf("%s.%s", base->frame->name, name);
|
return stralloc_printf("%s.%s", base->frame->name, name);
|
||||||
}
|
}
|
||||||
@ -546,6 +546,15 @@ static void dump_unit(FILE *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void reverse_frames(FILE *file, struct frame *last)
|
||||||
|
{
|
||||||
|
if (last) {
|
||||||
|
reverse_frames(file, last->next);
|
||||||
|
dump_frame(file, last, "\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int dump(FILE *file)
|
int dump(FILE *file)
|
||||||
{
|
{
|
||||||
struct frame *frame;
|
struct frame *frame;
|
||||||
@ -553,15 +562,12 @@ int dump(FILE *file)
|
|||||||
fprintf(file, "%s\n", MACHINE_GENERATED);
|
fprintf(file, "%s\n", MACHINE_GENERATED);
|
||||||
for (frame = frames; frame; frame = frame->next)
|
for (frame = frames; frame; frame = frame->next)
|
||||||
frame->dumped = 0;
|
frame->dumped = 0;
|
||||||
for (frame = frames; frame; frame = frame->next) {
|
|
||||||
if (!frame->name) {
|
reverse_frames(file, frames->next);
|
||||||
fprintf(file, "package \"%s\"\n", pkg_name);
|
fprintf(file, "package \"%s\"\n", pkg_name);
|
||||||
dump_unit(file);
|
dump_unit(file);
|
||||||
dump_frame(file, frame, "");
|
dump_frame(file, frames, "");
|
||||||
} else {
|
|
||||||
dump_frame(file, frame, "\t");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fflush(file);
|
fflush(file);
|
||||||
return !ferror(file);
|
return !ferror(file);
|
||||||
}
|
}
|
||||||
|
43
fpd.y
43
fpd.y
@ -35,7 +35,6 @@ static struct frame *curr_frame;
|
|||||||
static struct table *curr_table;
|
static struct table *curr_table;
|
||||||
static struct row *curr_row;
|
static struct row *curr_row;
|
||||||
|
|
||||||
static struct frame *last_frame = NULL;
|
|
||||||
static struct vec *last_vec = NULL;
|
static struct vec *last_vec = NULL;
|
||||||
|
|
||||||
static struct table **next_table;
|
static struct table **next_table;
|
||||||
@ -54,7 +53,7 @@ static struct frame *find_frame(const char *name)
|
|||||||
{
|
{
|
||||||
struct frame *f;
|
struct frame *f;
|
||||||
|
|
||||||
for (f = frames; f; f = f->next)
|
for (f = frames->next; f; f = f->next)
|
||||||
if (f->name == name)
|
if (f->name == name)
|
||||||
return f;
|
return f;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -210,8 +209,6 @@ static int dbg_delete(const char *frame_name, const char *name)
|
|||||||
yyerrorf("a frame can't delete itself");
|
yyerrorf("a frame can't delete itself");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (last_frame == frame)
|
|
||||||
last_frame = frame->prev;
|
|
||||||
delete_frame(frame);
|
delete_frame(frame);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -317,16 +314,6 @@ static int dbg_print(const struct expr *expr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void append_root_frame(void)
|
|
||||||
{
|
|
||||||
root_frame->prev = last_frame;
|
|
||||||
if (last_frame)
|
|
||||||
last_frame->next = root_frame;
|
|
||||||
else
|
|
||||||
frames = root_frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
@ -387,16 +374,13 @@ static void append_root_frame(void)
|
|||||||
all:
|
all:
|
||||||
START_FPD
|
START_FPD
|
||||||
{
|
{
|
||||||
root_frame = zalloc_type(struct frame);
|
frames = zalloc_type(struct frame);
|
||||||
set_frame(root_frame);
|
set_frame(frames);
|
||||||
id_sin = unique("sin");
|
id_sin = unique("sin");
|
||||||
id_cos = unique("cos");
|
id_cos = unique("cos");
|
||||||
id_sqrt = unique("sqrt");
|
id_sqrt = unique("sqrt");
|
||||||
}
|
}
|
||||||
fpd
|
fpd
|
||||||
{
|
|
||||||
append_root_frame();
|
|
||||||
}
|
|
||||||
| START_EXPR expr
|
| START_EXPR expr
|
||||||
{
|
{
|
||||||
expr_result = $2;
|
expr_result = $2;
|
||||||
@ -471,16 +455,12 @@ frame_def:
|
|||||||
curr_frame = zalloc_type(struct frame);
|
curr_frame = zalloc_type(struct frame);
|
||||||
curr_frame->name = $2;
|
curr_frame->name = $2;
|
||||||
set_frame(curr_frame);
|
set_frame(curr_frame);
|
||||||
curr_frame->prev = last_frame;
|
curr_frame->next = frames->next;
|
||||||
if (last_frame)
|
frames->next = curr_frame;
|
||||||
last_frame->next = curr_frame;
|
|
||||||
else
|
|
||||||
frames = curr_frame;
|
|
||||||
last_frame = curr_frame;
|
|
||||||
}
|
}
|
||||||
opt_frame_items '}'
|
opt_frame_items '}'
|
||||||
{
|
{
|
||||||
set_frame(root_frame);
|
set_frame(frames);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -535,13 +515,11 @@ frame_item:
|
|||||||
debug_item:
|
debug_item:
|
||||||
TOK_DBG_DEL ID
|
TOK_DBG_DEL ID
|
||||||
{
|
{
|
||||||
append_root_frame();
|
|
||||||
if (!dbg_delete(NULL, $2))
|
if (!dbg_delete(NULL, $2))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
}
|
}
|
||||||
| TOK_DBG_DEL ID '.' ID
|
| TOK_DBG_DEL ID '.' ID
|
||||||
{
|
{
|
||||||
append_root_frame();
|
|
||||||
if (!dbg_delete($2, $4))
|
if (!dbg_delete($2, $4))
|
||||||
YYABORT;
|
YYABORT;
|
||||||
}
|
}
|
||||||
@ -562,13 +540,6 @@ debug_item:
|
|||||||
}
|
}
|
||||||
| TOK_DBG_DUMP
|
| TOK_DBG_DUMP
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* It's okay to do append the root frame multiple
|
|
||||||
* times. If more frames are added afterwards, they
|
|
||||||
* just replace the root frame until it gets appended a
|
|
||||||
* final time when parsing ends.
|
|
||||||
*/
|
|
||||||
append_root_frame();
|
|
||||||
if (!dump(stdout)) {
|
if (!dump(stdout)) {
|
||||||
perror("stdout");
|
perror("stdout");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -929,7 +900,7 @@ meas:
|
|||||||
qbase:
|
qbase:
|
||||||
ID
|
ID
|
||||||
{
|
{
|
||||||
$$ = find_vec(root_frame, $1);
|
$$ = find_vec(frames, $1);
|
||||||
if (!$$) {
|
if (!$$) {
|
||||||
yyerrorf("unknown vector \"%s\"", $1);
|
yyerrorf("unknown vector \"%s\"", $1);
|
||||||
YYABORT;
|
YYABORT;
|
||||||
|
2
gui.c
2
gui.c
@ -393,7 +393,7 @@ int gui_main(void)
|
|||||||
gui_setup_style(root->window);
|
gui_setup_style(root->window);
|
||||||
init_canvas();
|
init_canvas();
|
||||||
edit_nothing();
|
edit_nothing();
|
||||||
select_frame(root_frame);
|
select_frame(frames);
|
||||||
make_popups();
|
make_popups();
|
||||||
|
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
29
gui_frame.c
29
gui_frame.c
@ -114,13 +114,8 @@ static void popup_add_frame(void)
|
|||||||
|
|
||||||
new = zalloc_type(struct frame);
|
new = zalloc_type(struct frame);
|
||||||
new->name = unique("_");
|
new->name = unique("_");
|
||||||
new->next = parent;
|
new->next = parent->next;
|
||||||
new->prev = parent->prev;
|
parent->next = new;
|
||||||
if (parent->prev)
|
|
||||||
parent->prev->next = new;
|
|
||||||
else
|
|
||||||
frames = new;
|
|
||||||
parent->prev = new;
|
|
||||||
change_world();
|
change_world();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,10 +124,10 @@ static void popup_del_frame(void)
|
|||||||
{
|
{
|
||||||
struct frame *frame = popup_data;
|
struct frame *frame = popup_data;
|
||||||
|
|
||||||
assert(frame != root_frame);
|
assert(frame != frames);
|
||||||
delete_frame(frame);
|
delete_frame(frame);
|
||||||
if (active_frame == frame)
|
if (active_frame == frame)
|
||||||
select_frame(root_frame);
|
select_frame(frames);
|
||||||
change_world();
|
change_world();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,8 +161,8 @@ static gboolean can_add_frame(void)
|
|||||||
{
|
{
|
||||||
const struct frame *frame;
|
const struct frame *frame;
|
||||||
|
|
||||||
for (frame = frames; frame; frame = frame->next)
|
for (frame = frames->next; frame; frame = frame->next)
|
||||||
if (frame->name && !strcmp(frame->name, "_"))
|
if (!strcmp(frame->name, "_"))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -206,7 +201,7 @@ static void pop_up_frame(struct frame *frame, GdkEventButton *event)
|
|||||||
{
|
{
|
||||||
gtk_widget_set_sensitive(
|
gtk_widget_set_sensitive(
|
||||||
gtk_item_factory_get_item(factory_frame, "/Delete frame"),
|
gtk_item_factory_get_item(factory_frame, "/Delete frame"),
|
||||||
frame != root_frame);
|
frame != frames);
|
||||||
|
|
||||||
gtk_widget_set_sensitive(
|
gtk_widget_set_sensitive(
|
||||||
gtk_item_factory_get_item(factory_frame, "/Add frame"),
|
gtk_item_factory_get_item(factory_frame, "/Add frame"),
|
||||||
@ -1638,8 +1633,8 @@ static int validate_frame_name(const char *s, void *ctx)
|
|||||||
|
|
||||||
if (!is_id(s))
|
if (!is_id(s))
|
||||||
return 0;
|
return 0;
|
||||||
for (f = frames; f; f = f->next)
|
for (f = frames->next; f; f = f->next)
|
||||||
if (f->name && !strcmp(f->name, s))
|
if (!strcmp(f->name, s))
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1818,7 +1813,7 @@ void build_frames(GtkWidget *vbox, int wrap_width)
|
|||||||
gtk_table_attach_defaults(GTK_TABLE(tab), packages, 1, 2, 0, 1);
|
gtk_table_attach_defaults(GTK_TABLE(tab), packages, 1, 2, 0, 1);
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for (frame = root_frame; frame; frame = frame->prev) {
|
for (frame = frames; frame; frame = frame->next) {
|
||||||
label = build_frame_label(frame);
|
label = build_frame_label(frame);
|
||||||
gtk_table_attach_defaults(GTK_TABLE(tab), label,
|
gtk_table_attach_defaults(GTK_TABLE(tab), label,
|
||||||
0, 1, n*2+1, n*2+2);
|
0, 1, n*2+1, n*2+2);
|
||||||
@ -1830,7 +1825,7 @@ void build_frames(GtkWidget *vbox, int wrap_width)
|
|||||||
|
|
||||||
wrap_width -= max_name_width+FRAME_AREA_MISC_WIDTH;
|
wrap_width -= max_name_width+FRAME_AREA_MISC_WIDTH;
|
||||||
n = 0;
|
n = 0;
|
||||||
for (frame = root_frame; frame; frame = frame->prev) {
|
for (frame = frames; frame; frame = frame->next) {
|
||||||
refs = build_frame_refs(frame);
|
refs = build_frame_refs(frame);
|
||||||
gtk_table_attach_defaults(GTK_TABLE(tab), refs,
|
gtk_table_attach_defaults(GTK_TABLE(tab), refs,
|
||||||
1, 2, n*2+1, n*2+2);
|
1, 2, n*2+1, n*2+2);
|
||||||
@ -1850,7 +1845,7 @@ void build_frames(GtkWidget *vbox, int wrap_width)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!show_vars) {
|
if (!show_vars) {
|
||||||
meas = build_meas(root_frame);
|
meas = build_meas(frames);
|
||||||
gtk_table_attach_defaults(GTK_TABLE(tab), meas,
|
gtk_table_attach_defaults(GTK_TABLE(tab), meas,
|
||||||
1, 2, n*2+2, n*2+3);
|
1, 2, n*2+2, n*2+3);
|
||||||
}
|
}
|
||||||
|
@ -650,7 +650,7 @@ void gui_draw_frame(struct inst *self)
|
|||||||
|
|
||||||
gc = self->u.frame.active ? gc_active_frame : gc_frame[get_mode(self)];
|
gc = self->u.frame.active ? gc_active_frame : gc_frame[get_mode(self)];
|
||||||
draw_eye(gc, center, FRAME_EYE_R1, FRAME_EYE_R2);
|
draw_eye(gc, center, FRAME_EYE_R1, FRAME_EYE_R2);
|
||||||
if (!self->u.frame.ref->name)
|
if (self->u.frame.ref == frames)
|
||||||
return;
|
return;
|
||||||
corner = translate(corner);
|
corner = translate(corner);
|
||||||
corner.x -= FRAME_CLEARANCE;
|
corner.x -= FRAME_CLEARANCE;
|
||||||
|
@ -277,7 +277,7 @@ static int end_new_meas(struct inst *from, struct inst *to)
|
|||||||
return 0;
|
return 0;
|
||||||
/* it's safe to pass "from" here, but we may change it later */
|
/* it's safe to pass "from" here, but we may change it later */
|
||||||
obj = new_obj_unconnected(ot_meas, from);
|
obj = new_obj_unconnected(ot_meas, from);
|
||||||
connect_obj(root_frame, obj);
|
connect_obj(frames, obj);
|
||||||
meas = &obj->u.meas;
|
meas = &obj->u.meas;
|
||||||
meas->label = NULL;
|
meas->label = NULL;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
2
inst.c
2
inst.c
@ -82,7 +82,7 @@ static int show_this(const struct inst *inst)
|
|||||||
if (inst->ops == &frame_ops && inst->u.frame.ref == active_frame)
|
if (inst->ops == &frame_ops && inst->u.frame.ref == active_frame)
|
||||||
return 1;
|
return 1;
|
||||||
if (!inst->outer)
|
if (!inst->outer)
|
||||||
return active_frame == root_frame;
|
return active_frame == frames;
|
||||||
return inst->outer->u.frame.ref == active_frame;
|
return inst->outer->u.frame.ref == active_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
meas.c
2
meas.c
@ -232,7 +232,7 @@ static int instantiate_meas_pkg(void)
|
|||||||
struct coord a0, b0;
|
struct coord a0, b0;
|
||||||
lt_op_type lt;
|
lt_op_type lt;
|
||||||
|
|
||||||
for (obj = root_frame->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;
|
||||||
|
7
obj.c
7
obj.c
@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
char *pkg_name = NULL;
|
char *pkg_name = NULL;
|
||||||
struct frame *frames = NULL;
|
struct frame *frames = NULL;
|
||||||
struct frame *root_frame = NULL;
|
|
||||||
struct frame *active_frame = NULL;
|
struct frame *active_frame = NULL;
|
||||||
void *instantiation_error = NULL;
|
void *instantiation_error = NULL;
|
||||||
|
|
||||||
@ -255,7 +254,7 @@ static int generate_objs(struct frame *frame, struct coord base, int active)
|
|||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case ot_meas:
|
case ot_meas:
|
||||||
assert(frame == root_frame);
|
assert(frame == frames);
|
||||||
offset = eval_unit_default(obj->u.meas.offset, frame,
|
offset = eval_unit_default(obj->u.meas.offset, frame,
|
||||||
DEFAULT_OFFSET);
|
DEFAULT_OFFSET);
|
||||||
if (is_undef(offset))
|
if (is_undef(offset))
|
||||||
@ -278,7 +277,7 @@ static int generate_items(struct frame *frame, struct coord base, int active)
|
|||||||
char *s;
|
char *s;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
if (!frame->name) {
|
if (frame == frames) {
|
||||||
s = expand(pkg_name, frame);
|
s = expand(pkg_name, frame);
|
||||||
inst_select_pkg(s);
|
inst_select_pkg(s);
|
||||||
free(s);
|
free(s);
|
||||||
@ -471,7 +470,7 @@ int instantiate(void)
|
|||||||
reset_found();
|
reset_found();
|
||||||
found = 0;
|
found = 0;
|
||||||
search_suspended = 0;
|
search_suspended = 0;
|
||||||
ok = generate_frame(root_frame, zero, NULL, NULL, 1);
|
ok = generate_frame(frames, zero, NULL, NULL, 1);
|
||||||
if (ok && (find_vec || find_obj) && found)
|
if (ok && (find_vec || find_obj) && found)
|
||||||
activate_found();
|
activate_found();
|
||||||
find_vec = NULL;
|
find_vec = NULL;
|
||||||
|
6
obj.h
6
obj.h
@ -156,7 +156,6 @@ struct frame {
|
|||||||
struct vec *vecs;
|
struct vec *vecs;
|
||||||
struct obj *objs;
|
struct obj *objs;
|
||||||
struct frame *next;
|
struct frame *next;
|
||||||
struct frame *prev; /* for the list of frames in the GUI */
|
|
||||||
|
|
||||||
/* used during generation */
|
/* used during generation */
|
||||||
const struct frame *curr_parent;
|
const struct frame *curr_parent;
|
||||||
@ -236,9 +235,8 @@ struct obj {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern char *pkg_name;
|
extern char *pkg_name; /* anonymous common package first */
|
||||||
extern struct frame *frames;
|
extern struct frame *frames; /* root frame first */
|
||||||
extern struct frame *root_frame;
|
|
||||||
extern struct frame *active_frame;
|
extern struct frame *active_frame;
|
||||||
extern void *instantiation_error;
|
extern void *instantiation_error;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user