• R/O
  • SSH
  • HTTPS

eircompile: Commit


Commit MetaInfo

Revisión97 (tree)
Tiempo2022-04-13 22:26:51
Autorquiret

Log Message

- added suffix-support for integer and decimal-floating-point COS literals (f/F and u/U) + unit-tests

Cambiar Resumen

Diferencia incremental

--- commonlangs/include/commonlangs/cos.h (revision 96)
+++ commonlangs/include/commonlangs/cos.h (revision 97)
@@ -3109,8 +3109,12 @@
31093109 BINARY
31103110 };
31113111
3112- inline IntegerLiteral( COSObjects *sys, intType type = intType::BASE10, cosCommonString <char> string = {} )
3113- : Literal( sys ), int_type( type ), string( std::move( string ) )
3112+ inline IntegerLiteral(
3113+ COSObjects *sys, intType type = intType::BASE10, cosCommonString <char> string = {},
3114+ bool enc_unsigned = false
3115+ )
3116+ : Literal( sys ), int_type( type ), string( std::move( string ) ),
3117+ enc_unsigned( enc_unsigned )
31143118 {
31153119 return;
31163120 }
@@ -3119,6 +3123,7 @@
31193123
31203124 intType int_type;
31213125 cosCommonString <char> string;
3126+ bool enc_unsigned; // if true, then the native version shall choose an unsigned data type for encoding.
31223127 };
31233128 // Decimal number with decimal point present.
31243129 // It is necessary to distinguish between with-decimal-point and without, because both can be numerically
@@ -3131,12 +3136,20 @@
31313136 HEX
31323137 };
31333138
3139+ enum class suffixType
3140+ {
3141+ DOUBLE,
3142+ FLOAT
3143+ };
3144+
31343145 inline DecimalLiteral(
31353146 COSObjects *sys, decimalType type = decimalType::BASE10,
31363147 cosCommonString <char> predot = {}, cosCommonString <char> postdot = {},
3137- bool exp_positive_sign = true, cosCommonString <char> base10_exponent = {}
3148+ bool exp_positive_sign = true, cosCommonString <char> base10_exponent = {},
3149+ suffixType valType = suffixType::DOUBLE
31383150 ) : Literal( sys ), dec_type( type ), predot( std::move( predot ) ), postdot( std::move( postdot ) ),
3139- exp_positive_sign( exp_positive_sign ), base10_exponent( std::move( base10_exponent ) )
3151+ exp_positive_sign( exp_positive_sign ), base10_exponent( std::move( base10_exponent ) ),
3152+ valType( std::move( valType ) )
31403153 {
31413154 return;
31423155 }
@@ -3148,6 +3161,7 @@
31483161 cosCommonString <char> postdot;
31493162 bool exp_positive_sign;
31503163 cosCommonString <char> base10_exponent;
3164+ suffixType valType;
31513165 };
31523166 struct BooleanLiteral : public Literal
31533167 {
--- commonlangs/include/commonlangs/cos_env.h (revision 96)
+++ commonlangs/include/commonlangs/cos_env.h (revision 97)
@@ -1473,6 +1473,7 @@
14731473 assert( lexer.CompileProduction( compiler, "digitseq", "'0123456789'^1:*" ) == true );
14741474 assert( lexer.CompileProduction( compiler, "hdigit", "digit | 'abcdefABCDEF'" ) == true );
14751475 assert( lexer.CompileProduction( compiler, "hdigitseq", "'0123456789abcdefABCDEF'^1:*" ) == true );
1476+ assert( lexer.CompileProduction( compiler, "decsuffix", "suffix:'fF'" ) == true );
14761477 assert( lexer.CompileProduction( compiler, "decfexp", "'eE' (expsign:'+-')^0:1 expval:digitseq" ) == true );
14771478 assert( lexer.CompileProduction( compiler, "hexfexp", "'pP' (expsign:'+-')^0:1 expval:digitseq" ) == true );
14781479
@@ -1503,6 +1504,14 @@
15031504 {
15041505 assign_to->postdot = value;
15051506 }
1507+ else if ( attrib == "suffix" )
1508+ {
1509+ if ( value == "f" || value == "F" )
1510+ {
1511+ // By default it is a double, but we can change it to float by suffix.
1512+ assign_to->valType = DecimalLiteral::suffixType::FLOAT;
1513+ }
1514+ }
15061515 }
15071516
15081517 static inline bool VerifyNode( const DecimalLiteral *node )
@@ -1511,250 +1520,255 @@
15111520 return ( node->predot.GetLength() > 0 || node->postdot.GetLength() > 0 );
15121521 }
15131522 };
1514- assert( lexer.CompileProduction( compiler, "literal", "(predot:digitseq)^0:1 '.' (postdot:digitseq)^0:1 decfexp^0:1" ) == true );
1523+ assert( lexer.CompileProduction( compiler, "literal", "(predot:digitseq)^0:1 '.' (postdot:digitseq)^0:1 decfexp^0:1 decsuffix^0:1" ) == true );
15151524 {
15161525 lexer.GetNamedProduction( "literal" ).GetLastStep()->setSelector <direct_obj_build_selector <char, DecimalLiteral, COSNode, decimal_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, DecimalLiteral::decimalType::BASE10 );
15171526 }
1518- assert( lexer.CompileProduction( compiler, "literal", "predot:digitseq decfexp" ) == true );
1527+ assert( lexer.CompileProduction( compiler, "literal", "predot:digitseq decfexp decsuffix^0:1" ) == true );
15191528 {
15201529 lexer.GetNamedProduction( "literal" ).GetLastStep()->setSelector <direct_obj_build_selector <char, DecimalLiteral, COSNode, decimal_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, DecimalLiteral::decimalType::BASE10 );
15211530 }
15221531 // Base 16 decimal token (with decimal point, a.k.a. the floating point).
1523- assert( lexer.CompileProduction( compiler, "literal", "'0' 'xX' (predot:hdigitseq)^0:1 '.' (postdot:hdigitseq)^0:1 hexfexp" ) == true );
1532+ assert( lexer.CompileProduction( compiler, "literal", "'0' 'xX' (predot:hdigitseq)^0:1 '.' (postdot:hdigitseq)^0:1 hexfexp decsuffix^0:1" ) == true );
15241533 {
15251534 lexer.GetNamedProduction( "literal" ).GetLastStep()->setSelector <direct_obj_build_selector <char, DecimalLiteral, COSNode, decimal_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, DecimalLiteral::decimalType::HEX );
15261535 }
1527- assert( lexer.CompileProduction( compiler, "literal", "'0' 'xX' predot:hdigitseq hexfexp" ) == true );
1536+ assert( lexer.CompileProduction( compiler, "literal", "'0' 'xX' predot:hdigitseq hexfexp decsuffix^0:1" ) == true );
15281537 {
15291538 lexer.GetNamedProduction( "literal" ).GetLastStep()->setSelector <direct_obj_build_selector <char, DecimalLiteral, COSNode, decimal_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, DecimalLiteral::decimalType::HEX );
15301539 }
1531- // Base 10 integer token.
1532- lexer.AddProgrammableTokenStep( "intliteral",
1533- []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
1540+ // *** INTEGER LITERALS ***
1541+ assert( lexer.CompileProduction( compiler, "intsuffix", "suffix:'uU'" ) == true );
1542+ struct integer_dispatcher
1543+ {
1544+ static inline void AssignAttributeTo( IntegerLiteral *assign_to, const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
15341545 {
1535- const char *startdata = pt.GetCurrentData();
1536- size_t startoff = pt.GetOffset();
1537-
1538- if ( pt.GetRemainder() == 0 )
1539- return std::nullopt;
1540-
1541- auto first_ucp = pt.ReadCharacter();
1542-
1543- if ( is_dec_base10_nonzero( first_ucp ) == false )
1546+ if ( attrib == "str" )
15441547 {
1545- return std::nullopt;
1548+ assign_to->string = value;
15461549 }
1550+ else if ( attrib == "suffix" )
1551+ {
1552+ if ( value == "u" || value == "U" )
1553+ {
1554+ // By default we promote signed native encodings of the integer literals,
1555+ // but we could be prompted to go unsigned instead.
1556+ assign_to->enc_unsigned = true;
1557+ }
1558+ }
1559+ }
1560+ };
1561+ // Base 10 integer token.
1562+ {
1563+ auto seq = lexer.MakeStep <COSRuntimeEnv::SerializedStep> ();
15471564
1548- while ( pt.GetRemainder() > 0 )
1565+ auto prelude = lexer.MakeStep <COSRuntimeEnv::StepProgrammableToken> ();
1566+ prelude.callback =
1567+ []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
15491568 {
1550- size_t oldoff = pt.GetOffset();
1569+ const char *startdata = pt.GetCurrentData();
1570+ size_t startoff = pt.GetOffset();
15511571
1552- auto ucp = pt.ReadCharacter();
1572+ if ( pt.GetRemainder() == 0 )
1573+ return std::nullopt;
15531574
1554- bool validchar = is_dec_base10( ucp );
1575+ auto first_ucp = pt.ReadCharacter();
15551576
1556- if ( validchar == false )
1577+ if ( is_dec_base10_nonzero( first_ucp ) == false )
15571578 {
1558- pt.SetOffset( oldoff );
1559- break;
1579+ return std::nullopt;
15601580 }
1561- }
15621581
1563- size_t cplen = ( pt.GetOffset() - startoff );
1582+ while ( pt.GetRemainder() > 0 )
1583+ {
1584+ size_t oldoff = pt.GetOffset();
15641585
1565- if ( cplen == 0 )
1566- return std::nullopt;
1586+ auto ucp = pt.ReadCharacter();
15671587
1568- return eir::FixedString( startdata, cplen );
1569- }
1570- );
1571- {
1572- struct intb10_dispatcher
1573- {
1574- static inline void AssignAttributeTo( IntegerLiteral *assign_to, const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
1575- {
1576- if ( attrib == "str" )
1577- {
1578- assign_to->int_type = IntegerLiteral::intType::BASE10;
1579- assign_to->string = value;
1588+ bool validchar = is_dec_base10( ucp );
1589+
1590+ if ( validchar == false )
1591+ {
1592+ pt.SetOffset( oldoff );
1593+ break;
1594+ }
15801595 }
1581- }
1582- };
1583- auto& numprod = *lexer.GetNamedProduction( "intliteral" ).GetLastStep();
1584- numprod.attribute_key = "str";
1585- numprod.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, intb10_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects );
1596+
1597+ size_t cplen = ( pt.GetOffset() - startoff );
1598+
1599+ if ( cplen == 0 )
1600+ return std::nullopt;
1601+
1602+ return eir::FixedString( startdata, cplen );
1603+ };
1604+ prelude.attribute_key = "str";
1605+
1606+ lexer.AddStepInto( seq, std::move( prelude ) );
1607+ assert( lexer.CompileInto( compiler, seq, "intsuffix^0:1" ) != nullptr );
1608+
1609+ seq.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, integer_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, IntegerLiteral::intType::BASE10 );
1610+
1611+ lexer.AddStep( "intliteral", std::move( seq ) );
15861612 }
15871613 // Base 16 integer token.
1588- lexer.AddProgrammableTokenStep( "intliteral",
1589- []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
1590- {
1591- if ( pt.GetRemainder() == 0 )
1592- return std::nullopt;
1614+ {
1615+ auto seq = lexer.MakeStep <COSRuntimeEnv::SerializedStep> ();
15931616
1594- if ( pt.ReadCharacter() != '0' )
1595- return std::nullopt;
1617+ auto prelude = lexer.MakeStep <COSRuntimeEnv::StepProgrammableToken> ();
1618+ prelude.callback =
1619+ []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
1620+ {
1621+ if ( pt.GetRemainder() == 0 )
1622+ return std::nullopt;
1623+
1624+ if ( pt.ReadCharacter() != '0' )
1625+ return std::nullopt;
15961626
1597- if ( pt.GetRemainder() == 0 )
1598- return std::nullopt;
1627+ if ( pt.GetRemainder() == 0 )
1628+ return std::nullopt;
15991629
1600- auto hex_spec = pt.ReadCharacter();
1630+ auto hex_spec = pt.ReadCharacter();
16011631
1602- if ( hex_spec != 'x' && hex_spec != 'X' )
1603- return std::nullopt;
1632+ if ( hex_spec != 'x' && hex_spec != 'X' )
1633+ return std::nullopt;
16041634
1605- const char *startdata = pt.GetCurrentData();
1606- size_t startoff = pt.GetOffset();
1635+ const char *startdata = pt.GetCurrentData();
1636+ size_t startoff = pt.GetOffset();
16071637
1608- while ( pt.GetRemainder() > 0 )
1609- {
1610- size_t oldoff = pt.GetOffset();
1638+ while ( pt.GetRemainder() > 0 )
1639+ {
1640+ size_t oldoff = pt.GetOffset();
16111641
1612- auto ucp = pt.ReadCharacter();
1642+ auto ucp = pt.ReadCharacter();
16131643
1614- bool validchar = is_dec_base16( ucp );
1644+ bool validchar = is_dec_base16( ucp );
16151645
1616- if ( validchar == false )
1617- {
1618- pt.SetOffset( oldoff );
1619- break;
1646+ if ( validchar == false )
1647+ {
1648+ pt.SetOffset( oldoff );
1649+ break;
1650+ }
16201651 }
1621- }
16221652
1623- size_t cplen = ( pt.GetOffset() - startoff );
1653+ size_t cplen = ( pt.GetOffset() - startoff );
16241654
1625- if ( cplen == 0 )
1626- return std::nullopt;
1655+ if ( cplen == 0 )
1656+ return std::nullopt;
16271657
1628- return eir::FixedString( startdata, cplen );
1629- }
1630- );
1631- {
1632- struct intb16_dispatcher
1633- {
1634- static inline void AssignAttributeTo( IntegerLiteral *assign_to, const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
1635- {
1636- if ( attrib == "str" )
1637- {
1638- assign_to->int_type = IntegerLiteral::intType::HEX;
1639- assign_to->string = value;
1640- }
1641- }
1642- };
1643- auto& numprod = *lexer.GetNamedProduction( "intliteral" ).GetLastStep();
1644- numprod.attribute_key = "str";
1645- numprod.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, intb16_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects );
1658+ return eir::FixedString( startdata, cplen );
1659+ };
1660+ prelude.attribute_key = "str";
1661+
1662+ lexer.AddStepInto( seq, std::move( prelude ) );
1663+ assert( lexer.CompileInto( compiler, seq, "intsuffix^0:1" ) != nullptr );
1664+
1665+ seq.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, integer_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, IntegerLiteral::intType::HEX );
1666+
1667+ lexer.AddStep( "intliteral", std::move( seq ) );
16461668 }
16471669 // Base 2 integer token.
1648- lexer.AddProgrammableTokenStep( "intliteral",
1649- []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
1650- {
1651- if ( pt.GetRemainder() == 0 )
1652- return std::nullopt;
1670+ {
1671+ auto seq = lexer.MakeStep <COSRuntimeEnv::SerializedStep> ();
16531672
1654- if ( pt.ReadCharacter() != '0' )
1655- return std::nullopt;
1673+ auto prelude = lexer.MakeStep <COSRuntimeEnv::StepProgrammableToken> ();
1674+ prelude.callback =
1675+ []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
1676+ {
1677+ if ( pt.GetRemainder() == 0 )
1678+ return std::nullopt;
1679+
1680+ if ( pt.ReadCharacter() != '0' )
1681+ return std::nullopt;
16561682
1657- if ( pt.GetRemainder() == 0 )
1658- return std::nullopt;
1683+ if ( pt.GetRemainder() == 0 )
1684+ return std::nullopt;
16591685
1660- auto bin_spec = pt.ReadCharacter();
1686+ auto bin_spec = pt.ReadCharacter();
16611687
1662- if ( bin_spec != 'b' && bin_spec != 'B' )
1663- return std::nullopt;
1688+ if ( bin_spec != 'b' && bin_spec != 'B' )
1689+ return std::nullopt;
16641690
1665- const char *startdata = pt.GetCurrentData();
1666- size_t startoff = pt.GetOffset();
1691+ const char *startdata = pt.GetCurrentData();
1692+ size_t startoff = pt.GetOffset();
16671693
1668- while ( pt.GetRemainder() > 0 )
1669- {
1670- size_t oldoff = pt.GetOffset();
1694+ while ( pt.GetRemainder() > 0 )
1695+ {
1696+ size_t oldoff = pt.GetOffset();
16711697
1672- auto ucp = pt.ReadCharacter();
1698+ auto ucp = pt.ReadCharacter();
16731699
1674- bool validchar = is_dec_base16( ucp );
1700+ bool validchar = is_dec_base16( ucp );
16751701
1676- if ( validchar == false )
1677- {
1678- pt.SetOffset( oldoff );
1679- break;
1702+ if ( validchar == false )
1703+ {
1704+ pt.SetOffset( oldoff );
1705+ break;
1706+ }
16801707 }
1681- }
16821708
1683- size_t cplen = ( pt.GetOffset() - startoff );
1709+ size_t cplen = ( pt.GetOffset() - startoff );
16841710
1685- if ( cplen == 0 )
1686- return std::nullopt;
1711+ if ( cplen == 0 )
1712+ return std::nullopt;
16871713
1688- return eir::FixedString( startdata, cplen );
1689- }
1690- );
1691- {
1692- struct intb2_dispatcher
1693- {
1694- static inline void AssignAttributeTo( IntegerLiteral *assign_to, const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
1695- {
1696- if ( attrib == "str" )
1697- {
1698- assign_to->int_type = IntegerLiteral::intType::BINARY;
1699- assign_to->string = value;
1700- }
1701- }
1702- };
1703- auto& numprod = *lexer.GetNamedProduction( "intliteral" ).GetLastStep();
1704- numprod.attribute_key = "str";
1705- numprod.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, intb2_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects );
1714+ return eir::FixedString( startdata, cplen );
1715+ };
1716+ prelude.attribute_key = "str";
1717+
1718+ lexer.AddStepInto( seq, std::move( prelude ) );
1719+ assert( lexer.CompileInto( compiler, seq, "intsuffix^0:1" ) != nullptr );
1720+
1721+ seq.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, integer_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, IntegerLiteral::intType::BINARY );
1722+
1723+ lexer.AddStep( "intliteral", std::move( seq ) );
17061724 }
17071725 // Base 8 integer token.
1708- lexer.AddProgrammableTokenStep( "intliteral",
1709- []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
1710- {
1711- if ( pt.GetRemainder() == 0 )
1712- return std::nullopt;
1726+ {
1727+ auto seq = lexer.MakeStep <COSRuntimeEnv::SerializedStep> ();
17131728
1714- const char *startdata = pt.GetCurrentData();
1715- size_t startoff = pt.GetOffset();
1729+ auto prelude = lexer.MakeStep <COSRuntimeEnv::StepProgrammableToken> ();
1730+ prelude.callback =
1731+ []( COSRuntimeEnv::LexingPoint& pt ) -> std::optional <eir::FixedString <char>>
1732+ {
1733+ if ( pt.GetRemainder() == 0 )
1734+ return std::nullopt;
17161735
1717- if ( pt.ReadCharacter() != '0' )
1718- return std::nullopt;
1736+ const char *startdata = pt.GetCurrentData();
1737+ size_t startoff = pt.GetOffset();
1738+
1739+ if ( pt.ReadCharacter() != '0' )
1740+ return std::nullopt;
17191741
1720- while ( pt.GetRemainder() > 0 )
1721- {
1722- size_t oldoff = pt.GetOffset();
1742+ while ( pt.GetRemainder() > 0 )
1743+ {
1744+ size_t oldoff = pt.GetOffset();
17231745
1724- auto ucp = pt.ReadCharacter();
1746+ auto ucp = pt.ReadCharacter();
17251747
1726- bool validchar = is_dec_base8( ucp );
1748+ bool validchar = is_dec_base8( ucp );
17271749
1728- if ( validchar == false )
1729- {
1730- pt.SetOffset( oldoff );
1731- break;
1750+ if ( validchar == false )
1751+ {
1752+ pt.SetOffset( oldoff );
1753+ break;
1754+ }
17321755 }
1733- }
17341756
1735- size_t cplen = ( pt.GetOffset() - startoff );
1757+ size_t cplen = ( pt.GetOffset() - startoff );
17361758
1737- if ( cplen == 0 )
1738- return std::nullopt;
1759+ if ( cplen == 0 )
1760+ return std::nullopt;
17391761
1740- return eir::FixedString( startdata, cplen );
1741- }
1742- );
1743- {
1744- struct intb8_dispatcher
1745- {
1746- static inline void AssignAttributeTo( IntegerLiteral *assign_to, const eir::FixedString <char>& attrib, const eir::FixedString <char>& value )
1747- {
1748- if ( attrib == "str" )
1749- {
1750- assign_to->int_type = IntegerLiteral::intType::OCTAL;
1751- assign_to->string = value;
1752- }
1753- }
1754- };
1755- auto& numprod = *lexer.GetNamedProduction( "intliteral" ).GetLastStep();
1756- numprod.attribute_key = "str";
1757- numprod.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, intb8_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects );
1762+ return eir::FixedString( startdata, cplen );
1763+ };
1764+ prelude.attribute_key = "str";
1765+
1766+ lexer.AddStepInto( seq, std::move( prelude ) );
1767+ assert( lexer.CompileInto( compiler, seq, "intsuffix^0:1" ) != nullptr );
1768+
1769+ seq.setSelector <direct_obj_build_selector <char, IntegerLiteral, COSNode, integer_dispatcher, COSRuntimeEnv>> ( &lexer.GetRuntimeEnvironment(), &objects, IntegerLiteral::intType::OCTAL );
1770+
1771+ lexer.AddStep( "intliteral", std::move( seq ) );
17581772 }
17591773 assert( lexer.CompileProduction( compiler, "literal", "intliteral" ) == true );
17601774 // Boolean literals.
--- eircompile/include/eircompile/lexing.h (revision 96)
+++ eircompile/include/eircompile/lexing.h (revision 97)
@@ -31,6 +31,7 @@
3131
3232 template <typename cStepType, typename envType>
3333 concept CompilationTargetStep = (
34+ std::derived_from <typename std::remove_cvref <cStepType>::type, typename envType::SerializedStep> ||
3435 std::derived_from <typename std::remove_cvref <cStepType>::type, typename envType::StepAlternatives> ||
3536 std::derived_from <typename std::remove_cvref <cStepType>::type, typename envType::StepProceduralAlternatives> ||
3637 std::derived_from <typename std::remove_cvref <cStepType>::type, typename envType::StepProceduralSequence> ||
--- testcompiler/src/cos_tests.cpp (revision 96)
+++ testcompiler/src/cos_tests.cpp (revision 97)
@@ -64,6 +64,7 @@
6464 assert( init != nullptr );
6565 assert( init->int_type == IntegerLiteral::intType::BASE10 );
6666 assert( init->string == "123" );
67+ assert( init->enc_unsigned == false );
6768
6869 init->Delete();
6970 root->Delete();
@@ -131,6 +132,7 @@
131132 assert( init->postdot == "14" );
132133 assert( init->exp_positive_sign == true );
133134 assert( init->base10_exponent.IsEmpty() == true );
135+ assert( init->valType == DecimalLiteral::suffixType::DOUBLE );
134136
135137 init->Delete();
136138 root->Delete();
@@ -403,6 +405,75 @@
403405 init->Delete();
404406 root->Delete();
405407 }
408+
409+ // 12)
410+ {
411+ COSNode *_root = cosEnv.Compile( "float fval = 2.0f;" );
412+
413+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
414+
415+ assert( root != nullptr );
416+
417+ SpecifierString *type = dynamic_cast <SpecifierString*> ( root->GetType() );
418+
419+ assert( type != nullptr );
420+ assert( type->string == "float" );
421+
422+ type->Delete();
423+
424+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->GetName() );
425+
426+ assert( name != nullptr );
427+ assert( name->string == "fval" );
428+
429+ name->Delete();
430+
431+ DecimalLiteral *init = dynamic_cast <DecimalLiteral*> ( root->GetInitializer() );
432+
433+ assert( init != nullptr );
434+ assert( init->dec_type == DecimalLiteral::decimalType::BASE10 );
435+ assert( init->predot == "2" );
436+ assert( init->postdot == "0" );
437+ assert( init->exp_positive_sign == true );
438+ assert( init->base10_exponent.IsEmpty() == true );
439+ assert( init->valType == DecimalLiteral::suffixType::FLOAT );
440+
441+ init->Delete();
442+ root->Delete();
443+ }
444+
445+ // 13)
446+ {
447+ COSNode *_root = cosEnv.Compile( "uint unsig = 102u;" );
448+
449+ DeclarationStatement *root = dynamic_cast <DeclarationStatement*> ( _root );
450+
451+ assert( root != nullptr );
452+
453+ SpecifierString *type = dynamic_cast <SpecifierString*> ( root->GetType() );
454+
455+ assert( type != nullptr );
456+ assert( type->string == "uint" );
457+
458+ type->Delete();
459+
460+ SpecifierString *name = dynamic_cast <SpecifierString*> ( root->GetName() );
461+
462+ assert( name != nullptr );
463+ assert( name->string == "unsig" );
464+
465+ name->Delete();
466+
467+ IntegerLiteral *init = dynamic_cast <IntegerLiteral*> ( root->GetInitializer() );
468+
469+ assert( init != nullptr );
470+ assert( init->int_type == IntegerLiteral::intType::BASE10 );
471+ assert( init->string == "102" );
472+ assert( init->enc_unsigned == true );
473+
474+ init->Delete();
475+ root->Delete();
476+ }
406477 }
407478 printf( "ok.\n" );
408479
Show on old repository browser