Do not strip the 0x prefix from the textual representation of hexadecimal constants.
authorChristoph Mallon <christoph.mallon@gmx.de>
Sun, 6 May 2012 17:00:27 +0000 (19:00 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sun, 6 May 2012 17:16:06 +0000 (19:16 +0200)
In particular this adds the missing prefix in print_token().

ast.c
ast2firm.c
lexer.c
wrappergen/write_jna.c

diff --git a/ast.c b/ast.c
index 1e0ff3f..63d3726 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -252,14 +252,13 @@ static void print_literal(const literal_expression_t *literal)
        case EXPR_LITERAL_MS_NOOP:
                print_string("__noop");
                return;
-       case EXPR_LITERAL_INTEGER_HEXADECIMAL:
-       case EXPR_LITERAL_FLOATINGPOINT_HEXADECIMAL:
-               print_string("0x");
-               /* FALLTHROUGH */
+
        case EXPR_LITERAL_BOOLEAN:
+       case EXPR_LITERAL_FLOATINGPOINT:
+       case EXPR_LITERAL_FLOATINGPOINT_HEXADECIMAL:
        case EXPR_LITERAL_INTEGER:
+       case EXPR_LITERAL_INTEGER_HEXADECIMAL:
        case EXPR_LITERAL_INTEGER_OCTAL:
-       case EXPR_LITERAL_FLOATINGPOINT:
                print_stringrep(&literal->value);
                print_stringrep(&literal->suffix);
                return;
index 155d308..26f613b 100644 (file)
@@ -1186,8 +1186,7 @@ static ir_node *string_to_firm(const source_position_t *const src_pos,
        return create_symconst(dbgi, entity);
 }
 
-static bool try_create_integer(literal_expression_t *literal,
-                               type_t *type, unsigned char base)
+static bool try_create_integer(literal_expression_t *literal, type_t *type)
 {
        const char *string = literal->value.begin;
        size_t      size   = literal->value.size;
@@ -1195,8 +1194,8 @@ static bool try_create_integer(literal_expression_t *literal,
        assert(type->kind == TYPE_ATOMIC);
        atomic_type_kind_t akind = type->atomic.akind;
 
-       ir_mode   *mode = atomic_modes[akind];
-       ir_tarval *tv   = new_integer_tarval_from_str(string, size, 1, base, mode);
+       ir_mode   *const mode = atomic_modes[akind];
+       ir_tarval *const tv   = new_tarval_from_str(string, size, mode);
        if (tv == tarval_bad)
                return false;
 
@@ -1219,40 +1218,32 @@ static void create_integer_tarval(literal_expression_t *literal)
                }
        }
 
-       unsigned base;
-       switch (literal->base.kind) {
-               case EXPR_LITERAL_INTEGER_OCTAL:       base =  8; break;
-               case EXPR_LITERAL_INTEGER:             base = 10; break;
-               case EXPR_LITERAL_INTEGER_HEXADECIMAL: base = 16; break;
-               default: panic("invalid literal kind");
-       }
-
        tarval_int_overflow_mode_t old_mode = tarval_get_integer_overflow_mode();
 
        /* now try if the constant is small enough for some types */
        tarval_set_integer_overflow_mode(TV_OVERFLOW_BAD);
        if (ls < 1) {
-               if (sign <= 0 && try_create_integer(literal, type_int, base))
+               if (sign <= 0 && try_create_integer(literal, type_int))
                        goto finished;
-               if (sign >= 0 && try_create_integer(literal, type_unsigned_int, base))
+               if (sign >= 0 && try_create_integer(literal, type_unsigned_int))
                        goto finished;
        }
        if (ls < 2) {
-               if (sign <= 0 && try_create_integer(literal, type_long, base))
+               if (sign <= 0 && try_create_integer(literal, type_long))
                        goto finished;
-               if (sign >= 0 && try_create_integer(literal, type_unsigned_long, base))
+               if (sign >= 0 && try_create_integer(literal, type_unsigned_long))
                        goto finished;
        }
        /* last try? then we should not report tarval_bad */
        if (sign < 0)
                tarval_set_integer_overflow_mode(TV_OVERFLOW_WRAP);
-       if (sign <= 0 && try_create_integer(literal, type_long_long, base))
+       if (sign <= 0 && try_create_integer(literal, type_long_long))
                goto finished;
 
        /* last try */
        assert(sign >= 0);
        tarval_set_integer_overflow_mode(TV_OVERFLOW_WRAP);
-       bool res = try_create_integer(literal, type_unsigned_long_long, base);
+       bool res = try_create_integer(literal, type_unsigned_long_long);
        if (!res)
                panic("internal error when parsing number literal");
 
@@ -1321,17 +1312,10 @@ static ir_node *literal_to_firm(const literal_expression_t *literal)
                break;
 
        case EXPR_LITERAL_FLOATINGPOINT:
+       case EXPR_LITERAL_FLOATINGPOINT_HEXADECIMAL:
                tv = new_tarval_from_str(string, size, mode);
                break;
 
-       case EXPR_LITERAL_FLOATINGPOINT_HEXADECIMAL: {
-               char buffer[size + 2];
-               memcpy(buffer, "0x", 2);
-               memcpy(buffer+2, string, size);
-               tv = new_tarval_from_str(buffer, size+2, mode);
-               break;
-       }
-
        case EXPR_LITERAL_BOOLEAN:
                if (string[0] == 't') {
                        tv = get_mode_one(mode);
diff --git a/lexer.c b/lexer.c
index 2177a30..1ad3b89 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -355,7 +355,6 @@ static void parse_number_hex(void)
        bool is_float   = false;
        bool has_digits = false;
 
-       assert(obstack_object_size(&symbol_obstack) == 0);
        while (isxdigit(c)) {
                has_digits = true;
                obstack_1grow(&symbol_obstack, (char) c);
@@ -392,8 +391,7 @@ static void parse_number_hex(void)
                is_float ? T_FLOATINGPOINT_HEXADECIMAL : T_INTEGER_HEXADECIMAL;
 
        if (!has_digits) {
-               errorf(&lexer_token.base.source_position,
-                      "invalid number literal '0x%S'", &lexer_token.number.number);
+               errorf(&lexer_token.base.source_position, "invalid number literal '%S'", &lexer_token.number.number);
                lexer_token.number.number.begin = "0";
                lexer_token.number.number.size  = 1;
        }
@@ -421,15 +419,16 @@ static void parse_number(void)
 
        assert(obstack_object_size(&symbol_obstack) == 0);
        if (c == '0') {
+               obstack_1grow(&symbol_obstack, (char)c);
                next_char();
                if (c == 'x' || c == 'X') {
+                       obstack_1grow(&symbol_obstack, (char)c);
                        next_char();
                        parse_number_hex();
                        return;
                } else {
                        has_digits = true;
                }
-               obstack_1grow(&symbol_obstack, '0');
        }
 
        while (isdigit(c)) {
index d005b46..c5735f8 100644 (file)
@@ -308,12 +308,11 @@ static void write_expression(const expression_t *expression)
        /* TODO */
        switch(expression->kind) {
        case EXPR_LITERAL_INTEGER:
+       case EXPR_LITERAL_INTEGER_HEXADECIMAL:
        case EXPR_LITERAL_INTEGER_OCTAL:
                fprintf(out, "%s", expression->literal.value.begin);
                break;
-       case EXPR_LITERAL_INTEGER_HEXADECIMAL:
-               fprintf(out, "0x%s", expression->literal.value.begin);
-               break;
+
        case EXPR_ENUM_CONSTANT: {
                /* UHOH... hacking */
                entity_t *entity = expression->reference.entity;