[EXPR_UNKNOWN] = PREC_PRIM,
[EXPR_INVALID] = PREC_PRIM,
[EXPR_REFERENCE] = PREC_PRIM,
+ [EXPR_CHAR_CONST] = PREC_PRIM,
[EXPR_CONST] = PREC_PRIM,
[EXPR_STRING_LITERAL] = PREC_PRIM,
[EXPR_WIDE_STRING_LITERAL] = PREC_PRIM,
if(cnst->base.type == NULL)
return;
- if(is_type_integer(cnst->base.type)) {
+ const type_t *const type = skip_typeref(cnst->base.type);
+
+ if (is_type_integer(type)) {
fprintf(out, "%lld", cnst->v.int_value);
- } else if(is_type_float(cnst->base.type)) {
+ } else if (is_type_float(type)) {
fprintf(out, "%Lf", cnst->v.float_value);
+ } else {
+ panic("unknown constant");
}
}
* Print a quoted string constant.
*
* @param string the string constant
+ * @param border the border char
*/
-static void print_quoted_string(const string_t *const string)
+static void print_quoted_string(const string_t *const string, char border)
{
- fputc('"', out);
+ fputc(border, out);
const char *end = string->begin + string->size;
for (const char *c = string->begin; c != end; ++c) {
+ if (*c == border) {
+ fputc('\\', out);
+ }
switch(*c) {
- case '\"': fputs("\\\"", out); break;
case '\\': fputs("\\\\", out); break;
case '\a': fputs("\\a", out); break;
case '\b': fputs("\\b", out); break;
break;
}
}
- fputc('"', out);
+ fputc(border, out);
+}
+
+/**
+ * Print a constant character expression.
+ *
+ * @param cnst the constant character expression
+ */
+static void print_char_const(const const_expression_t *cnst)
+{
+ print_quoted_string(&cnst->v.chars, '\'');
}
/**
static void print_string_literal(
const string_literal_expression_t *string_literal)
{
- print_quoted_string(&string_literal->value);
+ print_quoted_string(&string_literal->value, '"');
}
/**
case EXPR_INVALID:
fprintf(out, "*invalid expression*");
break;
+ case EXPR_CHAR_CONST:
+ print_char_const(&expression->conste);
+ break;
case EXPR_CONST:
print_const(&expression->conste);
break;
if(constraint->symbol) {
fprintf(out, "[%s] ", constraint->symbol->string);
}
- print_quoted_string(&constraint->constraints);
+ print_quoted_string(&constraint->constraints, '"');
fputs(" (", out);
print_expression(constraint->expression);
fputs(")", out);
if(clobber != clobbers)
fputs(", ", out);
- print_quoted_string(&clobber->clobber);
+ print_quoted_string(&clobber->clobber, '"');
}
}
fputs("volatile ", out);
}
fputs("(", out);
- print_quoted_string(&statement->asm_text);
+ print_quoted_string(&statement->asm_text, '"');
if(statement->inputs == NULL && statement->outputs == NULL
&& statement->clobbers == NULL)
goto end_of_print_asm_statement;
switch(expression->kind) {
case EXPR_CONST:
+ case EXPR_CHAR_CONST:
case EXPR_STRING_LITERAL:
case EXPR_WIDE_STRING_LITERAL:
case EXPR_SIZEOF: