#include "printer.h"
#include "adt/error.h"
#include "adt/xmalloc.h"
-#include <libfirm/adt/pset_new.h>
+#include "adt/pset_new.h"
+#include "separator_t.h"
typedef struct output_limit {
const char *filename;
{
if (strstart(fname, "/usr/include"))
return true;
- if (fname == builtin_source_position.input_name)
+ if (fname == builtin_position.input_name)
return true;
return false;
}
case TYPE_ERROR:
case TYPE_TYPEOF:
case TYPE_TYPEDEF:
- panic("invalid type found");
+ panic("invalid type");
case TYPE_ARRAY:
case TYPE_REFERENCE:
case TYPE_FUNCTION:
write_expression(expression->value);
return;
default:
- panic("unimeplemented unary expression found");
+ panic("unimplemented unary expression");
}
write_expression(expression->value);
}
fputs(")", out);
}
+static void write_integer(const literal_expression_t *literal)
+{
+ for (const char *c = literal->value.begin; c != literal->suffix; ++c) {
+ fputc(*c, out);
+ }
+}
+
static void write_expression(const expression_t *expression)
{
/* TODO */
switch(expression->kind) {
case EXPR_LITERAL_INTEGER:
- case EXPR_LITERAL_INTEGER_OCTAL:
- fprintf(out, "%s", expression->literal.value.begin);
- break;
- case EXPR_LITERAL_INTEGER_HEXADECIMAL:
- fprintf(out, "0x%s", expression->literal.value.begin);
+ write_integer(&expression->literal);
break;
- case EXPR_REFERENCE_ENUM_VALUE: {
+
+ case EXPR_ENUM_CONSTANT: {
/* UHOH... hacking */
entity_t *entity = expression->reference.entity;
write_enum_name(& entity->enum_value.enum_type->enumt);
fprintf(out, ".%s.val", entity->base.symbol->string);
break;
}
- EXPR_UNARY_CASES
+ case EXPR_UNARY_CASES:
write_unary_expression(&expression->unary);
break;
- EXPR_BINARY_CASES
+ case EXPR_BINARY_CASES:
write_binary_expression(&expression->binary);
break;
default:
static void write_function(const entity_t *entity)
{
- if (entity->function.statement != NULL) {
+ if (entity->function.body != NULL) {
fprintf(stderr, "Warning: can't convert function bodies (at %s)\n",
entity->base.symbol->string);
return;
write_type(return_type);
fprintf(out, " %s(", entity->base.symbol->string);
- entity_t *parameter = entity->function.parameters.entities;
- int first = 1;
- int n = 0;
+ entity_t *parameter = entity->function.parameters.entities;
+ separator_t sep = { "", ", " };
+ int n = 0;
for ( ; parameter != NULL; parameter = parameter->base.next) {
assert(parameter->kind == ENTITY_PARAMETER);
- if(!first) {
- fprintf(out, ", ");
- } else {
- first = 0;
- }
+ fputs(sep_next(&sep), out);
write_type(parameter->declaration.type);
if(parameter->base.symbol != NULL) {
fprintf(out, " %s", fix_builtin_names(parameter->base.symbol->string));
}
}
if(function_type->variadic) {
- if(!first) {
- fprintf(out, ", ");
- } else {
- first = 0;
- }
+ fputs(sep_next(&sep), out);
fputs("Object ... args", out);
}
fprintf(out, ");\n");
}
#if 0
- if(type->kind == TYPE_COMPOUND_STRUCT
- || type->kind == TYPE_COMPOUND_UNION) {
+ if (is_type_compound(type)) {
write_compound(entity->base.symbol, &type->compound);
}
#endif
for ( ; entity != NULL; entity = entity->base.next) {
if (entity->kind != ENTITY_FUNCTION)
continue;
- const char *input_name = entity->base.source_position.input_name;
+ const char *input_name = entity->base.pos.input_name;
if (is_system_header(input_name))
continue;
if (entity->function.elf_visibility != ELF_VISIBILITY_DEFAULT)