Augment MATCH_NEWLINE() in the preprocessor so its usage looks like an ordinary case...
[cparser] / ast.c
diff --git a/ast.c b/ast.c
index c0e6b1d..2daa235 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -110,7 +110,6 @@ static unsigned get_expression_precedence(expression_kind_t kind)
                [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,
@@ -196,13 +195,11 @@ static unsigned get_expression_precedence(expression_kind_t kind)
  *
  * @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_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) {
@@ -237,10 +234,8 @@ static void print_quoted_string(const string_t *const string, char border,
 
 static void print_string_literal(const string_literal_expression_t *literal)
 {
-       if (literal->base.kind == EXPR_WIDE_STRING_LITERAL) {
-               print_char('L');
-       }
-       print_quoted_string(&literal->value, '"', 1);
+       print_string(get_string_encoding_prefix(literal->encoding));
+       print_quoted_string(&literal->value, '"');
 }
 
 static void print_literal(const literal_expression_t *literal)
@@ -261,7 +256,7 @@ static void print_literal(const literal_expression_t *literal)
                print_char('L');
                /* FALLTHROUGH */
        case EXPR_LITERAL_CHARACTER:
-               print_quoted_string(&literal->value, '\'', 0);
+               print_quoted_string(&literal->value, '\'');
                return;
        default:
                break;
@@ -665,7 +660,6 @@ static bool needs_parentheses(expression_t const *const expr, unsigned const top
                case EXPR_LITERAL_CASES:
                case EXPR_REFERENCE:
                case EXPR_STRING_LITERAL:
-               case EXPR_WIDE_STRING_LITERAL:
                        /* Do not print () around subexpressions consisting of a single token. */
                        return false;
 
@@ -713,8 +707,7 @@ static void print_expression_prec(expression_t const *expr, unsigned const top_p
        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;
@@ -1043,7 +1036,7 @@ static void print_asm_arguments(asm_argument_t *arguments)
                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(')');
@@ -1062,7 +1055,7 @@ static void print_asm_clobbers(asm_clobber_t *clobbers)
                if (clobber != clobbers)
                        print_string(", ");
 
-               print_quoted_string(&clobber->clobber, '"', 1);
+               print_quoted_string(&clobber->clobber, '"');
        }
 }
 
@@ -1078,7 +1071,7 @@ static void print_asm_statement(const asm_statement_t *statement)
                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)
@@ -1216,10 +1209,10 @@ void print_initializer(const initializer_t *initializer)
                return;
        }
        case INITIALIZER_STRING:
-               print_quoted_string(&initializer->string.string, '"', 1);
+               print_quoted_string(&initializer->string.string, '"');
                return;
        case INITIALIZER_WIDE_STRING:
-               print_quoted_string(&initializer->string.string, '"', 1);
+               print_quoted_string(&initializer->string.string, '"');
                return;
        case INITIALIZER_DESIGNATOR:
                print_designator(initializer->designator.designator);
@@ -1595,7 +1588,6 @@ expression_classification_t is_linker_constant(const expression_t *expression)
 {
        switch (expression->kind) {
        case EXPR_STRING_LITERAL:
-       case EXPR_WIDE_STRING_LITERAL:
        case EXPR_FUNCNAME:
        case EXPR_LABEL_ADDRESS:
                return EXPR_CLASS_CONSTANT;
@@ -1806,7 +1798,6 @@ expression_classification_t is_constant_expression(const expression_t *expressio
        }
 
        case EXPR_STRING_LITERAL:
-       case EXPR_WIDE_STRING_LITERAL:
        case EXPR_FUNCNAME:
        case EXPR_LABEL_ADDRESS:
        case EXPR_SELECT: