print_char('\t');
}
-static void print_stringrep(const string_t *string)
-{
- for (size_t i = 0; i < string->size; ++i) {
- print_char(string->begin[i]);
- }
-}
-
/**
* Returns 1 if a given precedence level has right-to-left
* associativity, else 0.
[EXPR_LITERAL_INTEGER] = PREC_PRIMARY,
[EXPR_LITERAL_FLOATINGPOINT] = PREC_PRIMARY,
[EXPR_LITERAL_CHARACTER] = PREC_PRIMARY,
- [EXPR_LITERAL_WIDE_CHARACTER] = PREC_PRIMARY,
[EXPR_LITERAL_MS_NOOP] = PREC_PRIMARY,
[EXPR_STRING_LITERAL] = PREC_PRIMARY,
- [EXPR_WIDE_STRING_LITERAL] = PREC_PRIMARY,
[EXPR_COMPOUND_LITERAL] = PREC_UNARY,
[EXPR_CALL] = PREC_POSTFIX,
[EXPR_CONDITIONAL] = PREC_CONDITIONAL,
*
* @param string the string constant
* @param border the border char
- * @param skip number of chars to skip at the end
*/
-static void print_quoted_string(const string_t *const string, char border,
- int skip)
+static void print_quoted_string(const string_t *const string, char border)
{
+ print_string(get_string_encoding_prefix(string->encoding));
+
print_char(border);
- const char *end = string->begin + string->size - skip;
+ const char *end = string->begin + string->size;
for (const char *c = string->begin; c != end; ++c) {
const char tc = *c;
if (tc == border) {
print_char(border);
}
-static void print_string_literal(const string_literal_expression_t *literal)
+static void print_string_literal(string_literal_expression_t const *const literal, char const delimiter)
{
- if (literal->base.kind == EXPR_WIDE_STRING_LITERAL) {
- print_char('L');
- }
- print_quoted_string(&literal->value, '"', 1);
+ print_quoted_string(&literal->value, delimiter);
}
static void print_literal(const literal_expression_t *literal)
case EXPR_LITERAL_BOOLEAN:
case EXPR_LITERAL_FLOATINGPOINT:
case EXPR_LITERAL_INTEGER:
- print_stringrep(&literal->value);
- print_stringrep(&literal->suffix);
+ print_string(literal->value.begin);
return;
- case EXPR_LITERAL_WIDE_CHARACTER:
- print_char('L');
- /* FALLTHROUGH */
- case EXPR_LITERAL_CHARACTER:
- print_quoted_string(&literal->value, '\'', 0);
- return;
default:
break;
}
*/
static void print_typeprop_expression(const typeprop_expression_t *expression)
{
- if (expression->base.kind == EXPR_SIZEOF) {
- print_string("sizeof");
- } else {
- assert(expression->base.kind == EXPR_ALIGNOF);
- print_string("__alignof__");
+ switch (expression->base.kind) {
+ case EXPR_SIZEOF: print_string("sizeof"); break;
+ case EXPR_ALIGNOF: print_string(c_mode & _C11 ? "_Alignof" : "__alignof__"); break;
+ default: panic("invalid typeprop kind");
}
if (expression->tp_expression != NULL) {
/* PREC_TOP: always print the '()' here, sizeof x is right but unusual */
print_string("__builtin_va_start(");
print_assignment_expression(expression->ap);
print_string(", ");
- print_string(expression->parameter->base.base.symbol->string);
+ print_assignment_expression(expression->parameter);
print_char(')');
}
case EXPR_ENUM_CONSTANT:
case EXPR_FUNCNAME:
case EXPR_LITERAL_CASES:
+ case EXPR_LITERAL_CHARACTER:
case EXPR_REFERENCE:
case EXPR_STRING_LITERAL:
- case EXPR_WIDE_STRING_LITERAL:
/* Do not print () around subexpressions consisting of a single token. */
return false;
case EXPR_FUNCNAME: print_funcname( &expr->funcname); break;
case EXPR_LABEL_ADDRESS: print_label_address_expression(&expr->label_address); break;
case EXPR_LITERAL_CASES: print_literal( &expr->literal); break;
+ case EXPR_LITERAL_CHARACTER: print_string_literal( &expr->string_literal, '\''); break;
case EXPR_OFFSETOF: print_offsetof_expression( &expr->offsetofe); break;
case EXPR_REFERENCE:
case EXPR_ENUM_CONSTANT: print_reference_expression( &expr->reference); break;
case EXPR_SELECT: print_select( &expr->select); break;
case EXPR_STATEMENT: print_statement_expression( &expr->statement); break;
- case EXPR_STRING_LITERAL:
- case EXPR_WIDE_STRING_LITERAL: print_string_literal( &expr->string_literal); break;
+ case EXPR_STRING_LITERAL: print_string_literal( &expr->string_literal, '"'); break;
case EXPR_UNARY_CASES: print_unary_expression( &expr->unary); break;
case EXPR_VA_ARG: print_va_arg( &expr->va_arge); break;
case EXPR_VA_COPY: print_va_copy( &expr->va_copye); break;
}
}
-/**
- * Print a while statement.
- *
- * @param statement the statement
- */
-static void print_while_statement(const while_statement_t *statement)
-{
- print_string("while (");
- print_expression(statement->condition);
- print_char(')');
- print_inner_statement(statement->body);
-}
-
/**
* Print a do-while statement.
*
*/
static void print_for_statement(const for_statement_t *statement)
{
- print_string("for (");
- if (statement->initialisation != NULL) {
- print_expression(statement->initialisation);
+ if (statement->initialisation || statement->scope.entities || !statement->condition || statement->step) {
+ print_string("for (");
+ if (statement->initialisation != NULL) {
+ print_expression(statement->initialisation);
+ print_char(';');
+ } else {
+ entity_t const *entity = statement->scope.entities;
+ for (; entity != NULL; entity = entity->base.next) {
+ if (is_generated_entity(entity))
+ continue;
+ /* FIXME display of multiple declarations is wrong */
+ print_declaration(entity);
+ }
+ }
+ if (statement->condition != NULL) {
+ print_char(' ');
+ print_expression(statement->condition);
+ }
print_char(';');
- } else {
- entity_t const *entity = statement->scope.entities;
- for (; entity != NULL; entity = entity->base.next) {
- if (is_generated_entity(entity))
- continue;
- /* FIXME display of multiple declarations is wrong */
- print_declaration(entity);
+ if (statement->step != NULL) {
+ print_char(' ');
+ print_expression(statement->step);
}
- }
- if (statement->condition != NULL) {
- print_char(' ');
+ } else {
+ print_string("while (");
print_expression(statement->condition);
}
- print_char(';');
- if (statement->step != NULL) {
- print_char(' ');
- print_expression(statement->step);
- }
print_char(')');
print_inner_statement(statement->body);
}
if (argument->symbol) {
print_format("[%s] ", argument->symbol->string);
}
- print_quoted_string(&argument->constraints, '"', 1);
+ print_quoted_string(&argument->constraints, '"');
print_string(" (");
print_expression(argument->expression);
print_char(')');
if (clobber != clobbers)
print_string(", ");
- print_quoted_string(&clobber->clobber, '"', 1);
+ print_quoted_string(&clobber->clobber, '"');
}
}
print_string("volatile ");
}
print_char('(');
- print_quoted_string(&statement->asm_text, '"', 1);
+ print_quoted_string(&statement->asm_text, '"');
if (statement->outputs == NULL &&
statement->inputs == NULL &&
statement->clobbers == NULL)
case STATEMENT_MS_TRY: print_ms_try_statement( &stmt->ms_try); break;
case STATEMENT_RETURN: print_return_statement( &stmt->returns); break;
case STATEMENT_SWITCH: print_switch_statement( &stmt->switchs); break;
- case STATEMENT_WHILE: print_while_statement( &stmt->whiles); break;
}
}
}
switch (initializer->kind) {
- case INITIALIZER_VALUE: {
- const initializer_value_t *value = &initializer->value;
- print_assignment_expression(value->value);
+ case INITIALIZER_STRING:
+ case INITIALIZER_VALUE:
+ print_assignment_expression(initializer->value.value);
return;
- }
+
case INITIALIZER_LIST: {
- assert(initializer->kind == INITIALIZER_LIST);
print_string("{ ");
const initializer_list_t *list = &initializer->list;
print_string(" }");
return;
}
- case INITIALIZER_STRING:
- print_quoted_string(&initializer->string.string, '"', 1);
- return;
- case INITIALIZER_WIDE_STRING:
- print_quoted_string(&initializer->string.string, '"', 1);
- return;
+
case INITIALIZER_DESIGNATOR:
print_designator(initializer->designator.designator);
print_string(" = ");
print_type_ext(entity->declaration.type, entity->base.symbol,
&entity->function.parameters);
- if (entity->function.statement != NULL) {
+ if (entity->function.body != NULL) {
print_char('\n');
- print_indented_statement(entity->function.statement);
+ print_indented_statement(entity->function.body);
print_char('\n');
return;
}
case ENTITY_VARIABLE:
if (entity->variable.thread_local)
- print_string("__thread ");
+ print_string(c_mode & _C11 ? "_Thread_local " : "__thread ");
print_type_ext(declaration->type, declaration->base.symbol, NULL);
if (entity->variable.initializer != NULL) {
print_string(" = ");
{
switch (initializer->kind) {
case INITIALIZER_STRING:
- case INITIALIZER_WIDE_STRING:
case INITIALIZER_DESIGNATOR:
return EXPR_CLASS_CONSTANT;
{
switch (expression->kind) {
case EXPR_STRING_LITERAL:
- case EXPR_WIDE_STRING_LITERAL:
case EXPR_FUNCNAME:
case EXPR_LABEL_ADDRESS:
return EXPR_CLASS_CONSTANT;
expression_classification_t is_constant_expression(const expression_t *expression)
{
switch (expression->kind) {
- case EXPR_LITERAL_CASES:
- case EXPR_CLASSIFY_TYPE:
- case EXPR_OFFSETOF:
- case EXPR_ALIGNOF:
- case EXPR_BUILTIN_CONSTANT_P:
+ case EXPR_LITERAL_CHARACTER:
case EXPR_BUILTIN_TYPES_COMPATIBLE_P:
case EXPR_ENUM_CONSTANT:
+ case EXPR_LITERAL_BOOLEAN:
+ case EXPR_LITERAL_MS_NOOP:
return EXPR_CLASS_CONSTANT;
- case EXPR_SIZEOF: {
- type_t *const type = skip_typeref(expression->typeprop.type);
- return
- !is_type_array(type) || !type->array.is_vla ? EXPR_CLASS_CONSTANT :
- EXPR_CLASS_VARIABLE;
+ {
+ type_t *type;
+ case EXPR_ALIGNOF:
+ type = skip_typeref(expression->typeprop.type);
+ goto check_type;
+
+ case EXPR_CLASSIFY_TYPE:
+ type = skip_typeref(expression->classify_type.type_expression->base.type);
+ goto check_type;
+
+ case EXPR_LITERAL_INTEGER:
+ case EXPR_LITERAL_FLOATINGPOINT:
+ type = skip_typeref(expression->base.type);
+ goto check_type;
+
+ case EXPR_OFFSETOF:
+ type = skip_typeref(expression->offsetofe.type);
+ goto check_type;
+
+ case EXPR_SIZEOF:
+ type = skip_typeref(expression->typeprop.type);
+ if (is_type_array(type) && type->array.is_vla)
+ return EXPR_CLASS_VARIABLE;
+ goto check_type;
+
+check_type:
+ return is_type_valid(type) ? EXPR_CLASS_CONSTANT : EXPR_CLASS_ERROR;
+ }
+
+ case EXPR_BUILTIN_CONSTANT_P: {
+ expression_classification_t const c = is_constant_expression(expression->builtin_constant.value);
+ return c != EXPR_CLASS_ERROR ? EXPR_CLASS_CONSTANT : EXPR_CLASS_ERROR;
}
case EXPR_STRING_LITERAL:
- case EXPR_WIDE_STRING_LITERAL:
case EXPR_FUNCNAME:
case EXPR_LABEL_ADDRESS:
case EXPR_SELECT: