-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial basic support for namespaces and user-defined types
Added initial basic support. Includes: - access-specifiers: public, protected, private - defaults: in type scope (aka members), types and functions are public by default, objects (data members) are private by default - this-specifiers: implicit, virtual, override, final (but can't use them much since we don't have inheritance syntax yet, see next list) - explicit `this` parameters (where the this-specifiers go) NOT included yet: - special member functions (`operator=`) - inheritance / base classes - metaclass functions to apply checks, defaults, and generated code (that'll be last...) This checkin also changes the null/subscript/comparison checking opt-out command-line option from `/xxx-checks-` (which was only because the initial default was to opt into the checks) to `/no-xxx-checks`
- Loading branch information
Showing
16 changed files
with
589 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
N: namespace = { | ||
|
||
myclass : type = { | ||
|
||
f: (virtual this, x: int) = { | ||
std::cout << "N::myclass::f with (x)$\n"; | ||
} | ||
|
||
data: int; | ||
|
||
nested : type = { | ||
g: () = std::cout << "N::myclass::nested::g\n"; | ||
} | ||
|
||
f1: <T , U > (t:T, u:U) -> _ = t+u; | ||
f2: <T:type, U:type> (t:T, u:U) -> _ = t+u; | ||
f3: <T:_ , U:_ > () -> _ = T+U; | ||
f4: <T:i8 , U:i16 > () -> _ = T+U; | ||
|
||
} | ||
|
||
} | ||
|
||
main: () = { | ||
x: N::myclass = (); | ||
x.f(53); | ||
N::myclass::nested::g(); | ||
std::cout << "f1: (x.f1(1,1))$\n"; | ||
std::cout << "f2: (x.f2(2,2))$\n"; | ||
std::cout << "f3: (x.f3<3,3>())$\n"; | ||
std::cout << "f4: (x.f4<4,4>())$\n"; | ||
} |
6 changes: 6 additions & 0 deletions
6
regression-tests/test-results/clang-12/pure2-types-basics.cpp.execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
N::myclass::f with 53 | ||
N::myclass::nested::g | ||
f1: 2 | ||
f2: 4 | ||
f3: 6 | ||
f4: 8 |
Empty file.
6 changes: 6 additions & 0 deletions
6
regression-tests/test-results/gcc-10/pure2-types-basics.cpp.execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
N::myclass::f with 53 | ||
N::myclass::nested::g | ||
f1: 2 | ||
f2: 4 | ||
f3: 6 | ||
f4: 8 |
Empty file.
6 changes: 6 additions & 0 deletions
6
regression-tests/test-results/msvc-2022/pure2-types-basics.cpp.execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
N::myclass::f with 53 | ||
N::myclass::nested::g | ||
f1: 2 | ||
f2: 4 | ||
f3: 6 | ||
f4: 8 |
1 change: 1 addition & 0 deletions
1
regression-tests/test-results/msvc-2022/pure2-types-basics.cpp.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pure2-types-basics.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
#define CPP2_USE_MODULES Yes | ||
|
||
#include "cpp2util.h" | ||
|
||
|
||
#line 2 "pure2-types-basics.cpp2" | ||
namespace N { | ||
class myclass; | ||
}; | ||
#line 25 "pure2-types-basics.cpp2" | ||
auto main() -> int; | ||
|
||
//=== Cpp2 definitions ========================================================== | ||
|
||
#line 1 "pure2-types-basics.cpp2" | ||
|
||
namespace N { | ||
|
||
class myclass { | ||
|
||
public: virtual auto f(cpp2::in<int> x) const -> void{ | ||
std::cout << "N::myclass::f with " + cpp2::to_string(x) + "\n"; | ||
} | ||
|
||
private: int data; | ||
|
||
public: class nested { | ||
public: static auto g() -> void { std::cout << "N::myclass::nested::g\n"; } | ||
}; | ||
|
||
public: template<typename T, typename U> [[nodiscard]] static auto f1(T const& t, U const& u) -> auto { return t + u; } | ||
public: template<typename T, typename U> [[nodiscard]] static auto f2(T const& t, U const& u) -> auto { return t + u; } | ||
public: template<auto T, auto U> [[nodiscard]] static auto f3() -> auto { return T + U; } | ||
public: template<cpp2::i8 T, cpp2::i16 U> [[nodiscard]] static auto f4() -> auto { return T + U; } | ||
|
||
}; | ||
|
||
}; | ||
|
||
auto main() -> int{ | ||
N::myclass x {}; | ||
CPP2_UFCS(f, x, 53); | ||
N::myclass::nested::g(); | ||
std::cout << "f1: " + cpp2::to_string(CPP2_UFCS(f1, x, 1, 1)) + "\n"; | ||
std::cout << "f2: " + cpp2::to_string(CPP2_UFCS(f2, x, 2, 2)) + "\n"; | ||
std::cout << "f3: " + cpp2::to_string(CPP2_UFCS_TEMPLATE_0(f3, (<3,3>), x)) + "\n"; | ||
std::cout << "f4: " + cpp2::to_string(CPP2_UFCS_TEMPLATE_0(f4, (<4,4>), std::move(x))) + "\n"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pure2-types-basics.cpp2... ok (all Cpp2, passes safety checks) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
258190e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Now the more adventurous of us can start using Cpp2 in an actual code base and start seeing benefits.
Being limited to the global namespace, one could only use it in an actual code base in tests. Considering that, I'm surprised how much some tried to push
cppfront
to the limits. Specially @filipsajdak.I just wish we at least had a cheat sheet of the Cpp2 syntax.
258190e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @JohelEGP! I am working on providing my cheat sheet - I have implemented some code without classes and will rewrite it to the cpp2 now. That should give me even more understanding about new use cases and new idioms.
I hope I will find some time to push that work this week.
258190e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently I have a collection of test cases like the following #266 (comment) - that help me learn how cppfront work.
258190e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/ntrel/cpp2 has some notes.
258190e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also started to write some documentation sometime ago here but stopped at just functions, will continue it again sometime soon.
(there's a mistake where i describe
forward
parameter passing, ignore it pls)258190e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.