Move castable into utils.

The Castable class is used by utils/. This Cl moves the implementation
into the utils/ folder. The `Is` and `As` methods are added into the
`tint` namespace to make usage shorter.

Change-Id: I0decedb92ebed01b6aa12d2e3efa7190742e9a33
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127402
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2023-04-19 23:52:33 +00:00 committed by Dawn LUCI CQ
parent a965f520f9
commit 12fa303899
257 changed files with 547 additions and 500 deletions

View File

@ -14,7 +14,7 @@
* Do not use C++ exceptions
* Do not use C++ RTTI.
Instead, use `tint::Castable::As<T>()` from
Instead, use `tint::utils::Castable::As<T>()` from
[src/castable.h](../src/castable.h)
* Generally, avoid `assert`. Instead, issue a [diagnostic](../src/diagnostic.h)

View File

@ -195,8 +195,6 @@ template("libtint_source_set") {
libtint_source_set("libtint_base_src") {
sources = [
"castable.cc",
"castable.h",
"debug.cc",
"debug.h",
"diagnostic/diagnostic.cc",
@ -222,6 +220,8 @@ libtint_source_set("libtint_base_src") {
"utils/bitset.h",
"utils/block_allocator.h",
"utils/bump_allocator.h",
"utils/castable.cc",
"utils/castable.h",
"utils/compiler_macros.h",
"utils/concat.h",
"utils/crc32.h",
@ -1590,6 +1590,7 @@ if (tint_build_unittests) {
"utils/bitset_test.cc",
"utils/block_allocator_test.cc",
"utils/bump_allocator_test.cc",
"utils/castable_test.cc",
"utils/crc32_test.cc",
"utils/defer_test.cc",
"utils/enum_set_test.cc",
@ -1982,7 +1983,6 @@ if (tint_build_unittests) {
tint_unittests_source_set("tint_unittests_base_src") {
sources = [
"castable_test.cc",
"debug_test.cc",
"number_test.cc",
"reflection_test.cc",

View File

@ -230,8 +230,6 @@ list(APPEND TINT_LIB_SRCS
ast/while_statement.h
ast/workgroup_attribute.cc
ast/workgroup_attribute.h
castable.cc
castable.h
clone_context.cc
clone_context.h
constant/clone_context.h
@ -517,6 +515,8 @@ list(APPEND TINT_LIB_SRCS
utils/bitset.h
utils/block_allocator.h
utils/bump_allocator.h
utils/castable.cc
utils/castable.h
utils/compiler_macros.h
utils/concat.h
utils/crc32.h
@ -882,7 +882,6 @@ if(TINT_BUILD_TESTS)
ast/variable_test.cc
ast/while_statement_test.cc
ast/workgroup_attribute_test.cc
castable_test.cc
clone_context_test.cc
constant/composite_test.cc
constant/scalar_test.cc
@ -996,6 +995,7 @@ if(TINT_BUILD_TESTS)
utils/bitset_test.cc
utils/block_allocator_test.cc
utils/bump_allocator_test.cc
utils/castable_test.cc
utils/crc32_test.cc
utils/defer_test.cc
utils/enum_set_test.cc

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// Base class for IndexAccessorExpression and MemberAccessorExpression
class AccessorExpression : public Castable<AccessorExpression, Expression> {
class AccessorExpression : public utils::Castable<AccessorExpression, Expression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A type alias type. Holds a name and pointer to another type.
class Alias final : public Castable<Alias, TypeDecl> {
class Alias final : public utils::Castable<Alias, TypeDecl> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// An assignment statement
class AssignmentStatement final : public Castable<AssignmentStatement, Statement> {
class AssignmentStatement final : public utils::Castable<AssignmentStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// The base class for all attributes
class Attribute : public Castable<Attribute, Node> {
class Attribute : public utils::Castable<Attribute, Node> {
public:
~Attribute() override;

View File

@ -43,7 +43,7 @@ enum class BinaryOp {
};
/// An binary expression
class BinaryExpression final : public Castable<BinaryExpression, Expression> {
class BinaryExpression final : public utils::Castable<BinaryExpression, Expression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A binding attribute
class BindingAttribute final : public Castable<BindingAttribute, Attribute> {
class BindingAttribute final : public utils::Castable<BindingAttribute, Attribute> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// A bitcast expression
class BitcastExpression final : public Castable<BitcastExpression, Expression> {
class BitcastExpression final : public utils::Castable<BitcastExpression, Expression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -27,7 +27,7 @@ class Attribute;
namespace tint::ast {
/// A block statement
class BlockStatement final : public Castable<BlockStatement, Statement> {
class BlockStatement final : public utils::Castable<BlockStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,8 @@
namespace tint::ast {
/// A boolean literal
class BoolLiteralExpression final : public Castable<BoolLiteralExpression, LiteralExpression> {
class BoolLiteralExpression final
: public utils::Castable<BoolLiteralExpression, LiteralExpression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A break-if statement
class BreakIfStatement final : public Castable<BreakIfStatement, Statement> {
class BreakIfStatement final : public utils::Castable<BreakIfStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// An break statement
class BreakStatement final : public Castable<BreakStatement, Statement> {
class BreakStatement final : public utils::Castable<BreakStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -27,7 +27,7 @@ class Expression;
namespace tint::ast {
/// A builtin attribute
class BuiltinAttribute final : public Castable<BuiltinAttribute, Attribute> {
class BuiltinAttribute final : public utils::Castable<BuiltinAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -29,7 +29,7 @@ namespace tint::ast {
/// * sem::Builtin
/// * sem::ValueConstructor
/// * sem::ValueConversion
class CallExpression final : public Castable<CallExpression, Expression> {
class CallExpression final : public utils::Castable<CallExpression, Expression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// A call expression
class CallStatement final : public Castable<CallStatement, Statement> {
class CallStatement final : public utils::Castable<CallStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A case selector
class CaseSelector final : public Castable<CaseSelector, Node> {
class CaseSelector final : public utils::Castable<CaseSelector, Node> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A case statement
class CaseStatement final : public Castable<CaseStatement, Statement> {
class CaseStatement final : public utils::Castable<CaseStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,8 @@
namespace tint::ast {
/// A compound assignment statement
class CompoundAssignmentStatement final : public Castable<CompoundAssignmentStatement, Statement> {
class CompoundAssignmentStatement final
: public utils::Castable<CompoundAssignmentStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -30,7 +30,7 @@ namespace tint::ast {
/// const max_f32 : f32 = 0x1.fffffep+127; // f32 typed constant
/// ```
/// @see https://www.w3.org/TR/WGSL/#creation-time-consts
class Const final : public Castable<Const, Variable> {
class Const final : public utils::Castable<Const, Variable> {
public:
/// Create a 'const' creation-time value variable.
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// A `const_assert` statement
class ConstAssert final : public Castable<ConstAssert, Statement> {
class ConstAssert final : public utils::Castable<ConstAssert, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// An continue statement
class ContinueStatement final : public Castable<ContinueStatement, Statement> {
class ContinueStatement final : public utils::Castable<ContinueStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A diagnostic attribute
class DiagnosticAttribute final : public Castable<DiagnosticAttribute, Attribute> {
class DiagnosticAttribute final : public utils::Castable<DiagnosticAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -29,7 +29,7 @@ namespace tint::ast {
/// // Turn off diagnostics for derivative uniformity violations.
/// diagnostic(off, derivative_uniformity);
/// ```
class DiagnosticDirective final : public Castable<DiagnosticDirective, Node> {
class DiagnosticDirective final : public utils::Castable<DiagnosticDirective, Node> {
public:
/// Create a extension
/// @param pid the identifier of the program that owns this node

View File

@ -53,7 +53,7 @@ enum class DisabledValidation {
/// violations. Typically generated by transforms that need to produce ASTs that
/// would otherwise cause validation errors.
class DisableValidationAttribute final
: public Castable<DisableValidationAttribute, InternalAttribute> {
: public utils::Castable<DisableValidationAttribute, InternalAttribute> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// A discard statement
class DiscardStatement final : public Castable<DiscardStatement, Statement> {
class DiscardStatement final : public utils::Castable<DiscardStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -28,7 +28,7 @@ namespace tint::ast {
/// // Enable an extension named "f16"
/// enable f16;
/// ```
class Enable final : public Castable<Enable, Node> {
class Enable final : public utils::Castable<Enable, Node> {
public:
/// Create a extension
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// Base expression class
class Expression : public Castable<Expression, Node> {
class Expression : public utils::Castable<Expression, Node> {
public:
~Expression() override;

View File

@ -24,7 +24,7 @@ namespace tint::ast {
/// ```
/// enable f16;
/// ```
class Extension final : public Castable<Extension, Node> {
class Extension final : public utils::Castable<Extension, Node> {
public:
/// Create a extension
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,8 @@
namespace tint::ast {
/// A float literal
class FloatLiteralExpression final : public Castable<FloatLiteralExpression, LiteralExpression> {
class FloatLiteralExpression final
: public utils::Castable<FloatLiteralExpression, LiteralExpression> {
public:
/// Literal suffix
enum class Suffix {

View File

@ -22,7 +22,7 @@ namespace tint::ast {
class Expression;
/// A for loop statement
class ForLoopStatement final : public Castable<ForLoopStatement, Statement> {
class ForLoopStatement final : public utils::Castable<ForLoopStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -38,7 +38,7 @@ class IdentifierExpression;
namespace tint::ast {
/// A Function statement.
class Function final : public Castable<Function, Node> {
class Function final : public utils::Castable<Function, Node> {
public:
/// Create a function
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A group attribute
class GroupAttribute final : public Castable<GroupAttribute, Attribute> {
class GroupAttribute final : public utils::Castable<GroupAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// An id attribute for pipeline-overridable constants
class IdAttribute final : public Castable<IdAttribute, Attribute> {
class IdAttribute final : public utils::Castable<IdAttribute, Attribute> {
public:
/// Create an id attribute.
/// @param pid the identifier of the program that owns this node

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// An identifier
class Identifier : public Castable<Identifier, Node> {
class Identifier : public utils::Castable<Identifier, Node> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -25,7 +25,7 @@ class Identifier;
namespace tint::ast {
/// An identifier expression
class IdentifierExpression final : public Castable<IdentifierExpression, Expression> {
class IdentifierExpression final : public utils::Castable<IdentifierExpression, Expression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// An if statement
class IfStatement final : public Castable<IfStatement, Statement> {
class IfStatement final : public utils::Castable<IfStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,8 @@
namespace tint::ast {
/// An increment or decrement statement
class IncrementDecrementStatement final : public Castable<IncrementDecrementStatement, Statement> {
class IncrementDecrementStatement final
: public utils::Castable<IncrementDecrementStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -20,7 +20,8 @@
namespace tint::ast {
/// An index accessor expression
class IndexAccessorExpression final : public Castable<IndexAccessorExpression, AccessorExpression> {
class IndexAccessorExpression final
: public utils::Castable<IndexAccessorExpression, AccessorExpression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// An integer literal. The literal may have an 'i', 'u' or no suffix.
class IntLiteralExpression final : public Castable<IntLiteralExpression, LiteralExpression> {
class IntLiteralExpression final : public utils::Castable<IntLiteralExpression, LiteralExpression> {
public:
/// Literal suffix
enum class Suffix {

View File

@ -30,7 +30,7 @@ namespace tint::ast {
/// An attribute used to indicate that a function is tint-internal.
/// These attributes are not produced by generators, but instead are usually
/// created by transforms for consumption by a particular backend.
class InternalAttribute : public Castable<InternalAttribute, Attribute> {
class InternalAttribute : public utils::Castable<InternalAttribute, Attribute> {
public:
/// Constructor
/// @param program_id the identifier of the program that owns this node

View File

@ -27,7 +27,7 @@ class Expression;
namespace tint::ast {
/// An interpolate attribute
class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribute> {
class InterpolateAttribute final : public utils::Castable<InterpolateAttribute, Attribute> {
public:
/// Create an interpolate attribute.
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,7 @@
namespace tint::ast {
/// The invariant attribute
class InvariantAttribute final : public Castable<InvariantAttribute, Attribute> {
class InvariantAttribute final : public utils::Castable<InvariantAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -27,7 +27,7 @@ namespace tint::ast {
/// let twice_depth : i32 = width + width; // Must have initializer
/// ```
/// @see https://www.w3.org/TR/WGSL/#let-decls
class Let final : public Castable<Let, Variable> {
class Let final : public utils::Castable<Let, Variable> {
public:
/// Create a 'let' variable
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,7 @@
namespace tint::ast {
/// Base class for a literal value expressions
class LiteralExpression : public Castable<LiteralExpression, Expression> {
class LiteralExpression : public utils::Castable<LiteralExpression, Expression> {
public:
~LiteralExpression() override;

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A location attribute
class LocationAttribute final : public Castable<LocationAttribute, Attribute> {
class LocationAttribute final : public utils::Castable<LocationAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -20,7 +20,7 @@
namespace tint::ast {
/// A loop statement
class LoopStatement final : public Castable<LoopStatement, Statement> {
class LoopStatement final : public utils::Castable<LoopStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,7 @@ namespace tint::ast {
/// A member accessor expression
class MemberAccessorExpression final
: public Castable<MemberAccessorExpression, AccessorExpression> {
: public utils::Castable<MemberAccessorExpression, AccessorExpression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -29,7 +29,7 @@ class TypeDecl;
/// Module holds the top-level AST types, functions and global variables used by
/// a Program.
class Module final : public Castable<Module, Node> {
class Module final : public utils::Castable<Module, Node> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,7 @@
namespace tint::ast {
/// The must_use attribute
class MustUseAttribute final : public Castable<MustUseAttribute, Attribute> {
class MustUseAttribute final : public utils::Castable<MustUseAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// AST base class node
class Node : public Castable<Node, Cloneable> {
class Node : public utils::Castable<Node, Cloneable> {
public:
~Node() override;

View File

@ -30,7 +30,7 @@ namespace tint::ast {
/// override scale : f32; // No default - must be overridden.
/// ```
/// @see https://www.w3.org/TR/WGSL/#override-decls
class Override final : public Castable<Override, Variable> {
class Override final : public utils::Castable<Override, Variable> {
public:
/// Create an 'override' pipeline-overridable constant.
/// @param pid the identifier of the program that owns this node

View File

@ -31,7 +31,7 @@ namespace tint::ast {
/// ```
///
/// @see https://www.w3.org/TR/WGSL/#creation-time-consts
class Parameter final : public Castable<Parameter, Variable> {
class Parameter final : public utils::Castable<Parameter, Variable> {
public:
/// Create a 'parameter' creation-time value variable.
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@ namespace tint::ast {
/// Represents the `_` of a phony assignment `_ = <expr>`
/// @see https://www.w3.org/TR/WGSL/#phony-assignment-section
class PhonyExpression final : public Castable<PhonyExpression, Expression> {
class PhonyExpression final : public utils::Castable<PhonyExpression, Expression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// A return statement
class ReturnStatement final : public Castable<ReturnStatement, Statement> {
class ReturnStatement final : public utils::Castable<ReturnStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -23,7 +23,7 @@
namespace tint::ast {
/// A workgroup attribute
class StageAttribute final : public Castable<StageAttribute, Attribute> {
class StageAttribute final : public utils::Castable<StageAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,7 @@
namespace tint::ast {
/// Base statement class
class Statement : public Castable<Statement, Node> {
class Statement : public utils::Castable<Statement, Node> {
public:
~Statement() override;

View File

@ -24,7 +24,7 @@ namespace tint::ast {
/// A stride attribute used by the SPIR-V reader for strided arrays and
/// matrices.
class StrideAttribute final : public Castable<StrideAttribute, Attribute> {
class StrideAttribute final : public utils::Castable<StrideAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -26,7 +26,7 @@
namespace tint::ast {
/// A struct statement.
class Struct final : public Castable<Struct, TypeDecl> {
class Struct final : public utils::Castable<Struct, TypeDecl> {
public:
/// Create a new struct statement
/// @param pid the identifier of the program that owns this node

View File

@ -28,7 +28,7 @@ class Identifier;
namespace tint::ast {
/// A struct member statement.
class StructMember final : public Castable<StructMember, Node> {
class StructMember final : public utils::Castable<StructMember, Node> {
public:
/// Create a new struct member statement
/// @param pid the identifier of the program that owns this node

View File

@ -24,7 +24,8 @@
namespace tint::ast {
/// A struct member align attribute
class StructMemberAlignAttribute final : public Castable<StructMemberAlignAttribute, Attribute> {
class StructMemberAlignAttribute final
: public utils::Castable<StructMemberAlignAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -32,7 +32,8 @@ namespace tint::ast {
/// trivial for the Resolver to handle `@offset(n)` or `@size(n)` /
/// `@align(n)` attributes, so this is what we do, keeping all the layout
/// logic in one place.
class StructMemberOffsetAttribute final : public Castable<StructMemberOffsetAttribute, Attribute> {
class StructMemberOffsetAttribute final
: public utils::Castable<StructMemberOffsetAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -24,7 +24,8 @@
namespace tint::ast {
/// A struct member size attribute
class StructMemberSizeAttribute final : public Castable<StructMemberSizeAttribute, Attribute> {
class StructMemberSizeAttribute final
: public utils::Castable<StructMemberSizeAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// A switch statement
class SwitchStatement final : public Castable<SwitchStatement, Statement> {
class SwitchStatement final : public utils::Castable<SwitchStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -26,7 +26,7 @@ class Expression;
namespace tint::ast {
/// A templated identifier expression
class TemplatedIdentifier final : public Castable<TemplatedIdentifier, Identifier> {
class TemplatedIdentifier final : public utils::Castable<TemplatedIdentifier, Identifier> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -25,7 +25,7 @@ class Identifier;
namespace tint::ast {
/// The base class for type declarations.
class TypeDecl : public Castable<TypeDecl, Node> {
class TypeDecl : public utils::Castable<TypeDecl, Node> {
public:
/// Create a new struct statement
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// A unary op expression
class UnaryOpExpression final : public Castable<UnaryOpExpression, Expression> {
class UnaryOpExpression final : public utils::Castable<UnaryOpExpression, Expression> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -39,7 +39,7 @@ namespace tint::ast {
/// ```
///
/// @see https://www.w3.org/TR/WGSL/#var-decls
class Var final : public Castable<Var, Variable> {
class Var final : public utils::Castable<Var, Variable> {
public:
/// Create a 'var' variable
/// @param pid the identifier of the program that owns this node

View File

@ -40,7 +40,7 @@ namespace tint::ast {
/// declaration, "override" declaration, "const" declaration, or formal parameter to a function.
///
/// @see https://www.w3.org/TR/WGSL/#value-decls
class Variable : public Castable<Variable, Node> {
class Variable : public utils::Castable<Variable, Node> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -21,7 +21,7 @@
namespace tint::ast {
/// A variable declaration statement
class VariableDeclStatement final : public Castable<VariableDeclStatement, Statement> {
class VariableDeclStatement final : public utils::Castable<VariableDeclStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -22,7 +22,7 @@ namespace tint::ast {
class Expression;
/// A while loop statement
class WhileStatement final : public Castable<WhileStatement, Statement> {
class WhileStatement final : public utils::Castable<WhileStatement, Statement> {
public:
/// Constructor
/// @param pid the identifier of the program that owns this node

View File

@ -28,7 +28,7 @@ class Expression;
namespace tint::ast {
/// A workgroup attribute
class WorkgroupAttribute final : public Castable<WorkgroupAttribute, Attribute> {
class WorkgroupAttribute final : public utils::Castable<WorkgroupAttribute, Attribute> {
public:
/// constructor
/// @param pid the identifier of the program that owns this node

View File

@ -97,7 +97,7 @@ const tint::Cloneable* CloneContext::CloneCloneable(const Cloneable* object) {
return object->Clone(this);
}
void CloneContext::CheckedCastFailure(const Cloneable* got, const TypeInfo& expected) {
void CloneContext::CheckedCastFailure(const Cloneable* got, const utils::TypeInfo& expected) {
TINT_ICE(Clone, Diagnostics()) << "Cloned object was not of the expected type\n"
<< "got: " << got->TypeInfo().name << "\n"
<< "expected: " << expected.name;

View File

@ -21,10 +21,10 @@
#include <utility>
#include <vector>
#include "src/tint/castable.h"
#include "src/tint/debug.h"
#include "src/tint/program_id.h"
#include "src/tint/symbol.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/compiler_macros.h"
#include "src/tint/utils/hashmap.h"
#include "src/tint/utils/hashset.h"
@ -49,7 +49,7 @@ ProgramID ProgramIDOf(const Program*);
ProgramID ProgramIDOf(const ProgramBuilder*);
/// Cloneable is the base class for all objects that can be cloned
class Cloneable : public Castable<Cloneable> {
class Cloneable : public utils::Castable<Cloneable> {
public:
/// Constructor
Cloneable();
@ -308,18 +308,18 @@ class CloneContext {
using TPtr = utils::traits::ParameterType<F, 0>;
using T = typename std::remove_pointer<TPtr>::type;
for (auto& transform : transforms_) {
bool already_registered = transform.typeinfo->Is(&TypeInfo::Of<T>()) ||
TypeInfo::Of<T>().Is(transform.typeinfo);
bool already_registered = transform.typeinfo->Is(&utils::TypeInfo::Of<T>()) ||
utils::TypeInfo::Of<T>().Is(transform.typeinfo);
if (TINT_UNLIKELY(already_registered)) {
TINT_ICE(Clone, Diagnostics())
<< "ReplaceAll() called with a handler for type " << TypeInfo::Of<T>().name
<< " that is already handled by a handler for type "
<< transform.typeinfo->name;
TINT_ICE(Clone, Diagnostics()) << "ReplaceAll() called with a handler for type "
<< utils::TypeInfo::Of<T>().name
<< " that is already handled by a handler for type "
<< transform.typeinfo->name;
return *this;
}
}
CloneableTransform transform;
transform.typeinfo = &TypeInfo::Of<T>();
transform.typeinfo = &utils::TypeInfo::Of<T>();
transform.function = [=](const Cloneable* in) { return replacer(in->As<T>()); };
transforms_.Push(std::move(transform));
return *this;
@ -554,8 +554,8 @@ class CloneContext {
/// Destructor
~CloneableTransform();
// TypeInfo of the Cloneable that the transform operates on
const TypeInfo* typeinfo;
// utils::TypeInfo of the Cloneable that the transform operates on
const utils::TypeInfo* typeinfo;
std::function<const Cloneable*(const Cloneable*)> function;
};
@ -598,7 +598,7 @@ class CloneContext {
if (TINT_LIKELY(cast)) {
return cast;
}
CheckedCastFailure(obj, TypeInfo::Of<TO>());
CheckedCastFailure(obj, utils::TypeInfo::Of<TO>());
return nullptr;
}
@ -608,7 +608,7 @@ class CloneContext {
/// Adds an error diagnostic to Diagnostics() that the cloned object was not
/// of the expected type.
void CheckedCastFailure(const Cloneable* got, const TypeInfo& expected);
void CheckedCastFailure(const Cloneable* got, const utils::TypeInfo& expected);
/// @returns the diagnostic list of #dst
diag::List& Diagnostics() const;

View File

@ -30,7 +30,7 @@ struct Allocator {
utils::BlockAllocator<Cloneable> alloc;
};
struct Node : public Castable<Node, Cloneable> {
struct Node : public utils::Castable<Node, Cloneable> {
Node(Allocator* alloc,
Symbol n,
const Node* node_a = nullptr,
@ -55,7 +55,7 @@ struct Node : public Castable<Node, Cloneable> {
}
};
struct Replaceable : public Castable<Replaceable, Node> {
struct Replaceable : public utils::Castable<Replaceable, Node> {
Replaceable(Allocator* alloc,
Symbol n,
const Node* node_a = nullptr,
@ -64,18 +64,18 @@ struct Replaceable : public Castable<Replaceable, Node> {
: Base(alloc, n, node_a, node_b, node_c) {}
};
struct Replacement : public Castable<Replacement, Replaceable> {
struct Replacement : public utils::Castable<Replacement, Replaceable> {
Replacement(Allocator* alloc, Symbol n) : Base(alloc, n) {}
};
struct NotANode : public Castable<NotANode, Cloneable> {
struct NotANode : public utils::Castable<NotANode, Cloneable> {
explicit NotANode(Allocator* alloc) : allocator(alloc) {}
Allocator* const allocator;
NotANode* Clone(CloneContext*) const override { return allocator->Create<NotANode>(); }
};
struct ProgramNode : public Castable<ProgramNode, Cloneable> {
struct ProgramNode : public utils::Castable<ProgramNode, Cloneable> {
ProgramNode(Allocator* alloc, ProgramID id, ProgramID cloned_id)
: allocator(alloc), program_id(id), cloned_program_id(cloned_id) {}
@ -1051,7 +1051,7 @@ TEST_F(CloneContextNodeTest, CloneIntoSameBuilder) {
}
TEST_F(CloneContextNodeTest, CloneWithReplaceAll_SameTypeTwice) {
std::string node_name = TypeInfo::Of<Node>().name;
std::string node_name = utils::TypeInfo::Of<Node>().name;
EXPECT_FATAL_FAILURE(
{
@ -1066,8 +1066,8 @@ TEST_F(CloneContextNodeTest, CloneWithReplaceAll_SameTypeTwice) {
}
TEST_F(CloneContextNodeTest, CloneWithReplaceAll_BaseThenDerived) {
std::string node_name = TypeInfo::Of<Node>().name;
std::string replaceable_name = TypeInfo::Of<Replaceable>().name;
std::string node_name = utils::TypeInfo::Of<Node>().name;
std::string replaceable_name = utils::TypeInfo::Of<Replaceable>().name;
EXPECT_FATAL_FAILURE(
{
@ -1082,8 +1082,8 @@ TEST_F(CloneContextNodeTest, CloneWithReplaceAll_BaseThenDerived) {
}
TEST_F(CloneContextNodeTest, CloneWithReplaceAll_DerivedThenBase) {
std::string node_name = TypeInfo::Of<Node>().name;
std::string replaceable_name = TypeInfo::Of<Replaceable>().name;
std::string node_name = utils::TypeInfo::Of<Node>().name;
std::string replaceable_name = utils::TypeInfo::Of<Replaceable>().name;
EXPECT_FATAL_FAILURE(
{

View File

@ -15,10 +15,10 @@
#ifndef SRC_TINT_CONSTANT_COMPOSITE_H_
#define SRC_TINT_CONSTANT_COMPOSITE_H_
#include "src/tint/castable.h"
#include "src/tint/constant/value.h"
#include "src/tint/number.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/hash.h"
#include "src/tint/utils/vector.h"
@ -28,7 +28,7 @@ namespace tint::constant {
/// Composite may be of a vector, matrix, array or structure type.
/// If each element is the same type and value, then a Splat would be a more efficient constant
/// implementation. Use CreateComposite() to create the appropriate type.
class Composite : public Castable<Composite, Value> {
class Composite : public utils::Castable<Composite, Value> {
public:
/// Constructor
/// @param t the compsite type

View File

@ -15,12 +15,12 @@
#ifndef SRC_TINT_CONSTANT_NODE_H_
#define SRC_TINT_CONSTANT_NODE_H_
#include "src/tint/castable.h"
#include "src/tint/utils/castable.h"
namespace tint::constant {
/// Node is the base class for all constant nodes
class Node : public Castable<Node> {
class Node : public utils::Castable<Node> {
public:
/// Constructor
Node();

View File

@ -15,17 +15,17 @@
#ifndef SRC_TINT_CONSTANT_SCALAR_H_
#define SRC_TINT_CONSTANT_SCALAR_H_
#include "src/tint/castable.h"
#include "src/tint/constant/value.h"
#include "src/tint/number.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/hash.h"
namespace tint::constant {
/// Scalar holds a single scalar or abstract-numeric value.
template <typename T>
class Scalar : public Castable<Scalar<T>, Value> {
class Scalar : public utils::Castable<Scalar<T>, Value> {
public:
static_assert(!std::is_same_v<UnwrapNumber<T>, T> || std::is_same_v<T, bool>,
"T must be a Number or bool");

View File

@ -15,9 +15,9 @@
#ifndef SRC_TINT_CONSTANT_SPLAT_H_
#define SRC_TINT_CONSTANT_SPLAT_H_
#include "src/tint/castable.h"
#include "src/tint/constant/composite.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/vector.h"
namespace tint::constant {
@ -26,7 +26,7 @@ namespace tint::constant {
///
/// Splat is used for zero-initializers, 'splat' initializers, or initializers where each element is
/// identical. Splat may be of a vector, matrix, array or structure type.
class Splat : public Castable<Splat, Value> {
class Splat : public utils::Castable<Splat, Value> {
public:
/// Constructor
/// @param t the splat type

View File

@ -17,16 +17,16 @@
#include <variant>
#include "src/tint/castable.h"
#include "src/tint/constant/clone_context.h"
#include "src/tint/constant/node.h"
#include "src/tint/number.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
namespace tint::constant {
/// Value is the interface to a compile-time evaluated expression value.
class Value : public Castable<Value, Node> {
class Value : public utils::Castable<Value, Node> {
public:
/// Constructor
Value();

View File

@ -19,12 +19,12 @@
#include "src/tint/ast/module.h"
#include "src/tint/ast/variable_decl_statement.h"
#include "src/tint/castable.h"
#include "src/tint/program.h"
#include "src/tint/sem/block_statement.h"
#include "src/tint/sem/function.h"
#include "src/tint/sem/statement.h"
#include "src/tint/sem/variable.h"
#include "src/tint/utils/castable.h"
namespace tint::fuzzers::ast_fuzzer::util {
/// @file

View File

@ -456,7 +456,7 @@ std::vector<ResourceBinding> Inspector::GetWriteOnlyStorageTextureResourceBindin
std::vector<ResourceBinding> Inspector::GetTextureResourceBindings(
const std::string& entry_point,
const tint::TypeInfo* texture_type,
const tint::utils::TypeInfo* texture_type,
ResourceBinding::ResourceType resource_type) {
auto* func = FindEntryPointByName(entry_point);
if (!func) {
@ -485,19 +485,20 @@ std::vector<ResourceBinding> Inspector::GetTextureResourceBindings(
std::vector<ResourceBinding> Inspector::GetDepthTextureResourceBindings(
const std::string& entry_point) {
return GetTextureResourceBindings(entry_point, &TypeInfo::Of<type::DepthTexture>(),
return GetTextureResourceBindings(entry_point, &utils::TypeInfo::Of<type::DepthTexture>(),
ResourceBinding::ResourceType::kDepthTexture);
}
std::vector<ResourceBinding> Inspector::GetDepthMultisampledTextureResourceBindings(
const std::string& entry_point) {
return GetTextureResourceBindings(entry_point, &TypeInfo::Of<type::DepthMultisampledTexture>(),
return GetTextureResourceBindings(entry_point,
&utils::TypeInfo::Of<type::DepthMultisampledTexture>(),
ResourceBinding::ResourceType::kDepthMultisampledTexture);
}
std::vector<ResourceBinding> Inspector::GetExternalTextureResourceBindings(
const std::string& entry_point) {
return GetTextureResourceBindings(entry_point, &TypeInfo::Of<type::ExternalTexture>(),
return GetTextureResourceBindings(entry_point, &utils::TypeInfo::Of<type::ExternalTexture>(),
ResourceBinding::ResourceType::kExternalTexture);
}

View File

@ -195,7 +195,7 @@ class Inspector {
/// @returns vector of all of the bindings for depth textures.
std::vector<ResourceBinding> GetTextureResourceBindings(
const std::string& entry_point,
const tint::TypeInfo* texture_type,
const tint::utils::TypeInfo* texture_type,
ResourceBinding::ResourceType resource_type);
/// @param entry_point name of the entry point to get information about.

View File

@ -15,16 +15,16 @@
#ifndef SRC_TINT_IR_BINARY_H_
#define SRC_TINT_IR_BINARY_H_
#include "src/tint/castable.h"
#include "src/tint/ir/instruction.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/string_stream.h"
namespace tint::ir {
/// An instruction in the IR.
class Binary : public Castable<Binary, Instruction> {
class Binary : public utils::Castable<Binary, Instruction> {
public:
/// The kind of instruction.
enum class Kind {

View File

@ -15,16 +15,16 @@
#ifndef SRC_TINT_IR_BITCAST_H_
#define SRC_TINT_IR_BITCAST_H_
#include "src/tint/castable.h"
#include "src/tint/ir/instruction.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/string_stream.h"
namespace tint::ir {
/// A bitcast instruction in the IR.
class Bitcast : public Castable<Bitcast, Instruction> {
class Bitcast : public utils::Castable<Bitcast, Instruction> {
public:
/// Constructor
/// @param result the result value

View File

@ -25,7 +25,7 @@ namespace tint::ir {
/// A flow node comprising a block of statements. The instructions in the block are a linear list of
/// instructions to execute. The block will branch at the end. The only blocks which do not branch
/// are the end blocks of functions.
class Block : public Castable<Block, FlowNode> {
class Block : public utils::Castable<Block, FlowNode> {
public:
/// Constructor
Block();

View File

@ -16,16 +16,16 @@
#define SRC_TINT_IR_BUILTIN_H_
#include "src/tint/builtin/function.h"
#include "src/tint/castable.h"
#include "src/tint/ir/call.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/string_stream.h"
namespace tint::ir {
/// A value conversion instruction in the IR.
class Builtin : public Castable<Builtin, Call> {
class Builtin : public utils::Castable<Builtin, Call> {
public:
/// Constructor
/// @param result the result value

View File

@ -15,16 +15,16 @@
#ifndef SRC_TINT_IR_CALL_H_
#define SRC_TINT_IR_CALL_H_
#include "src/tint/castable.h"
#include "src/tint/ir/instruction.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/string_stream.h"
namespace tint::ir {
/// A Call instruction in the IR.
class Call : public Castable<Call, Instruction> {
class Call : public utils::Castable<Call, Instruction> {
public:
/// Constructor
/// @param result the result value

View File

@ -23,7 +23,7 @@
namespace tint::ir {
/// Constant in the IR.
class Constant : public Castable<Constant, Value> {
class Constant : public utils::Castable<Constant, Value> {
public:
/// Constructor
/// @param val the value stored in the constant

View File

@ -15,16 +15,16 @@
#ifndef SRC_TINT_IR_CONSTRUCT_H_
#define SRC_TINT_IR_CONSTRUCT_H_
#include "src/tint/castable.h"
#include "src/tint/ir/call.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/string_stream.h"
namespace tint::ir {
/// A constructor instruction in the IR.
class Construct : public Castable<Construct, Call> {
class Construct : public utils::Castable<Construct, Call> {
public:
/// Constructor
/// @param result the result value

View File

@ -15,16 +15,16 @@
#ifndef SRC_TINT_IR_CONVERT_H_
#define SRC_TINT_IR_CONVERT_H_
#include "src/tint/castable.h"
#include "src/tint/ir/call.h"
#include "src/tint/symbol_table.h"
#include "src/tint/type/type.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/string_stream.h"
namespace tint::ir {
/// A value conversion instruction in the IR.
class Convert : public Castable<Convert, Call> {
class Convert : public utils::Castable<Convert, Call> {
public:
/// Constructor
/// @param result the result value

View File

@ -15,13 +15,13 @@
#ifndef SRC_TINT_IR_FLOW_NODE_H_
#define SRC_TINT_IR_FLOW_NODE_H_
#include "src/tint/castable.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/vector.h"
namespace tint::ir {
/// Base class for flow nodes
class FlowNode : public Castable<FlowNode> {
class FlowNode : public utils::Castable<FlowNode> {
public:
~FlowNode() override;

View File

@ -27,7 +27,7 @@ class Terminator;
namespace tint::ir {
/// An IR representation of a function
class Function : public Castable<Function, FlowNode> {
class Function : public utils::Castable<Function, FlowNode> {
public:
/// Constructor
Function();

View File

@ -27,7 +27,7 @@ class Block;
namespace tint::ir {
/// A flow node representing an if statement.
class If : public Castable<If, FlowNode> {
class If : public utils::Castable<If, FlowNode> {
public:
/// Constructor
If();

View File

@ -15,15 +15,15 @@
#ifndef SRC_TINT_IR_INSTRUCTION_H_
#define SRC_TINT_IR_INSTRUCTION_H_
#include "src/tint/castable.h"
#include "src/tint/ir/value.h"
#include "src/tint/symbol_table.h"
#include "src/tint/utils/castable.h"
#include "src/tint/utils/string_stream.h"
namespace tint::ir {
/// An instruction in the IR.
class Instruction : public Castable<Instruction> {
class Instruction : public utils::Castable<Instruction> {
public:
Instruction(const Instruction& instr) = delete;
Instruction(Instruction&& instr) = delete;

View File

@ -22,7 +22,7 @@
namespace tint::ir {
/// Flow node describing a loop.
class Loop : public Castable<Loop, FlowNode> {
class Loop : public utils::Castable<Loop, FlowNode> {
public:
/// Constructor
Loop();

View File

@ -24,7 +24,7 @@
namespace tint::ir {
/// Flow node representing a switch statement
class Switch : public Castable<Switch, FlowNode> {
class Switch : public utils::Castable<Switch, FlowNode> {
public:
/// A case selector
struct CaseSelector {

View File

@ -22,7 +22,7 @@
namespace tint::ir {
/// Temporary value in the IR.
class Temp : public Castable<Temp, Value> {
class Temp : public utils::Castable<Temp, Value> {
public:
/// A value id.
using Id = uint32_t;

View File

@ -21,7 +21,7 @@ namespace tint::ir {
/// Flow node used as the end of a function. Must only be used as the `end_target` in a function
/// flow node. There are no instructions and no branches from this node.
class Terminator : public Castable<Terminator, FlowNode> {
class Terminator : public utils::Castable<Terminator, FlowNode> {
public:
/// Constructor
Terminator();

Some files were not shown because too many files have changed in this diff Show More