[WHLSL] Devirtualize the AST
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Aug 2019 23:30:29 +0000 (23:30 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Aug 2019 23:30:29 +0000 (23:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200522

Reviewed by Robin Morisset.

Source/WebCore:

This patch devirtualizes the AST for Type, Expression, and Statement.
We now have an enum which represents all the concrete types in the
three hierarchies. Doing dynamic dispatch is implemented as a switch
on that type enum.

The interesting part of this patch is how to handle destruction. We do
this by defining a custom deleter for all nodes in the AST. This ensures
that when they're used inside UniqueRef, unique_ptr, Ref, and RefPtr,
we do dynamic dispatch when we delete the object. This allows each base
class to define a "destroy" method which does dynamic dispatch on type
and calls the appropriate delete. We also mark all non-concrete nodes
in all type hierarchies with a protected destructor, which ensures it's
never called except from within the concrete child classes. We allow
all concrete classes to have public destructors, as it's valid for
their destructors to be called explicitly since there is no need for
dynamic dispatch in such scenarios. All concrete classes are also marked
as final.

This is a 3ms speedup on compute_boids, which is about a 10% improvement
in the WHLSL compiler.

* Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h:
* Modules/webgpu/WHLSL/AST/WHLSLArrayType.h:
* Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h:
(WebCore::WHLSL::AST::AssignmentExpression::AssignmentExpression): Deleted.
(WebCore::WHLSL::AST::AssignmentExpression::left): Deleted.
(WebCore::WHLSL::AST::AssignmentExpression::right): Deleted.
(WebCore::WHLSL::AST::AssignmentExpression::takeRight): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLBlock.h:
(WebCore::WHLSL::AST::Block::Block): Deleted.
(WebCore::WHLSL::AST::Block::statements): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLBooleanLiteral.h:
(WebCore::WHLSL::AST::BooleanLiteral::BooleanLiteral): Deleted.
(WebCore::WHLSL::AST::BooleanLiteral::value const): Deleted.
(WebCore::WHLSL::AST::BooleanLiteral::clone const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLBreak.h:
(WebCore::WHLSL::AST::Break::Break): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h:
(WebCore::WHLSL::AST::CallExpression::CallExpression): Deleted.
(WebCore::WHLSL::AST::CallExpression::arguments): Deleted.
(WebCore::WHLSL::AST::CallExpression::name): Deleted.
(WebCore::WHLSL::AST::CallExpression::setCastData): Deleted.
(WebCore::WHLSL::AST::CallExpression::isCast): Deleted.
(WebCore::WHLSL::AST::CallExpression::castReturnType): Deleted.
(WebCore::WHLSL::AST::CallExpression::function): Deleted.
(WebCore::WHLSL::AST::CallExpression::setFunction): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLCommaExpression.h:
(WebCore::WHLSL::AST::CommaExpression::CommaExpression): Deleted.
(WebCore::WHLSL::AST::CommaExpression::list): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h:
(WebCore::WHLSL::AST::ConstantExpression::ConstantExpression): Deleted.
(WebCore::WHLSL::AST::ConstantExpression::integerLiteral): Deleted.
(WebCore::WHLSL::AST::ConstantExpression::visit): Deleted.
(WebCore::WHLSL::AST::ConstantExpression::visit const): Deleted.
(WebCore::WHLSL::AST::ConstantExpression::clone const): Deleted.
(WebCore::WHLSL::AST::ConstantExpression::matches const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLContinue.h:
(WebCore::WHLSL::AST::Continue::Continue): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLDefaultDelete.h: Added.
* Modules/webgpu/WHLSL/AST/WHLSLDereferenceExpression.h:
(WebCore::WHLSL::AST::DereferenceExpression::DereferenceExpression): Deleted.
(WebCore::WHLSL::AST::DereferenceExpression::pointer): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLDoWhileLoop.h:
(WebCore::WHLSL::AST::DoWhileLoop::DoWhileLoop): Deleted.
(WebCore::WHLSL::AST::DoWhileLoop::body): Deleted.
(WebCore::WHLSL::AST::DoWhileLoop::conditional): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h:
(WebCore::WHLSL::AST::DotExpression::DotExpression): Deleted.
(WebCore::WHLSL::AST::DotExpression::fieldName): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLEffectfulExpressionStatement.h:
(WebCore::WHLSL::AST::EffectfulExpressionStatement::EffectfulExpressionStatement): Deleted.
(WebCore::WHLSL::AST::EffectfulExpressionStatement::effectfulExpression): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h:
(WebCore::WHLSL::AST::EnumerationDefinition::EnumerationDefinition): Deleted.
(WebCore::WHLSL::AST::EnumerationDefinition::type): Deleted.
(WebCore::WHLSL::AST::EnumerationDefinition::add): Deleted.
(WebCore::WHLSL::AST::EnumerationDefinition::memberByName): Deleted.
(WebCore::WHLSL::AST::EnumerationDefinition::enumerationMembers): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLEnumerationMemberLiteral.h:
(WebCore::WHLSL::AST::EnumerationMemberLiteral::EnumerationMemberLiteral): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::wrap): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::left const): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::right const): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::clone const): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationDefinition): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationDefinition const): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationMember): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationMember const): Deleted.
(WebCore::WHLSL::AST::EnumerationMemberLiteral::setEnumerationMember): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLExpression.cpp: Added.
(WebCore::WHLSL::AST::Expression::destroy):
(WebCore::WHLSL::AST::PropertyAccessExpression::getterFunctionName const):
(WebCore::WHLSL::AST::PropertyAccessExpression::setterFunctionName const):
(WebCore::WHLSL::AST::PropertyAccessExpression::anderFunctionName const):
* Modules/webgpu/WHLSL/AST/WHLSLExpression.h:
(WebCore::WHLSL::AST::Expression::Expression):
(WebCore::WHLSL::AST::Expression::kind const):
(WebCore::WHLSL::AST::Expression::isAssignmentExpression const):
(WebCore::WHLSL::AST::Expression::isBooleanLiteral const):
(WebCore::WHLSL::AST::Expression::isCallExpression const):
(WebCore::WHLSL::AST::Expression::isCommaExpression const):
(WebCore::WHLSL::AST::Expression::isDereferenceExpression const):
(WebCore::WHLSL::AST::Expression::isDotExpression const):
(WebCore::WHLSL::AST::Expression::isGlobalVariableReference const):
(WebCore::WHLSL::AST::Expression::isFloatLiteral const):
(WebCore::WHLSL::AST::Expression::isIndexExpression const):
(WebCore::WHLSL::AST::Expression::isIntegerLiteral const):
(WebCore::WHLSL::AST::Expression::isLogicalExpression const):
(WebCore::WHLSL::AST::Expression::isLogicalNotExpression const):
(WebCore::WHLSL::AST::Expression::isMakeArrayReferenceExpression const):
(WebCore::WHLSL::AST::Expression::isMakePointerExpression const):
(WebCore::WHLSL::AST::Expression::isNullLiteral const):
(WebCore::WHLSL::AST::Expression::isPropertyAccessExpression const):
(WebCore::WHLSL::AST::Expression::isReadModifyWriteExpression const):
(WebCore::WHLSL::AST::Expression::isTernaryExpression const):
(WebCore::WHLSL::AST::Expression::isUnsignedIntegerLiteral const):
(WebCore::WHLSL::AST::Expression::isVariableReference const):
(WebCore::WHLSL::AST::Expression::isEnumerationMemberLiteral const):
(WebCore::WHLSL::AST::Expression::codeLocation const):
(WebCore::WHLSL::AST::Expression::updateCodeLocation):
* Modules/webgpu/WHLSL/AST/WHLSLFallthrough.h:
(WebCore::WHLSL::AST::Fallthrough::Fallthrough): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h:
(WebCore::WHLSL::AST::FloatLiteral::FloatLiteral): Deleted.
(WebCore::WHLSL::AST::FloatLiteral::type): Deleted.
(WebCore::WHLSL::AST::FloatLiteral::value const): Deleted.
(WebCore::WHLSL::AST::FloatLiteral::clone const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp:
(WebCore::WHLSL::AST::FloatLiteralType::FloatLiteralType):
* Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h:
(WebCore::WHLSL::AST::FloatLiteralType::value const): Deleted.
(WebCore::WHLSL::AST::FloatLiteralType::preferredType): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLForLoop.h:
(WebCore::WHLSL::AST::ForLoop::ForLoop): Deleted.
(WebCore::WHLSL::AST::ForLoop::~ForLoop): Deleted.
(WebCore::WHLSL::AST::ForLoop::initialization): Deleted.
(WebCore::WHLSL::AST::ForLoop::condition): Deleted.
(WebCore::WHLSL::AST::ForLoop::increment): Deleted.
(WebCore::WHLSL::AST::ForLoop::body): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h:
(WebCore::WHLSL::AST::GlobalVariableReference::GlobalVariableReference): Deleted.
(WebCore::WHLSL::AST::GlobalVariableReference::structField): Deleted.
(WebCore::WHLSL::AST::GlobalVariableReference::base): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLIfStatement.h:
(WebCore::WHLSL::AST::IfStatement::IfStatement): Deleted.
(WebCore::WHLSL::AST::IfStatement::conditional): Deleted.
(WebCore::WHLSL::AST::IfStatement::body): Deleted.
(WebCore::WHLSL::AST::IfStatement::elseBody): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h:
(WebCore::WHLSL::AST::IndexExpression::IndexExpression): Deleted.
(WebCore::WHLSL::AST::IndexExpression::indexExpression): Deleted.
(WebCore::WHLSL::AST::IndexExpression::takeIndex): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h:
(WebCore::WHLSL::AST::IntegerLiteral::IntegerLiteral): Deleted.
(WebCore::WHLSL::AST::IntegerLiteral::type): Deleted.
(WebCore::WHLSL::AST::IntegerLiteral::value const): Deleted.
(WebCore::WHLSL::AST::IntegerLiteral::clone const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp:
(WebCore::WHLSL::AST::IntegerLiteralType::IntegerLiteralType):
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h:
(WebCore::WHLSL::AST::IntegerLiteralType::value const): Deleted.
(WebCore::WHLSL::AST::IntegerLiteralType::preferredType): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLLogicalExpression.h:
(WebCore::WHLSL::AST::LogicalExpression::LogicalExpression): Deleted.
(WebCore::WHLSL::AST::LogicalExpression::type const): Deleted.
(WebCore::WHLSL::AST::LogicalExpression::left): Deleted.
(WebCore::WHLSL::AST::LogicalExpression::right): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLLogicalNotExpression.h:
(WebCore::WHLSL::AST::LogicalNotExpression::LogicalNotExpression): Deleted.
(WebCore::WHLSL::AST::LogicalNotExpression::operand): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h:
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression): Deleted.
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::leftValue): Deleted.
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::mightEscape const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h:
(WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression): Deleted.
(WebCore::WHLSL::AST::MakePointerExpression::leftValue): Deleted.
(WebCore::WHLSL::AST::MakePointerExpression::mightEscape const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLNamedType.h:
(WebCore::WHLSL::AST::NamedType::NamedType):
(WebCore::WHLSL::AST::NamedType::unifyNodeImpl):
(): Deleted.
(WebCore::WHLSL::AST::NamedType::isTypeDefinition const): Deleted.
(WebCore::WHLSL::AST::NamedType::isStructureDefinition const): Deleted.
(WebCore::WHLSL::AST::NamedType::isEnumerationDefinition const): Deleted.
(WebCore::WHLSL::AST::NamedType::isNativeTypeDeclaration const): Deleted.
(WebCore::WHLSL::AST::NamedType::unifyNode const): Deleted.
(WebCore::WHLSL::AST::NamedType::unifyNode): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h:
(WebCore::WHLSL::AST::NativeTypeDeclaration::NativeTypeDeclaration): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::typeArguments): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isInt const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isNumber const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isFloating const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isAtomic const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isVector const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isMatrix const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isOpaqueType const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isTexture const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isTextureArray const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isDepthTexture const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isWritableTexture const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::textureDimension const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::isSigned const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::std::function<bool const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::std::function<int64_t const): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::iterateAllValues): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsInt): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsNumber): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsFloating): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsAtomic): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsVector): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsMatrix): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsOpaqueType): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsTexture): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsTextureArray): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsDepthTexture): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsWritableTexture): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setTextureDimension): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIsSigned): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setCanRepresentInteger): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setCanRepresentUnsignedInteger): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setCanRepresentFloat): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setSuccessor): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setFormatValueFromInteger): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setFormatValueFromUnsignedInteger): Deleted.
(WebCore::WHLSL::AST::NativeTypeDeclaration::setIterateAllValues): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h:
(WebCore::WHLSL::AST::NullLiteral::NullLiteral): Deleted.
(WebCore::WHLSL::AST::NullLiteral::type): Deleted.
(WebCore::WHLSL::AST::NullLiteral::clone const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLNullLiteralType.h:
* Modules/webgpu/WHLSL/AST/WHLSLPointerType.h:
* Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h:
(WebCore::WHLSL::AST::PropertyAccessExpression::PropertyAccessExpression):
* Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h:
(WebCore::WHLSL::AST::ReadModifyWriteExpression::create): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::setNewValueExpression): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::setResultExpression): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::oldVariableReference): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::newVariableReference): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::leftValue): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::oldValue): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::newValue): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::newValueExpression): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::resultExpression): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeLeftValue): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeOldValue): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeNewValue): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeNewValueExpression): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::takeResultExpression): Deleted.
(WebCore::WHLSL::AST::ReadModifyWriteExpression::ReadModifyWriteExpression): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
(WebCore::WHLSL::AST::ReferenceType::ReferenceType):
* Modules/webgpu/WHLSL/AST/WHLSLResolvableType.h:
(WebCore::WHLSL::AST::ResolvableType::ResolvableType):
(): Deleted.
(WebCore::WHLSL::AST::ResolvableType::isFloatLiteralType const): Deleted.
(WebCore::WHLSL::AST::ResolvableType::isIntegerLiteralType const): Deleted.
(WebCore::WHLSL::AST::ResolvableType::isNullLiteralType const): Deleted.
(WebCore::WHLSL::AST::ResolvableType::isUnsignedIntegerLiteralType const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLReturn.h:
(WebCore::WHLSL::AST::Return::Return): Deleted.
(WebCore::WHLSL::AST::Return::value): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLStatement.cpp: Added.
(WebCore::WHLSL::AST::Statement::destroy):
* Modules/webgpu/WHLSL/AST/WHLSLStatement.h:
(WebCore::WHLSL::AST::Statement::Statement):
(WebCore::WHLSL::AST::Statement::kind const):
(WebCore::WHLSL::AST::Statement::isBlock const):
(WebCore::WHLSL::AST::Statement::isBreak const):
(WebCore::WHLSL::AST::Statement::isContinue const):
(WebCore::WHLSL::AST::Statement::isDoWhileLoop const):
(WebCore::WHLSL::AST::Statement::isEffectfulExpressionStatement const):
(WebCore::WHLSL::AST::Statement::isFallthrough const):
(WebCore::WHLSL::AST::Statement::isForLoop const):
(WebCore::WHLSL::AST::Statement::isIfStatement const):
(WebCore::WHLSL::AST::Statement::isReturn const):
(WebCore::WHLSL::AST::Statement::isStatementList const):
(WebCore::WHLSL::AST::Statement::isSwitchCase const):
(WebCore::WHLSL::AST::Statement::isSwitchStatement const):
(WebCore::WHLSL::AST::Statement::isVariableDeclarationsStatement const):
(WebCore::WHLSL::AST::Statement::isWhileLoop const):
(WebCore::WHLSL::AST::Statement::codeLocation const):
(WebCore::WHLSL::AST::Statement::updateCodeLocation):
* Modules/webgpu/WHLSL/AST/WHLSLStatementList.h:
(WebCore::WHLSL::AST::StatementList::StatementList): Deleted.
(WebCore::WHLSL::AST::StatementList::statements): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h:
(WebCore::WHLSL::AST::StructureDefinition::StructureDefinition): Deleted.
(WebCore::WHLSL::AST::StructureDefinition::structureElements): Deleted.
(WebCore::WHLSL::AST::StructureDefinition::find): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLStructureElement.h:
(WebCore::WHLSL::AST::StructureElement::StructureElement): Deleted.
(WebCore::WHLSL::AST::StructureElement::codeLocation const): Deleted.
(WebCore::WHLSL::AST::StructureElement::type): Deleted.
(WebCore::WHLSL::AST::StructureElement::name): Deleted.
(WebCore::WHLSL::AST::StructureElement::semantic): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLSwitchCase.h:
(WebCore::WHLSL::AST::SwitchCase::SwitchCase): Deleted.
(WebCore::WHLSL::AST::SwitchCase::value): Deleted.
(WebCore::WHLSL::AST::SwitchCase::block): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLSwitchStatement.h:
(WebCore::WHLSL::AST::SwitchStatement::SwitchStatement): Deleted.
(WebCore::WHLSL::AST::SwitchStatement::value): Deleted.
(WebCore::WHLSL::AST::SwitchStatement::switchCases): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLTernaryExpression.h:
(WebCore::WHLSL::AST::TernaryExpression::TernaryExpression): Deleted.
(WebCore::WHLSL::AST::TernaryExpression::predicate): Deleted.
(WebCore::WHLSL::AST::TernaryExpression::bodyExpression): Deleted.
(WebCore::WHLSL::AST::TernaryExpression::elseExpression): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLType.cpp: Added.
(WebCore::WHLSL::AST::Type::destroy):
(WebCore::WHLSL::AST::Type::unifyNode):
(WebCore::WHLSL::AST::ResolvableType::canResolve const):
(WebCore::WHLSL::AST::ResolvableType::conversionCost const):
(WebCore::WHLSL::AST::UnnamedType::toString const):
* Modules/webgpu/WHLSL/AST/WHLSLType.h:
(WebCore::WHLSL::AST::Type::Type):
(WebCore::WHLSL::AST::Type::kind const):
(WebCore::WHLSL::AST::Type::isUnnamedType const):
(WebCore::WHLSL::AST::Type::isNamedType const):
(WebCore::WHLSL::AST::Type::isResolvableType const):
(WebCore::WHLSL::AST::Type::isTypeReference const):
(WebCore::WHLSL::AST::Type::isPointerType const):
(WebCore::WHLSL::AST::Type::isArrayReferenceType const):
(WebCore::WHLSL::AST::Type::isArrayType const):
(WebCore::WHLSL::AST::Type::isReferenceType const):
(WebCore::WHLSL::AST::Type::isTypeDefinition const):
(WebCore::WHLSL::AST::Type::isStructureDefinition const):
(WebCore::WHLSL::AST::Type::isEnumerationDefinition const):
(WebCore::WHLSL::AST::Type::isNativeTypeDeclaration const):
(WebCore::WHLSL::AST::Type::isFloatLiteralType const):
(WebCore::WHLSL::AST::Type::isIntegerLiteralType const):
(WebCore::WHLSL::AST::Type::isNullLiteralType const):
(WebCore::WHLSL::AST::Type::isUnsignedIntegerLiteralType const):
(WebCore::WHLSL::AST::Type::unifyNode const):
* Modules/webgpu/WHLSL/AST/WHLSLTypeDefinition.h:
(WebCore::WHLSL::AST::TypeDefinition::TypeDefinition): Deleted.
(WebCore::WHLSL::AST::TypeDefinition::type): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
* Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.cpp:
(WebCore::WHLSL::AST::UnnamedType::hash const):
(WebCore::WHLSL::AST::UnnamedType::operator== const):
* Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h:
(WebCore::WHLSL::AST::UnnamedType::UnnamedType):
(WebCore::WHLSL::AST::UnnamedType::unifyNodeImpl):
(): Deleted.
(WebCore::WHLSL::AST::UnnamedType::kind const): Deleted.
(WebCore::WHLSL::AST::UnnamedType::isTypeReference const): Deleted.
(WebCore::WHLSL::AST::UnnamedType::isPointerType const): Deleted.
(WebCore::WHLSL::AST::UnnamedType::isArrayReferenceType const): Deleted.
(WebCore::WHLSL::AST::UnnamedType::isArrayType const): Deleted.
(WebCore::WHLSL::AST::UnnamedType::isReferenceType const): Deleted.
(WebCore::WHLSL::AST::UnnamedType::unifyNode const): Deleted.
(WebCore::WHLSL::AST::UnnamedType::unifyNode): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h:
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::UnsignedIntegerLiteral): Deleted.
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::type): Deleted.
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::value const): Deleted.
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::clone const): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp:
(WebCore::WHLSL::AST::UnsignedIntegerLiteralType::UnsignedIntegerLiteralType):
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h:
(WebCore::WHLSL::AST::UnsignedIntegerLiteralType::value const): Deleted.
(WebCore::WHLSL::AST::UnsignedIntegerLiteralType::preferredType): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.h:
(WebCore::WHLSL::AST::VariableDeclarationsStatement::VariableDeclarationsStatement): Deleted.
(WebCore::WHLSL::AST::VariableDeclarationsStatement::variableDeclarations): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h:
(WebCore::WHLSL::AST::VariableReference::VariableReference): Deleted.
(WebCore::WHLSL::AST::VariableReference::wrap): Deleted.
(WebCore::WHLSL::AST::VariableReference::name): Deleted.
(WebCore::WHLSL::AST::VariableReference::variable): Deleted.
(WebCore::WHLSL::AST::VariableReference::setVariable): Deleted.
* Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h:
(WebCore::WHLSL::AST::WhileLoop::WhileLoop): Deleted.
(WebCore::WHLSL::AST::WhileLoop::conditional): Deleted.
(WebCore::WHLSL::AST::WhileLoop::body): Deleted.
* Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp:
(WebCore::WHLSL::Metal::BaseTypeNameNode::isPointerTypeNameNode const):
(WebCore::WHLSL::Metal::BaseTypeNameNode::isArrayReferenceTypeNameNode const):
(WebCore::WHLSL::Metal::BaseTypeNameNode::isArrayTypeNameNode const):
(WebCore::WHLSL::Metal::TypeNamer::createNameNode):
(WebCore::WHLSL::Metal::parent):
(WebCore::WHLSL::Metal::TypeNamer::emitUnnamedTypeDefinition):
* Modules/webgpu/WHLSL/WHLSLParser.cpp:
(WebCore::WHLSL::Parser::parseSuffixOperator):
(WebCore::WHLSL::Parser::completeAssignment):
(WebCore::WHLSL::Parser::parsePossiblePrefix):
* Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp:
* Modules/webgpu/WHLSL/WHLSLVisitor.cpp:
(WebCore::WHLSL::Visitor::visit):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* workers/WorkerScriptLoader.h:

Source/WTF:

Make RefCounted use std::default_delete instead of explicitly calling delete.
This allows uses of RefCounted to define their own custom deleter.

* wtf/RefCounted.h:
(WTF::RefCounted::deref const):
* wtf/UniqueRef.h:
(WTF::UniqueRef::UniqueRef):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248488 268f45cc-cd09-0410-ab3c-d52691b4dbfc

76 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/RefCounted.h
Source/WTF/wtf/UniqueRef.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBlock.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBooleanLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBreak.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCommaExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLContinue.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDefaultDelete.h [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDereferenceExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDoWhileLoop.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEffectfulExpressionStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationMemberLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.cpp [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFallthrough.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLForLoop.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIfStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLLogicalExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLLogicalNotExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNamedType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNullLiteralType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPointerType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReplaceWith.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResolvableType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReturn.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.cpp [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatementList.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStructureElement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSwitchCase.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSwitchStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTernaryExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLType.cpp [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeDefinition.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLVisitor.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/workers/WorkerScriptLoader.h

index 98fb026..4ba60cc 100644 (file)
@@ -1,3 +1,18 @@
+2019-08-09  Saam Barati  <sbarati@apple.com>
+
+        [WHLSL] Devirtualize the AST
+        https://bugs.webkit.org/show_bug.cgi?id=200522
+
+        Reviewed by Robin Morisset.
+
+        Make RefCounted use std::default_delete instead of explicitly calling delete.
+        This allows uses of RefCounted to define their own custom deleter.
+
+        * wtf/RefCounted.h:
+        (WTF::RefCounted::deref const):
+        * wtf/UniqueRef.h:
+        (WTF::UniqueRef::UniqueRef):
+
 2019-08-08  Chris Dumez  <cdumez@apple.com>
 
         Fix thread safety issue in AudioSampleDataSource() constructor
index 13762e0..ea9782a 100644 (file)
@@ -136,13 +136,13 @@ inline void adopted(RefCountedBase* object)
 }
 #endif
 
-template<typename T> class RefCounted : public RefCountedBase {
+template<typename T, typename Deleter = std::default_delete<T>> class RefCounted : public RefCountedBase {
     WTF_MAKE_NONCOPYABLE(RefCounted); WTF_MAKE_FAST_ALLOCATED;
 public:
     void deref() const
     {
         if (derefBase())
-            delete static_cast<const T*>(this);
+            Deleter()(const_cast<T*>(static_cast<const T*>(this)));
     }
 
 protected:
index d6d639a..73e9dfe 100644 (file)
@@ -43,7 +43,7 @@ class UniqueRef {
 public:
     template <typename U>
     UniqueRef(UniqueRef<U>&& other)
-        : m_ref(WTFMove(other.m_ref))
+        : m_ref(other.m_ref.release())
     {
         ASSERT(m_ref);
     }
index 7acc75b..3ffe620 100644 (file)
@@ -1,3 +1,407 @@
+2019-08-09  Saam Barati  <sbarati@apple.com>
+
+        [WHLSL] Devirtualize the AST
+        https://bugs.webkit.org/show_bug.cgi?id=200522
+
+        Reviewed by Robin Morisset.
+
+        This patch devirtualizes the AST for Type, Expression, and Statement.
+        We now have an enum which represents all the concrete types in the
+        three hierarchies. Doing dynamic dispatch is implemented as a switch
+        on that type enum.
+        
+        The interesting part of this patch is how to handle destruction. We do
+        this by defining a custom deleter for all nodes in the AST. This ensures
+        that when they're used inside UniqueRef, unique_ptr, Ref, and RefPtr,
+        we do dynamic dispatch when we delete the object. This allows each base
+        class to define a "destroy" method which does dynamic dispatch on type
+        and calls the appropriate delete. We also mark all non-concrete nodes
+        in all type hierarchies with a protected destructor, which ensures it's
+        never called except from within the concrete child classes. We allow
+        all concrete classes to have public destructors, as it's valid for
+        their destructors to be called explicitly since there is no need for
+        dynamic dispatch in such scenarios. All concrete classes are also marked
+        as final.
+        
+        This is a 3ms speedup on compute_boids, which is about a 10% improvement
+        in the WHLSL compiler.
+
+        * Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLArrayType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h:
+        (WebCore::WHLSL::AST::AssignmentExpression::AssignmentExpression): Deleted.
+        (WebCore::WHLSL::AST::AssignmentExpression::left): Deleted.
+        (WebCore::WHLSL::AST::AssignmentExpression::right): Deleted.
+        (WebCore::WHLSL::AST::AssignmentExpression::takeRight): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLBlock.h:
+        (WebCore::WHLSL::AST::Block::Block): Deleted.
+        (WebCore::WHLSL::AST::Block::statements): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLBooleanLiteral.h:
+        (WebCore::WHLSL::AST::BooleanLiteral::BooleanLiteral): Deleted.
+        (WebCore::WHLSL::AST::BooleanLiteral::value const): Deleted.
+        (WebCore::WHLSL::AST::BooleanLiteral::clone const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLBreak.h:
+        (WebCore::WHLSL::AST::Break::Break): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h:
+        (WebCore::WHLSL::AST::CallExpression::CallExpression): Deleted.
+        (WebCore::WHLSL::AST::CallExpression::arguments): Deleted.
+        (WebCore::WHLSL::AST::CallExpression::name): Deleted.
+        (WebCore::WHLSL::AST::CallExpression::setCastData): Deleted.
+        (WebCore::WHLSL::AST::CallExpression::isCast): Deleted.
+        (WebCore::WHLSL::AST::CallExpression::castReturnType): Deleted.
+        (WebCore::WHLSL::AST::CallExpression::function): Deleted.
+        (WebCore::WHLSL::AST::CallExpression::setFunction): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLCommaExpression.h:
+        (WebCore::WHLSL::AST::CommaExpression::CommaExpression): Deleted.
+        (WebCore::WHLSL::AST::CommaExpression::list): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLConstantExpression.h:
+        (WebCore::WHLSL::AST::ConstantExpression::ConstantExpression): Deleted.
+        (WebCore::WHLSL::AST::ConstantExpression::integerLiteral): Deleted.
+        (WebCore::WHLSL::AST::ConstantExpression::visit): Deleted.
+        (WebCore::WHLSL::AST::ConstantExpression::visit const): Deleted.
+        (WebCore::WHLSL::AST::ConstantExpression::clone const): Deleted.
+        (WebCore::WHLSL::AST::ConstantExpression::matches const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLContinue.h:
+        (WebCore::WHLSL::AST::Continue::Continue): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLDefaultDelete.h: Added.
+        * Modules/webgpu/WHLSL/AST/WHLSLDereferenceExpression.h:
+        (WebCore::WHLSL::AST::DereferenceExpression::DereferenceExpression): Deleted.
+        (WebCore::WHLSL::AST::DereferenceExpression::pointer): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLDoWhileLoop.h:
+        (WebCore::WHLSL::AST::DoWhileLoop::DoWhileLoop): Deleted.
+        (WebCore::WHLSL::AST::DoWhileLoop::body): Deleted.
+        (WebCore::WHLSL::AST::DoWhileLoop::conditional): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h:
+        (WebCore::WHLSL::AST::DotExpression::DotExpression): Deleted.
+        (WebCore::WHLSL::AST::DotExpression::fieldName): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLEffectfulExpressionStatement.h:
+        (WebCore::WHLSL::AST::EffectfulExpressionStatement::EffectfulExpressionStatement): Deleted.
+        (WebCore::WHLSL::AST::EffectfulExpressionStatement::effectfulExpression): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h:
+        (WebCore::WHLSL::AST::EnumerationDefinition::EnumerationDefinition): Deleted.
+        (WebCore::WHLSL::AST::EnumerationDefinition::type): Deleted.
+        (WebCore::WHLSL::AST::EnumerationDefinition::add): Deleted.
+        (WebCore::WHLSL::AST::EnumerationDefinition::memberByName): Deleted.
+        (WebCore::WHLSL::AST::EnumerationDefinition::enumerationMembers): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLEnumerationMemberLiteral.h:
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::EnumerationMemberLiteral): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::wrap): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::left const): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::right const): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::clone const): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationDefinition): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationDefinition const): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationMember): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::enumerationMember const): Deleted.
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::setEnumerationMember): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLExpression.cpp: Added.
+        (WebCore::WHLSL::AST::Expression::destroy):
+        (WebCore::WHLSL::AST::PropertyAccessExpression::getterFunctionName const):
+        (WebCore::WHLSL::AST::PropertyAccessExpression::setterFunctionName const):
+        (WebCore::WHLSL::AST::PropertyAccessExpression::anderFunctionName const):
+        * Modules/webgpu/WHLSL/AST/WHLSLExpression.h:
+        (WebCore::WHLSL::AST::Expression::Expression):
+        (WebCore::WHLSL::AST::Expression::kind const):
+        (WebCore::WHLSL::AST::Expression::isAssignmentExpression const):
+        (WebCore::WHLSL::AST::Expression::isBooleanLiteral const):
+        (WebCore::WHLSL::AST::Expression::isCallExpression const):
+        (WebCore::WHLSL::AST::Expression::isCommaExpression const):
+        (WebCore::WHLSL::AST::Expression::isDereferenceExpression const):
+        (WebCore::WHLSL::AST::Expression::isDotExpression const):
+        (WebCore::WHLSL::AST::Expression::isGlobalVariableReference const):
+        (WebCore::WHLSL::AST::Expression::isFloatLiteral const):
+        (WebCore::WHLSL::AST::Expression::isIndexExpression const):
+        (WebCore::WHLSL::AST::Expression::isIntegerLiteral const):
+        (WebCore::WHLSL::AST::Expression::isLogicalExpression const):
+        (WebCore::WHLSL::AST::Expression::isLogicalNotExpression const):
+        (WebCore::WHLSL::AST::Expression::isMakeArrayReferenceExpression const):
+        (WebCore::WHLSL::AST::Expression::isMakePointerExpression const):
+        (WebCore::WHLSL::AST::Expression::isNullLiteral const):
+        (WebCore::WHLSL::AST::Expression::isPropertyAccessExpression const):
+        (WebCore::WHLSL::AST::Expression::isReadModifyWriteExpression const):
+        (WebCore::WHLSL::AST::Expression::isTernaryExpression const):
+        (WebCore::WHLSL::AST::Expression::isUnsignedIntegerLiteral const):
+        (WebCore::WHLSL::AST::Expression::isVariableReference const):
+        (WebCore::WHLSL::AST::Expression::isEnumerationMemberLiteral const):
+        (WebCore::WHLSL::AST::Expression::codeLocation const):
+        (WebCore::WHLSL::AST::Expression::updateCodeLocation):
+        * Modules/webgpu/WHLSL/AST/WHLSLFallthrough.h:
+        (WebCore::WHLSL::AST::Fallthrough::Fallthrough): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h:
+        (WebCore::WHLSL::AST::FloatLiteral::FloatLiteral): Deleted.
+        (WebCore::WHLSL::AST::FloatLiteral::type): Deleted.
+        (WebCore::WHLSL::AST::FloatLiteral::value const): Deleted.
+        (WebCore::WHLSL::AST::FloatLiteral::clone const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp:
+        (WebCore::WHLSL::AST::FloatLiteralType::FloatLiteralType):
+        * Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h:
+        (WebCore::WHLSL::AST::FloatLiteralType::value const): Deleted.
+        (WebCore::WHLSL::AST::FloatLiteralType::preferredType): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLForLoop.h:
+        (WebCore::WHLSL::AST::ForLoop::ForLoop): Deleted.
+        (WebCore::WHLSL::AST::ForLoop::~ForLoop): Deleted.
+        (WebCore::WHLSL::AST::ForLoop::initialization): Deleted.
+        (WebCore::WHLSL::AST::ForLoop::condition): Deleted.
+        (WebCore::WHLSL::AST::ForLoop::increment): Deleted.
+        (WebCore::WHLSL::AST::ForLoop::body): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h:
+        (WebCore::WHLSL::AST::GlobalVariableReference::GlobalVariableReference): Deleted.
+        (WebCore::WHLSL::AST::GlobalVariableReference::structField): Deleted.
+        (WebCore::WHLSL::AST::GlobalVariableReference::base): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLIfStatement.h:
+        (WebCore::WHLSL::AST::IfStatement::IfStatement): Deleted.
+        (WebCore::WHLSL::AST::IfStatement::conditional): Deleted.
+        (WebCore::WHLSL::AST::IfStatement::body): Deleted.
+        (WebCore::WHLSL::AST::IfStatement::elseBody): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h:
+        (WebCore::WHLSL::AST::IndexExpression::IndexExpression): Deleted.
+        (WebCore::WHLSL::AST::IndexExpression::indexExpression): Deleted.
+        (WebCore::WHLSL::AST::IndexExpression::takeIndex): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h:
+        (WebCore::WHLSL::AST::IntegerLiteral::IntegerLiteral): Deleted.
+        (WebCore::WHLSL::AST::IntegerLiteral::type): Deleted.
+        (WebCore::WHLSL::AST::IntegerLiteral::value const): Deleted.
+        (WebCore::WHLSL::AST::IntegerLiteral::clone const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp:
+        (WebCore::WHLSL::AST::IntegerLiteralType::IntegerLiteralType):
+        * Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h:
+        (WebCore::WHLSL::AST::IntegerLiteralType::value const): Deleted.
+        (WebCore::WHLSL::AST::IntegerLiteralType::preferredType): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLLogicalExpression.h:
+        (WebCore::WHLSL::AST::LogicalExpression::LogicalExpression): Deleted.
+        (WebCore::WHLSL::AST::LogicalExpression::type const): Deleted.
+        (WebCore::WHLSL::AST::LogicalExpression::left): Deleted.
+        (WebCore::WHLSL::AST::LogicalExpression::right): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLLogicalNotExpression.h:
+        (WebCore::WHLSL::AST::LogicalNotExpression::LogicalNotExpression): Deleted.
+        (WebCore::WHLSL::AST::LogicalNotExpression::operand): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h:
+        (WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression): Deleted.
+        (WebCore::WHLSL::AST::MakeArrayReferenceExpression::leftValue): Deleted.
+        (WebCore::WHLSL::AST::MakeArrayReferenceExpression::mightEscape const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h:
+        (WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression): Deleted.
+        (WebCore::WHLSL::AST::MakePointerExpression::leftValue): Deleted.
+        (WebCore::WHLSL::AST::MakePointerExpression::mightEscape const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLNamedType.h:
+        (WebCore::WHLSL::AST::NamedType::NamedType):
+        (WebCore::WHLSL::AST::NamedType::unifyNodeImpl):
+        (): Deleted.
+        (WebCore::WHLSL::AST::NamedType::isTypeDefinition const): Deleted.
+        (WebCore::WHLSL::AST::NamedType::isStructureDefinition const): Deleted.
+        (WebCore::WHLSL::AST::NamedType::isEnumerationDefinition const): Deleted.
+        (WebCore::WHLSL::AST::NamedType::isNativeTypeDeclaration const): Deleted.
+        (WebCore::WHLSL::AST::NamedType::unifyNode const): Deleted.
+        (WebCore::WHLSL::AST::NamedType::unifyNode): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h:
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::NativeTypeDeclaration): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::typeArguments): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isInt const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isNumber const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isFloating const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isAtomic const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isVector const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isMatrix const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isOpaqueType const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isTexture const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isTextureArray const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isDepthTexture const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isWritableTexture const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::textureDimension const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::isSigned const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::std::function<bool const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::std::function<int64_t const): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::iterateAllValues): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsInt): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsNumber): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsFloating): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsAtomic): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsVector): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsMatrix): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsOpaqueType): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsTexture): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsTextureArray): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsDepthTexture): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsWritableTexture): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setTextureDimension): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIsSigned): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setCanRepresentInteger): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setCanRepresentUnsignedInteger): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setCanRepresentFloat): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setSuccessor): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setFormatValueFromInteger): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setFormatValueFromUnsignedInteger): Deleted.
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::setIterateAllValues): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h:
+        (WebCore::WHLSL::AST::NullLiteral::NullLiteral): Deleted.
+        (WebCore::WHLSL::AST::NullLiteral::type): Deleted.
+        (WebCore::WHLSL::AST::NullLiteral::clone const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLNullLiteralType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLPointerType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h:
+        (WebCore::WHLSL::AST::PropertyAccessExpression::PropertyAccessExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h:
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::create): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::setNewValueExpression): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::setResultExpression): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::oldVariableReference): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::newVariableReference): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::leftValue): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::oldValue): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::newValue): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::newValueExpression): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::resultExpression): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::takeLeftValue): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::takeOldValue): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::takeNewValue): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::takeNewValueExpression): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::takeResultExpression): Deleted.
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::ReadModifyWriteExpression): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
+        (WebCore::WHLSL::AST::ReferenceType::ReferenceType):
+        * Modules/webgpu/WHLSL/AST/WHLSLResolvableType.h:
+        (WebCore::WHLSL::AST::ResolvableType::ResolvableType):
+        (): Deleted.
+        (WebCore::WHLSL::AST::ResolvableType::isFloatLiteralType const): Deleted.
+        (WebCore::WHLSL::AST::ResolvableType::isIntegerLiteralType const): Deleted.
+        (WebCore::WHLSL::AST::ResolvableType::isNullLiteralType const): Deleted.
+        (WebCore::WHLSL::AST::ResolvableType::isUnsignedIntegerLiteralType const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLReturn.h:
+        (WebCore::WHLSL::AST::Return::Return): Deleted.
+        (WebCore::WHLSL::AST::Return::value): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLStatement.cpp: Added.
+        (WebCore::WHLSL::AST::Statement::destroy):
+        * Modules/webgpu/WHLSL/AST/WHLSLStatement.h:
+        (WebCore::WHLSL::AST::Statement::Statement):
+        (WebCore::WHLSL::AST::Statement::kind const):
+        (WebCore::WHLSL::AST::Statement::isBlock const):
+        (WebCore::WHLSL::AST::Statement::isBreak const):
+        (WebCore::WHLSL::AST::Statement::isContinue const):
+        (WebCore::WHLSL::AST::Statement::isDoWhileLoop const):
+        (WebCore::WHLSL::AST::Statement::isEffectfulExpressionStatement const):
+        (WebCore::WHLSL::AST::Statement::isFallthrough const):
+        (WebCore::WHLSL::AST::Statement::isForLoop const):
+        (WebCore::WHLSL::AST::Statement::isIfStatement const):
+        (WebCore::WHLSL::AST::Statement::isReturn const):
+        (WebCore::WHLSL::AST::Statement::isStatementList const):
+        (WebCore::WHLSL::AST::Statement::isSwitchCase const):
+        (WebCore::WHLSL::AST::Statement::isSwitchStatement const):
+        (WebCore::WHLSL::AST::Statement::isVariableDeclarationsStatement const):
+        (WebCore::WHLSL::AST::Statement::isWhileLoop const):
+        (WebCore::WHLSL::AST::Statement::codeLocation const):
+        (WebCore::WHLSL::AST::Statement::updateCodeLocation):
+        * Modules/webgpu/WHLSL/AST/WHLSLStatementList.h:
+        (WebCore::WHLSL::AST::StatementList::StatementList): Deleted.
+        (WebCore::WHLSL::AST::StatementList::statements): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h:
+        (WebCore::WHLSL::AST::StructureDefinition::StructureDefinition): Deleted.
+        (WebCore::WHLSL::AST::StructureDefinition::structureElements): Deleted.
+        (WebCore::WHLSL::AST::StructureDefinition::find): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLStructureElement.h:
+        (WebCore::WHLSL::AST::StructureElement::StructureElement): Deleted.
+        (WebCore::WHLSL::AST::StructureElement::codeLocation const): Deleted.
+        (WebCore::WHLSL::AST::StructureElement::type): Deleted.
+        (WebCore::WHLSL::AST::StructureElement::name): Deleted.
+        (WebCore::WHLSL::AST::StructureElement::semantic): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLSwitchCase.h:
+        (WebCore::WHLSL::AST::SwitchCase::SwitchCase): Deleted.
+        (WebCore::WHLSL::AST::SwitchCase::value): Deleted.
+        (WebCore::WHLSL::AST::SwitchCase::block): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLSwitchStatement.h:
+        (WebCore::WHLSL::AST::SwitchStatement::SwitchStatement): Deleted.
+        (WebCore::WHLSL::AST::SwitchStatement::value): Deleted.
+        (WebCore::WHLSL::AST::SwitchStatement::switchCases): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLTernaryExpression.h:
+        (WebCore::WHLSL::AST::TernaryExpression::TernaryExpression): Deleted.
+        (WebCore::WHLSL::AST::TernaryExpression::predicate): Deleted.
+        (WebCore::WHLSL::AST::TernaryExpression::bodyExpression): Deleted.
+        (WebCore::WHLSL::AST::TernaryExpression::elseExpression): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLType.cpp: Added.
+        (WebCore::WHLSL::AST::Type::destroy):
+        (WebCore::WHLSL::AST::Type::unifyNode):
+        (WebCore::WHLSL::AST::ResolvableType::canResolve const):
+        (WebCore::WHLSL::AST::ResolvableType::conversionCost const):
+        (WebCore::WHLSL::AST::UnnamedType::toString const):
+        * Modules/webgpu/WHLSL/AST/WHLSLType.h:
+        (WebCore::WHLSL::AST::Type::Type):
+        (WebCore::WHLSL::AST::Type::kind const):
+        (WebCore::WHLSL::AST::Type::isUnnamedType const):
+        (WebCore::WHLSL::AST::Type::isNamedType const):
+        (WebCore::WHLSL::AST::Type::isResolvableType const):
+        (WebCore::WHLSL::AST::Type::isTypeReference const):
+        (WebCore::WHLSL::AST::Type::isPointerType const):
+        (WebCore::WHLSL::AST::Type::isArrayReferenceType const):
+        (WebCore::WHLSL::AST::Type::isArrayType const):
+        (WebCore::WHLSL::AST::Type::isReferenceType const):
+        (WebCore::WHLSL::AST::Type::isTypeDefinition const):
+        (WebCore::WHLSL::AST::Type::isStructureDefinition const):
+        (WebCore::WHLSL::AST::Type::isEnumerationDefinition const):
+        (WebCore::WHLSL::AST::Type::isNativeTypeDeclaration const):
+        (WebCore::WHLSL::AST::Type::isFloatLiteralType const):
+        (WebCore::WHLSL::AST::Type::isIntegerLiteralType const):
+        (WebCore::WHLSL::AST::Type::isNullLiteralType const):
+        (WebCore::WHLSL::AST::Type::isUnsignedIntegerLiteralType const):
+        (WebCore::WHLSL::AST::Type::unifyNode const):
+        * Modules/webgpu/WHLSL/AST/WHLSLTypeDefinition.h:
+        (WebCore::WHLSL::AST::TypeDefinition::TypeDefinition): Deleted.
+        (WebCore::WHLSL::AST::TypeDefinition::type): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.cpp:
+        (WebCore::WHLSL::AST::UnnamedType::hash const):
+        (WebCore::WHLSL::AST::UnnamedType::operator== const):
+        * Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h:
+        (WebCore::WHLSL::AST::UnnamedType::UnnamedType):
+        (WebCore::WHLSL::AST::UnnamedType::unifyNodeImpl):
+        (): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::kind const): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::isTypeReference const): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::isPointerType const): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::isArrayReferenceType const): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::isArrayType const): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::isReferenceType const): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::unifyNode const): Deleted.
+        (WebCore::WHLSL::AST::UnnamedType::unifyNode): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h:
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteral::UnsignedIntegerLiteral): Deleted.
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteral::type): Deleted.
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteral::value const): Deleted.
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteral::clone const): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp:
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteralType::UnsignedIntegerLiteralType):
+        * Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h:
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteralType::value const): Deleted.
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteralType::preferredType): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.h:
+        (WebCore::WHLSL::AST::VariableDeclarationsStatement::VariableDeclarationsStatement): Deleted.
+        (WebCore::WHLSL::AST::VariableDeclarationsStatement::variableDeclarations): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h:
+        (WebCore::WHLSL::AST::VariableReference::VariableReference): Deleted.
+        (WebCore::WHLSL::AST::VariableReference::wrap): Deleted.
+        (WebCore::WHLSL::AST::VariableReference::name): Deleted.
+        (WebCore::WHLSL::AST::VariableReference::variable): Deleted.
+        (WebCore::WHLSL::AST::VariableReference::setVariable): Deleted.
+        * Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h:
+        (WebCore::WHLSL::AST::WhileLoop::WhileLoop): Deleted.
+        (WebCore::WHLSL::AST::WhileLoop::conditional): Deleted.
+        (WebCore::WHLSL::AST::WhileLoop::body): Deleted.
+        * Modules/webgpu/WHLSL/Metal/WHLSLTypeNamer.cpp:
+        (WebCore::WHLSL::Metal::BaseTypeNameNode::isPointerTypeNameNode const):
+        (WebCore::WHLSL::Metal::BaseTypeNameNode::isArrayReferenceTypeNameNode const):
+        (WebCore::WHLSL::Metal::BaseTypeNameNode::isArrayTypeNameNode const):
+        (WebCore::WHLSL::Metal::TypeNamer::createNameNode):
+        (WebCore::WHLSL::Metal::parent):
+        (WebCore::WHLSL::Metal::TypeNamer::emitUnnamedTypeDefinition):
+        * Modules/webgpu/WHLSL/WHLSLParser.cpp:
+        (WebCore::WHLSL::Parser::parseSuffixOperator):
+        (WebCore::WHLSL::Parser::completeAssignment):
+        (WebCore::WHLSL::Parser::parsePossiblePrefix):
+        * Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp:
+        * Modules/webgpu/WHLSL/WHLSLVisitor.cpp:
+        (WebCore::WHLSL::Visitor::visit):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/WorkerScriptLoader.h:
+
 2019-08-09  Youenn Fablet  <youenn@apple.com>
 
         Pass a ScriptExecutionContext as input to register/unregister URLRegistry routines
index bb0d886..e06d85c 100644 (file)
@@ -32,6 +32,7 @@
 #include <wtf/FastMalloc.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/UniqueRef.h>
+#include <wtf/text/StringConcatenate.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -46,7 +47,7 @@ class ArrayReferenceType final : public ReferenceType {
     using Base = ReferenceType;
 
     ArrayReferenceType(CodeLocation location, AddressSpace addressSpace, Ref<UnnamedType> elementType)
-        : Base(location, addressSpace, WTFMove(elementType), Kind::ArrayReferenceType)
+        : Base(location, addressSpace, WTFMove(elementType), Kind::ArrayReference)
     {
     }
 public:
@@ -55,7 +56,7 @@ public:
         return adoptRef(*new ArrayReferenceType(location, addressSpace, WTFMove(elementType)));
     }
 
-    virtual ~ArrayReferenceType() = default;
+    ~ArrayReferenceType() = default;
 
     unsigned hash() const
     {
@@ -67,7 +68,7 @@ public:
         return addressSpace() == other.addressSpace() && elementType() == other.elementType();
     }
 
-    String toString() const override
+    String toString() const
     {
         return makeString(elementType().toString(), "[]");
     }
index 9778037..fc22f48 100644 (file)
@@ -46,7 +46,7 @@ class ArrayType final : public UnnamedType {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(ArrayType);
     ArrayType(CodeLocation location, Ref<UnnamedType> elementType, unsigned numElements)
-        : UnnamedType(location, Kind::ArrayType)
+        : UnnamedType(location, Kind::Array)
         , m_elementType(WTFMove(elementType))
         , m_numElements(numElements)
     {
@@ -58,7 +58,7 @@ public:
         return adoptRef(*new ArrayType(location, WTFMove(elementType), numElements));
     }
 
-    virtual ~ArrayType() = default;
+    ~ArrayType() = default;
 
     const UnnamedType& type() const { return m_elementType; }
     UnnamedType& type() { return m_elementType; }
@@ -74,7 +74,7 @@ public:
         return numElements() == other.numElements() && type() == other.type();
     }
 
-    String toString() const override
+    String toString() const
     {
         return makeString(type().toString(), '[', numElements(), ']');
     }
@@ -90,6 +90,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(ArrayType)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_UNNAMED_TYPE(ArrayType, isArrayType())
 
 #endif
index f7eecea..db7a7a1 100644 (file)
@@ -37,11 +37,11 @@ namespace WHLSL {
 
 namespace AST {
 
-class AssignmentExpression : public Expression {
+class AssignmentExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     AssignmentExpression(CodeLocation location, UniqueRef<Expression>&& left, UniqueRef<Expression>&& right)
-        : Expression(location)
+        : Expression(location, Kind::Assignment)
         , m_left(WTFMove(left))
         , m_right(WTFMove(right))
     {
@@ -50,13 +50,11 @@ public:
 #endif
     }
 
-    virtual ~AssignmentExpression() = default;
+    ~AssignmentExpression() = default;
 
     AssignmentExpression(const AssignmentExpression&) = delete;
     AssignmentExpression(AssignmentExpression&&) = default;
 
-    bool isAssignmentExpression() const override { return true; }
-
     Expression& left() { return m_left; }
     Expression& right() { return m_right; }
     UniqueRef<Expression> takeRight() { return WTFMove(m_right); }
@@ -75,6 +73,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(AssignmentExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(AssignmentExpression, isAssignmentExpression())
 
 #endif
index 26f68d8..8d735bf 100644 (file)
@@ -38,24 +38,22 @@ namespace WHLSL {
 
 namespace AST {
 
-class Block : public Statement {
+class Block final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     Block(CodeLocation location, Statements&& statements)
-        : Statement(location)
+        : Statement(location, Kind::Block)
         , m_statements(WTFMove(statements))
     {
     }
 
-    virtual ~Block() = default;
+    ~Block() = default;
 
     Block(const Block&) = delete;
     Block(Block&&) = default;
 
     Statements& statements() { return m_statements; }
 
-    bool isBlock() const override { return true; }
-
 private:
     Statements m_statements;
 };
@@ -66,6 +64,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(Block)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(Block, isBlock())
 
 #endif
index a386ae1..bf275d6 100644 (file)
@@ -36,16 +36,16 @@ namespace WHLSL {
 
 namespace AST {
 
-class BooleanLiteral : public Expression {
+class BooleanLiteral final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     BooleanLiteral(CodeLocation location, bool value)
-        : Expression(location)
+        : Expression(location, Kind::BooleanLiteral)
         , m_value(value)
     {
     }
 
-    virtual ~BooleanLiteral() = default;
+    ~BooleanLiteral() = default;
 
     BooleanLiteral(const BooleanLiteral&) = delete;
     BooleanLiteral(BooleanLiteral&&) = default;
@@ -55,8 +55,6 @@ public:
 
     bool value() const { return m_value; }
 
-    bool isBooleanLiteral() const override { return true; }
-
     BooleanLiteral clone() const
     {
         BooleanLiteral result(codeLocation(), m_value);
@@ -74,6 +72,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(BooleanLiteral)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(BooleanLiteral, isBooleanLiteral())
 
 #endif
index 3946774..68d5f82 100644 (file)
@@ -37,21 +37,19 @@ namespace WHLSL {
 
 namespace AST {
 
-class Break : public Statement {
+class Break final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     Break(CodeLocation location)
-        : Statement(location)
+        : Statement(location, Kind::Break)
     {
     }
 
-    virtual ~Break() = default;
+    ~Break() = default;
 
     Break(const Break&) = delete;
     Break(Break&&) = default;
 
-    bool isBreak() const override { return true; }
-
 private:
 };
 
@@ -61,6 +59,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(Break)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(Break, isBreak())
 
 #endif
index 3412645..f062bca 100644 (file)
@@ -40,27 +40,25 @@ namespace AST {
 
 class NamedType;
 
-class CallExpression : public Expression {
+class CallExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     CallExpression(CodeLocation location, String&& name, Vector<UniqueRef<Expression>>&& arguments)
-        : Expression(location)
+        : Expression(location, Kind::Call)
         , m_name(WTFMove(name))
         , m_arguments(WTFMove(arguments))
     {
     }
 
-    virtual ~CallExpression() = default;
-
     CallExpression(const CallExpression&) = delete;
     CallExpression(CallExpression&&) = default;
 
-    bool isCallExpression() const override { return true; }
-
     Vector<UniqueRef<Expression>>& arguments() { return m_arguments; }
 
     String& name() { return m_name; }
 
+    ~CallExpression() = default;
+
     void setCastData(NamedType& namedType)
     {
         m_castReturnType = &namedType;
@@ -93,6 +91,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(CallExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(CallExpression, isCallExpression())
 
 #endif
index f94f0de..2e67534 100644 (file)
@@ -38,22 +38,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class CommaExpression : public Expression {
+class CommaExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     CommaExpression(CodeLocation location, Vector<UniqueRef<Expression>>&& list)
-        : Expression(location)
+        : Expression(location, Kind::Comma)
         , m_list(WTFMove(list))
     {
     }
 
-    virtual ~CommaExpression() = default;
+    ~CommaExpression() = default;
 
     CommaExpression(const CommaExpression&) = delete;
     CommaExpression(CommaExpression&&) = default;
 
-    bool isCommaExpression() const override { return true; }
-
     Vector<UniqueRef<Expression>>& list() { return m_list; }
 
 private:
@@ -66,6 +64,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(CommaExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(CommaExpression, isCommaExpression())
 
 #endif
index 0b38752..8f22f57 100644 (file)
@@ -45,7 +45,7 @@ namespace AST {
 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198158 macOS Sierra doesn't seem to support putting Variants inside Variants,
 // so this is a wrapper class to make sure that doesn't happen. As soon as we don't
 // have to support Sierra, this can be migrated to a Variant proper.
-class ConstantExpression {
+class ConstantExpression final {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     ConstantExpression(IntegerLiteral&& integerLiteral)
index d7e33c8..4378d61 100644 (file)
@@ -37,21 +37,19 @@ namespace WHLSL {
 
 namespace AST {
 
-class Continue : public Statement {
+class Continue final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     Continue(CodeLocation location)
-        : Statement(location)
+        : Statement(location, Kind::Continue)
     {
     }
 
-    virtual ~Continue() = default;
+    ~Continue() = default;
 
     Continue(const Continue&) = delete;
     Continue(Continue&&) = default;
 
-    bool isContinue() const override { return true; }
-
 private:
 };
 
@@ -61,6 +59,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(Continue)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(Continue, isContinue())
 
 #endif
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDefaultDelete.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDefaultDelete.h
new file mode 100644 (file)
index 0000000..7fef462
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include <type_traits>
+
+#define DEFINE_DEFAULT_DELETE(type) \
+    namespace std { \
+        template<> \
+        struct default_delete<WebCore::WHLSL::AST::type> { \
+            template <typename T> \
+            void callDelete(T* t) \
+            { \
+                delete t; \
+            } \
+            template <typename T> \
+            void callDestroy(T* t) \
+            { \
+                WebCore::WHLSL::AST::type::destroy(*t); \
+            } \
+            constexpr void operator()(WebCore::WHLSL::AST::type* value) \
+            { \
+                if constexpr (std::is_final<WebCore::WHLSL::AST::type>::value) \
+                    callDelete(value); \
+                else \
+                    callDestroy(value); \
+            } \
+        }; \
+    } \
+
+#endif
index 85ca677..8982d60 100644 (file)
@@ -37,22 +37,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class DereferenceExpression : public Expression {
+class DereferenceExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     DereferenceExpression(CodeLocation location, UniqueRef<Expression>&& pointer)
-        : Expression(location)
+        : Expression(location, Kind::Dereference)
         , m_pointer(WTFMove(pointer))
     {
     }
 
-    virtual ~DereferenceExpression() = default;
+    ~DereferenceExpression() = default;
 
     DereferenceExpression(const DereferenceExpression&) = delete;
     DereferenceExpression(DereferenceExpression&&) = default;
 
-    bool isDereferenceExpression() const override { return true; }
-
     Expression& pointer() { return m_pointer; }
 
 private:
@@ -65,6 +63,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(DereferenceExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(DereferenceExpression, isDereferenceExpression())
 
 #endif
index bd154a3..d5c9313 100644 (file)
@@ -38,23 +38,21 @@ namespace WHLSL {
 
 namespace AST {
 
-class DoWhileLoop : public Statement {
+class DoWhileLoop final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     DoWhileLoop(CodeLocation location, UniqueRef<Statement>&& body, UniqueRef<Expression>&& conditional)
-        : Statement(location)
+        : Statement(location, Kind::DoWhileLoop)
         , m_body(WTFMove(body))
         , m_conditional(WTFMove(conditional))
     {
     }
 
-    virtual ~DoWhileLoop() = default;
+    ~DoWhileLoop() = default;
 
     DoWhileLoop(const DoWhileLoop&) = delete;
     DoWhileLoop(DoWhileLoop&&) = default;
 
-    bool isDoWhileLoop() const override { return true; }
-
     Statement& body() { return m_body; }
     Expression& conditional() { return m_conditional; }
 
@@ -69,6 +67,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(DoWhileLoop)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(DoWhileLoop, isDoWhileLoop())
 
 #endif
index d06c8e3..d85c6a6 100644 (file)
@@ -38,33 +38,31 @@ namespace WHLSL {
 
 namespace AST {
 
-class DotExpression : public PropertyAccessExpression {
+class DotExpression final : public PropertyAccessExpression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     DotExpression(CodeLocation location, UniqueRef<Expression>&& base, String&& fieldName)
-        : PropertyAccessExpression(location, WTFMove(base))
+        : PropertyAccessExpression(location, Kind::Dot, WTFMove(base))
         , m_fieldName(WTFMove(fieldName))
     {
     }
 
-    virtual ~DotExpression() = default;
+    ~DotExpression() = default;
 
     DotExpression(const DotExpression&) = delete;
     DotExpression(DotExpression&&) = default;
 
-    bool isDotExpression() const override { return true; }
-
-    String getterFunctionName() const override
+    String getterFunctionName() const
     {
         return makeString("operator.", m_fieldName);
     }
 
-    String setterFunctionName() const override
+    String setterFunctionName() const
     {
         return makeString("operator.", m_fieldName, "=");
     }
 
-    String anderFunctionName() const override
+    String anderFunctionName() const
     {
         return makeString("operator&.", m_fieldName);
     }
@@ -81,6 +79,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(DotExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(DotExpression, isDotExpression())
 
 #endif
index 6688e2b..9df4d28 100644 (file)
@@ -38,22 +38,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class EffectfulExpressionStatement : public Statement {
+class EffectfulExpressionStatement final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     EffectfulExpressionStatement(UniqueRef<Expression>&& effectfulExpression)
-        : Statement(effectfulExpression->codeLocation())
+        : Statement(effectfulExpression->codeLocation(), Kind::EffectfulExpression)
         , m_effectfulExpression(WTFMove(effectfulExpression))
     {
     }
 
-    virtual ~EffectfulExpressionStatement() = default;
+    ~EffectfulExpressionStatement() = default;
 
     EffectfulExpressionStatement(const EffectfulExpressionStatement&) = delete;
     EffectfulExpressionStatement(EffectfulExpressionStatement&&) = default;
 
-    bool isEffectfulExpressionStatement() const override { return true; }
-
     Expression& effectfulExpression() { return m_effectfulExpression; }
 
 private:
@@ -66,6 +64,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(EffectfulExpressionStatement)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(EffectfulExpressionStatement, isEffectfulExpressionStatement())
 
 #endif
index f17b9a4..cd0d1aa 100644 (file)
@@ -45,22 +45,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class EnumerationDefinition : public NamedType {
+class EnumerationDefinition final : public NamedType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     EnumerationDefinition(CodeLocation location, String&& name, Ref<UnnamedType> type)
-        : NamedType(location, WTFMove(name))
+        : NamedType(Kind::EnumerationDefinition, location, WTFMove(name))
         , m_type(WTFMove(type))
     {
     }
 
-    virtual ~EnumerationDefinition() = default;
+    ~EnumerationDefinition() = default;
 
     EnumerationDefinition(const EnumerationDefinition&) = delete;
     EnumerationDefinition(EnumerationDefinition&&) = default;
 
-    bool isEnumerationDefinition() const override { return true; }
-
     UnnamedType& type() { return m_type; }
 
     bool add(EnumerationMember&& member)
@@ -96,6 +94,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(EnumerationDefinition)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_NAMED_TYPE(EnumerationDefinition, isEnumerationDefinition())
 
 #endif
index 15bfb79..574675d 100644 (file)
@@ -40,17 +40,17 @@ namespace AST {
 class EnumerationDefinition;
 class EnumerationMember;
 
-class EnumerationMemberLiteral : public Expression {
+class EnumerationMemberLiteral final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     EnumerationMemberLiteral(CodeLocation location, String&& left, String&& right)
-        : Expression(location)
+        : Expression(location, Kind::EnumerationMemberLiteral)
         , m_left(WTFMove(left))
         , m_right(WTFMove(right))
     {
     }
 
-    virtual ~EnumerationMemberLiteral() = default;
+    ~EnumerationMemberLiteral() = default;
 
     explicit EnumerationMemberLiteral(const EnumerationMemberLiteral&) = delete;
     EnumerationMemberLiteral(EnumerationMemberLiteral&&) = default;
@@ -58,8 +58,6 @@ public:
     EnumerationMemberLiteral& operator=(const EnumerationMemberLiteral&) = delete;
     EnumerationMemberLiteral& operator=(EnumerationMemberLiteral&&) = default;
 
-    bool isEnumerationMemberLiteral() const override { return true; }
-
     static EnumerationMemberLiteral wrap(CodeLocation location, String&& left, String&& right, EnumerationDefinition& enumerationDefinition, EnumerationMember& enumerationMember)
     {
         EnumerationMemberLiteral result(location, WTFMove(left), WTFMove(right));
@@ -118,6 +116,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(EnumerationMemberLiteral)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(EnumerationMemberLiteral, isEnumerationMemberLiteral())
 
 #endif
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.cpp
new file mode 100644 (file)
index 0000000..6befc7c
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WHLSLExpression.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WHLSLAST.h"
+
+namespace WebCore {
+
+namespace WHLSL {
+
+namespace AST {
+
+void Expression::destroy(Expression& expression)
+{
+    switch (expression.kind()) {
+    case Expression::Kind::Assignment:
+        delete &downcast<AssignmentExpression>(expression);
+        break;
+    case Expression::Kind::BooleanLiteral:
+        delete &downcast<BooleanLiteral>(expression);
+        break;
+    case Expression::Kind::Call:
+        delete &downcast<CallExpression>(expression);
+        break;
+    case Expression::Kind::Comma:
+        delete &downcast<CommaExpression>(expression);
+        break;
+    case Expression::Kind::Dereference:
+        delete &downcast<DereferenceExpression>(expression);
+        break;
+    case Expression::Kind::FloatLiteral:
+        delete &downcast<FloatLiteral>(expression);
+        break;
+    case Expression::Kind::IntegerLiteral:
+        delete &downcast<IntegerLiteral>(expression);
+        break;
+    case Expression::Kind::Logical:
+        delete &downcast<LogicalExpression>(expression);
+        break;
+    case Expression::Kind::LogicalNot:
+        delete &downcast<LogicalNotExpression>(expression);
+        break;
+    case Expression::Kind::MakeArrayReference:
+        delete &downcast<MakeArrayReferenceExpression>(expression);
+        break;
+    case Expression::Kind::MakePointer:
+        delete &downcast<MakePointerExpression>(expression);
+        break;
+    case Expression::Kind::NullLiteral:
+        delete &downcast<NullLiteral>(expression);
+        break;
+    case Expression::Kind::Dot:
+        delete &downcast<DotExpression>(expression);
+        break;
+    case Expression::Kind::GlobalVariableReference:
+        delete &downcast<GlobalVariableReference>(expression);
+        break;
+    case Expression::Kind::Index:
+        delete &downcast<IndexExpression>(expression);
+        break;
+    case Expression::Kind::ReadModifyWrite:
+        delete &downcast<ReadModifyWriteExpression>(expression);
+        break;
+    case Expression::Kind::Ternary:
+        delete &downcast<TernaryExpression>(expression);
+        break;
+    case Expression::Kind::UnsignedIntegerLiteral:
+        delete &downcast<UnsignedIntegerLiteral>(expression);
+        break;
+    case Expression::Kind::EnumerationMemberLiteral:
+        delete &downcast<EnumerationMemberLiteral>(expression);
+        break;
+    case Expression::Kind::VariableReference:
+        delete &downcast<VariableReference>(expression);
+        break;
+    }
+}
+
+void Expression::destruct(Expression& expression)
+{
+    switch (expression.kind()) {
+    case Expression::Kind::Assignment:
+        downcast<AssignmentExpression>(expression).~AssignmentExpression();
+        break;
+    case Expression::Kind::BooleanLiteral:
+        downcast<BooleanLiteral>(expression).~BooleanLiteral();
+        break;
+    case Expression::Kind::Call:
+        downcast<CallExpression>(expression).~CallExpression();
+        break;
+    case Expression::Kind::Comma:
+        downcast<CommaExpression>(expression).~CommaExpression();
+        break;
+    case Expression::Kind::Dereference:
+        downcast<DereferenceExpression>(expression).~DereferenceExpression();
+        break;
+    case Expression::Kind::FloatLiteral:
+        downcast<FloatLiteral>(expression).~FloatLiteral();
+        break;
+    case Expression::Kind::IntegerLiteral:
+        downcast<IntegerLiteral>(expression).~IntegerLiteral();
+        break;
+    case Expression::Kind::Logical:
+        downcast<LogicalExpression>(expression).~LogicalExpression();
+        break;
+    case Expression::Kind::LogicalNot:
+        downcast<LogicalNotExpression>(expression).~LogicalNotExpression();
+        break;
+    case Expression::Kind::MakeArrayReference:
+        downcast<MakeArrayReferenceExpression>(expression).~MakeArrayReferenceExpression();
+        break;
+    case Expression::Kind::MakePointer:
+        downcast<MakePointerExpression>(expression).~MakePointerExpression();
+        break;
+    case Expression::Kind::NullLiteral:
+        downcast<NullLiteral>(expression).~NullLiteral();
+        break;
+    case Expression::Kind::Dot:
+        downcast<DotExpression>(expression).~DotExpression();
+        break;
+    case Expression::Kind::GlobalVariableReference:
+        downcast<GlobalVariableReference>(expression).~GlobalVariableReference();
+        break;
+    case Expression::Kind::Index:
+        downcast<IndexExpression>(expression).~IndexExpression();
+        break;
+    case Expression::Kind::ReadModifyWrite:
+        downcast<ReadModifyWriteExpression>(expression).~ReadModifyWriteExpression();
+        break;
+    case Expression::Kind::Ternary:
+        downcast<TernaryExpression>(expression).~TernaryExpression();
+        break;
+    case Expression::Kind::UnsignedIntegerLiteral:
+        downcast<UnsignedIntegerLiteral>(expression).~UnsignedIntegerLiteral();
+        break;
+    case Expression::Kind::EnumerationMemberLiteral:
+        downcast<EnumerationMemberLiteral>(expression).~EnumerationMemberLiteral();
+        break;
+    case Expression::Kind::VariableReference:
+        downcast<VariableReference>(expression).~VariableReference();
+        break;
+    }
+}
+
+String PropertyAccessExpression::getterFunctionName() const
+{
+    if (is<DotExpression>(*this))
+        return downcast<DotExpression>(*this).getterFunctionName();
+    if (is<IndexExpression>(*this))
+        return downcast<IndexExpression>(*this).getterFunctionName();
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+String PropertyAccessExpression::setterFunctionName() const
+{
+    if (is<DotExpression>(*this))
+        return downcast<DotExpression>(*this).setterFunctionName();
+    if (is<IndexExpression>(*this))
+        return downcast<IndexExpression>(*this).setterFunctionName();
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+String PropertyAccessExpression::anderFunctionName() const
+{
+    if (is<DotExpression>(*this))
+        return downcast<DotExpression>(*this).anderFunctionName();
+    if (is<IndexExpression>(*this))
+        return downcast<IndexExpression>(*this).anderFunctionName();
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+} // namespace AST
+
+} // namespace WHLSL
+
+} // namespace WebCore
+
+#endif
index ca90e3b..e15ef91 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "WHLSLAddressSpace.h"
 #include "WHLSLCodeLocation.h"
+#include "WHLSLDefaultDelete.h"
 #include "WHLSLUnnamedType.h"
 #include <wtf/FastMalloc.h>
 #include <wtf/Optional.h>
@@ -42,13 +43,43 @@ namespace AST {
 
 class Expression {
     WTF_MAKE_FAST_ALLOCATED;
+
+protected:
+    ~Expression() = default;
+
 public:
-    Expression(CodeLocation codeLocation)
+
+    enum class Kind : uint8_t {
+        Assignment,
+        BooleanLiteral,
+        Call,
+        Comma,
+        Dereference,
+        Dot,
+        GlobalVariableReference,
+        FloatLiteral,
+        Index,
+        IntegerLiteral,
+        Logical,
+        LogicalNot,
+        MakeArrayReference,
+        MakePointer,
+        NullLiteral,
+        ReadModifyWrite,
+        Ternary,
+        UnsignedIntegerLiteral,
+        VariableReference,
+        EnumerationMemberLiteral,
+    };
+
+    Expression(CodeLocation codeLocation, Kind kind)
         : m_codeLocation(codeLocation)
+        , m_kind(kind)
     {
     }
 
-    virtual ~Expression() = default;
+    static void destroy(Expression&);
+    static void destruct(Expression&);
 
     Expression(const Expression&) = delete;
     Expression(Expression&&) = default;
@@ -92,27 +123,28 @@ public:
             other.setTypeAnnotation(TypeAnnotation(*typeAnnotation));
     }
 
-    virtual bool isAssignmentExpression() const { return false; }
-    virtual bool isBooleanLiteral() const { return false; }
-    virtual bool isCallExpression() const { return false; }
-    virtual bool isCommaExpression() const { return false; }
-    virtual bool isDereferenceExpression() const { return false; }
-    virtual bool isDotExpression() const { return false; }
-    virtual bool isGlobalVariableReference() const { return false; }
-    virtual bool isFloatLiteral() const { return false; }
-    virtual bool isIndexExpression() const { return false; }
-    virtual bool isIntegerLiteral() const { return false; }
-    virtual bool isLogicalExpression() const { return false; }
-    virtual bool isLogicalNotExpression() const { return false; }
-    virtual bool isMakeArrayReferenceExpression() const { return false; }
-    virtual bool isMakePointerExpression() const { return false; }
-    virtual bool isNullLiteral() const { return false; }
-    virtual bool isPropertyAccessExpression() const { return false; }
-    virtual bool isReadModifyWriteExpression() const { return false; }
-    virtual bool isTernaryExpression() const { return false; }
-    virtual bool isUnsignedIntegerLiteral() const { return false; }
-    virtual bool isVariableReference() const { return false; }
-    virtual bool isEnumerationMemberLiteral() const { return false; }
+    Kind kind() const  { return m_kind; }
+    bool isAssignmentExpression() const { return kind() == Kind::Assignment; }
+    bool isBooleanLiteral() const { return kind() == Kind::BooleanLiteral; }
+    bool isCallExpression() const { return kind() == Kind::Call; }
+    bool isCommaExpression() const { return kind() == Kind::Comma; }
+    bool isDereferenceExpression() const { return kind() == Kind::Dereference; }
+    bool isDotExpression() const { return kind() == Kind::Dot; }
+    bool isGlobalVariableReference() const { return kind() == Kind::GlobalVariableReference; }
+    bool isFloatLiteral() const { return kind() == Kind::FloatLiteral; }
+    bool isIndexExpression() const { return kind() == Kind::Index; }
+    bool isIntegerLiteral() const { return kind() == Kind::IntegerLiteral; }
+    bool isLogicalExpression() const { return kind() == Kind::Logical; }
+    bool isLogicalNotExpression() const { return kind() == Kind::LogicalNot; }
+    bool isMakeArrayReferenceExpression() const { return kind() == Kind::MakeArrayReference; }
+    bool isMakePointerExpression() const { return kind() == Kind::MakePointer; }
+    bool isNullLiteral() const { return kind() == Kind::NullLiteral; }
+    bool isPropertyAccessExpression() const { return isDotExpression() || isIndexExpression(); }
+    bool isReadModifyWriteExpression() const { return kind() == Kind::ReadModifyWrite; }
+    bool isTernaryExpression() const { return kind() == Kind::Ternary; }
+    bool isUnsignedIntegerLiteral() const { return kind() == Kind::UnsignedIntegerLiteral; }
+    bool isVariableReference() const { return kind() == Kind::VariableReference; }
+    bool isEnumerationMemberLiteral() const { return kind() == Kind::EnumerationMemberLiteral; }
 
     CodeLocation codeLocation() const { return m_codeLocation; }
     void updateCodeLocation(CodeLocation location) { m_codeLocation = location; }
@@ -121,6 +153,7 @@ private:
     CodeLocation m_codeLocation;
     RefPtr<UnnamedType> m_type;
     Optional<TypeAnnotation> m_typeAnnotation;
+    Kind m_kind;
 };
 
 } // namespace AST
@@ -129,6 +162,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(Expression)
+
 #define SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(ToValueTypeName, predicate) \
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WHLSL::AST::ToValueTypeName) \
     static bool isType(const WebCore::WHLSL::AST::Expression& expression) { return expression.predicate; } \
index 30d7ed4..4d53449 100644 (file)
@@ -37,21 +37,19 @@ namespace WHLSL {
 
 namespace AST {
 
-class Fallthrough : public Statement {
+class Fallthrough final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     Fallthrough(CodeLocation location)
-        : Statement(location)
+        : Statement(location, Kind::Fallthrough)
     {
     }
 
-    virtual ~Fallthrough() = default;
+    ~Fallthrough() = default;
 
     Fallthrough(const Fallthrough&) = delete;
     Fallthrough(Fallthrough&&) = default;
 
-    bool isFallthrough() const override { return true; }
-
 private:
 };
 
@@ -61,6 +59,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(Fallthrough)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(Fallthrough, isFallthrough())
 
 #endif
index 10bc2b4..936c297 100644 (file)
@@ -37,17 +37,17 @@ namespace WHLSL {
 
 namespace AST {
 
-class FloatLiteral : public Expression {
+class FloatLiteral final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     FloatLiteral(CodeLocation location, float value)
-        : Expression(location)
+        : Expression(location, Kind::FloatLiteral)
         , m_type(location, value)
         , m_value(value)
     {
     }
 
-    virtual ~FloatLiteral() = default;
+    ~FloatLiteral() = default;
 
     FloatLiteral(const FloatLiteral&) = delete;
     FloatLiteral(FloatLiteral&&) = default;
@@ -58,8 +58,6 @@ public:
     FloatLiteralType& type() { return m_type; }
     float value() const { return m_value; }
 
-    bool isFloatLiteral() const override { return true; }
-
     FloatLiteral clone() const
     {
         FloatLiteral result(codeLocation(), m_value);
@@ -81,6 +79,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(FloatLiteral)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(FloatLiteral, isFloatLiteral())
 
 #endif
index 413c07a..d01d21d 100644 (file)
@@ -39,17 +39,12 @@ namespace WHLSL {
 namespace AST {
 
 FloatLiteralType::FloatLiteralType(CodeLocation location, float value)
-    : m_value(value)
+    : ResolvableType(Kind::FloatLiteral)
+    , m_value(value)
     , m_preferredType(TypeReference::create(location, "float"_str, TypeArguments()))
 {
 }
 
-FloatLiteralType::~FloatLiteralType() = default;
-
-FloatLiteralType::FloatLiteralType(FloatLiteralType&&) = default;
-
-FloatLiteralType& FloatLiteralType::operator=(FloatLiteralType&&) = default;
-
 bool FloatLiteralType::canResolve(const Type& type) const
 {
     if (!is<NamedType>(type))
index 3294614..91036d4 100644 (file)
@@ -40,27 +40,25 @@ namespace AST {
 
 class TypeReference;
 
-class FloatLiteralType : public ResolvableType {
+class FloatLiteralType final : public ResolvableType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     FloatLiteralType(CodeLocation, float value);
 
-    virtual ~FloatLiteralType();
+    ~FloatLiteralType() = default;
 
     FloatLiteralType(const FloatLiteralType&) = delete;
-    FloatLiteralType(FloatLiteralType&&);
+    FloatLiteralType(FloatLiteralType&&) = default;
 
     FloatLiteralType& operator=(const FloatLiteralType&) = delete;
-    FloatLiteralType& operator=(FloatLiteralType&&);
-
-    bool isFloatLiteralType() const override { return true; }
+    FloatLiteralType& operator=(FloatLiteralType&&) = default;
 
     float value() const { return m_value; }
 
     TypeReference& preferredType() { return m_preferredType; }
 
-    bool canResolve(const Type&) const override;
-    unsigned conversionCost(const UnnamedType&) const override;
+    bool canResolve(const Type&) const;
+    unsigned conversionCost(const UnnamedType&) const;
 
     FloatLiteralType clone() const;
 
@@ -77,6 +75,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(FloatLiteralType)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_RESOLVABLE_TYPE(FloatLiteralType, isFloatLiteralType())
 
 #endif
index 7ea49e1..0a7e6f8 100644 (file)
@@ -42,11 +42,11 @@ namespace WHLSL {
 
 namespace AST {
 
-class ForLoop : public Statement {
+class ForLoop final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     ForLoop(CodeLocation location, Variant<UniqueRef<Statement>, UniqueRef<Expression>>&& initialization, std::unique_ptr<Expression>&& condition, std::unique_ptr<Expression>&& increment, UniqueRef<Statement>&& body)
-        : Statement(location)
+        : Statement(location, Kind::ForLoop)
         , m_initialization(WTFMove(initialization))
         , m_condition(WTFMove(condition))
         , m_increment(WTFMove(increment))
@@ -54,15 +54,11 @@ public:
     {
     }
 
-    virtual ~ForLoop()
-    {
-    }
+    ~ForLoop() = default;
 
     ForLoop(const ForLoop&) = delete;
     ForLoop(ForLoop&&) = default;
 
-    bool isForLoop() const override { return true; }
-
     Variant<UniqueRef<Statement>, UniqueRef<Expression>>& initialization() { return m_initialization; }
     Expression* condition() { return m_condition.get(); }
     Expression* increment() { return m_increment.get(); }
@@ -81,6 +77,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(ForLoop)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(ForLoop, isForLoop())
 
 #endif
index 0ef6eb9..954f61e 100644 (file)
@@ -37,19 +37,19 @@ namespace WHLSL {
 
 namespace AST {
 
-class GlobalVariableReference : public Expression {
+class GlobalVariableReference final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     GlobalVariableReference(CodeLocation location, UniqueRef<Expression>&& base, StructureElement* structField)
-        : Expression(location)
+        : Expression(location, Kind::GlobalVariableReference)
         , m_base(WTFMove(base))
         , m_structField(*structField)
     {
         ASSERT(structField);
     }
 
-    virtual ~GlobalVariableReference() = default;
-    bool isGlobalVariableReference() const override { return true; }
+    ~GlobalVariableReference() = default;
+    
     StructureElement& structField() { return m_structField; }
 
     Expression& base() { return m_base.get(); }
@@ -65,6 +65,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(GlobalVariableReference)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(GlobalVariableReference, isGlobalVariableReference())
 
 #endif
index 1155164..90740fd 100644 (file)
@@ -39,24 +39,22 @@ namespace WHLSL {
 
 namespace AST {
 
-class IfStatement : public Statement {
+class IfStatement final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     IfStatement(CodeLocation location, UniqueRef<Expression>&& conditional, UniqueRef<Statement>&& body, std::unique_ptr<Statement>&& elseBody)
-        : Statement(location)
+        : Statement(location, Kind::If)
         , m_conditional(WTFMove(conditional))
         , m_body(WTFMove(body))
         , m_elseBody(WTFMove(elseBody))
     {
     }
 
-    virtual ~IfStatement() = default;
+    ~IfStatement() = default;
 
     IfStatement(const IfStatement&) = delete;
     IfStatement(IfStatement&&) = default;
 
-    bool isIfStatement() const override { return true; }
-
     Expression& conditional() { return m_conditional; }
     Statement& body() { return m_body; }
     Statement* elseBody() { return m_elseBody.get(); }
@@ -73,6 +71,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(IfStatement)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(IfStatement, isIfStatement())
 
 #endif
index dd5c7f5..9c761c4 100644 (file)
@@ -38,33 +38,31 @@ namespace WHLSL {
 
 namespace AST {
 
-class IndexExpression : public PropertyAccessExpression {
+class IndexExpression final : public PropertyAccessExpression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     IndexExpression(CodeLocation location, UniqueRef<Expression>&& base, UniqueRef<Expression>&& index)
-        : PropertyAccessExpression(location, WTFMove(base))
+        : PropertyAccessExpression(location, Kind::Index, WTFMove(base))
         , m_index(WTFMove(index))
     {
     }
 
-    virtual ~IndexExpression() = default;
+    ~IndexExpression() = default;
 
     IndexExpression(const IndexExpression&) = delete;
     IndexExpression(IndexExpression&&) = default;
 
-    bool isIndexExpression() const override { return true; }
-
-    String getterFunctionName() const override
+    String getterFunctionName() const
     {
         return "operator[]"_str;
     }
 
-    String setterFunctionName() const override
+    String setterFunctionName() const
     {
         return "operator[]="_str;
     }
 
-    String anderFunctionName() const override
+    String anderFunctionName() const
     {
         return "operator&[]"_str;
     }
@@ -82,6 +80,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(IndexExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(IndexExpression, isIndexExpression())
 
 #endif
index ca627c9..44f38d7 100644 (file)
@@ -37,17 +37,17 @@ namespace WHLSL {
 
 namespace AST {
 
-class IntegerLiteral : public Expression {
+class IntegerLiteral final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     IntegerLiteral(CodeLocation location, int value)
-        : Expression(location)
+        : Expression(location, Kind::IntegerLiteral)
         , m_type(location, value)
         , m_value(value)
     {
     }
 
-    virtual ~IntegerLiteral() = default;
+    ~IntegerLiteral() = default;
 
     IntegerLiteral(const IntegerLiteral&) = delete;
     IntegerLiteral(IntegerLiteral&&) = default;
@@ -58,8 +58,6 @@ public:
     IntegerLiteralType& type() { return m_type; }
     int value() const { return m_value; }
 
-    bool isIntegerLiteral() const override { return true; }
-
     IntegerLiteral clone() const
     {
         IntegerLiteral result(codeLocation(), m_value);
@@ -83,6 +81,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(IntegerLiteral)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(IntegerLiteral, isIntegerLiteral())
 
 #endif
index f0282f4..92a8f3b 100644 (file)
@@ -40,17 +40,12 @@ namespace WHLSL {
 namespace AST {
 
 IntegerLiteralType::IntegerLiteralType(CodeLocation location, int value)
-    : m_value(value)
+    : ResolvableType(Kind::IntegerLiteral)
+    , m_value(value)
     , m_preferredType(TypeReference::create(location, "int"_str, TypeArguments()))
 {
 }
 
-IntegerLiteralType::~IntegerLiteralType() = default;
-
-IntegerLiteralType::IntegerLiteralType(IntegerLiteralType&&) = default;
-
-IntegerLiteralType& IntegerLiteralType::operator=(IntegerLiteralType&&) = default;
-
 bool IntegerLiteralType::canResolve(const Type& type) const
 {
     if (!is<NamedType>(type))
index 804591c..9eab985 100644 (file)
@@ -40,27 +40,25 @@ namespace AST {
 
 class TypeReference;
 
-class IntegerLiteralType : public ResolvableType {
+class IntegerLiteralType final : public ResolvableType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     IntegerLiteralType(CodeLocation, int value);
 
-    virtual ~IntegerLiteralType();
+    ~IntegerLiteralType() = default;
 
     IntegerLiteralType(const IntegerLiteralType&) = delete;
-    IntegerLiteralType(IntegerLiteralType&&);
+    IntegerLiteralType(IntegerLiteralType&&) = default;
 
     IntegerLiteralType& operator=(const IntegerLiteralType&) = delete;
-    IntegerLiteralType& operator=(IntegerLiteralType&&);
-
-    bool isIntegerLiteralType() const override { return true; }
+    IntegerLiteralType& operator=(IntegerLiteralType&&) = default;
 
     int value() const { return m_value; }
 
     TypeReference& preferredType() { return m_preferredType; }
 
-    bool canResolve(const Type&) const override;
-    unsigned conversionCost(const UnnamedType&) const override;
+    bool canResolve(const Type&) const;
+    unsigned conversionCost(const UnnamedType&) const;
 
     IntegerLiteralType clone() const;
 
@@ -77,6 +75,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(IntegerLiteralType)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_RESOLVABLE_TYPE(IntegerLiteralType, isIntegerLiteralType())
 
 #endif
index 25bbfd6..127653c 100644 (file)
@@ -37,7 +37,7 @@ namespace WHLSL {
 
 namespace AST {
 
-class LogicalExpression : public Expression {
+class LogicalExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     enum class Type : uint8_t {
@@ -46,22 +46,20 @@ public:
     };
 
     LogicalExpression(CodeLocation location, Type type, UniqueRef<Expression>&& left, UniqueRef<Expression>&& right)
-        : Expression(location)
+        : Expression(location, Kind::Logical)
         , m_type(type)
         , m_left(WTFMove(left))
         , m_right(WTFMove(right))
     {
     }
 
-    virtual ~LogicalExpression() = default;
+    ~LogicalExpression() = default;
 
     LogicalExpression(const LogicalExpression&) = delete;
     LogicalExpression(LogicalExpression&&) = default;
 
     Type type() const { return m_type; }
 
-    bool isLogicalExpression() const override { return true; }
-
     Expression& left() { return m_left; }
     Expression& right() { return m_right; }
 
@@ -77,6 +75,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(LogicalExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(LogicalExpression, isLogicalExpression())
 
 #endif
index 727cd2a..2e09cf2 100644 (file)
@@ -37,22 +37,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class LogicalNotExpression : public Expression {
+class LogicalNotExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     LogicalNotExpression(CodeLocation location, UniqueRef<Expression>&& operand)
-        : Expression(location)
+        : Expression(location, Kind::LogicalNot)
         , m_operand(WTFMove(operand))
     {
     }
 
-    virtual ~LogicalNotExpression() = default;
+    ~LogicalNotExpression() = default;
 
     LogicalNotExpression(const LogicalNotExpression&) = delete;
     LogicalNotExpression(LogicalNotExpression&&) = default;
 
-    bool isLogicalNotExpression() const override { return true; }
-
     Expression& operand() { return m_operand; }
 
 private:
@@ -65,6 +63,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(LogicalNotExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(LogicalNotExpression, isLogicalNotExpression())
 
 #endif
index 746fa47..1a28cce 100644 (file)
@@ -38,23 +38,21 @@ namespace WHLSL {
 
 namespace AST {
 
-class MakeArrayReferenceExpression : public Expression {
+class MakeArrayReferenceExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     MakeArrayReferenceExpression(CodeLocation location, UniqueRef<Expression>&& leftValue, AddressEscapeMode addressEscapeMode)
-        : Expression(location)
+        : Expression(location, Kind::MakeArrayReference)
         , m_leftValue(WTFMove(leftValue))
         , m_addressEscapeMode(addressEscapeMode)
     {
     }
 
-    virtual ~MakeArrayReferenceExpression() = default;
+    ~MakeArrayReferenceExpression() = default;
 
     MakeArrayReferenceExpression(const MakeArrayReferenceExpression&) = delete;
     MakeArrayReferenceExpression(MakeArrayReferenceExpression&&) = default;
 
-    bool isMakeArrayReferenceExpression() const override { return true; }
-
     Expression& leftValue() { return m_leftValue; }
 
     bool mightEscape() const { return m_addressEscapeMode == AddressEscapeMode::Escapes; }
@@ -70,6 +68,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(MakeArrayReferenceExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(MakeArrayReferenceExpression, isMakeArrayReferenceExpression())
 
 #endif
index cc56007..71e89ef 100644 (file)
@@ -38,23 +38,21 @@ namespace WHLSL {
 
 namespace AST {
 
-class MakePointerExpression : public Expression {
+class MakePointerExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     MakePointerExpression(CodeLocation location, UniqueRef<Expression>&& leftValue, AddressEscapeMode addressEscapeMode)
-        : Expression(location)
+        : Expression(location, Kind::MakePointer)
         , m_leftValue(WTFMove(leftValue))
         , m_addressEscapeMode(addressEscapeMode)
     {
     }
 
-    virtual ~MakePointerExpression() = default;
+    ~MakePointerExpression() = default;
 
     MakePointerExpression(const MakePointerExpression&) = delete;
     MakePointerExpression(MakePointerExpression&&) = default;
 
-    bool isMakePointerExpression() const override { return true; }
-
     Expression& leftValue() { return m_leftValue; }
 
     bool mightEscape() const { return m_addressEscapeMode == AddressEscapeMode::Escapes; }
@@ -70,6 +68,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(MakePointerExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(MakePointerExpression, isMakePointerExpression())
 
 #endif
index 3259d89..6c44303 100644 (file)
@@ -40,15 +40,18 @@ namespace AST {
 
 class NamedType : public Type {
     WTF_MAKE_FAST_ALLOCATED;
+
+protected:
+    ~NamedType() = default;
+
 public:
-    NamedType(CodeLocation location, String&& name)
-        : m_codeLocation(location)
+    NamedType(Kind kind, CodeLocation location, String&& name)
+        : Type(kind)
+        , m_codeLocation(location)
         , m_name(WTFMove(name))
     {
     }
 
-    virtual ~NamedType() = default;
-
     NamedType(const NamedType&) = delete;
     NamedType(NamedType&&) = default;
 
@@ -57,16 +60,10 @@ public:
 
     String& name() { return m_name; }
 
-    bool isNamedType() const override { return true; }
-    virtual bool isTypeDefinition() const { return false; }
-    virtual bool isStructureDefinition() const { return false; }
-    virtual bool isEnumerationDefinition() const { return false; }
-    virtual bool isNativeTypeDeclaration() const { return false; }
-
-    virtual const Type& unifyNode() const { return *this; }
-    virtual Type& unifyNode() { return *this; }
 
 private:
+    friend class Type;
+    Type& unifyNodeImpl() { return *this; }
     CodeLocation m_codeLocation;
     String m_name;
 };
@@ -77,6 +74,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(NamedType)
+
 #define SPECIALIZE_TYPE_TRAITS_WHLSL_NAMED_TYPE(ToValueTypeName, predicate) \
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WHLSL::AST::ToValueTypeName) \
     static bool isType(const WebCore::WHLSL::AST::NamedType& type) { return type.predicate; } \
index 170b64f..0190f83 100644 (file)
@@ -40,22 +40,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class NativeTypeDeclaration : public NamedType {
+class NativeTypeDeclaration final : public NamedType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     NativeTypeDeclaration(CodeLocation location, String&& name, TypeArguments&& typeArguments)
-        : NamedType(location, WTFMove(name))
+        : NamedType(Kind::NativeTypeDeclaration, location, WTFMove(name))
         , m_typeArguments(WTFMove(typeArguments))
     {
     }
 
-    virtual ~NativeTypeDeclaration() = default;
+    ~NativeTypeDeclaration() = default;
 
     NativeTypeDeclaration(const NativeTypeDeclaration&) = delete;
     NativeTypeDeclaration(NativeTypeDeclaration&&) = default;
 
-    bool isNativeTypeDeclaration() const override { return true; }
-
     TypeArguments& typeArguments() { return m_typeArguments; }
 
     bool isInt() const { return m_isInt; }
index 8e993fa..7db03ec 100644 (file)
@@ -37,15 +37,15 @@ namespace WHLSL {
 
 namespace AST {
 
-class NullLiteral : public Expression {
+class NullLiteral final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     NullLiteral(CodeLocation location)
-        : Expression(location)
+        : Expression(location, Kind::NullLiteral)
     {
     }
 
-    virtual ~NullLiteral() = default;
+    ~NullLiteral() = default;
 
     NullLiteral(const NullLiteral&) = delete;
     NullLiteral(NullLiteral&&) = default;
@@ -55,8 +55,6 @@ public:
 
     NullLiteralType& type() { return m_type; }
 
-    bool isNullLiteral() const override { return true; }
-
     NullLiteral clone() const
     {
         auto result = NullLiteral(codeLocation());
@@ -76,6 +74,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(NullLiteral)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(NullLiteral, isNullLiteral())
 
 #endif
index a80943a..be39fc1 100644 (file)
@@ -36,12 +36,14 @@ namespace WHLSL {
 
 namespace AST {
 
-class NullLiteralType : public ResolvableType {
+class NullLiteralType final : public ResolvableType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    NullLiteralType() = default;
+    NullLiteralType()
+        : ResolvableType(Kind::NullLiteral)
+    { }
 
-    virtual ~NullLiteralType() = default;
+    ~NullLiteralType() = default;
 
     NullLiteralType(const NullLiteralType&) = delete;
     NullLiteralType(NullLiteralType&&) = default;
@@ -49,10 +51,8 @@ public:
     NullLiteralType& operator=(const NullLiteralType&) = delete;
     NullLiteralType& operator=(NullLiteralType&&) = default;
 
-    bool isNullLiteralType() const override { return true; }
-
-    bool canResolve(const Type&) const override;
-    unsigned conversionCost(const UnnamedType&) const override;
+    bool canResolve(const Type&) const;
+    unsigned conversionCost(const UnnamedType&) const;
 
 private:
 };
@@ -63,6 +63,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(NullLiteralType)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_RESOLVABLE_TYPE(NullLiteralType, isNullLiteralType())
 
 #endif
index 613a69d..d86952e 100644 (file)
@@ -32,6 +32,7 @@
 #include <wtf/FastMalloc.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/UniqueRef.h>
+#include <wtf/text/StringConcatenate.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -46,17 +47,18 @@ class PointerType final : public ReferenceType {
     using Base = ReferenceType;
 
     PointerType(CodeLocation location, AddressSpace addressSpace, Ref<UnnamedType> elementType)
-        : Base(location, addressSpace, WTFMove(elementType), Kind::PointerType)
+        : Base(location, addressSpace, WTFMove(elementType), Kind::Pointer)
     {
     }
 
 public:
     static Ref<PointerType> create(CodeLocation location, AddressSpace addressSpace, Ref<UnnamedType> elementType)
     {
-        return adoptRef(*new PointerType(location, addressSpace, WTFMove(elementType)));
+        auto result = adoptRef(*new PointerType(location, addressSpace, WTFMove(elementType)));
+        return result;
     }
 
-    virtual ~PointerType() = default;
+    ~PointerType() = default;
 
     unsigned hash() const
     {
@@ -68,7 +70,7 @@ public:
         return addressSpace() == other.addressSpace() && elementType() == other.elementType();
     }
 
-    String toString() const override
+    String toString() const
     {
         return makeString(elementType().toString(), '*');
     }
@@ -80,6 +82,8 @@ public:
 
 }
 
+DEFINE_DEFAULT_DELETE(PointerType)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_UNNAMED_TYPE(PointerType, isPointerType())
 
 #endif
index 3f731c7..f7ff886 100644 (file)
@@ -40,23 +40,22 @@ namespace AST {
 
 class PropertyAccessExpression : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
+protected:
+    ~PropertyAccessExpression() = default;
+
 public:
-    PropertyAccessExpression(CodeLocation location, UniqueRef<Expression>&& base)
-        : Expression(location)
+    PropertyAccessExpression(CodeLocation location, Kind kind, UniqueRef<Expression>&& base)
+        : Expression(location, kind)
         , m_base(WTFMove(base))
     {
     }
 
-    virtual ~PropertyAccessExpression() = default;
-
     PropertyAccessExpression(const PropertyAccessExpression&) = delete;
     PropertyAccessExpression(PropertyAccessExpression&&) = default;
 
-    bool isPropertyAccessExpression() const override { return true; }
-
-    virtual String getterFunctionName() const = 0;
-    virtual String setterFunctionName() const = 0;
-    virtual String anderFunctionName() const = 0;
+    String getterFunctionName() const;
+    String setterFunctionName() const;
+    String anderFunctionName() const;
 
     FunctionDeclaration* getterFunction() { return m_getterFunction; }
     FunctionDeclaration* anderFunction() { return m_anderFunction; }
index 80190b3..8387eab 100644 (file)
@@ -49,15 +49,19 @@ namespace AST {
  *  6. Evaluate m_resultExpression
  *  7. Return the result
  */
-class ReadModifyWriteExpression : public Expression {
+class ReadModifyWriteExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static UniqueRef<ReadModifyWriteExpression> create(CodeLocation location, UniqueRef<Expression> lValue)
+    ReadModifyWriteExpression(CodeLocation location, UniqueRef<Expression> leftValue)
+        : Expression(location, Kind::ReadModifyWrite)
+        , m_leftValue(WTFMove(leftValue))
+        , m_oldValue(makeUniqueRef<VariableDeclaration>(location, Qualifiers(), nullptr, String(), nullptr, nullptr))
+        , m_newValue(makeUniqueRef<VariableDeclaration>(location, Qualifiers(), nullptr, String(), nullptr, nullptr))
     {
-        return makeUniqueRef<ReadModifyWriteExpression>(location, WTFMove(lValue));
     }
 
-    virtual ~ReadModifyWriteExpression() = default;
+
+    ~ReadModifyWriteExpression() = default;
 
     ReadModifyWriteExpression(const ReadModifyWriteExpression&) = delete;
     ReadModifyWriteExpression(ReadModifyWriteExpression&&) = default;
@@ -82,8 +86,6 @@ public:
         return makeUniqueRef<VariableReference>(VariableReference::wrap(m_newValue));
     }
 
-    bool isReadModifyWriteExpression() const override { return true; }
-
     Expression& leftValue() { return m_leftValue; }
     VariableDeclaration& oldValue() { return m_oldValue; }
     VariableDeclaration& newValue() { return m_newValue; }
@@ -114,16 +116,6 @@ public:
     }
 
 private:
-    template<class U, class... Args> friend UniqueRef<U> WTF::makeUniqueRef(Args&&...);
-
-    ReadModifyWriteExpression(CodeLocation location, UniqueRef<Expression> leftValue)
-        : Expression(location)
-        , m_leftValue(WTFMove(leftValue))
-        , m_oldValue(makeUniqueRef<VariableDeclaration>(location, Qualifiers(), nullptr, String(), nullptr, nullptr))
-        , m_newValue(makeUniqueRef<VariableDeclaration>(location, Qualifiers(), nullptr, String(), nullptr, nullptr))
-    {
-    }
-
     UniqueRef<Expression> m_leftValue;
     UniqueRef<VariableDeclaration> m_oldValue;
     UniqueRef<VariableDeclaration> m_newValue;
@@ -137,6 +129,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(ReadModifyWriteExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(ReadModifyWriteExpression, isReadModifyWriteExpression())
 
 #endif
index 16a6db3..aed82e7 100644 (file)
@@ -43,6 +43,10 @@ namespace AST {
 class ReferenceType : public UnnamedType {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(ReferenceType);
+
+protected:
+    ~ReferenceType() = default;
+
 protected:
     ReferenceType(CodeLocation location, AddressSpace addressSpace, Ref<UnnamedType> elementType, Kind kind)
         : UnnamedType(location, kind)
@@ -50,9 +54,9 @@ protected:
         , m_elementType(WTFMove(elementType))
     {
     }
-public:
-    virtual ~ReferenceType() = default;
 
+
+public:
     AddressSpace addressSpace() const { return m_addressSpace; }
     const UnnamedType& elementType() const { return m_elementType; }
     UnnamedType& elementType() { return m_elementType; }
@@ -73,6 +77,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(ReferenceType)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_UNNAMED_TYPE(ReferenceType, isReferenceType())
 
 #endif
index ab6eefe..ab5ae30 100644 (file)
@@ -38,7 +38,7 @@ ALWAYS_INLINE New* replaceWith(Old& old, Args&&... args)
 {
     static_assert(sizeof(New) <= sizeof(Old), "This is needed for the placement new below to not overwrite unowned memory.");
     void* location = &old;
-    old.~Old();
+    Old::destruct(old);
     return new (location) New(std::forward<Args>(args)...);
 }
 
index 46ce1ed..36d9dfc 100644 (file)
@@ -40,10 +40,15 @@ namespace AST {
 
 class ResolvableType : public Type {
     WTF_MAKE_FAST_ALLOCATED;
+
+protected:
+    ~ResolvableType() = default;
+
 public:
-    ResolvableType() = default;
+    ResolvableType(Kind kind)
+        : Type(kind)
+    { }
 
-    virtual ~ResolvableType() = default;
 
     ResolvableType(const ResolvableType&) = delete;
     ResolvableType(ResolvableType&&) = default;
@@ -51,14 +56,8 @@ public:
     ResolvableType& operator=(const ResolvableType&) = delete;
     ResolvableType& operator=(ResolvableType&&) = default;
 
-    bool isResolvableType() const override { return true; }
-    virtual bool isFloatLiteralType() const { return false; }
-    virtual bool isIntegerLiteralType() const { return false; }
-    virtual bool isNullLiteralType() const { return false; }
-    virtual bool isUnsignedIntegerLiteralType() const { return false; }
-
-    virtual bool canResolve(const Type&) const = 0;
-    virtual unsigned conversionCost(const UnnamedType&) const = 0;
+    bool canResolve(const Type&) const;
+    unsigned conversionCost(const UnnamedType&) const;
 
     const UnnamedType* maybeResolvedType() const { return m_resolvedType ? &*m_resolvedType : nullptr; }
     const UnnamedType& resolvedType() const
@@ -89,6 +88,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(ResolvableType)
+
 #define SPECIALIZE_TYPE_TRAITS_WHLSL_RESOLVABLE_TYPE(ToValueTypeName, predicate) \
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WHLSL::AST::ToValueTypeName) \
     static bool isType(const WebCore::WHLSL::AST::ResolvableType& type) { return type.predicate; } \
index e5742dc..94c4042 100644 (file)
@@ -39,22 +39,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class Return : public Statement {
+class Return final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     Return(CodeLocation location, std::unique_ptr<Expression>&& value)
-        : Statement(location)
+        : Statement(location, Kind::Return)
         , m_value(WTFMove(value))
     {
     }
 
-    virtual ~Return() = default;
+    ~Return() = default;
 
     Return(const Return&) = delete;
     Return(Return&&) = default;
 
-    bool isReturn() const override { return true; }
-
     Expression* value() { return m_value.get(); }
 
 private:
@@ -67,6 +65,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(Return)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(Return, isReturn())
 
 #endif
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.cpp
new file mode 100644 (file)
index 0000000..92779bd
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WHLSLStatement.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WHLSLAST.h"
+
+namespace WebCore {
+
+namespace WHLSL {
+
+namespace AST {
+
+void Statement::destroy(Statement& statement)
+{
+    switch (statement.kind()) {
+    case Kind::Block:
+        delete &downcast<Block>(statement);
+        break;
+    case Kind::Break:
+        delete &downcast<Break>(statement);
+        break;
+    case Kind::Continue:
+        delete &downcast<Continue>(statement);
+        break;
+    case Kind::DoWhileLoop:
+        delete &downcast<DoWhileLoop>(statement);
+        break;
+    case Kind::EffectfulExpression:
+        delete &downcast<EffectfulExpressionStatement>(statement);
+        break;
+    case Kind::Fallthrough:
+        delete &downcast<Fallthrough>(statement);
+        break;
+    case Kind::ForLoop:
+        delete &downcast<ForLoop>(statement);
+        break;
+    case Kind::If:
+        delete &downcast<IfStatement>(statement);
+        break;
+    case Kind::Return:
+        delete &downcast<Return>(statement);
+        break;
+    case Kind::StatementList:
+        delete &downcast<StatementList>(statement);
+        break;
+    case Kind::SwitchCase:
+        delete &downcast<SwitchCase>(statement);
+        break;
+    case Kind::Switch:
+        delete &downcast<SwitchStatement>(statement);
+        break;
+    case Kind::VariableDeclarations:
+        delete &downcast<VariableDeclarationsStatement>(statement);
+        break;
+    case Kind::WhileLoop:
+        delete &downcast<WhileLoop>(statement);
+        break;
+    }
+}
+
+void Statement::destruct(Statement& statement)
+{
+    switch (statement.kind()) {
+    case Kind::Block:
+        downcast<Block>(statement).~Block();
+        break;
+    case Kind::Break:
+        downcast<Break>(statement).~Break();
+        break;
+    case Kind::Continue:
+        downcast<Continue>(statement).~Continue();
+        break;
+    case Kind::DoWhileLoop:
+        downcast<DoWhileLoop>(statement).~DoWhileLoop();
+        break;
+    case Kind::EffectfulExpression:
+        downcast<EffectfulExpressionStatement>(statement).~EffectfulExpressionStatement();
+        break;
+    case Kind::Fallthrough:
+        downcast<Fallthrough>(statement).~Fallthrough();
+        break;
+    case Kind::ForLoop:
+        downcast<ForLoop>(statement).~ForLoop();
+        break;
+    case Kind::If:
+        downcast<IfStatement>(statement).~IfStatement();
+        break;
+    case Kind::Return:
+        downcast<Return>(statement).~Return();
+        break;
+    case Kind::StatementList:
+        downcast<StatementList>(statement).~StatementList();
+        break;
+    case Kind::SwitchCase:
+        downcast<SwitchCase>(statement).~SwitchCase();
+        break;
+    case Kind::Switch:
+        downcast<SwitchStatement>(statement).~SwitchStatement();
+        break;
+    case Kind::VariableDeclarations:
+        downcast<VariableDeclarationsStatement>(statement).~VariableDeclarationsStatement();
+        break;
+    case Kind::WhileLoop:
+        downcast<WhileLoop>(statement).~WhileLoop();
+        break;
+    }
+}
+
+} // namespace AST
+
+} // namespace WHLSL
+
+} // namespace WebCore
+
+#endif
index 06c3ed7..7adea47 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(WEBGPU)
 
 #include "WHLSLCodeLocation.h"
+#include "WHLSLDefaultDelete.h"
 #include <wtf/FastMalloc.h>
 #include <wtf/UniqueRef.h>
 
@@ -39,47 +40,74 @@ namespace AST {
 
 class Statement {
     WTF_MAKE_FAST_ALLOCATED;
+
+protected:
+    ~Statement() = default;
+
 public:
-    Statement(CodeLocation codeLocation)
+    enum class Kind : uint8_t {
+        Block,
+        Break,
+        Continue,
+        DoWhileLoop,
+        EffectfulExpression,
+        Fallthrough,
+        ForLoop,
+        If,
+        Return,
+        StatementList,
+        SwitchCase,
+        Switch,
+        VariableDeclarations,
+        WhileLoop,
+    };
+    Statement(CodeLocation codeLocation, Kind kind)
         : m_codeLocation(codeLocation)
+        , m_kind(kind)
     {
     }
 
-    virtual ~Statement() = default;
+    static void destroy(Statement&);
+    static void destruct(Statement&);
 
     Statement(const Statement&) = delete;
     Statement(Statement&&) = default;
 
-    virtual bool isBlock() const { return false; }
-    virtual bool isBreak() const { return false; }
-    virtual bool isContinue() const { return false; }
-    virtual bool isDoWhileLoop() const { return false; }
-    virtual bool isEffectfulExpressionStatement() const { return false; }
-    virtual bool isFallthrough() const { return false; }
-    virtual bool isForLoop() const { return false; }
-    virtual bool isIfStatement() const { return false; }
-    virtual bool isReturn() const { return false; }
-    virtual bool isStatementList() const { return false; }
-    virtual bool isSwitchCase() const { return false; }
-    virtual bool isSwitchStatement() const { return false; }
-    virtual bool isVariableDeclarationsStatement() const { return false; }
-    virtual bool isWhileLoop() const { return false; }
+    Kind kind() const { return m_kind; }
+
+    bool isBlock() const { return kind() == Kind::Block; }
+    bool isBreak() const { return kind() == Kind::Break; }
+    bool isContinue() const { return kind() == Kind::Continue; }
+    bool isDoWhileLoop() const { return kind() == Kind::DoWhileLoop; }
+    bool isEffectfulExpressionStatement() const { return kind() == Kind::EffectfulExpression; }
+    bool isFallthrough() const { return kind() == Kind::Fallthrough; }
+    bool isForLoop() const { return kind() == Kind::ForLoop; }
+    bool isIfStatement() const { return kind() == Kind::If; }
+    bool isReturn() const { return kind() == Kind::Return; }
+    bool isStatementList() const { return kind() == Kind::StatementList; }
+    bool isSwitchCase() const { return kind() == Kind::SwitchCase; }
+    bool isSwitchStatement() const { return kind() == Kind::Switch; }
+    bool isVariableDeclarationsStatement() const { return kind() == Kind::VariableDeclarations; }
+    bool isWhileLoop() const { return kind() == Kind::WhileLoop; }
 
     CodeLocation codeLocation() const { return m_codeLocation; }
     void updateCodeLocation(CodeLocation location) { m_codeLocation = location; }
 
 private:
     CodeLocation m_codeLocation;
+    Kind m_kind;
 };
 
 using Statements = Vector<UniqueRef<Statement>>;
 
-} // namespace AST
+}
 
 }
 
 }
 
+DEFINE_DEFAULT_DELETE(Statement)
+
 #define SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(ToValueTypeName, predicate) \
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WHLSL::AST::ToValueTypeName) \
     static bool isType(const WebCore::WHLSL::AST::Statement& statement) { return statement.predicate; } \
index adf8087..968d369 100644 (file)
@@ -38,21 +38,19 @@ namespace WHLSL {
 
 namespace AST {
 
-class StatementList : public Statement {
+class StatementList final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
     using Base = Statement;
 public:
     StatementList(CodeLocation location, Statements&& statements)
-        : Base(location)
+        : Base(location, Kind::StatementList)
         , m_statements(WTFMove(statements))
     { }
 
-    virtual ~StatementList() = default;
+    ~StatementList() = default;
 
     Statements& statements() { return m_statements; }
 
-    bool isStatementList() const override { return true; }
-
 private:
     Statements m_statements;
 };
@@ -63,6 +61,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(StatementList)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(StatementList, isStatementList())
 
 #endif
index d3b63f7..62a9526 100644 (file)
@@ -40,22 +40,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class StructureDefinition : public NamedType {
+class StructureDefinition final : public NamedType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     StructureDefinition(CodeLocation location, String&& name, StructureElements&& structureElements)
-        : NamedType(location, WTFMove(name))
+        : NamedType(Kind::StructureDefinition, location, WTFMove(name))
         , m_structureElements(WTFMove(structureElements))
     {
     }
 
-    virtual ~StructureDefinition() = default;
+    ~StructureDefinition() = default;
 
     StructureDefinition(const StructureDefinition&) = delete;
     StructureDefinition(StructureDefinition&&) = default;
 
-    bool isStructureDefinition() const override { return true; }
-
     StructureElements& structureElements() { return m_structureElements; }
     StructureElement* find(const String& name)
     {
@@ -77,6 +75,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(StructureDefinition)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_NAMED_TYPE(StructureDefinition, isStructureDefinition())
 
 #endif
index 27e4127..1cfe1ba 100644 (file)
@@ -40,7 +40,7 @@ namespace WHLSL {
 
 namespace AST {
 
-class StructureElement {
+class StructureElement final {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     StructureElement(CodeLocation location, Qualifiers&& qualifiers, Ref<UnnamedType> type, String&& name, std::unique_ptr<Semantic>&& semantic)
@@ -52,7 +52,7 @@ public:
     {
     }
 
-    virtual ~StructureElement() = default;
+    ~StructureElement() = default;
 
     StructureElement(const StructureElement&) = delete;
     StructureElement(StructureElement&&) = default;
index 0d95021..715eecb 100644 (file)
@@ -40,23 +40,21 @@ namespace WHLSL {
 
 namespace AST {
 
-class SwitchCase : public Statement {
+class SwitchCase final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     SwitchCase(CodeLocation location, Optional<ConstantExpression>&& value, Block&& block)
-        : Statement(location)
+        : Statement(location, Kind::SwitchCase)
         , m_value(WTFMove(value))
         , m_block(WTFMove(block))
     {
     }
 
-    virtual ~SwitchCase() = default;
+    ~SwitchCase() = default;
 
     SwitchCase(const SwitchCase&) = delete;
     SwitchCase(SwitchCase&&) = default;
 
-    bool isSwitchCase() const override { return true; }
-
     Optional<ConstantExpression>& value() { return m_value; }
     Block& block() { return m_block; }
 
@@ -71,6 +69,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(SwitchCase)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(SwitchCase, isSwitchCase())
 
 #endif
index 1fd1a92..1c7328d 100644 (file)
@@ -39,23 +39,21 @@ namespace WHLSL {
 
 namespace AST {
 
-class SwitchStatement : public Statement {
+class SwitchStatement final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     SwitchStatement(CodeLocation location, UniqueRef<Expression>&& value, Vector<SwitchCase>&& switchCases)
-        : Statement(location)
+        : Statement(location, Kind::Switch)
         , m_value(WTFMove(value))
         , m_switchCases(WTFMove(switchCases))
     {
     }
 
-    virtual ~SwitchStatement() = default;
+    ~SwitchStatement() = default;
 
     SwitchStatement(const SwitchStatement&) = delete;
     SwitchStatement(SwitchStatement&&) = default;
 
-    bool isSwitchStatement() const override { return true; }
-
     Expression& value() { return m_value; }
     Vector<SwitchCase>& switchCases() { return m_switchCases; }
 
@@ -70,6 +68,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(SwitchStatement)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(SwitchStatement, isSwitchStatement())
 
 #endif
index ef79fd3..68b10a5 100644 (file)
@@ -37,24 +37,22 @@ namespace WHLSL {
 
 namespace AST {
 
-class TernaryExpression : public Expression {
+class TernaryExpression final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     TernaryExpression(CodeLocation location, UniqueRef<Expression>&& predicate, UniqueRef<Expression>&& bodyExpression, UniqueRef<Expression>&& elseExpression)
-        : Expression(location)
+        : Expression(location, Kind::Ternary)
         , m_predicate(WTFMove(predicate))
         , m_bodyExpression(WTFMove(bodyExpression))
         , m_elseExpression(WTFMove(elseExpression))
     {
     }
 
-    virtual ~TernaryExpression() = default;
+    ~TernaryExpression() = default;
 
     TernaryExpression(const TernaryExpression&) = delete;
     TernaryExpression(TernaryExpression&&) = default;
 
-    bool isTernaryExpression() const override { return true; }
-
     Expression& predicate() { return m_predicate; }
     Expression& bodyExpression() { return m_bodyExpression; }
     Expression& elseExpression() { return m_elseExpression; }
@@ -71,6 +69,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(TernaryExpression)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(TernaryExpression, isTernaryExpression())
 
 #endif
diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLType.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLType.cpp
new file mode 100644 (file)
index 0000000..efd1280
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WHLSLType.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WHLSLAST.h"
+
+namespace WebCore {
+
+namespace WHLSL {
+
+namespace AST {
+
+void Type::destroy(Type& type)
+{
+    switch (type.kind()) {
+    case Kind::TypeReference:
+        delete &downcast<TypeReference>(type);
+        break;
+    case Kind::Pointer:
+        delete &downcast<PointerType>(type);
+        break;
+    case Kind::ArrayReference:
+        delete &downcast<ArrayReferenceType>(type);
+        break;
+    case Kind::Array:
+        delete &downcast<ArrayType>(type);
+        break;
+
+    case Kind::TypeDefinition:
+        delete &downcast<TypeDefinition>(type);
+        break;
+    case Kind::StructureDefinition:
+        delete &downcast<StructureDefinition>(type);
+        break;
+    case Kind::EnumerationDefinition:
+        delete &downcast<EnumerationDefinition>(type);
+        break;
+    case Kind::NativeTypeDeclaration:
+        delete &downcast<NativeTypeDeclaration>(type);
+        break;
+
+    case Kind::FloatLiteral:
+        delete &downcast<FloatLiteralType>(type);
+        break;
+    case Kind::IntegerLiteral:
+        delete &downcast<IntegerLiteralType>(type);
+        break;
+    case Kind::NullLiteral:
+        delete &downcast<NullLiteralType>(type);
+        break;
+    case Kind::UnsignedIntegerLiteral:
+        delete &downcast<UnsignedIntegerLiteralType>(type);
+        break;
+    }
+}
+
+void Type::destruct(Type& type)
+{
+    switch (type.kind()) {
+    case Kind::TypeReference:
+        downcast<TypeReference>(type).~TypeReference();
+        break;
+    case Kind::Pointer:
+        downcast<PointerType>(type).~PointerType();
+        break;
+    case Kind::ArrayReference:
+        downcast<ArrayReferenceType>(type).~ArrayReferenceType();
+        break;
+    case Kind::Array:
+        downcast<ArrayType>(type).~ArrayType();
+        break;
+
+    case Kind::TypeDefinition:
+        downcast<TypeDefinition>(type).~TypeDefinition();
+        break;
+    case Kind::StructureDefinition:
+        downcast<StructureDefinition>(type).~StructureDefinition();
+        break;
+    case Kind::EnumerationDefinition:
+        downcast<EnumerationDefinition>(type).~EnumerationDefinition();
+        break;
+    case Kind::NativeTypeDeclaration:
+        downcast<NativeTypeDeclaration>(type).~NativeTypeDeclaration();
+        break;
+
+    case Kind::FloatLiteral:
+        downcast<FloatLiteralType>(type).~FloatLiteralType();
+        break;
+    case Kind::IntegerLiteral:
+        downcast<IntegerLiteralType>(type).~IntegerLiteralType();
+        break;
+    case Kind::NullLiteral:
+        downcast<NullLiteralType>(type).~NullLiteralType();
+        break;
+    case Kind::UnsignedIntegerLiteral:
+        downcast<UnsignedIntegerLiteralType>(type).~UnsignedIntegerLiteralType();
+        break;
+    }
+}
+
+Type& Type::unifyNode()
+{
+    switch (kind()) {
+    case Kind::TypeReference:
+        return downcast<TypeReference>(*this).unifyNodeImpl();
+    case Kind::Pointer:
+        return downcast<PointerType>(*this).unifyNodeImpl();
+    case Kind::ArrayReference:
+        return downcast<ArrayReferenceType>(*this).unifyNodeImpl();
+    case Kind::Array:
+        return downcast<ArrayType>(*this).unifyNodeImpl();
+
+    case Kind::TypeDefinition:
+        return downcast<TypeDefinition>(*this).unifyNodeImpl();
+    case Kind::StructureDefinition:
+        return downcast<StructureDefinition>(*this).unifyNodeImpl();
+    case Kind::EnumerationDefinition:
+        return downcast<EnumerationDefinition>(*this).unifyNodeImpl();
+    case Kind::NativeTypeDeclaration:
+        return downcast<NativeTypeDeclaration>(*this).unifyNodeImpl();
+
+    default: 
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+}
+
+bool ResolvableType::canResolve(const Type& type) const
+{
+    switch (kind()) {
+    case Kind::FloatLiteral:
+        return downcast<FloatLiteralType>(*this).canResolve(type);
+    case Kind::IntegerLiteral:
+        return downcast<IntegerLiteralType>(*this).canResolve(type);
+    case Kind::NullLiteral:
+        return downcast<NullLiteralType>(*this).canResolve(type);
+    case Kind::UnsignedIntegerLiteral:
+        return downcast<UnsignedIntegerLiteralType>(*this).canResolve(type);
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+}
+
+unsigned ResolvableType::conversionCost(const UnnamedType& type) const
+{
+    switch (kind()) {
+    case Kind::FloatLiteral:
+        return downcast<FloatLiteralType>(*this).conversionCost(type);
+    case Kind::IntegerLiteral:
+        return downcast<IntegerLiteralType>(*this).conversionCost(type);
+    case Kind::NullLiteral:
+        return downcast<NullLiteralType>(*this).conversionCost(type);
+    case Kind::UnsignedIntegerLiteral:
+        return downcast<UnsignedIntegerLiteralType>(*this).conversionCost(type);
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+}
+
+String UnnamedType::toString() const
+{
+    switch (kind()) {
+    case Kind::TypeReference:
+        return downcast<TypeReference>(*this).toString();
+    case Kind::Pointer:
+        return downcast<PointerType>(*this).toString();
+    case Kind::ArrayReference:
+        return downcast<ArrayReferenceType>(*this).toString();
+    case Kind::Array:
+        return downcast<ArrayType>(*this).toString();
+    default: 
+        RELEASE_ASSERT_NOT_REACHED();
+    }
+
+}
+
+} // namespace AST
+
+} // namespace WHLSL
+
+} // namespace WebCore
+
+#endif
index a3307c7..1066f16 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(WEBGPU)
 
+#include "WHLSLDefaultDelete.h"
 #include <wtf/FastMalloc.h>
 #include <wtf/TypeCasts.h>
 
@@ -38,10 +39,34 @@ namespace AST {
 
 class Type {
     WTF_MAKE_FAST_ALLOCATED;
-public:
-    Type() = default;
 
-    virtual ~Type() = default;
+protected:
+    ~Type() = default;
+
+public:
+    enum class Kind : uint8_t {
+        // UnnamedTypes
+        TypeReference,
+        Pointer,
+        ArrayReference,
+        Array,
+        // NamedTypes
+        TypeDefinition,
+        StructureDefinition,
+        EnumerationDefinition,
+        NativeTypeDeclaration,
+        // ResolvableTypes
+        FloatLiteral,
+        IntegerLiteral,
+        NullLiteral,
+        UnsignedIntegerLiteral,
+    };
+
+    Type(Kind kind)
+        : m_kind(kind)
+    { }
+    static void destroy(Type&);
+    static void destruct(Type&);
 
     explicit Type(const Type&) = delete;
     Type(Type&&) = default;
@@ -49,11 +74,36 @@ public:
     Type& operator=(const Type&) = delete;
     Type& operator=(Type&&) = default;
 
-    virtual bool isNamedType() const { return false; }
-    virtual bool isUnnamedType() const { return false; }
-    virtual bool isResolvableType() const { return false; }
+    Kind kind() const { return m_kind; }
+
+    bool isUnnamedType() const { return kind() >= Kind::TypeReference && kind() <= Kind::Array; }
+    bool isNamedType() const { return kind() >= Kind::TypeDefinition && kind() <= Kind::NativeTypeDeclaration; }
+    bool isResolvableType() const { return kind() >= Kind::FloatLiteral && kind() <= Kind::UnsignedIntegerLiteral; }
+
+    bool isTypeReference() const { return kind() == Kind::TypeReference; }
+    bool isPointerType() const { return kind() == Kind::Pointer; }
+    bool isArrayReferenceType() const { return kind() == Kind::ArrayReference; }
+    bool isArrayType() const { return kind() == Kind::Array; }
+    bool isReferenceType() const { return isPointerType() || isArrayReferenceType(); }
+
+    bool isTypeDefinition() const { return kind() == Kind::TypeDefinition; }
+    bool isStructureDefinition() const { return kind() == Kind::StructureDefinition; }
+    bool isEnumerationDefinition() const { return kind() == Kind::EnumerationDefinition; }
+    bool isNativeTypeDeclaration() const { return kind() == Kind::NativeTypeDeclaration; }
+
+    bool isFloatLiteralType() const { return kind() == Kind::FloatLiteral; }
+    bool isIntegerLiteralType() const { return kind() == Kind::IntegerLiteral; }
+    bool isNullLiteralType() const { return kind() == Kind::NullLiteral; }
+    bool isUnsignedIntegerLiteralType() const { return kind() == Kind::UnsignedIntegerLiteral; }
+
+    Type& unifyNode();
+    const Type& unifyNode() const
+    {
+        return const_cast<Type*>(this)->unifyNode();
+    }
 
 private:
+    Kind m_kind;
 };
 
 } // namespace AST
@@ -62,6 +112,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(Type)
+
 #define SPECIALIZE_TYPE_TRAITS_WHLSL_TYPE(ToValueTypeName, predicate) \
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WHLSL::AST::ToValueTypeName) \
     static bool isType(const WebCore::WHLSL::AST::Type& type) { return type.predicate; } \
index f2280c0..ae05312 100644 (file)
@@ -40,35 +40,29 @@ namespace WHLSL {
 
 namespace AST {
 
-class TypeDefinition : public NamedType {
+class TypeDefinition final : public NamedType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     TypeDefinition(CodeLocation location, String&& name, Ref<UnnamedType> type)
-        : NamedType(location, WTFMove(name))
+        : NamedType(Kind::TypeDefinition, location, WTFMove(name))
         , m_type(WTFMove(type))
     {
     }
 
-    virtual ~TypeDefinition() = default;
+    ~TypeDefinition() = default;
 
     TypeDefinition(const TypeDefinition&) = delete;
     TypeDefinition(TypeDefinition&&) = default;
 
-    bool isTypeDefinition() const override { return true; }
-
     UnnamedType& type() { return m_type; }
 
-    const Type& unifyNode() const override
-    {
-        return m_type->unifyNode();
-    }
-
-    Type& unifyNode() override
+private:
+    friend class Type;
+    Type& unifyNodeImpl()
     {
         return m_type->unifyNode();
     }
 
-private:
     Ref<UnnamedType> m_type;
 };
 
@@ -78,6 +72,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(TypeDefinition)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_NAMED_TYPE(TypeDefinition, isTypeDefinition())
 
 #endif
index edaff9e..30c9956 100644 (file)
@@ -59,7 +59,7 @@ public:
         return adoptRef(* new TypeReference(location, WTFMove(name), WTFMove(typeArguments)));
     }
 
-    virtual ~TypeReference() = default;
+    ~TypeReference() = default;
 
     static Ref<TypeReference> wrap(CodeLocation, NamedType& resolvedType);
 
@@ -72,18 +72,6 @@ public:
         return *m_resolvedType;
     }
 
-    const Type& unifyNode() const override
-    {
-        ASSERT(m_resolvedType);
-        return m_resolvedType->unifyNode();
-    }
-
-    Type& unifyNode() override
-    {
-        ASSERT(m_resolvedType);
-        return m_resolvedType->unifyNode();
-    }
-
     void setResolvedType(NamedType& resolvedType)
     {
         m_resolvedType = &resolvedType;
@@ -103,13 +91,20 @@ public:
         return &unifyNode() == &other.unifyNode();
     }
 
-    String toString() const override
+    String toString() const
     {
         ASSERT(m_resolvedType);
         return m_resolvedType->name();
     }
 
 private:
+    friend class Type;
+    Type& unifyNodeImpl()
+    {
+        ASSERT(m_resolvedType);
+        return m_resolvedType->unifyNode();
+    }
+
     String m_name;
     TypeArguments m_typeArguments;
     NamedType* m_resolvedType { nullptr };
@@ -121,6 +116,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(TypeReference)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_UNNAMED_TYPE(TypeReference, isTypeReference())
 
 #endif
index 03a127a..d704d24 100644 (file)
@@ -41,32 +41,36 @@ namespace AST {
 
 unsigned UnnamedType::hash() const
 {
-    switch (m_kind) {
+    switch (kind()) {
     case Kind::TypeReference:
         return downcast<TypeReference>(*this).hash();
-    case Kind::PointerType:
+    case Kind::Pointer:
         return downcast<PointerType>(*this).hash();
-    case Kind::ArrayReferenceType:
+    case Kind::ArrayReference:
         return downcast<ArrayReferenceType>(*this).hash();
-    case Kind::ArrayType:
+    case Kind::Array:
         return downcast<ArrayType>(*this).hash();
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
     }
 }
 
 bool UnnamedType::operator==(const UnnamedType& other) const
 {
-    if (other.m_kind != m_kind)
+    if (other.kind() != kind())
         return false;
 
-    switch (m_kind) {
+    switch (kind()) {
     case Kind::TypeReference:
         return downcast<TypeReference>(*this) == downcast<TypeReference>(other);
-    case Kind::PointerType:
+    case Kind::Pointer:
         return downcast<PointerType>(*this) == downcast<PointerType>(other);
-    case Kind::ArrayReferenceType:
+    case Kind::ArrayReference:
         return downcast<ArrayReferenceType>(*this) == downcast<ArrayReferenceType>(other);
-    case Kind::ArrayType:
+    case Kind::Array:
         return downcast<ArrayType>(*this) == downcast<ArrayType>(other);
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
     }
 }
 
index d472c1e..732426b 100644 (file)
@@ -45,43 +45,23 @@ class UnnamedType : public Type, public RefCounted<UnnamedType> {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(UnnamedType);
 public:
-    enum class Kind {
-        TypeReference,
-        PointerType,
-        ArrayReferenceType,
-        ArrayType
-    };
-
     UnnamedType(CodeLocation location, Kind kind)
-        : m_codeLocation(location)
-        , m_kind(kind)
+        : Type(kind)
+        , m_codeLocation(location)
     {
     }
 
-    virtual ~UnnamedType() = default;
-
-    bool isUnnamedType() const override { return true; }
-
-    Kind kind() const { return m_kind; }
-    bool isTypeReference() const { return m_kind == Kind::TypeReference; }
-    bool isPointerType() const { return m_kind == Kind::PointerType; }
-    bool isArrayReferenceType() const { return m_kind == Kind::ArrayReferenceType; }
-    bool isArrayType() const { return m_kind == Kind::ArrayType; }
-    bool isReferenceType() const { return isPointerType() || isArrayReferenceType(); }
-
-    virtual const Type& unifyNode() const { return *this; }
-    virtual Type& unifyNode() { return *this; }
-
     unsigned hash() const;
     bool operator==(const UnnamedType&) const;
 
-    virtual String toString() const = 0;
+    String toString() const;
 
-    const CodeLocation& codeLocation() const { return m_codeLocation; }
+    CodeLocation codeLocation() const { return m_codeLocation; }
 
 private:
+    friend class Type;
+    Type& unifyNodeImpl() { return *this; }
     CodeLocation m_codeLocation;
-    Kind m_kind;
 };
 
 } // namespace AST
@@ -90,6 +70,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(UnnamedType)
+
 #define SPECIALIZE_TYPE_TRAITS_WHLSL_UNNAMED_TYPE(ToValueTypeName, predicate) \
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WHLSL::AST::ToValueTypeName) \
     static bool isType(const WebCore::WHLSL::AST::UnnamedType& type) { return type.predicate; } \
index 9222fb6..71af821 100644 (file)
@@ -37,17 +37,17 @@ namespace WHLSL {
 
 namespace AST {
 
-class UnsignedIntegerLiteral : public Expression {
+class UnsignedIntegerLiteral final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     UnsignedIntegerLiteral(CodeLocation location, unsigned value)
-        : Expression(location)
+        : Expression(location, Kind::UnsignedIntegerLiteral)
         , m_type(location, value)
         , m_value(value)
     {
     }
 
-    virtual ~UnsignedIntegerLiteral() = default;
+    ~UnsignedIntegerLiteral() = default;
 
     UnsignedIntegerLiteral(const UnsignedIntegerLiteral&) = delete;
     UnsignedIntegerLiteral(UnsignedIntegerLiteral&&) = default;
@@ -58,8 +58,6 @@ public:
     UnsignedIntegerLiteralType& type() { return m_type; }
     unsigned value() const { return m_value; }
 
-    bool isUnsignedIntegerLiteral() const override { return true; }
-
     UnsignedIntegerLiteral clone() const
     {
         UnsignedIntegerLiteral result(codeLocation(), m_value);
@@ -83,6 +81,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(UnsignedIntegerLiteral)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(UnsignedIntegerLiteral, isUnsignedIntegerLiteral())
 
 #endif
index 1886c2d..187a1c4 100644 (file)
@@ -41,17 +41,12 @@ namespace WHLSL {
 namespace AST {
 
 UnsignedIntegerLiteralType::UnsignedIntegerLiteralType(CodeLocation location, unsigned value)
-    : m_value(value)
+    : ResolvableType(Kind::UnsignedIntegerLiteral)
+    , m_value(value)
     , m_preferredType(TypeReference::create(location, "uint"_str, TypeArguments()))
 {
 }
 
-UnsignedIntegerLiteralType::~UnsignedIntegerLiteralType() = default;
-
-UnsignedIntegerLiteralType::UnsignedIntegerLiteralType(UnsignedIntegerLiteralType&&) = default;
-
-UnsignedIntegerLiteralType& UnsignedIntegerLiteralType::operator=(UnsignedIntegerLiteralType&&) = default;
-
 bool UnsignedIntegerLiteralType::canResolve(const Type& type) const
 {
     if (!is<NamedType>(type))
index dea4393..cd9e8aa 100644 (file)
@@ -40,27 +40,25 @@ namespace AST {
 
 class TypeReference;
 
-class UnsignedIntegerLiteralType : public ResolvableType {
+class UnsignedIntegerLiteralType final : public ResolvableType {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     UnsignedIntegerLiteralType(CodeLocation, unsigned value);
 
-    virtual ~UnsignedIntegerLiteralType();
+    ~UnsignedIntegerLiteralType() = default;
 
     UnsignedIntegerLiteralType(const UnsignedIntegerLiteralType&) = delete;
-    UnsignedIntegerLiteralType(UnsignedIntegerLiteralType&&);
+    UnsignedIntegerLiteralType(UnsignedIntegerLiteralType&&) = default;
 
     UnsignedIntegerLiteralType& operator=(const UnsignedIntegerLiteralType&) = delete;
-    UnsignedIntegerLiteralType& operator=(UnsignedIntegerLiteralType&&);
-
-    bool isUnsignedIntegerLiteralType() const override { return true; }
+    UnsignedIntegerLiteralType& operator=(UnsignedIntegerLiteralType&&) = default;
 
     unsigned value() const { return m_value; }
 
     TypeReference& preferredType() { return m_preferredType; }
 
-    bool canResolve(const Type&) const override;
-    unsigned conversionCost(const UnnamedType&) const override;
+    bool canResolve(const Type&) const;
+    unsigned conversionCost(const UnnamedType&) const;
 
     UnsignedIntegerLiteralType clone() const;
 
@@ -77,6 +75,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(UnsignedIntegerLiteralType)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_RESOLVABLE_TYPE(UnsignedIntegerLiteralType, isUnsignedIntegerLiteralType())
 
 #endif
index e1b8ca5..9f6a154 100644 (file)
@@ -39,22 +39,20 @@ namespace WHLSL {
 
 namespace AST {
 
-class VariableDeclarationsStatement : public Statement {
+class VariableDeclarationsStatement final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     VariableDeclarationsStatement(CodeLocation location, VariableDeclarations&& variableDeclarations)
-        : Statement(location)
+        : Statement(location, Kind::VariableDeclarations)
         , m_variableDeclarations(WTFMove(variableDeclarations))
     {
     }
 
-    virtual ~VariableDeclarationsStatement() = default;
+    ~VariableDeclarationsStatement() = default;
 
     VariableDeclarationsStatement(const VariableDeclarationsStatement&) = delete;
     VariableDeclarationsStatement(VariableDeclarationsStatement&&) = default;
 
-    bool isVariableDeclarationsStatement() const override { return true; }
-
     Vector<UniqueRef<VariableDeclaration>>& variableDeclarations() { return m_variableDeclarations; }
 
 private:
@@ -67,6 +65,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(VariableDeclarationsStatement)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(VariableDeclarationsStatement, isVariableDeclarationsStatement())
 
 #endif
index cb2e984..8f9b18f 100644 (file)
@@ -38,16 +38,16 @@ namespace WHLSL {
 
 namespace AST {
 
-class VariableReference : public Expression {
+class VariableReference final : public Expression {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     VariableReference(CodeLocation location, String&& name)
-        : Expression(location)
+        : Expression(location, Kind::VariableReference)
         , m_name(WTFMove(name))
     {
     }
 
-    virtual ~VariableReference() = default;
+    ~VariableReference() = default;
 
     VariableReference(const VariableReference&) = delete;
     VariableReference(VariableReference&&) = default;
@@ -60,8 +60,6 @@ public:
         return result;
     }
 
-    bool isVariableReference() const override { return true; }
-
     String& name() { return m_name; }
 
     VariableDeclaration* variable() { return m_variable; }
@@ -73,7 +71,7 @@ public:
 
 private:
     VariableReference(CodeLocation location)
-        : Expression(location)
+        : Expression(location, Kind::VariableReference)
     {
     }
 
@@ -87,6 +85,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(VariableReference)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_EXPRESSION(VariableReference, isVariableReference())
 
 #endif
index 758088f..0f8bb08 100644 (file)
@@ -38,23 +38,21 @@ namespace WHLSL {
 
 namespace AST {
 
-class WhileLoop : public Statement {
+class WhileLoop final : public Statement {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     WhileLoop(CodeLocation location, UniqueRef<Expression>&& conditional, UniqueRef<Statement>&& body)
-        : Statement(location)
+        : Statement(location, Kind::WhileLoop)
         , m_conditional(WTFMove(conditional))
         , m_body(WTFMove(body))
     {
     }
 
-    virtual ~WhileLoop() = default;
+    ~WhileLoop() = default;
 
     WhileLoop(const WhileLoop&) = delete;
     WhileLoop(WhileLoop&&) = default;
 
-    bool isWhileLoop() const override { return true; }
-
     Expression& conditional() { return m_conditional; }
     Statement& body() { return m_body; }
 
@@ -69,6 +67,8 @@ private:
 
 }
 
+DEFINE_DEFAULT_DELETE(WhileLoop)
+
 SPECIALIZE_TYPE_TRAITS_WHLSL_STATEMENT(WhileLoop, isWhileLoop())
 
 #endif
index fa8c914..185ba0b 100644 (file)
@@ -72,9 +72,9 @@ public:
     
     AST::UnnamedType::Kind kind() { return m_kind; }
     bool isReferenceTypeNameNode() const { return m_kind == AST::UnnamedType::Kind::TypeReference; }
-    bool isPointerTypeNameNode() const { return m_kind == AST::UnnamedType::Kind::PointerType; }
-    bool isArrayReferenceTypeNameNode() const { return m_kind == AST::UnnamedType::Kind::ArrayReferenceType; }
-    bool isArrayTypeNameNode() const { return m_kind == AST::UnnamedType::Kind::ArrayType; }
+    bool isPointerTypeNameNode() const { return m_kind == AST::UnnamedType::Kind::Pointer; }
+    bool isArrayReferenceTypeNameNode() const { return m_kind == AST::UnnamedType::Kind::ArrayReference; }
+    bool isArrayTypeNameNode() const { return m_kind == AST::UnnamedType::Kind::Array; }
 
     BaseTypeNameNode* parent() { return m_parent; }
     MangledTypeName mangledName() const { return m_mangledName; }
@@ -89,7 +89,7 @@ class ArrayTypeNameNode final : public BaseTypeNameNode {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     ArrayTypeNameNode(BaseTypeNameNode* parent, MangledTypeName&& mangledName, unsigned numElements)
-        : BaseTypeNameNode(parent, WTFMove(mangledName), AST::UnnamedType::Kind::ArrayType)
+        : BaseTypeNameNode(parent, WTFMove(mangledName), AST::UnnamedType::Kind::Array)
         , m_numElements(numElements)
     {
     }
@@ -104,7 +104,7 @@ class ArrayReferenceTypeNameNode final : public BaseTypeNameNode {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     ArrayReferenceTypeNameNode(BaseTypeNameNode* parent, MangledTypeName&& mangledName, AST::AddressSpace addressSpace)
-        : BaseTypeNameNode(parent, WTFMove(mangledName), AST::UnnamedType::Kind::ArrayReferenceType)
+        : BaseTypeNameNode(parent, WTFMove(mangledName), AST::UnnamedType::Kind::ArrayReference)
         , m_addressSpace(addressSpace)
     {
     }
@@ -119,7 +119,7 @@ class PointerTypeNameNode final : public BaseTypeNameNode {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     PointerTypeNameNode(BaseTypeNameNode* parent, MangledTypeName&& mangledName, AST::AddressSpace addressSpace)
-        : BaseTypeNameNode(parent, WTFMove(mangledName), AST::UnnamedType::Kind::PointerType)
+        : BaseTypeNameNode(parent, WTFMove(mangledName), AST::UnnamedType::Kind::Pointer)
         , m_addressSpace(addressSpace)
     {
     }
@@ -274,18 +274,20 @@ std::unique_ptr<BaseTypeNameNode> TypeNamer::createNameNode(AST::UnnamedType& un
         auto& typeReference = downcast<AST::TypeReference>(unnamedType);
         return std::make_unique<ReferenceTypeNameNode>(parent, generateNextTypeName(), typeReference.resolvedType());
     }
-    case AST::UnnamedType::Kind::PointerType: {
+    case AST::UnnamedType::Kind::Pointer: {
         auto& pointerType = downcast<AST::PointerType>(unnamedType);
         return std::make_unique<PointerTypeNameNode>(parent, generateNextTypeName(), pointerType.addressSpace());
     }
-    case AST::UnnamedType::Kind::ArrayReferenceType: {
+    case AST::UnnamedType::Kind::ArrayReference: {
         auto& arrayReferenceType = downcast<AST::ArrayReferenceType>(unnamedType);
         return std::make_unique<ArrayReferenceTypeNameNode>(parent, generateNextTypeName(), arrayReferenceType.addressSpace());
     }
-    case AST::UnnamedType::Kind::ArrayType: {
+    case AST::UnnamedType::Kind::Array: {
         auto& arrayType = downcast<AST::ArrayType>(unnamedType);
         return std::make_unique<ArrayTypeNameNode>(parent, generateNextTypeName(), arrayType.numElements());
     }
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
     }
 }
 
@@ -294,12 +296,14 @@ static AST::UnnamedType* parent(AST::UnnamedType& unnamedType)
     switch (unnamedType.kind()) {
     case AST::UnnamedType::Kind::TypeReference:
         return nullptr;
-    case AST::UnnamedType::Kind::PointerType:
+    case AST::UnnamedType::Kind::Pointer:
         return &downcast<AST::PointerType>(unnamedType).elementType();
-    case AST::UnnamedType::Kind::ArrayReferenceType:
+    case AST::UnnamedType::Kind::ArrayReference:
         return &downcast<AST::ArrayReferenceType>(unnamedType).elementType();
-    case AST::UnnamedType::Kind::ArrayType:
+    case AST::UnnamedType::Kind::Array:
         return &downcast<AST::ArrayType>(unnamedType).type();
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
     }
 }
 
@@ -361,13 +365,13 @@ void TypeNamer::emitUnnamedTypeDefinition(StringBuilder& stringBuilder, BaseType
         stringBuilder.flexibleAppend("typedef ", mangledNameForType(namedType), ' ', baseTypeNameNode.mangledName(), ";\n");
         break;
     }
-    case AST::UnnamedType::Kind::PointerType: {
+    case AST::UnnamedType::Kind::Pointer: {
         auto& pointerType = downcast<PointerTypeNameNode>(baseTypeNameNode);
         ASSERT(baseTypeNameNode.parent());
         stringBuilder.flexibleAppend("typedef ", toString(pointerType.addressSpace()), ' ', pointerType.parent()->mangledName(), "* ", pointerType.mangledName(), ";\n");
         break;
     }
-    case AST::UnnamedType::Kind::ArrayReferenceType: {
+    case AST::UnnamedType::Kind::ArrayReference: {
         auto& arrayReferenceType = downcast<ArrayReferenceTypeNameNode>(baseTypeNameNode);
         ASSERT(baseTypeNameNode.parent());
         stringBuilder.flexibleAppend(
@@ -378,12 +382,14 @@ void TypeNamer::emitUnnamedTypeDefinition(StringBuilder& stringBuilder, BaseType
         );
         break;
     }
-    case AST::UnnamedType::Kind::ArrayType: {
+    case AST::UnnamedType::Kind::Array: {
         auto& arrayType = downcast<ArrayTypeNameNode>(baseTypeNameNode);
         ASSERT(baseTypeNameNode.parent());
         stringBuilder.flexibleAppend("typedef array<", arrayType.parent()->mangledName(), ", ", arrayType.numElements(), "> ", arrayType.mangledName(), ";\n");
         break;
     }
+    default:
+        RELEASE_ASSERT_NOT_REACHED();
     }
 
     emittedUnnamedTypes.add(&baseTypeNameNode);
index 8f3bcd3..7cab6c9 100644 (file)
@@ -1494,7 +1494,7 @@ auto Parser::parseSuffixOperator(UniqueRef<AST::Expression>&& previous) -> Suffi
     }
     case Token::Type::PlusPlus: {
         CodeLocation location(previous->codeLocation(), *suffix);
-        auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(previous));
+        auto result = makeUniqueRef<AST::ReadModifyWriteExpression>(location, WTFMove(previous));
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(result->oldVariableReference());
         result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator++"_str, WTFMove(callArguments)));
@@ -1504,7 +1504,7 @@ auto Parser::parseSuffixOperator(UniqueRef<AST::Expression>&& previous) -> Suffi
     default: {
         ASSERT(suffix->type == Token::Type::MinusMinus);
         CodeLocation location(previous->codeLocation(), *suffix);
-        auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(previous));
+        auto result = makeUniqueRef<AST::ReadModifyWriteExpression>(location, WTFMove(previous));
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(result->oldVariableReference());
         result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator--"_str, WTFMove(callArguments)));
@@ -1606,7 +1606,7 @@ auto Parser::completeAssignment(UniqueRef<AST::Expression>&& left) -> Expected<U
         break;
     }
 
-    auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(left));
+    auto result = makeUniqueRef<AST::ReadModifyWriteExpression>(location, WTFMove(left));
     Vector<UniqueRef<AST::Expression>> callArguments;
     callArguments.append(result->oldVariableReference());
     callArguments.append(WTFMove(*right));
@@ -1898,7 +1898,7 @@ auto Parser::parsePossiblePrefix(bool *isEffectful) -> Expected<UniqueRef<AST::E
         case Token::Type::PlusPlus: {
             if (isEffectful)
                 *isEffectful = true;
-            auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(*next));
+            auto result = makeUniqueRef<AST::ReadModifyWriteExpression>(location, WTFMove(*next));
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(result->oldVariableReference());
             result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator++"_str, WTFMove(callArguments)));
@@ -1908,7 +1908,7 @@ auto Parser::parsePossiblePrefix(bool *isEffectful) -> Expected<UniqueRef<AST::E
         case Token::Type::MinusMinus: {
             if (isEffectful)
                 *isEffectful = true;
-            auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(*next));
+            auto result = makeUniqueRef<AST::ReadModifyWriteExpression>(location, WTFMove(*next));
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(result->oldVariableReference());
             result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator--"_str, WTFMove(callArguments)));
index e4d9c72..53e3788 100644 (file)
@@ -157,7 +157,7 @@ public:
             structVariableDeclarations.append(WTFMove(structVariableDeclaration));
             auto structDeclarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(functionDefinition.codeLocation(), WTFMove(structVariableDeclarations));
 
-            auto makePointerExpression = std::make_unique<AST::MakePointerExpression>(functionDefinition.codeLocation(), WTFMove(structVariableReference), AST::AddressEscapeMode::DoesNotEscape);
+            std::unique_ptr<AST::Expression> makePointerExpression(new AST::MakePointerExpression(functionDefinition.codeLocation(), WTFMove(structVariableReference), AST::AddressEscapeMode::DoesNotEscape));
             makePointerExpression->setType(m_pointerToStructType.copyRef());
             makePointerExpression->setTypeAnnotation(AST::RightValue());
 
index 0e7c175..c8cd025 100644 (file)
@@ -303,34 +303,50 @@ void Visitor::visit(AST::StatementList& statementList)
 
 void Visitor::visit(AST::Statement& statement)
 {
-    if (is<AST::Block>(statement))
+    switch (statement.kind()) {
+    case AST::Statement::Kind::Block:
         checkErrorAndVisit(downcast<AST::Block>(statement));
-    else if (is<AST::Break>(statement))
+        break;
+    case AST::Statement::Kind::Break:
         checkErrorAndVisit(downcast<AST::Break>(statement));
-    else if (is<AST::Continue>(statement))
+        break;
+    case AST::Statement::Kind::Continue:
         checkErrorAndVisit(downcast<AST::Continue>(statement));
-    else if (is<AST::DoWhileLoop>(statement))
+        break;
+    case AST::Statement::Kind::DoWhileLoop:
         checkErrorAndVisit(downcast<AST::DoWhileLoop>(statement));
-    else if (is<AST::EffectfulExpressionStatement>(statement))
+        break;
+    case AST::Statement::Kind::EffectfulExpression:
         checkErrorAndVisit(downcast<AST::EffectfulExpressionStatement>(statement));
-    else if (is<AST::Fallthrough>(statement))
+        break;
+    case AST::Statement::Kind::Fallthrough:
         checkErrorAndVisit(downcast<AST::Fallthrough>(statement));
-    else if (is<AST::ForLoop>(statement))
+        break;
+    case AST::Statement::Kind::ForLoop:
         checkErrorAndVisit(downcast<AST::ForLoop>(statement));
-    else if (is<AST::IfStatement>(statement))
+        break;
+    case AST::Statement::Kind::If:
         checkErrorAndVisit(downcast<AST::IfStatement>(statement));
-    else if (is<AST::Return>(statement))
+        break;
+    case AST::Statement::Kind::Return:
         checkErrorAndVisit(downcast<AST::Return>(statement));
-    else if (is<AST::StatementList>(statement))
+        break;
+    case AST::Statement::Kind::StatementList:
         checkErrorAndVisit(downcast<AST::StatementList>(statement));
-    else if (is<AST::SwitchCase>(statement))
+        break;
+    case AST::Statement::Kind::SwitchCase:
         checkErrorAndVisit(downcast<AST::SwitchCase>(statement));
-    else if (is<AST::SwitchStatement>(statement))
+        break;
+    case AST::Statement::Kind::Switch:
         checkErrorAndVisit(downcast<AST::SwitchStatement>(statement));
-    else if (is<AST::VariableDeclarationsStatement>(statement))
+        break;
+    case AST::Statement::Kind::VariableDeclarations:
         checkErrorAndVisit(downcast<AST::VariableDeclarationsStatement>(statement));
-    else
+        break;
+    case AST::Statement::Kind::WhileLoop:
         checkErrorAndVisit(downcast<AST::WhileLoop>(statement));
+        break;
+    }
 }
 
 void Visitor::visit(AST::Break&)
@@ -349,46 +365,68 @@ void Visitor::visit(AST::DoWhileLoop& doWhileLoop)
 
 void Visitor::visit(AST::Expression& expression)
 {
-    if (is<AST::AssignmentExpression>(expression))
+    switch (expression.kind()) {
+    case AST::Expression::Kind::Assignment:
         checkErrorAndVisit(downcast<AST::AssignmentExpression>(expression));
-    else if (is<AST::BooleanLiteral>(expression))
+        break;
+    case AST::Expression::Kind::BooleanLiteral:
         checkErrorAndVisit(downcast<AST::BooleanLiteral>(expression));
-    else if (is<AST::CallExpression>(expression))
+        break;
+    case AST::Expression::Kind::Call:
         checkErrorAndVisit(downcast<AST::CallExpression>(expression));
-    else if (is<AST::CommaExpression>(expression))
+        break;
+    case AST::Expression::Kind::Comma:
         checkErrorAndVisit(downcast<AST::CommaExpression>(expression));
-    else if (is<AST::DereferenceExpression>(expression))
+        break;
+    case AST::Expression::Kind::Dereference:
         checkErrorAndVisit(downcast<AST::DereferenceExpression>(expression));
-    else if (is<AST::FloatLiteral>(expression))
+        break;
+    case AST::Expression::Kind::FloatLiteral:
         checkErrorAndVisit(downcast<AST::FloatLiteral>(expression));
-    else if (is<AST::IntegerLiteral>(expression))
+        break;
+    case AST::Expression::Kind::IntegerLiteral:
         checkErrorAndVisit(downcast<AST::IntegerLiteral>(expression));
-    else if (is<AST::LogicalExpression>(expression))
+        break;
+    case AST::Expression::Kind::Logical:
         checkErrorAndVisit(downcast<AST::LogicalExpression>(expression));
-    else if (is<AST::LogicalNotExpression>(expression))
+        break;
+    case AST::Expression::Kind::LogicalNot:
         checkErrorAndVisit(downcast<AST::LogicalNotExpression>(expression));
-    else if (is<AST::MakeArrayReferenceExpression>(expression))
+        break;
+    case AST::Expression::Kind::MakeArrayReference:
         checkErrorAndVisit(downcast<AST::MakeArrayReferenceExpression>(expression));
-    else if (is<AST::MakePointerExpression>(expression))
+        break;
+    case AST::Expression::Kind::MakePointer:
         checkErrorAndVisit(downcast<AST::MakePointerExpression>(expression));
-    else if (is<AST::NullLiteral>(expression))
+        break;
+    case AST::Expression::Kind::NullLiteral:
         checkErrorAndVisit(downcast<AST::NullLiteral>(expression));
-    else if (is<AST::DotExpression>(expression))
+        break;
+    case AST::Expression::Kind::Dot:
         checkErrorAndVisit(downcast<AST::DotExpression>(expression));
-    else if (is<AST::GlobalVariableReference>(expression))
+        break;
+    case AST::Expression::Kind::GlobalVariableReference:
         checkErrorAndVisit(downcast<AST::GlobalVariableReference>(expression));
-    else if (is<AST::IndexExpression>(expression))
+        break;
+    case AST::Expression::Kind::Index:
         checkErrorAndVisit(downcast<AST::IndexExpression>(expression));
-    else if (is<AST::ReadModifyWriteExpression>(expression))
+        break;
+    case AST::Expression::Kind::ReadModifyWrite:
         checkErrorAndVisit(downcast<AST::ReadModifyWriteExpression>(expression));
-    else if (is<AST::TernaryExpression>(expression))
+        break;
+    case AST::Expression::Kind::Ternary:
         checkErrorAndVisit(downcast<AST::TernaryExpression>(expression));
-    else if (is<AST::UnsignedIntegerLiteral>(expression))
+        break;
+    case AST::Expression::Kind::UnsignedIntegerLiteral:
         checkErrorAndVisit(downcast<AST::UnsignedIntegerLiteral>(expression));
-    else if (is<AST::EnumerationMemberLiteral>(expression))
+        break;
+    case AST::Expression::Kind::EnumerationMemberLiteral:
         checkErrorAndVisit(downcast<AST::EnumerationMemberLiteral>(expression));
-    else
+        break;
+    case AST::Expression::Kind::VariableReference:
         checkErrorAndVisit(downcast<AST::VariableReference>(expression));
+        break;
+    }
 }
 
 void Visitor::visit(AST::DotExpression& dotExpression)
index 514893b..e802541 100644 (file)
@@ -341,6 +341,7 @@ Modules/webgpu/WHLSL/Metal/WHLSLNativeTypeWriter.cpp
 Modules/webgpu/WHLSL/Metal/WHLSLVertexBufferIndexCalculator.cpp
 Modules/webgpu/WHLSL/WHLSLFunctionStageChecker.cpp
 Modules/webgpu/WHLSL/AST/WHLSLTypeArgument.cpp
+Modules/webgpu/WHLSL/AST/WHLSLExpression.cpp
 Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp
 Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp
 Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp
@@ -349,9 +350,12 @@ Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp
 Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp
 Modules/webgpu/WHLSL/AST/WHLSLNullLiteralType.cpp
 Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp
+Modules/webgpu/WHLSL/AST/WHLSLStatement.cpp
+Modules/webgpu/WHLSL/AST/WHLSLType.cpp
 Modules/webgpu/WHLSL/AST/WHLSLTypeReference.cpp
 Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.cpp
 Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.cpp
+Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.cpp
 Modules/webgpu/WHLSL/WHLSLPrepare.cpp
 Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp
 Modules/webgpu/WebGPU.cpp
index 578f6d1..0dad560 100644 (file)
                7C8139A81ED6287400CE26E8 /* JSDOMOperationReturningPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C8139A51ED6281D00CE26E8 /* JSDOMOperationReturningPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C8139AA1ED6604B00CE26E8 /* JSDOMCastedThisErrorBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C8139A91ED62DF200CE26E8 /* JSDOMCastedThisErrorBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C83DE861D04CC5D00FEBCF3 /* SpringSolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C83DE851D04CBD400FEBCF3 /* SpringSolver.h */; };
-               7C85B20222FB04850030684F /* WHLSLUnnamedType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C85B20122FB04850030684F /* WHLSLUnnamedType.cpp */; };
                7C8E34AD1E4A33AF0054CE23 /* JSDOMConvertAny.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C8E34921E4A338E0054CE23 /* JSDOMConvertAny.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C8E34AE1E4A33AF0054CE23 /* JSDOMConvertBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C8E34931E4A338E0054CE23 /* JSDOMConvertBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
                7C8E34AF1E4A33AF0054CE23 /* JSDOMConvertBoolean.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C8E34941E4A338E0054CE23 /* JSDOMConvertBoolean.h */; settings = {ATTRIBUTES = (Private, ); }; };
                52131E5A1C4F15610033F802 /* VideoFullscreenInterfaceMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoFullscreenInterfaceMac.mm; sourceTree = "<group>"; };
                5215862C229377B7005925EF /* WHLSLAST.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLAST.h; sourceTree = "<group>"; };
                522BAB9622E6A36200C54CE9 /* WHLSLCodeLocation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLCodeLocation.h; sourceTree = "<group>"; };
+               522D07A322FBAB4300B905BE /* WHLSLExpression.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLExpression.cpp; sourceTree = "<group>"; };
                522DA3D3229E1D390042D151 /* WHLSLGlobalVariableReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLGlobalVariableReference.h; sourceTree = "<group>"; };
                522E1A172297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLPreserveVariableLifetimes.cpp; sourceTree = "<group>"; };
                522E1A192297D6D400E5D36A /* WHLSLPreserveVariableLifetimes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLPreserveVariableLifetimes.h; sourceTree = "<group>"; };
                52B0D4BD1C57FD1E0077CE53 /* PlatformView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformView.h; sourceTree = "<group>"; };
                52B0D4BF1C57FD660077CE53 /* VideoFullscreenChangeObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenChangeObserver.h; sourceTree = "<group>"; };
                52B0D4C11C57FF910077CE53 /* VideoFullscreenInterfaceMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenInterfaceMac.h; sourceTree = "<group>"; };
+               52CB11DB22FDDB2E009F0A64 /* WHLSLDefaultDelete.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLDefaultDelete.h; sourceTree = "<group>"; };
                52D5A18D1C54590300DE34A3 /* VideoFullscreenLayerManagerObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoFullscreenLayerManagerObjC.mm; sourceTree = "<group>"; };
                52D5A18E1C54590300DE34A3 /* VideoFullscreenLayerManagerObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenLayerManagerObjC.h; sourceTree = "<group>"; };
                52D5A1A41C57488900DE34A3 /* VideoFullscreenModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoFullscreenModel.h; sourceTree = "<group>"; };
                                C21BF70621CD89C700227979 /* WHLSLCommaExpression.h */,
                                C21BF73321CD89F000227979 /* WHLSLConstantExpression.h */,
                                C21BF6F521CD89B500227979 /* WHLSLContinue.h */,
+                               52CB11DB22FDDB2E009F0A64 /* WHLSLDefaultDelete.h */,
                                C21BF70121CD89C400227979 /* WHLSLDereferenceExpression.h */,
                                C21BF71821CD89D700227979 /* WHLSLDotExpression.h */,
                                C21BF6FB21CD89BE00227979 /* WHLSLDoWhileLoop.h */,
                                C21BF72621CD89E300227979 /* WHLSLEnumerationMember.h */,
                                C21BF70221CD89C400227979 /* WHLSLEnumerationMemberLiteral.h */,
                                C21BF70C21CD89CC00227979 /* WHLSLExpression.h */,
+                               522D07A322FBAB4300B905BE /* WHLSLExpression.cpp */,
                                C21BF70021CD89C200227979 /* WHLSLFallthrough.h */,
                                C21BF73521CD89F200227979 /* WHLSLFloatLiteral.h */,
                                1CB69B3821DF03E1006E846A /* WHLSLFloatLiteralType.cpp */,
                                F12171F516A8CED2000053CA /* WebVTTElement.cpp in Sources */,
                                5D21A80213ECE5DF00BB7064 /* WebVTTParser.cpp in Sources */,
                                B10B6981140C174000BC1C26 /* WebVTTTokenizer.cpp in Sources */,
-                               7C85B20222FB04850030684F /* WHLSLUnnamedType.cpp in Sources */,
                                A14832C2187F65C700DA63A6 /* WKUtilities.c in Sources */,
                                A833C7CC0A2CF07400D57664 /* XLinkNames.cpp in Sources */,
                                A833C80C0A2CF25600D57664 /* XMLNames.cpp in Sources */,
index b574856..9a0f487 100644 (file)
@@ -79,6 +79,7 @@ public:
 
 private:
     friend class WTF::RefCounted<WorkerScriptLoader>;
+    friend struct std::default_delete<WorkerScriptLoader>;
 
     WorkerScriptLoader();
     ~WorkerScriptLoader();