X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=write_fluffy.c;h=bd979c37deb385b639f0e585ad5fe875a1865e3c;hb=bf31a06b276a73ea4dbe0b2099b60f43bda797ad;hp=c6463d030967f8a7a31eecb03a4969edc0596136;hpb=6fe9dcaa0774eaea804b563d5c7b6e656ce41734;p=cparser diff --git a/write_fluffy.c b/write_fluffy.c index c6463d0..bd979c3 100644 --- a/write_fluffy.c +++ b/write_fluffy.c @@ -14,7 +14,7 @@ static FILE *out; static void write_type(const type_t *type); -static const char *get_atomic_type_string(const atomic_type_type_t type) +static const char *get_atomic_type_string(const atomic_type_kind_t type) { switch(type) { case ATOMIC_TYPE_VOID: return "void"; @@ -39,7 +39,7 @@ static const char *get_atomic_type_string(const atomic_type_type_t type) static void write_atomic_type(const atomic_type_t *type) { - fprintf(out, "%s", get_atomic_type_string(type->atype)); + fprintf(out, "%s", get_atomic_type_string(type->akind)); } static void write_pointer_type(const pointer_type_t *type) @@ -137,22 +137,22 @@ static void write_function_type(const function_type_t *type) static void write_type(const type_t *type) { - switch(type->type) { + switch(type->kind) { case TYPE_ATOMIC: - write_atomic_type((const atomic_type_t*) type); + write_atomic_type(&type->atomic); return; case TYPE_POINTER: - write_pointer_type((const pointer_type_t*) type); + write_pointer_type(&type->pointer); return; case TYPE_COMPOUND_UNION: case TYPE_COMPOUND_STRUCT: - write_compound_type((const compound_type_t*) type); + write_compound_type(&type->compound); return; case TYPE_ENUM: - write_enum_type((const enum_type_t*) type); + write_enum_type(&type->enumt); return; case TYPE_FUNCTION: - write_function_type((const function_type_t*) type); + write_function_type(&type->function); return; case TYPE_INVALID: panic("invalid type found"); @@ -200,11 +200,11 @@ static void write_expression(const expression_t *expression); static void write_unary_expression(const unary_expression_t *expression) { - switch(expression->type) { - case UNEXPR_NEGATE: + switch(expression->expression.kind) { + case EXPR_UNARY_NEGATE: fputc('-', out); break; - case UNEXPR_NOT: + case EXPR_UNARY_NOT: fputc('!', out); break; default: @@ -217,7 +217,7 @@ static void write_expression(const expression_t *expression) { const const_expression_t *constant; /* TODO */ - switch(expression->type) { + switch(expression->kind) { case EXPR_CONST: constant = &expression->conste; if(is_type_integer(expression->base.datatype)) { @@ -226,7 +226,7 @@ static void write_expression(const expression_t *expression) fprintf(out, "%Lf", constant->v.float_value); } break; - case EXPR_UNARY: + EXPR_UNARY_CASES write_unary_expression((const unary_expression_t*) expression); break; default: @@ -306,18 +306,12 @@ static void write_function(const declaration_t *declaration) fputc('\n', out); } -void write_fluffy_decls(const translation_unit_t *unit) +void write_fluffy_decls(FILE *output, const translation_unit_t *unit) { -#if 0 - out = fopen("out.fluffy", "w"); - if(out == NULL) { - fprintf(stderr, "Couldn't open out.fluffy: %s\n", strerror(errno)); - exit(1); - } -#endif - out = stdout; + out = output; global_context = &unit->context; + ast_set_output(out); fprintf(out, "/* WARNING: Automatically generated file */\n"); /* write structs,unions + enums */ @@ -328,12 +322,12 @@ void write_fluffy_decls(const translation_unit_t *unit) continue; } type_t *type = declaration->type; - if(type->type == TYPE_COMPOUND_STRUCT) { - write_struct(declaration->symbol, (compound_type_t*) type); - } else if(type->type == TYPE_COMPOUND_UNION) { - write_union(declaration->symbol, (compound_type_t*) type); - } else if(type->type == TYPE_ENUM) { - write_enum(declaration->symbol, (enum_type_t*) type); + if(type->kind == TYPE_COMPOUND_STRUCT) { + write_struct(declaration->symbol, &type->compound); + } else if(type->kind == TYPE_COMPOUND_UNION) { + write_union(declaration->symbol, &type->compound); + } else if(type->kind == TYPE_ENUM) { + write_enum(declaration->symbol, &type->enumt); } } @@ -347,7 +341,7 @@ void write_fluffy_decls(const translation_unit_t *unit) continue; type_t *type = declaration->type; - if(type->type == TYPE_FUNCTION) + if(type->kind == TYPE_FUNCTION) continue; write_variable(declaration); @@ -363,11 +357,9 @@ void write_fluffy_decls(const translation_unit_t *unit) continue; type_t *type = declaration->type; - if(type->type != TYPE_FUNCTION) + if(type->kind != TYPE_FUNCTION) continue; write_function(declaration); } - - //fclose(out); }