1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 07:54:06 +02:00

separate dumping of hierchy rules from dumping of fields

With only one function, top-level fields definitions were printed in
a style as if they were rules and not fields.
This commit is contained in:
Werner Almesberger 2012-05-30 11:53:58 -03:00
parent e943baf1c3
commit b6a4a80652
3 changed files with 32 additions and 21 deletions

View File

@ -97,7 +97,7 @@ void field_finalize(struct field *field)
#define INDENT 8 #define INDENT 8
static void dump_fields(FILE *file, const struct field *field, int level); static void dump_rules(FILE *file, const struct field *field, int level);
static void dump_set_decl(FILE *file, const struct names *first_name) static void dump_set_decl(FILE *file, const struct names *first_name)
@ -127,23 +127,16 @@ static void dump_field_decl(FILE *file, const struct field *field)
static void dump_action(FILE *file, const struct action *act, int level) static void dump_action(FILE *file, const struct action *act, int level)
{ {
const struct field *field;
if (act->fields) { if (act->fields) {
fprintf(file, " {"); fprintf(file, " ");
for (field = act->fields; field; field = field->next) { fields_dump(file, act->fields);
fprintf(file, " %s=", field->name);
dump_field_decl(file, field);
} }
fprintf(file, " }\n");
} else {
fprintf(file, "\n"); fprintf(file, "\n");
} dump_rules(file, act->rules, level+1);
dump_fields(file, act->rules, level+1);
} }
static void dump_one_field(FILE *file, const struct field *field, int level) static void dump_one_rule(FILE *file, const struct field *field, int level)
{ {
const struct selector *sel; const struct selector *sel;
const struct condition *cond; const struct condition *cond;
@ -162,7 +155,7 @@ static void dump_one_field(FILE *file, const struct field *field, int level)
dump_relop(file, cond->relop); dump_relop(file, cond->relop);
dump(file, field->fmt, &cond->value); dump(file, field->fmt, &cond->value);
} }
fprintf(file, ": "); fprintf(file, ":");
dump_action(file, &sel->act, level); dump_action(file, &sel->act, level);
} }
if (field->any.fields || field->any.rules) { if (field->any.fields || field->any.rules) {
@ -173,16 +166,31 @@ static void dump_one_field(FILE *file, const struct field *field, int level)
} }
static void dump_fields(FILE *file, const struct field *field, int level) void fields_dump(FILE *file, const struct field *fields)
{
const struct field *f;
if (!fields)
return;
fprintf(file, "{ ");
for (f = fields; f; f = f->next) {
fprintf(file, "%s%s=", f == fields ? "" : " ", f->name);
dump_field_decl(file, f);
}
fprintf(file, " }");
}
static void dump_rules(FILE *file, const struct field *field, int level)
{ {
while (field) { while (field) {
dump_one_field(file, field, level); dump_one_rule(file, field, level);
field = field->next; field = field->next;
} }
} }
void field_dump(FILE *file, const struct field *field) void rules_dump(FILE *file, const struct field *field)
{ {
dump_fields(file, field, 0); dump_rules(file, field, 0);
} }

View File

@ -53,6 +53,7 @@ struct field *new_field(const char *name, const struct format *fmt,
struct selector *new_selector(void); struct selector *new_selector(void);
struct condition *new_condition(enum relop relop, const char *word); struct condition *new_condition(enum relop relop, const char *word);
void field_finalize(struct field *field); void field_finalize(struct field *field);
void field_dump(FILE *file, const struct field *field); void fields_dump(FILE *file, const struct field *field);
void rules_dump(FILE *file, const struct field *field);
#endif /* !CHR_H */ #endif /* !CHR_H */

View File

@ -156,8 +156,10 @@ hierarchy:
| action | action
{ {
$$ = $1; $$ = $1;
field_dump(stderr, $1.fields); fields_dump(stderr, $1.fields);
field_dump(stderr, $1.rules); if ($1.fields)
fprintf(stderr, "\n");
rules_dump(stderr, $1.rules);
} }
; ;