summaryrefslogtreecommitdiffstats
path: root/libcpp/expr.c
diff options
context:
space:
mode:
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-05 22:25:27 +0000
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>2007-06-05 22:25:27 +0000
commitd7282a2b2cacdf62e80c1f29f06933f38a70d743 (patch)
treef7bdd99b29a4dc2624af52e3f3a9d6c816e0b468 /libcpp/expr.c
parentc8f1be8d399a461f343ef3bfaf0cf5da91918577 (diff)
downloadppe42-gcc-d7282a2b2cacdf62e80c1f29f06933f38a70d743.tar.gz
ppe42-gcc-d7282a2b2cacdf62e80c1f29f06933f38a70d743.zip
2007-06-05 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
PR preprocessor/23479 gcc/ * doc/extend.texi: Document the 0b-prefixed binary integer constant extension. libcpp/ * expr.c (cpp_classify_number): Implement 0b-prefixed binary integer constants. (append_digit): Likewise. * include/cpplib.h: Add CPP_N_BINARY, to be used for 0b-prefixed binary integer constants. testsuite/ * testsuite/gcc.dg/binary-constants-1.c: Add test suites for the 0b-prefixed binary integer constants. * testsuite/gcc.dg/binary-constants-2.c: Ditto. * testsuite/gcc.dg/binary-constants-3.c: Ditto. * testsuite/gcc.dg/binary-constants-4.c: Ditto. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125346 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/expr.c')
-rw-r--r--libcpp/expr.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 20090195acc..59de8ef9ec9 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -185,6 +185,11 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
radix = 16;
str++;
}
+ else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
+ {
+ radix = 2;
+ str++;
+ }
}
/* Now scan for a well-formed integer or float. */
@@ -223,10 +228,22 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
radix = 10;
if (max_digit >= radix)
- SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+ {
+ if (radix == 2)
+ SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
+ else
+ SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
+ }
if (float_flag != NOT_FLOAT)
{
+ if (radix == 2)
+ {
+ cpp_error (pfile, CPP_DL_ERROR,
+ "invalid prefix \"0b\" for floating constant");
+ return CPP_N_INVALID;
+ }
+
if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
cpp_error (pfile, CPP_DL_PEDWARN,
"use of C99 hexadecimal floating constant");
@@ -315,11 +332,16 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token)
if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
cpp_error (pfile, CPP_DL_PEDWARN,
"imaginary constants are a GCC extension");
+ if (radix == 2 && CPP_PEDANTIC (pfile))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "binary constants are a GCC extension");
if (radix == 10)
result |= CPP_N_DECIMAL;
else if (radix == 16)
result |= CPP_N_HEX;
+ else if (radix == 2)
+ result |= CPP_N_BINARY;
else
result |= CPP_N_OCTAL;
@@ -370,6 +392,11 @@ cpp_interpret_integer (cpp_reader *pfile, const cpp_token *token,
base = 16;
p += 2;
}
+ else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
+ {
+ base = 2;
+ p += 2;
+ }
/* We can add a digit to numbers strictly less than this without
needing the precision and slowness of double integers. */
@@ -425,12 +452,25 @@ static cpp_num
append_digit (cpp_num num, int digit, int base, size_t precision)
{
cpp_num result;
- unsigned int shift = 3 + (base == 16);
+ unsigned int shift;
bool overflow;
cpp_num_part add_high, add_low;
- /* Multiply by 8 or 16. Catching this overflow here means we don't
+ /* Multiply by 2, 8 or 16. Catching this overflow here means we don't
need to worry about add_high overflowing. */
+ switch (base)
+ {
+ case 2:
+ shift = 1;
+ break;
+
+ case 16:
+ shift = 4;
+ break;
+
+ default:
+ shift = 3;
+ }
overflow = !!(num.high >> (PART_PRECISION - shift));
result.high = num.high << shift;
result.low = num.low << shift;
OpenPOWER on IntegriCloud