#include "lang_features.h"
#include "entity_t.h"
#include "printer.h"
+#include "separator_t.h"
#include "types.h"
#include <assert.h>
{
print_expression_prec(call->function, PREC_POSTFIX);
print_char('(');
- char const *sep = "";
+ separator_t sep = { "", ", " };
for (call_argument_t const *arg = call->arguments; arg; arg = arg->next) {
- print_string(sep);
- sep = ", ";
+ print_string(sep_next(&sep));
print_assignment_expression(arg->expression);
}
print_char(')');
*/
static void print_asm_arguments(asm_argument_t *arguments)
{
+ separator_t sep = { "", ", " };
asm_argument_t *argument = arguments;
for (; argument != NULL; argument = argument->next) {
- if (argument != arguments)
- print_string(", ");
-
+ print_string(sep_next(&sep));
if (argument->symbol) {
print_format("[%s] ", argument->symbol->string);
}
*/
static void print_asm_clobbers(asm_clobber_t *clobbers)
{
+ separator_t sep = { "", ", " };
asm_clobber_t *clobber = clobbers;
for (; clobber != NULL; clobber = clobber->next) {
- if (clobber != clobbers)
- print_string(", ");
-
+ print_string(sep_next(&sep));
print_quoted_string(&clobber->clobber, '"');
}
}
decl_modifiers_t modifiers = declaration->modifiers;
- bool ds_shown = false;
- const char *next = "(";
+ separator_t sep = { "__declspec(", ", " };
if (declaration->base.kind == ENTITY_VARIABLE) {
variable_t *variable = (variable_t*)declaration;
if (variable->alignment != 0
|| variable->get_property_sym != NULL
|| variable->put_property_sym != NULL) {
- if (!ds_shown) {
- print_string("__declspec");
- ds_shown = true;
- }
-
if (variable->alignment != 0) {
- print_string(next); next = ", "; print_format("align(%u)", variable->alignment);
+ print_format("%salign(%u)", sep_next(&sep), variable->alignment);
}
if (variable->get_property_sym != NULL
|| variable->put_property_sym != NULL) {
char *comma = "";
- print_string(next); next = ", "; print_string("property(");
+ print_format("%sproperty(", sep_next(&sep));
if (variable->get_property_sym != NULL) {
print_format("get=%s", variable->get_property_sym->string);
comma = ", ";
/* DM_FORCEINLINE handled outside. */
if ((modifiers & ~DM_FORCEINLINE) != 0) {
- if (!ds_shown) {
- print_string("__declspec");
- ds_shown = true;
- }
if (modifiers & DM_DLLIMPORT) {
- print_string(next); next = ", "; print_string("dllimport");
+ print_format("%sdllimport", sep_next(&sep));
}
if (modifiers & DM_DLLEXPORT) {
- print_string(next); next = ", "; print_string("dllexport");
+ print_format("%sdllexport", sep_next(&sep));
}
if (modifiers & DM_THREAD) {
- print_string(next); next = ", "; print_string("thread");
+ print_format("%sthread", sep_next(&sep));
}
if (modifiers & DM_NAKED) {
- print_string(next); next = ", "; print_string("naked");
+ print_format("%snaked", sep_next(&sep));
}
if (modifiers & DM_THREAD) {
- print_string(next); next = ", "; print_string("thread");
+ print_format("%sthread", sep_next(&sep));
}
if (modifiers & DM_SELECTANY) {
- print_string(next); next = ", "; print_string("selectany");
+ print_format("%sselectany", sep_next(&sep));
}
if (modifiers & DM_NOTHROW) {
- print_string(next); next = ", "; print_string("nothrow");
+ print_format("%snothrow", sep_next(&sep));
}
if (modifiers & DM_NORETURN) {
- print_string(next); next = ", "; print_string("noreturn");
+ print_format("%snoreturn", sep_next(&sep));
}
if (modifiers & DM_NOINLINE) {
- print_string(next); next = ", "; print_string("noinline");
+ print_format("%snoinline", sep_next(&sep));
}
if (modifiers & DM_DEPRECATED) {
- print_string(next); next = ", "; print_string("deprecated");
+ print_format("%sdeprecated", sep_next(&sep));
if (declaration->deprecated_string != NULL)
print_format("(\"%s\")",
declaration->deprecated_string);
}
if (modifiers & DM_RESTRICT) {
- print_string(next); next = ", "; print_string("restrict");
+ print_format("%srestrict", sep_next(&sep));
}
if (modifiers & DM_NOALIAS) {
- print_string(next); next = ", "; print_string("noalias");
+ print_format("%snoalias", sep_next(&sep));
}
}
- if (ds_shown)
+ if (!sep_at_first(&sep))
print_string(") ");
}
#endif
#include "warning.h"
#include "diagnostic.h"
#include "printer.h"
+#include "separator_t.h"
/** The default calling convention. */
cc_kind_t default_calling_convention = CC_CDECL;
const scope_t *parameters)
{
print_char('(');
- bool first = true;
+ separator_t sep = { "", ", " };
if (parameters == NULL) {
function_parameter_t *parameter = type->parameters;
for( ; parameter != NULL; parameter = parameter->next) {
- if (first) {
- first = false;
- } else {
- print_string(", ");
- }
+ print_string(sep_next(&sep));
print_type(parameter->type);
}
} else {
if (parameter->kind != ENTITY_PARAMETER)
continue;
- if (first) {
- first = false;
- } else {
- print_string(", ");
- }
+ print_string(sep_next(&sep));
const type_t *const param_type = parameter->declaration.type;
if (param_type == NULL) {
print_string(parameter->base.symbol->string);
}
}
if (type->variadic) {
- if (first) {
- first = false;
- } else {
- print_string(", ");
- }
+ print_string(sep_next(&sep));
print_string("...");
}
- if (first && !type->unspecified_parameters) {
+ if (sep_at_first(&sep) && !type->unspecified_parameters) {
print_string("void");
}
print_char(')');
#include <string.h>
#include "write_fluffy.h"
+#include "separator_t.h"
#include "symbol_t.h"
#include "ast_t.h"
#include "type_t.h"
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) {
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, ", ");
- }
+ fputs(sep_next(&sep), out);
fputs("...", out);
}
fprintf(out, ")");
#include "adt/error.h"
#include "adt/xmalloc.h"
#include "adt/pset_new.h"
+#include "separator_t.h"
typedef struct output_limit {
const char *filename;
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, ", ");
- }
+ fputs(sep_next(&sep), out);
fputs("Object ... args", out);
}
fprintf(out, ");\n");