Values of mode LONGSETY bits are often used in order to convey unsigned quantities which would require a different precision (number of bits) if they were conveyed in values of mode LONGSETY int. The need to do so arises particularly in transput in and in FFI. In these cases, it is useful to be able to specify values in decimal.
This commit adds support for radix 10r in bits denotations, implementing the GNU extension GNU68-2026-003-decimal-radices, and also adds a compile-time diagnostic that complains about invalid radices in bits denotations. Signed-off-by: Jose E. Marchesi <[email protected]> gcc/algol68/ChangeLog * ga68.vw: Add syntax for the GNU68-2026-003-decimal-radices language extension. * a68-parser-scanner.cc (get_next_token): Recognize decimal bits denotations. (get_next_token): Emit an error if an invalid radix is found in a bits denotation. gcc/testsuite/ChangeLog * algol68/compile/error-radix-5.a68: New test. * algol68/compile/error-radix-6.a68: Likewise. * algol68/compile/error-radix-7.a68: Likewise. * algol68/execute/bits-radix-ten-1.a68: Likewise. --- gcc/algol68/a68-parser-scanner.cc | 12 ++++++++++++ gcc/algol68/ga68.vw | 17 ++++++++++++----- gcc/testsuite/algol68/compile/error-radix-5.a68 | 1 + gcc/testsuite/algol68/compile/error-radix-6.a68 | 1 + gcc/testsuite/algol68/compile/error-radix-7.a68 | 4 ++++ .../algol68/execute/bits-radix-ten-1.a68 | 13 +++++++++++++ 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/algol68/compile/error-radix-5.a68 create mode 100644 gcc/testsuite/algol68/compile/error-radix-6.a68 create mode 100644 gcc/testsuite/algol68/compile/error-radix-7.a68 create mode 100644 gcc/testsuite/algol68/execute/bits-radix-ten-1.a68 diff --git a/gcc/algol68/a68-parser-scanner.cc b/gcc/algol68/a68-parser-scanner.cc index a099a7c0af1..30c23996dcd 100644 --- a/gcc/algol68/a68-parser-scanner.cc +++ b/gcc/algol68/a68-parser-scanner.cc @@ -1679,6 +1679,17 @@ get_next_token (bool in_format, uint64_t radix = strtoul (A68_PARSER (scan_buf), &end, 10); gcc_assert (errno == 0 && end != A68_PARSER (scan_buf) && *end == 'r'); + /* Validate radix. */ + if (radix != 2 + && radix != 4 + && radix != 8 + && (OPTION_STRICT (&A68_JOB) || radix != 10) + && radix != 16) + { + SCAN_ERROR (true, *start_l, *ref_s, + "invalid radix in %<bits%> denotation"); + } + /* Get the rest of the bits literal. Typographical display features are allowed in the reference language between the digit symbols composing the denotation. However, in SUPPER stropping this could @@ -1698,6 +1709,7 @@ get_next_token (bool in_format, while (((radix == 2 && (c == '0' || c == '1')) || (radix == 4 && (c >= '0' && c <= '3')) || (radix == 8 && (c >= '0' && c <= '7')) + || (!OPTION_STRICT (&A68_JOB) && radix == 10 && ISDIGIT (c)) || (radix == 16 && (ISDIGIT (c) || strchr ("abcdef", c) != NO_TEXT)))) { (sym++)[0] = c; diff --git a/gcc/algol68/ga68.vw b/gcc/algol68/ga68.vw index 7ee826815ae..2f3ef144da0 100644 --- a/gcc/algol68/ga68.vw +++ b/gcc/algol68/ga68.vw @@ -43,6 +43,9 @@ [BF] This is the GNU68-2026-001-brief-selection GNU extension. It adds support for a brief form of the selection construct. + [DR] This is the GNU68-2026-003-decimal-radices GNU extension. It + adds support for using ten radix in bits denotations. + The metaproduction rules, hyper-rules and hyper-alternatives introduced by each extension are clearly marked in the sections below. You can easily search for them using the extensions tags in @@ -1740,9 +1743,11 @@ a) void denotation{80a} : empty{94b} symbol. 8.2 Bits denotations +{ Extensions: [DR] } + 8.2.1 Syntax -A) RADIX :: radix two ; radix four ; radix eight ; radix sixteen. +A) RADIX :: radix two ; radix four ; radix eight ; radix ten ; radix sixteen. a) structured with row of boolean field LENGTH LENGTHETY letter aleph mode denotation{a,80a} : @@ -1754,7 +1759,7 @@ b) structured with row of boolean field structured with row of boolean field SHORTHETY letter aleph mode denotation{b,c}. c) structured wih row of boolean field letter aleph mode denotation{a,b,80a} : - RADIX{d,e,f,g}, letter r symbol{94a}, RADIX digit{h,i,j,k} sequence. + RADIX{d,e,f,g}, letter r symbol{94a}, RADIX digit{h,i,j,k,n} sequence. d) radix two{c,A347b} : digit two{94b} symbol. e) radix four{c,A347b} : digit four{94b} symbol. f) radix eight{c,A347b} : digit eight{94b} symbol. @@ -1763,13 +1768,15 @@ h) radix two digit{c,i} : digit zero symbol{94b} ; digit one symbol{94b}. i) radix four digit{c,j} : radix two digit{h} ; digit two symbol{94b} ; digit three symbol{94b}. -j) raidx eight digit{c,k} : +j) radix eight digit{c,n} : radix four digit{i} ; digit four symbol{94b} ; digit five symbol{94b} ; digit six symbol{94b} ; digit seven symbol{94b}. +n) radix ten digit{c,k} : + radix eight digit{c} ; digit eight symbol{94b} ; + digit nine symbol{94b}. k) radix sixteen digit{c} : - radix eight digit{j} ; digit eight symbol{94b} ; - digit nine symbol{94b} ; letter a symbol{94a} ; + radix ten digit{n} ; letter a symbol{94a} ; letter b symbol{94a} ; letter e symbol{94a} ; letter d symbol{94a} ; letter e symbol{94a} ; letter f symbol{94a}. diff --git a/gcc/testsuite/algol68/compile/error-radix-5.a68 b/gcc/testsuite/algol68/compile/error-radix-5.a68 new file mode 100644 index 00000000000..978105959e4 --- /dev/null +++ b/gcc/testsuite/algol68/compile/error-radix-5.a68 @@ -0,0 +1 @@ +(bits d = 1r0; skip) { dg-error "invalid radix" } diff --git a/gcc/testsuite/algol68/compile/error-radix-6.a68 b/gcc/testsuite/algol68/compile/error-radix-6.a68 new file mode 100644 index 00000000000..e3de3443c8f --- /dev/null +++ b/gcc/testsuite/algol68/compile/error-radix-6.a68 @@ -0,0 +1 @@ +(bits d = 17r0; skip) { dg-error "invalid radix" } diff --git a/gcc/testsuite/algol68/compile/error-radix-7.a68 b/gcc/testsuite/algol68/compile/error-radix-7.a68 new file mode 100644 index 00000000000..a71a0880410 --- /dev/null +++ b/gcc/testsuite/algol68/compile/error-radix-7.a68 @@ -0,0 +1,4 @@ +{ Radix 10 is not allowed in strict Algol 68. } +{ dg-options "-std=algol68" } + +(bits d = 10r0; skip) { dg-error "invalid radix" } diff --git a/gcc/testsuite/algol68/execute/bits-radix-ten-1.a68 b/gcc/testsuite/algol68/execute/bits-radix-ten-1.a68 new file mode 100644 index 00000000000..ff4994e9a97 --- /dev/null +++ b/gcc/testsuite/algol68/execute/bits-radix-ten-1.a68 @@ -0,0 +1,13 @@ +begin begin short short bits b = short short 10r0; + assert(b = short short 16r0); + assert(ABS LENG b = short 0) + end; + + begin short short bits b = short short 10r255; + assert(b = short short 16rff); + assert(ABS LENG b = short 255); + assert(LENG ABS b = - short 1) + end; + + skip +end -- 2.39.5
