AST: Add `reconstruct_type()` method
-
ast: reconstruct: Add base for reconstructing and asserting different IDs
-
ast: Add reconstruct_type() method
-
ast: builder: Remove ASTTypeBuilder
This is the first step of adding the
reconstruct_*()methods as discussed on Zulip. The goal is to have something similar toclone_*(), but each time reconstructing the node and assigning it a differentNodeID- and modifyingclone_*()where necessary to ensure the node ID stays the same. Subsequently, this also deletes theASTTypeBuildervisitor as it is replaced by simple calls to.reconstruct_type()instead.
TLDR, it looks like you can override functions with functions that return a different type, if you're not overriding a virtual function
https://godbolt.org/z/TW1rjbMba
#include <memory>
class A
{
public:
std::unique_ptr<A> clone()
{
return std::make_unique<A> ();
}
};
class B: public A
{
public:
std::unique_ptr<B> clone()
{
return std::make_unique<B> ();
}
};
int main() {
A w;
std::unique_ptr<A> x = w.clone ();
B y;
std::unique_ptr<A> z = y.clone ();
}
So clone_* methods shouldn't need different names, especially since std::unique_ptr has a constructor that can do upcasting
The "^^^" comment was supposed to be a reply to https://github.com/Rust-GCC/gccrs/pull/3799#discussion_r2098520527
We could use deducing-this to great effect here, but that's a C++23 thing (GCC 14)
Looks like auto-merge didn't work