X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=write_fluffy.c;h=3c870da41c5e69e1d1bf99d79cdedd5108fb558c;hb=323968fc088f953b2f435504c24686a73f200a6b;hp=e2d9aac8136c40b869b73851fe85d23445729884;hpb=3ed4fdd019f473d959409bd39d128435189108d4;p=cparser diff --git a/write_fluffy.c b/write_fluffy.c index e2d9aac..3c870da 100644 --- a/write_fluffy.c +++ b/write_fluffy.c @@ -131,28 +131,28 @@ static void write_function_type(const function_type_t *type) } fprintf(out, ") : "); - write_type(type->result_type); + write_type(type->return_type); fprintf(out, ")"); } 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: @@ -215,18 +215,18 @@ static void write_unary_expression(const unary_expression_t *expression) static void write_expression(const expression_t *expression) { - const const_t *constant; + const const_expression_t *constant; /* TODO */ - switch(expression->type) { + switch(expression->kind) { case EXPR_CONST: - constant = (const const_t*) expression; - if(is_type_integer(expression->datatype)) { - fprintf(out, "%d", constant->v.int_value); + constant = &expression->conste; + if(is_type_integer(expression->base.datatype)) { + fprintf(out, "%lld", constant->v.int_value); } else { fprintf(out, "%Lf", constant->v.float_value); } break; - case EXPR_UNARY: + EXPR_UNARY_CASES write_unary_expression((const unary_expression_t*) expression); break; default: @@ -234,15 +234,6 @@ static void write_expression(const expression_t *expression) } } -static void write_initializer(const initializer_t *initializer) -{ - if(initializer->type != INITIALIZER_VALUE) { - panic("list initializers not supported yet"); - } - - //write_expression(initializer->v.value); -} - static void write_enum(const symbol_t *symbol, const enum_type_t *type) { fprintf(out, "enum %s:\n", symbol->string); @@ -253,7 +244,7 @@ static void write_enum(const symbol_t *symbol, const enum_type_t *type) fprintf(out, "\t%s", entry->symbol->string); if(entry->init.initializer != NULL) { fprintf(out, " <- "); - write_initializer(entry->init.initializer); + write_expression(entry->init.enum_value); } fputc('\n', out); } @@ -307,27 +298,20 @@ static void write_function(const declaration_t *declaration) } fprintf(out, ")"); - const type_t *result_type = function_type->result_type; - if(result_type->type != TYPE_ATOMIC || - ((const atomic_type_t*) result_type)->atype != ATOMIC_TYPE_VOID) { + const type_t *return_type = function_type->return_type; + if(!is_type_atomic(return_type, ATOMIC_TYPE_VOID)) { fprintf(out, " : "); - write_type(result_type); + write_type(return_type); } 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 */ @@ -338,24 +322,26 @@ 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); } } /* write global variables */ declaration = unit->context.declarations; for( ; declaration != NULL; declaration = declaration->next) { + if(declaration->namespc != NAMESPACE_NORMAL) + continue; if(declaration->storage_class == STORAGE_CLASS_TYPEDEF || declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY) continue; type_t *type = declaration->type; - if(type->type == TYPE_FUNCTION) + if(type->kind == TYPE_FUNCTION) continue; write_variable(declaration); @@ -364,16 +350,16 @@ void write_fluffy_decls(const translation_unit_t *unit) /* write functions */ declaration = unit->context.declarations; for( ; declaration != NULL; declaration = declaration->next) { + if(declaration->namespc != NAMESPACE_NORMAL) + continue; if(declaration->storage_class == STORAGE_CLASS_TYPEDEF || declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY) continue; type_t *type = declaration->type; - if(type->type != TYPE_FUNCTION) + if(type->kind != TYPE_FUNCTION) continue; write_function(declaration); } - - //fclose(out); }