Add tint::Cloneable base class

The CloneContext was previously dealing with pointers to CastableBase, which has no guarantees that the object was actually cloneable.
Add a Cloneable base class that CloneContext can use instead.

Improves readability and produces cleaner compiler errors if you try to clone a non-cloneable object.

Change-Id: I4352fc5dab3da434e4ab160a54c4c82d50e427b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41722
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2021-02-17 13:17:39 +00:00
committed by Commit Bot service account
parent f81df124f6
commit 52296de528
5 changed files with 73 additions and 86 deletions

View File

@@ -19,7 +19,7 @@
#include <string>
#include <vector>
#include "src/castable.h"
#include "src/clone_context.h"
#include "src/source.h"
namespace tint {
@@ -36,16 +36,10 @@ class Info;
namespace ast {
/// AST base class node
class Node : public Castable<Node> {
class Node : public Castable<Node, Cloneable> {
public:
~Node() override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
virtual Node* Clone(CloneContext* ctx) const = 0;
/// @returns the node source data
const Source& source() const { return source_; }