Date:2010-04-28 02:34:32 (9 years 1 month ago)
Author:werner
Commit:dbace0b2fa712088a3ccba662cad8e2e7f48872d
Message: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
Files: delete.c (3 diffs)
dump.c (3 diffs)
fpd.y (9 diffs)
gui.c (1 diff)
gui_frame.c (8 diffs)
gui_inst.c (1 diff)
gui_meas.c (1 diff)
inst.c (1 diff)
meas.c (1 diff)
obj.c (4 diffs)
obj.h (2 diffs)

Change Details

delete.c
177177
178178    delete_vecs_by_ref(vec->frame->vecs, vec);
179179    delete_objs_by_ref(&vec->frame->objs, vec);
180    delete_objs_by_ref(&root_frame->objs, vec); /* catch measurements */
180    /*
181     * Catch measurements. During final cleanup, we may operate on an empty
182     * list of frames, hence the test.
183     */
184    if (frames)
185        delete_objs_by_ref(&frames->objs, vec);
181186}
182187
183188
...... 
546551void delete_frame(struct frame *frame)
547552{
548553    struct deletion *del;
549
554    struct frame *walk;
550555    groups++;
551556
552557    del = new_deletion(dt_frame);
553558    del->u.frame.ref = frame;
554    del->u.frame.prev = frame->prev;
555
556    if (frame->next)
557        frame->next->prev = frame->prev;
558    if (frame->prev)
559        frame->prev->next = frame->next;
559    del->u.frame.prev = NULL;
560    for (walk = frames; walk != frame; walk = walk->next)
561        del->u.frame.prev = walk;
562    if (del->u.frame.prev)
563        del->u.frame.prev->next = frame->next;
560564    else
561        frames = frame->next;
565        frames = frame->next; /* hmm, deleting the root frame ? */
562566
563567    delete_references(frame);
564568}
...... 
573577        assert(frame->next == frames);
574578        frames = frame;
575579    }
576    frame->next->prev = frame;
577580}
578581
579582
dump.c
394394    const char *name;
395395
396396    name = base_name(base, NULL);
397    if (base->frame == root_frame)
397    if (base->frame == frames)
398398        return stralloc(name);
399399    return stralloc_printf("%s.%s", base->frame->name, name);
400400}
...... 
546546}
547547
548548
549static void reverse_frames(FILE *file, struct frame *last)
550{
551    if (last) {
552        reverse_frames(file, last->next);
553        dump_frame(file, last, "\t");
554    }
555}
556
557
549558int dump(FILE *file)
550559{
551560    struct frame *frame;
...... 
553562    fprintf(file, "%s\n", MACHINE_GENERATED);
554563    for (frame = frames; frame; frame = frame->next)
555564        frame->dumped = 0;
556    for (frame = frames; frame; frame = frame->next) {
557        if (!frame->name) {
558            fprintf(file, "package \"%s\"\n", pkg_name);
559            dump_unit(file);
560            dump_frame(file, frame, "");
561        } else {
562            dump_frame(file, frame, "\t");
563        }
564    }
565
566    reverse_frames(file, frames->next);
567    fprintf(file, "package \"%s\"\n", pkg_name);
568    dump_unit(file);
569    dump_frame(file, frames, "");
570
565571    fflush(file);
566572    return !ferror(file);
567573}
fpd.y
3535static struct table *curr_table;
3636static struct row *curr_row;
3737
38static struct frame *last_frame = NULL;
3938static struct vec *last_vec = NULL;
4039
4140static struct table **next_table;
...... 
5453{
5554    struct frame *f;
5655
57    for (f = frames; f; f = f->next)
56    for (f = frames->next; f; f = f->next)
5857        if (f->name == name)
5958            return f;
6059    return NULL;
...... 
210209                yyerrorf("a frame can't delete itself");
211210                return 0;
212211            }
213            if (last_frame == frame)
214                last_frame = frame->prev;
215212            delete_frame(frame);
216213            return 1;
217214        }
...... 
317314}
318315
319316
320static void append_root_frame(void)
321{
322    root_frame->prev = last_frame;
323    if (last_frame)
324        last_frame->next = root_frame;
325    else
326        frames = root_frame;
327}
328
329
330317%}
331318
332319
...... 
387374all:
388375    START_FPD
389376        {
390            root_frame = zalloc_type(struct frame);
391            set_frame(root_frame);
377            frames = zalloc_type(struct frame);
378            set_frame(frames);
392379            id_sin = unique("sin");
393380            id_cos = unique("cos");
394381            id_sqrt = unique("sqrt");
395382        }
396383        fpd
397        {
398            append_root_frame();
399        }
400384    | START_EXPR expr
401385        {
402386            expr_result = $2;
...... 
471455            curr_frame = zalloc_type(struct frame);
472456            curr_frame->name = $2;
473457            set_frame(curr_frame);
474            curr_frame->prev = last_frame;
475            if (last_frame)
476                last_frame->next = curr_frame;
477            else
478                frames = curr_frame;
479            last_frame = curr_frame;
458            curr_frame->next = frames->next;
459            frames->next = curr_frame;
480460        }
481461        opt_frame_items '}'
482462        {
483            set_frame(root_frame);
463            set_frame(frames);
484464        }
485465    ;
486466
...... 
535515debug_item:
536516    TOK_DBG_DEL ID
537517        {
538            append_root_frame();
539518            if (!dbg_delete(NULL, $2))
540519                YYABORT;
541520        }
542521    | TOK_DBG_DEL ID '.' ID
543522        {
544            append_root_frame();
545523            if (!dbg_delete($2, $4))
546524                YYABORT;
547525        }
...... 
562540        }
563541    | TOK_DBG_DUMP
564542        {
565            /*
566             * It's okay to do append the root frame multiple
567             * times. If more frames are added afterwards, they
568             * just replace the root frame until it gets appended a
569             * final time when parsing ends.
570             */
571            append_root_frame();
572543            if (!dump(stdout)) {
573544                perror("stdout");
574545                exit(1);
...... 
929900qbase:
930901    ID
931902        {
932            $$ = find_vec(root_frame, $1);
903            $$ = find_vec(frames, $1);
933904            if (!$$) {
934905                yyerrorf("unknown vector \"%s\"", $1);
935906                YYABORT;
gui.c
393393    gui_setup_style(root->window);
394394    init_canvas();
395395    edit_nothing();
396    select_frame(root_frame);
396    select_frame(frames);
397397    make_popups();
398398
399399    gtk_main();
gui_frame.c
114114
115115    new = zalloc_type(struct frame);
116116    new->name = unique("_");
117    new->next = parent;
118    new->prev = parent->prev;
119    if (parent->prev)
120        parent->prev->next = new;
121    else
122        frames = new;
123    parent->prev = new;
117    new->next = parent->next;
118    parent->next = new;
124119    change_world();
125120}
126121
...... 
129124{
130125    struct frame *frame = popup_data;
131126
132    assert(frame != root_frame);
127    assert(frame != frames);
133128    delete_frame(frame);
134129    if (active_frame == frame)
135        select_frame(root_frame);
130        select_frame(frames);
136131    change_world();
137132}
138133
...... 
166161{
167162    const struct frame *frame;
168163
169    for (frame = frames; frame; frame = frame->next)
170        if (frame->name && !strcmp(frame->name, "_"))
164    for (frame = frames->next; frame; frame = frame->next)
165        if (!strcmp(frame->name, "_"))
171166            return FALSE;
172167    return TRUE;
173168}
...... 
206201{
207202    gtk_widget_set_sensitive(
208203        gtk_item_factory_get_item(factory_frame, "/Delete frame"),
209        frame != root_frame);
204        frame != frames);
210205
211206    gtk_widget_set_sensitive(
212207        gtk_item_factory_get_item(factory_frame, "/Add frame"),
...... 
16381633
16391634    if (!is_id(s))
16401635        return 0;
1641    for (f = frames; f; f = f->next)
1642        if (f->name && !strcmp(f->name, s))
1636    for (f = frames->next; f; f = f->next)
1637        if (!strcmp(f->name, s))
16431638            return 0;
16441639    return 1;
16451640}
...... 
18181813    gtk_table_attach_defaults(GTK_TABLE(tab), packages, 1, 2, 0, 1);
18191814
18201815    n = 0;
1821    for (frame = root_frame; frame; frame = frame->prev) {
1816    for (frame = frames; frame; frame = frame->next) {
18221817        label = build_frame_label(frame);
18231818        gtk_table_attach_defaults(GTK_TABLE(tab), label,
18241819            0, 1, n*2+1, n*2+2);
...... 
18301825
18311826    wrap_width -= max_name_width+FRAME_AREA_MISC_WIDTH;
18321827    n = 0;
1833    for (frame = root_frame; frame; frame = frame->prev) {
1828    for (frame = frames; frame; frame = frame->next) {
18341829        refs = build_frame_refs(frame);
18351830        gtk_table_attach_defaults(GTK_TABLE(tab), refs,
18361831            1, 2, n*2+1, n*2+2);
...... 
18501845    }
18511846
18521847    if (!show_vars) {
1853        meas = build_meas(root_frame);
1848        meas = build_meas(frames);
18541849        gtk_table_attach_defaults(GTK_TABLE(tab), meas,
18551850            1, 2, n*2+2, n*2+3);
18561851    }
gui_inst.c
650650
651651    gc = self->u.frame.active ? gc_active_frame : gc_frame[get_mode(self)];
652652    draw_eye(gc, center, FRAME_EYE_R1, FRAME_EYE_R2);
653    if (!self->u.frame.ref->name)
653    if (self->u.frame.ref == frames)
654654        return;
655655    corner = translate(corner);
656656    corner.x -= FRAME_CLEARANCE;
gui_meas.c
277277        return 0;
278278    /* it's safe to pass "from" here, but we may change it later */
279279    obj = new_obj_unconnected(ot_meas, from);
280    connect_obj(root_frame, obj);
280    connect_obj(frames, obj);
281281    meas = &obj->u.meas;
282282    meas->label = NULL;
283283    switch (mode) {
inst.c
8282    if (inst->ops == &frame_ops && inst->u.frame.ref == active_frame)
8383        return 1;
8484    if (!inst->outer)
85        return active_frame == root_frame;
85        return active_frame == frames;
8686    return inst->outer->u.frame.ref == active_frame;
8787}
8888
meas.c
232232    struct coord a0, b0;
233233    lt_op_type lt;
234234
235    for (obj = root_frame->objs; obj; obj = obj->next) {
235    for (obj = frames->objs; obj; obj = obj->next) {
236236        if (obj->type != ot_meas)
237237            continue;
238238        meas = &obj->u.meas;
obj.c
3434
3535char *pkg_name = NULL;
3636struct frame *frames = NULL;
37struct frame *root_frame = NULL;
3837struct frame *active_frame = NULL;
3938void *instantiation_error = NULL;
4039
...... 
255254                goto error;
256255            break;
257256        case ot_meas:
258            assert(frame == root_frame);
257            assert(frame == frames);
259258            offset = eval_unit_default(obj->u.meas.offset, frame,
260259                DEFAULT_OFFSET);
261260            if (is_undef(offset))
...... 
278277    char *s;
279278    int ok;
280279
281    if (!frame->name) {
280    if (frame == frames) {
282281        s = expand(pkg_name, frame);
283282        inst_select_pkg(s);
284283        free(s);
...... 
471470    reset_found();
472471    found = 0;
473472    search_suspended = 0;
474    ok = generate_frame(root_frame, zero, NULL, NULL, 1);
473    ok = generate_frame(frames, zero, NULL, NULL, 1);
475474    if (ok && (find_vec || find_obj) && found)
476475        activate_found();
477476    find_vec = NULL;
obj.h
156156    struct vec *vecs;
157157    struct obj *objs;
158158    struct frame *next;
159    struct frame *prev; /* for the list of frames in the GUI */
160159
161160    /* used during generation */
162161    const struct frame *curr_parent;
...... 
236235};
237236
238237
239extern char *pkg_name;
240extern struct frame *frames;
241extern struct frame *root_frame;
238extern char *pkg_name; /* anonymous common package first */
239extern struct frame *frames; /* root frame first */
242240extern struct frame *active_frame;
243241extern void *instantiation_error;
244242

Archive Download the corresponding diff file

Branches:
master



interactive