1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-26 01:00:38 +02:00

Vector name generation could produce duplicates if vectors were moved or

deleted. The new algorithm checks for collisions and also reduces the number
of allocations.

- dump.c (generate_name): store the name in the vector being named
- dump.c (generate_name): compare the new name against all names in use
- dump.c (base_name, obj_base_name, print_label): don't allocate the name
- dump.c: changed all users of the above functions accordingly



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5715 99fdad57-331a-0410-800a-d7fa5415bdb3
This commit is contained in:
werner 2009-11-27 19:55:25 +00:00
parent 907bcf919b
commit 1daa0068d5
3 changed files with 43 additions and 42 deletions

79
dump.c
View File

@ -260,41 +260,51 @@ static void dump_loop(FILE *file, const struct loop *loop, const char *indent)
/* ----- vectors and objects ----------------------------------------------- */ /* ----- vectors and objects ----------------------------------------------- */
static char *generate_name(const struct vec *base) static void generate_name(struct vec *base)
{ {
const struct vec *walk; char tmp[10]; /* plenty */
int n; const char *s;
struct vec *walk;
int n = 0;
n = 0; while (1) {
for (walk = base->frame->vecs; walk != base; walk = walk->next) sprintf(tmp, "__%d", n);
s = unique(tmp);
for (walk = base->frame->vecs; walk; walk = walk->next)
if (walk->name == s)
break;
if (!walk)
break;
n++; n++;
return stralloc_printf("__%d", n); }
base->name = s;
} }
static char *base_name(const struct vec *base, const struct vec *next) static const char *base_name(struct vec *base, const struct vec *next)
{ {
if (!base) if (!base)
return stralloc("@"); return "@";
if (next && base->next == next) if (next && base->next == next)
return stralloc("."); return ".";
if (base->name) if (!base->name)
return stralloc(base->name); generate_name(base);
return generate_name(base); return base->name;
} }
static char *obj_base_name(const struct vec *base, const struct vec *prev) static const char *obj_base_name(struct vec *base, const struct vec *prev)
{ {
if (base && base == prev) if (base && base == prev)
return stralloc("."); return ".";
return base_name(base, NULL); return base_name(base, NULL);
} }
char *print_obj(const struct obj *obj, const struct vec *prev) char *print_obj(const struct obj *obj, const struct vec *prev)
{ {
char *base, *s, *s1, *s2, *s3; const char *base, *s1, *s3;
char *s, *s2;
base = obj_base_name(obj->base, prev); base = obj_base_name(obj->base, prev);
switch (obj->type) { switch (obj->type) {
@ -306,14 +316,12 @@ char *print_obj(const struct obj *obj, const struct vec *prev)
s1 = obj_base_name(obj->u.line.other, prev); s1 = obj_base_name(obj->u.line.other, prev);
s2 = unparse(obj->u.line.width); s2 = unparse(obj->u.line.width);
s = stralloc_printf("line %s %s %s", base, s1, s2); s = stralloc_printf("line %s %s %s", base, s1, s2);
free(s1);
free(s2); free(s2);
break; break;
case ot_rect: case ot_rect:
s1 = obj_base_name(obj->u.rect.other, prev); s1 = obj_base_name(obj->u.rect.other, prev);
s2 = unparse(obj->u.rect.width); s2 = unparse(obj->u.rect.width);
s = stralloc_printf("rect %s %s %s", base, s1, s2); s = stralloc_printf("rect %s %s %s", base, s1, s2);
free(s1);
free(s2); free(s2);
break; break;
case ot_pad: case ot_pad:
@ -337,26 +345,23 @@ char *print_obj(const struct obj *obj, const struct vec *prev)
s = stralloc_printf("%spad \"%s\" %s %s%s", s = stralloc_printf("%spad \"%s\" %s %s%s",
obj->u.pad.rounded ? "r" : "", obj->u.pad.rounded ? "r" : "",
obj->u.pad.name, base, s1, s2); obj->u.pad.name, base, s1, s2);
free(s1);
break; break;
case ot_arc: case ot_arc:
s1 = obj_base_name(obj->u.arc.start, prev); s1 = obj_base_name(obj->u.arc.start, prev);
s3 = unparse(obj->u.arc.width); s2 = unparse(obj->u.arc.width);
if (obj->u.arc.start == obj->u.arc.end) { if (obj->u.arc.start == obj->u.arc.end) {
s = stralloc_printf("circ %s %s %s", base, s1, s3); s = stralloc_printf("circ %s %s %s", base, s1, s2);
} else { } else {
s2 = obj_base_name(obj->u.arc.end, prev); s3 = obj_base_name(obj->u.arc.end, prev);
s = stralloc_printf("arc %s %s %s %s", s = stralloc_printf("arc %s %s %s %s",
base, s1, s2, s3); base, s1, s3, s2);
free(s2); free(s2);
} }
free(s1); free(s2);
free(s3);
break; break;
default: default:
abort(); abort();
} }
free(base);
return s; return s;
} }
@ -373,14 +378,12 @@ static const char *meas_type_name[mt_n] = {
static char *print_meas_base(struct vec *base) static char *print_meas_base(struct vec *base)
{ {
char *name, *res; const char *name;
name = base_name(base, NULL); name = base_name(base, NULL);
if (base->frame == root_frame) if (base->frame == root_frame)
return name; return stralloc(name);
res = stralloc_printf("%s.%s", base->frame->name, name); return stralloc_printf("%s.%s", base->frame->name, name);
free(name);
return res;
} }
@ -423,18 +426,18 @@ char *print_meas(const struct obj *obj)
/* ----- print vector ------------------------------------------------------ */ /* ----- print vector ------------------------------------------------------ */
char *print_label(const struct vec *vec) const char *print_label(struct vec *vec)
{ {
if (vec->name) if (!vec->name)
return stralloc(vec->name); generate_name(vec);
else return vec->name;
return generate_name(vec);
} }
char *print_vec(const struct vec *vec) char *print_vec(const struct vec *vec)
{ {
char *base, *x, *y, *s; const char *base;
char *x, *y, *s;
base = base_name(vec->base, vec); base = base_name(vec->base, vec);
x = unparse(vec->x); x = unparse(vec->x);
@ -444,7 +447,6 @@ char *print_vec(const struct vec *vec)
else { else {
s = stralloc_printf("vec %s(%s, %s)", base, x, y); s = stralloc_printf("vec %s(%s, %s)", base, x, y);
} }
free(base);
free(x); free(x);
free(y); free(y);
return s; return s;
@ -461,7 +463,8 @@ static void dump_frame(FILE *file, struct frame *frame, const char *indent)
struct obj *obj; struct obj *obj;
struct order *order; struct order *order;
const struct order *item; const struct order *item;
char *s, *s1; char *s;
const char *s1;
if (frame->dumped) if (frame->dumped)
return; return;

2
dump.h
View File

@ -34,7 +34,7 @@ struct order {
}; };
char *print_label(const struct vec *vec); const char *print_label(struct vec *vec);
char *print_vec(const struct vec *vec); char *print_vec(const struct vec *vec);
char *print_obj(const struct obj *obj, const struct vec *prev); char *print_obj(const struct obj *obj, const struct vec *prev);
char *print_meas(const struct obj *obj); char *print_meas(const struct obj *obj);

View File

@ -1167,9 +1167,7 @@ static GtkWidget *build_items(struct frame *frame)
label_in_box_fg(item->obj->list_widget, label_in_box_fg(item->obj->list_widget,
COLOR_ITEM_ERROR); COLOR_ITEM_ERROR);
} else { } else {
s = print_label(item->vec); t = stralloc_printf("%s: ", print_label(item->vec));
t = stralloc_printf("%s: ", s);
free(s);
item_label(tab, t, 0, n, NULL, NULL); item_label(tab, t, 0, n, NULL, NULL);
s = print_vec(item->vec); s = print_vec(item->vec);