Skip to content

Commit 35fa7f0

Browse files
committed
Add *value meta functions, and don't mark copy/move ctors explicit, closes hsutter#375
Generated code now doesn't get tacked together as a very long emitted line - which is legal code, but isn't visually pleasing or readable. This matters more in this commit now that we have meta functions that generate multiple functions in the same type.
1 parent 8c0915c commit 35fa7f0

20 files changed

+409
-48
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
widget: @value type = {
3+
val: int = 0;
4+
operator=: (out this, i: int) = { val = i; }
5+
}
6+
7+
w_widget: @weakly_ordered_value type = {
8+
val: int = 0;
9+
operator=: (out this, i: int) = { val = i; }
10+
}
11+
12+
p_widget: @partially_ordered_value type = {
13+
val: int = 0;
14+
operator=: (out this, i: int) = { val = i; }
15+
}
16+
17+
main: () = {
18+
test<widget>();
19+
test<w_widget>();
20+
test<p_widget>();
21+
}
22+
23+
test: <T> () = {
24+
// should be default constructible
25+
a: T = ();
26+
27+
// widget should be comparable
28+
b: T = 2;
29+
if (a<b) {
30+
std::cout << "less ";
31+
}
32+
else {
33+
std::cout << "more ";
34+
}
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
less less less

regression-tests/test-results/clang-12/pure2-types-value-types-via-meta-functions.cpp.output

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
less less less

regression-tests/test-results/gcc-10/pure2-types-value-types-via-meta-functions.cpp.output

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
less less less
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pure2-types-value-types-via-meta-functions.cpp

regression-tests/test-results/pure2-types-inheritance.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,22 @@ class Cyborg;
2828
#line 2 "pure2-types-inheritance.cpp2"
2929
class Human {
3030
public: virtual auto speak() const -> void = 0;
31+
3132
public: virtual ~Human();
33+
3234
public: Human() = default;
3335
public: Human(Human const&) = delete;
3436
public: auto operator=(Human const&) -> void = delete;
35-
3637
#line 4 "pure2-types-inheritance.cpp2"
3738
};
3839

3940
namespace N {
4041
template<int I> class Machine {
4142
public: explicit Machine(cpp2::in<std::string> id);
4243
public: virtual auto work() const -> void = 0;
44+
4345
public: virtual ~Machine();
46+
4447
public: Machine(Machine const&) = delete;
4548
public: auto operator=(Machine const&) -> void = delete;
4649

@@ -88,13 +91,15 @@ auto main() -> int;
8891

8992
//=== Cpp2 function definitions =================================================
9093

91-
#line 0 "pure2-types-inheritance.cpp2"
92-
Human::~Human(){}
9394

95+
96+
Human::~Human(){}
9497
#line 6 "pure2-types-inheritance.cpp2"
9598
namespace N {
9699

97-
template <int I> Machine<I>::Machine(cpp2::in<std::string> id){}template <int I> Machine<I>::~Machine(){}
100+
template <int I> Machine<I>::Machine(cpp2::in<std::string> id){}
101+
template <int I>
102+
Machine<I>::~Machine(){}
98103

99104
#line 11 "pure2-types-inheritance.cpp2"
100105
}

regression-tests/test-results/pure2-types-ordering-via-meta-functions.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ class my_integer {
2828
public: explicit my_integer(cpp2::in<int> val);
2929
#line 4 "pure2-types-ordering-via-meta-functions.cpp2"
3030
public: auto operator=(cpp2::in<int> val) -> my_integer& ;
31+
3132
public: [[nodiscard]] auto operator<=>(my_integer const& that) const -> std::strong_ordering = default;
33+
3234
public: my_integer(my_integer const&) = delete;
3335
public: auto operator=(my_integer const&) -> void = delete;
34-
3536
#line 5 "pure2-types-ordering-via-meta-functions.cpp2"
3637
};
3738

@@ -40,10 +41,11 @@ class case_insensitive_string {
4041
public: explicit case_insensitive_string(cpp2::in<std::string> val);
4142
#line 9 "pure2-types-ordering-via-meta-functions.cpp2"
4243
public: auto operator=(cpp2::in<std::string> val) -> case_insensitive_string& ;
44+
4345
public: [[nodiscard]] auto operator<=>(case_insensitive_string const& that) const -> std::weak_ordering = default;
46+
4447
public: case_insensitive_string(case_insensitive_string const&) = delete;
4548
public: auto operator=(case_insensitive_string const&) -> void = delete;
46-
4749
#line 10 "pure2-types-ordering-via-meta-functions.cpp2"
4850
};
4951

@@ -52,10 +54,11 @@ class person_in_family_tree {
5254
public: explicit person_in_family_tree(cpp2::in<int> parents);
5355
#line 14 "pure2-types-ordering-via-meta-functions.cpp2"
5456
public: auto operator=(cpp2::in<int> parents) -> person_in_family_tree& ;
57+
5558
public: [[nodiscard]] auto operator<=>(person_in_family_tree const& that) const -> std::partial_ordering = default;
59+
5660
public: person_in_family_tree(person_in_family_tree const&) = delete;
5761
public: auto operator=(person_in_family_tree const&) -> void = delete;
58-
5962
#line 15 "pure2-types-ordering-via-meta-functions.cpp2"
6063
};
6164

regression-tests/test-results/pure2-types-smf-and-that-1-provide-everything.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class myclass;
1717
#line 2 "pure2-types-smf-and-that-1-provide-everything.cpp2"
1818
class myclass {
1919

20-
public: explicit myclass(myclass const& that);
20+
public: myclass(myclass const& that);
2121

2222

2323
#line 8 "pure2-types-smf-and-that-1-provide-everything.cpp2"
24-
public: explicit myclass(myclass&& that);
24+
public: myclass(myclass&& that);
2525

2626

2727
#line 13 "pure2-types-smf-and-that-1-provide-everything.cpp2"

0 commit comments

Comments
 (0)