@@ -36,10 +36,10 @@ class type_declaration;
36
36
#line 592 "reflect.h2"
37
37
class alias_declaration ;
38
38
39
- #line 965 "reflect.h2"
39
+ #line 976 "reflect.h2"
40
40
class value_member_info ;
41
41
42
- #line 1483 "reflect.h2"
42
+ #line 1494 "reflect.h2"
43
43
}
44
44
45
45
}
@@ -674,7 +674,7 @@ auto cpp1_rule_of_zero(meta::type_declaration& t) -> void;
674
674
//
675
675
auto cpp2_struct (meta::type_declaration& t) -> void;
676
676
677
- #line 948 "reflect.h2"
677
+ #line 959 "reflect.h2"
678
678
// -----------------------------------------------------------------------
679
679
//
680
680
// "C enumerations constitute a curiously half-baked concept. ...
@@ -696,6 +696,9 @@ class value_member_info {
696
696
public: std::string name;
697
697
public: std::string type;
698
698
public: std::string value;
699
+ public: explicit value_member_info (auto const & name_, auto const & type_, auto const & value_);
700
+
701
+ #line 980 "reflect.h2"
699
702
};
700
703
701
704
auto basic_enum (
@@ -704,7 +707,7 @@ auto basic_enum(
704
707
cpp2::impl::in<bool > bitwise
705
708
) -> void;
706
709
707
- #line 1155 "reflect.h2"
710
+ #line 1166 "reflect.h2"
708
711
// -----------------------------------------------------------------------
709
712
//
710
713
// "An enum[...] is a totally ordered value type that stores a
@@ -716,7 +719,7 @@ auto basic_enum(
716
719
//
717
720
auto cpp2_enum (meta::type_declaration& t) -> void;
718
721
719
- #line 1181 "reflect.h2"
722
+ #line 1192 "reflect.h2"
720
723
// -----------------------------------------------------------------------
721
724
//
722
725
// "flag_enum expresses an enumeration that stores values
@@ -729,7 +732,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void;
729
732
//
730
733
auto flag_enum (meta::type_declaration& t) -> void;
731
734
732
- #line 1213 "reflect.h2"
735
+ #line 1224 "reflect.h2"
733
736
// -----------------------------------------------------------------------
734
737
//
735
738
// "As with void*, programmers should know that unions [...] are
@@ -756,14 +759,14 @@ auto flag_enum(meta::type_declaration& t) -> void;
756
759
757
760
auto cpp2_union (meta::type_declaration& t) -> void;
758
761
759
- #line 1366 "reflect.h2"
762
+ #line 1377 "reflect.h2"
760
763
// -----------------------------------------------------------------------
761
764
//
762
765
// print - output a pretty-printed visualization of t
763
766
//
764
767
auto print (cpp2::impl::in<meta::type_declaration> t) -> void;
765
768
766
- #line 1376 "reflect.h2"
769
+ #line 1387 "reflect.h2"
767
770
// -----------------------------------------------------------------------
768
771
//
769
772
// apply_metafunctions
@@ -774,7 +777,7 @@ auto print(cpp2::impl::in<meta::type_declaration> t) -> void;
774
777
auto const & error
775
778
) -> bool;
776
779
777
- #line 1483 "reflect.h2"
780
+ #line 1494 "reflect.h2"
778
781
}
779
782
780
783
}
@@ -1597,6 +1600,9 @@ auto cpp1_rule_of_zero(meta::type_declaration& t) -> void
1597
1600
#line 930 "reflect.h2"
1598
1601
auto cpp2_struct (meta::type_declaration& t) -> void
1599
1602
{
1603
+ std::string ctor_params {};
1604
+ std::string ctor_inits {};
1605
+
1600
1606
for ( auto & m : CPP2_UFCS (get_members)(t) )
1601
1607
{
1602
1608
CPP2_UFCS (require)(m, CPP2_UFCS (make_public)(m),
@@ -1608,11 +1614,24 @@ auto cpp2_struct(meta::type_declaration& t) -> void
1608
1614
CPP2_UFCS (require)(t, !(CPP2_UFCS (has_name)(cpp2::move (mf), " operator=" )),
1609
1615
" a struct may not have a user-defined operator=" );
1610
1616
}
1617
+ else {if (CPP2_UFCS (is_object)(m)) {
1618
+ ctor_params += (cpp2::to_string (CPP2_UFCS (name)(m)) + " _, " );
1619
+ ctor_inits += (cpp2::to_string (CPP2_UFCS (name)(m)) + " = " + cpp2::to_string (CPP2_UFCS (name)(m)) + " _; " );
1620
+ }}
1611
1621
}
1612
1622
CPP2_UFCS (cpp1_rule_of_zero)(t);
1623
+
1624
+ // However, to enable construction from values requires a
1625
+ // constructor... an exception to the rule of zero
1626
+ CPP2_UFCS (add_member)(t, (" operator=: (out this, " + cpp2::to_string (cpp2::move (ctor_params)) + " ) = { " + cpp2::to_string (cpp2::move (ctor_inits)) + " }" ));
1613
1627
}
1614
1628
1615
- #line 971 "reflect.h2"
1629
+ value_member_info::value_member_info (auto const & name_, auto const & type_, auto const & value_)
1630
+ : name{ name_ }
1631
+ , type{ type_ }
1632
+ , value{ value_ }{}
1633
+
1634
+ #line 982 "reflect.h2"
1616
1635
auto basic_enum (
1617
1636
meta::type_declaration& t,
1618
1637
auto const & nextval,
@@ -1637,7 +1656,7 @@ auto basic_enum(
1637
1656
{
1638
1657
std::string value{" -1" };
1639
1658
1640
- #line 994 "reflect.h2"
1659
+ #line 1005 "reflect.h2"
1641
1660
for (
1642
1661
auto const & m : CPP2_UFCS (get_members)(t) )
1643
1662
if ( CPP2_UFCS (is_member_object)(m))
@@ -1676,7 +1695,7 @@ std::string value{"-1"};
1676
1695
}
1677
1696
}
1678
1697
1679
- #line 1031 "reflect.h2"
1698
+ #line 1042 "reflect.h2"
1680
1699
if ((CPP2_UFCS (empty)(enumerators))) {
1681
1700
CPP2_UFCS (error)(t, " an enumeration must contain at least one enumerator value" );
1682
1701
return ;
@@ -1722,7 +1741,7 @@ std::string value{"-1"};
1722
1741
}
1723
1742
}
1724
1743
1725
- #line 1077 "reflect.h2"
1744
+ #line 1088 "reflect.h2"
1726
1745
// 2. Replace: Erase the contents and replace with modified contents
1727
1746
//
1728
1747
// Note that most values and functions are declared as '==' compile-time values, i.e. Cpp1 'constexpr'
@@ -1770,7 +1789,7 @@ std::string to_string{" to_string: (this) -> std::string = { \n"};
1770
1789
1771
1790
// Provide a 'to_string' function to print enumerator name(s)
1772
1791
1773
- #line 1122 "reflect.h2"
1792
+ #line 1133 "reflect.h2"
1774
1793
{
1775
1794
if (bitwise) {
1776
1795
to_string += " _ret : std::string = \" (\" ;\n " ;
@@ -1802,10 +1821,10 @@ std::string to_string{" to_string: (this) -> std::string = { \n"};
1802
1821
CPP2_UFCS (add_member)(t, cpp2::move (to_string));
1803
1822
}
1804
1823
}
1805
- #line 1152 "reflect.h2"
1824
+ #line 1163 "reflect.h2"
1806
1825
}
1807
1826
1808
- #line 1164 "reflect.h2"
1827
+ #line 1175 "reflect.h2"
1809
1828
auto cpp2_enum (meta::type_declaration& t) -> void
1810
1829
{
1811
1830
// Let basic_enum do its thing, with an incrementing value generator
@@ -1822,7 +1841,7 @@ auto cpp2_enum(meta::type_declaration& t) -> void
1822
1841
);
1823
1842
}
1824
1843
1825
- #line 1191 "reflect.h2"
1844
+ #line 1202 "reflect.h2"
1826
1845
auto flag_enum (meta::type_declaration& t) -> void
1827
1846
{
1828
1847
// Let basic_enum do its thing, with a power-of-two value generator
@@ -1844,7 +1863,7 @@ auto flag_enum(meta::type_declaration& t) -> void
1844
1863
);
1845
1864
}
1846
1865
1847
- #line 1237 "reflect.h2"
1866
+ #line 1248 "reflect.h2"
1848
1867
auto cpp2_union (meta::type_declaration& t) -> void
1849
1868
{
1850
1869
std::vector<value_member_info> alternatives {};
@@ -1853,7 +1872,7 @@ auto value{0};
1853
1872
1854
1873
// 1. Gather: All the user-written members, and find/compute the max size
1855
1874
1856
- #line 1244 "reflect.h2"
1875
+ #line 1255 "reflect.h2"
1857
1876
for (
1858
1877
1859
1878
auto const & m : CPP2_UFCS (get_members)(t) ) { do
@@ -1879,7 +1898,7 @@ auto value{0};
1879
1898
} while (false ); ++value; }
1880
1899
}
1881
1900
1882
- #line 1268 "reflect.h2"
1901
+ #line 1279 "reflect.h2"
1883
1902
std::string discriminator_type {};
1884
1903
if (cpp2::impl::cmp_less (CPP2_UFCS (ssize)(alternatives),std::numeric_limits<cpp2::i8 >::max ())) {
1885
1904
discriminator_type = " i8" ;
@@ -1894,7 +1913,7 @@ auto value{0};
1894
1913
discriminator_type = " i64" ;
1895
1914
}}}
1896
1915
1897
- #line 1283 "reflect.h2"
1916
+ #line 1294 "reflect.h2"
1898
1917
// 2. Replace: Erase the contents and replace with modified contents
1899
1918
1900
1919
CPP2_UFCS (remove_marked_members)(t);
@@ -1903,7 +1922,7 @@ std::string storage{" _storage: cpp2::aligned_storage<cpp2::max( "};
1903
1922
1904
1923
// Provide storage
1905
1924
1906
- #line 1289 "reflect.h2"
1925
+ #line 1300 "reflect.h2"
1907
1926
{
1908
1927
for (
1909
1928
auto const & e : alternatives ) {
@@ -1923,7 +1942,7 @@ std::string storage{" _storage: cpp2::aligned_storage<cpp2::max( "};
1923
1942
}
1924
1943
1925
1944
// Provide discriminator
1926
- #line 1307 "reflect.h2"
1945
+ #line 1318 "reflect.h2"
1927
1946
CPP2_UFCS (add_member)(t, (" _discriminator: " + cpp2::to_string (cpp2::move (discriminator_type)) + " = -1;\n " ));
1928
1947
1929
1948
// Add the alternatives: is_alternative, get_alternative, and set_alternative
@@ -1945,7 +1964,7 @@ std::string destroy{" private _destroy: (inout this) = {\n"};
1945
1964
1946
1965
// Add destroy
1947
1966
1948
- #line 1326 "reflect.h2"
1967
+ #line 1337 "reflect.h2"
1949
1968
{
1950
1969
for (
1951
1970
auto const & a : alternatives ) {
@@ -1959,7 +1978,7 @@ std::string destroy{" private _destroy: (inout this) = {\n"};
1959
1978
}
1960
1979
1961
1980
// Add the destructor
1962
- #line 1338 "reflect.h2"
1981
+ #line 1349 "reflect.h2"
1963
1982
CPP2_UFCS (add_member)(t, " operator=: (move this) = { _destroy(); _ = this; }" );
1964
1983
1965
1984
// Add default constructor
@@ -1969,7 +1988,7 @@ std::string value_set{""};
1969
1988
1970
1989
// Add copy/move construction and assignment
1971
1990
1972
- #line 1345 "reflect.h2"
1991
+ #line 1356 "reflect.h2"
1973
1992
{
1974
1993
for (
1975
1994
auto const & a : cpp2::move (alternatives) ) {
@@ -1989,16 +2008,16 @@ std::string value_set{""};
1989
2008
);
1990
2009
}
1991
2010
}
1992
- #line 1363 "reflect.h2"
2011
+ #line 1374 "reflect.h2"
1993
2012
}
1994
2013
1995
- #line 1370 "reflect.h2"
2014
+ #line 1381 "reflect.h2"
1996
2015
auto print (cpp2::impl::in<meta::type_declaration> t) -> void
1997
2016
{
1998
2017
std::cout << CPP2_UFCS (print)(t) << " \n " ;
1999
2018
}
2000
2019
2001
- #line 1380 "reflect.h2"
2020
+ #line 1391 "reflect.h2"
2002
2021
[[nodiscard]] auto apply_metafunctions (
2003
2022
declaration_node& n,
2004
2023
type_declaration& rtype,
@@ -2101,7 +2120,7 @@ auto print(cpp2::impl::in<meta::type_declaration> t) -> void
2101
2120
return true ;
2102
2121
}
2103
2122
2104
- #line 1483 "reflect.h2"
2123
+ #line 1494 "reflect.h2"
2105
2124
}
2106
2125
2107
2126
}
0 commit comments