}
fprintf(out, ") : ");
- write_type(type->result_type);
+ write_type(type->return_type);
fprintf(out, ")");
}
static void write_unary_expression(const unary_expression_t *expression)
{
- switch(expression->type) {
- case UNEXPR_NEGATE:
+ switch(expression->expression.type) {
+ case EXPR_UNARY_NEGATE:
fputc('-', out);
break;
- case UNEXPR_NOT:
+ case EXPR_UNARY_NOT:
fputc('!', out);
break;
default:
static void write_expression(const expression_t *expression)
{
- const const_t *constant;
+ const const_expression_t *constant;
/* TODO */
switch(expression->type) {
case EXPR_CONST:
- constant = (const const_t*) expression;
- if(is_type_integer(expression->datatype)) {
+ 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:
}
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 */
write_function(declaration);
}
-
- //fclose(out);
}