Add support for C++17 hexadecimal floating literals

This commit is contained in:
Zackery Spytz 2019-02-13 15:16:40 -07:00
parent 200984f051
commit cf83adfcd1
7 changed files with 111 additions and 1 deletions

View File

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress)
===========================
2019-02-13: ZackerySpytz
#1469 Add support for C++17 hexadecimal floating literals.
2019-02-11: wsfulton
[OCaml] #1437 OCaml has been give the 'Experimental' language status. The examples work
and most of the test-suite is also working, so it is quite close to being a 'Supported' language.

View File

@ -16,6 +16,7 @@
<ul>
<li><a href="#CPlusPlus17_nested_namespaces">Nested namespace definitions</a>
<li><a href="#CPlusPlus17_u8_char_literals">UTF-8 character literals</a>
<li><a href="#CPlusPlus17_hexadecimal_floating_literals">Hexadecimal floating literals</a>
</ul>
<li><a href="#CPlusPlus17_standard_library_changes">Standard library changes</a>
</ul>
@ -87,6 +88,20 @@ char a = u8'a';
</pre>
</div>
<H3><a name="CPlusPlus17_hexadecimal_floating_literals">9.2.3 Hexadecimal floating literals</a></H3>
<p>
C++17 added hexadecimal floating literals.
For example:
</p>
<div class="code">
<pre>
double f = 0xF.68p2;
</pre>
</div>
<H2><a name="CPlusPlus17_standard_library_changes">9.3 Standard library changes</a></H2>

View File

@ -365,6 +365,7 @@
<ul>
<li><a href="CPlusPlus17.html#CPlusPlus17_nested_namespaces">Nested namespace definitions</a>
<li><a href="CPlusPlus17.html#CPlusPlus17_u8_char_literals">UTF-8 character literals</a>
<li><a href="CPlusPlus17.html#CPlusPlus17_hexadecimal_floating_literals">Hexadecimal floating literals</a>
</ul>
<li><a href="CPlusPlus17.html#CPlusPlus17_standard_library_changes">Standard library changes</a>
</ul>

View File

@ -163,6 +163,7 @@ CPP_TEST_CASES += \
cpp_static \
cpp_typedef \
cpp14_binary_integer_literals \
cpp17_hex_floating_literals \
cpp17_nested_namespaces \
cpp17_nspace_nested_namespaces \
cpp17_u8_char_literals \

View File

@ -0,0 +1,43 @@
%module cpp17_hex_floating_literals
// Tests are designed so that code compiles with C++98 compilers
%{
#if __cplusplus >= 201703L
#define CPP17 1
#endif
%}
double f1 = 0x.0p1;
double f2 = 0x0.p1;
double f3 = 0x0.0p-1;
double f4 = 0xf.p-1;
double f5 = 0xA.0p1;
double f6 = 0x0.10P+10;
double f7 = 0xb2F.p2;
float f8 = 0x1234AP1F;
float f9 = 0x45A1.D1A2p+10f;
%{
#if defined(CPP17)
double f1 = 0x.0p1;
double f2 = 0x0.p1;
double f3 = 0x0.0p-1;
double f4 = 0xf.p-1;
double f5 = 0xA.0p1;
double f6 = 0x0.10P+10;
double f7 = 0xb2F.p2;
float f8 = 0x1234AP1F;
float f9 = 0x45A1.D1A2p+10f;
#else
double f1 = 0.;
double f2 = 0.;
double f3 = 0.;
double f4 = 7.5;
double f5 = 20.;
double f6 = 64.;
double f7 = 11452.;
float f8 = 149140.f;
float f9 = 18253638.f;
#endif
%}

View File

@ -0,0 +1,28 @@
from cpp17_hex_floating_literals import *
if cvar.f1 != 0.:
raise RuntimeError
if cvar.f2 != 0.:
raise RuntimeError
if cvar.f3 != 0.:
raise RuntimeError
if cvar.f4 != 7.5:
raise RuntimeError
if cvar.f5 != 20.:
raise RuntimeError
if cvar.f6 != 64.:
raise RuntimeError
if cvar.f7 != 11452.:
raise RuntimeError
if cvar.f8 != 149140.:
raise RuntimeError
if cvar.f9 != 18253638.:
raise RuntimeError

View File

@ -1196,6 +1196,10 @@ static int look(Scanner *s) {
return SWIG_TOKEN_INT;
if (isxdigit(c))
state = 85;
else if (c == '.') /* hexadecimal float */
state = 860;
else if ((c == 'p') || (c == 'P')) /* hexadecimal float */
state = 820;
else if ((c == 'l') || (c == 'L')) {
state = 87;
} else if ((c == 'u') || (c == 'U')) {
@ -1220,7 +1224,22 @@ static int look(Scanner *s) {
return SWIG_TOKEN_INT;
}
break;
case 860:
/* hexadecimal float */
if ((c = nextchar(s)) == 0) {
Swig_error(cparse_file, cparse_start_line, "Hexadecimal floating literals require an exponent\n");
return SWIG_TOKEN_ERROR;
}
if (isxdigit(c))
state = 860;
else if ((c == 'p') || (c == 'P'))
state = 820;
else {
retract(s, 2);
Swig_error(cparse_file, cparse_start_line, "Hexadecimal floating literals require an exponent\n");
return SWIG_TOKEN_ERROR;
}
break;
case 86:
/* Rest of floating point number */