/*
* This file is part of cparser.
- * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
*/
#include <config.h>
-#include <errno.h>
-#include <string.h>
-
#include "write_fluffy.h"
+#include "separator_t.h"
#include "symbol_t.h"
#include "ast_t.h"
#include "type_t.h"
case ATOMIC_TYPE_CHAR: return "byte";
case ATOMIC_TYPE_SCHAR: return "byte";
case ATOMIC_TYPE_UCHAR: return "unsigned byte";
- case ATOMIC_TYPE_SHORT: return "short";
+ case ATOMIC_TYPE_SHORT: return "short";
case ATOMIC_TYPE_USHORT: return "unsigned short";
case ATOMIC_TYPE_INT: return "int";
case ATOMIC_TYPE_UINT: return "unsigned int";
fprintf(out, "(func(");
function_parameter_t *parameter = type->parameters;
- int first = 1;
+ separator_t sep = { "", ", " };
while(parameter != NULL) {
- if(!first) {
- fprintf(out, ", ");
- } else {
- first = 0;
- }
+ fputs(sep_next(&sep), out);
#if 0
if(parameter->symbol != NULL) {
case TYPE_FUNCTION:
write_function_type(&type->function);
return;
- case TYPE_INVALID:
- panic("invalid type found");
case TYPE_COMPLEX:
case TYPE_IMAGINARY:
default:
fputc('!', out);
break;
default:
- panic("unimeplemented unary expression found");
+ panic("unimplemented unary expression");
}
write_expression(expression->value);
}
case EXPR_LITERAL_INTEGER:
fprintf(out, "%s", expression->literal.value.begin);
break;
- EXPR_UNARY_CASES
+ case EXPR_UNARY_CASES:
write_unary_expression((const unary_expression_t*) expression);
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);
}
const function_type_t *function_type
= (const function_type_t*) entity->declaration.type;
- entity_t *parameter = entity->function.parameters.entities;
- int first = 1;
+ entity_t *parameter = entity->function.parameters.entities;
+ separator_t sep = { "", ", " };
for( ; parameter != NULL; parameter = parameter->base.next) {
assert(parameter->kind == ENTITY_PARAMETER);
- if(!first) {
- fprintf(out, ", ");
- } else {
- first = 0;
- }
+ fputs(sep_next(&sep), out);
if(parameter->base.symbol != NULL) {
fprintf(out, "%s : ", parameter->base.symbol->string);
} else {
write_type(parameter->declaration.type);
}
if(function_type->variadic) {
- if(!first) {
- fprintf(out, ", ");
- } else {
- first = 0;
- }
+ fputs(sep_next(&sep), out);
fputs("...", out);
}
fprintf(out, ")");
const type_t *return_type = skip_typeref(function_type->return_type);
- if(!is_type_atomic(return_type, ATOMIC_TYPE_VOID)) {
+ if (!is_type_void(return_type)) {
fprintf(out, " : ");
write_type(return_type);
}
continue;
type_t *type = entity->typedefe.type;
- if(type->kind == TYPE_COMPOUND_STRUCT
- || type->kind == TYPE_COMPOUND_UNION) {
+ if (is_type_compound(type)) {
write_compound(entity->base.symbol, &type->compound);
} else if(type->kind == TYPE_ENUM) {
write_enum(entity->base.symbol, &type->enumt);